﻿function CreateControl(DivID, ObjectID)//显示日历
{
  var d = document.getElementById(DivID);
	  d.innerHTML = '<object id="'+ObjectID+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="player/8/swflash.cab#version=8,0,0,0" '+
				'width="207" height="215" style="position:absolute;Z-INDEX:1;" VIEWASTEXT>'+
				'<param name="movie" value="images/ChoseDate.swf" /><param name="quality" value="high" /><param name="allowScriptAccess" value="sameDomain" />'+
				'<param name="loop" value="false" /><param name="menu" value="false"><param name="wmode" value="transparent" />'+
				'<embed src="images/ChoseDate.swf" quality="high" loop="false" width="207" height="215" name="'+ObjectID+'" align="" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';			

}
//创建日历//
function CreateDate(DivID, ObjectID, BtnAlign, Depth)
{
	var d = document.getElementById(DivID);
	d.innerHTML = '<object id="'+ObjectID+'" name="'+ObjectID+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="player/8/swflash.cab#version=8,0,0,0" '+
		'width="206" height="215" style="width:18px;height:18px;position:absolute;Z-INDEX:'+Depth+';" onblur="closeChoseDate(this)" VIEWASTEXT>'+
		'<param name="movie" value="images/ChoseDate.swf?btnalign='+BtnAlign+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" />'+
		'<param name="allowScriptAccess" value="sameDomain" /><param name="loop" value="false" /><param name="menu" value="false">'+
		'<embed id="'+ObjectID+'" src="images/ChoseDate.swf?btnalign='+BtnAlign+'" quality="high" loop="false" width="206" height="215" name="'+ObjectID+'" align="" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';			
	d.children(0).mask = new Array();
	return d.children(0);	
}
//关闭日历//
function closeChoseDate(eventTarget) {
	eventTarget.GotoFrame(2);
	eventTarget.style.left = 0;
	eventTarget.style.width = 18;
	eventTarget.style.height = 18;
	if(eventTarget.mask != null && eventTarget.mask.length>0){
		for(i=0;i<eventTarget.mask.length;i++){
			eventTarget.mask[i].style.display = "";
		}
	}
}
//显示日历//
function showChoseDate(eventTarget, btnAlign) {
	eventTarget.style.width = 206;
	eventTarget.style.height = 215;
	if(btnAlign.toLowerCase() == "right"){
		eventTarget.style.left  = -188;
	}
	if(eventTarget.mask != null && eventTarget.mask.length>0){
		for(i=0;i<eventTarget.mask.length;i++){
			eventTarget.mask[i].style.display = "none";
		}
	}	
}

function GetSRValue(ipv,fori){
    var objdiv;
	for(i=0;i<fori;i++){
		objdiv = document.getElementById(ipv+"_"+i);
		if(objdiv.checked == true){
			return objdiv.value;
		}
	}	
}

//声明XMLHttpRequest对象
var xmlHttp;

function CreateXMLHTTP()
{
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();//mozilla浏览器
    }
    else if(window.ActiveXObject)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");//IE老版本
        }
        catch(e)
        {}
        try
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
        }
        catch(e)
        {}
        if(!xmlHttp)
        {
            window.alert("不能创建XMLHttpRequest对象实例！");
            return false;
        }
    }
}

function GetUrlHtml(url){
	var xmltxthttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmltxthttp.Open("POST", url, false);
	xmltxthttp.Send();
	var txt=xmltxthttp.responseText;
	xmltxthttp=null;
	return txt;
}

function Login(UrlString)
{
	var uid = document.getElementById("UserName").value; 
	var pwd = document.getElementById("PassWord").value; 
	
	var alertstr = "";
	if(uid==""){
		alertstr += "请输入用户名!";	
	}
	if(pwd==""){
		alertstr += "请输入密码!";	
	}
	if(alertstr!=""){
		document.getElementById("error").innerHTML = alertstr;
	}else{
		CreateXMLHTTP();//创建XMLHttpRequest对象
		var url="Login.aspx?uid="+encodeURIComponent(uid)+"&pwd="+pwd+"&cmd="+Math.round(Math.random()*100);
		
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = function(){ExecGetLoginText(UrlString)};
		xmlHttp.send(null);
	}
}

