
function checkKey(submit)
{
	var key; 
	if(window.event){ key = event.keyCode;}else if(event.which){ key = event.which;} 
	if (key == 13)  
   {
		searchSubmit(submit); 
		return false;
   }
	else
	return true;
}


function getQueryVariable(variable,url) { 
  var url_string=url.toString();
  var end = url_string.split("?"); 
  var vars =  end[1].split("&"); 
  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return pair[1]; 
    } 
  } 
} 



function searchString(obj,tr)
{
	if (tr==1){
		document.tempform.tr.value = 1;
	}
	else document.tempform.tr.value = 0;
	search=document.getElementById('searchField_front').value;
	loc=document.getElementById('locationField_front').value;
	c_from_get = getQueryVariable("c",obj);
	l_from_get = getQueryVariable("l",obj);
	z_from_get = getQueryVariable("z",obj);
	p_from_get = getQueryVariable("p",obj);
	document.tempform.c.value = c_from_get;
	document.tempform.l.value = l_from_get;
	document.tempform.z.value = z_from_get;
	document.tempform.p.value = p_from_get;
	
	document.tempform.search.value = search;
	document.tempform.p.value = loc;
	document.tempform.submit();
	return false;
}


function changeSearchParams(c,l,tr)
{
	if (tr==1){
		document.tempform.tr.value = 1;
	}
	else document.tempform.tr.value = 0;
	search=document.getElementById('searchField_front').value;
	loc=document.getElementById('locationField_front').value;
	document.tempform.c.value = c;
	document.tempform.l.value = l;
	
	document.tempform.search.value = search;
	document.tempform.p.value = loc;
	document.tempform.submit();
	return false;
}

function searchSubmit(pageaddr)
{
	var search=document.getElementById('searchField_front').value;
	var loc=document.getElementById('locationField_front').value;
	document.tempform.search.value = search;
	document.tempform.p.value = loc;
	document.tempform.action = pageaddr;//"searchresults.php";
	document.tempform.submit();
	return false;
}


function onopenlang(somediv) {
	if (somediv.style.visibility != "visible") {
    	somediv.style.visibility = "visible";
    	if (somediv.id=='langselect'){
	        somediv.style.width = "420px";
	        somediv.style.height = "120px";
    	}
    	else{
    		somediv.style.width = "420px";
	        somediv.style.height = "100px";
    	}
	}
	else onlangclose(somediv);
}

function onlangclose(somediv) {
	somediv.style.visibility = "hidden";
	somediv.style.width = "1px";
	somediv.style.height = "1px";
}


function buttonmouseover(btn,image){
	btn.style.backgroundImage = "url(\'images/" + image + "\')";
}


function submitenter(myfield, e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
        myfield.form.submit();
        return false;
    }
    else
        return true;
}
		

function langclick(languagecode) {
    var searchform = document.getElementById('searchform');
	searchform.l.value = languagecode;
	searchform.op.value = "changelanguage";
    //searchform.c.value = iso;
	searchform.action = "index.php";
	searchform.submit(); 
}    

function mapclick(iso) {
    var searchform = document.getElementById('searchform');
    if (searchform.c != iso) {
        searchform.op.value = "changecountry";
        searchform.c.value = iso;
        searchform.action = "index.php";
        searchform.submit();
    }
}

// functions for map tooltips ----------------------------------------------
function initmapover(iso) {

    mapovertooltip(iso, '');
    document.onmousemove = handleMouseMove;
}

function handleMouseMove(e) {
    var  xMousePos = 0;
    var yMousePos = 0;
    if (document.all) {
        xMousePos = event.clientX; yMousePos = event.clientY;
    }
    else {
        xMousePos = e.pageX; yMousePos = e.pageY;
    }
    AssignPosition(document.getElementById("tooltipmap"), xMousePos, yMousePos);
    return true;
}

