pos = 0;
var msg;
var verticalpos="fromtop";

function ScrollMessage() {
   		window.status = msg.substring(pos, msg.length) + msg.substring(0, pos);
   		pos++;
   		if (pos > msg.length) pos = 0;
   		window.setTimeout("ScrollMessage()",150);
}

var hiba_window;
var leall;
var hibanum;
var messagehiba;
var message;
var titleparam;
var messagehead;
var messagefoot;
var language;
var alerttext;

var pluraladult = "";
var pluralkid = "";
var hibaplus = 20;

var availabilitystartyear=2010;
var availabilitystartmonth=3;//a tényleges hónap száma nem kell számolgatni
var availabilitystartday=4;

availability = new Date(availabilitystartyear, availabilitystartmonth-1, availabilitystartday);

function availabilitystart() {
	document.urlap.yyy.options[1].selected=true;
	document.urlap.mmm.options[availabilitystartmonth].selected=true;
	document.urlap.ddd.options[availabilitystartday].selected=true;
}

tablasorokhu = ["E-MAIL: ", "ÉRKEZÉS: ", "TÁVOZÁS: ", "CSALÁDI NÉV: ", "UTÓNÉV: ", "ORSZÁG: ", "TELEFONSZÁM: ", "MOBILSZÁM: ", "A SZOBA JELLEMZ&#336;I: ", "ÉRKEZ&#336; FELN&#336;TTEK: ", " f&#337;", "ÉRKEZ&#336; GYERMEKEK: ", "ITT TALÁLT RÁNK: ", "ÉJSZAKÁK SZÁMA: ", "HELYSZÍN: ", "MEGSZÓLÍTÁS: "];
tablasoroken = ["E-MAIL: ", "ARRIVAL: ", "DEPARTURE: ", "SURNAME: ", "NAME: ", "COUNTRY: ", "PHONE NUMBER: ", "CELL NUMBER: ", "TYPE OF THE ROOM: ", "ADULTS: ", " person", "CHILDREN: ", "YOU FOUND US: ", "NUMBER OF NIGHTS: ", "LOCATION: ", "TITLE: "];
tablasorok = new Array();

var subsafe=0;
var N=(navigator.appName=="Netscape");
var UA=navigator.userAgent;

var titleparamhibahu = "Adatellen&#337;rzés";
var titleparamhibaen = "Data checking";

var messageheadhibahu = "Az alábbi javítások szükségesek.<br>Köszönöm.<br>&nbsp;<br>";
var messageheadhibaen = "Please, revise the fields listed below.<br>Thank you!<br>&nbsp;<br>";
var messageheadsendhu = "Az alábbi adatokat adta meg küldésre. Ha mindent rendben talál, akkor küldheti. Köszönöm.<br>&nbsp;<br>";
var messageheadsenden = "You filled in the form and it will be sent as shown below. If you find all correct, please, submit the form. Thank you!<br>&nbsp;<br>";

var messagefoothu = "Ez az ablak 20 másodpercen belül bezárul,<br>ezért nem szükséges bezárnia.<br>";
var messagefooten = "This window closes automatically in 20 seconds.<br>You do not need to close it.<br>";

function close_hiba_window() {
	if (N) {
		if (String(hiba_window)=="[object Window]") {//nem értem
        	if (!hiba_window.closed) hiba_window.close();
}
}
	if (hiba_window) hiba_window.close();
	if (leall) window.clearTimeout(leall);
}

function validatemonth31() {
	getdatum();
	if (indexmontharrival==4||indexmontharrival==6||indexmontharrival==9||indexmontharrival==11) {
		if (indexdayarrival==31) {
			indexdayarrival=30;
			document.urlap.ddd.options[30].selected=true;
			textdayarrival="30";
}
}
	if (indexmontharrival==2) {
		if (Math.floor(textyeararrival/4)==textyeararrival/4) {
			if (indexdayarrival==30||indexdayarrival==31) {
				indexdayarrival=29;
				document.urlap.ddd.options[29].selected=true;
				textdayarrival="29";
}
}
		else {
			if (indexdayarrival==29||indexdayarrival==30||indexdayarrival==31) {
				indexdayarrival=28;
				document.urlap.ddd.options[28].selected=true;
				textdayarrival="28";
}
}
}
	if (indexmonthdepart==4||indexmonthdepart==6||indexmonthdepart==9||indexmonthdepart==11) {
		if (indexdaydepart==31) {
			indexdaydepart=30;
			document.urlap.dddt.options[30].selected=true;
			textdayarrival="30";
}
}
	if (indexmonthdepart==2) {
		if (Math.floor(textyeardepart/4)==textyeardepart/4) {
			if (indexdaydepart==30||indexdaydepart==31) {
				indexdaydepart=29;
				document.urlap.dddt.options[29].selected=true;
				textdaydepart="29";
}
}
		else {
			if (indexdaydepart==29||indexdaydepart==30||indexdaydepart==31) {
				indexdaydepart=28;
				document.urlap.dddt.options[28].selected=true;
				textdaydepart="28";
}
}
}
}

