/************************************************************************************************************
	(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 = 300;
	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';		
	}

//======================================================================================================================
//======================================================================================================================
//======================================================================================================================
//=====buna - verificarea validitatii email-ului in mod corect============
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;
	}
}

//=====buna - intai verific daca data este mai mare decat data curenta
//=1==================================================================
//=apeleul functiei: dateisNotPossible(day,month,year,$lang["earliest_date"], user_type)
function dateisNotPossible(day, month, year, mes, mes2, user_type) 
{
	if(user_type == 'user')
	{
		//=====for all the usual users=====================
		var datePoss = new Date();
		datePoss.setTime(datePoss.getTime() + 2*(1000*3600*24));
	}
	else
	{
		//======for EwebInfoPRO users========
		var datePoss = new Date();
		datePoss.setTime(datePoss.getTime());
	}

	var dateReal = new Date();
	dateReal.setMonth(Number(month) - 1);
	dateReal.setYear(parseInt(year));
	dateReal.setDate(Number(day));

	if (dateReal.valueOf() < datePoss) {
	    var next_month = datePoss.getMonth() + 1;
		var date_tomorrow = datePoss.getDate()+'/'+next_month+'/'+datePoss.getFullYear();
		alert(mes + "(" + date_tomorrow + ")" + "\n" + mes2);
		return false;
	}
	return true;
}

//=======buna - pas 2- verific daca data este corecta(valida)=================================================================
//======2======================================================================================================================
//==========apelul este:  - function isDate(date, $lang["year_greater"], $lang["not_valid_date"], $lang["date_not_correct"])
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}$");
	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));

		var d = new Date();
		var current_year = d.getFullYear();
	
		if (theYear < current_year) {
			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;
		}
}	

//===============================================================
//=======buna pasul 3 - verific daca datele sunt ok(d2 > d1)
//===============================================================
//=apel functie: checkmyDates(day1,day2,month1,month2,year1,year2, $lang["later_first_date"], $lang["equal_first_date"])
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;
	}		


//=========the function returns the number of days between 2 dates=============
function get_no_days(firstdate, seconddate, firsttime, secondtime, grace_hours) {
date1 = new Date();
date2 = new Date();
diff  = new Date();

date1temp = new Date(firstdate + " " + firsttime);
date1.setTime(date1temp.getTime());

date2temp = new Date(seconddate + " " + secondtime);
date2.setTime(date2temp.getTime());

// sets difference date to difference of first date and second date
diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
timediff = diff.getTime();

days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
timediff -= days * (1000 * 60 * 60 * 24);

hours = Math.floor(timediff / (1000 * 60 * 60)); 
if(hours >= grace_hours)
{
	days++;
}

return days; 
}


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;
}

//=============functions added for SolCarHire======================================
//====added by Irina on 19 Nov 2009================================================
function check_quote(no_max_days, date_format, err_pick_up_date, err_drop_off_date, mes_date, mes_date_2, mes_isdate_1, mes_isdate_2, mes_isdate_3, mes1, mes2, mes3, mes4, mes5, days_mes, grace_hours, user_type)
{
	f = document.onlinequote;

	//check dates
	var date1String = f.pickup.value;
	var day1    = date1String.substr(0,2);
	var month1  = date1String.substr(3,2);
	var year1   = date1String.substr(6,4);
	var drawdate1String = month1+"/"+day1+"/"+year1;

	var date2String = f.dropoff.value;
	var day2    = date2String.substr(0,2);
	var month2  = date2String.substr(3,2);
	var year2   = date2String.substr(6,4);
	var drawdate2String = month2+"/"+day2+"/"+year2;


	var hour1String = f.pickup_time.value;
	var hour1		= hour1String.substr(0,2);
	var minute1		= hour1String.substr(3,2);
	var second1		= "00";
	var time1String = hour1String+":00";

	var hour2String = f.dropoff_time.value;
	var hour2		= hour2String.substr(0,2);
	var minute2		= hour2String.substr(3,2);
	var second2		= "00";
	var time2String = hour2String+":00";

	//====format de apelare a functiei: check_quote($global_additional_taxes["max_number_rental_days"],$lang["date_format"],$lang["choose_pickup_date"],$lang["choose_dropoff_date"],$lang["earliest_date"], $lang["year_greater"], $lang["not_valid_date"], $lang["date_not_correct"], $lang["later_first_date"], $lang["equal_first_date"], $lang["maximum_number_rental_days"])
	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, mes_date_2, user_type)==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, mes_date_2, user_type)==false) { f.dropoff.focus(); return false; }

	if (!checkmyDates(day1,day2,month1,month2,year1,year2, mes1, mes2)) {return false;}
	no_days = get_no_days(drawdate1String, drawdate2String, time1String, time2String, grace_hours);

	if(no_days > no_max_days)
	{
		alert(mes3 + '\n' + mes4 + ' ' + no_days + ' ' + days_mes + '.' + '\n' + mes5);
		f.dropoff.focus();
		return false;
	}
	f.submit();
	return true;
}

function checktxt(myobj,mes, mes2)
{
	if (myobj.value=='') {
		alert(mes);
		myobj.focus();
		return false;
	}
	if (myobj.value.length<2) {
		alert(mes2);
		myobj.focus();
		return false;
	}
	return true;

}

function ck_num(field)
{
	val = parseInt(field.value);
	if (isNaN(val)) 
	{
		field.focus();
		return false;
	}
	
	return true;
}

function ck_pos_num(field)
{
	val = parseInt(field.value);

	if (isNaN(val)) {
		field.focus();
		return false;
	}

	if (val>0) return true; 
		else 
	{
		field.focus();
		return false;
	}
}

function ck_not_float_pos_num(field)
{
	if (!Number(field.value)) 
	{
		field.focus();
		return false;
	}
	val = parseFloat(field.value);	
	if (val > 0) 
	{
		field.focus();
		return false;
	}
	else 
	{	
		return true;
	}
}


function check_booking(existing_client, first_name_js, first_name_js_2, last_name_js, last_name_js_2, age_js, age_min_js, select_a_country, mobile_js, pickup_flight_js, dropoff_flight_js, check_booking_agreement_js, min_drivers_age)
{
	f = document.onlinequote;

	if(existing_client == 0)
	{
		if(!checktxt(f.client_fname, first_name_js, first_name_js_2))
		{
			return false;
		}

		if(!checktxt(f.client_lname, last_name_js, last_name_js_2))
		{
			return false;
		}

		if((!ck_num(f.client_age)) || (!ck_pos_num(f.client_age)) || (ck_not_float_pos_num(f.client_age)))
		{
			alert(age_js);
			return false;
		}

		if(parseInt(f.client_age.value) < min_drivers_age)
		{
			alert(age_min_js);
			return false;
		}

		if(f.client_country_id.selectedIndex == 0)
		{
			alert(select_a_country);
			f.client_country_id.focus();
			return false;
		}

		if(!checktxt(f.client_mobile, mobile_js, mobile_js))
		{
			return false;
		}
	}

	if(f.pickup_location_airport.value == 'yes')
	{
		if(!checktxt(f.booking_flight_number, pickup_flight_js, pickup_flight_js))
		{
			return false;
		}
	}

	if(f.dropoff_location_airport.value == 'yes')
	{
		if(!checktxt(f.departure_flight_number, dropoff_flight_js, dropoff_flight_js))
		{
			return false;
		}
	}

	if(f.booking_agreement.checked == false)
	{
		alert(check_booking_agreement_js);
		f.booking_agreement.focus();
		return false;
	}

	f.submit();
	return true;	
}

function check_contact_form(err1, err2, err3, err4, err5, err6, err7, err8, err9)
{
	f = document.sendemail;

	if  (f.fullname.value=='') 
	{
		alert(err1);
		f.fullname.focus();
		return false;
	}
	
	if  (f.fullname.value.length<5) 
	{
		alert(err2);
		f.fullname.focus();
		return false;
	}
	
	if (f.email.value=='')
	{
		alert(err3);
		f.email.focus();
		return false;
	}

	if(!emailck(f.email,err9))
	{
		return false;
	}
	
	
	if  ((f.mysubject.value=='')) 
	{
		alert(err4);
		f.mysubject.focus();
		return false;
	}
	
	if  ((f.mysubject.value.length<5)) 
	{
		alert(err5);
		f.mysubject.focus();
		return false;
	}
	
	if  ((f.mymessage.value=='')) 
	{
		alert(err6);
		f.mymessage.focus();
		return false;
	}
	
	if  ((f.mymessage.value.length<5)) 
	{
		alert(err7);
		f.mymessage.focus();
		return false;
	}

	/*if  ((f.img_check.value.length != 5)) 
	{
		alert(err8);
		f.img_check.focus();
		return false;
	}*/

	f.submit();
	return true;
}

