function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else
		if (obj.x)
			curleft += obj.x;

	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else
		if (obj.y)
			curtop += obj.y;

	return curtop;
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   if ((version >= 5.5) && (version < 7) && (document.body.filters))
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>"
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
}

function add_partner()
{
	if(document.add_cat.name.value == "")
	{
		alert('Please enter the partners name!');
		document.add_cat.name.focus();
	}
	else if(document.add_cat.foto.value == "")
	{
		alert('Please select an image for this partner!');
		document.add_cat.foto.focus();
	}
	else if(document.add_cat.url.value == "")
	{
		alert('Please enter the URL for this partner!');
		document.add_cat.url.focus();
	}
	else
	{
		document.add_cat.submit();
	}
}

function edit_partner()
{
	if(document.add_cat.name.value == "")
	{
		alert('Please enter the partners name!');
		document.add_cat.name.focus();
	}
	else if(document.add_cat.url.value == "")
	{
		alert('Please enter the URL for this partner!');
		document.add_cat.url.focus();
	}
	else
	{
		document.add_cat.submit();
	}
}

function add_link()
{
	if(document.add_cat.name.value == "")
	{
		alert('Please enter the partners name!');
		document.add_cat.name.focus();
	}
	else if(document.add_cat.url.value == "")
	{
		alert('Please enter the URL for this partner!');
		document.add_cat.url.focus();
	}
	else
	{
		document.add_cat.submit();
	}
}

function edit_lg()
{
	if(document.add_cat.ro.value == "")
	{
		alert('Please enter the RO translation!');
		document.add_cat.ro.focus();
	}
	else if(document.add_cat.hu.value == "")
	{
		alert('Please enter the HU translation!');
		document.add_cat.hu.focus();
	}
	else if(document.add_cat.en.value == "")
	{
		alert('Please enter the EN translation!');
		document.add_cat.en.focus();
	}
	else if(document.add_cat.de.value == "")
	{
		alert('Please enter the DE translation!');
		document.add_cat.de.focus();
	}
	else if(document.add_cat.fr.value == "")
	{
		alert('Please enter the FR translation!');
		document.add_cat.fr.focus();
	}
	else
	{
		document.add_cat.submit();
	}
}

function days_in_month(month)
{
	switch(month)
	{
		case"01": days_in = 31;
		case"02": days_in = 28;
		case"03": days_in = 31;
		case"04": days_in = 30;
		case"05": days_in = 31;
		case"06": days_in = 30;
		case"07": days_in = 31;
		case"08": days_in = 31;
		case"09": days_in = 30;
		case"10": days_in = 31;
		case"11": days_in = 30;
		case"12": days_in = 31;
	}
	return days_in;
}

function update_difference()
{
	y_start = document.reservation.year.value;
	m_start = document.reservation.month.value;
	d_start = document.reservation.day.value;

	y_now = document.reservation.year1.value;
	m_now = document.reservation.month1.value;
	d_now = document.reservation.day1.value;

	years = y_now-y_start;
	months = m_now-m_start;
	days = d_now-d_start;

	days_inside = 0;
	if(months == 1)
	{
		days_inside = days_in_month(m_start);
	}
	else
	{
		if(months != 0)
		{
			for(i=m_start; i<m_end; i++)
			{
				days_inside=days_inside+days_in_month(i);
			}
		}
		else
		{
			days_inside = 0;
		}
	}

	days_total = ((years * 365) + (days_inside) + days)*(-1);
	//alert(days_total);
	document.reservation.difference.value = days_total;
}

