﻿
//start of drop down menu

var menuwidth='165px' //default menu width
var menubgcolor=''  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4 = document.all
var ns6 = document.getElementById && !document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

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 showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x - 1 -clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y + 0 -clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu

// end of drop down menu

//dynamic tooltip script

function ietruebody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth) {
    if (ns6 || ie) {
        if (typeof thewidth != "undefined") tipobj.style.width = thewidth + "px"
        if (typeof thecolor != "undefined" && thecolor != "") tipobj.style.backgroundColor = thecolor
        tipobj.innerHTML = thetext
        enabletip = true
        return false
    }
}

function positiontip(e) {
    if (enabletip) {
        var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
        var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
        //Find out how close the mouse is to the corner of the window
        var rightedge = ie && !window.opera ? ietruebody().clientWidth - event.clientX - offsetxpoint : window.innerWidth - e.clientX - offsetxpoint - 20
        var bottomedge = ie && !window.opera ? ietruebody().clientHeight - event.clientY - offsetypoint : window.innerHeight - e.clientY - offsetypoint - 20

        var leftedge = (offsetxpoint < 0) ? offsetxpoint * (-1) : -1000

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge < tipobj.offsetWidth)
        //move the horizontal position of the menu to the left by it's width
            tipobj.style.left = ie ? ietruebody().scrollLeft + event.clientX - tipobj.offsetWidth + "px" : window.pageXOffset + e.clientX - tipobj.offsetWidth + "px"
        else if (curX < leftedge)
            tipobj.style.left = "5px"
        else
        //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left = curX + offsetxpoint + "px"

        //same concept with the vertical position
        if (bottomedge < tipobj.offsetHeight)
            tipobj.style.top = ie ? ietruebody().scrollTop + event.clientY - tipobj.offsetHeight - offsetypoint + "px" : window.pageYOffset + e.clientY - tipobj.offsetHeight - offsetypoint + "px"
        else
            tipobj.style.top = curY + offsetypoint + "px"
        setTimeout("tipobj.style.visibility = 'visible';", 1250);

        //tipobj.style.display = "block"
    }
}

function hideddrivetip() {
    if (ns6 || ie) {
        enabletip = false
        tipobj.style.visibility = "hidden"
        tipobj.style.left = "-1000px"
        tipobj.style.backgroundColor = ''
        tipobj.style.width = ''
    }
}

//end of


// Font dynamic size

var min = 12;
var max = 18;
var def = 15;

function increaseFontSize(arg) {
    var p = document.getElementById(arg);
    var b = document.getElementById('lbl_leading_paragraph');

    if (arg == 'display_text') {

        if (def < max + 1) {
            def++;
        }

        if (p && b) {
            p.style.fontSize = def + "px"
            b.style.fontSize = def + "px"
        }
    }
    

}
function decreaseFontSize(arg) {
    var p = document.getElementById(arg);
    var b = document.getElementById('lbl_leading_paragraph');
    
    if (arg == 'display_text') {
        if (def > min - 1) {
            def--;
        }

        if (p && b) {
            p.style.fontSize = def + "px"
            b.style.fontSize = def + "px"
        }
    }

}


// START OF POLLS

