
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 compare_dates(day1,month1,year1,day2,month2,year2) 
{
	var dateReal_1 = new Date();
	var dateReal_2 = new Date();

	dateReal_1.setMonth(month1 - 1);
	dateReal_1.setYear(parseInt(year1));
	dateReal_1.setDate(parseInt(day1));

	
	dateReal_2.setMonth(month2 - 1);
	dateReal_2.setYear(parseInt(year2));
	dateReal_2.setDate(parseInt(day2));

	if (dateReal_2.valueOf() < dateReal_1.valueOf())
	{
		return -1;
	}
	else if (dateReal_2.valueOf() == dateReal_1.valueOf())
	{
		return 0;
	}
	else
	{
		return 1;
	}
	return true;
}
			
			function isDate2(dtStr){
				var myRegex = new RegExp("^([0-2][0-9]|[3][0-1])\/([0][0-9]|[1][0-2])\/[0-9]{4}$");
				
				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 ("The year have to be greater then 2004.");
						return false;
						}
					else if ((theYear%4 == 0) && (theDay > 29) && (theMonth == 2)) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else if ((theYear%4 != 0) && (theDay > 28) && (theMonth == 2)) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else if ((theDay > 30) && ((theMonth == 0) || (theMonth == 4) || (theMonth == 6) || (theMonth == 9) || (theMonth == 11) )) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else {
						return true;
						}
					}
				else
					{
					alert ("Date not in correct dd/mm/yyyy format of the date specified does not exist.");
					return false;
					}
				
			
			}	
			
function checkmyDates(day1,day2,month1,month2,year1,year2, mes1, mes2) {
			
		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;
				}
				if (parseFloat(day1) == parseFloat(day2)) {
					alert(mes2);
					return false;
				}
			}
		}
	return true;
	}		

	function checkmyDates_ajax(pickup, dropoff) 
	{
		var date1String = pickup;
		var day1    = date1String.substr(0,2);
		var month1  = date1String.substr(3,2);
		var year1   = date1String.substr(6,4);

		var date2String = dropoff;
		var day2    = date2String.substr(0,2);
		var month2  = date2String.substr(3,2);
		var year2   = date2String.substr(6,4);
			
		if (parseFloat(year1) > parseFloat(year2)) {
			return false;
		}
		if (parseFloat(year1) == parseFloat(year2)) {
			if (parseFloat(month1) > parseFloat(month2)) {
 				return false;
			}
			if (parseFloat(month1) == parseFloat(month2)) {
				if (parseFloat(day1) > parseFloat(day2)) {
					return false;
				}
				if (parseFloat(day1) == parseFloat(day2)) {
					return false;
				}
			}
		}
	return true;
	}		
	
	function mindatePossible(day,month,year) {
		var datePoss = new Date().valueOf() + 86400000;
		var dateReal = new Date();
		dateReal.setMonth(month - 1);
		dateReal.setYear(parseInt(year));
		dateReal.setDate(parseInt(day));
		//if (dateReal.valueOf() < datePoss) { alert("Earliest possible date of service is 1 day from now. You specify the date: "+day+"-"+month+"-"+year+"  "+dateReal);	return false; }
		return true;
	}
	
	function myisDate(dtStr){
				var myRegex = new RegExp("^([0-2][0-9]|[3][0-1])\/([0][0-9]|[1][0-2])\/[0-9]{4}$");
				
				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 ("The year have to be greater then 2004.");
						return false;
						}
					else if ((theYear%4 == 0) && (theDay > 29) && (theMonth == 2)) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else if ((theYear%4 != 0) && (theDay > 28) && (theMonth == 2)) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else if ((theDay > 30) && ((theMonth == 0) || (theMonth == 4) || (theMonth == 6) || (theMonth == 9) || (theMonth == 11) )) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else {
						return true;
						}
					}
				else
					{
					alert ("Date not in correct dd/mm/yyyy format of the date specified does not exist.");
					return false;
					}
				
			
			}
	

