var longterm="";
var str_time="";
var dauer=0;
var ort_check=0;var strA="";var strB="";

var jetzt=new Date();
var a_tag=jetzt.getDate();var e_tag=jetzt.getDate()+7;
var a_monat=jetzt.getMonth();
if ((a_monat==0)||(a_monat==2)||(a_monat==4)||(a_monat==6)||(a_monat==7)||(a_monat==9)||(a_monat==11)) {
	if (a_tag < 25) {
		var e_monat=jetzt.getMonth();}
	else {
		if ((a_monat==11)&&(a_tag>24)) {
			var e_monat=jetzt.getMonth()-11;
			e_tag=e_tag-31;}
		else {
			var e_monat=jetzt.getMonth()+1;
			e_tag=e_tag-31;}
	}
}	
else {
	if ((a_monat==3)||(a_monat==5)||(a_monat==8)||(a_monat==10)) {
		if (a_tag < 24) {
			var e_monat=jetzt.getMonth();}
		else {
			var e_monat=jetzt.getMonth()+1;
			e_tag=e_tag-30;}
	}
	else {
		if (a_tag < 22) {
			var e_monat=jetzt.getMonth();}
		else {
			var e_monat=jetzt.getMonth()+1;
			e_tag=e_tag-28;}
	}
}
var a_jahr = jetzt.getYear();
if (a_jahr<200) {
	a_jahr=a_jahr+1900;
}
if ((a_monat==11)&&(a_tag>24)) {
	var e_jahr=a_jahr+1;
}
else {
	var e_jahr=a_jahr;
}



cars = new Array();
cars[0] = new Array();
cars[0][0] = "A";
cars[0][1] = new Array();
cars[0][1][0]=92; cars[0][1][1]=126; cars[0][1][2]=151;

cars[1] = new Array();
cars[1][0] = "B";
cars[1][1] = new Array();
cars[1][1][0]=101; cars[1][1][1]=134; cars[1][1][2]=160;

cars[2] = new Array();
cars[2][0] = "C";
cars[2][1] = new Array();
cars[2][1][0]=126; cars[2][1][1]=168; cars[2][1][2]=210;

cars[3] = new Array();
cars[3][0] = "D";
cars[3][1] = new Array();
cars[3][1][0]=151; cars[3][1][1]=218; cars[3][1][2]=277;

cars[4] = new Array();
cars[4][0] = "E";
cars[4][1] = new Array();
cars[4][1][0]=252; cars[4][1][1]=294; cars[4][1][2]=328;

cars[5] = new Array();
cars[5][0] = "F";
cars[5][1] = new Array();
cars[5][1][0]=294; cars[5][1][1]=378; cars[5][1][2]=462;


month = new Array();
month[0]="";month[1]=31;month[2]=28;month[3]=31;month[4]=30;month[5]=31;month[6]=30;month[7]=31;month[8]=31;month[9]=30;month[10]=31;month[11]=30;month[12]=31;

function pop() {
	pop=window.open()
}
function check() {
	if(pop.closed==0) pop.close()
}
pop.closed=1;

