// SET ALL PRICE VALUES
var del_cost = 0,count,season, fcost, curc, foo, paid, discount=0.90, tmp_price=0;

var pricesbygroup = new Array();
//PRICELIST | CAR | 1WEEK (LS) | 2WEEKS (LS) | 1WEEK (HS) | 2WEEKS (HS) | 1WEEK (WS) | 2WEEKS (WS) | MY QUOTED PRICE | 1WEEK (ES) | 2WEEKS (ES)
pricesbygroup[0]= new Array('A','155','289', '205' , '379', '135','260',parseInt(0),'175','309');
pricesbygroup[1]= new Array('B','174','329', '229' , '419', '155','290',parseInt(0),'195','349');
pricesbygroup[2]= new Array('C','195','369', '249' , '459', '175','320',parseInt(0),'215','399');
pricesbygroup[3]= new Array('D','235','420', '279' , '499', '190','360',parseInt(0),'255','449');
pricesbygroup[4] =new Array('D1','259','470', '309' , '549', '229','400',parseInt(0),'279','499');
pricesbygroup[5]= new Array('E','300','590', '399' , '750', '280','520',parseInt(0),'349','690');
pricesbygroup[6]= new Array('F','259','479', '339' , '649', '220','430',parseInt(0),'289','539');
pricesbygroup[7]= new Array('F1','380','680', '450' , '890', '315','580',parseInt(0),'450','790');
pricesbygroup[8]= new Array('G','395','690', '519' , '1030', '399','699',parseInt(0),'490','850');
pricesbygroup[9]= new Array('H','315','600', '450' , '890', '280','520',parseInt(0),'375','690');
pricesbygroup[10]= new Array('I','350','690', '490' , '960', '330','620',parseInt(0),'410','790');
pricesbygroup[11]= new Array('K','245','460', '330' , '620', '220','400',parseInt(0),'285','539');
pricesbygroup[12]= new Array('K1','245','460', '330' , '620', '220','400',parseInt(0),'295','550');
pricesbygroup[13]= new Array('L','375','740', '490' , '900', '350','680',parseInt(0),'490','900');
pricesbygroup[14]= new Array('L1','419','819', '559' , '1079', '419','819',parseInt(0),'559','1079');
pricesbygroup[15]= new Array('L2','449','849', '599' , '1149', '449','849',parseInt(0),'599','1149');
pricesbygroup[16]= new Array('J','1743','3486', '2093' , '5186', '1393','2786',parseInt(0),'1743','3486');

function fix_dates(){	
	if (!fixBridge()){
		fix_dfields();
	}
}
function fix_dfields(){
	today = new Date();
	today.setDate(today.getDate()+1);
	document.onlinequote.pickupdate.value = today.toString().substr(0,3)+" "+today.getDate()+" "+today.toString().substr(4,3)+" "+today.getFullYear();
	today.setDate(today.getDate()+7);
	document.onlinequote.returndate.value = today.toString().substr(0,3)+" "+today.getDate()+" "+today.toString().substr(4,3)+" "+today.getFullYear();	
}
function calc(){
	var ttemp = document.onlinequote.pickupdate.value;
	dateP = new Date(ttemp);
	dateP.setHours(document.onlinequote.Phour.value);
	ttemp = document.onlinequote.returndate.value;
	dateR = new Date(ttemp);
	dateR.setHours(document.onlinequote.Rhour.value);
	
	//calc duration
	count = (dateR - dateP) / 1000 / 3600 / 24;
	count = Math.ceil(count);
	if (dateP < new Date()){
		alert('Pickup Datum moet later zijn dan de huidige datum met een dag!');
		}
	else if (dateR < dateP){
		alert('Pickup Datum moet worden eerder dan de datum van terugkeer!\nVul correct in!');
		}
	else if (count < 4){
		alert('Contacteer ons voor minder dan 4-Dagen verhuur\n\n- Telefoontje Nu: +30 2810 240120\n- E-mail: info@rental-center-crete.com\n- Ga naar Contact pagina');
		}
	else
		{
		if ((count <7 )&&(count >3))
			{//count=7
			}
		else if ((count == 13))
			{count=14}
		document.getElementById('fill-box').style.display = 'none';
		document.getElementById('conf-box').style.display = 'block';
			document.getElementById('compact').checked = true;
			document.getElementById('large').checked = true;
			document.getElementById('4WD').checked = true;
			document.getElementById('vans').checked = true;
			document.getElementById('cabriolet').checked = true;
		showcars();
		}
		
}
function showcars(){
	getSeason();
	document.getElementById('conf1').innerHTML = document.onlinequote.pickupdate.value+", "+document.onlinequote.Phour.value+":00 hrs<br>"+document.onlinequote.pickup.value.split("_").join(" ");
	document.getElementById('conf2').innerHTML = document.onlinequote.returndate.value+", "+document.onlinequote.Rhour.value+":00 hrs<br>"+document.onlinequote.retur.value.split("_").join(" ");
			
	document.getElementById('conf3').innerHTML = "<img src='../images/check_m.gif' border='0'/> Alles ist inbegrepen<br>";
	if (document.onlinequote.pay1.checked)
		document.getElementById('conf3').innerHTML += "<img src='../images/check_m.gif' border='0'/> Betalen bij aankomst"
		else
		document.getElementById('conf3').innerHTML += "<img src='../images/check_m.gif' border='0'/> Betaal nu"
	document.getElementById('conf3').innerHTML += "<br><img src='../images/check_m.gif' border='0'/> Dagen: " + count;

	if (document.onlinequote.booster.checked) document.getElementById('conf4').innerHTML += "1 x Kinderzitje<br>";
	if (document.onlinequote.babyseat.checked) document.getElementById('conf4').innerHTML += "1 x Babyzitje<br>";
	if (document.onlinequote.gps.checked) document.getElementById('conf4').innerHTML += "1 x GPS";
	
	document.getElementById('banners').style.display = 'none';
	if(getcarprice(count))	show_listings()
}
function getSeason(){
	season = 0;
	cur_y = dateP.getFullYear();	
	if (dateP > new Date (cur_y, 3, 25 ) && dateP <= new Date (cur_y, 8, 27 )){
		season = 'LS';
		if (dateP > new Date (cur_y, 6, 15 ) && dateP <= new Date (cur_y, 7, 30 ))
		season = 'HS';
	}
	else 
		season = 'WS';	
	//EXTRA SEASON	
	if (dateP > new Date (cur_y, 6, 1 ) && dateP <= new Date (cur_y, 6, 15 ))
		season = 'ES';

}

