﻿// JavaScript Document
var _lc = null;

function goToPage(page) {
	//showLoad();
	if(! _lc) _lc = "../..";
	this.location.href = _lc + "/ser/" + page;	
}

var aj_xmlHttp;
var currPage = null;

function showLoad() {
	//document.getElementById("loader").style.visibility = "visible";
}
function showLogInData(username,root) {
	obj = (parent.frames[0].document.getElementById('log_in'));
	obj.style.display = "block";
	obj.innerHTML = "Ulogovani ste kao: " + username + " | <a href='" + root + "/ser/analize/log_out.php' target='down_frame' style='color:#FFFFFF; text-decoration:underline' >Log Out</a>";
}
function hideLogInData() {
	obj = (parent.frames[0].document.getElementById('log_in'));
	obj.style.display = "none";
}
function hideLoad() {
	//document.getElementById("loader").style.visibility = "hidden";
}
function aj_GetXmlHttpObject(handler) { 
	var objXmlHttp=null;

	// Microsoft
	if (navigator.userAgent.indexOf("MSIE")>=0) { 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP";
		} 
		try { 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler ;
			return objXmlHttp;
		} 
		catch(e) { 
			//alert("Error. Scripting for ActiveX might be disabled") ;
			return null;
		} 
	} 
	// Mozilla
	if (navigator.userAgent.indexOf("Mozilla")>=0) {
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler ;
		return objXmlHttp;
	}
} 

function aj_formRetrived() {
	if (aj_xmlHttp.readyState==4 || aj_xmlHttp.readyState=="complete") { 
		if(currPage == "home_page.php") {
			document.getElementById("home_page_img").style.display = "block";
		} else {
			document.getElementById("home_page_img").style.display = "none";
		}
		hideLoad();
		pub_currBelex = "";
		pub_currHov = "";
		pub_currB15 = "";
		pub_currBL = "";
		document.getElementById("container_body").innerHTML = (aj_xmlHttp.responseText);
		window.scroll(0,0);
	} 
}

function aj_showType() {
	aj_xmlHttp=aj_GetXmlHttpObject(aj_formRetrived);
	//document.getElementById("div_loading").innerHTML = "Loading ...";

}

/* -------------- HOME PAGE ----------------- */
var pub_currBelex = "";

function hp_showBelexDiv(div) {
	if(pub_currBelex == "") pub_currBelex = "belex15";
	if(pub_currBelex == div) return;
	pub_currBelex = div;
	hp_hideAllBelex();
	document.getElementById(div).style.display = 'block';
	var dTitle = document.getElementById('bt_' + div);
	dTitle.style.backgroundColor = "#FFFFFF";
	dTitle.style.color = "#000000";
}

function hp_hideAllBelex() {
	hp_hideBelex('belex15');
	hp_hideBelex('belexline');
	hp_hideBelex('srx');
	hp_hideBelex('obveznice');
}

function hp_hideBelex(div) {
	var dTitle = document.getElementById('bt_' + div);
	dTitle.style.backgroundColor = "#464646";
	dTitle.style.color = "#EEEEEE";
	document.getElementById(div).style.display = 'none';
}

/* ----------- HOV POJEDINACNO -------------- */
var pub_currHov = "";

function hp_showHovDiv(div) {
	if(pub_currHov == "") pub_currHov = "cena_smb";
	if(pub_currHov == div) return;
	pub_currHov = div;
	hp_hideAllHov();
	document.getElementById(div).style.display = 'block';
	var dTitle = document.getElementById('bt_' + div);
	dTitle.style.backgroundColor = "#FFFFFF";
	dTitle.style.color = "#000000";
}

function hp_hideAllHov() {
	hp_hideBelex('cena_smb');
	hp_hideBelex('obim_smb');
}
/* --------- BELEX15 POJEDINACNO ------------ */

var pub_currB15 = "";

function b15_showDiv(div) {
	if(pub_currB15 == "") pub_currB15 = "belex15_15";
	if(pub_currB15 == div) return;
	pub_currB15 = div;
	b15_hideAll();
	document.getElementById(div).style.display = 'block';
	var dTitle = document.getElementById('bt_' + div);
	dTitle.style.backgroundColor = "#FFFFFF";
	dTitle.style.color = "#000000";
}

