
// Loginbar / Username / Password

function submitenter(e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   document.loginform.submit();
   return false;
   }
else
   return true;
}

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

function jConfirm(div,eYes,eCancel){
	$(div).dialog( 'destroy' );
	$(div).dialog({
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		width:350,
		height:150,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.7
		},
		buttons: {
			Yes: function() {
				eval(eYes);
				$(this).dialog('close');
			},
			Cancel: function() {
				if(eCancel!=''){eval(eCancel);}
				$(this).dialog('close');
			}
		}
	});
	$(div).dialog("open"); 
}

function DHTMLSound(surl) {
  document.getElementById("dummyspan").innerHTML=
    "<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}
	
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function ajaxGetmc(){
	var xmlHttp;
	try{  
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e){
		try{    
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e){    
			try{      
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
			}
		// If no ajax support - message. MAYBE TODO: a doc.loc to a non ajax page?
			catch (e){      
				alert("Din webbläsare stöder inte AJAX\n\nVänligen kontakta support@haket.com med vilken browser du kör så att vi kan åtgärda problemet...");      
				return false;
			}	    
		}  
	}
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4)
		{

	// Variables set by callback
		var all = 0;
		var mail = 0;
		var comments = 0;
		var track = 0;
		var usersonline = 0;
		var online = 0;
		var friends = 0;
		var tmp_b;
		var expdate = new Date ();

	// Tempint stores prev number of received messages and compares
	// S mute gets s_mute from asp on page load. TODO: Make on the fly
		var temp_int = 0;
		var s_mute = 0;

	// Var b is set to the result from callback
		var b = xmlHttp.responseText	
		var temp = new Array();

	//Split callback string to an array
			temp = b.split('|');
			mail = temp[0];
			comments = temp[1];
			track = temp[2];
			usersonline = temp[3];
			s_mute = temp[4];
			online = parseInt(temp[5]);
			friends = parseInt(temp[6]);
			tmp_b = temp[7];
			eval(tmp_b);

	// Add mail, comments and tracking to one var (for playsound)
			all = parseInt(mail) + parseInt(comments) + parseInt(track);

	// Setting temp_int to prev mailcount from global, then setting global to current mail count
			temp_int = GetCookie("parent_mail");
//			parent_mail_no = all;
			FixCookieDate (expdate);
			expdate.setTime (expdate.getTime() + (5 * 60 * 1000));
			SetCookie ("parent_mail", all, expdate);


	// if global mailcount is larger than temp_int (prev global mail count then do)
			if (GetCookie("parent_mail")>temp_int && s_mute==0)
			{
				DHTMLSound('/sound/notify.wav');
			}

	// This previously handled frameupdate timer, TODO: HANDLE AJAX TIMER
			if (online)
			{
//				document.getElementById("onlinestatus").innerHTML = '&nbsp;(<%=L("MINIINFO/ACTIVE")%>)'
			}
			else
			{
//				parent.doUpdate(600);	
//				document.getElementById("onlinestatus").innerHTML = '&nbsp;(<%=L("MINIINFO/INACTIVE")%>)'
			}

// Update Inner HTML and images using variables set by callback  TODO: 1 nytt / 2 nya
//			document.getElementById("usersonline").innerHTML = '<img border="0" src="../_images/default_skin/icons/icon-online.gif" width="6" height="8" hspace="5"><%=L("MINIINFO/TOTALLY")%> <b>'+usersonline+'</b> <%=L("MINIINFO/LOGGED_IN")%>';

			if(mail>0){
					document.getElementById("topmenu_info_email").style.background = 'url(/_design/default/icons/32/Email.png)';
					$("#mailcount").text(mail);
			}else{
					document.getElementById("topmenu_info_email").style.background = 'url(/_design/default/icons/32/Email_inactive.png)';
					$("#mailcount").text('');
			}

			if(comments>0){
					document.getElementById("topmenu_info_comments").style.background = 'url(/_design/default/icons/32/Comment.png)'
					$("#commentcount").text(comments);
			}else{
					document.getElementById("topmenu_info_comments").style.background = 'url(/_design/default/icons/32/Comment_inactive.png)'
					$("#commentcount").text('');
			}
			if(friends>0){
					document.getElementById("topmenu_info_friends").style.background = 'url(/_design/default/icons/32/Profile.png)'
			}else{
					document.getElementById("topmenu_info_friends").style.background = 'url(/_design/default/icons/32/Profile_inactive.png)'
			}
		}
	}
	xmlHttp.open("GET","/callbacks/mini_info_getmc.asp?nocache="+Math.random(),true);
	xmlHttp.send(null);  
}