var oLED = new Date()

function getTommorow(S) {
	oS = makeDate(S["day"], S["month"], S["year"]);
	oLED = new Date();
	oLED.setTime(oS.getTime() + 86400000);
	return oLED;
}

function makeDate(d,m,y) {
//	alert(d + "\n" + m + "\n" + y)
	oS = new Date();
	oS.setDate(d);
	oS.setMonth(m - 1);
	oS.setYear(y);
//	alert(oS.getTime())
	return oS;
}

function makeFDate(sDI) {
	oF = document.forms["fsearch"];
	return makeDate(1+oF.elements[sDI + "_Day"].selectedIndex, 1+oF.elements[sDI + "_Month"].selectedIndex, oF.elements[sDI + "_Year"].options[oF.elements[sDI + "_Year"].selectedIndex].value);
}

function setFDate(sDI, oD) {
	oF = document.forms["fsearch"];
	setFOption(oF, sDI+"_Day", oD.getDate());
	setFOption(oF, sDI+"_Month", oD.getMonth()+1);
	setFOption(oF, sDI+"_Year", oD.getFullYear());
}

function setFOption(oF,sDI,iV) {
	oE = oF.elements[sDI];
	for(i=0;i<oE.options.length;i++) {
		if (oE.options[i].value == iV) {
			oE.selectedIndex=i;
			return;
		}
	}
}

function fixDates(oE) {
	aN = oE.name.split("_");
	if (aN[0] == "start" || aN[0] == "end") {
		oST = makeFDate("start");
		oEN = makeFDate("end");

		if (oEN.getTime()<=oST.getTime()) {
			if (aN[0] == "start") {
				oEN = new Date();
				oEN.setTime(oST.getTime() + 86400000);
				setFDate("end", oEN);
			}
			if (aN[0] == "end") {
				setFDate("end", oLED);
				return;
			}
		}
		oLED = oEN;
	}
	if (aN[0]=="SGL" || aN[0]=="DBL") {
		oF = oE.form;
		iA = 1 * getOptionVal(oF, "SGL") + 2 * getOptionVal(oF, "DBL");
		setFOption(oF, "adults", iA);
	}
}

function drawOptions(sName, iS, iE, iV, bLZ) {
	HT = '';
	HT += '<select name="' + sName + '" style="width: ' + ((iE>99)?62:45) + 'px"  onChange="fixDates(this)">';
for (i=iS; i<iE+1; i++) {
	HT += '<option value="' + i + '"' + ((iV==i)?' selected="selected"':'') + '>' + ((i<10 && bLZ)?"0"+i:i) + '</option>';
}
HT += '</select>';

return HT;
}

function checkSearch(oF) {
	SGL = getOptionVal(oF,"SGL");
	DBL = getOptionVal(oF,"DBL");
	adults = getOptionVal(oF,"adults");
	if ((1*SGL + 2*DBL)!=adults) {
		alert("Number of adults, doesn't fit to the number of (" + (1*SGL+2*DBL) + ") bed(s)!");
		return false;
	}
	if ((Number(SGL)+Number(DBL))>3) {
		window.open("http://book.visitserbia.org/popup_more_rooms.php", "popup_more_rooms", "width=300,height=350,scrollbars=no,status=no");
		return false;
	}
	return true;
}

function getOptionVal(oF,sN) {
	oE = oF.elements[sN];
	return oE.options[oE.selectedIndex].value;
}
D = new Array()
S = new Array()
E = new Array()

D["day"] = 9
D["month"] = 2
D["year"] = 2010
S=D

oE = getTommorow(S)
E["day"] = oE.getDate()
E["month"] = oE.getMonth() + 1
E["year"] = oE.getFullYear()

document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"http://book.visitserbia.org/css/remote_search_css.php?BGCOLOR=%23ffffff&FONTCOLOR=%23000000&BORDERSIZE=2&BORDERCOLOR=%23003366\">')
document.write('<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"180\" id=\"vsrs_search_caontainer\">')
document.write('	<tr>')
document.write('		<td width=\"180\" align=\"center\">')
document.write('')
document.write('<form action=\"http://book.visitserbia.org/results.php\" method=\"get\" name=\"vsrs_search_form\" style=\"margin: 0px; padding 0px\" onSubmit=\"return checkSearch(this)\" target=\"_blank\">')
document.write('<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\" id=\"vsrs_search\">')
document.write('	<tr>')
document.write('		<th colspan=\"2\">Accomodation Search in Serbia</th>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<td colspan=\"2\" valign=\"top\">City / Town<br><input type=\"text\" style=\"width: 140px\" name=\"City\"/></td>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<td colspan=\"2\" valign=\"top\">Hotel/Chain<br><input type=\"text\" style=\"width: 140px\" name=\"Hotel\"/></td>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<td colspan=\"2\" valign=\"top\">Minimal Rating<br><select name=\"minRating\" class=\"standard\" style=\"width: 140px\"><option value=\"0\">all</option><option value=\"1\">*</option><option value=\"2\">* *</option><option value=\"3\">* * *</option><option value=\"4\">* * * *</option><option value=\"5\">* * * * *</option><option value=\"6\">* * * * * *</option></select></td>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<td colspan=\"2\" valign=\"top\">Arrival (D.M.Y.)<br>')



document.write(drawOptions("start_Day", 1, 31, S["day"],true) + ".")
document.write(drawOptions("start_Month", 1, 12, S["month"],true) + ".")
document.write(drawOptions("start_Year", D["year"], 3 + D["year"], S["year"],true))



document.write('</td>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<td colspan=\"2\" valign=\"top\">Departure (D.M.Y.)<br>')



document.write(drawOptions("end_Day", 1, 31, E["day"],true) + ".")
document.write(drawOptions("end_Month", 1, 12, E["month"],true) + ".")
document.write(drawOptions("end_Year", D["year"], 3 + D["year"], E["year"],true))



document.write('</td>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<td valign=\"top\">Single Rooms<br>')



document.write(drawOptions("SGL", 0, 3, 1,false))


document.write('</td>')
document.write('		<td valign=\"top\">Double Rooms<br>')



document.write(drawOptions("DBL", 0, 3, 0,false))


document.write('</td>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<td valign=\"top\">Adults<br>')



document.write(drawOptions("adults", 1, 10, 1,false))



document.write('</td>')
document.write('		<td valign=\"top\">Children<br>')



document.write(drawOptions("children", 0, 6, 0,false))



document.write('</td>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<td colspan=\"2\" valign=\"top\">Prefered currency<br><select name=\"Currency\" class=\"standard\" style=\"width: 140px\"><option value=\"EUR\">&euro;</option><option value=\"CSD\">RSD</option></select></td>')
document.write('	</tr>')
document.write('	<tr>')
document.write('		<th colspan=\"2\"><input type=\"hidden\" name=\"REFID\" value=\"b92\"/><input type=\"hidden\" name=\"L\" value=\"EN\"/><input name=\"trazi\" type=\"submit\" value=\"SEARCH\" style=\"width: 140px\"/></th>')
document.write('	</tr>')
document.write('</table>')
document.write('</form>')
document.write('')
document.write('</td>')
document.write('</tr>')
document.write('</table>')