//执行检测用户名回调函数
function ExecGetLoginText(UrlString)
{
    if(xmlHttp.readyState==4)//判断对象状态
    {
        if(xmlHttp.status==200)//信息成功返回，开始处理信息
        {
            var isok = xmlHttp.responseText;
            isok = ATrim(isok);
            //alert(isok);
			if(isok!="" && isok!="Yes"){
				document.getElementById("error").innerHTML = isok;
			}else{
				MyAlert('');
				SetLoginSession('1');
				if(UrlString!=null && UrlString!=""){
				location.href = UrlString;
				}
			}
        }
    }
}

function Logout()
{
	CreateXMLHTTP();//创建XMLHttpRequest对象
	var url="LoginOut.aspx?cmd="+Math.round(Math.random()*100);
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = ExecLogout;
	xmlHttp.send(null);
}

function ExecLogout()
{
	if(xmlHttp.readyState==4)//判断对象状态
    {
        if(xmlHttp.status==200)//信息成功返回，开始处理信息
        {
            var isok = xmlHttp.responseText;   
            isok = ATrim(isok);
			if(isok!="" && isok=="Yes"){
				var S_url = GetUrlString();
				switch(S_url){
					case "member.aspx":
					case "member_leaveproduct.aspx":
					case "member_byleaveproduct.aspx":
					case "member_samplingproduct.aspx":
					case "member_bysamplingproduct.aspx":
					case "member_pendproduct.aspx":
					case "member_addpendproduct.aspx":
					case "member_favoriteproduct.aspx":
					case "member_steppedup.aspx":
						location.href = "default.aspx?tid=1&navindex=0";
						break;
				}
				SetLoginSession('0');
			}else{
				alert(isok);
			}
        }
    }
}

function GetUrlString()
{
	var ustr = document.URL;
	var I_a = ustr.lastIndexOf("/");
	var I_b = ustr.indexOf("?");
	if(I_b>0){
		ustr = ustr.substring(I_a+1,I_b);
	}else{
		ustr = ustr.substring(I_a+1,ustr.length);
	}
	ustr = ustr.replace("#","");
	ustr = ustr.toLowerCase();
	return ustr;
}

function SetLoginSession(state)
{
	if(state==""){
		CreateXMLHTTP();//创建XMLHttpRequest对象
		var url = "CheckLogin.aspx?cmd="+Math.round(Math.random()*100);
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = ExecSetLoginSession;
		xmlHttp.send(null);	
	}else{
		SetLoginSessioninnerHTML(state);
	}
}

function ExecSetLoginSession(state)
{
	if(xmlHttp.readyState==4)//判断对象状态
	{
		if(xmlHttp.status==200)//信息成功返回，开始处理信息
		{
			var isok = xmlHttp.responseText; 
			if(isok=="Yes"){
				state = "1";
			}else{
				state = "0";
			}
			SetLoginSessioninnerHTML(state);
			document.getElementById("islogin").value = state;
		}
	}	
}

function SetLoginSessioninnerHTML(state)
{
	if(state == "0"){
		document.getElementById("head_1").src="images/ml_1.jpg";
		document.getElementById("head_2").background="images/ml_2.jpg";
		
		document.getElementById("head_3").src="images/ml_3.jpg";
		document.getElementById("head_4").background="images/ml_4.jpg";
		
		document.getElementById("Head_Member_reg").innerHTML = "<a href='reg.aspx'><img src=\"images/ml_zc.jpg\" border=\"0\" /></a>";
		document.getElementById("Head_Member_log").innerHTML = "<a href='#' onclick=\"MyAlert('');\"><img src=\"images/ml_dl.jpg\" border=\"0\" /></a>";
	}else if(state == "1"){
		document.getElementById("head_1").src="images/ml_1_2.jpg";
		document.getElementById("head_2").background="images/ml_2_2.jpg";
		
		document.getElementById("head_3").src="images/ml_3_2.jpg";
		document.getElementById("head_4").background="images/ml_4_2.jpg";
		
		document.getElementById("Head_Member_reg").innerHTML = "<a href='#' onclick=\"Redirect('Member.aspx');\"><img src=\"images/ml_wdmlg.jpg\" border=\"0\" /></a>";
		document.getElementById("Head_Member_log").innerHTML = "<a href='#' onclick='Logout();'><img src=\"images/ml_tc.jpg\" border=\"0\" /></a>";
	}/**/
}


