function toggleOff(id) {
	var winID = document.getElementById(id);
	winID.style.display = 'none';
}

function toggleOn(id) {
	var winID = document.getElementById(id);
	winID.style.display = 'block';
}

function clearText(field){
    if (field.defaultValue == field.value)
		field.value = '';
    else if (field.value == '')
		field.value = field.defaultValue;
} 

function toggle(id) {
   	var winID = document.getElementById(id);
   	if(winID.style.display == 'block') {
		winID.style.display = 'none';
	}
	else{
   		winID.style.display = 'block';
	}
}

function gotoPage(strType, strPosition){
	var objElement = document.formResults.elements['cmbPage' + strPosition];
	
	if(strType == "next"){
		var intPage = objElement.options[objElement.selectedIndex].value;
		intPage++;
	}
	else if(strType == "previous"){
		var intPage = objElement.options[objElement.selectedIndex].value;
		intPage--;
	}
	else if(strType == "select"){
		var intPage = objElement.options[objElement.selectedIndex].value;
	}
		
	document.formResults.intPage.value = intPage;
	document.formResults.submit();
}

function bookAccommodation(lngID, strVirtualDir, strLanguage){
	document.location.href = strVirtualDir + '/' + strLanguage + '/booking_calendar.php/' + lngID;
}

function infoAccommodation(lngID, intType, strVirtualDir, strLanguage){
	if(intType == 1)
		document.location.href = strVirtualDir + '/' + strLanguage + '/apartment.php/' + lngID;
	else
		document.location.href = strVirtualDir + '/' + strLanguage + '/villa.php/' + lngID;
}

function gotoPreviousPage(strType, lngID, strVirtualDir, strLanguage, strLastpage){
	if(strLastpage == undefined) strLastpage = '';
	
	if(strType == 'calendar'){
		document.location.href = strVirtualDir + '/' + strLanguage + '/booking_calendar.php';
	}
	else if(strType == 'accommodation'){
		if(strLastpage == '/apartment.php')
			document.location.href = strVirtualDir + '/' + strLanguage + '/apartment.php/' + lngID;
		else if(strLastpage == '/apartments.php')
			document.location.href = strVirtualDir + '/' + strLanguage + '/apartments.php';		
		else if(strLastpage == '/villas.php')
			document.location.href = strVirtualDir + '/' + strLanguage + '/villas.php';
		else
			document.location.href = strVirtualDir + '/' + strLanguage + '/results.php';
	}
	else if(strType == 'details'){
		document.location.href = strVirtualDir + '/' + strLanguage + '/booking_details.php';
	}
	else if(strType == 'overview'){
		document.location.href = strVirtualDir + '/' + strLanguage + '/booking_overview.php';
	}
	else if(strType == 'contactinfo'){
		document.location.href = strVirtualDir + '/' + strLanguage + '/booking_contactinfo.php';
	}
}

function transferCheck(){
	for(var intCount = 0; intCount < document.Formulier.elements.length; intCount++){
		if(document.Formulier.elements[intCount].name == 'lOptionID[]' && document.Formulier.elements[intCount].value == "2"){
			//we have transfer option on the form....
			if(document.Formulier.elements[intCount].checked && document.Formulier.lAirportID.selectedIndex == 0)
				return false;
			else
				return true;
		}
	}
	return true;
}

function checkTitle(){
	var intCount = document.Formulier.elements['sTitle[]'].length;
	var blnFound = false;
	
	for(var i=0; i<intCount; i++){
		if(document.Formulier.elements['sTitle[]'][i].checked == true){
			blnFound = true;
			break;
		}
	}
	return blnFound;
}

function CheckEmailAddress(emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	  //  alert("The username doesn't seem to be valid.")
	    return false
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        //alert("Destination IP address is invalid!")
			return false
		    }
	    }
	    return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
	    return false
	}
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	  // alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   //alert(errStr)
	   return false
	}
	
	return true;
}

function prevCal(intMonth, intYear, lngAccomodationID){
	var strParams = 'startMonth=' + intMonth;
	strParams += '&startYear=' + intYear;
	strParams += '&AccomodationID=' + lngAccomodationID;
	
	ajaxRequest("calendar", "showavailable", strParams);
}

function nextCal(intMonth, intYear, lngAccomodationID){
	var strParams = 'startMonth=' + intMonth;
	strParams += '&startYear=' + intYear;
	strParams += '&AccomodationID=' + lngAccomodationID;
	
	ajaxRequest("calendar", "showavailable", strParams);
}

function updateAirportPrice(objSelect, lngAccomodation){
	var lngValue = objSelect.options[objSelect.selectedIndex].value;
	var strParams = 'AirportID=' + lngValue;
	strParams += '&AccomodationID=' + lngAccomodation;
	
	ajaxRequest("airport", "price", strParams);
}

function updateAirportPrice_ajax(strPrice){
	document.getElementById('dTransfer').value = strPrice;
	
	if(unescape(strPrice) != '') strPrice = '&euro; ' + unescape(strPrice);
	
	document.getElementById('airportPrice').innerHTML = strPrice;
}

function selectAirport(objCheckbox){
	if(objCheckbox.checked){
		document.Formulier.lAirportID.disabled = false;
	}
	else{
		document.getElementById('airportPrice').innerHTML = '';
		document.getElementById('dTransfer').value = '';
		document.Formulier.lAirportID.selectedIndex = 0;
		document.Formulier.lAirportID.disabled = true;
	}
}

function updateDepartureDate(){
	var strParams = 'sDateDay=' + document.availability.avl_arrival_day.options[document.availability.avl_arrival_day.selectedIndex].value;
	strParams += '&sDateMonthYear=' + document.availability.avl_arrival_monthyear.options[document.availability.avl_arrival_monthyear.selectedIndex].value;
	
	ajaxRequest('departure', 'update', strParams);
}

function fillDeparture(strDate){
	strDate = unescape(strDate);
	var arrDate = strDate.split("-");
	var intCount = 0;
	
	for(intCount=0; intCount<document.availability.avl_departure_day.options.length; intCount++){
		if(document.availability.avl_departure_day.options[intCount].value == parseInt(arrDate[2])){
			document.availability.avl_departure_day.selectedIndex = intCount;
			break;
		}
	}
	for(intCount=0; intCount<document.availability.avl_departure_monthyear.options.length; intCount++){
		if(document.availability.avl_departure_monthyear.options[intCount].value == parseInt(arrDate[1]) + ' ' + arrDate[0]){
			document.availability.avl_departure_monthyear.selectedIndex = intCount;
			break;
		}
	}
}