﻿var temp, temp2, cookieArray, cookieArray2, cookieCount;

function initiate(){

  cookieCount=0;

  if(document.cookie){

    cookieArray=document.cookie.split(";");
    cookieArray2=new Array();

    for(i in cookieArray){
      cookieArray2[cookieArray[i].split("=")[0].replace(/ /g,"")]=cookieArray[i].split("=")[1].replace(/ /g,"");
    }

  }

  cookieArray=(document.cookie.indexOf("state=")>=0)?cookieArray2["state"].split(","):new Array();

  temp=document.getElementById("containerul");

  for(var o=0;o<temp.getElementsByTagName("li").length;o++){

    if(temp.getElementsByTagName("li")[o].getElementsByTagName("ul").length>0){

      temp2				= document.createElement("span");
      temp2.className			= "symbols";
      temp2.style.backgroundImage	= (cookieArray.length>0)?((cookieArray[cookieCount]=="true")?"url(images/minus.png)":"url(images/plus.png)"):"url(images/plus.png)";
      temp2.onclick=function(){
        showhide(this.parentNode);
        writeCookie();
      }

      temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild)

      temp.getElementsByTagName("li")[o].getElementsByTagName("ul")[0].style.display = "none";

      if(cookieArray[cookieCount]=="true"){
        showhide(temp.getElementsByTagName("li")[o]);
      }

      cookieCount++;

    }
    else{

      temp2				= document.createElement("span");
      temp2.className			= "symbols";
      temp2.style.backgroundImage	= "url(images/page.png)";

      temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild);

    }

  }

}

function showhide(el){

  el.getElementsByTagName("ul")[0].style.display=(el.getElementsByTagName("ul")[0].style.display=="block")?"none":"block";

  el.getElementsByTagName("span")[0].style.backgroundImage=(el.getElementsByTagName("ul")[0].style.display=="block")?"url(images/minus.png)":"url(images/plus.png)";

}



function writeCookie(){		// Runs through the menu and puts the "states" of each nested list into an array, the array is then joined together and assigned to a cookie.

  cookieArray=new Array()

  for(var q=0;q<temp.getElementsByTagName("li").length;q++){

    if(temp.getElementsByTagName("li")[q].childNodes.length>0){
      if(temp.getElementsByTagName("li")[q].childNodes[0].nodeName=="SPAN" && temp.getElementsByTagName("li")[q].getElementsByTagName("ul").length>0){

        cookieArray[cookieArray.length]=(temp.getElementsByTagName("li")[q].getElementsByTagName("ul")[0].style.display=="block");

      }
    }

  }

  document.cookie="state="+cookieArray.join(",")+";expires="+new Date(new Date().getTime() + 365*24*60*60*1000).toGMTString();

}
function GoPage(Myself)
{
   window.location.href=Myself+"Page="+document.formpro.SkipPage.value;
}

