function createXmlHttp()
{
	var xmlHttp;
	
	if(window.ActiveXObject)
	{
		return xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest)
	{
		return xmlHttp = new XMLHttpRequest();
	}
}

function evalScript(scripts)
{	try
	{	if(scripts != '')	
		{	var script = "";
			scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
									 if (scripts !== null) script += arguments[1] + '\n';
										return '';});
			if(script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
		}
		return false;
	}
	catch(e)
	{	alert(e)
	}
}

var page_timeout = null;
var cnt_timeout = null;
var timeout_counter = 0;
function getTabContent(elmName,serv,meth,ptimeout,url_add)
{
	elm = gid(elmName);
	
	//refresh page - 0 = no refresh
	if (!ptimeout)
	{
		ptimeout = 0;
	}
	
	if (page_timeout)
	{
		clearTimeout(page_timeout);
	}

	elm.parentNode.nextSibling.innerHTML = '<div id="loader_box">' +
											'<div id="loader_text">loading data ..</div>' +
											'<img src="/newvisionimg/loader.gif" alt="" />' +
											'</div>';
	
	
	var xmlHttp = createXmlHttp();
	
	var url = "/newvision/service.php";
	var query = null;

	if (!meth)
	{
		meth = "GET";
	}
	
	if (meth == "GET")
	{
		url += "?serv=" + serv;
		
		if (url_add)
		{
			url += url_add;
		}
	}
	else
	{
		query = "serv="+serv;
	}

	if (xmlHttp)
	{
		xmlHttp.open(meth,url,true);
		xmlHttp.onreadystatechange = function()
		{
			tabs = elm.parentNode.getElementsByTagName("SPAN");
			
			for (var i = 0; i < tabs.length; i++)
			{
				tabs[i].style.borderBottom = 'solid 1px #728997';
			}
			elm.style.borderBottom = 'solid 1px #ffffff';
			
			if (xmlHttp.readyState == 4)
			{
				elm.parentNode.nextSibling.innerHTML = xmlHttp.responseText;
				evalScript(xmlHttp.responseText);
				xmlHttp = null;
				
				if (ptimeout > 0)
				{
					
					page_timeout = setTimeout("getTabContent('" + elmName + "','" + serv + "','" + meth + "'," + ptimeout + ")",ptimeout);
					timeout_counter = ptimeout/1000;
					timeoutCounter();
				}
			}
		}
		xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		xmlHttp.setRequestHeader("Last-Modified", "Sat, 1 Jan 2000 01:00:00 GMT");
		xmlHttp.setRequestHeader("Expires", "Sat, 1 Jan 2000 01:00:00 GMT");
		xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");  // HTTP/1.1
		xmlHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		xmlHttp.setRequestHeader("Pragma", "no-cache");

		xmlHttp.send(query);

	}
}

function timeoutCounter()
{
	cnt_timeout = setTimeout("timeoutCounter",1000);
	gid('refreshing_field').innerHTML = "Refreshed in " + timeout_counter + " sec";
	timeout_counter = timeout_counter-1;
}


function gid(ename)
{
	return document.getElementById(ename);
}

function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function make_this_class_blinking(wheretostart,tag,classname,colorchange,colorback)
{
	var blinking_elements =  getElementsByClassName(wheretostart,tag,classname);

	for (var i = 0; i < blinking_elements.length; i++)
	{
		blinking_elements[i].onmouseover = function(){
											this.style.backgroundColor = colorchange;
											}
		blinking_elements[i].onmouseout = function(){
											this.style.backgroundColor = colorback;
											}
	}
}
var search_panel_search_type = 'all';
function search_panel_init()
{
	lis = document.getElementById("search_panel").getElementsByTagName("li");
	
	for (var i = 0; i < lis.length; i++)
	{
		lis[i].onclick = function(){
			
			lis = document.getElementById("search_panel").getElementsByTagName("li");
			
			for (var i = 0; i < lis.length; i++)
			{
				//span
				lis[i].firstChild.style.border = '0px';
				lis[i].firstChild.style.backgroundColor = '#FFFFFF';
				lis[i].firstChild.style.backgroundImage = 'none';
				lis[i].firstChild.style.textDecoration = 'underline';
				
				//li
				lis[i].style.textDecoration = 'underline';
				lis[i].style.paddingBottom = '7px';
				lis[i].style.backgroundImage = 'none';
			}
			
			//span
			this.firstChild.style.border = 'solid 1px #8FB0D1';
			this.firstChild.style.backgroundColor = '#C3E2FF';
			this.firstChild.style.backgroundImage = 'url("../newvisionimg/search_panel_sel_top.jpg")';
			this.firstChild.style.backgroundRepeat = 'repeat-x';
			this.firstChild.style.backgroundPosition = 'top';
			this.firstChild.style.textDecoration = 'none';
			
			//save selected value
			search_panel_search_type = this.firstChild.className;
			
			//li
			this.style.textDecoration = 'none';
			this.style.paddingBottom = '7px';
			this.style.backgroundImage = 'url("../newvisionimg/search_panel_sel_down.jpg")';
			this.style.backgroundRepeat = 'no-repeat';
			this.style.backgroundPosition = 'bottom center';
			
		}
	}
}

function small_search_panel_init()
{
	document.getElementById('quick_search_field').onclick = function()
	{
		if (this.value == 'Search')
		{
			this.value = '';
		}
		hw = gid('small_search_categories');
		hw.style.display = '';
	}
	
	document.getElementById('small_search_close').onclick = function()
	{
		gid('small_search_categories').style.display = 'none';
	}
}

function doSearch(frm)
{
	
	if (frm == 2)
	{
		var frmName = 'search_panel_form_id';
		var searchField = 'search_panel_keywords_id';
		var stype = search_panel_search_type;
		gid('search_panel_type').value = stype;
	}
	else
	{
		var frmName = 'smallSearchForm';
		var searchField = 'quick_search_field';
		
		var form_elements = gid(frmName).elements;
	
		for(var i = 0; i < form_elements.length; i++)
		{
			if (form_elements[i].name == "type" && form_elements[i].checked === true)
			{
				var stype = form_elements[i].value;
			}
		}
	}
	
	if (gid(searchField).value == '')
	{
		alert('Please, enter search expression');
		return false;
	}
	
	switch(stype)
	{
		case "all":
		case "dir":
		case "art":
			gid(frmName).submit();
			break;
		case "dip":
			window.location.href = '/prague/search.php?query=' + gid(searchField).value + '&do=process&titleonly=0';
			break;
		case "dit":
			window.location.href = '/prague/search.php?query=' + gid(searchField).value + '&do=process&titleonly=1';
			break;
		case "eve":
			window.location.href = '/prague/events.php?search_for=' + gid(searchField).value;
			break;
		case "job":
			window.location.href = '/prague/jobs.php?search='+ gid(searchField).value + '#resultsetstart';
			break;
		case "goo":
			window.location.href = 'http://www.google.com/search?hl=cs&q=' + gid(searchField).value + '+site%3Awww.expats.cz&lr=&aq=f&oq=';
			break;
		default:
			alert('Search type not specified.');
	}
	
	return false;
}


function getLetter(letter,serv)
{
	var hlp = gid('tabbed_box_inner_ajax_helper');
	getTabContent(hlp.previousSibling.id,serv,'GET',0,'&letter=' + letter);
}

function showBox(bid)
{
	gid(bid).style.display = gid(bid).style.display == 'none' ? '' : 'none';
}

function openNewWindow(url) {
	window.open(url,'popup');
	return false;
}