function validatedatums() {
	per = 1000*60*60*24;
	datearrival = new Date(textyeararrival, indexmontharrival-1, textdayarrival);
	datedepart = new Date(textyeardepart, indexmonthdepart-1, textdaydepart);
	diff = datedepart - datearrival;

	if (indexyeararrival==0||indexmontharrival==0||indexdayarrival==0||indexyeardepart==0||indexmonthdepart==0||indexdaydepart==0) {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". Kérem, ellen&#337;rizze a <span class='redletter'>dátumok</span> helyes kiválasztását.<br>";
}
		else {
			messagehiba += hibanum + ". Please, select valid <span class='redletter'>arrival and departure dates</span>.<br>";
}	
	return;		
}

	if (datearrival<availability) {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". A megadott <span class='redletter'>kezd&#337;dátum</span>tól már nem tudunk szobát biztosítani.<br>";
}
		else {
			messagehiba += hibanum + ". There is not an apartment available from the <span class='redletter'>start date</span>.<br>";
}	
	return;		
}

	if (diff/per<1) {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". <span class='redletter'>Hibás dátum</span> - távozásra.<br>";
}
		else {
			messagehiba += hibanum + ". <span class='redletter'>Wrong date</span> for departure.<br>";
}	
	return;		
}
	if (diff/per<3) {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". Felhívjuk figyelmét, hogy 1-2 éjszakás tartózkodás esetén <span class='redletter'>3 éjszaka díja fizetend&#337;</span>.<br>";
}
		else {
			messagehiba += hibanum + ". Please, consider that <span class='redletter'>staying 1 or 2 nights pays 3 nights' fee</span>.<br>";
}	
	return;		
}
}

function validateemail() {
	if (document.urlap.email.value!==document.urlap.emailcheck.value) {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". Ellen&#337;rizze az <span class='redletter'>e-mail cím</span>et, mert az ismételt beírásnál eltér&#337;en adta meg!<br>";
			document.urlap.emailcheck.value="Adja meg az e-mail címet ismét!";//átírja a hibás mezőt
}
		else {
			messagehiba += hibanum + ". Please, check the <span class='redletter'>e-mail</span> address because confirmation is different.<br>";
			document.urlap.emailcheck.value="Enter the e-mail address again";//átírja a hibás mezőt
}			
}
	emailaddr = document.urlap.email.value
	if (emailaddr.length<6||document.urlap.email.value=="Adja meg az e-mail címet ismét!"||document.urlap.email.value=="Enter the e-mail address again"||emailaddr.indexOf("@")<1||emailaddr.indexOf(".")<1||emailaddr.indexOf(".",emailaddr.indexOf("@"))<emailaddr.indexOf("@")+2||emailaddr.lastIndexOf(".")>emailaddr.length-3) {
		hibaheight = hibaheight+ hibaplus;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". Ellen&#337;rizze az <span class='redletter'>e-mail cím</span>et, mert érvénytelennek t&#369;nik!<br>";
			document.urlap.email.value="Adja meg az e-mail címet ismét!";//átírja a hibás mezőt
			document.urlap.emailcheck.value="Adja meg az e-mail címet ismét!";//átírja a hibás mezőt
}
		else {
			messagehiba += hibanum + ". Please, check the <span class='redletter'>e-mail</span> address because it seems invalid.<br>";
			document.urlap.email.value="Enter the e-mail address again";//átírja a hibás mezőt
			document.urlap.emailcheck.value="Enter the e-mail address again";//átírja a hibás mezőt
}
}
}