function Redirect(UrlString)
{
	CreateXMLHTTP();//创建XMLHttpRequest对象
	var url = "CheckLogin.aspx?cmd="+Math.round(Math.random()*100);
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = function(){ExecRedirect(UrlString)};
	xmlHttp.send(null);
}

function ExecRedirect(UrlString)
{
	if(xmlHttp.readyState==4)//判断对象状态
    {
        if(xmlHttp.status==200)//信息成功返回，开始处理信息
        {
            var isok = xmlHttp.responseText;   
            isok = ATrim(isok);
			if(isok=="Yes"){
				location.href = UrlString;
			}else{
				MyAlert(UrlString);
			}
        }
    }
}

var v_select = "";
/*
function ShowFactoryDetail(id){
	
	if (document.body.className!="Normal"){
		document.body.className="Normal";
		SetAllSelectOut();
	}else{
		CreateXMLHTTP();//创建XMLHttpRequest对象
		var url = "GetFactoryDetail.aspx?id="+id+"&cmd="+Math.round(Math.random()*100);
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = ExecShowFactoryDetail;
		xmlHttp.send(null);
	}
}

function ExecShowFactoryDetail(){

	if(xmlHttp.readyState==4)//判断对象状态
    {
        if(xmlHttp.status==200)//信息成功返回，开始处理信息
        {
            var FactoryHtml = xmlHttp.responseText;   
            //alert('ddd');
            document.body.className="";
			var msbox = document.getElementById("MsgBox");
			msbox.innerHTML = FactoryHtml;
			msbox.setAttribute("onclick",Function("ShowPic('')"),0)
			var sWidth=document.body.offsetWidth;
			var sHeight1=document.body.scrollHeight;
			var sHeight2=screen.height;
			var sHeight = sHeight1;
			if(sHeight2>sHeight1){
				sHeight = sHeight2;	
			}
			document.getElementById("Filter").style.height = sHeight + "px";
			SetAllSelect();
			
        }
    }
}*/

function ShowPic(imgstr){
	
	if (document.body.className!="Normal"){
		document.body.className="Normal";
		SetAllSelectOut();
	}else{
		document.body.className="";
		
		var msbox = document.getElementById("MsgBox");
		msbox.innerHTML = imgstr;
		msbox.setAttribute("onclick",Function("ShowPic('')"),0)
		
		var sWidth=document.body.offsetWidth;
		
		var sHeight1=document.body.scrollHeight;
		var sHeight2=screen.height;
		
		var sHeight = sHeight1;
		if(sHeight2>sHeight1){
			sHeight = sHeight2;	
		}
		
		//var mWidth=800;//msbox.offsetWidth;
		//var nLeft=(sWidth - mWidth)/2;
		
		//msbox.style.top = sHeight2/3; 
		//msbox.style.left = nLeft+"px";
		
		document.getElementById("Filter").style.height = sHeight + "px";
		
		SetAllSelect();
	}
}