function idiom() {
	if (document.forms[0].language.value=="en") {
		longterm="Please contact us by email for special longterm conditions.";
        wrongdate="The planned end date cannot be before the planned start date.";
		today="The planned start date cannot be before today.";
		fill_nome="Please enter your last name";
		fill_tel="Please enter your phone number";
		fill_email="Please enter your email address";
		not_valid="Not a valid email address";
		no_week="Minimum rental period: 3 days";
		fao_airport="Faro Airport";
		lis_airport="Lisbon Airport";
		rueckgabe="to be agreed on later";
		ort_title="Specify other place";
		ort_ansage1="Please specify the place to pick up the car";
		ort_ansage2="Please specify the place to return the car";
		ort_lugar="Meeting point: ";
		ort_lugar_help="\(Villa Name, Hotel, etc.\)";
		ort_local="Place: "
		ort_local_help="\(City, town, etc.\)";
	}
	else {
		if (document.forms[0].language.value=="de") {
			longterm="Bitte kontaktieren Sie uns per Email &uuml;ber spezielle Langzeitkonditionen.";
			fill_nome="Bitte Nachnamen eingeben";
			fill_tel="Bitte Telefon-Nr. eingeben";
			fill_email="Bitte Email-Adresse eingeben";
			not_valid="Keine g&uuml;ltige Email-Adresse";
			no_week="Mindestmietdauer: 3 Tage";
			fao_airport="Flughafen Faro";
			lis_airport="Flughafen Lissabon";
			rueckgabe="noch festzulegen";
			ort_title="Anderen Ort w&auml;hlen";
			ort_ansage1="Bitte geben Sie einen anderen Ort f&uuml;r die &Uuml;bergabe an";
			ort_ansage2="Bitte geben Sie einen anderen Ort f&uuml;r die R&uuml;ckgabe an";
			ort_lugar="Treffpunkt: ";
			ort_lugar_help="\(Hotel, etc.\)";
			ort_local="Ort: "
			ort_local_help="\(Stadt, Dorf, etc.\)";
		}
		else { 
		    if (document.forms[0].language.value=="pt") {
			    longterm="S.f.f. de contactar-nos via email sobre as condi&ccedil;&otilde;es de longo prazo.";
			    fill_nome="S.f.f. de indicar o seu apelido";
			    fill_tel="S.f.f. de indicar o seu n&uacute;mero de telefone";
			    fill_email="S.f.f. de indicar o seu endere&ccedil;o electr&oacute;nico";
			    not_valid="Endere&ccedil;o de email n&atilde;o est&aacute; correcto";
			    no_week="Prazo m&iacute;nimo de aluguer: 3 dias";
			    fao_airport="Aeroporto de Faro";
			    lis_airport="Aeroporto de Lisboa";
			    rueckgabe="ainda por determinar";
			    ort_title="Indicar outro local";
			    ort_ansage1="S.f.f. de indicar outro local de entrega do carro";
			    ort_ansage2="S.f.f. de indicar outro local de retorno do carro";
			    ort_lugar="Local de encontro: ";
			    ort_lugar_help="\(Hotel, etc.\)";
			    ort_local="Localidade: "
			    ort_local_help="\(Cidade, vila, etc.\)";
		   }
		}
	}
}

function anderort() {

	j=ort_check;
	strA=ort.document.ortform.lugar.value;
	strB=ort.document.ortform.local.value;

	if (strA != "" && strB != "") {
		if (j==0) {
			document.forms[0].local_1.value=strB+", "+strA;
		}
		else {
			document.forms[0].local_2.value=strB+", "+strA;
		}
	}
}

function eingabe(i) {
	ix = (i==1) ? document.forms[0].local1.selectedIndex : document.forms[0].local2.selectedIndex;
	if (ix == 2) {
		idiom();
		str=(i==1)?ort_ansage1 : ort_ansage2;
		ort_check=i;		
		ort = window.open("","abfrage","width=580,height=210"); 
		ort.document.open();
		ort.document.writeln("<HTML><HEAD><TITLE>"+ort_title+"</TITLE>");
		ort.document.writeln("<link rel=stylesheet type='text/css' href='../stylesheet.css'>");
		ort.document.writeln("</HEAD>");
		ort.document.writeln("<BODY bgproperties='fixed'>");
		ort.document.writeln("<FORM NAME='ortform'><DIV><TABLE cellpadding=5 cellspacing=5><TR><TD rowspan=2 width=50>&nbsp;</TD><TD class='cin' colspan=2><TABLE cellspacing=0 cellpadding=5>");
		ort.document.writeln("<TR><TD colspan=3 class='red'><IMG SRC='images/key.gif' align='right'><B>"+str+"</B></TD></TR>");
		ort.document.writeln("<TR><TD id='right'>"+ort_lugar+"</TD><TD><INPUT TYPE='Text' NAME='lugar' VALUE='' SIZE=20></TD><TD>"+ort_lugar_help+"</TD></TR>");
		ort.document.writeln("<TR><TD id='right'>"+ort_local+"</TD><TD><INPUT TYPE='Text' NAME='local' VALUE='' SIZE=20></TD><TD>"+ort_local_help+"</TD></TR>");
		ort.document.writeln("</TABLE></TD></TR>");
		ort.document.writeln("<TR><TD><DIV><INPUT TYPE='Button' NAME='cancel' VALUE='Cancel' onclick='self.close()' width=70></DIV></TD><TD><DIV><INPUT TYPE='Button' VALUE='OK' onClick='window.opener.anderort();self.close()' width=70></DIV></TD></TR>");
		ort.document.writeln("</TABLE></DIV></FORM></BODY></HTML>");
		ort.document.close();
		ort.document.ortform.lugar.focus();
	}
}

