﻿
var udxtimer = null;
var udtimer = 30*1000;
var _overcolor = "#00CCFF";
var _defcolor = "#E9E9E9";
var _fonts = "Lucida Grande,Trebuchet Ms,Tahoma";
var _fontsize = "10px";
var _gtop = 0;
var _menu = document.createElement("div");
_menu.style.position = "absolute";
_menu.style.top =  _gtop;
_menu.style.color = "white";
_menu.style.width = document.body.clientWidth;
_menu.style.height = 40;
_menu.align = "center";
_menu.style.backgroundImage = "url('http://imgs.heeloo.net/gadgets/login/menubg50.png')";
_menu.style.backgroundRepeat = "repeat-x";
_menu.style.backgroundPosition = "left bottom";
_menu.style.backgroundColor="black";
_menu.style.left = parseInt(document.body.clientWidth)/2-parseInt(_menu.style.width)/2;
_menu.style.zIndex = 3000;
var _width = 900;
var blogid = "";
var blogCommand ="";
var _username = "unknown";
var _userid = "n/a";
var _email = "";
var _userserver = "www.";
var _userlang = "";
_menu.innerHTML = "Login";
try{
	var _txthnid = document.getElementById("txt_heeloo_userid");
	_txthnid.value = _userid;
}catch(E){
}
try{
	var _txthn = document.getElementById("txt_heeloo_name");
	_txthn.value = _username;
	var _txthe = document.getElementById("txt_heeloo_email");
	_txthe.value = _email;
}catch(E){
}

document.body.appendChild(_menu);
var _lform = null;
var newMails = 0;

if (blogid!=""){blogCommand += "<a href='http://"+_userserver+"/apps#blog' target='_top' style='text-decoration:none;color:"+_defcolor+";font-family:"+_fonts+";font-size:"+_fontsize+"' onmouseover='this.style.color=&quot;"+_overcolor+"&quot;' onmouseout='this.style.color=&quot;"+_defcolor+"&quot;'><img id='m_em_img_blog' src='http://imgs.heeloo.net/gadgets/login/blog.png' border='0'onmouseover='_m_mouseover(this)' onmouseout = '_m_mouseout(this)'/></a>";
		}else { blogCommand= "";}

