var which = 0;
var intId;

function showPhoto() {
	if (curPhoto>imgCount) {curPhoto=1;}
	if (curPhoto<1) {curPhoto=imgCount;}
	document.getElementById("photoView").src=photos[curPhoto].src;
	document.getElementById("phc").innerHTML=curPhoto.toString();
}

function initObject() {
	loadPhotos();
	intId = setInterval("chkPhotosLoaded()",50);
}

function chkPhotosLoaded() {
	var pCntRun = 1;
	var pCntRdy = 0;
	for (pCntRun=1;pCntRun<=imgCount;pCntRun++) if (photos[pCntRun].complete) pCntRdy++;

	document.getElementById('loadFill').style.width = parseInt((300/imgCount)*pCntRdy)+'px';
	document.getElementById('apLoaded').innerHTML = pCntRdy+' / '+imgCount;

	if (pCntRdy==imgCount) {
		clearInterval(intId);
		intId = setInterval("switchElements()",2000);
	}
}

function switchElements() {
	clearInterval(intId);
	document.getElementById('apLoaded').style.visibility='hidden';
	document.getElementById('apLoaded').style.display='none';
	document.getElementById('loadBar').style.visibility='hidden';
	document.getElementById('loadBar').style.display='none';
	document.getElementById('photoNav').style.visibility='visible';
	document.getElementById('photoNav').style.display='block';
}

function show(elementID) {
	var element = document.getElementById("tblData"+elementID);
	element.style.visibility = "visible";
	element.style.display = "block";
	element=null;

	var element2 = document.getElementById("tab"+elementID);
	element2.style.color="#444444";
	element2.style.backgroundColor="#CCCCCC";
	element2=null;

	var element3 = document.getElementById("tdTab"+elementID);
	element3.style.borderRightColor="#BD2024";
	element3.style.borderBottomColor="#CCCCCC";
	element3.style.color="#444444";
	element3.style.backgroundColor="#CCCCCC";
	element3=null;
}

function hide(elementID) {
	var element = document.getElementById("tblData"+elementID);
	element.style.visibility = "hidden";
	element.style.display = "none";
	element=null;

	var element2 = document.getElementById("tab"+elementID);
	element2.style.color="#FFFFFF";
	element2.style.backgroundColor="#BD2024";
	element2=null;
	
	var element3 = document.getElementById("tdTab"+elementID);
	element3.style.borderColor="#BD2024";
	element3.style.color="#FFFFFF";
	element3.style.backgroundColor="#BD2024";
	element3=null;
}

function omOver(elementID) {
	document.getElementById(elementID).style.textDecoration="underline";
}

function omOut(elementID) {
	document.getElementById(elementID).style.textDecoration="none";
}

//style='font:bold 8pt Arial, Helvetica, sans-serif; color:#444444; '
var searchPlace = "search place";
var pleaseWait = "please wait";
if (curLanguage=="de") {searchPlace="Platz Suchen";pleaseWait="Bitte warten...";}
if (curLanguage=="nl") {searchPlace="plaats zoeken";pleaseWait="een moment gedult a.u.b...";}
if (curLanguage=="pl") {searchPlace="szukaj miejsce";pleaseWait="prosz&#281; czecka&#247;...";}
var startSrng="<a href=javascript:placeTypeSupport(document.getElementById('place').value)>"+searchPlace+"</a>";
var stopSrng="<div style='font:bold 8pt Arial, Helvetica, sans-serif; color:#BD2024; '>"+pleaseWait+"...</div>";
var placeselect;

function enable() {
	document.getElementById("selectprovince").disabled=false;
	document.getElementById("place").disabled=false;
	document.getElementById("placeselect").disabled=false;
}

function disable() {
	document.getElementById("selectprovince").disabled=true;
	document.getElementById("place").disabled=true;
	document.getElementById("placeselect").disabled=true;
}

function placeTypeSupport(word) {
	placeselect = document.getElementById("placeselect");

	placeselect.innerHTML="";
	for (i=0;i<placeselect.childNodes.length;i++) {
		placeselect.removeChild("option");
	}
	if (startLoading("/showplaces.xml?w=0&prid="+document.getElementById("selectprovince").value+"&place="+word+"&pid=0")==false) {
		var option = document.createElement("option");
		option.innerHTML="Error!";
		option.setAttribute("value","-1");
		placeselect.appendChild(option);
	} else {
		disable();
		document.getElementById("searchAndStop").innerHTML=stopSrng;
	}
}

function getPlaceById(pid) {
	placeselect = document.getElementById("placeselect");

	placeselect.innerHTML="";
	for (i=0;i<placeselect.childNodes.length;i++) {
		placeselect.removeChild("option");
	}
	if (startLoading("/showplaces.xml?w=1&prid="+document.getElementById("selectprovince").value+"&place=0&pid="+pid)==false) {
		var option = document.createElement("option");
		option.innerHTML="Error!";
		option.setAttribute("value","-1");
		placeselect.appendChild(option);
	} //else {
		//disable();
		//document.getElementById("searchAndStop").innerHTML=stopSrng;
	//}
}



