
function openwindow(pagelink,pagewidth,pageheight,scrollonoff) {
	if (arguments.length != 4) {
		scrollonoff = 0;
	}
	mywin=window.open( pagelink, 'Note', 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars='+scrollonoff+', resizable=1, copyhistory=0, width='+pagewidth+',height='+pageheight );
}
function hideretcal()
{
document.getElementById("retcalall").style.visibility="hidden";
var daysinmonth=new Array("",31,28,31,30,31,30,31,31,30,31,30,31);
var test=new String(document.getElementById("return_month_year").value);
var intmonth=parseFloat(test.substr(0,2));
mthcount=daysinmonth[intmonth];

for(i=1;i<=mthcount;i++)
{
	document.getElementById("retidDate"+i).style.visibility="hidden";
}

}
function showretcal()
{
document.getElementById("retcalall").style.visibility="visible";
var daysinmonth=new Array("",31,28,31,30,31,30,31,31,30,31,30,31);
var test=new String(document.getElementById("return_month_year").value);
var intmonth=parseFloat(test.substr(0,2));

mthcount=daysinmonth[intmonth];

for(i=1;i<=mthcount;i++)
{
	document.getElementById("retidDate"+i).style.visibility="visible";
}


}



function hidefromcity(){

	}

function hidetocity()
{
	
}

function resetInputs() {
 hidefromcity();
  hidetocity();
  var frmSearch = document.forms[0];
   frmSearch.txtOriginAirport.value = "CPH";

}


function getDate(strType){

 var txtDate =  document.getElementById(strType + "_date");
 if(!txtDate){
    alert("FATAL ERROR ! " + strType + " DATE ELEMENT NOT FOUND");
 }
 var strDateValue = txtDate.value;
 if(strDateValue == ""){
   alert("FATAL ERROR ! " + strType + " DATE VALUE EMPTY");
 }
 
 var txtMonthYear =  document.getElementById(strType + "_month_year");
 if(!txtMonthYear){
    alert("FATAL ERROR ! " + strType + " MONTH YEAR ELEMENT NOT FOUND");
 } 
 var strMonthYearValue = txtMonthYear.value
 if(strMonthYearValue == ""){
   alert("FATAL ERROR ! " + strType + " MONTH YEAR VALUE EMPTY");
 }
 var arrTemp = strMonthYearValue.split("-");
 var strMonth = arrTemp[0];
 var strYear  = arrTemp[1];
 
 var strDate = strYear + "/" + strMonth + "/" + strDateValue;
 
 var objDate = new Date(strDate);
 return objDate;
}


function submitForm(){
    var frmSearch = document.forms[0];
  
    var objDepartDate = getDate("depart");
	var objReturnDate = getDate("return");
	
	for(var i=0;i<frmSearch.rdoJourneyType.length;i++){
	      if(frmSearch.rdoJourneyType[i].checked == true){
	        strJourneyType = frmSearch.rdoJourneyType[i].value;
	      }
	}
	
	if(strJourneyType == "roundtrip"){
	  if(objDepartDate.getTime() > objReturnDate.getTime()){
	    alert("Depart date cannot be greater than return date"); 
        return false
	 }
	}
  

   if(frmSearch.txtDestinationAirport.value == ""){
     alert("Please enter destination airport");
     return false;
   }
   
   var strOriginAirport =frmSearch.txtOriginAirport.value;
   var strDestinationAirport =frmSearch.txtDestinationAirport.value;
   
   strOriginAirport = strOriginAirport.replace(/\(/g,"");
   strOriginAirport = strOriginAirport.replace(/\)/g,"");
  
   strDestinationAirport = strDestinationAirport.replace(/\(/g,"");
   strDestinationAirport =  strDestinationAirport.replace(/\)/g,"");
  
   
   
   
   
   frmSearch.txtOriginAirport.value = "(" + strOriginAirport + ")";
   frmSearch.txtDestinationAirport.value = "(" + strDestinationAirport + ")";
    
  	frmSearch.txtDepartDay.value  = objDepartDate.getDate();
    if(parseInt(frmSearch.txtDepartDay.value) < 10 ){
      frmSearch.txtDepartDay.value = "0" + frmSearch.txtDepartDay.value;
    }
    
	frmSearch.txtDepartMonth.value  = objDepartDate.getMonth() + 1 ;
    if(parseInt(frmSearch.txtDepartMonth.value) < 10 ){
      frmSearch.txtDepartMonth.value = "0" + frmSearch.txtDepartMonth.value;
    }
    frmSearch.txtDepartYear.value  = objDepartDate.getFullYear();
    
    frmSearch.txtReturnDay.value  = objReturnDate.getDate();
    if(parseInt(frmSearch.txtReturnDay.value) < 10 ){
      frmSearch.txtReturnDay.value = "0" + frmSearch.txtReturnDay.value;
    }
	frmSearch.txtReturnMonth.value  = objReturnDate.getMonth() + 1 ;
    if(parseInt(frmSearch.txtReturnMonth.value) < 10 ){
      frmSearch.txtReturnMonth.value = "0" + frmSearch.txtReturnMonth.value;
    }
  
    frmSearch.txtReturnYear.value  = objReturnDate.getFullYear();
    
    
    frmSearch.submit();
    
    return true;
}

function handleAirportSelect(cmb,strAirport){
  var frmSearch = document.forms[0];
  var strValue = cmb.value;
  if(strAirport == "origin"){
      frmSearch.txtOriginAirport.value = strValue; 
  }else{
     
     frmSearch.txtDestinationAirport.value = strValue;
  }
}


