﻿/*script document*/
/*
 * csair.com v0.1
 * http://csair.com/
 *
 * Copyright (c) 2009 csair.com
 *
 * @author Gangrock
 * 
 * Date: 2009-05-18 11:14:14 (GMT+08:00)
 * Revision: 1
 */
if(!thisUrl){
	var thisUrl=document.URL+window.location.search;
	//发布时需改此项
	if(thisUrl.indexOf('www.cs-air.com')>0){window.location.href=thisUrl.replace('www.cs-air.com','www.csair.com')}
	function webPath(url){var allstr="http://10.108.70.15:8081/"+url;return allstr}
}
 
/*常用函数定义*/
function g$(id){
	return document.getElementById(id);	
}
function $C(ele){
	return document.createElement(ele);	
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  //eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if(selObj.options[selObj.selectedIndex].value != ""){
  	window.open(selObj.options[selObj.selectedIndex].value);
  }
  if (restore) selObj.selectedIndex=1;
}
function clearchildnodes(parentnodenames){//清除节点所有子节点
		var parentnodes = g$(parentnodenames);
		var childnodecounts = parentnodes.childNodes.length;
		if(parentnodes.hasChildNodes()){
			for (i=0 ; i<childnodecounts;i++){
				parentnodes.removeChild(parentnodes.childNodes[0]);
			}
		}
}
function addCssClass(htmlEl,iclssName){//对元素添加class样式
	try{
    htmlEl.className += " "+iclssName;
	}catch(e){
		var iLoading = new loading("对"+htmlEl.className+"元素添加class样式时出错！",2);
	}
}
function delCssClass(htmlEl,iclssName){//对元素删除class样式
	try{
		var arrClassName = htmlEl.className.split(" ");
		for(i=0;i<arrClassName.length;i++){
			if(arrClassName[i] == iclssName){
				arrClassName.baoremove(i);
			}
		}
		var nowClassName ="";
		for(i=0;i<arrClassName.length;i++){
			nowClassName +=  arrClassName[i]+" ";	
		}
		htmlEl.className = nowClassName;
	}catch(e){
		var iLoading = new loading("对"+htmlEl.className+"元素删除class样式时出错！",2);
	}
}

/*数组方法*/
Array.prototype.baoremove = function(dx){
    if(isNaN(dx)||dx>this.length){return false;}
    this.splice(dx,1);
}
Array.prototype.append=function(obj,nobup){
	if(!(nobup && this.contacts(obj))){
		this[this.length]=obj;
	}
}
Array.prototype.contacts=function(obj){
	return (this.indexOf(obj)>=0);
}
Array.prototype.indexOf=function(obj){
	var results=-1;
	for(var i=0; i<this.length; i++ ){
		if(this[i]==obj){
		results = i;
		break;
		}
	}
	return results;
}

/*事件路由*/
var jsEvent=new Array();
jsEvent.EventRouter=function(el,evenType){
		this.lsnrs=new Array();
		this.el=el;
		el.eventRouter=this;
		el[evenType]=jsEvent.EventRouter.callback;
}
jsEvent.EventRouter.prototype.addListener=function(lsnr){
		this.lsnrs.append(lsnr,true);
}
jsEvent.EventRouter.prototype.removeListener=function(lsnr){
		this.lsnrs.remove(lsnr);
}
jsEvent.EventRouter.prototype.notify=function(e){
		var lsnrs=this.lsnrs;
		for(var i=0;i<lsnrs.length; i++){
			var lsnr=lsnrs[i];
			lsnr.call(this,e);
		}
}
jsEvent.EventRouter.callback=function(event){
		var e=event||window.event;
		var router=this.eventRouter;
		router.notify(e);
}