function verify() {

	time1=document.forms[0].hora1.selectedIndex;
	time1 = (time1<10) ? "0"+time1 : time1; 
	time2=document.forms[0].minuto1.selectedIndex*5;
	time2 = (time2<6) ? "0"+time2 : time2;
	str_time=time1 +":"+ time2;
	idiom();
	calc();
	str_email = document.forms[0].email.value;
	punkt = str_email.match(/\./);
	if (punkt) {
		punkt="ok";
	}
	else {
		punkt="no";
	}

	if (document.forms[0].periodo.value <= 1) {
		alert(no_week);
		document.forms[0].dia2.focus();
      	return false;
	}

	if (document.forms[0].apelido.value == "") {
		alert(fill_nome);
		document.forms[0].apelido.focus();
      	return false;
	}

	if (document.forms[0].tel.value == "") {
		alert(fill_tel);
		document.forms[0].tel.focus();
      	return false;
	}

	if (document.forms[0].email.value == "") {
		alert(fill_email);
		document.forms[0].email.focus();
      	return false;
	}

	if (document.forms[0].email.value.indexOf('@') == -1 || punkt=="no") {
		alert(not_valid);
		document.forms[0].email.focus();
      	return false;
	}

	if (document.forms[0].local1.selectedIndex < 1) {
		document.forms[0].local_1.value = fao_airport;
	}
	else {
		if (document.forms[0].local_1.value == " ") {
			eingabe(0);
			return false;
		}
	}

	if (document.forms[0].local2.selectedIndex < 1) {
		document.forms[0].local_2.value = fao_airport;
	}
	else {
		if (strA == "" || strB == "") {
			document.forms[0].local_2.value = rueckgabe;
		}

	}
}

