﻿/**
 * @author ms_tripx 2007.11
 * TripxTabs
 * TripxToolTip
 */
//**TripxTabs
function TripxTabs()
{
  this.tabs=new Array();
};
TripxTabs.prototype.addTab=function(tabid)
{  
  this.tabs.push(tabid);
};
TripxTabs.prototype.showTab=function(tabid)
{  
  for(var i=0;i<this.tabs.length;i++)
  {
    var tabo=this.getObject(this.tabs[i]);
    if(this.tabs[i]==tabid)
    {
     tabo.style.display="block"
    }
    else
    {
      tabo.style.display="none";
    }
  }
};
TripxTabs.prototype.getObject=function(objectid)
{
  return document.getElementById(objectid);
};
var tripxcrslan=new TripxCrsLan();
//**TripxCrsLan
function TripxCrsLan()
{
	this.isvtk=false;
	this.lan=new Array();
	this.push=function(name,value)
	{
		this.lan.push(new TripxCrsLanEntity(name,value));
	};
	this.getValue=function(name)
	{
		for(var i=0;i<this.lan.length;i++)
		{
			if(this.lan[i].name==name)
			{
				return this.lan[i].value;
			}
		}
		return "";
	};
	this.showMsg=function(name)
	{
		this.alertMsg(this.getValue(name));
	};
	this.confirm=function(name)
	{
		return window.confirm(this.getValue(name));
	};
	this.initial=function(str)
	{
		var split1="|";
		var split2="||";
		var nvs=str.split(split2);
		for(var i=0;i<nvs.length;i++)
		{
			var nv=nvs[i].split(split1);
			if(nv.length==2)
			{
				this.push(nv[0],nv[1]);
			}
		}
	};
	this.showMsgInfo=function(msgInfo,spliter)
	{
		if(spliter==null)spliter=",";
		var infos=msgInfo.split(spliter);
		if(infos.length>=3)
		{
			var lan=this.getLanguage();
			//alert(infos[lan]);
			this.alertMsg(infos[lan]);
		}
		else{this.alertMsg("language wrong!");}
	};
	this.getMsgInfo=function(msgInfo,spliter)
	{
	    if(spliter==null)spliter=",";
		var infos=msgInfo.split(spliter);
		if(infos.length>=3)
		{
			var lan=this.getLanguage();
			return infos[lan];
		}
		else{this.alertMsg("language wrong!");}
	};
	this.confirmMsgInfo=function(msgInfo,spliter)
	{
		if(spliter==null)spliter=",";
		var infos=msgInfo.split(spliter);
		if(infos.length>=3)
		{
			var lan=this.getLanguage();
			return window.confirm(infos[lan]);
		}
		else{this.alertMsg("language wrong!");}
	}
	this.getCookieVal=function(offset)
    {
        var endstr = document.cookie.indexOf(";", offset);
        if(endstr == -1)
        {
            endstr = document.cookie.length;
        }

        return unescape(document.cookie.substring(offset, endstr));
    };
    this.getCookie=function(name)
    {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while(i < clen)
        {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
            {
                return this.getCookieVal(j);
            }
            i = document.cookie.indexOf(" ", i) + 1;
            if(i == 0) break;
        }
        return;
    };
	this.getLanguage=function()
	{
		return this.getCookie("LanguagePref");
	};
	this.alertMsg=function(msg)
	{
		if(!this.isvtk)
		{
			alert(msg);
		}
		else{
			showMessage(msg,1,1);
		}
	};
};
function TripxCrsLanEntity(name,value)
{
	this.name=name;
	this.value=value;
};
//**TripxToolTip
function TripxCRSToolTip(className)
{
  this.tip=document.createElement("div");
  if(className)
  {
   this.tip.className=className;
  }
  else
  {
   this.tip.style.position="absolute";   
   this.tip.style.border="1px solid gray";
   this.tip.style.backgroundColor="#ffffff";    
   this.tip.style.left="-10px";
   this.tip.style.top="0px";
   this.tip.style.zIndex="20";
   this.tip.style.visibility="hidden";
  }
  document.body.appendChild(this.tip);
  this.controls=new Array();
};
TripxCRSToolTip.prototype.addControl=function(controlid,tipstr)
{   
  this._addControl(controlid,tipstr,this.tip);
};
TripxCRSToolTip.prototype._addControl=function(controlid,tipstr,tip)
{
  var ctrl=document.getElementById(controlid);  
  var me=this;  
  ctrl.onmouseover=function(e)
  {        
  	if(tip.style.visibility.toString()=="visible")
	{
		return;
	}
	tip.innerHTML=tipstr;
    var p=getMousePosition(e);		
	if(tripxcrstoolkit.isIE()){
		me.showToolTip([p,tip]);
	}
	else{
		me.showtimeout=window.setTimeout(me.showToolTip,500,[p,tip])
	}	
  };
  ctrl.onmouseout=function(e)
  {
    tip.style.visibility="hidden";	
	if(me.showtimeout){
		window.clearTimeout(me.showtimeout);
	}	
  } ; 
};
TripxCRSToolTip.prototype.showToolTip=function(parms){	
	var p=parms[0];
	var tip=parms[1];
	if(p.x+tip.clientWidth>document.documentElement.clientWidth)
	{
		tip.style.left="";
		tip.style.right=(document.documentElement.clientWidth-p.x+20)+"px";		
	}
	else{
		tip.style.left=p.x+"px";
		tip.style.right="";
	}	
	if(tip.clientHeight>document.documentElement.clientHeight){
		tip.style.top="0px";
		tip.style.bottom="";
	}
	else if(p.y+tip.clientHeight>document.documentElement.clientHeight+document.documentElement.scrollTop){
		tip.style.top="";
		tip.style.bottom=(document.documentElement.clientHeight-p.y)+"px";		
	}
	else{
		tip.style.top=p.y+"px";
		tip.style.bottom="";
	}
    tip.style.visibility="visible"; 
}
//**getMousePosition
function getMousePosition(e)
{
  var ev=e?e:window.event;
  if(ev.pageX || ev.pageY){return {x:ev.pageX, y:ev.pageY};}  
  return {x:ev.clientX + document.documentElement.scrollLeft ,y:ev.clientY + document.documentElement.scrollTop};
} ;
//**doNothing
function doNothing()
{
};
function clearSelectOptions(select)
{        
    while(select.length>0)
    {
        select.options[0]=null;
    }    
};
function addSelectOption(select,text,value)
{   
    select.options[select.length]=new Option(text,value);    
};
function getSelectOption(select)
{   
    if(select.selectedIndex>-1)
    {
        return select.options[select.selectedIndex];
    }
    return null;
};
function getSelectOptionValue(select)
{    
    var option=getSelectOption(select);    
    if(option){return option.value;}
    return null;
};
function getSelectOptionText(select)
{
    var option=getSelectOption(select);
    if(option){return option.text;}
    return null;    
};
function setSelectOption(select,value)
{
  for(var i=0;i<select.length;i++)
  {
    if(select.options[i].value==value)
    {  
        select.selectedIndex=i;
    }
  }  
};
function SetOptionTitle()
{
    var selects = document.getElementsByTagName("select");
    if (selects.length > 0)
    {
	    for (var i = 0; i < selects.length; i++)
	    {
		    var options = selects[i].options;
		    if (selects[i].options.length > 0)
		    {
			    for (var j = 0; j < options.length; j++)
			    {
				    if (options[j].title == "")
					    options[j].title = options[j].text;
			    }
		    }
	    }
    }
};
function setSelectMaxLength()
{
	var selects = document.getElementsByTagName("select");
	if (selects.length > 0)
    {
	    for (var i = 0; i < selects.length; i++) {
			var s=selects[i];
			if(s.attributes['maxlength']){
				var maxlen=s.attributes['maxlength'].value;
				if(s.clientWidth>parseInt(maxlen))
				{
					s.style.width=maxlen;
				}
			}
		}
    }
};
var tripxcrstoolkit=new Object();
tripxcrstoolkit.checkDate=function(datestr)
{
	var pattern = /^\d\d\d\d[-]([1-9]|0[1-9]|1[012])[-]([1-9]|0[1-9]|[12][0-9]|3[01])$/;
	if(pattern.test(datestr))
	{
		return true;
	}
	return false;
};
tripxcrstoolkit.checkInt=function(str,allowempty)
{
	if(str=="" && allowempty)return true;
	var pattern = /^\d+$/;	
	if(pattern.test(str))
	{
		return true;
	}
	return false;
};
tripxcrstoolkit.parseDate=function(datestr)
{		
	if(tripxcrstoolkit.isDate(datestr))
	{
		var date=new Date();
		var strs=datestr.split("-");
		date.setFullYear(strs[0]);
		date.setMonth(strs[1]-1,1);
		date.setDate(strs[2]);		
		return date;
	}
	return null;
};
tripxcrstoolkit.setIframeHeight=function(iframeid,minheight)
{	
	var iframe=parent.document.getElementById(iframeid);	
	if(iframe)
	{		
		if(minheight)
		{
			if(minheight>document.body.scrollHeight)
			{
				iframe.style.height=minheight+"px";
			}
			else
			{
				iframe.style.height=document.body.scrollHeight+"px";
			}
		}	
		else{
			iframe.style.height=document.body.scrollHeight+"px";
		}		
	}  
};
tripxcrstoolkit.isIE=function()
{
	if (window.navigator.userAgent.indexOf("MSIE")>=1)
	{
		return true;	
	}
};
tripxcrstoolkit.isFF=function()
{	
	if (window.navigator.userAgent.indexOf("Firefox")>=1)
	{
		return true;	
	}
	return false;
};
tripxcrstoolkit.isDate=function(str)
{
	/*
	var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/
    if (reg.test(str)) return true;
    return false;
    */
	var reg = /^\d{4}-((0{0,1}[1-9]{1})|(1[0-2]{1}))-((0{0,1}[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/;  
  var result=true;
  if(!reg.test(str))
    result = false;
  else{
    var arr_hd=str.split("-");
    var dateTmp;
    dateTmp= new Date(arr_hd[0],parseFloat(arr_hd[1])-1,parseFloat(arr_hd[2]));
    if(dateTmp.getFullYear()!=parseFloat(arr_hd[0])
       || dateTmp.getMonth()!=parseFloat(arr_hd[1]) -1 
        || dateTmp.getDate()!=parseFloat(arr_hd[2])){
        result = false
    }
  }
  return result;
};
tripxcrstoolkit.compareDate=function(strStart,strEnd)
{
    if(tripxcrstoolkit.isDate(strStart) == false || tripxcrstoolkit.isDate(strEnd) == false)
        return -2;        
    var arr1 = strStart.split("-");
    var arr2 = strEnd.split("-");
    var date1 = new Date(arr1[0],parseInt(arr1[1].replace(/^0/,""),10) - 1,arr1[2]);
    var date2 = new Date(arr2[0],parseInt(arr2[1].replace(/^0/,""),10) - 1,arr2[2]);
    if(arr1[1].length == 1)
        arr1[1] = "0" + arr1[1];
    if(arr1[2].length == 1)
        arr1[2] = "0" + arr1[2];
    if(arr2[1].length == 1)
        arr2[1] = "0" + arr2[1];
    if(arr2[2].length == 1)
        arr2[2]="0" + arr2[2];
    var d1 = arr1[0] + arr1[1] + arr1[2];
    var d2 = arr2[0] + arr2[1] + arr2[2];
    if(parseInt(d1,10) > parseInt(d2,10))
       return -1;
    else if(parseInt(d1,10) == parseInt(d2,10))
       return 0;
    else
       return 1;
};
tripxcrstoolkit.checkIdcard=function(idcard,showMsg){
	var reg=/^[\d|a-z|A-Z]{1,30}$/;
	if(reg.test(idcard)){
		return true;
	}
	else{
		var errInfo="身份证输入错误!,Please enter legal document no.!,身份證輸入錯誤!";
		if(showMsg!=false)tripxcrslan.showMsgInfo(errInfo);
		return false;
	}
}
tripxcrstoolkit.checkIdcardStrict=function(idcard,showMsg){ 		
	//debugger; 
      //var Errors=new Array("验证通过!","身份证号码位数不对!","身份证号码出生日期超出范围或含有非法字符!","身份证号码校验错误!","身份证地区非法!");   
	  var errInfo="身份证输入错误!,Please enter legal document no.!,身份證輸入錯誤!";
      var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}   
      var idcard,Y,JYM;   
      var S,M;   
      var idcard_array = new Array();   
      idcard_array = idcard.split("");        
      if(area[parseInt(idcard.substr(0,2))]==null)
      {
        //alert(Errors[4]);//return false;   
		if(showMsg!=false)tripxcrslan.showMsgInfo(errInfo);
		return false;
      }
	  if(idcard=="111111111111111")
	  {
	  	if(showMsg!=false)tripxcrslan.showMsgInfo(errInfo);
		return false;
	  }
      switch(idcard.length){   
        case 15:   
          if ((parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){   
            ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性   
          }   
          else{   
            ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性   
          }   
          if(ereg.test(idcard))   
            return true;   
          else  
          {
            //alert(Errors[2]); //return false; 
			if(showMsg!=false) tripxcrslan.showMsgInfo(errInfo);
			return false;  
          }
            
        break;   
      case 18:   
        if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){   
          ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式   
        }   
        else{   
        ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式   
        }   
        if(ereg.test(idcard)){   
          S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 + parseInt(idcard_array[7]) * 1 + parseInt(idcard_array[8]) * 6 + parseInt(idcard_array[9]) * 3 ;   
          Y = S % 11;   
          M = "F";   
          JYM = "10X98765432";   
          M = JYM.substr(Y,1);   
          if(M == idcard_array[17])   
            return true;   
          else  
          {
            //alert(Errors[3]); //return false;  
			if(showMsg!=false) tripxcrslan.showMsgInfo(errInfo);
			return false; 
          }
        }   
        else  
          {
            //alert(Errors[2]); //return false; 
			if(showMsg!=false) tripxcrslan.showMsgInfo(errInfo);
			return false;  
          }
        break;   
      default:   
        //alert(Errors[1]); //return false;   
		if(showMsg!=false) tripxcrslan.showMsgInfo(errInfo);
		return false;
        break;   
      }   
    } ;
tripxcrstoolkit.checkPassport=function(str)
{
	var pattern = /^[A-Za-z0-9]{0,20}$/;
	var result=pattern.test(str);
	if(!result)
	{		
		//alert("护照输入错误!");
		tripxcrslan.showMsgInfo("护照输入错误!,Please enter legal document no.!,護照輸入錯誤!");
	}	
	return result;
};
tripxcrstoolkit.checkMilitaryCard=function(str)
{
	var pattern=/^[A-Za-z0-9\u4e00-\u9fa5\(\)]{0,20}$/;
	var result=pattern.test(str);
	if(!result)
	{
		//alert("军官证输入错误!");
		tripxcrslan.showMsgInfo("军官证输入错误!,Please enter legal document no.!,軍官證輸入錯誤!");
	}
	return result;
};
tripxcrstoolkit.checkOtherCard=function(str)
{
	var pattern=/^[A-Za-z0-9\u4e00-\u9fa5]{0,20}$/;
	var result=pattern.test(str);
	if(!result)
	{
		//alert("证件号码输入错误!");
		tripxcrslan.showMsgInfo("证件号码输入错误!,Please enter document no.!,證件號碼輸入錯誤!");
	}
	return result;
}
tripxcrstoolkit.checkCertificateNo=function(checktype,str)
{
	var result=true;
	if(checktype=="1")
	{
		result=tripxcrstoolkit.checkIdcard(str);
	}
	else if(checktype=="2")
	{
		result=tripxcrstoolkit.checkMilitaryCard(str);
	}
	else if(checktype=="3")
	{
		result=tripxcrstoolkit.checkPassport(str);
	}
	else if(checktype=="99")
	{
		result=tripxcrstoolkit.checkOtherCard(str);
	}
	return result;
};
tripxcrstoolkit.getBirthdayFromId=function(idstr)
{
	if(tripxcrstoolkit.checkIdcardStrict(idstr,false))
	{		
		if(idstr.length==18)
		{
			return idstr.substring(6,10)+"-"+idstr.substring(10,12)+"-"+idstr.substring(12,14);	
		}
		else if(idstr.length==15)
		{
			return "19"+idstr.substring(6,8)+"-"+idstr.substring(8,10)+"-"+idstr.substring(10,12);	
		}		
	}
	return "";	
}
tripxcrstoolkit.checkName=function(str)
{
	var pattern=/^[\sA-Za-z0-9\u4e00-\u9fa5|\_]{0,20}$/;
	var result=pattern.test(str);
	if(!result)
	{
		//alert("姓名中含有非法字符!");
		tripxcrslan.showMsgInfo("姓名中含有非法字符!,Name contains illegal character!,姓名中含有非法字符!");
	}
	return result;
};
tripxcrstoolkit.checkFlightPsgAmount=function(str)
{
	/*
	if(trim(str)!="")
	{
		pattern=/^\d+$/;
		if(!pattern.test(str))
		{
			alert("请输入合法的乘客人数!");
			return false;
		}
		var istr=parseInt(str);
		if(istr<1 ||istr>10)
		{
			alert("乘客人数必须是1-10之间的整数!");
			return false;
		}
	}	
	*/	
	return true;
}
var tripxsxmlparser=new TripxSimpleXmlParser();
function TripxSimpleXmlParser()
{};
TripxSimpleXmlParser.prototype.getFirstNodeValue=function(xmlstr,tagname)
{
	var xmlDoc=null;
	if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  		xmlDoc.async=false;
		xmlDoc.loadXML(xmlstr);			
	}
	else if(document.implementation && document.implementation.createDocument)
	{		
		var oParser = new DOMParser();
    	xmlDoc = oParser.parseFromString(xmlstr,"text/xml");				
	}
	var nodes=xmlDoc.getElementsByTagName(tagname);
	if(nodes)
	{
		if(nodes.length>0)
		{
			if(nodes[0].firstChild)
			{
				return nodes[0].firstChild.nodeValue;
			}
		}
	}
	return "";
}
//added by xuht

//去左空格;
function ltrim(s){
return s.replace( /^\s*/, "");
}
//去右空格;
function rtrim(s){
return s.replace( /\s*$/, "");
}
//去左右空格;
function trim(s){
return rtrim(ltrim(s));
}
//验证数字
function isDigit(s)

{

var patrn=/^[0-9]{1,20}$/;

if (!patrn.exec(s)) return false

return true

}
//限制文本框的长度
function textLimit(txt,maxlimit)   
  {   
    if(txt.value.length>maxlimit)  
	{
		txt.value=txt.value.substring(0,maxlimit);   
	}       
  } ;

//弹出一个确定宽、高的新页
function OpenModalDialog(pageFile,width,height)
{
    return window.showModalDialog(pageFile,'','dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;status:0') || false;
}  
 
 //弹出一个确定宽、高的新页
function OpenDialog(pageFile,width,height)
{
    return window.open(pageFile ,'','height=' + height + ',width=' + width + ',top=100,left=400,toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');
}   
//**表格排序 cgg (2008.8.19)
    /*
     {
     islocal:true,
     tableid:"sortdt",
     sortcols:[{
     			colindex:0,
     			clickid:"btnname",
     			sortvalues:[{value:1,direction:"asc",image:""},{value:2,direction:"desc",image:""}],
     			isdefault:true,
     			defaultimag:"".
     			datatype:"decimal"
     			},
     			{
     			colindex:1,
     			clickid:"btnage",
     			sortvalues:[{value:3,direction:"asc",image:""},{value:4,direction:"desc",image:""}],
     			isdefault:false,
     			defaultimag:""
    		 }],
     aftersort:"aftersort"
     }
     */
    function TripxSortTableNew(opt){
        this.table = document.getElementById(opt.tableid);        
        var me = this;
        init = function(){
            me.cursortcolindex = null;
            me.cursortcolvalue = null;            
            if (me.table) {
                me.tbody = me.table.getElementsByTagName("tbody")[0];
            }
            for (var i = 0; i < opt.sortcols.length; i++) {
                var scol = opt.sortcols[i];
                var clickctrl = document.getElementById(scol.clickid);
                if (clickctrl) {
                    clickctrl.onclick = new Function("sort(" + i + ",false);");
                }
                if (scol.isdefault) {
                    sort(i,true);
                }
            }
        };
        getNextSortValue = function(sortcol){
            for (var i = 0; i < sortcol.sortvalues.length; i++) {
                if (this.cursortcolvalue == sortcol.sortvalues[i].value) {
                    if (i < sortcol.sortvalues.length - 1) {
                        return sortcol.sortvalues[i + 1];
                    }
                    else {
                        return sortcol.sortvalues[0];
                    }
                }
            }
            return sortcol.sortvalues[0];
        };
        sort = function(index,isdefault){			
            var sortcol = opt.sortcols[index];
            var sortvalue = null;
            if (this.cursortcolindex == index) {
                sortvalue = getNextSortValue(sortcol);
            }
            else {
                sortvalue = sortcol.sortvalues[0];
            }
            
            if (opt.islocal) {
                sortTable(sortcol.colindex, sortvalue.direction,sortcol.datatype);
            }
            this.cursortcolindex = index;
            this.cursortcolvalue = sortvalue.value;             
            
            if (opt.islocal) {
                if (opt.aftersort) {
                    eval(opt.aftersort + "('" + sortvalue.value + "');");
                }
            }
            else {
                if (!isdefault) {
                    if (opt.aftersort) {
                        eval(opt.aftersort + "('" + sortvalue.value + "');");
                    }
                }
            }             
			setDefaultImage();
			if(sortvalue.image!=null && sortvalue!=""){
				document.getElementById(sortcol.clickid).src=getImagePath(sortvalue.image);
			}            
        };
		setDefaultImage=function(){
			for(var i=0;i<opt.sortcols.length;i++){
				var col=opt.sortcols[i];
				var clicktrl=document.getElementById(col.clickid);
				if(clicktrl){
					clicktrl.src=getImagePath(col.defaultimage);	
				}							
			}
		};
		getImagePath=function(image){
			var lan=tripxcrslan.getLanguage();
			return "/crs/images/"+lan+"/"+image;
		};
        sortTable = function(index, sortdirect,datatype){
            if (me.table) {
                var rows = me.table.rows;
                var rowArray = new Array();
                for (var i = 1; i < rows.length; i++) {
                    rowArray.push(rows[i]);
                }
                rowArray.sort(function(a, b){
                    var va = a.cells[index].innerHTML;
                    var vb = b.cells[index].innerHTML;
					if(datatype){
						if(datatype=="decimal"){
							va=parseFloat(va);
							vb=parseFloat(vb);
						}
					}
                    if (va < vb) 
                        if (sortdirect == "asc") {
                            return -1;
                        }
                        else {
                            return 1;
                        }
                    if (va > vb) 
                        if (sortdirect == "asc") {
                            return 1;
                        }
                        else {
                            return -1;
                        }
                    return 0;
                });
                for (var i = 0; i < rowArray.length; i++) {
                    me.tbody.appendChild(rowArray[i]);
                }
            }
        };
		setDefaultImage();
        init();
    };
	Date.prototype.format = function(formatter)
    {
        if(!formatter || formatter == "")
        {
            formatter = "yyyy-MM-dd";
        }
        var year = this.getYear().toString();
		if(tripxcrstoolkit.isFF()){
			year=(this.getYear()+1900).toString();
		}
        var month = (this.getMonth() + 1).toString();
        var day = this.getDate().toString();
        var yearMarker = formatter.replace(/[^y|Y]/g,'');
        if(yearMarker.length == 2)
        {
            year = year.substring(2,4);
        }    
        var monthMarker = formatter.replace(/[^m|M]/g,'');
        if(monthMarker.length > 1)
        {
            if(month.length == 1) 
            {
                month = "0" + month;
            }
        }    
        var dayMarker = formatter.replace(/[^d]/g,'');
        if(dayMarker.length > 1)
        {
            if(day.length == 1) 
            {
                day = "0" + day;
            }
        }    
        return formatter.replace(yearMarker,year).replace(monthMarker,month).replace(dayMarker,day);    
    }
     
//---------配送信息控件联动控制 Start ----------------------  
function DeliverControlManage(productType, startIndex)
{
    this.rbSelf = null;
    this.rbCourier = null;
    this.rbPostal = null;
    this.ddlDeliverSolution = null;
    this.dataSourceCtrl = null;
    this.dataSourceStr = "";
    this.currentRbIndex = 0;
    this.currentDdlValue = "";
    this.productType = productType;
    this.startIndex = startIndex;
    this.showDescTd = null;
};
DeliverControlManage.prototype.LoadCtrl=function()
{
//debugger;
    switch(this.productType)
    {
        case "Common":
        case "AddingProduct":
        case "BusTicket":
        case "Car":
        case "Flight":
        case "OtherTicket":
        case "PackageProduct":
        case "TrainTicket":
        case "Travel":
            this.rbSelf = document.getElementById("RBtnGetbySelf");
            this.rbCourier = document.getElementById("RBtnCourier");
            this.rbPostal = document.getElementById("RBtnPostal");
            this.ddlDeliverSolution = document.getElementById("DdlDeliverySolution");
            this.dataSourceCtrl = document.getElementById("HiddenDCMDataSource");
            this.currentRb = this.rbSelf;
            this.showDescTd = document.getElementById("deliverSolutionDesc");
            break;            
        case "Cruises":
            this.rbSelf = document.getElementById("RBtnGetbySelf");
            this.rbCourier = document.getElementById("RBtnCourier");
            this.rbPostal = document.getElementById("RBtnPostal");
            this.ddlDeliverSolution = document.getElementById("DdlDeliverySolution");
            this.dataSourceCtrl = document.getElementById("HiddenDCMDataSource");
            this.currentRb = this.rbSelf;
            this.showDescTd = document.getElementById("deliverSolutionDesc");
            break;            
        case "Hotel":
            this.rbSelf = document.getElementById("CtrlHotelFillOrder1_RBtnGetbySelf");
            this.rbCourier = document.getElementById("CtrlHotelFillOrder1_RBtnCourier");
            this.rbPostal = document.getElementById("CtrlHotelFillOrder1_RBtnPostal");
            this.ddlDeliverSolution = document.getElementById("CtrlHotelFillOrder1_DdlDeliverySolution");
            this.dataSourceCtrl = document.getElementById("CtrlHotelFillOrder1_HiddenDCMDataSource");
            this.currentRb = this.rbSelf;
            this.showDescTd = document.getElementById("deliverSolutionDesc");
            break;
            
        case "Flight2":
            this.rbSelf = document.getElementById("RBtnGetbySelf2");
            this.rbCourier = document.getElementById("RBtnCourier2");
            this.rbPostal = document.getElementById("RBtnPostal2");
            this.ddlDeliverSolution = document.getElementById("DdlDeliverySolution2");
            this.dataSourceCtrl = document.getElementById("HiddenDCMDataSource2");
            this.currentRb = this.rbSelf;
            this.showDescTd = document.getElementById("deliverSolutionDesc2");
            break;                    
        case "Flight3":
            this.rbSelf = document.getElementById("RBtnGetbySelf3");
            this.rbCourier = document.getElementById("RBtnCourier3");
            this.rbPostal = document.getElementById("RBtnPostal3");
            this.ddlDeliverSolution = document.getElementById("DdlDeliverySolution3");
            this.dataSourceCtrl = document.getElementById("HiddenDCMDataSource3");
            this.currentRb = this.rbSelf;
            this.showDescTd = document.getElementById("deliverSolutionDesc3");
            break;            
    } 
};

DeliverControlManage.prototype.BindDeliverSolution=function(isInitial)
{
//debugger;
    if(this.dataSourceCtrl != null && this.dataSourceCtrl.value != "")
    {
        this.dataSourceStr = this.dataSourceCtrl.value;
        
        if(this.dataSourceStr.indexOf('^^') >= 0)
        {
            var solutionList = this.dataSourceStr.split('^^');
            
            if(solutionList != null && solutionList.length == 4)
            {
                //如果是初始化，则先绑定radioButtion控件
                if(isInitial)
                {
                    var initCtrlStr = solutionList[3];
                    if(initCtrlStr != null && initCtrlStr.indexOf('$$') >= 0);
                    {
                        var initRbCtrlType = initCtrlStr.split('$$')[0];                        
                        if(initRbCtrlType != null && initRbCtrlType == "GetbySelf")
                        {
                            this.currentRbIndex = 0;
                            this.rbSelf.checked = true;
                        }
                        else if(initRbCtrlType != null && initRbCtrlType == "Courier")
                        {
                            this.currentRbIndex = 1;
                            this.rbCourier.checked = true;
                        }
                        else if(initRbCtrlType != null && initRbCtrlType == "Postal")
                        {
                            this.currentRbIndex = 2;
                            this.rbPostal.checked = true;
                        }
                    }
                }
                
                //找到对应的下拉列表的值，并初始化下拉列表控件
                var currentSolution = solutionList[this.currentRbIndex];
                
                
                if(currentSolution.indexOf('##') >= 0)
                {
                    var solutionItems = currentSolution.split('##');
                    
                    for(var i=0; i<solutionItems.length; i++)
                    {
                        var option = document.createElement("OPTION");
                        option.text = solutionItems[i].split('$$')[0];
	                    option.value = solutionItems[i].split('$$')[1];
	                    option.description = solutionItems[i].split('$$')[2];
	                    
	                    if(isIE())
                            this.ddlDeliverSolution.add(option);
                        else
                            this.ddlDeliverSolution.options.add(option);
                            
                        this.showDeliverSolutionDesc();    
                    }
                }
                else if(currentSolution.indexOf('##') < 0 && currentSolution.indexOf('$$') >= 0)
                {
                    var solutionItems = currentSolution;
                    var option = document.createElement("OPTION");
                    option.text = solutionItems.split('$$')[0];
                    option.value = solutionItems.split('$$')[1];
                    option.description = solutionItems.split('$$')[2];
                    
                    if(isIE())
                        this.ddlDeliverSolution.add(option);
                    else
                        this.ddlDeliverSolution.options.add(option);
                    
                    this.showDeliverSolutionDesc();
                }
                
                //如果是初始化，指定到下拉列表对应的值
                if(isInitial && this.ddlDeliverSolution != null)
                {
                    var initCtrlStr = solutionList[3];
                    if(initCtrlStr != null && initCtrlStr.indexOf('$$') >= 0);
                    {
                        var initDdlCtrlValue = initCtrlStr.split('$$')[1];
                        setSelectOption(this.ddlDeliverSolution, initDdlCtrlValue);
                        
                        this.showDeliverSolutionDesc();
                    }
                 }   
            }
        }
    }
};

DeliverControlManage.prototype.GetCurrentRb=function()
{
    if(this.rbSelf != null && this.rbSelf.checked)
        this.currentRbIndex = 0;
    else if(this.rbCourier != null && this.rbCourier.checked)
        this.currentRbIndex = 1;
    else if(this.rbPostal != null && this.rbPostal.checked)
        this.currentRbIndex = 2;
}

DeliverControlManage.prototype.onRbChange=function()
{
//debugger;
    this.LoadCtrl();
    this.GetCurrentRb();
    this.clearOptions(this.ddlDeliverSolution);
    this.BindDeliverSolution(false);
};

DeliverControlManage.prototype.initial=function(needBind)
{
//debugger;
    this.LoadCtrl();
    this.GetCurrentRb();
    this.clearOptions(this.ddlDeliverSolution);
    this.BindDeliverSolution(needBind);
};

DeliverControlManage.prototype.clearOptions=function(select)
{
    if(select == null) return;
    
    var count =select.length;
    for(var i=this.startIndex;i<count;i++)
    {
        select.options[this.startIndex]=null;
    } 
    
    if(isIE())
        this.showDescTd.innerText = "";
    else
        this.showDescTd.textContent = "";
}

DeliverControlManage.prototype.showDeliverSolutionDesc=function()
{
    if(this.ddlDeliverSolution != null 
        && this.ddlDeliverSolution.selectedIndex != -1
        && this.ddlDeliverSolution.options[this.ddlDeliverSolution.selectedIndex] != null)
    {
        if(this.ddlDeliverSolution.options[this.ddlDeliverSolution.selectedIndex].value != "-1")
        {
            if(isIE())
                this.showDescTd.innerText = this.ddlDeliverSolution.options[this.ddlDeliverSolution.selectedIndex].description == undefined ? "" : this.ddlDeliverSolution.options[this.ddlDeliverSolution.selectedIndex].description;
            else
                this.showDescTd.textContent = this.ddlDeliverSolution.options[this.ddlDeliverSolution.selectedIndex].description == undefined ? "" :this.ddlDeliverSolution.options[this.ddlDeliverSolution.selectedIndex].description;
                
        }
        else
        {
            if(isIE())
                this.showDescTd.innerText = "";
            else
                this.showDescTd.textContent = "";
        }
    }
}

function isIE()
{
    var userAgent = window.navigator.userAgent; 
    return userAgent.indexOf("MSIE") > 0;
}

//---------配送信息控件联动控制 End ----------------------  

