﻿function buildsubmenus_horizontalEx(elid){ 
	if (!document.getElementById(elid)) return;
	var ultags=document.getElementById(elid).getElementsByTagName("ul"); 
	for (var i=0; i<ultags.length; i++){ 
		ultags[i].parentNode.onmouseover=function(){ 
			var childTags = this.getElementsByTagName("ul");
			for (var j=0; j<childTags.length; j++) {
				childTags[j].style.visibility="visible";
			}
			this.className = "hover";
		}
		ultags[i].parentNode.onmouseout=function(){ 
			var childTags = this.getElementsByTagName("ul");
			for (var j=0; j<childTags.length; j++) {
				childTags[j].style.visibility="hidden";
			}
			this.className = "normal";
		}
	}
}
function buildsubmenus_horizontal1() {
	buildsubmenus_horizontalEx("dmenu");
}
function buildsubmenus_horizontal2() {
	buildsubmenus_horizontalEx("smmenu");
}

if (window.addEventListener) {
	window.addEventListener("load", buildsubmenus_horizontal1, false);
	window.addEventListener("load", buildsubmenus_horizontal2, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", buildsubmenus_horizontal1);
	window.attachEvent("onload", buildsubmenus_horizontal2);
}

function __getEl(id)
{
  return document.getElementById(id);
}
var searchFieldHasFocus = false;
function Search(){
	var input = __getEl(searchfieldId);
	if (input.value.toLowerCase() == "pretraži oglase" || input.value == ""){
		alert("Unesite pojam za pretraživanje.");
		input.focus();
		return false;
	}
	
	if (input.value.length < 2) {
		alert("Pojam za pretraživanje ne može biti kraći od 2 znaka.");
		input.focus();
		return false;
	}
	
	var cat = __getEl("catid");
	var catId = (cat) ? cat.value : "0";
	var t = __getEl("stype");
	var type = (t) ? t.value : "0";
	
	if (searchadv){
		var selRubrika = __getEl(selRubrikaId);
		if (selRubrika)
		{
			catId = selRubrika.value;
		}
		var chkType1 = __getEl(chkType1Id);
		var chkType2 = __getEl(chkType2Id);
		//var chkType3 = __getEl(chkType3Id);
		//type = (chkType1.checked) ? "1" : (chkType2.checked) ? "2" : (chkType3.checked) ? "3" : "0";
		type = (chkType1.checked) ? "1" : (chkType2.checked) ? "2" : "0";

	}
	else{
		var chkCurrent = __getEl(chkCurrentId);
		if (chkCurrent && !chkCurrent.checked)	{
			catId = "";
		}
	}
	var search = "/search.aspx?q=" + encodeURI(input.value.replace(/<|>|\r|\n|\r\n|\t|\b|\f|\s{2,}/gim, '').replace(/\s{1}/gi, '\+'));
	if (catId != "" && catId != "0"){
		search += "&cat=" + catId;
	}
	if (type != "" && type != "0"){
		search += "&type=" + type;
	}
	top.location.href = search;
	
	return false;
}

function SetPCVisible(value) {
	var popupControl = GetPopupControl();
	if (popupControl) {
		if(value) {
			 
			popupControl.Show();
		}
	}
    else {
        popupControl.Hide();
       
	}
}
function GetPopupControl() {
    return ASPxClientControl.GetControlCollection().Get(popupControlID);
}