function InsertVote(ID, type){
    var a = document.getElementById('poll_results');
    var vval = "0";
    var v1val = 'n', v2val = 'n', v3val = 'n', v4val = 'n', v5val = 'n', v6val = 'n', v7val = 'n', v8val = 'n', v9val = 'n', v10val = 'n';
                    
    if(type=='0'){
        var v = document.getElementById('vote_');
        if (v)
        len = document.frm_main.vote_.length

            for (i = 0; i < len; i++) {
                if (document.frm_main.vote_[i].checked) {
                    vval = document.frm_main.vote_[i].value
                }
            }

    }else{
        var v1 = document.getElementById('vote_1');
        if (v1) {
        if (v1.checked==1)
        v1val = 'y';
        }
        
        var v2 = document.getElementById('vote_2');
        if (v2) {
        if (v2.checked==1)
        v2val = 'y';
        }
        
        var v3 = document.getElementById('vote_3');
        if (v3) {
        if (v3.checked==1)
        v3val = 'y';
        }
        
        var v4 = document.getElementById('vote_4');  
        if (v4){
        if (v4.checked==1)
        v4val = 'y';
        }
        
        var v5 = document.getElementById('vote_5');
        if (v5) {
        if (v5.checked==1)
        v5val = 'y';
        }
        
        var v6 = document.getElementById('vote_6');
        if (v6){
        if (v6.checked==1)
        v6val ='y';
        }
        
        var v7 = document.getElementById('vote_7');
        if (v7) {
        if (v7.checked==1)
        v7val = 'y';
        }
        
        var v8 = document.getElementById('vote_8');  
        if (v8) {
        if (v8.checked==1)
        v8val = 'y';       
        }
        
        var v9 = document.getElementById('vote_9');
        if (v9){
        if (v9.checked==1)
        v9val = 'y';
        }
        
        var v10 = document.getElementById('vote_10');
        if (v10) {
        if (v10.checked==1)
        v10val = 'y';
        }
      }
    
    if(type=='0'){
      if(vval=="0"){
        alert("Prije glasovanja morate odabrati barem jednu od ponuđenih opcija.");
        return;
      }
    }else{
      if(v1val=="n" && v2val=="n" && v3val=="n" && v4val=="n" && v5val=="n" && v6val=="n" && v7val=="n" && v8val=="n" && v9val=="n" && v10val=="n"){
        alert("Prije glasovanja morate odabrati barem jednu od ponuđenih opcija.");
        return;
      }
    }
    
    if(a){
    PageMethods.InsertPollVotes(ID, type, vval, v1val, v2val, v3val, v4val, v5val, v6val, v7val, v8val, v9val, v10val, InsertPollVotesSuccess, GlobalAjaxError);
    }else{
    GlobalObjectError();
    }
}

function ViewPoll(arg){
    var a = document.getElementById('poll_results');    
    if(a){
    PageMethods.ViewPollOptions(arg, ReturnPollSuccess, GlobalAjaxError);
    }else{
    GlobalObjectError();
    }
}

function ViewVotes(arg){
    var a = document.getElementById('poll_results');    
    if(a){
    PageMethods.ViewPollResults(arg, ReturnPollSuccess, GlobalAjaxError);
    }else{
    GlobalObjectError();
    }
}

function ReturnPollSuccess(data){
    var a = document.getElementById('poll_results');    
    if(a){
    a.innerHTML = data;
    }else{
    GlobalObjectError();
    }
}

function InsertPollVotesSuccess(data){
    var isNumber = false;
    isNumber = isNumeric(data);
    if(isNumber){
        ViewVotes(data);
    }else{
    alert(data);
    }
}