if (_username != "unknown"){
var commands = "<table border='0' cellspacing='0' cellspacing='0' style='position:relative;top:3px;'>";
commands +="<tr>";
	commands +="<td width='50' height='32' align='center' valign='top'>";
	commands +="<a href='http://"+_userserver+"/apps/#Mail' target='_top' style='color:"+_defcolor+";font-family:"+_fonts+";font-size:"+_fontsize+"' onmouseover='this.style.color=&quot;"+_overcolor+"&quot;' onmouseout='this.style.color=&quot;"+_defcolor+"&quot;'><img id='m_em_img_mail' src='http://imgs.heeloo.net/gadgets/login/mail.png' border='0'";
	commands +=" onmouseover='_m_mouseover(this)' onmouseout='_m_mouseout(this)'/></a>";
	commands+="</td>";
	commands +="<td width='50' height='32' align='center' valign='top'>";
//	commands +="<a href='javascript:_composeMail()' target='_top' style='color:"+_defcolor+";font-family:"+_fonts+";font-size:"+_fontsize+"' onmouseover='this.style.color=&quot;"+_overcolor+"&quot;' onmouseout='this.style.color=&quot;"+_defcolor+"&quot;'><img id='m_em_img_wmail' src='http://imgs.heeloo.net/gadgets/login/write.png' border='0'";
//	commands +=" onmouseover='_m_mouseover(this)' onmouseout='_m_mouseout(this)'/></a>";
	commands +="</td>";
	commands+="<td width='50'height='32' align='center' valign='top'> ";
	commands+=blogCommand;
	commands +="</td>";
commands +="</tr>";
commands +="</table>";
commands +="<img id='m_em_img_mail_tooltip' src='http://imgs.heeloo.net/icons/mail_tooltip.png' border='0' style='position:absolute;visibility:hidden'/>";
commands +="<div id='m_em_img_new' style='width:19px;height:18px;background-image:url(http://imgs.heeloo.net/gadgets/login/mail_new.png);background-repeat:no-repeat;position:absolute;visibility:hidden;font-family:tahoma,verdana,helvetica;font-size:9px;padding-top:3px;text-align:center;color:white'></div>";
commands +="<img id='m_em_img_wmail_tooltip' src='http://imgs.heeloo.net/icons/write_mail.png' border='0' style='position:absolute;visibility:hidden'/>";
commands +="<img id='m_em_img_blog_tooltip' src='http://imgs.heeloo.net/icons/blog_tooltip.png' border='0' style='position:absolute;visibility:hidden'/>";
commands +="<div id='m_em_img_nmail' style='color:black;visibility:hidden;position:absolute;left:20px;top:5px;width:155px;height:37px;background-image:url(http://imgs.heeloo.net/gadgets/login/new_mail.png);background-repeat:no-repeat;padding-top:13px;padding-left:1px;text-align:center;padding-right:6px;'>"
			+"</div>";

var _loc = "n/a";
try{
_loc = window.location.href;
}catch(e){

}

var _html = "<table id='users_table' border='0' cellspacing='2' cellpadding='2' width='"+_width+"' height='100%'>";
_html +="<tr>";
_html+="<td width='1%' valign='middle'><div style='width:200px;font-family:Lucida Grande,Trebuchet Ms,Tahoma;font-size:12px;color:white'><b>no resource found for [login.dock.hi,] !</b></div>";
_html+="</td>";
_html+="<td width='49%'><span style='font-family:Lucida Grande,Trebuchet Ms,Tahoma;font-size:12px;color:white'>"+commands+"</span></td>";
_html+="<td width='50%' align='left' valign='top'>";
_html+="<div style='margin-top:7px;float:left;color:"+_defcolor+";font-size:"+_fontsize+";'>Online in Heeloo &gt; <span id='dock_online_section' style='font-weight:bolder;margin-right:20px;'>129428</span><a href='http://"+_userserver+"' style='text-decoration:none;color:"+_defcolor+";font-family:"+_fonts+";font-size:"+_fontsize+"' onmouseover='this.style.color=&quot;"+_overcolor+"&quot;' onmouseout='this.style.color=&quot;"+_defcolor+"&quot;' target='_top'>Heeloo</a>&nbsp;&bull;&nbsp;";
_html +=" <a href='http://"+_userserver+"/apps#settings' style='text-decoration:none;color:"+_defcolor+";font-family:"+_fonts+";font-size:"+_fontsize+"' onmouseover='this.style.color=&quot;"+_overcolor+"&quot;' onmouseout='this.style.color=&quot;"+_defcolor+"&quot;' target='_top'>no resource found for [login.dock.settings,]</a>&nbsp;&bull;&nbsp;";
_html +="<a href='https://heeloo.net/login/singoutuser/' target='_top' style='text-decoration:none;color:"+_defcolor+";font-family:"+_fonts+";font-size:"+_fontsize+"' onmouseover='this.style.color=&quot;"+_overcolor+"&quot;' onmouseout='this.style.color=&quot;"+_defcolor+"&quot;'>no resource found for [login.dock.logout,]</a></div>";
_html+="</span></td>";
_html+="</tr></table>";
_html+="<iframe id='_frm_check' src='about:blank' width='1' height='1' style='visibility:hidden'></iframe>";

_menu.innerHTML = _html;
var foto = "http://"+_userserver+"/ui/n/a";

	var _fotoC = document.createElement("DIV");
	_fotoC.style.position = "absolute"; 
	_fotoC.style.top = _gtop+5; 
	_fotoC.style.zIndex = 3001;
	_fotoC.style.left = document.body.clientWidth/2 - _width/2-60;
	
	_fotoC.style.border = "solid orange 3px";
	_fotoC.style.backgroundColor = "white";
	
	
	_fotoC.innerHTML = "<img src='"+foto+"' width='50' border='0'/>";
	document.body.appendChild(_fotoC);
	
}else{
var _html = "<table id='users_table' border='0' cellspacing='2' cellpadding='2' width='"+_width+"' height='30'>";
_html +="<tr>";
_html +="<td align='left' valign='top'>";
_html+="<div style='color:#AAAAAA;width:100%;height:25px;'>&nbsp;</div>";
_html+="</td>";
_html+="<td align='right' valign='middle'>";	 
	_html+="<span style='color:"+_defcolor+";font-family:Lucida Grande,Tahoma;font-size:10px;'>Online in Heeloo &gt;<span id='dock_online_section' style='font-weight:bolder'>129428</span></span>&nbsp;|&nbsp;"
			+"<b><a href='javascript:_createUser()' target='_top' style='text-decoration:none;color:"+_defcolor+";font-family:"+
			_fonts+";font-size:"+_fontsize+"' onmouseover='this.style.color=&quot;"+_overcolor+"&quot;' onmouseout='this.style.color=&quot;"+_defcolor+"&quot;'>"+
			"no resource found for [login.dock.createuser,en]</a></b>";
_html+="</td>";
_html+="<td>&nbsp;</td>";
_html +="<td align='right' valign='middle' width='1%'>";
	_html +=" <div style='width:100px;'><a href='javascript:_startShowLogin()' class='blue_button' onclick='this.blur()'><span>no resource found for [login.dock.login,en]</span></a></div>";
_html+="</td>";
_html+="</tr></table>";
 _menu.innerHTML = _html;
}