function CheckBuy()
{
	if (document.buyform.proname.value =="" ){
		alert ("提示：\n\n产品名称不能空！");
		document.buyform.proname.focus();
		return false;
	}
	if (document.buyform.prono.value == "" ){
		alert ("提示：\n\n产品编号不能空！");
		document.buyform.prono.focus();
		return false;
	}
	if (document.buyform.buynum.value.length <1){
		alert ("提示：\n\n定购数量不能空！");
		document.buyform.buynum.focus();
		return false;
	}
	if (document.buyform.name.value.length < 2 || document.buyform.name.value.length > 16){
		alert ("提示：\n\n姓名必须在2-16字之间！");
		document.buyform.name.focus();
		return false;
	}
	if (document.buyform.com.value.length < 2 || document.buyform.com.value.length > 16){
		alert ("提示：\n\n单位名称不能为空\n如果是个人购买请填写“个人购买”！");
		document.buyform.com.focus();
		return false;
	}
	if (document.buyform.tel.value == ""|| document.buyform.tel.value.length < 8){
		alert ("提示：\n\n联系电话必须在8个字符以上！");
		document.buyform.tel.focus();
		return false;
	}

	if (document.buyform.address.value == ""|| document.buyform.address.value.length < 8){
		alert ("提示：\n\n联系地址不能少于8个字符！");
		document.buyform.address.focus();
		return false;
	}
	if (document.buyform.zip.value.length !=6){
		alert ("提示：\n\n邮编必须6个数字组成的！");
		document.buyform.zip.focus();
		return false;
	}	
    if(document.buyform.email.value.length!=0)
     {
       if (document.buyform.email.value.charAt(0)=="." ||        
            document.buyform.email.value.charAt(0)=="@"||       
            document.buyform.email.value.indexOf('@', 0) == -1 || 
            document.buyform.email.value.indexOf('.', 0) == -1 || 
            document.buyform.email.value.lastIndexOf("@")==document.buyform.email.value.length-1 || 
            document.buyform.email.value.lastIndexOf(".")==document.buyform.email.value.length-1)
        {
         alert("Email地址格式不正确！");
         document.buyform.email.focus();
         return false;
         }
      }
    else
     {
      alert("Email不能为空！");
      document.buyform.email.focus();
      return false;
      }
 }
 
 function OpenScript(url,width,height)
{
  var win = window.open(url,"SelectToSort",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}
//调用在线内容编辑器-----------------------------------------------------------
function OpenDialog(sURL, iWidth, iHeight)
{
   var oDialog = window.open(sURL, "_EditorDialog", "width=" + iWidth.toString() + ",height=" + iHeight.toString() + ",resizable=no,left=0,top=0,scrollbars=no,status=no,titlebar=no,toolbar=no,menubar=no,location=no");
   oDialog.focus();
}
//另类弹出窗口
function sAlert(str){
			var msgw,msgh,bordercolor;
			msgw=400;//提示窗口的宽度
			msgh=100;//提示窗口的高度
			titleheight=25 //提示窗口标题高度
			bordercolor="#336699";//提示窗口的边框颜色
			titlecolor="#99CCFF";//提示窗口的标题颜色
			
			var sWidth,sHeight;
			sWidth=document.body.offsetWidth;
			sHeight=screen.height;

			var bgObj=document.createElement("div");
			bgObj.setAttribute('id','bgDiv');
			bgObj.style.position="absolute";
			bgObj.style.top="0";
			bgObj.style.background="#777";
			bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
			bgObj.style.opacity="0.6";
			bgObj.style.left="0";
			bgObj.style.width=sWidth + "px";
			bgObj.style.height=sHeight + "px";
			bgObj.style.zIndex = "10000";
			document.body.appendChild(bgObj);
			
			var msgObj=document.createElement("div")
			msgObj.setAttribute("id","msgDiv");
			msgObj.setAttribute("align","center");
			msgObj.style.background="white";
			msgObj.style.border="1px solid " + bordercolor;
	    	msgObj.style.position = "absolute";
            msgObj.style.left = "50%";
            msgObj.style.top = "50%";
            msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
            msgObj.style.marginLeft = "-225px" ;
            msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
            msgObj.style.width = msgw + "px";
            msgObj.style.height =msgh + "px";
            msgObj.style.textAlign = "center";
            msgObj.style.lineHeight ="25px";
            msgObj.style.zIndex = "10001";
   
		   var title=document.createElement("h4");
		   title.setAttribute("id","msgTitle");
		   title.setAttribute("align","right");
		   title.style.margin="0";
		   title.style.padding="3px";
		   title.style.background=bordercolor;
		   title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
		   title.style.opacity="0.75";
		   title.style.border="1px solid " + bordercolor;
		   title.style.height="18px";
		   title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
		   title.style.color="white";
		   title.style.cursor="pointer";
		   title.innerHTML="关闭";
		   title.onclick=function(){
		        document.body.removeChild(bgObj);
                document.getElementById("msgDiv").removeChild(title);
                document.body.removeChild(msgObj);
                }
		   document.body.appendChild(msgObj);
		   document.getElementById("msgDiv").appendChild(title);
		   var txt=document.createElement("p");
		   txt.style.margin="1em 0"
		   txt.setAttribute("id","msgTxt");
		   txt.innerHTML=str;
           document.getElementById("msgDiv").appendChild(txt);
            }
			
function runCode(c)  //定义一个运行代码的函数，
{
  var code=c;//即要运行的代码。
  var newwin=window.open('','','');  //打开一个窗口并赋给变量newwin。
  newwin.opener = null // 防止代码对论谈页面修改
  newwin.document.write(code);  //向这个打开的窗口中写入代码code，这样就实现了运行代码功能。
  newwin.document.close();
}
			