function AssignPosition(d, cX, cY) {
    var rX = 0;
    var rY = 0;
    if (self.pageYOffset) {
        rX = self.pageXOffset;
        rY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        rX = document.documentElement.scrollLeft;
        rY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        rX = document.body.scrollLeft;
        rY = document.body.scrollTop;
    }
    if (document.all) {
        cX += rX;
        cY += rY;
    }
    d.style.left = (cX + 10) + "px";
    d.style.top = (cY + 10) + "px";
}

function mapoverflagtooltip(iso, tooltiptext) {
    document.getElementById("tooltipmap").innerHTML = tooltiptext;
    if (tooltiptext == "") {
        document.getElementById("tooltipmap").style.visibility = "hidden";
    }
    else {
        document.getElementById("tooltipmap").style.visibility = "visible";
    }
    mapover(iso);    
}
function mapovertooltip(iso, tooltiptext) {
    document.getElementById("tooltipmap").innerHTML = tooltiptext;
    if (tooltiptext == "") {
        document.getElementById("tooltipmap").style.visibility = "hidden";
    }
    else {
        document.getElementById("tooltipmap").style.visibility = "visible";
    }
    mapover(iso);    
}
// end of map tooltip functions ----------------------------------------------
function mapover(iso){
	var x=0;
	var y = 0;
	var c = 'transparent.png';
	var tra = document.getElementById('tra');
	
	if (iso == 'li') { x = 139, y = 233, c = 'li.png' }
	if (iso=='ad') {x=101,y=310,c='ad.png'}
	if (iso=='be') {x=119,y=218,c='be.png'}
	if (iso=='nl') {x=124,y=198,c='nl.png'}
	if (iso=='is') {x=20,y=25,c='is.png'}
	if (iso=='se') {x=175,y=28,c='se.png'}
	if (iso=='ee') {x=235,y=121,c='ee.png'}
	if (iso=='fi') {x=211,y=12,c='fi.png'}
	if (iso=='no') {x=142,y=-92,c='no.png'}
	if (iso=='ie') {x=36,y=165,c='ie.png'}
	if (iso=='gb') {x=57,y=133,c='gb.png'}
	if (iso=='dk') {x=84,y=101,c='dk.png'}
	if (iso=='sk') {x=217,y=235,c='sk.png'}
	if (iso=='cz') {x=183,y=223,c='cz.png'}
	if (iso=='lv') {x=234,y=139,c='lv.png'}
	if (iso=='lt') {x=234,y=157,c='lt.png'}
	if (iso=='pl') {x=193,y=181,c='pl.png'}
	if (iso=='by') {x=253,y=155,c='by.png'}
	if (iso=='ch') {x=139,y=259,c='ch.png'}
	if (iso=='at') {x=165,y=245,c='at.png'}
	if (iso=='hu') {x=214,y=244,c='hu.png'}
	if (iso=='si') {x=194,y=267,c='si.png'}
	if (iso=='me') {x=236,y=300,c='me.png'}
	if (iso=='ba') {x=213,y=284,c='ba.png'}
	if (iso=='kr') {x=195,y=270,c='kr.png'}
	if (iso=='al') {x=243,y=309,c='al.png'}
	if (iso=='mk') {x=253,y=309,c='mk.png'}
	if (iso=='bg') {x=264,y=282,c='bg.png'}
	if (iso=='pt') {x=-139,y=267,c='pt.png'}
	if (iso=='de') {x=141,y=183,c='de.png'}
	if (iso=='fr') {x=64,y=221,c='fr.png'}
	if (iso=='it') {x=143,y=266,c='it.png'}
	if (iso=='es') {x=-93,y=285,c='es.png'}
	if (iso=='rs') {x=235,y=271,c='rs.png'}
	if (iso=='md') {x=287,y=236,c='md.png'}
	if (iso=='ro') {x=245,y=240,c='ro.png'}
	if (iso=='gr') {x=249,y=309,c='gr.png'}
	if (iso=='ua') {x=255,y=184,c='ua.png'}
	if (iso=='') {x=0;y=0;c='transparent.png'}
	if(tra){
	
		tra.style.backgroundPosition=x + "px " + y + "px";
		tra.style.backgroundImage = "url(\'images/map/"+c+"\')";
	}
}