function validateguestnumber() {
	if (!parseInt(document.urlap.adults.value)) {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". Legalább egy <span class='redletter'>feln&#337;tt</span> kell a foglaláshoz.<br>";
			document.urlap.adults.value="2";//átírja a hibás mezőt
}
		else {
			messagehiba += hibanum + ". Number of <span class='redletter'>adults</span> must be minimum 1.<br>";
			document.urlap.adults.value="2";//átírja a hibás mezőt
}
}

	if (!parseInt(document.urlap.kids.value)&&document.urlap.kids.value!=="0") {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". A <span class='redletter'>gyermekek</span>nél csak számot adhat meg.<br>";
			document.urlap.kids.value="0";//átírja a hibás mezőt
}
		else {
			messagehiba += hibanum + ". <span class='redletter'>Children</span> - number required.<br>";
			document.urlap.kids.value="0";//átírja a hibás mezőt
}
}
	if (parseInt(document.urlap.adults.value)>5||parseInt(document.urlap.adults.value)+parseInt(document.urlap.kids.value)>5) {
		hibaheight = hibaheight + 150;
		hibanum++;
		if (language=="hu") {
			messagehiba += hibanum + ". Ellen&#337;rizze az érkez&#337; vendégek számát, mert az apartman <span class='redletter'>legfeljebb 5 f&#337;</span> elhelyezésére alkalmas!<br><br>Ha gyerekágyat igényel, azt a Megjegyzésnél jelezze, ekkor a gyermekeknél nem kell feltüntetni.<br><br>Ha mindkét apartmant szeretné lefoglalni, akkor azt jelezze a Megjegyzésben.<br>";
			document.urlap.adults.value="2";//átírja a hibás mezőt
			document.urlap.kids.value="0";//átírja a hibás mezőt
}
		else {
			messagehiba += hibanum + ". Please, check the number of guests; <span class='redletter'>maximum 5 persons</span> can stay.<br><br>If you request a baby-cot, please, write a comment on it and do not count the baby as a  child.<br><br>If you book both apartments, please, write it in the Comment field.<br>";
			document.urlap.adults.value="2";//átírja a hibás mezőt
			document.urlap.kids.value="0";//átírja a hibás mezőt
}
}
}

function validatefamilyname() {
	if (!document.urlap.familyname.value||document.urlap.familyname.value=="Adja meg a nevét!"||document.urlap.familyname.value=="Enter your surname") {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
		messagehiba += hibanum + ". A <span class='redletter'>családi név</span> megadása kötelez&#337;!<br>";
		document.urlap.familyname.value="Adja meg a nevét!";//átírja a hibás mezőt
}
		else {
		messagehiba += hibanum + ". <span class='redletter'>Surname</span> is required.<br>";
		document.urlap.familyname.value="Enter your surname";//átírja a hibás mezőt
}
}
}

function validatefirstname() {
	if (!document.urlap.firstname.value||document.urlap.firstname.value=="Adja meg a nevét!"||document.urlap.firstname.value=="Enter your name") {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
		messagehiba += hibanum + ". Az <span class='redletter'>utónév</span> megadása kötelez&#337;!<br>";
		document.urlap.firstname.value="Adja meg a nevét!";//átírja a hibás mezőt
}
		else {
		messagehiba += hibanum + ". <span class='redletter'>Name</span> is required.<br>";
		document.urlap.firstname.value="Enter your name";//átírja a hibás mezőt
}
}
}

function validatecountry() {
	if (document.urlap.country.value=="default") {
		hibaheight = hibaheight + hibaplus;
		hibanum++;
		if (language=="hu") {
		messagehiba += hibanum + ". Az <span class='redletter'>ország</span> kiválasztása kötelez&#337;!<br>";
}
		else {
		messagehiba += hibanum + ". Selecting your <span class='redletter'>country</span> is required.<br>	";
}
}
}

