﻿
var tripxcrsdefault=new TripxCrsDefaultOpr();
function TripxCrsDefaultOpr()
{
	this.xmlHttp=new TripX.Ajax.XmlHttp();
	this.xmlHttpRecommend=new TripX.Ajax.XmlHttp();
	this.xmlHttpPublishInfo = new TripX.Ajax.XmlHttp();
	this.xmlHttpCity=null;
	this.$=function(id){return document.getElementById(id);}	
	this.initialLogin=function(nameid,pwdid,loginid,userinfoid,unameid,ulevelid,checkcodeid)
	{
		this.nameid=nameid;	
		this.pwdid=pwdid;
		this.loginid=loginid;
		this.userinfoid=userinfoid;
		this.unameid=unameid;
		this.ulevelid=ulevelid;
		this.checkcodeid=checkcodeid;		
		this.appendEnterEvent(this.nameid,this.login);
		this.appendEnterEvent(this.pwdid,this.login);
		this.appendEnterEvent(this.checkcodeid,this.login);
	};
	this.appendEnterEvent=function(txtid,presshandler)
	{
		var me=this;
		document.getElementById(txtid).onkeypress=function(e)
		{
			var et=e?e:window.event
			if(et.keyCode==13){				
				presshandler.call(me);return false;
			}			
		};
	};	
	this.initialRecommend=function(recommendid,recommendcityid)
	{
		this.recommendid=recommendid;
		this.recommendcityid=recommendcityid;
		var rcity=this.$(this.recommendcityid);	
		/*	
		rcity.onchange=function()
		{
			var city=getSelectOptionValue(rcity);
			if(city)
			{
				if(city!="-1")
				{					
					tripxcrsdefault.getRecommendInfo(city);
				}
			}
		};
		*/			
	};
	this.refreshRecommend=function()
	{
		var city=this.$(this.recommendcityid+"_hfCityValue").value;
		if(city)
		{
			tripxcrsdefault.getRecommendInfo(city);
		}
	};
	this.refreshPublishInfo=function()
	{		
		var city=this.$(this.publishcityid+"_hfCityValue").value;
		if(city)
		{
			tripxcrsdefault.getPublishInfo(city);
		}
	};
	this.initialPublishInfo = function(containerID, citySelectorID)
	{
	    this.PublishInfoContainerID = containerID;
		var citySelector=this.$(citySelectorID);
		this.publishcityid=citySelectorID;
		/*
		citySelector.onchange=function()
		{
			var city=getSelectOptionValue(citySelector);
			if(city)
			{
				if(city!="-1")
				{					
					tripxcrsdefault.getPublishInfo(city);
				}
			}
		}
		*/
	}
	
	this.resetLoginfo=function(fieldid)
	{
		var loginfo=this.$(fieldid);
		if(loginfo.value!="")
		{
			this.setLoginfo(loginfo.value);
		}
	};
	this.checklogin=function()
	{
		if(this.$(this.nameid).value==""||this.$(this.pwdid).value=="")
		{
			//alert("用户名密码不能为空!");
			tripxcrslan.showMsgInfo("用户名密码不能为空!,User ID and password can not be empty,用戶名密碼不能為空！");

			return false;
		}	
		if(this.checkcodeid)
		{
			if(this.$(this.checkcodeid).value=="")
			{
				//alert("验证码不能为空!");
				tripxcrslan.showMsgInfo("验证码不能为空!,Secure code can not be empty,驗證碼不能為空!");
				return false;
			}
		}
		return true;
	};
	this.login=function()
	{
		if(!this.checklogin())
		{
			return;
		}	
		var userName=this.$(this.nameid).value;
		var password=this.$(this.pwdid).value;
		var checkcode="";
		if(this.checkcodeid)
		{
			checkcode=this.$(this.checkcodeid).value;
		}
		/*
		this.xmlHttp.Method = "post";
    	this.xmlHttp.IsSync = false;
    	this.xmlHttp.Url = "Default.aspx/youarepeeper";
    	this.xmlHttp.OnSucceed = "tripxcrsdefault.sucLogin()";
    	this.xmlHttp.OnFailed = "tripxcrsdefault.faiLogin()";
    	this.xmlHttp.Content = "user=" + userName + "&password=" + password+"&checkcode="+checkcode;
    	this.xmlHttp.Request();
    	*/
    	this.$("txtName").value=userName;
    	this.$("txtPwd").value=password;
    	this.$("txtAuthCode").value=checkcode;
    	this.$("loginsubmit").click();
	};
	this.sucLogin=function()
	{		
		var result=this.xmlHttp.ResponseText;
		if(result.charAt(0)=="1")
		{
			/*
			this.setLoginfo(result.substring(2,result.length));
			this.$("hideloginfo").value=result.substring(2,result.length);
			tripxshoppingcart.reloadData();
			this.getLoginLabel();
			*/
			//open( window.location,"_self","",true)
			//var str3 = window.location.href;			
        	//str3.indexOf("#") > 0 ? window.location.assign(str3.substr(0, str3.indexOf("#"))) : window.location.assign(str3);
        	window.location.reload();
		}
		else
		{
			alert(result.substring(2,result.length));			
			var url=this.$("imgCheckCode").src;
			if(url.split('?').length==1)
			{
				this.$("imgCheckCode").src=url+"?index=1";
			}
			else
			{
				var parms=url.split('?')[1].split('=');
				if(parms.length==2)
				{
					var index=parseInt(parms[1])+1;
					this.$("imgCheckCode").src=url.split('?')[0]+'?index='+index;
				}
			}	            
            if (this.checkcodeid) {
                this.$(this.checkcodeid).value="";
            }
		}	
	};
	this.faiLogin=function()
	{
		alert("failed"+this.xmlHttp.ResponseText);
	};
	this.getLoginLabel=function()
	{
		this.xmlHttplog=new TripX.Ajax.XmlHttp();
		this.xmlHttplog.Method = "post";
    	this.xmlHttplog.IsSync = true;
    	this.xmlHttplog.Url = "Default.aspx/GetLoginLabel";
    	this.xmlHttplog.OnSucceed = "tripxcrsdefault.sucGetLogin()";
    	this.xmlHttplog.OnFailed = "tripxcrsdefault.faiGetLogin()";
    	this.xmlHttplog.Content = "";
    	this.xmlHttplog.Request();
	};	
	this.sucGetLogin=function()
	{		
		var result=this.xmlHttplog.ResponseText;		
		this.$("CtrlHeader_lbtnHeaderLogOut").innerHTML=result;
	};
	this.faiGetLogin=function()
	{
		
	}
	this.setLoginfo=function(loginfo)
	{
		var strs=loginfo.split('*');		
		this.$(this.unameid).innerHTML=tripxcrslan.getMsgInfo("您好,hello,您好")+","+strs[0];
		
		this.$(this.ulevelid).innerHTML=tripxcrslan.getMsgInfo("您的会员等级是:,your level is:,您的會員等級是:")+strs[1]; 
		
		this.$(this.loginid).style.display="none";     
		this.$(this.userinfoid).style.display="block";
	};
	this.getRecommendInfo=function(city)
	{
		this.xmlHttpRecommend.Method="post";
		this.xmlHttpRecommend.IsSync=true;
		this.xmlHttpRecommend.Url="default.aspx/GetRecommendInfo";
		this.xmlHttpRecommend.OnSucceed="tripxcrsdefault.sucGetRecommend();";
		this.xmlHttpRecommend.OnFailed="tripxcrsdefault.faiGetRecommend()";
		this.xmlHttpRecommend.Content="city="+city;
		this.xmlHttpRecommend.Request();
	};
	this.sucGetRecommend=function()
	{
		var result=this.xmlHttpRecommend.ResponseText;		
		this.$(this.recommendid).innerHTML=result;
	};
	this.faiGetRecommend=function()
	{
	};
	
	this.getPublishInfo = function(city)
	{
		this.xmlHttpPublishInfo.Method="post";
		this.xmlHttpPublishInfo.IsSync=true;
		this.xmlHttpPublishInfo.Url="default.aspx/GetPublishInfo";
		this.xmlHttpPublishInfo.OnSucceed="tripxcrsdefault.sucGetPublishInfo();";
		this.xmlHttpPublishInfo.OnFailed="tripxcrsdefault.faiGetPublishInfo()";
		this.xmlHttpPublishInfo.Content="city="+city;
		this.xmlHttpPublishInfo.Request();
	}
	this.sucGetPublishInfo = function()
	{
		var result=this.xmlHttpPublishInfo.ResponseText;		
		this.$(this.PublishInfoContainerID).innerHTML=result;
	}
	this.faiGetPublishInfo = function()
	{
	}
	
	this.initialFlightSearch=function(traveltypeid,departureid,departuredateid,arrivalid,returndatedtid,returndateid)
	{
		this.traveltypeid=traveltypeid;
		this.departureid=departureid;
		this.departuredateid=departuredateid;
		this.arrivalid=arrivalid;
		this.returndatedtid=returndatedtid;
		this.returndateid=returndateid;
		this.$(this.traveltypeid).onchange=new Function("tripxcrsdefault.setFlightTravelType();");
		this.setFlightCountryType();
	 	document.getElementById("dlstSearchType").onchange=this.setFlightCountryType;		
	};
	this.setFlightTravelType=function()
	{
		var traveltype=this.$(this.traveltypeid);
		var traveltypevalue=getSelectOptionValue(traveltype);
		if(traveltypevalue=="01")
		{
			this.$(this.returndatedtid).style.display="none";
			this.$(this.returndateid).style.display="none";
		}
		else{
			this.$(this.returndatedtid).style.display="";
			this.$(this.returndateid).style.display="";			
		}
	};	
	this.checkFlightSearch=function()
	{		
		//if(!getSelectOptionValue(this.$(this.departureid)))
		if(this.$(this.departureid+"_hfCityValue").value=="")
		{
			//alert("出发城市不能为空!");
			tripxcrslan.showMsgInfo("出发城市不能为空!,please select departure city!,出發城市不能為空!");
			return false;
		}
		//if(!getSelectOptionValue(this.$(this.arrivalid)))
		if(this.$(this.arrivalid+"_hfCityValue").value=="")
		{
			//alert("到达城市不能为空!");
			tripxcrslan.showMsgInfo("到达城市不能为空!,please select arrive city!,到達城市不能為空!");
			return false;
		}
		if(!tripxcrstoolkit.checkDate(this.$(this.departuredateid).value))
		{
			//alert("请输入正确的出发日期!");
			tripxcrslan.showMsgInfo("请输入正确的出发日期!,please input correct departure date!,請輸入正確的出發日期!");
			return false;
		}
		var traveltype=this.$(this.traveltypeid);
		var traveltypevalue=getSelectOptionValue(traveltype);
		if(traveltypevalue=="02")
		{
			if(!tripxcrstoolkit.checkDate(this.$(this.returndateid).value))
			{
				//alert("请输入正确的返程日期!");
				tripxcrslan.showMsgInfo("请输入正确的返程日期!,please input correct return date!,請輸入正確的返程日期!");
				return false;
			}
		}
		return true;
	};
	this.initialHotelSearch=function(hotelcityid,checkindateid,checkoutdateid)
	{
		this.hotelcityid=hotelcityid;
		this.checkindateid=checkindateid;
		this.checkoutdateid=checkoutdateid;
	};
	this.checkHotelSearch=function()
	{
		//if(!getSelectOptionValue(this.$(this.hotelcityid)))
		if(this.$(this.hotelcityid+"_hfCityValue").value=="")
		{
			//alert("所在城市不能为空!");
			tripxcrslan.showMsgInfo("所在城市不能为空!,please select a city!,所在城市不能為空!");
			return false;
		}
		if(!tripxcrstoolkit.checkDate(this.$(this.checkindateid).value))
		{
			//alert("请输入正确的入住日期!");
			tripxcrslan.showMsgInfo("请输入正确的入住日期!,please input correct check in date!,請輸入正確的入住日期!");
			return false;
		}
		if(!tripxcrstoolkit.checkDate(this.$(this.checkoutdateid).value))
		{
			//alert("请输入正确的离店日期!");
			tripxcrslan.showMsgInfo("请输入正确的离店日期!,please input correct check out date!,請輸入正確的離店日期!");
			return false;
		}
		return true;
	};
	this.checkTravelSearch=function()
	{
		if(this.$("dlstDepart_hfCityValue").value=="")
		{
			//alert("出发城市不能为空!");
			tripxcrslan.showMsgInfo("出发地不能为空!,please select a from city!,出發地不能為空!");
			return false;
		}
		return true;
	};
	this.initialTipsSearch=function(tipsdepartureid,tipsdeparturedateid,tipsarrivalid,tipsarrivaldateid,tipstraveldaysid,tipsadultid,tipschildid,tipsbudgetid)
	{
		this.tipsdepartureid=tipsdepartureid;
		this.tipsdeparturedateid=tipsdeparturedateid;
		this.tipsarrivalid=tipsarrivalid;
		this.tipsarrivaldateid=tipsarrivaldateid;
		this.tipstraveldaysid=tipstraveldaysid;
		this.tipsadultid=tipsadultid;
		this.tipschildid=tipschildid;
		this.tipsbudgetid=tipsbudgetid;
	};
	this.checkTipsSearch=function()
	{
		//if(!getSelectOptionValue(this.$(this.tipsdepartureid)))
		if(this.$(this.tipsdepartureid+"_hfCityValue").value=="")
		{
			//alert("出发城市不能为空!");
			tripxcrslan.showMsgInfo("出发城市不能为空!,please input select a departure city!,出發城市不能為空!");
			return false;
		}
		//if(!getSelectOptionValue(this.$(this.tipsarrivalid)))
		if(this.$(this.tipsarrivalid+"_hfCityValue").value=="")
		{
			//alert("到达城市不能为空!");
			tripxcrslan.showMsgInfo("到达城市不能为空!,please input select a arrive city!,到達城市不能為空!");
			return false;
		}
		if(!tripxcrstoolkit.checkDate(this.$(this.tipsdeparturedateid).value))
		{
			//alert("请输入正确的出发日期!");
			tripxcrslan.showMsgInfo("请输入正确的出发日期!,please input correct departure date!,請輸入正確的出發日期!");
			return false;
		}
		if(!tripxcrstoolkit.checkDate(this.$(this.tipsarrivaldateid).value))
		{
			//alert("请输入正确的到达日期!");
			tripxcrslan.showMsgInfo("请输入正确的到达日期!,please input correct arrive date!,請輸入正確的到達日期!");
			return false;
		}
//		if(!tripxcrstoolkit.checkInt(this.$(this.tipstraveldaysid).value,true))
//		{
//			alert("请输入正确的旅行天数!");
//			return false;
//		}
		if(!tripxcrstoolkit.checkInt(this.$(this.tipsadultid).value,true))
		{
			//alert("请输入正确的人数!");
			tripxcrslan.showMsgInfo("请输入正确的人数!,please input person number!,請輸入正確的人數!");
			return false;
		}
//		if(!tripxcrstoolkit.checkInt(this.$(this.tipschildid).value,true))
//		{
//			alert("请输入正确的儿童数!");
//			return false;
//		}
		if(!tripxcrstoolkit.checkInt(this.$(this.tipsbudgetid).value,true))
		{
			//alert("请输入正确的预算金额!");
			tripxcrslan.showMsgInfo("请输入正确的预算金额!,please input your budget!,請輸入正確的預算金額!");
			return false;
		}
		return true;
	};
	this.getCity=function(splitcc,splitnv,cityids)
	{
		if(cityids && cityids.length>0)
		{
			this.splitcc=splitcc;
			this.splitnv=splitnv;
			this.cityids=cityids;
			this.xmlHttpCity=new TripX.Ajax.XmlHttp();
			this.xmlHttpCity.Method = "post";
   			this.xmlHttpCity.IsSync = true;
    		this.xmlHttpCity.Url = "default.aspx/GetCitys";    
   			this.xmlHttpCity.OnSucceed="tripxcrsdefault.sucGetCity();";
			this.xmlHttpCity.OnFailed="tripxcrsdefault.failGetCity();";
    		this.xmlHttpCity.Content ="";
			this.xmlHttpCity.Request();	
		}			
	};
	this.sucGetCity=function()
	 { 	
 		var result=this.xmlHttpCity.ResponseText;	
		var citys=new Array();
		var dds=result.split(this.splitcc);
		for(var i=0;i<dds.length;i++)
		{
			var nvs=dds[i].split(this.splitnv);
			if(nvs.length==2)
			{
				citys.push(new HotelCity(nvs[0],nvs[1]));
			}
		}	
		//this.addOptions(this.c,citys);	
		for(var i=0;i<this.cityids.length;i++)	
		{
			var citylist=this.$(this.cityids[i]);
			if(citylist)
			{
				this.addOptions(citylist,citys);
			}			
		}
 	};
	this.failGetCity=function()
 	{
 		
 	};
	this.addOptions=function(select,objects)
 	{
 		if(objects)
		{
			if(objects.length>0)
			{
				for(var i=0;i<objects.length;i++)
    			{
        			addSelectOption(select,objects[i].name,objects[i].value);
    			}	
			}			
		}        
 	};
    this.setFlightCountryType = function(){
         var countryType = document.getElementById("dlstSearchType");
         if (countryType) {
             var passengerType = document.getElementById("dlstPassengerType");
             if (passengerType) {
                 var ctype = getSelectOptionValue(countryType);
                 clearSelectOptions(passengerType);
                 if (ctype == "1") {
                     addSelectOption(passengerType, tripxcrslan.getMsgInfo("成人,Adult,成人"), "0");
                     addSelectOption(passengerType, tripxcrslan.getMsgInfo("儿童,Child,兒童"), "1");
                 }
                 else {
                     addSelectOption(passengerType, tripxcrslan.getMsgInfo("成人,Adult,成人"), "0");
                 }
             }
             var leavecity = document.getElementById("dlstDeparture1_tbCity");
             var arrivecity = document.getElementById("dlstDestination1_tbCity");
             if (leavecity && arrivecity) {
                 if (ctype == "1") {
                     leavecity.setAttribute("country", "1");
                     arrivecity.setAttribute("country", "1");
                 }
                 else {
                     leavecity.setAttribute("country", "3");
                     arrivecity.setAttribute("country", "3");
                 }
             }
			 airlinesetter.setAirline();
         }
     };
	 this.setFlightAirline=function(){
	 	var countryType = document.getElementById("dlstSearchType");
        if (countryType) {
			
		}
	 };	 
}
 /*
 *HotelCity
 */
 function HotelCity(name,value)
 {
    this.name=name;
    this.value=value;
    this.districts=new Array();
 };
 
 function AirlineSet(varName,dlstSearchType, lstairlineid){ 	 
     var countryType = document.getElementById(dlstSearchType);
     if (countryType) {
	 	//countryType.onchange=setAirline;
		//setAirline();         
     };
     this.setAirline=function(){     
         var ctype = getSelectOptionValue(countryType);
         if (ctype == "1") {
             getAirline("1");
         }
         else {
             getAirline("0");
         }         
     };
	 var xmlHttpAirline;
	 function getAirline(countryType){
	 		xmlHttpAirline=new TripX.Ajax.XmlHttp();
			xmlHttpAirline.Method = "post";
   			xmlHttpAirline.IsSync = true;
    		xmlHttpAirline.Url = "/crs/flight/FlightServ.aspx/GetAirlines";    
   			xmlHttpAirline.OnSucceed=varName+ ".sucGetAirlines();";
			xmlHttpAirline.OnFailed=varName+".failGetAirlines();";
    		xmlHttpAirline.Content ="countryType="+countryType;
			xmlHttpAirline.Request();
	 };
	 this.sucGetAirlines=function(){
	 	var str=xmlHttpAirline.ResponseText;		
		var lstairline=document.getElementById(lstairlineid);
		if(lstairline){
			clearSelectOptions(lstairline);
			var lines=str.split("$$");
			for(var i=0;i<lines.length;i++){
				var line=lines[i];
				var nv=line.split("||");
				if(nv.length==2){
					addSelectOption(lstairline,nv[1],nv[0]);
				}
			}
		}
	 };
	 this.failGetAirlines=function(){
	 	
	 };
 };

