var xmlDoc;
function PostRequestData(URL,data){
	
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.Open("POST",URL, false);
    xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=GB2312");       
  //  xmlhttp.SetRequestHeader ("SOAPAction","http://tempuri.org/"+method);       
    try {       
        xmlhttp.Send(data);               
        var result = xmlhttp.status;             
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xmlhttp.responseText);			
		
		xmlDoc.async="false";
		xmlDoc.loadXML(xmlhttp.responseText);//alert(xmlhttp.responseText);
	
    }
    catch(ex) {
            return("0" + ex.description + "|" + ex.number); 
    }
    if(result==200) { 
            return("1" + xmlhttp.responseText); 
    }
    xmlhttp = null;
}

function ReadXml(TagName,i)
{	
	if (xmlDoc.getElementsByTagName(TagName).item(i)==null)
	{
		return null;
	}
	else
	{
		return (xmlDoc.getElementsByTagName(TagName).item(i).text);
	}
}

//add by wangxz for CommonJS
//function $() {
	//var elements = new Array();

	//for (var i = 0; i < arguments.length; i++) {
		//var element = arguments[i];
		//if (typeof element == 'string')
		//element = document.getElementById(element);

		//if (arguments.length == 1)
		//return element;

		//elements.push(element);
	//}

	//return elements;
//}

String.prototype.Trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");  
}


function CheckFileFormat(control)
{
	var fullPath = control.value;
	var FileExtend = fullPath.substring(fullPath.lastIndexOf("."));
	if ((FileExtend.toLowerCase() != "") && (FileExtend.toLowerCase() != ".jpg") && (FileExtend.toLowerCase() != ".jpeg") && (FileExtend.toLowerCase() != ".bmp") && (FileExtend.toLowerCase() != ".gif") )
	{
	//alert(FileExtend);
		alert("上传的图片格式必须为.jpg，.jpeg，.bmp，.gif其中之一！");
		//control.innerText = "";
		control.focus();
	}
	
}

function TrucHtmlStrToCommStr( vu_Des )
{
	var vu_br = /<br>/gi;
	var vu_space = /&nbsp;/gi;
	vu_Des = vu_Des.replace(vu_br, "\r\n");
	vu_Des = vu_Des.replace(vu_space, " ");
	
	return vu_Des;
}

function __doPostBack_Ex(eventTarget, eventArgument) 
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.forms[0];
	}

	if(!theform.__EVENTTARGET)
	{            
		try
        {
            theform.appendChild(document.createElement("<input type='hidden' name='__EVENTTARGET'>"));
        }
        catch(e)
        {
            var objinput1=document.createElement('input');
            objinput1.setAttribute('name','__EVENTTARGET');
            objinput1.setAttribute('type','hidden');  
            theform.appendChild(objinput1);          
        }
	}
	
	if(!theform.__EVENTARGUMENT)
	{            
		try
        {
            theform.appendChild(document.createElement("<input type='hidden' name='__EVENTARGUMENT'>"));
        }
        catch(e)
        {
            var objinput2=document.createElement('input');
            objinput2.setAttribute('name','__EVENTARGUMENT');
            objinput2.setAttribute('type','hidden');  
            theform.appendChild(objinput2);          
        }                        
	}
	
	theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
	theform.__EVENTARGUMENT.value = eventArgument;
	
	if ((typeof(theform.onsubmit) == "function")) 
	{
		if(theform.onsubmit()!=false)
		{
			theform.submit();    
		}
	}
	else
	{            
		theform.submit();    
	}
	
	function __doPostBack(eventTarget, eventArgument)
	{
		__doPostBack_Ex(eventTarget, eventArgument);
    }
}
//机票JS控制页面跳转
function FlightPageTransfer(url){
    window.location = url;
}
function FlightPageOpen(url){
    window.open(url);
}


//获取位置
function PointsPos(el, ePro) {
    var ePos = 0;
    while (el != null) {
        
        ePos += el["offset" + ePro];
        el = el.offsetParent;
    }
    
    return ePos;
}