//=====drawing functions=========================================================================
function change_bullet(bullet_id, mod, allhttproot)
{
	if(mod == 1)
	{
		document.getElementById(bullet_id).src = allhttproot+"images/solmar/solmar_bullet_on.jpg";
	}
	else
	{
		document.getElementById(bullet_id).src = allhttproot+"images/solmar/solmar_bullet.jpg";
	}
	
	return true;
}

function change_menu_item(menu_item_name)
{
	cnt = document.getElementById("nr_menu_items").value;
	for(i = 1; i <= cnt; i++)
	{
		k = menu_item_name;
		z = menu_item_name-1;
		if(i != menu_item_name)
		{
			document.getElementById("td_"+i+"_1").className = "top_item_left";
			document.getElementById("td_"+i+"_2").className = "top_item_left";
			document.getElementById("td_"+i+"_3").className = "top_item_left";
			document.getElementById("td_"+i+"_4").className = "menu_link";
		}
		else
		{
			if(document.getElementById("td_"+menu_item_name+"_1").className == "top_item_left")
			{
				document.getElementById("td_"+menu_item_name+"_1").className = "menu_tab_left";
				document.getElementById("td_"+menu_item_name+"_2").className = "menu_tab_bg";
				document.getElementById("td_"+menu_item_name+"_3").className = "menu_tab_right";
				document.getElementById("td_"+menu_item_name+"_4").className = "menu_link_2";	
			}
			else
			{
				document.getElementById("td_"+menu_item_name+"_1").className = "top_item_left";
				document.getElementById("td_"+menu_item_name+"_2").className = "top_item_left";
				document.getElementById("td_"+menu_item_name+"_3").className = "top_item_left";
				document.getElementById("td_"+menu_item_name+"_4").className = "menu_link";
			}

			
		}
		if(k <= cnt)
		{
			document.getElementById("div_"+k).innerHTML = "";
		}
		if(z)
		{
			document.getElementById("div_"+z).innerHTML = "";
		}
	}

	return true;
}