function tabledisplay() {
kid = "";
hiba_window.document.write("<table class='formhiba'>");
//a kinyert mezőadatok
    		message  = "<tr><td class='cc'><b>" + tablasorok[14] + "</b></td><td class='aa'>" + locationtext + "</td></tr>";
    		message += "<tr><td class='cc'><b>" + tablasorok[0] + "</b></td><td class='aa'>" + document.urlap.email.value + "</td></tr>";
    		message += "<tr><td class='cc'><b>" + tablasorok[1] + "</b></td><td class='aa'>" + textyeararrival+ ". " + textmontharrival + " " + textdayarrival + ".</td></tr>";
    		message += "<tr><td class='cc'><b>" + tablasorok[2] + "</b></td><td class='aa'>" + textyeardepart + ". " + textmonthdepart + " " + textdaydepart + ".</td></tr>";
		message += "<tr><td class='cc'><b>" + tablasorok[13] + "</b></td><td class='aa'>" + Math.round(diff/per) + "</td></tr>";
for (i=0;i<3;i++) {
	if (document.urlap.title[i].checked==true) {
	message += "<tr><td class='cc'><b>" + tablasorok[15] + "</b></td><td class='aa'>" + document.urlap.title[i].value + "</td></tr>";
}
}
    		message += "<tr><td class='cc' width='45%'><b>" + tablasorok[3] + "</b></td><td class='aa'>" + document.urlap.familyname.value + "</td></tr>";
		message += "<tr><td class='cc'><b>" + tablasorok[4] + "</b></td><td class='aa'>" + document.urlap.firstname.value + "</td></tr>";
	indcountry = document.urlap.country.selectedIndex;
	valcountry = document.urlap.country.options[indcountry].firstChild.nodeValue;
		message += "<tr><td class='cc'><b>" + tablasorok[5] + "</b></td><td class='aa'>" + valcountry + "</td></tr>";
    		//message += "<tr><td class='cc'><b><i>" + tablasorok[6] + "</i></b></td><td class='aa'>" + document.urlap.tel.value + "</td></tr>";		
    		//message += "<tr><td class='cc'><b><i>" + tablasorok[7] + "</i></b></td><td class='aa'>" + document.urlap.cell.value + "</td></tr>";
//a szoba jellemzői
for (i=0;i<2;i++) {
	if (document.urlap.smoke[i].checked==true) {
	message += "<tr><td class='cc'><b>" + tablasorok[8] + "</b></td><td class='aa'>" + document.urlap.smoke[i].value + "</td></tr>";
}
}
for (i=0;i<4;i++) {
	if (document.urlap.beds[i].checked==true) {
	message += "<tr><td class='cc'></td><td class='aa'>" + document.urlap.beds[i].value + "</td></tr>";
}
}
//újabb kinyert mezőadatok
    		message += "<tr><td class='cc'><b>" + tablasorok[9] + "</b></td><td class='aa'>" + document.urlap.adults.value + tablasorok[10] + pluraladult +"</td></tr>";
	if (document.urlap.kids.value==0) kid="";
		else kid = document.urlap.kids.value + tablasorok[10] + pluralkid;
    	if (document.urlap.kids.value>0) message += "<tr><td class='cc'><b>" + tablasorok[11] + "</b></td><td class='aa'>" + kid + "</td></tr>";
	indwhere = document.urlap.where.selectedIndex;
	valwhere = document.urlap.where.options[indwhere].firstChild.nodeValue;
    		//message += "<tr><td class='cc'><b>" + tablasorok[12] + "</b></td><td class='aa'>" + valwhere + "</td></tr>";

    		hiba_window.document.write(message);

hiba_window.document.write("</table>");
}

function getdatum() {	

	indexyeararrival = document.urlap.yyy.selectedIndex;
	textyeararrival = document.urlap.yyy.options[indexyeararrival].text;
	indexmontharrival = document.urlap.mmm.selectedIndex;
	textmontharrival = document.urlap.mmm.options[indexmontharrival].text;
	indexdayarrival = document.urlap.ddd.selectedIndex;
	textdayarrival = document.urlap.ddd.options[indexdayarrival].text; //helyette firstChild.nodeValue is használható

	indexyeardepart = document.urlap.yyyt.selectedIndex;
	textyeardepart = document.urlap.yyyt.options[indexyeardepart].text;
	indexmonthdepart = document.urlap.mmmt.selectedIndex;
	textmonthdepart = document.urlap.mmmt.options[indexmonthdepart].text;
	indexdaydepart = document.urlap.dddt.selectedIndex;
	textdaydepart = document.urlap.dddt.options[indexdaydepart].text;
}

