
function open_window(url,win_name,features) 
{ 
  window.open(url,win_name,features);
}

function emailck(field, alert_str)
{
	var str = field.value;
	//alert(str);
	if (window.RegExp) {
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp(reg1str);
		var reg2 = new RegExp(reg2str);
		if (!reg1.test(str) && reg2.test(str)) {
			return true;
		}
		if(alert_str.length>0)
			alert(alert_str);
		field.select();
		return false;
	} else {
		if(str.indexOf("@") >= 0)
		{
			return true;
		}
		if(alert_str.length>0)
			alert(alert_str);
		field.select();
		return false;
	}
}

function isDate(dtStr, mes1, mes2, mes3)
{
	var myRegex = new RegExp("^([0-2][0-9]|[3][0-1])\/([0][0-9]|[1][0-2])\/[0-9]{4}$");
	//var myRegex2 = new RegExp("^([0-2][0-9]|[3][0-1])\.([0][0-9]|[1][0-2])\.[0-9]{4}$");
	// || (dtStr.match(myRegex2))
	if (dtStr.match(myRegex))
		{//valid date format, check for valid date dd/mm/yyyy
		var theDay = Math.round(dtStr.substr(0,2));
		var theMonth = Math.round(dtStr.substr(3,2));
		var theYear = Math.round(dtStr.substr(6,4));
		
		if (theYear< 2005) {
			alert (mes1);
			return false;
			}
		else if ((theYear%4 == 0) && (theDay > 29) && (theMonth == 2)) {
			alert (mes2);
			return false;
			}
		else if ((theYear%4 != 0) && (theDay > 28) && (theMonth == 2)) {
			alert (mes2);
			return false;
			}
		else if ((theDay > 30) && ((theMonth == 0) || (theMonth == 4) || (theMonth == 6) || (theMonth == 9) || (theMonth == 11) )) {
			alert (mes2);
			return false;
			}
		else {
			return true;
			}
		}
	else
		{
		alert (mes3);
		return false;
		}
	

}	

function dateisNotPossible(day,month,year, mes) {


	var datePoss = new Date().valueOf();
	var dateReal = new Date();
	dateReal.setMonth(Number(month) - 1);
	dateReal.setYear(parseInt(year));
	dateReal.setDate(Number(day));

	if (dateReal.valueOf() < datePoss) {
		alert(mes+day+"-"+month+"-"+year);
		return false;
	}
	return true;
}


function checkmyDates(day1,day2,month1,month2,year1,year2, mes1) {
			
		if (parseFloat(year1) > parseFloat(year2)) {
			alert(mes1);
			return false;
		}
		if (parseFloat(year1) == parseFloat(year2)) {
			if (parseFloat(month1) > parseFloat(month2)) {
				alert(mes1);
 				return false;
			}
			if (parseFloat(month1) == parseFloat(month2)) {
				if (parseFloat(day1) > parseFloat(day2)) {
					alert(mes1);
					return false;
				}
			}
		}
	return true;
	}		


function onlinequote_check(err_pick_up, err_drop_off, err_pick_up_date, err_drop_off_date, mes1, mes_date, mes_isdate_1, mes_isdate_2, mes_isdate_3, date_format, valid_email)
{
	f = document.book_clubs;
	
	//var error = $("company_id"); 
	if (f.delivery_location.value==0) 
	{ 
		alert(err_pick_up);
		f.delivery_location.focus(); 
		return false;
	}

	if (f.collection_location.value==0) 
	{ 
		alert(err_drop_off);
		f.collection_location.focus(); 
		return false;
	}
	var date1String = f.delivery_date.value;
	var day1    = date1String.substr(0,2);
	var month1  = date1String.substr(3,2);
	var year1   = date1String.substr(6,4);



	var date2String = f.collection_date.value;
	var day2    = date2String.substr(0,2);
	var month2  = date2String.substr(3,2);
	var year2   = date2String.substr(6,4);



	
	if ((date1String==date_format) || (date1String=='')) 
	{
		alert(err_pick_up_date);
		f.delivery_date.value='';
		f.delivery_date.focus();
		return false;
	}

	if (isDate(date1String, mes_isdate_1, mes_isdate_2, mes_isdate_3)==false) { f.delivery_date.focus(); return false; }
	if (dateisNotPossible(day1,month1,year1,mes_date)==false) { f.delivery_date.focus(); return false; }	

	if ((date2String==date_format) || (date2String=='')) 
	{
		alert(err_drop_off_date);
		f.collection_date.value='';
		f.collection_date.focus();
		return false;
	}

	if (isDate(date2String, mes_isdate_1, mes_isdate_2, mes_isdate_3)==false) { f.collection_date.focus(); return false; }
	if (dateisNotPossible(day2,month2,year2,mes_date)==false) { f.collection_date.focus(); return false; }

	if (!checkmyDates(day1,day2,month1,month2,year1,year2, mes1)) {f.collection_date.focus(); return false;}

	if (!emailck(f.email, valid_email)) { return false; }
	
	getagentids();
	f.submit();
	return true;

}

function check_personal_info()
{
	f = document.book_personal;

	if(f.pickup_address.value.length < 3)
	{
		alert("Please fill in the delivery address.The address must be at least 3 characters length.");
		f.pickup_address.focus();
		return false;
	}

	if(f.dropoff_address.value.length < 3)
	{
		alert("Please fill in the collection address.The address must be at least 3 characters length.");
		f.dropoff_address.focus();
		return false;
	}

	if(f.new_client.value == 1)
	{
		//if the client is new, we have to check his personal data
		if(f.first_name.value.length < 3)
		{
			alert("Please fill in the First Name.The First Name must be at least 3 characters length.");
			f.first_name.focus();
			return false;
		}

		if(f.last_name.value.length < 3)
		{
			alert("Please fill in the Last Name.The Last Name must be at least 3 characters length.");
			f.last_name.focus();
			return false;
		}

		if(f.country.value == 0)
		{
			alert("Please select the country.");
			f.country.focus();
			return false;
		}

		if(f.telephone.value.length < 3)
		{
			alert("Please fill in the telephone.The telephone must be at least 3 characters length.");
			f.telephone.focus();
			return false;
		}


		if(f.mobile.value.length < 3)
		{
			alert("Please fill in the mobile phone.The mobile must be at least 3 characters length.");
			f.mobile.focus();
			return false;
		}
		
		if(f.agree.checked == false)
		{
			alert("Please read and check the terms and conditions box before you complete the booking.");
			f.agree.focus();
			return false;
		}
	}

	f.submit();
	return true;
}

function check_contact_form()
{
	f = document.contact_form;

	if(f.name.value.length < 3)
	{
		alert("Please fill in the full name.The name must be at least 3 characters length.");
		f.name.focus();
		return false;
	}

	if (!emailck(f.email, "Please enter a valid email.")) { return false; }

	if(f.subject.value.length < 3)
	{
		alert("Please fill in the subject.The subject must be at least 3 characters length.");
		f.subject.focus();
		return false;
	}

	if(f.message.value.length < 3)
	{
		alert("Please fill in the message.The message must be at least 3 characters length.");
		f.message.focus();
		return false;
	}

	f.submit();
	return true;

}