// JScript 文件

//删除左右两端的空格

function Trim(str)
{
  str=str.replace(/(^\s*)|(\s*$)/g,"");
  return str;  
}

//手机小灵通验证
function CheckPhone(obj)
{        
    var isSuccess=false;
    
    var mobile=document.getElementById(obj).value;
    mobile=Trim(mobile);
    var mobileReg=/^(\+?86)?1(3[0-35-9]\d|34[0-8]|5\d{2}|8[05-9]\d)\d{7}$/;
    var xiaoLingTongReg=/^((\+?86)|((\+?86)?(106)?0))(87\d|88[36-8]|69[12])[1-9]\d{6}$/;        
    
    /*
     *首先匹配手机
     * 前面可以为86或者+86或者没有
     * 号段匹配：
     * 13：除了1349（中国卫通，不属于手机号段）
     * 15：全号段匹配 15
     * 18：180（电信），185，186（联通）,187,188（移动）,189（电信）
     */
    if(mobileReg.test(mobile))
    {            
        isSuccess=true;   
        //赋值，取右边的11位手机号码         
        document.getElementById(obj).value=mobile.substring(mobile.length-11,mobile.length);            
    }
    else
    {
        /*
         * 小灵通匹配,云南省区号：0691西双版纳，0692德宏
         * 0870昭通，0871昆明，0872大理，0873红河，0874曲靖，0875保山，0876文山，0877玉溪，0878楚雄，0879普洱
         * 0883临沧，0886怒江，0887迪庆，0888丽江
         * 匹配模式868711234567,8608711234567,8610608711234567,10608711234567,08711234567,86前面的+可有可无
         */
        if(xiaoLingTongReg.test(mobile))
        {                             
            isSuccess=true;
            //0+右边的10位小灵通号码
            document.getElementById(obj).value="0"+mobile.substring(mobile.length-10,mobile.length);                
        }            
    }
    
    if(!isSuccess)
    {
        alert("请输入正确的手机或者小灵通号码！");
        document.getElementById(obj).focus();
        
    }
    return isSuccess;
}

//验证邮箱
function CheckEmail(obj)
{
    var isSuccess=false;
    
    var Email=document.getElementById(obj).value;
    Email=Trim(Email);

    var emailReg=/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    
    if(emailReg.test(Email))
    {            
        isSuccess=true; 
    }
    else
    {
        alert("请输入正确的邮箱！");
        document.getElementById(obj).focus();
    }
    return isSuccess;
}

function showdiv(divid,iframeid,url)
{    
    document.getElementById(iframeid).src = "";                  
    document.getElementById(iframeid).src = url;
    
    var box = document.getElementById(divid);
         
    box.style.display = "";
    var pageSize = getPageSize();
    var size = getElementSize(box);
    box.style.left = (pageSize.windowWidth-size.width)/2 + "px";
    box.style.top = scroll_top() + (pageSize.windowHeight-size.height)/2 + "px";
    
    document.getElementById("BGDiv").style.width = pageSize.pageWidth + "px";
    document.getElementById("BGDiv").style.height = pageSize.pageHeight + "px";
    document.getElementById("BGDiv").style.display = "";
        
        
        
}
function divclose(divid)
{
    document.getElementById(divid).style.display = "none";
    document.getElementById("BGDiv").style.display = "none";
}

function onlineshowdiv(divid,iframeid,url)
{             
        document.getElementById(iframeid).src = url;
        
        var box = document.getElementById(divid);
             
        box.style.display = "";
        
        if(url == "onlinelogin.aspx")
        {
            box.style.height='180px';
            box.style.width='240px';
            document.getElementById(iframeid).height='180px';
            document.getElementById(iframeid).width='240px';
        }
        else if(url == "onlineregister.aspx")
        {
            box.style.height='320px';
            box.style.width='270px';
            document.getElementById(iframeid).height='320px';
            document.getElementById(iframeid).width='270px';
        }
        else if(url == "modifymember.aspx")
        {
            box.style.height='360px';
            box.style.width='280px';
            document.getElementById(iframeid).height='360px';
            document.getElementById(iframeid).width='280px';
        }
        
        var pageSize = getPageSize();
        var size = getElementSize(box);
        box.style.left = (pageSize.windowWidth-size.width)/2 + "px";
        box.style.top = scroll_top() + (pageSize.windowHeight-size.height)/2 + "px";
        
        document.getElementById("BGDiv").style.width = pageSize.pageWidth + "px";
        document.getElementById("BGDiv").style.height = pageSize.pageHeight + "px";
        document.getElementById("BGDiv").style.display = "";       
}

function onlinedivclose(divid,iframeid)
{
    document.getElementById(iframeid).src = "";
    document.getElementById(divid).style.display = "none";
    document.getElementById("BGDiv").style.display = "none";
}

function getPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY){
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } 
    else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } 
    else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if(self.innerHeight) { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } 
    else if(document.documentElement && document.documentElement.clientHeight){ // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } 
    else if(document.body){ // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } 
    else{
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport 
    if(xScroll < windowWidth){ 
        pageWidth = xScroll; 
    } 
    else{ 
        pageWidth = windowWidth; 
    } 
    
    return {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight};
}


function getElementSize(element){
    if(element.clientWidth){
        return {width:element.clientWidth,height:element.clientHeight};
    }
    if(element.style.width){
        return {width:parseInt(element.style.width),height:parseInt(element.style.height)};
    }
    if(element.currentStyle){
        return {width:element.currentStyle.width,height:element.currentStyle.height};
    }
    if(document.defaultView && document.defaultView.getComputedStyle){
        return {width:document.defaultView.getComputedStyle(element,"").getPropertyValue("width"),
                height:document.defaultView.getComputedStyle(element,"").getPropertyValue("height")};
    }
}

function scroll_top(){    
    var scrollPos;    
    if (typeof window.pageYOffset != 'undefined') {    
         scrollPos = window.pageYOffset;    
     }    
    else if (typeof document.compatMode != 'undefined' &&    
         document.compatMode != 'BackCompat') {    
         scrollPos = document.documentElement.scrollTop;    
     }    
    else if (typeof document.body != 'undefined') {    
         scrollPos = document.body.scrollTop;    
     }    
    return scrollPos;    
}

function Importprovince(nProvince, district) 
{
      var i;
      var maxnum;
      var iIndexNumber;
      maxnum = province.length;
      document.form1.selectpc.length = 0;
      for (i=0;i< maxnum;i++)
      {
		    document.form1.selectpc.options[i] = new Option(provincename[i],province[i]);
//				    new Option(provincename[i],province[i]);
		    if(province[i]==nProvince){
			    document.form1.selectpc.options[i].selected = true;
				
			    iIndexNumber = i;
		    }
		    else{
			    iIndexNumber = 0;
		    }
      };
      document.form1.pc[0].checked = true;
      //Changedistrict(nProvince, district);							
}


function Importcountry(nCountry, district) 
{
	 
      var i;
      var maxnum;
      maxnum = country.length;
      document.form1.selectpc.length = 0;
      for (i=0;i< maxnum;i++){
		    document.form1.selectpc.options[i] = new Option(countryname[i],country[i]);
//				    new Option(countryname[i],country[i]);
		    if(country[i]==nCountry)
			    document.form1.selectpc.options[i].selected=true;
      };
      document.form1.pc[1].checked = true;
      //Changedistrict(nCountry, district);
}


function Changedistrict(arg, district) 
{
    var i;
    var maxnum;
    var numProvince;
    document.form1.district.length = 0
	
    switch(arg)
    {
	    case "0":	//所有
		    document.form1.district.options[0] = new Option('所有景区','所有景区');
		    break;
	    case "-1":	//其他
		    document.form1.district.options[0] = new Option('所有景区','所有景区');
		    break;
	    default:
		    if (document.form1.pc[0].checked)
		    {
			    maxnum = districtprovince[arg].length;		
			    for (i=0;i< maxnum;i++){
				    document.form1.district.options[i] = new Option(districtname[districtprovince[arg][i]],districtname[districtprovince[arg][i]]);
//						    new Option(districtname[districtprovince[arg][i]],districtid[districtprovince[arg][i]]);
				    if(districtid[districtprovince[arg][i]]==district)
					    document.form1.district.options[i].selected = true;
			    }
		    }
		    else
		    {
			    maxnum = districtcountry[arg].length;
			    for (i=0;i< maxnum;i++) {
				    document.form1.district.options[i] = new Option(districtname[districtcountry[arg][i]],districtname[districtcountry[arg][i]]);
//						    new Option(districtname[districtcountry[arg][i]],districtid[districtcountry[arg][i]]);
				    if(districtid[districtcountry[arg][i]]==district)
					    document.form1.district.options[i].selected = true;
			    }
		    }
     }
}

function isNumber(oNum) 
{ 
    if(!oNum) return false; 
    var strP=/^\d+(\.\d+)?$/; 
    if(!strP.test(oNum)) return false; 
    try{ 
    if(parseFloat(oNum)!=oNum) return false; 
    } 
    catch(ex) 
    { 
        return false; 
    } 
    return true; 
} 


function getObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) 
    {    	
        return document.getElementById(objectId);
    } 
    else if (document.all && document.all(objectId)) 
    {
        return document.all(objectId);
    } 
    else if (document.layers && document.layers[objectId]) 
    {
        return document.layers[objectId];
    } 
    else 
    {
        return false;
    }
}