var xmlDoc;
var xmlSupport;

function startLoading(xmlFile) {
	if (document.implementation && document.implementation.createDocument) {
		xmlDoc = document.implementation.createDocument("","",null);
		xmlDoc.onload = function() {
			xmlLoaded();
		}
	} else if (typeof ActiveXObject != "undefined") {
		if (document.getElementById("msxml").async) {
			xmlDoc = new ActiveXObject("Msxml.DOMDocument");
			xmlDoc.onreadystatechange = function() {
				if (xmlDoc.readyState == 4) {
					xmlLoaded();
				}
			}
		}
	}
	if (xmlDoc && typeof xmlDoc.load != "undefined") {
		xmlDoc.async = true;
		xmlDoc.load(xmlFile);
		return true;
	}
	return false;
}

function xmlLoaded() {
	var oneRecord,m=0;
	var data = xmlDoc.getElementsByTagName("places")[0];
	for (m=0;m<data.childNodes.length;m++) {
		if (data.childNodes[m].nodeType==1) {
			oneRecord = data.childNodes[m];
			if (oneRecord.nodeName=="place") {
				var option = document.createElement("option");
				option.innerHTML=oneRecord.getElementsByTagName("name")[0].firstChild.nodeValue;
				option.setAttribute("value",oneRecord.getElementsByTagName("pid")[0].firstChild.nodeValue);
				placeselect.appendChild(option);
				if (which=="0") document.getElementById("specific").innerHTML="";
			} else if (oneRecord.nodeName=="results") {
				if (parseInt(oneRecord.firstChild.nodeValue)==0) {
					var option = document.createElement("option");
					var noResult = "no results found";
					if (curLanguage=="de") noResult="keine Ergebnisse gefunden";
					if (curLanguage=="nl") noResult="geen resultaten gevonden";
					if (curLanguage=="pl") noResult="brak wyników wyszukiwania";

					option.innerHTML=noResult;
					option.setAttribute("value","-1");
					placeselect.appendChild(option);
					if (which=="0") document.getElementById("specific").innerHTML="";
				} else if (parseInt(oneRecord.firstChild.nodeValue)==-10) {
					var option = document.createElement("option");
					var tooManyResults = "found too many results";
					if (curLanguage=="de") tooManyResults="zu viele Ergebnisse gefunden";
					if (curLanguage=="nl") tooManyResults="te veel resultaten gevonden";
					if (curLanguage=="pl") tooManyResults="znaleziono zbyt wiele wyników";
					option.innerHTML=tooManyResults;
					option.setAttribute("value","-10");
					placeselect.appendChild(option);

					var moreDetailed = "Be more exact";
					if (curLanguage=="de") moreDetailed="Schreib genauer";
					if (curLanguage=="nl") moreDetailed="Schrijf preciezer";
					if (curLanguage=="pl") moreDetailed="Okresl dokladniej";
					if (which=="0") document.getElementById("specific").innerHTML=moreDetailed+" >>";
				}
			}
		}
	}

	if (which=="0") {
		enable();
		document.getElementById("searchAndStop").innerHTML=startSrng;
	}
}

function openCalendar() {
	var tempUrl = "calendar.jsp"+
				"?jan="+document.getElementById("jan").innerHTML+
				"&feb="+document.getElementById("feb").innerHTML+
				"&mar="+document.getElementById("mar").innerHTML+
				"&apr="+document.getElementById("apr").innerHTML+
				"&may="+document.getElementById("may").innerHTML+
				"&jun="+document.getElementById("jun").innerHTML+
				"&jul="+document.getElementById("jul").innerHTML+
				"&aug="+document.getElementById("aug").innerHTML+
				"&sep="+document.getElementById("sep").innerHTML+
				"&oct="+document.getElementById("oct").innerHTML+
				"&nov="+document.getElementById("nov").innerHTML+
				"&dec="+document.getElementById("dec").innerHTML;
	open(tempUrl,"calendar","top=200,left=200,height=200,width=550");
	tempUrl="";
}

function openObjPrnFrn() {
	//window.open("printerfriendly.jsp","printerfriendly","toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,top=0,left=0,height=550,width=800");
	window.open("printerfriendly.jsp","printerfriendly","menubar,scrollbars,resizable,top=0,left=0,height=550,width=800");
}


var cFg1='#FFFFFF';
var cBg1='#BD2024';
var cFg2='#444444';
var cBg2='#CCCCCC';

function ROMOver(objNr) {
	var tempElement=document.getElementById("resultName"+objNr);
	tempElement.style.color=cFg1;
	tempElement.style.backgroundColor=cBg1;
	tempElement.style.cursor="pointer";
	tempElement=document.getElementById("resultPlace"+objNr);
	tempElement.style.color=cFg1;
	tempElement.style.backgroundColor=cBg1;
	tempElement.style.cursor="pointer";
	tempElement=document.getElementById("resultVar"+objNr);
	tempElement.style.color=cFg1;
	tempElement.style.backgroundColor=cBg1;
	tempElement.style.cursor="pointer";
	tempElement=document.getElementById("resultLink"+objNr);
	tempElement.style.color=cFg1;
	tempElement.style.backgroundColor=cBg1;
	tempElement.style.cursor="pointer";
	tempElement=null;
}

