function MM_openBrWindow(theURL,winName,features) 
{ 
  window.open(theURL,winName,features);
}
function vrsta_korisnikaF(vrsta)
{
	if(vrsta=="fizicko_lice")
	{
		document.getElementById("firma_label").style.display="none";
		document.getElementById("pib_label").style.display="none";
		document.getElementById("jmbg_label").style.display="block";
		document.getElementById("firma_hint").style.display="none";
		document.getElementById("jmbg_hint").style.block="block";
		document.getElementById("pib_hint").style.display="none";
	}
	else if(vrsta=="pravno_lice")
	{
		document.getElementById("firma_label").style.display="block";
		document.getElementById("pib_label").style.display="block";
		document.getElementById("jmbg_label").style.display="none";
		document.getElementById("firma_hint").style.display="block";
		document.getElementById("jmbg_hint").style.display="none";
		document.getElementById("pib_hint").style.display="block";
	}
}

function validate_required(field,vrednost,alerttxt)
{
	with (field)
  	{
  		if (value==null || value=="" || value==vrednost)
    	{
    		alert(alerttxt);return false;
    	}
  		else
    	{
    		return true;
    	}
  	}
}
function IsNumeric(sText,ValidChars)
{
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
   {
	   	Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
        {
        	IsNumber = false;
        }
   }
   return IsNumber;
   
}

var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}
function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox

function prijavaShow()
{
	if(document.getElementById("div_logovanja").style.display=="block")
	{
		document.getElementById("div_logovanja").style.display="none";	
	}
	else
	{
		document.getElementById("div_logovanja").style.display="block";
		document.getElementById("div_lostpass").style.display="none";
	}
}


function promenaLozShow()
{
	if(document.getElementById("div_promena").style.display=="block")
	{
		document.getElementById("div_promena").style.display="none";	
	}
	else
	{
		document.getElementById("div_promena").style.display="block";
	}
}

function templateLogo(img)
{
	document.getElementById("dhtmltooltip").innerHTML='<img src="'+img+'" />';	
}

function templateLogoHide()
{
	document.getElementById("dhtmltooltip").innerHTML='';
}

var divid = 'output';
var loadingmessage = '<img src="images/loading.gif" alt="loading..." />';

function AJAX()
{
	var xmlHttp;
	try
	{
		xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
		return xmlHttp;
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
			return xmlHttp;
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

}

function formget(div,f,url,sajt_id,tekst,domen_sajta) 
{
	//tinyMCE.execCommand('mceToggleEditor',false,tekst);
	//tinyMCE.removeMCEControl(tinyMCE.getEditorId(tekst+"_parent"));
	
	//tinyMCE.triggerSave();
	//tinyMCE.get(tekst).remove();
	tinyMCE.execCommand('mceRemoveControl', false, tekst);
	
	var poststr = $(f).serialize();//getFormValues(f);
	
	postData(div,url,poststr,sajt_id,tekst,domen_sajta);
}

function postData(div,url,parameters,sajt_id,tekst,domen_sajta)
{
	/*var xmlHttp = AJAX();
	
	xmlHttp.onreadystatechange =  function()
	{
		
		if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4)
		{
			document.getElementById(div+"_output").innerHTML=loadingmessage;
		}
		if (xmlHttp.readyState == 4) 
		{
			document.getElementById(div+"_output").innerHTML=xmlHttp.responseText;
			updateLinks(div+"_input",url,sajt_id);
			dodajEditor(domen_sajta);
			tinyMCE.execCommand('mceAddControl', true, tekst);
		}
	}
	
	//alert(params);
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Accept-Charset","UTF-8");
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);*/
	var params=parameters;
	$.ajax({
	  type: "POST",
	  url: url,
	  data: params,
	  success: function(html){
		document.getElementById(div+"_output").innerHTML=html;
		updateLinks(div+"_input",url,sajt_id);
		dodajEditor(domen_sajta);
		tinyMCE.execCommand('mceAddControl', true, tekst);
	  }

	})
}
function getFormValues(fobj)
{
	var str = "";
	var valueArr = null;
	var val = "";
	var cmd = "";

	for(var i = 0;i < fobj.elements.length;i++)
	{
		
		switch(fobj.elements[i].type)
		{
			
			case "text":

				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
				break;
			case "hidden":

				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
				break;

			case "textarea":

				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
				break;

			case "select-one":

				str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
				break;

		}
	}

	str = str.substr(0,(str.length - 1));
	return str;

}

function showPage(id,domen_sajta)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4)
	  {
	  document.getElementById("pages_output").innerHTML=xmlhttp.responseText;
	  dodajEditor(domen_sajta);
	  
	  //tinyMCE.execCommand('mceAddControl', true, 'tekst_strane');
	  }
	}
	xmlhttp.open("GET",".includes/ajax_page.php?strana_id="+id,true);
	xmlhttp.send(null);
}

function showGadget(div,id,sajt_id,domen_sajta)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4)
	  {
	  document.getElementById(div+"_output").innerHTML=xmlhttp.responseText;
	  dodajEditor(domen_sajta);
	  //tinyMCE.execCommand('mceAddControl', true, 'tekst_gadgeta');
	  }
	}
	xmlhttp.open("GET",".includes/ajax_gadget.php?gadget_id="+id+"&sajt_id="+sajt_id,true);
	xmlhttp.send(null);
}

function updateLinks(div,url,sajt_id)
{
	
	var xmlhttpL;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttpL=new XMLHttpRequest();
	  }
	else
	  {
	  // code for IE6, IE5
	  xmlhttLp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttpL.onreadystatechange=function()
	{
	if(xmlhttpL.readyState==4)
	  {
	  document.getElementById(div).innerHTML=xmlhttpL.responseText;
	  
	  }
	}
	var brokenstring=url.split("?"); 
	var ulrN=brokenstring[0];
	var javno="";
	if(div=="gadgets_input")
	{
		javno="&javno=1";	
	}
	else if(div=="owngadgets_input")
	{
		javno="&javno=0";
	}
	xmlhttpL.open("GET",ulrN+"?links="+sajt_id+javno,true);
	xmlhttpL.send(null);
}

var http_request = false;
function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
}
function alertContents() {
    if(http_request.readyState > 0 && http_request.readyState < 4)
	{
		document.getElementById("result_check").innerHTML=loadingmessage;
	}
	else if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('result_check').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

function proveraDomena() 
{
	var godTrajanja

	for (var i=0; i<document.forma_trajanja.duzinaTrajanja.length; i++)  
	{
		if (document.forma_trajanja.duzinaTrajanja[i].checked)  
		{
			godTrajanja = document.forma_trajanja.duzinaTrajanja[i].value;
		}
	} 
	
	var poststr = "tld=" + encodeURI( document.getElementById("tld").value ) + "&domain=" + encodeURI( document.getElementById("domen_sajta").value ) + "&god_trajanja=" + godTrajanja;
	
    makePOSTRequest('.includes/check_domain/check_domain.php', poststr);
}

function Reload () {
var f = document.getElementById('pregledSajta');
f.src = f.src;
}

function produziSajt(id)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4)
	  {
	  document.getElementById("results").innerHTML=xmlhttp.responseText;
	  }
	}
	var domen_username=document.getElementById('domen_username').value;
	xmlhttp.open("GET",".includes/admin_ajax.php?kupovina_id="+id+"&domen_username="+domen_username,true);
	xmlhttp.send(null);	
}