function _createUser(){
	var wl = window.location.toString();
	wl = replaceStr(wl,"/#/","/!hash!/");
	wl = replaceStr(wl,"#","!hash!");
	window.open("https://heeloo.net/login/intl/register/?.done="+wl+"&token=55579FDBAAC35225D5E8CA9B7F45F682.heeloo","_self");
}

function _startShowLogin(){
	var wl = window.location.toString();
	wl = replaceStr(wl,"/#/","/!hash!/");
	wl = replaceStr(wl,"#","!hash!");
	
	window.open("https://heeloo.net/login/intl/?.done="+wl+"&token=55579FDBAAC35225D5E8CA9B7F45F682.heeloo","_self");
}

function _m_mouseover(obj){
	var id = obj.id;
	var tt = document.getElementById(id+"_tooltip");
	
	if (newMails > 0){
		if (id == "m_em_img_mail"){
			var newmm = document.getElementById("m_em_img_nmail");
			newmm.style.visibility = "visible";
			return;
		}
	}
	var newmm = document.getElementById("m_em_img_nmail");
	newmm.style.visibility = "hidden";
	tt.style.visibility = "visible";
	tt.style.left = xgd_getLeft(obj)-10;
	tt.style.top = xgd_getTop(obj)+30;
}

function _m_mouseout(obj){
	var id = obj.id;
	var tt = document.getElementById(id+"_tooltip");
	tt.style.visibility = "hidden";
	var newmm = document.getElementById("m_em_img_nmail");
	newmm.style.visibility = "hidden";
}

function _composeMail(){
		var x = 20;
		var y = -20;
		var height = 570;

		if (document.body.clientHeight < 600){
			height = 570;
			y = -80;
		}
		xg.window.showInner("lala","http://"+_userserver+"/mail/compose/?external=yes",680,600,x,y);
}



function _updateEmail(mn,nmt){
	var newm = document.getElementById("m_em_img_new");
	var newmm = document.getElementById("m_em_img_nmail");
	var emailc = document.getElementById("m_em_img_mail");
	newm.style.left = xgd_getLeft(emailc)+20;
	newm.style.top = xgd_getTop(emailc)+5;
	newmm.style.left = xgd_getLeft(emailc)-10;
	newmm.style.top = xgd_getTop(emailc)+24;
	
	if (mn != 0){
		newm.style.visibility = "visible";
		newm.innerHTML = mn;
		
		if (newMails != mn){
			newmm.style.visibility = "visible";
			if (nmt == 1){
				newmm.innerHTML = "Ai "+nmt + " un mail nou";
			}else{
				newmm.innerHTML = "Ai "+nmt+" mail-uri necitite";
			}
		}else{
			if (nmt == 1){
				newmm.innerHTML = "Ai "+nmt + " un mail nou";
			}else{
				newmm.innerHTML = "Ai "+nmt+" mail-uri necitite";
				if (nmt > 100){
					newm.style.backgroundImage = "url('http://imgs.heeloo.net/gadgets/login/mail_new_big.png')";
					newm.style.width = 30;
					newm.style.left = xgd_getLeft(emailc)+10;
					newm.style.top = xgd_getTop(emailc)+10;
				}
				
			}
		
		}
		newMails = mn;

	}else{
		newm.style.visibility = "hidden";
		newmm.style.visibility = "hidden";
	}
}



udxtimer = window.setTimeout("_startCheckTimer()",udtimer);

function _startCheckTimer(){
	UD_loadXMLDoc(myServer+"/check/");
	
}