function validate() {
	messagehiba="<p class='levelled'>";
	hibanum=0;
	hibaheight = 210;	

	getdatum();

	validatemonth31();
	validatedatums();
	validateemail();
	validatefamilyname();
	validatefirstname();
	validatecountry();
	validateguestnumber();

	close_hiba_window();
	
	if (subsafe==1&&hibanum==0) return;

   	hiba_window=window.open('','hW','toolbar=no,scrollbars=yes,width=500,height=100');
   	hiba_window.focus();
	if (hibanum==0) {
		messagehead = messageheadsend;
		hibaheight = 570;
}
	else {
		messagehead = messageheadhiba;
}
hiba_window.moveTo(0,0);
hiba_window.resizeTo(500,hibaheight);

hiba_window.document.write("<html>");
hiba_window.document.write("<head>");
hiba_window.document.write("<title>Budapest-Astoria Apartments - " + titleparam + "</title>");
hiba_window.document.write("<link type='text/css' rel='stylesheet' href='astoria.css'>");
hiba_window.document.write("<head>");
hiba_window.document.write("<body>");
hiba_window.document.write("<br><center><img src='pictures/astoria_title2.gif' width='470px' height='40px' alt='Budapest-Astoria Apartments'>");
hiba_window.document.write("<br><p class='levelled'>" + messagehead + "</p>");
	if (hibanum==0) {
tabledisplay();
}
	else hiba_window.document.write(messagehiba + "</p>");
hiba_window.document.write("<br><p class='levelled'>" + messagefoot + "</p>");
hiba_window.document.write("</center>");
hiba_window.document.write("</body>");
hiba_window.document.write("</html>");

	leall=window.setTimeout('hiba_window.close(); alerter(); ', 20000);
}

function alerter() {
	if (hibanum==0&&subsafe==0) {
		alert(alerttext);
		document.urlap.sub.focus();
}
}

function validatecheckhu() {
	language = "hu";
	titleparam = titleparamhibahu;
	messageheadhiba = messageheadhibahu;
	messageheadsend = messageheadsendhu;
	messagefoot = messagefoothu;
	alerttext = "Ne feledje az adatokat elküldeni a Foglalás küldése* gombbal!";
	locationtext = "az Astoriánál";
	for (i in tablasorokhu) {
	tablasorok[i] = tablasorokhu[i];
}
	validate();
}

function validatechecken() {
	language = "en";
	pluraladult = "";
	pluralkid = "";
	titleparam = titleparamhibaen;
	messageheadhiba = messageheadhibaen;
	messageheadsend = messageheadsenden;
	messagefoot = messagefooten;
	alerttext = "Click on Submit form* button to send the data!";
	locationtext = "at Astoria";
	for (i in tablasoroken) {
	tablasorok[i] = tablasoroken[i];
}
	if (document.urlap.adults.value>1) pluraladult ="s";
	if (document.urlap.kids.value>1) pluralkid ="s";
	validate();
}

function validatesubhu() {
	document.urlap.emailgood.value="hu " + document.urlap.email.value + " .";
	subsafe=1;
	validatecheckhu();
	if (hibanum==0) {
	subsafe=0;
	return true;
}
	else {
	subsafe=0;
	return false;
}
}

function validatesuben() {
	document.urlap.emailgood.value="en " + document.urlap.email.value + " .";
	subsafe=1;
	validatechecken();
	if (hibanum==0) {
	subsafe=0;
	return true;
}
	else {
	subsafe=0;
	return false;
}
}


function JSFX_FloatTopDiv() {
	
	var startX = 0;
	startY = 5;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;

	function ml(id)
 {
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers) el.style=el;
		el.sP=function(x,y)
  {		
			this.style.left=x;this.style.top=y;
  }
		el.x = startX;
		if (verticalpos=="fromtop") el.y = startY;
			else
  {
				el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
				el.y -= startY;
  }	
		return el;
 }
		window.stayTopLeft=function()
 {
			if (verticalpos=="fromtop")
  {
				var pY = ns ? pageYOffset : document.body.scrollTop;
				ftlObj.y += (pY + startY - ftlObj.y)/32;
  }
				else
  {
					var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
					ftlObj.y += (pY - startY - ftlObj.y)/32;
  }
			ftlObj.sP(ftlObj.x, ftlObj.y);
			setTimeout("stayTopLeft()", 10);
 }
		ftlObj = ml("moveit");
		stayTopLeft();
}












