﻿// JScript File

//-------------------------------------------------
// save a reference to the original __doPostBack
//var __oldDoPostBack = __doPostBack;

// replace __doPostBack with another function
//__doPostBack = AlwaysFireBeforeFormSubmit;

function AlwaysFireBeforeFormSubmit (eventTarget, eventArgument) {
    // do whatever pre-form submission
    // chores you need here
    // finally, let the original __doPostBack do its work
    alert(eventTarget+""+eventArgument);
    return __oldDoPostBack (eventTarget, eventArgument);
}

//-------------------------------------------------
slika= Array();

function promeni_sliku(){ 
    var obj=MM_findObj('ctl00_main_content_firma_slike_img');//ctl00_main_content_firma_slike_img 
    //var obj_src=obj.src; 
    //var broj= obj_src.substr(obj_src.lastIndexOf('.jpg')-1, 1); 
    //alert(broj);
    if(broj<max_broj)
    { 
        broj++; 
        obj.src= slika[broj];
    } 
    else{ 
        broj=1; 
        obj.src= slika[broj]; 
    } 
}
//-------------------------------------------------
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nt=val.title; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nt+' mora biti e-mail adresa.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nt+' mora biti broj.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nt+' mora biti broj između '+min+' i '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nt+' je zahtevano polje.\n'; }
  } if (errors) alert('Postoje sledeće greške:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-------------------------------------------------
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//-------------------------------------------------
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

//-----------------AJAX POZIVI - prozor za unos sa zatamnjivanje----------------
function showInputForm(akcija, element, language){
	//akcija:
	//	email, posao (aplikacija), prijavi (los sadrzaj), prijavljivanje (kategorije posla),...
	//element:
	//	objekat (ID objekta) u kom treba prikazati sadrzaj
	//language:
	//	jezik na kom nam treba sadrzaj. ako je prazno podrazumeva se srpski
	var jezik="";
	if(language!="en" && language!="sr") jezik = "l=sr";
	else jezik = "l="+language;
	
	link= new Array();
	link['email']="contact.aspx";

	if(element == "" || element==null) element= "pop_content";
	if(link[akcija]=="" || link[akcija]==null) link[akcija]="email";
	
	var str_link= new String(link[akcija]);
	if( str_link.indexOf("?",str_link)<0) link[akcija]= str_link+"?"+jezik;
	else link[akcija]= str_link+"&"+jezik;
	
	//alert(element+" : "+link[akcija] );
	
	if(element=="pop_content"){
		var ww = getWindow('width');
		var wh = getWindow('height');
		var fw = 640;
		var fh = 480;
		
		//offset SCROLL
		if (self.pageYOffset) // all except Explorer
		{
			scroll_x = self.pageXOffset;
			scroll_y = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
		{
			
			scroll_x = document.documentElement.scrollLeft;
			scroll_y = document.documentElement.scrollTop;
			//alert("upada 1 "+scroll_y);
		}
		else if (document.body) // all other Explorers
		{
	
			scroll_x = document.body.scrollLeft;
			scroll_y = document.body.scrollTop;
			//alert("upada 2"+scroll_y);
		}
		
		//scroll_x=0; scroll_y=0;
		win_width=self.screen.availWidth;
		//win_height=self.screen.availHeight;
		//win_height= document.offsetHeight;
		if (window.innerWidth)
		{
			win_width = window.innerWidth;
			win_height=window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientWidth)
		{
			win_width = document.documentElement.clientWidth;
			win_height=document.documentElement.clientHeight;
		}
		else if (document.body)
		{
			win_width = document.body.clientHeight;
			win_height=document.body.clientHeight;
		}
		
		var darkDiv = document.createElement("div");
		darkDiv.style.width = ww+"px";//+scroll_x
		darkDiv.style.height = 2*win_height+2*wh+scroll_y+"px";
	//	darkDiv.style.width = win_width+"px";
	//	darkDiv.style.height = win_height+"px";
		darkDiv.id = "pop_darkDiv";
		
		
	
		var formDiv = document.createElement("div");
		formDiv.id = "pop_formDiv";
		formDiv.style.width = fw+"px";
		formDiv.style.height = fh+"px";
		
		if(fw < ww){
			formDiv.style.left = Math.round((ww+scroll_x-fw)/2)+"px";
		}else{
			formDiv.style.left = "0px";
		}
		
		if(fh < wh){
			if(document.all)
				formDiv.style.top = Math.round((wh-fh)/2)+scroll_y+"px";
			else 
				formDiv.style.top = Math.round((wh-fh)/2)+scroll_y+"px";
		}
		else{
			formDiv.style.top = scroll_y+"px";
			//formDiv.style.height = "70%";
			
		}
		
		var html = '<div id="pop_header">';
		html += '<div id="pop_header_title"></div>';
		html += '<div id="pop_header_right"><a href="javascript:void(0);" onclick="hideInputForm()">zatvori <img src="icon_close_hover.gif" width="10" height="10" /></a></div>';
		//html += '<a id="pop_close" href="javascript:void(0);" onclick="hideInputForm()">zatvori</a>';
		html += '</div><br clear="all" />';
		html += '<div id="pop_content"></div>';
		html += '<div id="pop_footer"><div id="pop_footer_center"></div><div id="pop_footer_right"></div></div>';
		
		formDiv.innerHTML = html;
		//'<a id="pop_close" href="javascript:void(0);" onclick="hideInputForm()">zatvori</a><br clear="all" /><div id="pop_content"></div>';
		
		//if(navigator.appName.indexOf("Opera") < 0)
		document.body.appendChild(darkDiv);
		document.body.appendChild(formDiv);
		
		/*window.scrollbars.visible="false";
		
		if(document.body.style.overflow!="hidden"){
			document.body.style.overflow="hidden";
		}
		else{
			document.body.style.overflow="auto";
		}
		*/
	}
	
	//if(link[akcija]){
	loadRSDoc(link[akcija],element);
	//}
}
//-------------------------------------------------
function hideInputForm(){
	
	document.body.removeChild(document.getElementById("pop_formDiv"));
	//if(navigator.appName.indexOf("Opera") < 0)
	document.body.removeChild(document.getElementById("pop_darkDiv"));
}
//-------------------------------------------------
function getWindow(what){
	var ret;
	
	//----------------------
	if (self.innerHeight) // all except Explorer
	{
		switch(what){
			case 'width':	
							ret = self.innerWidth;
							//ret = self.screen.availWidth;
							break;
			case 'height':	
							ret = self.innerHeight;
							//ret = self.screen.availHeight;
							break;
		}
							
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		switch(what){
			case 'width':	
							ret = document.documentElement.clientWidth;
							break;
			case 'height':	
							ret = document.documentElement.clientHeight;
							break;
		}
	}
	else if (document.body) // other Explorers
	{
		switch(what){
			case 'width':	
							ret = document.body.clientWidth;
							break;
			case 'height':	
							ret = document.body.clientHeight;
							break;
		}
	}
	return ret;
}
//-------------------------------------------------
function loadRSDoc(url,id){
	if(navigator.appName.indexOf("Microsoft") >= 0){
		var req = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		var req = new XMLHttpRequest();
	}
	
	if(req){
		req.onreadystatechange = parseRequest;
		req.open("POST",url);
		req.send("");
	}
	function parseRequest(){
		var obj = document.getElementById(id);
		switch(req.readyState){
			case 0://uninitialized(initializing)
				if(obj)
				obj.innerHTML = "inicijalizacija...";
				break;
			case 1://loading
				if(obj)
				obj.innerHTML = "učitavanje...";
				break;
			case 2://loaded
				if(obj)
				obj.innerHTML = "učitano...";
				break;
			case 3://interactive
				if(obj)
				obj.innerHTML = "molimo sačekajte...";
				break;
			case 4://complete
				if(req.status == 200){
					var out = req.responseText;
					//reg = /\n/g;
					//out = out.replace(reg,"<br />");
					document.getElementById(id).innerHTML = out;
				}else{
					document.getElementById(id).innerHTML = "Postoje greške! "+req.status;
				}
				break;
		}
	}
}

//----------------------------------------
function moveHelpTip(){
	//if(event.x != "undefined")  event = window.event;
	//if(!e)
	var e = window.event;
	
	//alert(e.type);
	
	var xpos=0;
	var ypos=0;
	//--------
	if (e.pageX || e.pageY) 	{
			xpos = e.pageX;
			ypos = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			xpos = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			ypos = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
	//--------
	
	
	
	//xpos=event.clientX;
	//ypos=event.clientX;
	
	
	obj_owner= MM_findObj('pop_help');
	
	//alert("obj position:"+xpos+" x "+ypos+"\n windows:"+document.body.clientWidth+" x "+document.body.clientHeight);
	
	if((xpos+200) >= document.body.clientWidth) 
		xpos= xpos-200-1;
	if((ypos+200) >= document.body.clientHeight) 
		ypos= ypos-200-1;
	
	obj_owner.style.top = ypos+"px";
	obj_owner.style.left = xpos+"px";
	//alert("X: "+xpos+" Y:"+ypos); 
	

}
//----------------------------------------
function showHelpTip(indikator, kategorija, language, e){
	if(!e)
		e = window.event;
	
	if (typeof e == "undefined")
 	{
   		e = window.event;
 	}
	
	if(language=="" || language==null) jezik="sr";
	else jezik=language;
	
	obj_owner= MM_findObj('pop_help');
	
	obj_content=MM_findObj('pop_help_content');
	
	if(indikator==1)
		{
			obj_owner.style.display="block";
			element='pop_help_content';
			
			showInputForm(kategorija, element, jezik);
			
			var xpos=0;
			var ypos=0;
			//--------
			if (e.pageX || e.pageY) 	{
					xpos = e.pageX;
					ypos = e.pageY;
				}
			else if (e.clientX || e.clientX) 	{
					xpos = e.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft;
					ypos = e.clientY + document.body.scrollTop+ document.documentElement.scrollTop;
				}
			//--------
			if((xpos+200) >= document.body.clientWidth) 
			xpos= xpos-200-1;
			if((ypos+400) >= document.body.clientHeight) 
				ypos= ypos-400-1;
			
			obj_owner.style.top = ypos+"px";
			obj_owner.style.left = xpos+"px";
	
			//moveHelpTip(e);
			//var pin = document.createElement("img");
			//alert("done");
			//pin.src = "http://cvet.yellow/yp/yp1/images/paper_pin2.gif";
			//pin.style.position = "absolute";
			//pin.style.padding="5px";
			//pin.style.background = "#000";
			//pin.style.zIndex = 1001;
			//pin.style.left = "-12px";
			//pin.style.top = "-12px";
			//document.body.appendChild(pin);
		}
	else
		{
			obj_owner.style.display="none";
		}

	//obj_content.innerHTML = html;

}
//--------------------------------------
//document.CSSStyleDeclaration="";
	vrste_pretrage= new Array();
	vrste_pretrage[0]="osnovna";
	vrste_pretrage[1]="telefon";
	vrste_pretrage[2]="adresa";
	
	function showHidePretraga(element){
		for(i=0; i<3; i++){
		
			obj=MM_findObj("pretraga_"+element+"_box");
			obj_bottom=MM_findObj("pretraga_"+element+"_box_bottom");

			if(vrste_pretrage[i]==element){
				//alert(element+" izabrana");
				obj.style.display="block";
				obj_bottom.style.display="block";
			}
			else{
				obj=MM_findObj("pretraga_"+vrste_pretrage[i]+"_box");
				obj_bottom=MM_findObj("pretraga_"+vrste_pretrage[i]+"_box_bottom");
				//alert(vrste_pretrage[i]+" NIJE izabrana");
				obj.style.display="none";
				obj_bottom.style.display="none";
			}
		}	
	}
//----------------------------------------

// JavaScript Document
function xpopup(url){
	var popupWidth  = 640;
	var popupHeight = 480;
	
	var w,h;
	w = document.body.clientWidth+10;
	h = document.body.clientHeight+10;
	
	var darker = document.createElement("div");
	darker.id = "darker";
	darker.style.width  = w+"px";
	darker.style.height = h+"px";
	
	var main = document.createElement("div");
	main.id = "xpopup";
	main.style.width = popupWidth+"px";
	main.style.height = popupHeight+"px";
	// IE
	if(document.all){
		main.style.left = Math.round((w-popupWidth)/2)+"px";
		main.style.top = Math.round((h-popupHeight)/2)+"px";
	// rest
	}else{
		main.style.left = Math.round((window.innerWidth-popupWidth)/2)+"px";
		main.style.top = Math.round((window.innerHeight-popupHeight)/2)+"px";
	}
	
	var btnClose = document.createElement("input");
	btnClose.type = "button";
	btnClose.className = "btnClose";
	btnClose.title = "Close";
	btnClose.onclick = function(){
		var dark = document.getElementById("darker");
		var main = document.getElementById("xpopup");
		document.body.removeChild(dark);
		document.body.removeChild(main);
	}
	
	var mainContent = document.createElement("div");
	mainContent.style.height = popupHeight+"px";
	mainContent.id = "xpopupContent";
	
	main.appendChild(btnClose);
	main.appendChild(mainContent);
	document.body.appendChild(darker);
	document.body.appendChild(main);
	
	LoadRequest(url,"xpopupContent");
}

function LoadRequest(url,id){
	var browser = navigator.appName;
	if(browser.indexOf("Microsoft")>=0){
		var req = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		var req = new XMLHttpRequest();
	}

	if(req){
		req.onreadystatechange = processReqStateChange;
		req.open("POST",url,true);
		req.send("");
	}
	function processReqStateChange(){
		var obj = document.getElementById(id);
		switch (req.readyState){
			case 0:
			case 1:
			case 2:
			case 3:
				obj.innerHTML = "Molim sačekajte...";
				break;
			case 4: //finished
				if(req.status == 200){
					var vrati = req.responseText;
					obj.innerHTML = vrati;
				}else{
					obj.innerHTML = "Error #"+req.status+"<br />"+req.statusText;
				}
				break;
		}
	}
}
//----------------------------
function sendmail(){
    var param="";
    
    obj_to= MM_findObj('TextBoxTo');
    param="to="+obj_to.value;
    
    obj_body= MM_findObj('TextBoxBody');
    param+="body="+obj_body.value;
        
    obj_subject= MM_findObj('TextBoxSubject');
    param+="subject="+obj_subject.value;
    
    LoadRequest('kontakt.aspx?'+param, "xpopupContent");
}
//------------------------------
function search_site(obj){
    var parent= obj.parentNode;
    //alert(obj+" "+ parent);
    var inputs= parent.getElementsByTagName('input');
    //alert(inputs);
    var keyword= inputs[0];
    //alert(keyword);
    var param="pretraga.aspx?k="+keyword.value;
    window.open(param);
    //LoadRequest('pretraga.aspx?'+param);
    
}