/* 提示窗口模块*/
function loading(textnotice,msgClass){
	this.textnotice = textnotice;
	this.msgClass = msgClass;
	
	var sWidth,sHeight;
	sWidth=document.body.offsetWidth;//浏览器工作区域内页面宽度
	sHeight=screen.height;//屏幕高度（垂直分辨率）
	cWidth = sWidth/2
	cHeight = sWidth/2
	
	
	if(!(g$("loadingId"))){
		var loadingDiv = document.createElement("div");
		loadingDiv.className = "loading";
		loadingDiv.id = "loadingId";
		loadingDiv.style.zIndex = 1;
		loadingDiv.innerHTML = this.textnotice;
		document.body.appendChild(loadingDiv);
		var loadingDiv = g$("loadingId");
		loadingDiv.style.left = cWidth -(loadingDiv.offsetWidth/2)+"px";
		loadingDiv.style.zIndex = 210;
		if(this.msgClass == 1){//成功后关闭
			
		}else if(this.msgClass == 2){//5秒后关闭提示窗口
			setTimeout("clearLoading()",5000);
		}else if(this.msgClass == 3){//用户确认后关闭提示窗口
			loadingDiv.style.paddingRight = "20px"
			var btnCloseLoading = document.createElement("span");
			btnCloseLoading.className="closeloading";
			btnCloseLoading.style.styleFloat  = "rihgt"; //for IE
		    btnCloseLoading.style.cssFloat  = "rihgt"; //for FF
			btnCloseLoading.id = "closeloading";
			var imgCloseLoading = document.createElement("span");
			imgCloseLoading.innerHTML = "X";
			imgCloseLoading.className = "";
			imgCloseLoading.title = "关闭";
			btnCloseLoading.appendChild(imgCloseLoading);
			loadingDiv.appendChild(btnCloseLoading);
			try{
				var EventEle=g$("closeloading");
				var mouseRouter=new jsEvent.EventRouter(EventEle,'onclick');
				mouseRouter.addListener(clearLoading);
			}catch(e){}
		}
	}
}
function clearLoading(){// clear loading div
		var loadingDiv = document.getElementsByTagName("div");
		for(var i = 0; i < loadingDiv.length; i++){
				if(loadingDiv[i].className.indexOf('loading')>=0){
					loadingDiv[i].parentNode.removeChild(loadingDiv[i]);
				}
		}
}

var XMLHttp = {
    _objPool: [],
    
    _getInstance: function (){
        for (var i = 0; i < this._objPool.length; i ++){
            if (this._objPool[i].readyState == 0 || this._objPool[i].readyState == 4){
                return this._objPool[i];
            }
        }
        
        // IE5中不支持push方法
        this._objPool[this._objPool.length] = this._createObj();

        return this._objPool[this._objPool.length - 1];
    },

    _createObj: function (){
        if (window.XMLHttpRequest){
            var objXMLHttp = new XMLHttpRequest();
			}else{
            var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
            for(var n = 0; n < MSXML.length; n ++){
                try{
                    var objXMLHttp = new ActiveXObject(MSXML[n]);        
                    break;
                }catch(e){
                }
            }
         }          
        
        // mozilla某些版本没有readyState属性
        if (objXMLHttp.readyState == null){
            objXMLHttp.readyState = 0;

            objXMLHttp.addEventListener("load", function (){
                    objXMLHttp.readyState = 4;
                    if (typeof objXMLHttp.onreadystatechange == "function"){
                        objXMLHttp.onreadystatechange();
                    }
                },  false);
        }

        return objXMLHttp;
    },
    
    // 发送请求(方法[post,get], 地址, 数据, 回调函数)
    sendReq: function (method, url, data, callback,EleId){
        var objXMLHttp = this._getInstance();

        with(objXMLHttp){
            try{
                // 加随机数防止缓存
                if (url.indexOf("?") > 0){
                    url += "&randnum=" + Math.random();
					//url += "&randnum=" + new Date().getHours();
                }else{
                    url += "?randnum=" + Math.random();
					//url += "?randnum=" + new Date().getHours();
                }

                open(method, url, true);
                
                // 设定请求编码方式
                setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
                send(data);
				var begintime = new Date().getTime();
                onreadystatechange = function (){             
					if(objXMLHttp.readyState == 4){
						if(objXMLHttp.status == 200 || objXMLHttp.status == 304){
							callback(objXMLHttp,EleId);
							//clearLoading();
						}else{
							//var iLoading = new loading("Loading...", 1);
							//var iLoading = new loading("看上去网络好像有问题,您可拨打南航95539电话订票.", 3);
						}
					}else{
						
					}
                }
            }catch(e){
                alert(e);
            }
        }
    }
};