function ROMOut(objNr) {
	var tempElement=document.getElementById("resultName"+objNr);
	tempElement.style.color=cFg2;
	tempElement.style.backgroundColor=cBg2;
	tempElement.style.cursor="default";
	tempElement=document.getElementById("resultPlace"+objNr);
	tempElement.style.color=cFg2;
	tempElement.style.backgroundColor=cBg2;
	tempElement.style.cursor="default";
	tempElement=document.getElementById("resultVar"+objNr);
	tempElement.style.color=cFg2;
	tempElement.style.backgroundColor=cBg2;
	tempElement.style.cursor="default";
	tempElement=document.getElementById("resultLink"+objNr);
	tempElement.style.color=cBg1;
	tempElement.style.backgroundColor=cBg2;
	tempElement.style.cursor="default";
	tempElement=null;
}

function getParameterNV(paramName,nv) {
	var queryArray=new Array();
	var paramArray=new Array();
	var tempArray=new Array();
	var paramValue="";
	
	queryArray=window.location.href.split("?");

	if (queryArray.length>1) {
		paramArray=queryArray[1].split("&");
		for (var lanPos=0;lanPos<paramArray.length;lanPos++) {
			tempArray=paramArray[lanPos].split("=");
			if (tempArray[0]==paramName) {
				switch (nv) {
					case 0:
						//return the parameter name + value
						return tempArray[0]+"="+tempArray[1];
					case 1:
						//return the parameter name
						return tempArray[0];
					case 2:
						//return the parameter value
						return tempArray[1];
				}
			}
		}
	}
	
	queryArray=null;
	paramArray=null;
	tempArray =null;
	return null;
}

function getAddPars() {
	var OOURL="";
	for (var i=1;i<11;i++) {
		var tPar=getParameterNV("acc"+i,0);
		if (tPar!=null) OOURL+="&"+tPar;
		tPar=null;
	}

	if (getParameterNV("prid",0)!=null) OOURL+="&"+getParameterNV("prid",0);
	if (getParameterNV("pid",0)!=null) OOURL+="&"+getParameterNV("pid",0);
	if (getParameterNV("around",0)!=null) OOURL+="&"+getParameterNV("around",0);
	if (getParameterNV("inclplace",0)!=null) OOURL+="&"+getParameterNV("inclplace",0);
	if (getParameterNV("pers",0)!=null) OOURL+="&"+getParameterNV("pers",0);
	if (getParameterNV("start",0)!=null) OOURL+="&"+getParameterNV("start",0);

	//OOURL+="&"+getParameterNV("arrDay",0)+"&"+getParameterNV("arrMonth",0)+"&"+getParameterNV("arrYear",0)+
	//	"&"+getParameterNV("depDay",0)+"&"+getParameterNV("depMonth",0)+"&"+getParameterNV("depYear",0);

	return OOURL;
}

function searchOpen() {window.location.href="/search/searchpr.jsp?"+getAddPars().substring(1);}
function resultOpen() {window.location.href="/search/results?"+getAddPars().substring(1);}
function objOpen(ID) {window.location.href="/search/object?oid="+ID+getAddPars();}
function accOpen(OID,RID) {window.location.href="/search/accommodation?oid="+OID+"&rid="+RID+getAddPars();}
function objOpenDir(map) {window.location.href="http://home.exploringpoland.com/"+map;}
function accOpenDir(OID,RID,map) {window.location.href="http://home.exploringpoland.com/"+map+"?rid="+RID;}


function objOMOver(objNr) {
	var tempElement=document.getElementById("objAD"+objNr);
	tempElement.style.color=cFg1;
	tempElement.style.backgroundColor=cBg1;
	tempElement.style.cursor="pointer";

	tempElement=document.getElementById("objADP"+objNr);
	tempElement.style.color=cFg1;
	tempElement.style.backgroundColor=cBg1;
	tempElement.style.cursor="pointer";

	tempElement=document.getElementById("objAL"+objNr);
	tempElement.style.color=cFg1;
	tempElement.style.backgroundColor=cBg1;
	tempElement.style.cursor="pointer";

	tempElement=null;
}

function objOMOut(objNr) {
	var tempElement=document.getElementById("objAD"+objNr);
	tempElement.style.color=cFg2;
	tempElement.style.backgroundColor=cBg2;
	tempElement.style.cursor="default";

	tempElement=document.getElementById("objADP"+objNr);
	tempElement.style.color='#BD2024';
	tempElement.style.backgroundColor=cBg2;
	tempElement.style.cursor="default";

	tempElement=document.getElementById("objAL"+objNr);
	tempElement.style.color=cFg2;
	tempElement.style.backgroundColor=cBg2;
	tempElement.style.cursor="default";

	tempElement=null;
}

function bookmark(bmurl,bmtitle) {
	if (window.sidebar) {
	    window.sidebar.addPanel(bmtitle, bmurl, "");
	} else if (document.all) {
		window.external.AddFavorite(bmurl,bmtitle);
	}
}