var hotel_init = [];

function addHotelInit(hotel_id){
	hotel_init[hotel_init.length] = hotel_id;
}

function init_hotels(){
	if(hotel_init.length){
		for(var this_item = 0; this_item < hotel_init.length;this_item++){
			setdate(hotel_init[this_item]);
		}
	}
}

function zeroSearch(text_box){
	text_box.style.color = '#000';
	if(text_box.value == 'Search'){
		text_box.value = '';
	}
}


function setdate(form_id){
	thisForm = document.getElementById(form_id);
	if ( thisForm != null ) {
		var now = new Date();
		var checkinDate = new Date(now.getTime() + (14 * 24*60*60*1000));
		var checkoutDate = new Date(now.getTime() + (16 * 24*60*60*1000));
		thisForm.arrivalMonth.options[checkinDate.getMonth()].selected = true;
		thisForm.departureMonth.options[checkoutDate.getMonth()].selected = true;
		thisForm.arrivalDay.options[checkinDate.getDate()-1].selected = true;
		thisForm.departureDay.options[checkoutDate.getDate()-1].selected = true;
		updateSelect(thisForm.arrivalMonth, thisForm.arrivalDay);	
		updateSelect(thisForm.departureMonth, thisForm.departureDay);
	}
}


function isBrowserSupp() {
    version =  parseFloat( navigator.appVersion );
	if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    }
    else {
    	return true;
    }
	return true;
}

function isLeapYear(yrStr) {
	var leapYear=false;
	var year = parseInt(yrStr, 10);
	if (year%4 == 0) {
	    leapYear=true;
    	if (year%100 == 0) {
	        leapYear=false;
        	if (year%400 == 0) {
	            leapYear=true;
            }
        }
    }
	return leapYear;

}






function getDaysInMonth(mthIdx, YrStr) {
	var maxDays=31
	if (mthIdx==1) {
	    if (isLeapYear(YrStr)) {
	        maxDays=29;
        }
    	else {
	        maxDays=28;
        }
    }
	if (mthIdx==3 || mthIdx==5 || mthIdx==8 || mthIdx==10) {
	    maxDays=30;
    }
	return maxDays;
}

function getYear(mthIdx) {
	var today = new Date();
	var theYear = parseInt(today.getYear(),10)
	if (mthIdx < today.getMonth()) {
    	theYear = (parseInt(today.getYear(), 10) + 1)
	}
	if(theYear<100){
    	theYear = "19" + theYear
	}
	else {
    	if((theYear-100) < 10) {
        	theYear = "0" + (theYear-100)
    	}
    	else{
        	theYear = (theYear-100)+""
    	}
    	theYear = "20" + theYear
	}
	return theYear;
}

function adjustDate(mthIdx, Dt) {
	var value=0;
	var today = new Date()
	var theYear = getYear(mthIdx);

	var numDays=getDaysInMonth(mthIdx, theYear);
	if (mthIdx==1) {
	    if (Dt.options.selectedIndex + 1 < numDays) {
	        return 0;
        }
    	else {
        	Dt.options.selectedIndex=numDays - 1;
        	if (numDays==29) {
	            return 99;
            }
        	else {
            	return 1;
            }
        }
    }
	if (Dt.options.selectedIndex + 1 < numDays) {
    	value=0;
    }
	else {
    	if (Dt.options.selectedIndex + 1 > numDays) {
	        Dt.options.selectedIndex ;
       	 	value=3;
        }
    	else {
        	value=2;
        }
    }
	return value;
}

/*function dateChange(inM,inD,outM,outD) {
    if (!isBrowserSupp()) {
    	return;
    }
	var res = adjustDate(inM.options.selectedIndex, inD);
	if (res != 0) {
		outD.options.selectedIndex=0;
        if (outM.options.selectedIndex==11) {
        	outM.options.selectedIndex=0
		} else {
			outM.options.selectedIndex=inM.options.selectedIndex + 1;
        }
    } else {
    	outM.options.selectedIndex = inM.options.selectedIndex;
    	outD.options.selectedIndex = inD.options.selectedIndex+2;
    }
	return ;
}*/

function updateSelect(month, day) {
	var inDay = day.options.selectedIndex;
	var days = getDaysInMonth(month.options.selectedIndex, getYear(month.options.selectedIndex));
	day.options.length = 0;
	for (var i = 0; i < days; i++) {
		day.options[i] = new Option(i+1, i+1);
	}
	day.options[inDay].selected = true;
}

function dateChange(form_id) {
	if (!isBrowserSupp())
		return;
	
	var the_form = document.getElementById(form_id);
	
	var inM = the_form.arrivalMonth;
	var inD = the_form.arrivalDay;
	var outM = the_form.departureMonth;
	var outD = the_form.departureDay
			
	updateSelect(inM, inD);
		
	var theYear = getYear(inM.options.selectedIndex);
	var daysInMonth = getDaysInMonth(inM.options.selectedIndex, theYear);
	var difference = daysInMonth - (inD.options.selectedIndex + 2)

	outM.options.selectedIndex = inM.options.selectedIndex;
	if (difference <= 0) {
		if (inM.options.selectedIndex == 11)	
			outM.options.selectedIndex = 0;
		else
			outM.options.selectedIndex = inM.options.selectedIndex + 1;
		outD.options.selectedIndex = Math.abs(difference);
	} else {
		outD.options.selectedIndex = inD.options.selectedIndex + 2;
	}
	updateSelect(outM, outD);
	
	return;
}

function dmddChange(form_id) {
    if (!isBrowserSupp()) {
	    return;
    }
	var the_form = document.getElementById(form_id);
	adjustDate(the_form.departureMonth.options.selectedIndex,the_form.departureDay);
	return;
}

function focusTB(text_box_name){
	var target_box=document.getElementById(text_box_name);
	if(target_box != null){
		target_box.focus();
		target_box.select();
	} 
}

function setCookie(cookie_name,cookie_value,cookie_path,cookie_domain){
	cookie_path == null ? cookie_path = '/' : '';
	if(cookie_domain != null){
		document.cookie = cookie_name+'='+escape(cookie_value)+';path=' + cookie_path + ';domain=' + cookie_domain;
	} else{
		document.cookie = cookie_name+'='+escape(cookie_value)+';path=' + cookie_path;
	}
}

function forcast(){
	document.getElementById('flink').style.display = 'none';
	document.getElementById('forcast').style.display = 'block';
}

function setad(ad_txt){
	document.getElementById('adbox').innerHTML = ad_txt;
}