function calculate_price_check(err_car_id, err_pick_up, err_drop_off, err_pick_up_date, err_drop_off_date, err_diff_date, mes1, mes2, mes_date, mes_isdate_1, mes_isdate_2, mes_isdate_3, date_format)
{
	f = document.onlinequote;

	
	
	//var error = $("company_id"); 
	if (isNaN(f.location_from.value) || (f.location_from.value==0)) 
	{ 
		alert(err_pick_up);
		f.location_from.focus(); 
		return false;
	}

	if (isNaN(f.location_to.value) || (f.location_to.value==0)) 
	{ 
		alert(err_drop_off);
		f.location_to.focus(); 
		return false;
	}

	if(isNaN(f.car_id.value) || (f.car_id.value == 0))
	{
		alert(err_car_id);
		f.car_id.focus(); 
		return false;
	}
	var date1String = f.pickup.value;
	var day1    = date1String.substr(0,2);
	var month1  = date1String.substr(3,2);
	var year1   = date1String.substr(6,4);

	var date2String = f.dropoff.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.pickup.value='';
		f.pickup.focus();
		return false;
	}

	if (isDate(date1String, mes_isdate_1, mes_isdate_2, mes_isdate_3)==false) { f.pickup.focus(); return false; }
	if (dateisNotPossible(day1,month1,year1,mes_date)==false) { f.pickup.focus(); return false; }	

	if ((date2String==date_format) || (date2String=='')) 
	{
		alert(err_drop_off_date);
		f.dropoff.value='';
		f.dropoff.focus();
		return false;
	}

	if (isDate(date2String, mes_isdate_1, mes_isdate_2, mes_isdate_3)==false) { f.dropoff.focus(); return false; }
	if (dateisNotPossible(day2,month2,year2,mes_date)==false) { f.dropoff.focus(); return false; }

	if(date1String == date2String)
	{
		alert(err_diff_date);
		f.dropoff.focus();
		return false;
	}


	if (!checkmyDates(day1,day2,month1,month2,year1,year2, mes1, mes2)) {return false;}


	//calculate_price();

	return true;
}

function onlinequote_check(err_car_id, err_pick_up, err_drop_off, err_pick_up_date, err_drop_off_date, err_diff_date, mes1, mes2, mes_date, mes_isdate_1, mes_isdate_2, mes_isdate_3, date_format, mes_valid_email)
{
	
	if(!calculate_price_check(err_car_id, err_pick_up, err_drop_off, err_pick_up_date, err_drop_off_date, err_diff_date, mes1, mes2, mes_date, mes_isdate_1, mes_isdate_2, mes_isdate_3, date_format))
	{
		return false;
	}

	return true;
}


function myonlinequote_check(err_car_id, err_pick_up, err_drop_off, err_pick_up_date, err_drop_off_date, err_diff_date, mes1, mes2, mes_date, mes_isdate_1, mes_isdate_2, mes_isdate_3, date_format, mes_valid_email)
{
	f = document.onlinequote;
	f.final_price.value = "yes";
	if(!calculate_price_check(err_car_id, err_pick_up, err_drop_off, err_pick_up_date, err_drop_off_date, err_diff_date, mes1, mes2, mes_date, mes_isdate_1, mes_isdate_2, mes_isdate_3, date_format, mes_valid_email))
	{
		return false;
	}

	if (!emailck(f.email, mes_valid_email)) 
	{
		return false;
	}
	f.email_valid.value = 'yes';

	calculate_price();
	return true;
}

function change_currency(rate)
{
	f = document.onlinequote;

	if(f.totalprice_euro.value > 0)
	{
		if(f.currency.value == 'gbp' && f.current_currency.value == 'euro')
		{
			f.total_price.value = Math.round((f.totalprice_euro.value / rate) * 100) / 100;
		}

		if(f.currency.value == 'euro' && f.current_currency.value == 'gbp')
		{
			f.total_price.value = f.totalprice_euro.value;
		}
		f.current_currency.value = f.currency.value;
	}
	else
	{
		if(f.currency.value == 'gbp')
		{
			f.currency.value = 'euro';
		}
	}
	return true;
}




//=======================================================================================
//======================START HERE we include the code previous in functions.js================
//=======================================================================================
function show_box(i)
{
	document.getElementById("left_"+i).className = "menu_box_left_2";
	document.getElementById("middle_"+i).className = "menu_box_line_2";
	document.getElementById("right_"+i).className = "menu_box_right_2";
}

function hide_box(i)
{
	document.getElementById("left_"+i).className = "menu_box_left";
	document.getElementById("middle_"+i).className = "menu_box_line";
	document.getElementById("right_"+i).className = "menu_box_right";
}


