﻿ 
      /***********************
      *******创建遮罩层,拖动并遮罩层 *****
      **参数说明：
      ********** valuname：指针对哪一个界面进行操作，因为每个界面input,radio,select的资料不一样
      **********      vac：指有几个span(1.2.3.4)错误提示框
      *********    isbool：指打开遮罩层时，时否要清空所选的资料
      *******************************************************************************/
	function AlertMsg(valuname,vac,isbool){

	   /**第一步：创建DIV遮罩层。*/
		var sWidth,sHeight;
		sWidth = window.screen.availWidth;
		//屏幕可用工作区高度： window.screen.availHeight;
		//屏幕可用工作区宽度： window.screen.availWidth;
		//网页正文全文宽：     document.body.scrollWidth;
		//网页正文全文高：     document.body.scrollHeight;
		if(window.screen.availHeight > document.body.scrollHeight){  //当高度少于一屏
			sHeight = window.screen.availHeight;  
		}else{//当高度大于一屏
			sHeight = document.body.scrollHeight;   
		}
		if(isbool)  //是否要清空
		{
		     if(valuname=="reguser")
		     {   
		         //注册用户界面
		         clearReguser(vac);
		     }
		 }
		 else  //不要清空，但是有select资料，所以要把它默认设为0
		 {
		     if(valuname=="reguser")
		     {
		        setReguserSelect();
		     }
		 }
		
		//创建遮罩背景
		var maskObj = document.createElement("div");
		maskObj.setAttribute('id','BigDiv');
		maskObj.style.position = "absolute";
		maskObj.style.top = "0";
		maskObj.style.left = "0";
		maskObj.style.background = "#777";
		maskObj.style.filter = "Alpha(opacity=30);";
		maskObj.style.opacity = "0.3";
		maskObj.style.width = sWidth + "px";
		maskObj.style.height = sHeight + "px";
		maskObj.style.zIndex = "10000";
		document.body.appendChild(maskObj);

      
        /**第二步：动态设置div的上边距和左边距，使弹出div居中打开。*/
        var MyDiv =document.getElementById("MyDiv");
//		var MyDiv_w = getStyle(MyDiv,"width");
//		var MyDiv_h = getStyle(MyDiv,"height");
        var MyDiv_w = 460;
		var MyDiv_h = 525;
		
 
	    
//		MyDiv_w = parseInt(MyDiv_w); //去掉 单位 "px"
//		MyDiv_h = parseInt(MyDiv_h);

		var width = pageWidth(); 
		var height = pageHeight();
		var left = leftPosition();
		var top = topPosition();

		var Div_topposition = top + (height / 2) - (MyDiv_h / 2); //计算上边距
		var Div_leftposition = left + (width / 2) - (MyDiv_w / 2); //计算左边距

		MyDiv.style.left = Div_leftposition + "px";  //拼接上 单位"px"
		MyDiv.style.top =  Div_topposition + "px";
		MyDiv.style.width=MyDiv_w+"px";
		MyDiv.style.height=MyDiv_h+"px";
		MyDiv.style.display = "block";  //设置弹出div显示
	}

		/**第三步：关闭窗口和遮罩层。*/
	function CloseDiv(){
		var Bigdiv = document.getElementById("BigDiv");
		var Mydiv = document.getElementById("MyDiv");
		document.body.removeChild(Bigdiv); 
		Mydiv.style.display="none";
	}
	  /** 第四步：弹出层拖动。*/ 
	 window.onload = function(){
	   if(document.getElementById("MyDiv")){
			var MyDiv = document.getElementById("MyDiv");
			var dragMe   = document.getElementById("dragMe");
			Drag.init(dragMe, MyDiv);
		}
	}

      /**第五步：弹出层跟随滚动条滚动。*/
	window.onscroll = window_onscroll;
	function window_onscroll(){
		var MyDiv =document.getElementById("MyDiv");
		var MyDiv_h = getStyle(MyDiv,"height");
		MyDiv_h = parseInt(MyDiv_h);
		var height = pageHeight();
		var top = topPosition();
		var Div_topposition = top + (height / 2) - (MyDiv_h / 2); //计算上边距
		MyDiv.style.top =  Div_topposition + "px";
	}

        // 计算当前窗口的宽度 //
        function pageWidth(){
			         return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
        }

        // 计算当前窗口的高度 //
        function pageHeight(){
			         return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
        }

        // 计算当前窗口的上边滚动条//
        function topPosition(){
			          return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
        }

        // 计算当前窗口的左边滚动条//
        function leftPosition(){
			         return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
        }

        //解决外嵌样式style , 用js获取不到的问题。
        function getStyle(elem, name){
			        if(elem.style[name])
				        return elem.style[name];
			        else if(elem.currentStyle)	//ie
				        return elem.currentStyle[name];
			        else if(document.defaultView && document.defaultView.getComputedStyle){	//w3c
				        name = name.replace(/([A-Z])/g,"-$1");
				        name = name.toLowerCase();
        				
				        var s = document.defaultView.getComputedStyle(elem,"");
				        return s && s.getPropertyValue(name);
			        } else
				        return null
        }
        
    
    //清空注册会员的资料
    function clearReguser(vac)
    {
        
      for(var i=0,l=document.forms[0].elements.length;i<l;i++)
      {   
        if(document.forms[0].elements[i].type=='text')   
        {                
            document.forms[0].elements[i].value="";   
        }
      } 
      
      for(var s=1;s<=vac;s++)
      {
         document.getElementById("span"+s).innerHTML="";
      }
       
    }
    
    //设定注册界面的地区性显示，城市为请选择
    function setReguserSelect()
    {
        var varc=document.getElementById("parea1");      
        varc.selectedIndex=0;
    }