function  b15_hideAll() {
	hp_hideBelex('belex15_15');
	hp_hideBelex('belexK_korpa');
}
/* --------- BELEXLINE POJEDINACNO ---------- */

var pub_currBL = "";

function b1l_showDiv(div) {
	if(pub_currBL == "") pub_currBL = "belexL_15";
	if(pub_currBL == div) return;
	pub_currBL = div;
	b1l_hideAll();
	document.getElementById(div).style.display = 'block';
	var dTitle = document.getElementById('bt_' + div);
	dTitle.style.backgroundColor = "#FFFFFF";
	dTitle.style.color = "#000000";
}

function  b1l_hideAll() {
	hp_hideBelex('belexL_15');
	hp_hideBelex('belexL_korpa');
	//hp_hideBelex('obveznice');
}
/* ---------------- POLL -------------------- */

	var currentID = 0;
	function glGlasaj(ID) {
		currentID = ID;
		nId = 0;
		try {
			for(i=0;i<20;i++) {
				obj = document.getElementById("rb_" + i);
				if(obj.checked == true) {
					nId = obj.value;
					break;
				}
			}
		} catch(ob) {}
		if(nId == 0) {
			alert("Obeležite jedan od ponudjenih odgovora");
			return;
		}
		sendGlasaj(currentID,nId);
	}
	function sendG(ID,odgovorID) {
		currentID = ID;
		aj_xmlHttp=aj_GetXmlHttpObject(showPollResult);
		values= "pitanjeID=" + currentID + "&glasaoID=" + odgovorID;
		if(! _lc) _lc = "../..";
		aj_xmlHttp.open("POST", _lc + "/ser/_include/polls_retrive_results.php" , false);
		aj_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		aj_xmlHttp.send(values);
	}
	
	function showPollResult() {
		if (aj_xmlHttp.readyState==4 || aj_xmlHttp.readyState=="complete") { 
			sRT = aj_xmlHttp.responseText;
			document.getElementById("div_glasanje_" + currentID).innerHTML = sRT;
		}
	}	
	
/* ---- PONUDE za preuzimanje AKCIJA -------- */

	function zavrsenePonude_callNewSearch(obj,sopstvene) {
		document.getElementById('img_indicator').style.display = 'block';
		aj_xmlHttp=aj_GetXmlHttpObject(showSearchResult);
		values= "search=" + obj.value + "&sopstvene=" + sopstvene;
		if(! _lc) _lc = "../..";
		aj_xmlHttp.open("POST", _lc + "/ser/berza/_include_ponude_zavrsene.php" , true);
		aj_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		aj_xmlHttp.send(values);
	}
/* ---------------- BERZA -------------------- */

	function berza_callNewSearch(obj) {
		document.getElementById('img_indicator').style.display = 'block';
		aj_xmlHttp=aj_GetXmlHttpObject(showSearchResult);
		values= "search=" + obj.value;
		if(! _lc) _lc = "../..";
		aj_xmlHttp.open("POST", _lc + "/ser/berza/_include_index.php" , true);
		aj_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		aj_xmlHttp.send(values);
	}
	
	function showSearchResult() {
		if (aj_xmlHttp.readyState==4 || aj_xmlHttp.readyState=="complete") { 
			document.getElementById('img_indicator').style.display = 'none';
			sRT = aj_xmlHttp.responseText;
			document.getElementById("berza_show").innerHTML = sRT;
		}
	}	
	
/* ---------- KURS ------------ */

	function datum_callNewListingKurs(file,smb) {
		var odDatuma = document.getElementById("odDatuma").value;
		var doDatuma = document.getElementById("doDatuma").value;
		aj_xmlHttp=aj_GetXmlHttpObject(showNewListingResult);
		var values = "smb=" + smb + "&odDatuma=" + odDatuma + "&doDatuma=" + doDatuma;
		showLoad();
		var where = Base64.encode("simbol='" + smb + "' AND datum>='" + odDatuma.substr(6,4) + "-" + odDatuma.substr(3,2) + "-" + odDatuma.substr(0,2) + "' AND datum <= '" + doDatuma.substr(6,4) + "-" + doDatuma.substr(3,2) + "-" + doDatuma.substr(0,2) + "'");
		var s_src = "../../webadmin/prg/class/img_chart_line.php?table=bebot_nbs_kurs&dateField=datum&field=srednji&where=" + where + "&title=Kurs "+ smb + "&limit=1000";
		document.getElementById("img_kurs_vrednosti").src = s_src;
		aj_xmlHttp.open("POST", file , true);
		aj_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		aj_xmlHttp.send(values);
	}
	