/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Updated:	
		March, 11th, 2006 - Fixed positioning of tooltip when displayed near the right edge of the browser.
		April, 6th 2006, Using iframe in IE in order to make the tooltip cover select boxes.
		
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
	var dhtmlgoodies_tooltip = false;
	var dhtmlgoodies_tooltipShadow = false;
	var dhtmlgoodies_shadowSize = 4;
	var dhtmlgoodies_tooltipMaxWidth = 200;
	var dhtmlgoodies_tooltipMinWidth = 100;
	var dhtmlgoodies_iframe = false;
	var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;
	function showTooltip(e,tooltipTxt)
	{
		
		var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;
	
		if(!dhtmlgoodies_tooltip){
			dhtmlgoodies_tooltip = document.createElement('DIV');
			dhtmlgoodies_tooltip.id = 'dhtmlgoodies_tooltip';
			dhtmlgoodies_tooltipShadow = document.createElement('DIV');
			dhtmlgoodies_tooltipShadow.id = 'dhtmlgoodies_tooltipShadow';
			
			document.body.appendChild(dhtmlgoodies_tooltip);
			document.body.appendChild(dhtmlgoodies_tooltipShadow);	
			
			if(tooltip_is_msie){
				dhtmlgoodies_iframe = document.createElement('IFRAME');
				dhtmlgoodies_iframe.frameborder='5';
				dhtmlgoodies_iframe.style.backgroundColor='#FFFFFF';
				dhtmlgoodies_iframe.src = '#'; 	
				dhtmlgoodies_iframe.style.zIndex = 100;
				dhtmlgoodies_iframe.style.position = 'absolute';
				document.body.appendChild(dhtmlgoodies_iframe);
			}
			
		}
		
		dhtmlgoodies_tooltip.style.display='block';
		dhtmlgoodies_tooltipShadow.style.display='block';
		if(tooltip_is_msie)dhtmlgoodies_iframe.style.display='block';
		
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
		var leftPos = e.clientX + 10;
		
		dhtmlgoodies_tooltip.style.width = null;	// Reset style width if it's set 
		dhtmlgoodies_tooltip.innerHTML = tooltipTxt;
		dhtmlgoodies_tooltip.style.left = leftPos + 'px';
		dhtmlgoodies_tooltip.style.top = e.clientY + 10 + st + 'px';

		
		dhtmlgoodies_tooltipShadow.style.left =  leftPos + dhtmlgoodies_shadowSize + 'px';
		dhtmlgoodies_tooltipShadow.style.top = e.clientY + 10 + st + dhtmlgoodies_shadowSize + 'px';
		
		if(dhtmlgoodies_tooltip.offsetWidth>dhtmlgoodies_tooltipMaxWidth){	/* Exceeding max width of tooltip ? */
			dhtmlgoodies_tooltip.style.width = dhtmlgoodies_tooltipMaxWidth + 'px';
		}
		
		var tooltipWidth = dhtmlgoodies_tooltip.offsetWidth;		
		if(tooltipWidth<dhtmlgoodies_tooltipMinWidth)tooltipWidth = dhtmlgoodies_tooltipMinWidth;
		
		
		dhtmlgoodies_tooltip.style.width = tooltipWidth + 'px';
		dhtmlgoodies_tooltipShadow.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
		dhtmlgoodies_tooltipShadow.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';		
		
		if((leftPos + tooltipWidth)>bodyWidth){
			dhtmlgoodies_tooltip.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
			dhtmlgoodies_tooltipShadow.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + dhtmlgoodies_shadowSize) + 'px';
		}
		
		if(tooltip_is_msie){
			dhtmlgoodies_iframe.style.left = dhtmlgoodies_tooltip.style.left;
			dhtmlgoodies_iframe.style.top = dhtmlgoodies_tooltip.style.top;
			dhtmlgoodies_iframe.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
			dhtmlgoodies_iframe.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';
		
		}
				
	}
	
	function hideTooltip()
	{
		dhtmlgoodies_tooltip.style.display='none';
		dhtmlgoodies_tooltipShadow.style.display='none';		
		if(tooltip_is_msie)dhtmlgoodies_iframe.style.display='none';		
	}
//=======================================================================================
//======================END HERE we include the code previous in functions.js================
//=======================================================================================


//===================================
function show_calendar()
{
	if(document.getElementById("div_calendar").style.display == "none")
	{
		document.getElementById("div_calendar").style.display = "inline";
		document.getElementById("div_period").style.display = "none";
	}
	else
	{
		document.getElementById("div_calendar").style.display = "none";
		document.getElementById("div_period").style.display = "block";
	}
}

//========================================================================================================
function check_price_faro(err_pick_up_date, err_drop_off_date, err_diff_date, mes1, mes2, mes_date, mes_isdate_1, mes_isdate_2, mes_isdate_3, date_format)
{
	f = document.onlinequote;

	var date1String = f.pickup.value;
	var day1    = date1String.substr(0,2);
	var month1  = date1String.substr(3,2);
	var year1   = date1String.substr(6,4);

	var date2String = f.dropoff.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.pickup.value='';
		f.pickup.focus();
		return false;
	}

	if (isDate(date1String, mes_isdate_1, mes_isdate_2, mes_isdate_3)==false) { f.pickup.focus(); return false; }
	if (dateisNotPossible(day1,month1,year1,mes_date)==false) { f.pickup.focus(); return false; }	

	if ((date2String==date_format) || (date2String=='')) 
	{
		alert(err_drop_off_date);
		f.dropoff.value='';
		f.dropoff.focus();
		return false;
	}

	if (isDate(date2String, mes_isdate_1, mes_isdate_2, mes_isdate_3)==false) { f.dropoff.focus(); return false; }
	if (dateisNotPossible(day2,month2,year2,mes_date)==false) { f.dropoff.focus(); return false; }

	if(date1String == date2String)
	{
		alert(err_diff_date);
		f.dropoff.focus();
		return false;
	}


	if (!checkmyDates(day1,day2,month1,month2,year1,year2, mes1, mes2)) {return false;}
	
	f.submit();

	return true;
}