/**
*页面数据验证类
**/
function MyReg()
{
	this.EMailReg =  /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
	this.MobileReg = /^1[0-9]{10}$/;
	this.PhoneReg = /^\d{3}-\d{8}|\d{4}-\d{7}$/;/*/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;*/
	this.DateReg = /^[0-9]{4}-(0[1-9]|[1-9]|1[0-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1])$/;
	this.DecimalReg = /^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$/;
	this.IntReg = /^[1-9]\d*|0$/;
	this.PostcodeReg = /^\d{6}$/;
	this.LongDateReg = /^[0-9]{4}-(0[1-9]|[1-9]|1[0-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1]) (\d{1,2}):(\d{1,2})$/;
	this.CNReg = /^([\u0391-\uFFE5])+$/;
	this.PersonNameReg =  /^([A-Za-z]|[\u0391-\uFFE5])+$/;	//人名验证
	this.XLTReg = /^0[1-9]\d{1,2}[1-9]\d{6,7}$/;
	
	this.ValidLongDate = function( testLongDate )
	{
		if (this.LongDateReg.test( testLongDate))
			return true;
		else
			return false;
	}
	//儿童年龄验证[>=2周岁<12周岁]
	this.ValidChildAge = function( testAge )
	{
		if (this.ValidInt(testAge))
		{
			var nAge = parseInt( testAge );
			if ((nAge >= 12) || (nAge < 2))
				return false;
			else
				return true;
		}
		else
			return false;
	}
	
	//婴儿出生日期验证[小于2周岁]
	this.ValidBabyBirth = function( testBabyBirth )
	{
		if (this.ValidDate( testBabyBirth ))
		{
			var curDate = new Date();
			var strCurDate = curDate.getFullYear() + "-" + (curDate.getMonth()+1)+"-"+curDate.getDate()
			var strLimitDate = (curDate.getFullYear()-2)+"-01-01";
			//出生日期大于当前或婴儿大于3岁
			if (this.CompareDate(testBabyBirth, strCurDate) || (this.CompareDate(strLimitDate, testBabyBirth))) 
				return false;
			else
				return true;
		}
		else
			return false;
	}
	
	//日期比较，如DateOne>DateTwo则返回true,否则返回false
	this.CompareDate = function( DateOne, DateTwo )
	{
		var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ("-"));
		var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ("-")+1);
		var OneYear = DateOne.substring(0,DateOne.indexOf ("-"));

		var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ("-"));
		var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ("-")+1);
		var TwoYear = DateTwo.substring(0,DateTwo.indexOf ("-"));

		if (Date.parse(OneMonth+"/"+OneDay+"/"+OneYear) >
		Date.parse(TwoMonth+"/"+TwoDay+"/"+TwoYear))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	this.ValidInt = function(testInt)
	{
		if (this.IntReg.test(testInt))
			return true;
		else
			return false;
	}
	
	this.ValidDecimal = function(testDecimal)
	{
		if (this.DecimalReg.test(testDecimal))
			return true;
		else
			return false;
	}
	
	this.ValidPostcode = function( testPostcode )
	{
		if (this.PostcodeReg.test(testPostcode))
			return true;
		else
			return false;
	}
	
	this.ValidEMail=function(testEmail)
	{
		if (this.EMailReg.test(testEmail))
			return true;
		else
			return false;
	}

	this.ValidMobile = function(testMobile)
	{
		if (this.MobileReg.test(testMobile))
			return true;
		else
			return false;
	}

	this.ValidPhone = function(testPhone)
	{
		if (this.PhoneReg.test(testPhone))
			return true;
		else
			return false;
	}
	
	this.ValidXLT = function( tsetXLT )
	{
		if (this.XLTReg.test(tsetXLT))
			return true;
		else
			return false;
	}
	
	this.ValidDate = function(testDate)
	{
		if (this.DateReg.test(testDate))
			return true;
		else
			return false;
	}
	
	//人名的验证
	this.ValidPersonName = function( testPersonName )
	{
		if (this.PersonNameReg.test( testPersonName ))
			return true;
		else
			return false;
	}
	
	//汉字验证
	this.ValidChinese = function(testChinese)
	{
		if (this.CNReg.test(testChinese))
			return true;
		else
			return false;
	}
	
	//验证身份证
	this.checkSum = function( str )
	{
		var bln=true;
		if(str=="")
		{
			bln=false;
			return bln;
		}
			
		var stra=new String(str);
		for(i=0;i<stra.length;i++)
		{
			var a=stra.substr(i,1);
			if(!(a=="0" || a=="1" || a=="2" || a=="3" || a=="4" || a=="5" || a=="6" || a=="7" || a=="8" || a=="9"))
			{
				bln=false;
				break;
			} 
		}
		return bln;
	}
	this.ValidSFZ = function( sNo )
	{
		if(sNo.length!=18 && sNo.length!=15)
		{
			return false;
		}
	    if (sNo.length==18)
	    {
	       var a,b,c
	       if (!this.checkSum(sNo.substr(0,17))) {return false}
	       a=parseInt(sNo.substr(0,1))*7+parseInt(sNo.substr(1,1))*9+parseInt(sNo.substr(2,1))*10;
	       a=a+parseInt(sNo.substr(3,1))*5+parseInt(sNo.substr(4,1))*8+parseInt(sNo.substr(5,1))*4;
	       a=a+parseInt(sNo.substr(6,1))*2+parseInt(sNo.substr(7,1))*1+parseInt(sNo.substr(8,1))*6; 
	       a=a+parseInt(sNo.substr(9,1))*3+parseInt(sNo.substr(10,1))*7+parseInt(sNo.substr(11,1))*9; 
	       a=a+parseInt(sNo.substr(12,1))*10+parseInt(sNo.substr(13,1))*5+parseInt(sNo.substr(14,1))*8; 
	       a=a+parseInt(sNo.substr(15,1))*4+parseInt(sNo.substr(16,1))*2;
	       b=a%11;
	       if (b==2)
	       {
	          c=sNo.substr(17,1).toUpperCase();
	       }
	       else
	       {
	         c=parseInt(sNo.substr(17,1));
	       }
	       
	       switch(b)
	       {
	         case 0: if ( c!=1 ) {return false;}break;
	         case 1: if ( c!=0 ) {return false;}break;
	         case 2: if ( c!="X") {return false;}break;
	         case 3: if ( c!=9 ) {return false;}break;
	         case 4: if ( c!=8 ) {return false;}break;
	         case 5: if ( c!=7 ) {return false;}break;
	         case 6: if ( c!=6 ) {return false;}break;
	         case 7: if ( c!=5 ) {return false;}break;
	         case 8: if ( c!=4 ) {return false;}break;
	         case 9: if ( c!=3 ) {return false;}break;
	         case 10: if ( c!=2 ){return false}
	      }
	   }
	   else
	   {
	      if (!this.checkSum(sNo)) {return false} 
	   }
	   var B;
	   var year;
	   var month;
	   var day;
	    if (sNo.length==15)
        {
			year=parseInt(sNo.substr(6,2),10);
			month=parseInt(sNo.substr(8,2),10);
			day=parseInt(sNo.substr(10,2),10);
			var D = new Date("19"+year+"/"+month+"/"+day);
			B= D.getYear()==year&&(D.getMonth()+1)==month&&D.getDate()==day;
			
        }else if(sNo.length==18)
        {
			year=parseInt(sNo.substr(6,4),10);
			month=parseInt(sNo.substr(10,2),10);
			day=parseInt(sNo.substr(12,2),10);
			var D = new Date(year+"/"+month+"/"+day);
			B= D.getFullYear()==year&&(D.getMonth()+1)==month&&D.getDate()==day;
        }       
		if(!B)
			return false;
		else
			return true;
	}
}

reg = new  MyReg();
