	

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


function dateValues(){
var dtStr=document.form1.inDate.value;
if(dtStr != ""){
isDateValid(dtStr,'arrival');
 }

var dtStr=document.form1.outDate.value;
if(dtStr != ""){
isDateValid(dtStr,'departure');
 }

}

function isDateValid(dtStr,frm_type){
    	var dtCh= "/";
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	
	day=parseInt(strDay)
	
	year=parseInt(strYr)
	
	if (pos1==-1 || pos2==-1){
	//	alert("The date format should be : mm/dd/yyyy")
		strMonth="";
		strDay="";
		strYear="";
	//	return false
	}

eval("document.form1."+frm_type+"Day.value ="+ strDay);
eval("document.form1."+frm_type+"Month.value="+ strMonth);
eval("document.form1."+frm_type+"Year.value="+ strYear);
}

function openPopup(){
    dateValues();
    var city = document.form1.city.value;
    if(city == null){
      city = "";
     } 
   
   var country = document.form1.country.value;
   var stateProvince = document.form1.stateProvince.value;
   var cid = document.form1.cid.value;
   
   var adults = document.form1.adults.value;
   var children = document.form1.children.value;
   
   var numberOfRooms = document.form1.numberOfRooms.value;
   var currency = document.form1.CurrencyCode.value;
   var checkinday = document.form1.arrivalDay.value;
   var checkinMonth = calculateNewMonth(document.form1.arrivalMonth.value);
   var checkinYear = document.form1.arrivalYear.value;
   var checkoutday = document.form1.departureDay.value;
   var checkoutMonth = calculateNewMonth(document.form1.departureMonth.value);
   var checkoutYear = document.form1.departureYear.value;
   var datesInfo = "arrivalDay="+checkinday+"&arrivalMonth="+checkinMonth+"&arrivalYear="+checkinYear+"&departureDay="+checkoutday+"&departureMonth="+checkoutMonth+"&departureYear="+checkoutYear;
   
   var defaultUrl = "fc=list&pageName=hotSearch&locale=en_US&submitted=true&validateCity=true&passThrough=true&showHotels=true&showCondos=true&showPopUp=true&mode=2";
   
   var buildUrl="http://travel.ian.com/index.jsp?city="+city+"&country="+country+"&stateProvince="+
                  stateProvince+"&cid="+cid+"&numberOfRooms="+numberOfRooms+"&CurrencyCode="+currency+"&room-0-adult-total="+adults+"&room-0-child-total="+children+
                  "&"+datesInfo+"&"+defaultUrl ;
                                    
    window.open(buildUrl,"HotelSearch","resizable=1,width=800,height=500,status=yes,scrollbars=yes,location=1,toolbar=1");
      return;
   
}

function calculateNewMonth(month){
   month--;
   return month;
  }