/*创建包容器 wrapper*/
function wrapper(){
	var wpDiv = $C("div");
	wpDiv.id = "wrapper";
	return wpDiv;
}

/*设置格内容块位置*/
function setPosition(){
	var middler = g$("middlerId");
	var wpDiv = new wrapper();
	var hdDiv = new header();
	var ftDiv = new footer();
	if(!middler){
		middlerId = $C("div");
		addCssClass(conId,"middler");
		middlerId.id = "middlerId";
		addCssClass(middler,"clearfix");
		document.body.appendChild(middlerId);
		middler = g$("middlerId");
	}
	
	document.body.appendChild(wpDiv);
	var wrapperId = g$("wrapper");
	
	wrapperId.appendChild(hdDiv);
	wrapperId.appendChild(middler);
	wrapperId.appendChild(ftDiv);
	/*try{var islt = document.getElementById("login_id").contentWindow;
	//islt.document.getElementById("login").style.display = "";
	//islt.document.getElementById("loginform").style.display = "";
	}catch(e){}*/
}

function ioneway(){//机票预订
	g$("iInfo").innerHTML = "";
	g$("boutarea").style.display="none";
	//g$("moreline").style.display="none";
	g$("addon").disabled = "";
}
function ibout(){
	g$("iInfo").innerHTML = "";
	g$("boutarea").style.display="block";
	//g$("moreline").style.display="none";
	g$("return_d").innerHTML = "返回日期";
	g$("addon").disabled = "";		
}
function imoreline(){
	window.location.href="moreline.asp"
}

function GetObj(objName){/*Tab*/
if(document.getElementById){
return eval('document.getElementById("' + objName + '")');
}else if(document.layers){
return eval("document.layers['" + objName +"']");
}else{
return eval('document.all.' + objName);
}
}
function PARMenu(index,flag){
for(var i=0;i<5;i++){/*max-5*/
if(GetObj("content"+i)&&GetObj("PARm"+i)){
GetObj("content"+i).style.display = 'none';
GetObj("PARm"+i).className = "out";
}
}
if(GetObj("content"+index)&&GetObj("PARm"+index)){
GetObj("content"+index).style.display = 'block';
GetObj("PARm"+index).className = "active";
}
}

function addHTML(obj,EleId){//加载页面到Id为EleId元素内
	g$(EleId).innerHTML = obj.responseText;
}

function crtscpt(obj,EleId){//加载JS到页面head区域
	var iHead = document.getElementsByTagName('head')[0];
	var iScript = $C("script");
	iScript.language = "javascript";
	iScript.type = "text/javascript";
	iScript.id = EleId;
	iScript.defer = true;
	iScript.text = obj.responseText;
	iHead.appendChild(iScript);
}
function setPst(obj,EleId){//设置各内容快的位置
	//crtscpt(obj,EleId)
	//setPosition();
	if(g$("r_parameter").value!="y"){
		setDefaultTime('date1');
	}else{
		c1 = g$("r_city1").value;
		c2 = g$("r_city2").value;
		s1 = g$("s_city1").value;
		s2 = g$("s_city2").value;
		d1 = g$("r_date1").value;
		d2 = g$("r_date2").value;
		a = g$("r_adult").value;
		c = g$("r_child").value;
		ad = g$("r_addon").value;
		i = g$("r_iet").value;
		segtype = g$("r_segtype").value
		if(d1!=""){
			g$("date1").value = d1;
		}
		if(c1!=""&&c2!=""){
			g$("cname_city1").value = c1;
			g$("city1").value = s1;
			g$("cname_city1").style.color ="#00BE00";
			g$("cname_city2").value = c2;
			g$("city2").value = s2;
			g$("cname_city2").style.color ="#00BE00";
		}
		if(a!=""){
			g$("adult").value = a;
		}
		if(c!=""){
			g$("child").value = c;
		}
		if(ad!=""){
			g$("addon").checked = true;
		}
		if(i!=""){
			g$("iet").checked = true;
		}
		if(segtype == "S"){
			ioneway();
			g$("oneway").checked = true;
			if(d1!=""){
				g$("date1").value = d1;
			}
		}
		else if(segtype == "R"){
			ibout();
			g$("bout").checked = true;
			if(d2!=""){
				g$("date2").value = d2;
			}
		}
		else if(segtype == "M"){
			imoreline();
			g$("more").checked = true;
			c3 = g$("r_city3").value;
			c4 = g$("r_city4").value;
			c5 = g$("r_city5").value;
			c6 = g$("r_city6").value;
			s3 = g$("s_city3").value;
			s4 = g$("s_city4").value;
			s5 = g$("s_city5").value;
			s6 = g$("s_city6").value;
			d3 = g$("r_date3").value;
			d4 = g$("r_date4").value;
			d5 = g$("r_date5").value;
			if(d2!=""){
				g$("date2").value = d2;
			}
			for (i=3;i<6;i++){
				if(eval('d'+i)!=""){
					g$("date"+i).value = eval('d'+i);
				}
			}
			for (i=3;i<7;i++){
				if(eval('c'+i)!=""){
					g$("cname_city"+i).value = eval('c'+i);
					g$("city"+i).value = eval('s'+i);
					g$("cname_city"+i).style.color ="#00BE00";
				}
			}
		}else{
			ibout();
			g$("bout").checked = true;
			if(d2!=""){
					g$("date2").value = d2;
			}
		}		
	}
	if(g$('date2')){
		setDefaultTimeBack('date2')
	}
	adultchild();
	internationalChild('city1');
	internationalChild('city2');
}

