var lastPull=null;
setInterval("pull();", 600000);
function pull(){
    if(lastPull==null)lastPull=new Date().valueOf()-100001
    var diff=new Date().valueOf()-lastPull;
    if(diff>10000&&Remote)new Remote("Microline.Domain.Simple","Microline.Domain.Simple.DocumentRecipient","existsForLogged",taskBack).evaluate();
}
function taskBack(http,origArguments){
    var xml = selectSingleNodeIEF(http.responseXML,"/msg/value/unread");
    var mail = selectSingleNodeIEF(xml, "mail").firstChild.nodeValue;
    var task = selectSingleNodeIEF(xml, "task").firstChild.nodeValue;
	//var exists = selectSingleNodeIEF(http.responseXML.documentElement,"/msg/value").firstChild.nodeValue;
	if(document.parentWindow){
	    if (mail=="true")changeColor("red","Ostalo","Poruka");else changeColor("","Ostalo","Poruka");
	    if (task=="true")changeColor("red","Razno","Zadatak");else changeColor("","Razno","Zadatak");
	}
	lastPull=new Date().valueOf();
}
function changeColor(color,menu,item){
    var tbl=parent.document.getElementsByTagName("table")[0];
    if(tbl){
        for(var i=0;i<tbl.rows.item(0).cells.length;i++){
            var aTag=tbl.rows.item(0).cells.item(i).childNodes[0];
            if(aTag!=null&&aTag.innerHTML==menu)
                aTag.style.backgroundColor=color;
        }
        var aTags=parent.document.getElementsByTagName("a");
        for(var i=0;i<aTags.length;i++)
            if(aTags[i]!=null&&aTags[i].innerHTML==item)
                aTags[i].style.backgroundColor=color;
    }
}
function showLoginDialog(){window.open("Login.ashx","Login","width=400px, height=300px, toolbar=no, status=no, menubar=no");}
function handleError(izvor, e){
	var opis=(e.description==null?e:e.description);
	alert("Greška u "+izvor+",opis:"+opis);
}
function showLegacyPage(name,isHttps){
	document.getElementById("ifr").style.display="block"; 
	if (isHttps!=null && isHttps) name=httpsDir+name;
	if (name.match('.aspx')){
		name=name+(name.indexOf("?")>=0?'&':'?')+'cookieIdNET=' + cookieMOL;
	}
	try{
	window.frames.ifr.document.location.replace(name);
	}catch(e){}
}
function isDigit(e){if (!(e.keyCode>=48 && e.keyCode<=57)){alert('Nije znamenka');return false;}}
function isQuote(e){if (e.keyCode==34 || e.keyCode==39){alert('Navodnik nije dozvoljen.');return false;}}
function containsQuote(arg){
	if (arg.indexOf("'")>0 || arg.indexOf("\"")>0){alert('Navodnik nije dozvoljen.');return false;}
	else return true;
}
function getHelp(evt) {
    if(evt==null)evt=event;
    var s = window['ifr'].location.pathname;
    s = s.substring(1, s.lastIndexOf("."));
    window.open('Help.ashx?screen=' + s + (evt.ctrlKey ? "&edit=true" : ""), 'help', 'location=no,status=no,scrollbars=yes,menubar=no,width=500,height=900', '');
	return false;
}