function getcarprice(duration){
		// ADD DELIVERY COST
		check_del();
		// PRICE CALCULATION
		var ss=0;
		if (season=='WS')
			if (3 < duration && duration < 14) ss = 5
			else if (duration > 13)	ss = 6
			else ss=10 //ERROR	
		else if (season=='LS')
			if (3 < duration && duration < 14) ss = 1
			else if (duration > 13)	ss = 2
			else ss=10 //ERROR	
		else if (season=='HS')
			if (3 < duration && duration < 14) ss = 3
			else if (duration > 13)	ss = 4
			else ss=10 //ERROR
		else 
			if (3 < duration && duration < 14) ss = 8
			else if (duration > 13)	ss = 9
			else ss=10 //ERROR
		if (ss!=10){
			for (var i=0; i<17; i++)
			{
				if (duration>13) pricesbygroup[i][7] = parseInt((pricesbygroup[i][ss] / 14) * duration) + del_cost;
				else if (duration < 7 )pricesbygroup[i][7] = parseInt((pricesbygroup[i][ss] / 7) * 7) + del_cost - 1;
				else pricesbygroup[i][7] = parseInt((pricesbygroup[i][ss] / 7) * duration) + del_cost;
					
					var tmp2 = 0;
					if (count <8 )tmp2 = 7
					
					if (document.onlinequote.pay2.checked) paid = discount;
					else paid = 1
					//alert (paid);
					document.getElementById('price'+i).innerHTML = "&euro; " + (paid * (pricesbygroup[i][7]/count)).toFixed(2);
					document.getElementById('gbpprice'+i).innerHTML = "&pound; " + (paid * ((pricesbygroup[i][7]/count))*(0.84)).toFixed(2);
					document.getElementById('tprice'+i).innerHTML = "&euro; " + (paid * (pricesbygroup[i][7])).toFixed(0);
					document.getElementById('gbptprice'+i).innerHTML = "&pound; " + (paid * (pricesbygroup[i][7]*(0.84))).toFixed(0);	
			};
			return true;
		}
}
function show_listings(){
	for (var k=0; k<17; k++)
		document.getElementById('group'+k).style.display = "block";	
}
function hide_listings(){
	for (var l=0; l<17; l++)
		document.getElementById('group'+l).style.display = "none";
}
function mygroup(sel_group){
	switch (sel_group) {
 		case 1:	group = "Group A. Economy";tmp_price = document.getElementById('tprice0').innerHTML;break;
	    case 2:	group = "Group B. Compact";tmp_price = document.getElementById('tprice1').innerHTML;break;
	    case 3:	group = "Group C. Medium";tmp_price = document.getElementById('tprice2').innerHTML;break;
	    case 4:	group = "Group D. Full-Sized";tmp_price = document.getElementById('tprice3').innerHTML;break;
	    case 5:	group = "Group D1. Family";tmp_price = document.getElementById('tprice4').innerHTML;break;
	    case 6:	group = "Group E. Sedan";tmp_price = document.getElementById('tprice5').innerHTML;break;
	    case 7:	group = "Group F. Jeeps-Mini";tmp_price = document.getElementById('tprice6').innerHTML;break;
	    case 8:	group = "Group F1. Jeeps-Full";tmp_price = document.getElementById('tprice7').innerHTML;break;
	    case 9: group = "Group G. SUV";tmp_price = document.getElementById('tprice8').innerHTML;break;
	    case 10: group = "Group H. Mini-bus";tmp_price = document.getElementById('tprice9').innerHTML;break;
	    case 11: group = "Group I. Van";tmp_price = document.getElementById('tprice10').innerHTML;break;
	    case 12: group = "Group K. Automatic";tmp_price = document.getElementById('tprice11').innerHTML;break;
	    case 13: group = "Group K1. Automatic";tmp_price = document.getElementById('tprice12').innerHTML;break;
	    case 14: group = "Group L. Cabiolet";tmp_price = document.getElementById('tprice13').innerHTML;break;
	    case 15: group = "Group L1. Cabiolet";tmp_price = document.getElementById('tprice14').innerHTML;break;
	    case 16: group = "Group L2. Cabiolet";tmp_price = document.getElementById('tprice15').innerHTML;break;
	    case 17: group = "Group J. Luxury";tmp_price = document.getElementById('tprice16').innerHTML;break;
	    default: group = "-";break;        
	    }
		
		if (document.onlinequote.pay2.checked){
			document.onlinequote.fullpay.value = "PREPAID";
			document.onlinequote.price.value = (tmp_price.substr(2)*1) + Math.floor((tmp_price.substr(2) / discount)-(tmp_price.substr(2) * 1.00));
			document.onlinequote.discountedprice.value = ((tmp_price.substr(2) * 1)).toFixed(0);
		}
		else{
			document.onlinequote.fullpay.value = "PAY ON ARRIVAL";
			document.onlinequote.price.value = ((tmp_price.substr(2) * 1)).toFixed(0);
			document.onlinequote.discountedprice.value = (discount * (tmp_price.substr(2) * 1)).toFixed(0);
		}
		document.onlinequote.group.value = group;
		document.onlinequote.days.value = count;
		
		document.onlinequote.fullbos.value = 'No';
		document.onlinequote.fullbas.value = 'No';
		document.onlinequote.fullgps.value = 'No';
	if (document.onlinequote.booster.checked) document.onlinequote.fullbos.value = 'Yes';
	if (document.onlinequote.babyseat.checked) document.onlinequote.fullbas.value = 'Yes';
	if (document.onlinequote.gps.checked) document.onlinequote.fullgps.value = 'Yes';
	
		document.onlinequote.submit();
		
		
}
function restart_quote(){
	hide_listings();
	document.getElementById('fill-box').style.display = 'block';
	document.getElementById('conf-box').style.display = 'none';
	document.getElementById('banners').style.display = 'block';
	document.getElementById('conf4').innerHTML = "";
}
function check_del(){	
	var area = document.onlinequote.pickup.options[document.onlinequote.pickup.selectedIndex].parentNode.label;
	if (area == "Heraklion Area")	{del_cost = 0;}
	else if (area == "Chania Area")	{del_cost = 25;}
	else if (area == "Rethymno Area")	{del_cost = 19;}
	else	{del_cost = 15;}
	check_oneway();
}
function check_oneway(){
	var oneway = 0;//idc = document.onlinequote.pickup.selectedIndex;
	tmp1 = document.onlinequote.pickup.options[document.onlinequote.pickup.selectedIndex].parentNode.label;
	tmp2 = document.onlinequote.pickup.options[document.onlinequote.retur.selectedIndex].parentNode.label;
	if ((tmp1!=tmp2)&&(document.onlinequote.retur.value!="Same_as_Pick_Up")){
		oneway = 20;
		if (tmp2=="Heraklion Area"){
			oneway=10;
		}
	}
	//document.onlinequote.oneway.value = oneway;
}

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
function addZero(num)
{
	(String(num).length < 2) ? num = String("0" + num) :  num = String(num);
	return num;		
}
function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
} 
function fixBridge(){
	//alert(getQuerystring('PUP').length);
	var flg = false;
	if(getQuerystring('PUP').length > 0) {document.onlinequote.pickup.value=getQuerystring('PUP'); flg=true;}
	if(getQuerystring('REP').length > 0) {document.onlinequote.retur.value=getQuerystring('REP'); flg=true;}
	if(getQuerystring('PUD').length > 0) {document.onlinequote.pickupdate.value=getQuerystring('PUD').split("_").join(" "); flg=true;}
	else{fix_dfields()}
	if(getQuerystring('RED').length > 0) {document.onlinequote.returndate.value=getQuerystring('RED').split("_").join(" "); flg=true;}
	if(getQuerystring('PUH').length > 0) {document.onlinequote.Phour.value=getQuerystring('PUH'); flg=true;}
	if(getQuerystring('REH').length > 0) {document.onlinequote.Rhour.value=getQuerystring('REH'); flg=true;}
	//document.onlinequote.pickup.value=getQuerystring('PUP');
	//document.onlinequote.pickup.value=getQuerystring('PUP');
	//document.onlinequote.pickup.value=getQuerystring('PUP');
	//alert(getQuerystring('PUP'));
	return true;
}

function appear(arr, dom1){
	if(dom1.checked){
	for (var i=0;i<arr.length;i++){	
			document.getElementById('group'+arr[i]).style.display = "block";
		}
	}
	else{	
	for (var i=0;i<arr.length;i++){	
			document.getElementById('group'+arr[i]).style.display = "none";
		}
	}
}

//-->