function LoginHtml(UrlString){
var reval  = "";reval += "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">";reval += "<tr style=\"background-color:#8C0000;\">";reval += "	<td height=\"30\" align=\"right\" style=\"color:#ffffff\">用户登录</td>";reval += "	<td align=\"left\" style=\"padding-left:10px;\"></td>";reval += "	<td align=\"right\" style=\"padding-right:16px;\"><img src=\"icon/dialogclose.gif\" onclick=\"MyAlert('');\" style=\"cursor:hand;\"></td>";reval += "</tr>";reval += "<tr>";reval += "	<td width=\"25%\" height=\"20\" align=\"right\"></td>";reval += "	<td width=\"50%\" align=\"left\" style=\"padding-left:10px;\"></td>";reval += "	<td width=\"25%\" align=\"left\" style=\"padding-left:10px;\"></td>";reval += "</tr>";reval += "<tr>";reval += "	<td width=\"25%\" height=\"25\" align=\"right\">用户名：</td>";reval += "	<td width=\"50%\" align=\"left\" style=\"padding-left:10px;\"><input id=\"UserName\" type=\"text\" onkeydown=\"loginkedown(this,'"+UrlString+"')\" style=\"width:100%;\"/></td>";reval += "	<td width=\"25%\" align=\"left\" style=\"padding-left:10px;\"></td>";reval += "</tr>";reval += "<tr>";reval += "	<td  height=\"25\" align=\"right\">密&nbsp;&nbsp;&nbsp;&nbsp;码：</td>";reval += "	<td  align=\"left\" style=\"padding-left:10px;\"><input id=\"PassWord\" type=\"password\" onkeydown=\"loginkedown(this,'"+UrlString+"')\" style=\"width:100%;\"/></td>";reval += "	<td  align=\"left\"></td>";reval += "</tr>";reval += "<tr>";reval += "	<td height=\"35\"></td>";reval += "	<td align=\"left\" colspan=\"2\" style=\"padding-left:10px;\"><img id=\"bt_login\" src=\"images/ml_dl2.gif\" onclick=\"Login('');\" style=\"cursor:hand;\">&nbsp;&nbsp;<a href='reg.aspx'><img src=\"images/ml_zchy.gif\" border=\"0\"></a></td>";reval += "</tr>";reval += "<tr>";reval += "	<td height=\"25\"></td>";reval += "	<td align=\"left\" colspan=\"2\" style=\"padding-left:10px;\"><div id=\"error\" style=\"color:#ff0000;\"></div></td>";reval += "</tr>";reval += "</table>";return reval;}

function loginkedown(obj,UrlString){
	if(event.keyCode == "13" && (obj.id=="UserName" || obj.id=="PassWord")){
		Login(UrlString);	
	}
}

function MyAlert(UrlString){
	var msbox = document.getElementById("MsgBox");
	msbox.innerHTML = LoginHtml(UrlString);
		
	document.getElementById("UserName").value = ""; 
	document.getElementById("PassWord").value = ""; 
	
	document.getElementById("error").innerHTML = "";
	if (document.body.className!="Normal"){
		document.body.className="Normal";
		SetAllSelectOut();
	}else{
		document.body.className="";
		
		
		
		var sWidth=document.body.offsetWidth;
		
		var sHeight1=document.body.scrollHeight;
		var sHeight2=screen.height;
		
		var sHeight = sHeight1;
		if(sHeight2>sHeight1){
			sHeight = sHeight2;	
		}
		
		var mWidth=msbox.offsetWidth;
		var nLeft=(sWidth - mWidth)/2;
		
		msbox.style.top = screen.height/3; 
		msbox.style.left=nLeft+"px";
		
		document.getElementById("Filter").style.height = sHeight + "px";
		
		SetAllSelect();
		
		document.all.bt_login.setAttribute("onclick",Function("Login('"+UrlString+"')"),0)
		
		//document.all.bt_login.onclick=Function("Login(UrlString)");
	}
}

function SetAllSelect()
{
	v_select = "";
	var items = window.document.all.tags("select");
	for (i=0; i<items.length; i++)
	{
		if(items[i].disabled == false){
			items[i].disabled = true;
			v_select += items[i].id+";";
		}
	}		
}

function SetAllSelectOut()
{
	var arr = v_select.split(';');	
	for (i=0; i<arr.length; i++)
	{
		if(arr[i]!=""){
			if(document.getElementById(arr[i]).disabled == true){
				document.getElementById(arr[i]).disabled = false;
			}
		}
	}	
}

function ATrim(str) { 
	return str.replace(/^\s+|\s+$/g,"");
}

function LTrim() { 
	return this.replace(/(^\s*)/g, ""); 
} 

function RTrim() { 
	return this.replace(/(\s*$)/g, ""); 
}