function airport(){//网上值机
	var ApId = g$("ApId").value;
	var ApFlt = g$("ApFlt").value;
	var ApMb = g$("ApMb").value;
	var ApUrl ="http://airport.csair.com/cki/app?service=external/login&sp=Szh&sp="
	//var ApUrl ="http://10.108.71.18/cki/app?service=external/login&sp=Szh&sp="
	if (ApId.length == 0){
		clearchildnodes("ApInfo");
		g$("ApInfo").innerHTML="请填写证件号码"
	}else if(ApFlt.length == 0){
		clearchildnodes("ApInfo");
		g$("ApInfo").innerHTML="请填写航班号"
	}else if(ApMb.length == 0){
		clearchildnodes("ApInfo");
		g$("ApInfo").innerHTML="请填写手机号"	
	}else{
		clearchildnodes("ApInfo");
		window.location.href=ApUrl+"S"+ApId+"&sp=S"+ApFlt+"&sp=S"+ApMb;	
	}		
}
function orderFood(){//餐食预订
	var foodID = g$("foodID").value;
	var foodMb = g$("foodMb").value;
	var foodurl ="http://hvp.csair.com/food/app?service=external/Login&sp="
	if (foodID.length == 0){
		clearchildnodes("foodInfo");
		g$("foodInfo").innerHTML="请填写证件号码"
	}else if(foodMb.length == 0){
		clearchildnodes("foodID");
		g$("foodInfo").innerHTML="请填写手机号码"
	}else{
		window.location.href=foodurl+"S"+foodID+"&sp=S"+foodMb;	
	}
		
}

function checkTicket_0(){
	var regPsgName1 = new RegExp('^(([\u4E00-\u9fA5]{2,9})(\sCHD)?|[A-Za-z][]?[A-Za-z]([]?[A-Za-z]){0,49}/[A-Za-z](([]?[A-Za-z]){1,49})(\sCHD)?|([\u4E00-\u9fA5]{1,5}[]?[A-Za-z]([]?[A-Za-z]){1,21}[/]?[A-Za-z](([]?[A-Za-z]){1,21})))$');
	var name = document.getElementsByName("passengerName").item(0).value;
	var infoorderNo=g$('infoorderNo');
	var tempt = ''; 
	if(!regPsgName1.exec(name)){infoorderNo.innerHTML='';infoorderNo.innerHTML='请输入正确的旅客姓名！'; return false;} 
	if(g$('orderNo').value.length>12 && g$('orderNo').value.length<15){}else{infoorderNo.innerHTML='';infoorderNo.innerHTML='请输入正确的订单编号！'; return false;}
}


/*事件处理*/
function eventhing(){
	var evts=eventhing.arguments[0]||window.event;//根据FF和IE的不同取得相应的事件对象
	var element=evts.target||evts.srcElement;//根据FF和IE的不同取得事件触发对象
	if(element.id == "ApBtn"){
		airport();
	}
	if(element.id == "foodsubmit"){
		orderFood();
	}
}