function isNumeric(value) {
  if (value != null && !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}


// END OF POLLS

// FLIP SCREENSHOTS

function postLoad(){
    //here we run post-body-load scripts
}

//

// FLIP INDEX

// REMOVED

//

// FLIP VIDEOS

// REMOVED

//

// LOGIN


function checkLogin(){
    var u = document.getElementById("login_username");
    var p = document.getElementById("login_password");
    var c = document.getElementById("login_rememberme");
    var i = document.getElementById("login_loading");
    if (u && p && c){
        if(u.value==''){
        alert("Molimo, upišite Vaše korisničko ime.");
        u.focus();
        }else{
            
            if (!checkEntry(u.value,1)){
                   alert("Korisničko ime sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
                   u.focus();
                   return;
            }
            
            if(p.value==''){
            alert("Molimo, upišite Vašu lozinku.");
            p.focus();
            }else{
            
               if (!checkEntry(p.value,1)){
                   alert("Upisana lozinka sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
                   u.focus();
                   return;
               }
            
                if(i){ i.style.visibility = 'visible';}
                PageMethods.CheckLogin(u.value, p.value, c.checked, LoginOut, GlobalAjaxError);
            }
        }
    }else{
    alert(global_objError);
    }
}

function LoginOut(data) {
    var o = document.getElementById("login_status");
    var i = document.getElementById("login_loading");
    if(i){i.style.visibility = 'hidden';}
    
    if (o) {
    
        if(data=='OK'){
            window.location.reload();
        }else{
            o.innerHTML = data;
        }
        
    } else {
        GlobalObjectError();
    }
}

function SendAuthCode(){
    var u = document.getElementById("lostpwd_username");
    var i = document.getElementById("lostpwd_loading");
    if (u){
       if(u.value==''){
            alert("Molimo, upišite Vaše korisničko ime ili e-mail adresu s kojom ste registrirani.");
            u.focus();
        }else{
           
            if (!checkEntry(u.value,1)){
               alert("Korisničko ime sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
               u.focus();
               return;
            }
           
           if(i){i.style.visibility = 'visible';}
           PageMethods.SendAuthCode(u.value, SendAuthCodeSuccess, GlobalAjaxError);
        }
    }else{
    GlobalObjectError();
    }
}

function SendAuthCodeSuccess(data) {
    var o = document.getElementById("lostpwd_status");
    var i = document.getElementById("lostpwd_loading");
    if(i){i.style.visibility = 'hidden';}
    
    if (o) {
    
        if(data=='Pričekajte trenutak...'){
            DisplayContent('authcode','520','310','');
        }else{
            alert(data);
        }
        
    } else {
        GlobalObjectError();
    }
}

function GeneratePwd(){

    var u = document.getElementById("authcode_authcode");
    var i = document.getElementById("authcode_loading");
    if (u){
       if(u.value==''){
            alert("Molimo, upišite autorizacijsku šifru koja je poslana na Vašu e-mail adresu.");
            u.focus();
        }else{
           
            if (!checkEntry(u.value,1)){
               alert("Šifra za autorizaciju sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
               u.focus();
               return;
            }
           
           if(i){i.style.visibility = 'visible';}
           PageMethods.GeneratePwd(u.value, GeneratePwdSuccess, GlobalAjaxError);
        }
    }else{
    GlobalObjectError();
    }
    
}

function GeneratePwdSuccess(data) {
    var o = document.getElementById("authcode_status");
    var i = document.getElementById("authcode_loading");
    if(i){i.style.visibility = 'hidden';}
    
    if (o) {
    
        if(data=='Pričekajte trenutak...'){
            DisplayContent('newpasswd','520','290','');
        }else{
            alert(data);
        }
        
    } else {
        GlobalObjectError();
    }
}

function ActivateAccount(){

    var u = document.getElementById("activate_authcode");
    var i = document.getElementById("activate_loading");
    if (u){
       if(u.value==''){
            alert("Molimo, upišite šifru za aktivaciju koja je poslana na Vašu e-mail adresu.");
            u.focus();
        }else{
            if (!checkEntry(u.value,1)){
               alert("Šifra za aktivaciju sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
               u.focus();
               return;
            }
           if(i){i.style.visibility = 'visible';}
           PageMethods.ActivateAccount(u.value, ActivateAccountSuccess, GlobalAjaxError);
        }
    }else{
      GlobalObjectError();
    }
    
}

function ActivateAccountSuccess(data) {
    var o = document.getElementById("activate_status");
    var i = document.getElementById("activate_loading");
    if(i){i.style.visibility = 'hidden';}
    
    if (o) {
    
        if(data=='Pričekajte trenutak...'){
            DisplayContent('activated','520','290','');
        }else{
            alert(data);
        }
        
    } else {
       GlobalObjectError();
    }
}

function SendActivationCode(){
    var u = document.getElementById("reactivate_username");
    var i = document.getElementById("reactivate_loading");
    if (u){
       if(u.value==''){
            alert("Molimo, upišite Vaše korisničko ime ili e-mail adresu s kojom ste registrirani.");
            u.focus();
        }else{
        
            if (!checkEntry(u.value,1)){
               alert("Korisničko ime sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
               u.focus();
               return;
            }
            
           if(i){i.style.visibility = 'visible';}
           PageMethods.SendActivationCode(u.value, '1', SendActivationCodeSuccess, GlobalAjaxError);
        }
    }else{
     GlobalObjectError();
    }
}

function SendActivationCodeSuccess(data) {
    var o = document.getElementById("reactivate_status");
    var i = document.getElementById("reactivate_loading");
    if(i){i.style.visibility = 'hidden';}
    
    if (o) {
    
        if(data=='Pričekajte trenutak...'){
            DisplayContent('activate','520','310','');
        }else{
            alert(data);
        }
        
    } else {
       GlobalObjectError();
    }
}

function DoLogout(){
     PageMethods.Logout(LogoutDone, GlobalAjaxError);
}

function LogoutDone(data) {
    window.location.reload();
}

// LOGIN END

// REGISTER

function RegCheckStep(arg){
    if (arg == 1) {
        var c = document.getElementById("reg_stp1_accept");
        var i = document.getElementById("reg_stp1_loading");
            if (c){
                if(c.checked==true){
                    DisplayContent('reg_step2','520','420','')
                }else{
                    alert("Da biste nastavili proces registracije morate prihvatiti opće uvjete registracije.");
                }
            }else{
            alert(global_objError);
            }
    }

    if (arg == 2) {
        var u = document.getElementById("reg_stp2_username");
        var p = document.getElementById("reg_stp2_password");
        var p2 = document.getElementById("reg_stp2_password2");
        var e = document.getElementById("reg_stp2_email");
        var e2 = document.getElementById("reg_stp2_email2");
        var i = document.getElementById("reg_stp2_loading");
            if (u && p && p2 && e && e2){
               
               if (u.value==''){
                   alert("Molimo, upišite željeno korisničko ime.");
                   u.focus();
                   return;
               }

               if (p.value==''){
                   alert("Molimo, upišite željenu lozinku za Vaš korisnički račun.");
                   p.focus();
                   return;
               }

               if (p2.value==''){
                   alert("Molimo, još jednom upišite željenu lozinku.");
                   p2.focus();
                   return;
               }

               if (e.value==''){
                   alert("Molimo, upišite e-mail adresu koju ćete koristiti uz svoj korisnički račun.");
                   e.focus();
                   return;
               }

               if (e2.value==''){
                   alert("Molimo, još jednom upišite e-mail adresu.");
                   e2.focus();
                   return;
               }

               var tmp = u.value;
               var tmp_len = tmp.length;
               if (tmp_len < 4){
                   alert("Korisničko ime mora imati najmanje 4 znaka (karaktera).");
                   u.focus();
                   return;
               }

               if (!checkEntry(u.value,2)){
                   alert("Korisničko ime mora počinjati sa slovom (A-Z).");
                   u.focus();
                   return;
               }

               if (!checkEntry(u.value,1)){
                   alert("Korisničko ime sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
                   u.focus();
                   return;
               }

               var tmp = p.value;
               var tmp_len = tmp.length;
               if (tmp_len < 6){
                   alert("Željena lozinka mora biti duga najmanje 6 znakova (karaktera).");
                   p.focus();
                   return;
               }

               if (!checkEntry(p.value,1)){
                   alert("Željena lozinka sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
                   p.focus();
                   return;
               }

               if (p.value!=p2.value){
                   alert("Željena lozinka i željena lozinka ponovo se ne poklapaju, molimo provjerite unos.");
                   p2.focus();
                   return;
               }
               
               if (e.value!=e2.value){
                   alert("Polja e-mail adresa i e-mail adresa ponovo se ne poklapaju, molimo provjerite unos.");
                   e2.focus();
                   return;
               }

               if (!checkEntry(e.value,3)){
                   alert("E-mail adresa koju ste unijeli nije napisana u ispravnom obliku.");
                   e.focus();
                   return;
               }
               
               if(i){ i.style.visibility = 'visible';}
               PageMethods.DoRegister(u.value, p.value, e.value, DoRegisterSuccess, GlobalAjaxError);
                          
            }else{
            alert(global_objError);
            }
      }
}

function DoRegisterSuccess(data) {
    var o = document.getElementById("reg_stp2_status");
    var i = document.getElementById("reg_stp2_loading");
    if(i){i.style.visibility = 'hidden';}
    
    if (o) {
    
        if(data!='OK'){
            alert(data);
        }else{
            DisplayContent('reg_step3','520','420','');
        }
        
    } else {
       GlobalObjectError();
    }
}

//

//CTYPE

var global_width = 0;
var global_height = 0;

function DisplayContent(cType, width, height, arg) {
    var o = document.getElementById("divScreen").style;
    var p = document.getElementById("popUpContent");
    
    global_width = width;
    global_height = height;
    
    p.innerHTML = '<div style=\"padding-left:230px; width:250px; padding-top:150px; height:165px;\"><img alt=\".\" src=\"http://www.mportal.com.hr/gfx/_loading.gif\" /></div>';
    o.display = "block";
    centerPopUp(global_width, global_height, "divPopUp");
    PageMethods.GetStream(cType, arg, GetStreamSuccess, GlobalAjaxError);
}

function GetStreamSuccess(data) {
    var o = document.getElementById("popUpContent");
    if (o) {
        o.innerHTML = data;
    } else {
        alert('An error occurred!');
    }
}

function centerPopUp(Xwidth, Yheight, divid) {
    var o = document.getElementById(divid).style;

        var centerX, centerY;
        if (self.innerHeight) {
            centerX = self.innerWidth;
            centerY = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            centerX = document.documentElement.clientWidth;
            centerY = document.documentElement.clientHeight;
        } else if (document.body) {
            centerX = document.body.clientWidth;
            centerY = document.body.clientHeight;
        }

            var scrolledX, scrolledY;
            if (self.pageYOffset) {
                scrolledX = self.pageXOffset;
                scrolledY = self.pageYOffset;
            } else if (document.documentElement && document.documentElement.scrollTop) {
                scrolledX = document.documentElement.scrollLeft;
                scrolledY = document.documentElement.scrollTop;
            } else if (document.body) {
                scrolledX = document.body.scrollLeft;
                scrolledY = document.body.scrolltop;
            }

            if (!scrolledX) {
                scrolledX = 0;
            }

            if (!scrolledY) {
                scrolledY = 0;
            }
        
        o.top = scrolledY + ((centerY / 2) - (Yheight / 2)) + 'px';
        o.left = scrolledX +  ((centerX / 2) - (Xwidth / 2)) + 'px';
        o.display = "block";
}

function hidePopUp() {
    var o = document.getElementById("divPopUp").style;
    var s = document.getElementById("divScreen").style;
    o.display = "none";
    s.display = "none";
}

// CTYPE END


// SEARCH

function Check_Search(obj) {  
    var tmpobj = document.getElementById(obj);
	if (tmpobj) {
         if (tmpobj.value == ''){
		    tmpobj.value = 'upišite pojam za traženje'
         }else if (tmpobj.value == 'upišite pojam za traženje'){
            tmpobj.value = '';
         }
     }
} 

function Check_Query(obj) {  
    var tmpobj = document.getElementById(obj);

	if (tmpobj) {
     if (tmpobj.value != ''){
         if(tmpobj.value != 'upišite pojam za traženje'){
		     if(!checkEntry(tmpobj.value,4)){
		        alert("Traženi pojam sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_).");
		     }else{

		           var tmp = tmpobj.value;
                   var tmp_len = tmp.length;
                   if (tmp_len < 3){
                       alert("Traženi pojam mora imati barem 3 znaka.");
                       tmpobj.focus();
                       return;
                   }
		     
		        self.location='http://www.mportal.com.hr/Default.aspx?ref=search&q=' + tmpobj.value		 
		     }
		 }else{
		    alert("Molimo, upišite pojam za traženje.");
		    tmpobj.value='';
		    tmpobj.focus();
		 }
      }
   }
}

// FAV
function addToFavorites(title, url) {
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "")
}
// END

// MAIL TEXT

function startMailText(ID) {
var obj = document.getElementById('mailText_email');
var sender = document.getElementById('mailText_sender');
var loading = document.getElementById('mailText_loading').style;
var btnsend = document.getElementById('mailText_send');

    if (!checkEntry(obj.value,3)) {
        alert('E-mail poruka primatelja nije napisana u ispravnom obliku!');
        obj.focus();
    } else {
    
        if (sender.value=='') {
            alert('Molimo, upišite ime pošiljatelja!');
            sender.focus();
        } else {
        
            if (!checkEntry(sender.value,4)) {
                alert('Ime pošiljatelja sadržava nedozvoljene znakove (karaktere), molimo koristite samo standardne alfanumeričke znakove i underscore (_)');
                sender.focus();
                return;
            }
        
            loading.visibility = 'visible';
            btnsend.disabled = true;
            PageMethods.MailText(ID, obj.value, sender.value, MailTextSuccess, GlobalAjaxError);
        }
    }
}

function MailTextSuccess(data) {

    var loading = document.getElementById('mailText_loading').style;
    loading.visibility = 'hidden';
    var btnsend = document.getElementById('mailText_send');
    btnsend.disabled = false;
    
if(data=='SENT'){
    alert('E-mail poruka je uspješno poslana na adresu primatelja!');
    hidePopUp();
    }
if (data == 'NOTEXT') {
    alert('Greška prilikom pristupanja traženom tekstu, molimo pokušajte ponovo ili napravite refresh stranice!');
    }
if (data == 'TIME') {
    alert('Ne možete slati e-mail preporuke teksta tako često, možete poslati najviše 1 preporuku unutar 3 minute!');
}
if (data == 'JAM') {
    alert('Ne možete zaredom slati e-mail preporuke teksta istom primatelju!');
}
}

function checkEntry(arg, mode) {
    if(mode==1) var reg = /^[a-zA-Z0-9_]+$/; //allow only a-z, numbers and _
    if(mode==2) var reg = /^[a-zA-Z]{1}[a-zA-Z0-9_]+$/; //first char must be letter
    if(mode==3) var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; //email check
    if(mode==4) var reg = /^[a-zA-Z0-9_ ]+$/; //same as mode 1 but with space added
    if(mode==5) var reg = /^[a-zA-Z0-9_ čćžšđČĆŽĐŠ!?\.\,\:\(\)\-]+$/; //test for text
    var testing = arg;
    if (reg.test(testing) == false) {
        return false;
    }
    else{
        return true;
    }
}

//
// END OF PART 2


// GLOBAL AJAX ERRORS
function GlobalAjaxError(data) {
	alert("Dogodila se pogreška prilikom učitavanja podataka, molimo pokušajte još jednom ili ponovno učitajte cijelu web stranicu.");
}

function GlobalObjectError(data) {
	alert("Dogodila se pogreška prilikom učitavanja objekta, molimo pokušajte još jednom ili ponovno učitajte cijelu web stranicu.");
}
//


// CENTER POP UP
function DynamicCenterPopUp(){
    var p = document.getElementById("divPopUp");
    if(p){
        var o = document.getElementById("divPopUp").style;
        if (o.display == "block"){
        centerPopUp(global_width, global_height, "divPopUp");
        }
    }
}

window.onresize = DynamicCenterPopUp;

// END