/* ---------- HOV, BELEX LISTING ------------ */

	function datum_callNewListing(file) {
		var odDatuma = document.getElementById("odDatuma").value;
		var doDatuma = document.getElementById("doDatuma").value;
		aj_xmlHttp=aj_GetXmlHttpObject(showNewListingResult);
		values = "odDatuma=" + odDatuma + "&doDatuma=" + doDatuma;
		showLoad();
		aj_xmlHttp.open("POST", file , true);
		aj_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		aj_xmlHttp.send(values);
	}
	function datum_callNewListingHov(file,smb) {
		var odDatuma = document.getElementById("odDatuma").value;
		var doDatuma = document.getElementById("doDatuma").value;
		aj_xmlHttp=aj_GetXmlHttpObject(showNewListingResult);
		values = "smb=" + smb + "&odDatuma=" + odDatuma + "&doDatuma=" + doDatuma;
		showLoad();
		var t64 = ("smb='" + smb + "' AND datum_trgovanja >='" + odDatuma.substr(6,4) + "-" + odDatuma.substr(3,2) + "-" + odDatuma.substr(0,2) + "' AND datum_trgovanja <= '" + doDatuma.substr(6,4) + "-" + doDatuma.substr(3,2) + "-" + doDatuma.substr(0,2) + "'");
		t64 =  Base64.encode(t64).replace(/\+/g,"!");
		var tS =  "../../webadmin/prg/class/img_chart_line.php?title=" + smb + " cena&where=" + t64 + "&limit=1000";
		//document.getElementById("cena_smb").innerHTML = createSwf();
		//document.getElementById("img_hov_obim").src = "../../webadmin/prg/class/img_chart_bar.php?field=obim&title=" + smb + " obim (1000)&where=" + t64 + "&limit=1000";
		aj_xmlHttp.open("POST", file , true);
		aj_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		aj_xmlHttp.send(values);
	}
	function datum_callNewListingObveznice(file,smb) {
		var odDatuma = document.getElementById("odDatuma").value;
		var doDatuma = document.getElementById("doDatuma").value;
		aj_xmlHttp=aj_GetXmlHttpObject(showNewListingResult);
		values = "smb=" + smb + "&odDatuma=" + odDatuma + "&doDatuma=" + doDatuma;
		showLoad();
		var t64 = ("smb='" + smb + "' AND datum_trgovanja >='" + odDatuma.substr(6,4) + "-" + odDatuma.substr(3,2) + "-" + odDatuma.substr(0,2) + "' AND datum_trgovanja <= '" + doDatuma.substr(6,4) + "-" + doDatuma.substr(3,2) + "-" + doDatuma.substr(0,2) + "'");
		t64 =  Base64.encode(t64).replace(/\+/g,"!");
		var tS =  "../../webadmin/prg/class/img_chart_line.php?title=" + smb + " cena&where=" + t64 + "&limit=1000";
		document.getElementById("img_hov_cena").src = tS;
		document.getElementById("img_hov_obim").src = "../../webadmin/prg/class/img_chart_bar.php?field=promet&title=" + smb + " obim (1000)&where=" + t64 + "&limit=1000";
		aj_xmlHttp.open("POST", file , true);
		aj_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		aj_xmlHttp.send(values);
	}
	function showNewListingResult() {
		if (aj_xmlHttp.readyState==4 || aj_xmlHttp.readyState=="complete") { 
			hideLoad();
			document.getElementById('show_listing').innerHTML = aj_xmlHttp.responseText;
		}
	}
/* ------------- SUGESTIJE -------------------- */

	function s_PosaljiSugestiju() {
		var dIme = document.getElementById('ime');
		var dEmail = document.getElementById('email');
		var dText = document.getElementById('sugestija');
		if(dIme.value == "" || dEmail.value == "" || dText.value =="") {
			alert("Sva polja su obavezna");
			return;
		}
		if(! this.pmw_validateControls("frm")) return;
		// creates values and sends request
		var values = this.pmw_createValuesFromForm("frm");
		this.pmw_callAjaxSave("s_PosaljiSugestijuRetrived",values,"../../webadmin/prg/_update_form.php",true);
		
	}
	function s_PosaljiSugestijuRetrived() {
		if (pubXmlHttpSave.readyState==4 || pubXmlHttpSave.readyState=="complete") { 
			var sRes = pubXmlHttpSave.responseText;	
			if(sRes.substr(0,2) == "OK") {
				goToPage('usluge/ps.php?status=primljeno');
			} else {
				alert(sRes);
			}
		}
	}
