var floate = false;
var floateid = '';

function showsearch(op,cl){
	if(floate == true){
		clearTimeout(floateid);
		floate=false;
		}
	var docH = getPageSizeWithScroll();
	if(docH[1]-365<300) floateDoc();
	var oDIV = document.getElementById('detsearch');
	var currh = parseInt(oDIV.style.height);
	var oBtn = document.getElementById('imeklet');
	if(currh>0){
		floate = true;
		oBtn.value = op;
		floateup();
		}
	else{
		oDIV.style.display = 'block';
		oBtn.value = cl;
		floate=true;
		floatedown();
		}
	}
function floateDoc() {
	var docH = getPageSizeWithScroll();
	if(docH[1]-365<300){
		docH[1]+=25;
		document.getElementById('frame').style.height = docH[1] + 'px';
		setTimeout("floateDoc()",0);
		}
	}
function floateup(){
	var oDIV = document.getElementById('detsearch');
	var currh = parseInt(oDIV.style.height);
	if(currh>0){
		currh-=25;
		if(currh<0) currh = 0;
		oDIV.style.height = currh+"px";
		floateid=setTimeout("floateup()",0);
		}
	else{
		floate=false;
		oDIV.style.display = 'none';
		}
	}
function floatedown(){
	var oDIV = document.getElementById('detsearch');
	var currh = parseInt(oDIV.style.height);
	var docH = getPageSizeWithScroll();
	docH = docH[1];
	docH -=361;
	if(currh<docH){
		currh+=25;
		oDIV.style.height = currh+"px";
		floateid=setTimeout("floatedown()",0);
		}
	else{
		oDIV.style.height = docH+'px';
		floate=false;
		}
	}
function getdocHeight(){
	var documentHeight = document.documentElement.clientHeight; // FF, Safari, IE
	if(documentHeight < document.body.scrollHeight) // Opera
		documentHeight = document.body.scrollHeight;
	return documentHeight;
}

function getSelectElements(select,toch,main){
	if(value != ''){
		var oXMLHttp = createXMLHttp();
		var value = select.value;
		var name = select.name;
		if(main != null) main = document.getElementById(main).value; else main='';
		oXMLHttp.open("get","./select.php?v="+ value +"&n="+name+"&m="+main,true);
		oXMLHttp.onreadystatechange = function(){
			if(oXMLHttp.readyState == 4){
				if(oXMLHttp.status == 200){
					var params = '';
					var values = oXMLHttp.responseText.split('|');
					var objSel = document.getElementById(toch);
					objSel.options.length = 0;
					for(var i = 0; i<values.length; i++){
						params = values[i].split(':');
						addOption(objSel,params[1],params[0],false);
						}
					objSel.onchange();
				}else{
					newwindow(w,h,"Notika kluda " + oXMLHttp1.statusText);
					}
				}
			};
			oXMLHttp.send(null);
		}
	}
function addOption(oListbox, text, value, isDefaultSelected, isSelected)
{
  var oOption = document.createElement("option");
  oOption.appendChild(document.createTextNode(text));
  oOption.setAttribute("value", value);

  if (isDefaultSelected) oOption.defaultSelected = true;
  else if (isSelected) oOption.selected = true;

  oListbox.appendChild(oOption);
}

function changesearch(value,operation,city) {
	if(value != ''){
		var oXMLHttp2 = createXMLHttp();
		oXMLHttp2.open("get","./chsearc.php?v="+ value + "&o="+ operation+"&cy="+city ,true);
		oXMLHttp2.onreadystatechange = function(){
			if(oXMLHttp2.readyState == 4){
				if(oXMLHttp2.status == 200){					var newdiv = document.createElement('div');
					newdiv.setAttribute('id','searchdiv');
					newdiv.innerHTML = oXMLHttp2.responseText;
					document.getElementById('detsearch').removeChild(document.getElementById('searchdiv'));
					document.getElementById('detsearch').appendChild(newdiv)
					if(document.getElementById('ch_city').value != 0){
						document.getElementById('dntitle').style.display = 'block';
						document.getElementById('ch_place').style.display = 'block';
						}
					else{
						document.getElementById('dntitle').style.display = 'none';
						document.getElementById('ch_place').style.display = 'none';
						}
				}else{
					newwindow(w,h,"Notika kluda " + oXMLHttp2.statusText);
					}
				}
			};
			oXMLHttp2.send(null);
		}
	}
function setmark(){
	var arr = getElementsByClassName('mark','');
	for(var i=0; i<arr.length; i++){
		arr[i].onmouseover = function(){
			this.style.background = "#e7e7e7";
			}
		arr[i].onmouseout= function() {
			this.style.background = "#fff";
			}
		}
	}

function sendmail(){
	var mail = document.getElementById('sendmailto').value;
	var regmail=/^[A-Z\d.~,\-_]+@{1}[A-Z\d._\-]+\.{1}[A-Z]{2,6}$/i;
	if(regmail.test(mail)){
		var c_value = [];
		var checks = getElementsByClassName('listch','');
		for (var i=0; i < checks.length; i++){
			if (checks[i].checked){
				c_value.push('list[]=' + checks[i].value);
				}
			}
		if(c_value.length >0){
			RequestPost(c_value.join('&')+'&email='+mail);
			closenewwindow();
			}
		else
			document.getElementById('mailerror').style.display = "block";
		}
	else
		 document.getElementById('sendmailto').style.backgroundColor = "#faa695";
}

function sendfriend(){
	var mail = document.getElementById('sendmailto').value;
	var mailfr = document.getElementById('sendmailfrom').value;
	var regmail=/^[A-Z\d.~,\-_]+@{1}[A-Z\d._\-]+\.{1}[A-Z]{2,6}$/i;
 	var obj = document.getElementById('friend').rel;
 	if(regmail.test(mail)){
 		if(regmail.test(mailfr)){
			RequestPost('list[]='+ obj +'&email='+mail+'&emailfr='+mailfr);
			closenewwindow();
			}
		document.getElementById('sendmailfrom').style.backgroundColor = "#faa695";
		}
	else
		 document.getElementById('sendmailto').style.backgroundColor = "#faa695";
	}
function sendagent(){
    var params = document.getElementById('mail').rel;
	params = params.split(':');
 	var mail = document.getElementById('sae_mail');
 	var name = document.getElementById('saname');
  	var message = document.getElementById('samessage');
  	var regmail=/^[A-Z\d.~,\-_]+@{1}[A-Z\d._\-]+\.{1}[A-Z]{2,6}$/i;
   	if(regmail.test(mail.value)){
   		mail.style.backgroundColor = "#fff";
   		if(message.value.length<5)
   			message.style.backgroundColor = "#faa695";
   		else{
   			message.style.backgroundColor = "#fff";
			RequestPost('obj='+params[1]+'&email='+mail.value+'&emailag='+params[0]+'&msg='+message.value+'&name='+name.value);
			closenewwindow();
			}
   		}
   	else
   		mail.style.backgroundColor = "#faa695";
	}