function calc_items(type)
{
	days_total = document.getElementById("number_of_days").value;

	//FORD FIESTA 2007
	if(type == "1")
	{
		if((days_total>=1) && (days_total<=3))
		{
			price_per_day = 35;
		}
		else if((days_total>=4) && (days_total<=7))
		{
			price_per_day = 30;
		}
		else if((days_total>=8) && (days_total<=15))
		{
			price_per_day = 25;
		}
		else if(days_total>15)
		{
			price_per_day = 20;
		}
		else
		{
			price_per_day = 0;
		}
	}
	else
	//OPEL CORSA ENJOY 2007
	 if(type == "2")
	{
		if((days_total>=1) && (days_total<=3))
		{
			price_per_day = 40;
		}
		else if((days_total>=4) && (days_total<=7))
		{
			price_per_day = 35;
		}
		else if((days_total>=8) && (days_total<=15))
		{
			price_per_day = 30;
		}
		else if(days_total>15)
		{
			price_per_day = 25;
		}
		else
		{
			price_per_day = 0;
		}
	}
	else
	//VW JETTA 2007
	 if(type == "3")
	{
		if((days_total>=1) && (days_total<=3))
		{
			price_per_day = 55;
		}
		else if((days_total>=4) && (days_total<=7))
		{
			price_per_day = 50;
		}
		else if((days_total>=8) && (days_total<=15))
		{
			price_per_day = 45;
		}
		else if(days_total>15)
		{
			price_per_day = 40;
		}
		else
		{
			price_per_day = 0;
		}
	}
	else
	//VW GOLF V VARIANT TRENDLINE
	 if(type == "4")
	{
		if((days_total>=1) && (days_total<=3))
		{
			price_per_day = 55;
		}
		else if((days_total>=4) && (days_total<=7))
		{
			price_per_day = 50;
		}
		else if((days_total>=8) && (days_total<=15))
		{
			price_per_day = 45;
		}
		else if(days_total>15)
		{
			price_per_day = 40;
		}
		else
		{
			price_per_day = 0;
		}
	}
	//VW MULTIVAN 2006
	if(type == "5")
	{
		if((days_total>=1) && (days_total<=3))
		{
			price_per_day = 45;
		}
		else if((days_total>=4) && (days_total<=7))
		{
			price_per_day = 40;
		}
		else if((days_total>=8) && (days_total<=15))
		{
			price_per_day = 35;
		}
		else if(days_total>15)
		{
			price_per_day = 30;
		}
		else
		{
			price_per_day = 0;
		}
	}

	//RENAULT MEGANE CABRIO 2007
	if(type == "6")
	{
		if((days_total>=1) && (days_total<=3))
		{
			price_per_day = 45;
		}
		else if((days_total>=4) && (days_total<=7))
		{
			price_per_day = 40;
		}
		else if((days_total>=8) && (days_total<=15))
		{
			price_per_day = 35;
		}
		else if(days_total>15)
		{
			price_per_day = 30;
		}
		else
		{
			price_per_day = 0;
		}
	}

	//CITROEN JUMPER
	if(type == "7")
	{
		if((days_total>=1) && (days_total<=3))
		{
			price_per_day = 45;
		}
		else if((days_total>=4) && (days_total<=7))
		{
			price_per_day = 40;
		}
		else if((days_total>=8) && (days_total<=15))
		{
			price_per_day = 35;
		}
		else if(days_total>15)
		{
			price_per_day = 30;
		}
		else
		{
			price_per_day = 0;
		}
	}


	//extras
	if(document.reservation.driver.checked == true)
	{
		driver_price = days_total*20;
	}
	else if(document.reservation.driver.checked == false)
	{
		driver_price = 0;
	}
	if(document.reservation.chains.checked == true)
	{
		chains_price = days_total*5;
	}
	else if(document.reservation.chains.checked == false)
	{
		chains_price = 0;
	}

	document.reservation.total_days.value = days_total;
	document.reservation.total_price.value = price_per_day*days_total + driver_price + chains_price;
	document.getElementById("prperday").innerHTML = price_per_day;
	document.getElementById("total_price_").innerHTML = (price_per_day*days_total) + driver_price + chains_price;
}

function update_price_1( type)
{
	var price = parseInt(document.getElementById("total_price_").innerHTML);
	var days = parseInt(document.reservation.total_days.value);



	if(document.reservation.driver.checked == true)
	{
		var new_price = price*1 + days*20;
		document.getElementById("total_price_").innerHTML = new_price;
		document.reservation.total_price.value = new_price;
	}
	else if(document.reservation.driver.checked == false)
	{
		var new_price = price*1 - days*20;
		document.getElementById("total_price_").innerHTML = new_price;
		document.reservation.total_price.value = new_price;
	}
}

