
var isAgentIE = navigator.appName.indexOf("Microsoft");
var checkWinReload=0;
var winOpen="";
var newTimeout = false;
var WindowUrl=window.location.href;
var loginStatus=0;

function LogIn()
{
	var url="https://"+window.location.hostname+"/home/?_page=LogIn&_op=to";
	checkWinReload=1;
	loginStatus=1;
	popUpOpen(url,480,100);
}

function popUpOpen(surl,win_width,win_height)
{
	if(win_width==null||win_width=="underfined"||win_width=="") win_width=screen.availWidth-10;
	if(win_height==null||win_height=="underfined"||win_height=="") win_height=screen.availHeight-50;
	var left = (screen.width / 2) - (win_width / 2);
	var top = (screen.height / 2) - (win_height / 2);
	    winOpen = window.open(surl,'','status=no,menubar=no,scrollbars=yes,width='+win_width+',height='+win_height+',resizable=yes,left='+left+',top='+top);

		if(checkWinReload==1)checkWin();
	    winOpen.focus();
}

function checkMailForm()
{
	var telefon=document.getElementById("mailtelefon").value;
	var mail=document.getElementById("mailemail").value;
	if(telefon=="" && mail=="")
	{
		alert("E-maili aadress või telefon peab olema sisestatud!");
		return false;
	}
	return true;
}

// vajalik winOpen
function checkWin() {
	var self="";
	if (winOpen.closed) {
		self=top.location.href;
		if(self.indexOf("#")>-1 && loginStatus==0)
		    self=self.substring(0,self.length-1);
		if(self.indexOf("#")>-1 && loginStatus==1)
		{
		    self=self.substring(0,self.length-1)+"?true";
		    //self=self.substring(4,self.length);
		    //self="https"+self;
		    loginStatus=0;
		}	
		if(checkWinReload==1)top.location.href = self;
		checkWinReload=0;
		if (newTimeout) window.clearTimeout(newTimeout);
	}
	else {
		newTimeout = window.setTimeout("checkWin()",800);
	}
} 

