function getTarget(e)
{
  evt = e || window.event;
  return(evt.target || evt.srcElement);
}


function popAdmin(url)
{
	var win=window.open(url, 'winname', 'scrollbars=1,status=0, location=0, resizable=1, menubar=0, directories=0, toolbar=0, width=700,height=550, top=10, left=10');
}

		function opengal(laius,korgus,id,pid,kus,table,lang){
			var laius = '500';
			var korgus = '400';
			var kyssa=window.open('/gal.php?lang='+lang+'&pid='+pid+'&id='+id+'&kus='+kus+'&table='+table+'&did=<?=$did?>&path=<?=$path?>&width='+laius+'&height='+korgus,'','scrollbars=yes,width='+laius+',height='+korgus+',resizable=yes,top=10,left=10');	
		}		

		function nothing(){
			return;
		}	

		function checknum(val) /*forms*/
		{
			temp_val=val.split("");
			_exp = new RegExp(/\d/);
			_exp2 = new RegExp(/,/);
			_exp3 = new RegExp(/\./);
			ret_str='';
			for(i=0;i<temp_val.length;i++)
			{
				temp=_exp.test(temp_val[i]);
				temp2=_exp2.test(temp_val[i]);
				temp3=_exp3.test(temp_val[i]);
				if(temp || temp2 || temp3 || temp_val[i]==' ') 
				{
					ret_str+=temp_val[i];
				}

			}
			return ret_str;
		}


function popWin(url,he,wi){
		if(he<=0)he = '300';
		if(wi<=0)wi = '300';
		
		var kyssa=window.open(url,'','scrollbars=yes,width='+wi+',height='+he+',resizable=yes,top=10,left=10');	
}

	function myHide(useDiv){
		 if (document.getElementById) {
				eval("document.getElementById(useDiv).style.visibility = \"hidden\"");
			  } else {
				if (document.layers) {
					document.layers[useDiv].visibility = 'hidden';
				} else {
				  if (document.all) {
					eval("document.all."+useDiv+".style.visibility = \"hidden\"");
				  }
				}
			  }
		}

		function myShow(useDiv)
		{
			 if (document.getElementById) {
				eval("document.getElementById(useDiv).style.visibility = \"visible\"");
			  } else {
				if (document.layers) {
					document.layers[useDiv].visibility = 'show';
				} else {
				  if (document.all) {
					eval("document.all."+useDiv+".style.visibility = \"visible\"");
				  }
				}
			  }

		}

		function confirmation2(url,txt)
		{
			input_box=confirm(txt);
			if (input_box==true){ document.location=url}
		}

function returnObjById( id ) 
{ 
	if (document.getElementById) 
		var returnVar = document.getElementById(id); 
	else if (document.all) 
		var returnVar = document.all[id]; 
	else if (document.layers) 
		var returnVar = document.layers[id]; 
	else 
		var returnVar = document.getElementById(id); 
	return returnVar; 
} 

var Telli=window["Telli"];

function select_change(value) {
	window.top.location.href='index.php?'+value;
}

function telli(lang,id) {
	if(Telli)
		Telli.close();
	Telli=window.open('telli.php?lang='+lang+'&id='+id,'Telli','toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes,top=30,left=100,width=600,height=500');
}

function sendTellimine(){
	var firstname = document.forms['tellimine'].firstname.value;
	var lastname = document.forms['tellimine'].lastname.value;
	var mail_s = document.forms['tellimine'].mail_s.value;
	var phone = document.forms['tellimine'].phone.value;
	var adults = document.forms['tellimine'].adults.value;
	var children = document.forms['tellimine'].children.value;
	var comments = document.forms['tellimine'].comments.value;
	var rp = document.getElementById('rp').value;
	var id = document.forms['tellimine'].id.value;
	var lang = document.forms['tellimine'].lang.value;
	var bron = document.forms['tellimine'].bron.value;
	var price = document.forms['tellimine'].price.value;
	var reisikorraldaja = document.getElementById('reisikorraldaja').value;

	//var soodus = document.forms['tellimine'].soodus.value;

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

	$.ajax({
		url: "ajax.php",
		type: "POST",
		data: "action=telli&firstname=" + firstname + "&lastname=" + lastname + "&mail_s=" + mail_s + "&phone=" + phone + "&adults=" + adults + "&children=" + children + "&comments=" + comments + "&rp=" + rp + "&id=" + id + "&lang=" + lang + "&bron=" + bron + "&price=" + price + "&reisikorraldaja=" + reisikorraldaja,
		dataType: "html",
		success: function(data) {$("#pakkuminewait").html(data);},
		error: function() { alert("error") },
		cache: true
	});
}