/*成人儿童婴儿联动*/
function refreshChild(n){
	if(n!=-1){
		var _value = $("#child").val();
		var i=0;
		if($("#child").children("option").length>0)$("#child").empty();
		while(i<= 6-n){
			$("#child").append("<option value="+i+">"+i+"</option>");
			i++;
		}
		$("#child").val(_value);
		if($("#child").val() != _value)$("#child").val(0);
		var _value2 = $("#infant").val();
		var i2=0;
		if($("#infant").children("option").length>0)$("#infant").empty();
		while(i2<= n && (i2*1+n*1+$("#child").val()*1)<=6){
			$("#infant").append("<option value="+i2+">"+i2+"</option>");
			i2++;
		}
		$("#infant").val(_value2);
		if($("#infant").val() != _value2)$("#infant").val(0);
	}else{
		var _value3 = $("#infant").val();
		var i2=0;
		if($("#infant").children("option").length>0)$("#infant").empty();
		while(i2<= $("#adult").val() && (i2*1+$("#adult").val()*1+$("#child").val()*1)<=6){
			$("#infant").append("<option value="+i2+">"+i2+"</option>");
			i2++;
		}
		$("#infant").val(_value3);
		if($("#infant").val() != _value3)$("#infant").val(0);	
	}
	
	ietNoInfant("#infant");
}

function ietNoInfant(obj){
	if($(obj).val()>0){
		$("#iet").attr("checked","");
		$("#iet").attr("disabled","true");
		$("#addon").attr("checked","");
		$("#addon").attr("disabled","true");		
	}else if($(obj).val()=="0"){
		$("#iet").attr("checked","");
		$("#iet").attr("disabled","");	
		$("#addon").attr("checked","");
		$("#addon").attr("disabled","");
	}
}

/*end成人儿童婴儿联动*/

//航班动态验证
function coderefurbish(){
	g$('mycode').src+=parseInt(Math.random()*10);return false;
}
function smtrequest(){
	var n = g$('flightNum').value;
	var c = g$('checkcode').value;
	var ct7 = g$('city7').value;
	var ct8 = g$('city8').value;
	if(g$("all").checked){
		if(ct7 == "" || ct7 =="全拼/简拼/汉字"){
			g$('msg_code').innerHTML = '';
			g$('msg_code').innerHTML = '请输入出发机场！';
			return false;	
		}else if(ct8 == "" || ct8 =="全拼/简拼/汉字"){
			g$('msg_code').innerHTML = '';
			g$('msg_code').innerHTML = '请输入到达机场！';
			return false;
		}else if(ct7 == ct8){
			g$('msg_code').innerHTML = '';
			g$('msg_code').innerHTML = '出发机场和到达机场不能相同！';
			return false;
		}else if(c == ""){
			g$('msg_code').innerHTML = '';
			g$('msg_code').innerHTML = '请输入验证码！';
			return false;
		}else{
			var rul = "booking/07/check.asp?types=all&ct7="+ct7+"&ct8="+ct8+"&checkcode="+c+"&codeKey="+g$('codeKey').value;
			XMLHttp.sendReq('GET', rul, '', callback,'msg_code');
			g$('checkcode').value = '';
			return false;
		}
	}else if(g$("kk").checked){
		if(n == ""){
			g$('msg_code').innerHTML = '';
			g$('msg_code').innerHTML = '请输入航班号！';
			return false;
		}else if(c == ""){
			g$('msg_code').innerHTML = '';
			g$('msg_code').innerHTML = '请输入验证码！';
			return false;
		}else{
			var rul = "booking/07/check.asp?types=kk&flightNum="+n+"&checkcode="+c+"&codeKey="+g$('codeKey').value;
			XMLHttp.sendReq('GET', rul, '', callback,'msg_code');
			g$('checkcode').value = '';
			return false;
		}
	}else{
		
	}
}
function callback(obj,EleId){
	var callbackDate = obj.responseText;
	coderefurbish();
	g$(EleId).innerHTML = '';
	if(callbackDate == "OK"){
		g$("postid").submit();
	}else{
		g$(EleId).innerHTML = callbackDate;
		return false;
	}
}