﻿//**************************************************
function GetObject(oName){
	return document.getElementById(oName);
}

//**************************************************
// SEARCH HANDLER
//**************************************************
function StartSearch(tx, server, startnow, e){
	if(startnow){
		document.location = "/sr-" + server +"/default.aspx?searchtext=" + encodeURI(tx);
		return false;
	}
	if(!e){
		e = window.event;
	}
	if(e.keyCode==13){
		document.location = "/sr-" + server +"/default.aspx?searchtext=" + encodeURI(tx);
		return false;
	}else{
		return true;
	}
}
//**************************************************
function StartCatalogSearch(srv){
	var sURI = new Array();
	var sVAL = new Array();
	if(document.forms[0].elements["sb-one"].selectedIndex>0){
		sVAL.push(document.forms[0].elements["sb-one"].selectedIndex);
		sURI.push(7);
	}
	if(document.forms[0].elements["sb-two"].selectedIndex>0){
		sVAL.push(document.forms[0].elements["sb-two"].selectedIndex);
		sURI.push(6);
	}
	if(document.forms[0].elements["sb-three"].selectedIndex>0){
		sVAL.push(document.forms[0].elements["sb-three"].selectedIndex);
		sURI.push(4);
	}
	var catUri = (srv ==  1) ? "/Nabidka-bytu/sr-1/" : "/Apartment-offers/sr-2/";
	if(sVAL.length>0){
		document.location = catUri + "default.aspx?searchcat=1&catsrfield=" + sURI.join("|") + "&catsrtext=" + sVAL.join("|");
	}else{
		document.location = catUri + "default.aspx?searchcat=1";
	}
}

//**************************************************
// E-MAIL HANDLER
//**************************************************
function SetMailerRegistration(BtnId, e){
	if(!e){
		e = window.event;
	}
	if(e.keyCode==13){
		try{
			eval(GetObject(BtnId).getAttribute("href"));
		}catch(e){
			//unhandled
		}
		return false;
	}else{
		return true;
	}
	
}
//**************************************************
function runMailClient(mMail){
	if(!mMail) return;
	var eAdd = new String("") + mMail.replace(" zavinac ", "@");
	eAdd = eAdd.replace(/\$/igm, ".");
	document.location = "mailto:" + eAdd;
	
}

//**************************************************
// FULL SIZE IMAGE HANDLER
//**************************************************
var ArImage = null;

function ShowFullThumbNail(id_file, width, height, title){
	window.open("/ShowFullThumbNail.aspx?id_file=" + id_file + "&width=" + width + "&height=" + height + "&title=" + title,"fullImage" + id_file, "scrollbars=no,status=yes,width=" + width + ",height=" + height);
	return false;
}
//**************************************************
function ShowArticleImage(id_file, width, height, title, id_article){
	if(arguments.length==4 || !ArImage){
		return ShowFullThumbNail(id_file, width, height, title)
	}else{
		window.open("/ShowArticleImages.aspx?file=" + id_file + "&article=" + (!ArImage ? "" : ArImage), "fullImage" + id_file, "scrollbars=no,status=yes,width=800,height=600");
		return false;
	}
}

//*****************************************************************
// MENU HANDLERS
//*****************************************************************
var menuDisabler 	= null;
var activeMenu		= null;
var fixPositions	= new Array(40, 110, 172, 230, 314);

//***********************************
function HideMenuNow(){
	 if(activeMenu!=null){
	 	var oObj 	= document.getElementById("mn" + activeMenu);
		if(oObj){
			oObj.style.visibility="hidden";
		}
		activeMenu = null;
	 }
	 if(menuDisabler!=null){
	 	clearTimeout(menuDisabler);
		menuDisabler = null;
	 }
}
//***********************************
function ShowMenu(which){
	if(which!=activeMenu){
		HideMenuNow();
		var oObj 	= document.getElementById("mn" + which);
			if(oObj){
				oObj.style.left = fixPositions[which] + "px";
				oObj.style.visibility="visible";
				activeMenu = which;
		}
	}else{
		HideMenu();
	}
}
//***********************************
function HideMenu(){
	if(menuDisabler!=null){
	 	clearTimeout(menuDisabler);
		menuDisabler = null;
	}
	
	menuDisabler = setTimeout("HideMenuNow()", 1000);
}



//*****************************************************************
// ROLLOVERS
//*****************************************************************
function SetBackground(el, css){
	try{
		el.style.backgroundColor = css;
	}catch(e){
		//empty catch
	}
}