function sendTellimineLinn(){
	var firstname = document.forms['tellimine'].firstname.value;
	var lastname = document.forms['tellimine'].lastname.value;
	var mail_s = document.forms['tellimine'].mail_s.value;
	var phone = document.forms['tellimine'].phone.value;
	var adults = document.forms['tellimine'].adults.value;
	var children = document.forms['tellimine'].children.value;
	var comments = document.forms['tellimine'].comments.value;
	var rp = document.forms['tellimine'].rp.value;
	var id = document.forms['tellimine'].id.value;
	var lang = document.forms['tellimine'].lang.value;
	var bron = document.forms['tellimine'].bron.value;
	var price = document.forms['tellimine'].price.value;


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

	$.ajax({
		url: "ajax.php",
		type: "POST",
		data: "action=telliLinn&firstname=" + firstname + "&lastname=" + lastname + "&mail_s=" + mail_s + "&phone=" + phone + "&adults=" + adults + "&children=" + children + "&comments=" + comments + "&rp=" + rp + "&id=" + id + "&lang=" + lang + "&bron=" + bron + "&price=" + price,
		dataType: "html",
		success: function(data) {$("#pakkuminewait").html(data);},
		error: function() { alert("error") },
		cache: true
	});
}

function changePrice(hotel_id, rp_id, tid, soodus){
	$.ajax({
		url: "ajax.php",
		type: "POST",
		data: "action=changePrice&hotel_id=" + hotel_id + "&rp_id=" + rp_id + "&soodus=" + soodus + "&tid=" + tid,
		dataType: "html",
		success: function(data) {$("#price").html(data);$("#price_input").val(data);},
		error: function() { alert("error") },
		cache: true
	});
}

function changePriceLinn(id, rp_id){
	$.ajax({
		url: "ajax.php",
		type: "POST",
		data: "action=changePriceLinn&id=" + id + "&rp_id=" + rp_id,
		dataType: "html",
		success: function(data) {$("#price").html(data);$("#price_input").val(data);},
		error: function() { alert("error") },
		cache: true
	});
}

function changeTid(hotel_id, tid, soodus) {
	$.ajax({
		url: "ajax.php",
		type: "POST",
		data: "action=changeTid&hotel_id=" + hotel_id + "&tid=" + tid + "&soodus=" + soodus,
		dataType: "html",
		success: function(data) {$("#dates").html(data); $("#price").html(""); $("#price_input").val(0);},
		error: function() { alert("error") },
		cache: true
	});
}

// Imagery's slideshow.
function applyHandler(o, e, f) { 
e = (e instanceof Array) ? (arguments.callee(o, e[1], f), e[0]) : e;
return (o.attachEvent) ? o.attachEvent(e, f) : (o.addEventListener) ? o.addEventListener(e.substr(2), f, false) : false;
} 

function initScroller() {
	try
	{
		var t = document.getElementById('control'), s = document.getElementById('scroller');
		t.back_control = t.getElementsByTagName('div')[0];
		(t.scroll_obj = s).scroll_position = s.scroll_active = 0;
		s.scroll_range = s.offsetWidth - s.parentNode.offsetWidth;
		return applyHandler(t, ['onmouseover', 'onmouseout'], scrollControl);		
	}
	catch (e)
	{
	}
} 

function scrollControl(e) {
var el = (e = e || event).target || e.srcElement, t = el.tagName.toLowerCase(), p, b;
if(t == 'div') { p = el.parentNode.scroll_obj;
return (p.scroll_active = !p.scroll_active) ? (b = (el == el.parentNode.back_control), scrollProcess(p, b)) : false;
} else return false; 
} 

function scrollProcess(o, b) {
var p = o.scroll_position; 
o.scroll_position = (!b && p > -o.scroll_range) ? p - 5 : (b && p < 0) ? p + 5 : (o.scroll_active = 0, b) ? 0 : p;
o.style.left = o.scroll_position + 'px';
return (o.scroll_active) ? window.setTimeout(function() { return scrollProcess(o, b); }, 10) : false; 
} 
applyHandler(window, 'onload', initScroller);



