function get_value(formName,fieldName)
{
	return document.getElementById(fieldName).value;
}


function get_pull_val(formName,pullName)
{
	var this_val  = '';

	this_element = document.getElementById(pullName);
	
	if (!this_element) return false;
	
	for(i=0; i<this_element.length; ++i)
	{
		if(this_element.options[i].selected==true)
		{
 		 	 this_val = this_element.options[i].value;
		}
	}
	return this_val;
}


function openBooking(formName)
{
	var HotelId = get_pull_val(formName,'ddl_hotel');
	
	if (isNaN(parseInt(HotelId, 10)))
	{
		alert('Please select a Hotel');
		return false;
	}
	else
	{ 
		var bookingUrl = HotelUrl + get_pull_val(formName,'ddl_hotel');
		window.open(bookingUrl, '', '');
	}
}


function validate(formName)
{
	var dest = get_pull_val(formName,'ddl_destination');
	
	//if (isNaN(parseInt(dest, 10)))
	if ("" == dest)
	{
		alert('Please select a Destination');
		return false;
	}
	else
	{
		document.getElementById(formName).submit();
	}
}


function getUrl(formName)
{
	var dest = get_pull_val(formName,'ddl_destination');
	
	if (isNaN(parseInt(dest, 10)))
	{
		alert('Please select a Destination');
		return false;
	}
	else
	{
		var txtNumberNights = parseInt(get_value(formName,'txt_numberofnights'), 10);

		if (!(txtNumberNights > 1))
		{
			txtNumberNights = 2;
		}
		
		var varToday             = new Date();
		var varYear              = varToday.getYear();
		if (varYear < 2000) varYear += 1900;
		
		var ddlHotelId           = get_pull_val(formName,'ddl_hotel');
		var ddArrivalDateDay     = parseInt(get_pull_val(formName,'ddl_checkindate'), 10);
		var ddArrivalDateMonth   = get_pull_val(formName,'ddl_checkinyear');
		
		var ddArrivalDateDay2    = ddArrivalDateDay + txtNumberNights;
		var varDepartureDate     = new Date(varYear,ddArrivalDateMonth,ddArrivalDateDay2,0,0,0);
		var varDepartureDate2    = varYear+'-'+varDepartureDate.getMonth()+'-'+varDepartureDate.getDate();
		
		var bookingUrl           = HotelUrl + ddlHotelId + '&departure='+varDepartureDate2+'&arrival='+varYear+'-'+ddArrivalDateMonth+'-'+ddArrivalDateDay+'&Step=2';
		
		window.open(bookingUrl, '', '');
	}
}


function createRequestObject() 
{
    var ro;
    var browser = navigator.appName;
	
    if (browser == "Microsoft Internet Explorer")
	{
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }
	else
	{
        ro = new XMLHttpRequest();
    }
	
    return ro;
}


function sendReq(event_city) 
{
	http.open('get', '/ajax/hotels/?ddl_city='+event_city);
    http.onreadystatechange = handleResponse;
    http.send(null);
}


function dynamiccontent(elementid,content)
{
	el = document.getElementById(elementid);
	el.innerHTML = content;
}


function handleResponse() 
{
    if(http.readyState == 4)
	{
		if (http.status == 200) 
		{
			var response = http.responseText;
			dynamiccontent('ddl_hotel_ti', response);
		}
		else
		{
			dynamiccontent('ddl_hotel_ti', 'Cannot verify at this moment<br />');
		}
    }
	else
	{
		dynamiccontent('ddl_hotel_ti', 'Checking...<br />');
	}
}
