
function loadHtmlMenu(targetUrl,params){

	xmlHttp_menu=GetXmlHttpObject();

	if (xmlHttp_menu==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url=targetUrl+"?"+params;
	
	url=url+"&sid="+Math.random();

	xmlHttp_menu.onreadystatechange=function() {
		if (xmlHttp_menu.readyState==4 && xmlHttp_menu.status == 200) { 
			document.getElementById("newsMenuContent").innerHTML=xmlHttp_menu.responseText;
			$("ul.paging").quickPager();
			$("#simplePagerNavContent").hide();


		}
	};
	
	xmlHttp_menu.open("GET",url,true);
	xmlHttp_menu.send(null);


}


function loadHtmlContent(targetUrl,params,direct){

	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url=targetUrl+"?"+params;
	
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 && xmlHttp.status == 200) { 
			document.getElementById("newsContent").innerHTML=xmlHttp.responseText;
			if(direct==false){
				//loadHtmlMenu("proxyMenu.php","offset=0&count=5&"+params);
				loadHtmlMenu("admin/getNewsLinks.php","offset=0&count=5&"+params);  
			}
			updateNewsBox();
		}
	};
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);


}

function updateNewsBox(){	
	$("#newsbox").height(165);
	
	targetHeight=$("#newsTable").height();	
	
	if(targetHeight<165){
		targetHeight=165;
	}
	
	$("#newsbox").height(targetHeight);
	
	listHeight=targetHeight-68;

	$("#newsLinkList").height(listHeight);
}



function loadDownloadableFiles(targetUrl,params){

	xmlHttp_download=GetXmlHttpObject();

	if (xmlHttp_download==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url=targetUrl+"?"+params;
	
	url=url+"&sid="+Math.random();

	xmlHttp_download.onreadystatechange=function() {
		if (xmlHttp_download.readyState==4 && xmlHttp_download.status == 200) { 		
			if(xmlHttp_download.responseText==""){$("#dldTitle").fadeOut("slow");}
			document.getElementById("downloadableFilesContainer").innerHTML=xmlHttp_download.responseText ;
		}
	};
	xmlHttp_download.open("GET",url,true);
	xmlHttp_download.send(null);
}

function showDownloads(lang, title){	
	queryString="popUp=1&lang="+lang;
	queryString+="&TB_iframe=true&height=500&width=800";
	tb_show(title,"http://www.bestoftravel.cz/admin/getDownloads.php?"+queryString, null);
}


function newsletterRegister(){

	email=document.getElementById('newsletterEmailAddress').value;

	if(emailCheck(email)==true){
		xmlHttp_mail=GetXmlHttpObject();
		var url = "proxyRegister.php";
		var params = "email="+email;		
		
		xmlHttp_mail.onreadystatechange = function() {
			if(xmlHttp_mail.readyState == 4 && xmlHttp_mail.status == 200) {
				$("#newsletterThanks").slideToggle(100);
				$("#newsletterForm").slideToggle(100);
			}
		};
		
		xmlHttp_mail.open("POST", url, true);
		
		xmlHttp_mail.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp_mail.setRequestHeader("Content-length", params.length);
		xmlHttp_mail.setRequestHeader("Connection", "close");
		
		xmlHttp_mail.send(params);
	}

}


function searchHotels(lang, title){

	$("#pleaseFilter").hide();

	searchLocation=encodeURIComponent(document.forms["searchForm"].hotel_location_search.value);
	searchStars=$(".star:checked").val();
	searchName=encodeURIComponent(document.forms["searchForm"].hotel_name_search.value);

	queryString="searchLocation="+searchLocation+"&searchStars="+searchStars+"&searchName="+searchName+"&lang="+lang;

	queryString+="&TB_iframe=true&height=500&width=800";

	if(searchLocation!="" || searchStars!=null || searchName!=""){
		//tb_show("Search results","http://www.bestoftravel.cz/admin/getResults.php?"+queryString, null);
		tb_show(title,"admin/getResults.php?"+queryString, null);
	}else{
		$("#pleaseFilter").slideToggle(200);
	}

	
}


function emailCheck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid e-mail address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid e-mail address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid e-mail address")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid e-mail address")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid e-mail address")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid e-mail address")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid e-mail address")
		return false
	 }

	 return true					
}



function GetXmlHttpObject(){
var xmlHttp=null;
try {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e) {
 // Internet Explorer
 try {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e) {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;

}

function hideShowLayer(idList){
	var hideArray=idList.split(",");
	for(i=0;i< hideArray.length ;i++) {
		if(document.getElementById(hideArray[i]).className=="hidden"){
			document.getElementById(hideArray[i]).className="visible";
		}else{
			document.getElementById(hideArray[i]).className="hidden";
		}
	}
}


function selectMe(id){
	myList=$('#newsLinkList');	
	myList.children().each(function(i){ 
			$(this).find("a.current").removeClass("current");
	});

	$("#newsLink"+id).addClass("current");
}