function update_price_2()
{
	var price = parseInt(document.getElementById("total_price_").innerHTML);
	var days = parseInt(document.reservation.total_days.value);

	if(document.reservation.chains.checked == true)
	{
		var new_price1 = price*1 + days*5;
		document.getElementById("total_price_").innerHTML = new_price1;
		document.reservation.total_price.value = new_price1;
	}
	else if(document.reservation.chains.checked == false)
	{
		var new_price1 = price*1 - days*5;
		document.getElementById("total_price_").innerHTML = new_price1;
		document.reservation.total_price.value = new_price1;
	}

}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage)
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters))
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ?
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width
                  + "px; height:" + myImage.height
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"

	   myImage.outerHTML = strNewHTML
    }
}


function isValidEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		return true
	else
		return false
}


function check_reservation(error_firstname, error_lastname, error_phone, error_email, error_street, error_number, error_city, error_zipcode, error_country, error_start, error_days)
{
	document.error_msg.errors.value = "";
	if(document.reservation.firstname.value == "")
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_firstname;
		document.getElementById("show_error").style.display="block";
		document.reservation.firstname.focus();
	}
	else if(document.reservation.lastname.value == "")
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_lastname;
		document.getElementById("show_error").style.display="block";
		document.reservation.lastname.focus();
	}
	else if(document.reservation.street.value == "")
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_street;
		document.getElementById("show_error").style.display="block";
		document.reservation.street.focus();
	}
	else if(document.reservation.number.value == "")
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_number;
		document.getElementById("show_error").style.display="block";
		document.reservation.number.focus();
	}
	else if(document.reservation.city.value == "")
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_city;
		document.getElementById("show_error").style.display="block";
		document.reservation.city.focus();
	}
	else if(document.reservation.zipcode.value == "")
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_zipcode;
		document.getElementById("show_error").style.display="block";
		document.reservation.zipcode.focus();
	}
	else if(document.reservation.country.value == "")
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_country;
		document.getElementById("show_error").style.display="block";
		document.reservation.country.focus();
	}
	else if(document.reservation.phone.value == "")
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_phone;
		document.getElementById("show_error").style.display="block";
		document.reservation.phone.focus();
	}
	else if(!isValidEmail(document.reservation.email.value))
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_email;
		document.getElementById("show_error").style.display="block";
		document.reservation.email.focus();
	}
	else if(document.reservation.difference.value < 0)
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_start;
		document.getElementById("show_error").style.display="block";
		document.reservation.year.focus();
	}
	else if(document.reservation.number_of_days.value < 1)
	{
		document.error_msg.errors.value = document.error_msg.errors.value + error_days;
		document.getElementById("show_error").style.display="block";
		document.reservation.number_of_days.focus();
	}
	else
	{
		document.reservation.submit();
	}
}

/*NEW FUNCTIONALITIES CREATED: 2008-04-08*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//CREATING ASSOCIATIVE ARRAY FOR SHOWING CARS BY ID
//VERY IMPORTANT
var arr_cars = new Array(0, 1, 2, 7, 3, 4, 5, 6);

var last_img = readCookie("last_img");
if (last_img == null || Number(last_img) ==NaN || last_img < 1 || last_img > 7)
  last_img = 3;

function set_cars(){
	update_cars();
}



function update_cars(){
	document.getElementById("img_visible_car_1").innerHTML = document.getElementById("img_car_"+(arr_cars[get_prev_img(get_prev_img(last_img))])).innerHTML;
	document.getElementById("img_visible_car_2").innerHTML = document.getElementById("img_car_"+(arr_cars[get_prev_img(last_img)])).innerHTML;
	document.getElementById("img_visible_car_3").innerHTML = document.getElementById("img_car_"+(arr_cars[last_img])).innerHTML;
}

function get_prev_img( id ){
	if (id == 1)
		return 7;
	else
		return id - 1;
}

function get_next_img( id ){
	if (id == 7)
		return 1;
	else
		return parseInt(id) + 1;
}

function get_last_disp_img(){
	var i=1
	while ( i< 7){
		if ((document.getElementById("img_car_"+ i).style.display == "inline") && (document.getElementById("img_car_"+ get_next_img(i)).style.display == "none"))
			return i;
		i++;
	}
	return 7;
}

function show_prev_img(){
	last_img=get_prev_img(last_img);
	createCookie("last_img", last_img);
	update_cars();
}

function show_next_img(){
	last_img=get_next_img(last_img);
	createCookie("last_img", last_img);
	update_cars();
}