/* ------------- PRETRAGA -------------------- */

	function startSearch() {
		var sValue = document.getElementById('txtSearch').value.replace(/&/g,'[amp]').replace(/\?/g,'[qm]');
		goToPage('pretraga/index.php?search=' + sValue);
	}


/* ------------- VESTI IZ RAZNIH IZVORA: RSS -------------------- */

var pub_currRSS = "";

function hp_showRssDiv(div) {
	if(pub_currRSS == "") pub_currRSS = "belex";
	if(pub_currRSS == div) return;
	pub_currRSS = div;
	hp_hideAllRss();
	document.getElementById(div).style.display = 'block';
	var dTitle = document.getElementById('bt_' + div);
	dTitle.style.backgroundColor = "#FFFFFF";
	dTitle.style.color = "#000000";
}

function hp_hideAllRss() {
	hp_hideRss('belex');
	hp_hideRss('b92');
	/*hp_hideRss('biznovine');*/
	hp_hideRss('ekonomist');
	/*hp_hideRss('seebiz');*/
}

function hp_hideRss(div) {
	var dTitle = document.getElementById('bt_' + div);
	dTitle.style.backgroundColor = "#464646";
	dTitle.style.color = "#EEEEEE";
	document.getElementById(div).style.display = 'none';
}

/* ------------- REGISTRACIJA ZA DEMO eTRGOVANJE -------------------- */
function ProveraZaObrazac(theForm)
{

	if (theForm.puno_ime.value == "")
	{
		alert("Molim Vas unesite Vase ime i prezime.");
		theForm.puno_ime.focus();
		return (false);
	}
	if (theForm.email.value == "")
	{
		alert("Molim Vas unesite Vasu e-mail adresu.");
		theForm.email.focus();
		return (false);
	} 
	if (!ProveraEmailAdrese(theForm.email.value))
	{
		alert("Navedena e-mail adresa nije regularna.");
		theForm.email.focus();
		return (false);
	}
	if (theForm.telefon.value == "")
	{
		alert("Molim Vas unesite Vas broj telefona.");
		theForm.telefon.focus();
		return (false);
	} 	
	return (true);
}
function ProveraEmailAdrese(email)
{
	var PrviDeo,indx,DrugiDeo

	if (email == ""){
		// email adresa nije uneta
		return false
	}

	//uzima se pozicija karaktera "@"
	indx = email.indexOf("@")

	//provera da li string sadrzi karakter "@"
	if (indx == -1 ){
		return false
	}

	PrviDeo = email.substr(0,indx)
	DrugiDeo = email.substr(indx + 1) 

	//ako je prvi deo email adrese < 2 karaktera a drugi deo < 6 karaktera odbija se email adresa
	//ovaj uslov nije pravilo ali je delotvoran
	if ((PrviDeo.length < 2 ) || (DrugiDeo.length < 6))
	{ 
		return false
	}	
	
	//ako drugi deo email adrese ne sadrzi tacku odbija se email adresa
	if (DrugiDeo.indexOf(".") == -1)
	{ 
		return false
	}
	//ako se u drugom delu tacka nalazi na pocetku ili na kraju email se odbija
	if ((DrugiDeo.substring(0,1) == ".") || DrugiDeo.substring(DrugiDeo.length - 1) == ".")
	{ 
		return false
	}
	//ako email string sadrzi bcc: ili cc: ili to:
	if ((email.toLowerCase().indexOf("bcc:") != -1) || (email.toLowerCase().indexOf("bcc :") != -1) ||
	    (email.toLowerCase().indexOf("cc:") != -1) || (email.toLowerCase().indexOf("cc :") != -1) ||
		(email.toLowerCase().indexOf("to:") != -1) || (email.toLowerCase().indexOf("to :") != -1))
	{ 
		return false
	}
	
	
	return true
}