function calc() {
	var preis=0;
	var i=0;
	var data = new Date();
	for (i==0;i<=5;i++) {
		if (document.forms[0].grupo[i].checked==true) {
			gruppe=i
		}
	}

	idiom();

	tag1=document.forms[0].dia1.selectedIndex+1;
	tag2=document.forms[0].dia2.selectedIndex+1;
	monat1=document.forms[0].mes1.selectedIndex+1;
	monat2=document.forms[0].mes2.selectedIndex+1;
	jahr1=document.forms[0].ano1.selectedIndex+1;
	jahr2=document.forms[0].ano2.selectedIndex+1;

	if ((monat1==monat2)&&(tag2<tag1)){
			alert(wrongdate);
			dauer=0;
               }
		if (monat1>monat2){
			alert(wrongdate);
			dauer=0;
               }
			if ((data.getDate()>tag1)&&((data.getMonth()+1)==monat1)){
				alert(today);
				dauer=0
				  }
												  
	if (jahr1==jahr2) {
		if (monat1==monat2) {
			dauer=tag2-tag1
			if (monat1<=3 || monat1>=11) {
				wpreis=cars[gruppe][1][0];
				tpreis=wpreis/7;
				preis=dauer*tpreis;
			}
			else {
				if ((monat1>=4 && monat1<7) || monat1==10) {
					wpreis=cars[gruppe][1][1];
					tpreis=wpreis/7;
					preis=dauer*tpreis;
				}
				else {
					wpreis=cars[gruppe][1][2];
					tpreis=wpreis/7;
					preis=dauer*tpreis;
				}
			}
		}
		else {
			if (monat2-monat1>1) {
				alert(longterm);
				dauer=0;
			}
			else {
				if (monat2-monat1==2) {
					dauer1=month[monat1]-tag1+1;
					dauer2=month[monat1+1];
					dauer3=tag2-1;
					dauer=dauer1+dauer2+dauer3;
					if (monat1==1) {
						wpreis=cars[gruppe][1][0];
						tpreis=wpreis/7;
						preis=dauer*tpreis;
					}
					if (monat1==2) {
						wpreis=cars[gruppe][1][0];
						wpreis1=cars[gruppe][1][1];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis+dauer2*tpreis+dauer3*tpreis1;
					}
					if (monat1==3) {
						wpreis=cars[gruppe][1][0];
						wpreis1=cars[gruppe][1][1];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis+dauer2*tpreis1+dauer3*tpreis1;
					}
					if (monat1==4) {
						wpreis=cars[gruppe][1][1];
						tpreis=wpreis/7;
						preis=dauer*tpreis;
					}
					if (monat1==5) {
						wpreis=cars[gruppe][1][1];
						wpreis1=cars[gruppe][1][2];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis+dauer2*tpreis+dauer3*tpreis1;
					}
					if (monat1==6) {
						wpreis=cars[gruppe][1][1];
						wpreis1=cars[gruppe][1][2];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis+dauer2*tpreis1+dauer3*tpreis1;
					}
					if (monat1==7) {
						wpreis=cars[gruppe][1][2];
						tpreis=wpreis/7;
						preis=dauer*tpreis;
					}
					if (monat1==8) {
						wpreis=cars[gruppe][1][1];
						wpreis1=cars[gruppe][1][2];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis1+dauer2*tpreis1+dauer3*tpreis;
					}
					if (monat1==9) {
						wpreis=cars[gruppe][1][0];
						wpreis1=cars[gruppe][1][1];
						wpreis2=cars[gruppe][1][2];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						tpreis2=wpreis2/7;
						preis=dauer1*tpreis2+dauer2*tpreis1+dauer3*tpreis;
					}
					if (monat1==10) {
						wpreis=cars[gruppe][1][0];
						wpreis1=cars[gruppe][1][1];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis1+dauer2*tpreis+dauer3*tpreis;
					}
					if (monat1>10) {
						wpreis=cars[gruppe][1][0];
						tpreis=wpreis/7;
						preis=dauer*tpreis;
					}
				}
				else {
					dauer1=month[monat1]-tag1+1;
					dauer2=tag2-1;
					dauer=dauer1+dauer2;
					if ((monat1<3) || (monat1>10)) {
						wpreis=cars[gruppe][1][0];
						tpreis=wpreis/7;
						preis=dauer*tpreis;
					}
					if (monat1==3) {
						wpreis=cars[gruppe][1][0];
						wpreis1=cars[gruppe][1][1];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis+dauer2*tpreis1;
					}
					if ((monat1>3) && (monat1<6)) {
						wpreis=cars[gruppe][1][1];
						tpreis=wpreis/7;
						preis=dauer*tpreis;
					}
					if (monat1==6) {
						wpreis=cars[gruppe][1][1];
						wpreis1=cars[gruppe][1][2];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis+dauer2*tpreis1;
					}
					if ((monat1>6) && (monat1<9)) {
						wpreis=cars[gruppe][1][2];
						tpreis=wpreis/7;
						preis=dauer*tpreis;
					}
					if (monat1==9) {
						wpreis=cars[gruppe][1][1];
						wpreis1=cars[gruppe][1][2];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis1+dauer2*tpreis;
					}
					if (monat1==10) {
						wpreis=cars[gruppe][1][0];
						wpreis1=cars[gruppe][1][1];
						tpreis=wpreis/7;
						tpreis1=wpreis1/7;
						preis=dauer1*tpreis1+dauer2*tpreis;
					}
				}
			}
		}
	}
	else {
		if ((monat2+12-monat1>2)&&(jahr2>jahr1)) {
			alert(longterm);
			dauer=0;
		}
                if ((monat2+12-monat1>2)&&(jahr2<jahr1)) {
			alert(wrongdate);
			dauer=0;
		}
		else {
			if (monat2+12-monat1==2) {
				dauer1=month[monat1]-tag1;
				dauer2=month[monat1+1];
				dauer=dauer1+dauer2+tag2;
			}
			else {
				dauer=month[monat1]-tag1+tag2
			}
			wpreis=cars[gruppe][1][0];
			tpreis=wpreis/7;
			preis=dauer*tpreis;
		}
	}

        
endpreis=Math.round(preis)+".00";
document.forms[0].preco.value=endpreis;
document.forms[0].periodo.value=dauer;
}
  
