﻿function ChkName(Name) {
  var IsValid=true;
  var Cn=0;
  len=Name.length;
  if (len > 0){
    Namecn = escape(Name.charAt(0));
    if (Namecn.length<=3){Cn=0;}else{Cn=1;}
    for (i=0; i<len; i++){
      Namecn = escape(Name.charAt(i));
       if (Namecn.length<=3){
         if (Cn==0){if(parseInt(Namecn)){IsValid=false;break;}}
         if (Cn==1){IsValid=false;break;}
       }
       else{
        if (Cn==0){IsValid=false;break;}
       }
    }
    if ((IsValid)&&(Cn==0)){
      if(Name.length<5){IsValid=false;return false;}
      indexg = Name.indexOf("/");
      if (indexg!=-1){IsValid=true;}
      else{IsValid=false;}
    }
  }
  else {
    IsValid=false;
  }
  return IsValid;
}

function isNull(str)
{
	if(str == ""|str==null)
	{
		return true;
	}else
	{
		return false;
	}
}
             
function compareDate(DateOne,DateTwo,AllowEq)
{
   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 (AllowEq)
   {
		if (Date.parse(OneMonth+"/"+OneDay+"/"+OneYear) > Date.parse(TwoMonth+"/"+TwoDay+"/"+TwoYear))
		{
			return true;
		}
		else
		{
			return false;
		}      
   }
   else
   {
       	if (Date.parse(OneMonth+"/"+OneDay+"/"+OneYear) >= Date.parse(TwoMonth+"/"+TwoDay+"/"+TwoYear))
		{
			return true;
		}
		else
		{
			return false;
		}      
   }
   
}


function isDate(sDate) {
	var iYear, iMonth, iDay, iIndex

	var	reg
	reg = new RegExp('[^0-9-]','')
	if (sDate.search(reg) >= 0)
		return false;
	
	iIndex = sDate.indexOf('-');
	if ( iIndex == -1 )
		return false;
	else {
		iYear = parseFloat(sDate.substr(0, iIndex));
		if ( isNaN(iYear) || iYear < 1900 || iYear > 2099 )
			return false;
		else
			sDate = sDate.substring(iIndex + 1, sDate.length);
	}
	
	iIndex = sDate.indexOf('-');
	if ( iIndex == -1 )
		return false;
	else {
		iMonth = parseFloat(sDate.substr(0, iIndex));
		if ( isNaN(iMonth) || iMonth < 1 || iMonth > 12 )
			return false;
		else
			sDate = sDate.substring(iIndex + 1, sDate.length);
	}
	
	iIndex = sDate.indexOf('-');
	if ( iIndex >= 0 )
		return false;
	else {
		iDay = parseFloat(sDate);
		if ( isNaN(iDay) || iDay < 1 || iDay > 31 )
			return false;
	}
	
	
	switch(iMonth) {
		case 4:
		case 6:
		case 9:
		case 11:
			if ( iDay > 30 )
				return false;
			else
				break;
		case 2:
			if ( ( ( iYear % 4 == 0 && iYear % 100 != 0 ) || iYear % 400 == 0 ) && iDay > 29 )
				return false;
			else if ( (iYear % 4 != 0 || (iYear % 100 == 0 && iYear % 400 != 0)) && iDay > 28 )
				return false;
			else
				break;
		default:
	}
	return true;
}

function AddToday(k)
{
    hh=new Date;
	jj=new Date(hh.getYear()<1900?hh.getYear()+1900:hh.getYear(),hh.getMonth(),hh.getDate()+k);
	y=jj.getFullYear();
	m=jj.getMonth();
	d=jj.getDate();
	strdate=y+"-"+(m+1)+"-"+d;
	return strdate;
}
	
function ConfirmMsg(Msg){
    return(confirm(Msg));   
}

function btnClick()
{  
    if (event.keyCode==13)
    {   
	event.keyCode=9;
        event.returnValue = false;
	document.all.BtnSearch.click(); 
    }
}

function ShowHideFlight(Id,HideText,ShowText){
     
     RowId="R"+Id; 
     TxtId="T"+Id;
     LId  ="L"+Id;
     IId  ="I"+Id;
     if (document.all[RowId].style.display=="none")
     {
        document.all[RowId].style.display="";
        document.all[IId].src="../Flight/Files/Images/niu4.gif";
        document.all[TxtId].innerText="只显示最低价";
        document.all[LId].style.display="none";
     }
     else
     {
          document.all[RowId].style.display="none";
          document.all[IId].src="../Flight/Files/Images/niu3.gif";
          document.all[TxtId].innerText="显示所有舱位";
          document.all[LId].style.display="";
     }
} 
  
function ShowHide(Id,HideText,ShowText){
     
     RowId="R"+Id; 
     TxtId="T"+Id;
     if (document.all[RowId].style.display=="none")
     {
        document.all[RowId].style.display="";
        document.all[TxtId].innerText=HideText;
     }
     else
     {
          document.all[RowId].style.display="none";
          document.all[TxtId].innerText=ShowText;
     }
  }     

var Win
function OpenWin(Name,strUrl,width,height)
{
var str = "height=" + height + ",innerHeight=" + height;
str += ",width=" + width + ",innerWidth=" + width;
if (window.screen) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = (aw - width) / 2;
var yc = (ah - height) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}
  
   if (!Win || Win.closed)
   {
     Win=open(strUrl,Name,"resizable=0,scrollbars=1," + str);
   }else{
     Win.location.href=strUrl;
     Win.focus();
   }  
}