UD_onload();

window.onload = function(){
	if ("unknown" != "unknown"){
		_startCheckTimer();
	}
			try{
			_window_onload();
		}catch(E){
		}
}
window.onresize = function(){
	UD_resize();
}

function UD_onload(){
try{
		var allowed_mod = true;
		var ua = "CCBot/1.0 (+http://www.commoncrawl.org/bot.html)";
		ua = ua.toLowerCase();

		if (ua.indexOf("ipad")>-1 || ua.indexOf("iphone")>-1){
			document.body.style.overflow = "auto";
			allowed_mod = false;
		}

		if (allowed_mod){
			var _db = document.getElementById("doc_background");
			_db.style.position = "absolute";
			_db.style.top = parseInt(_menu.style.height);
			_db.style.width = document.body.clientWidth;
			_db.style.height = document.body.clientHeight-parseInt(_db.style.top);
			}

		}catch(e){
			//window.status = e;
		}
}

function UD_resize(){

	_menu.style.width = document.body.clientWidth;
		_menu.style.left = parseInt(document.body.clientWidth)/2-parseInt(_menu.style.width)/2;
		try{
			_fotoC.style.left = document.body.clientWidth/2 - _width/2-60;
		}catch(e){}
		try{
			var allowed_mod = true;
			var ua = "CCBot/1.0 (+http://www.commoncrawl.org/bot.html)";
			ua = ua.toLowerCase();

			if (ua.indexOf("ipad")>-1 || ua.indexOf("iphone") > -1){
				document.body.style.overflow = "auto";
				allowed_mod = false;
			}
			if (allowed_mod){
				var _db = document.getElementById("doc_background");
				_db.style.position = "absolute";			
				_db.style.top = parseInt(_menu.style.height);
				_db.style.width = document.body.clientWidth;
				_db.style.height = document.body.clientHeight-parseInt(_db.style.top);
			}
		}catch(e){
			//window.status = e;
		}
		try{
			_window_onresize();
		}catch(E){
		}
}

var UD_req ;

function UD_loadXMLDoc(url) {
	UD_req = false;

    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			UD_req = new XMLHttpRequest();
        } catch(e) {
			UD_req = false;
        }
    } else if(window.ActiveXObject) {
       	try {
        	UD_req = new ActiveXObject("Microsoft.XMLHTTP");
      	} catch(e) {
        	try {
          		UD_req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		UD_req = false;
        	}
		}
    }
	if(UD_req) {
		UD_req.onreadystatechange = UD_processReqChange;
		/*if (url.indexOf("?")>-1){
			url = url+"&token="+xgd_GenerateID();
		}else{
			url = url+"?token="+xgd_GenerateID();
		}*/
		try{
			UD_req.open("POST", url, true);
			UD_req.send("");
		}catch(e){
		}
	}
}

function UD_processReqChange(){
	if (UD_req.readyState == 4) {
        if (UD_req.status == 200) {
			var xmltext = UD_req.responseText;
			if (xmltext.indexOf("403 Acces Deny")>-1){
				
				//top.window.location.reload();
			}
			var users =	xmltext.substring(xmltext.indexOf("users>")+6,xmltext.indexOf("</users>")); 
			var x = document.getElementById("dock_online_section");
			if (x != null) x.innerHTML = users;
			try{
			var nm = xmltext.substring(xmltext.indexOf("nm>")+3,xmltext.indexOf("</nm>"));
			var nmt = xmltext.substring(xmltext.indexOf("nmt>")+4,xmltext.indexOf("</nmt>"));
			_updateEmail(nm,nmt);
			}catch(e){}
			udxtimer = window.setTimeout("_startCheckTimer()",udtimer);
		}else {
	        }
    }
}


function xgd_getLeft(_object){
	var nLeft = 0;
	while (_object.offsetParent)
	{
		nLeft += _object.offsetLeft;
		_object = _object.offsetParent;
	}
	return nLeft;
}

function xgd_getTop(_object){
 	var nTop = 0;
 	while (_object.offsetParent)
 	{
 		nTop += _object.offsetTop;
 		_object = _object.offsetParent;
 	}
 	return nTop;
	}

function xgd_GenerateID(){
	try{
		var s=""
		var d = new Date();
		s= d.getTime();
		return s;	
	}
	catch(e)
	{
	}
}


