//var uri = "/Default.aspx";
var uri = "/DefaultProxy2.aspx";
var cX = 0; var cY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) 
{
d.style.left = (cX-125) + "px";
d.style.top = (cY+775) + "px";
}

function AssignPositionFF(d) 
{
d.style.left = (cX-40) + "px";
d.style.top = (cY-390) + "px";
}


function HideContent(d, posContent) {
if(d.length < 1) { return; }
//document.getElementById(d).style.display = "none";
document.getElementById(d).style.visibility = "hidden";
}
function ShowContent(d, posContent) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
if(posContent)
{
    AssignPosition(dd);
}
//dd.style.display = "inline-block";
dd.style.visibility = "visible";
}



function HideContent2FF(d, posContent) 
{
    if(d.length < 1) { return; }
    document.getElementById(d).style.visibility = "hidden";
}

function HideContent2(d, posContent) 
{
    if(d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowContent2(d, posContent) 
{
    if(d.length < 1) 
    { 
        return; 
    }
    var dd = document.getElementById(d);
    if(posContent)
    {
        AssignPosition(dd);
    }
    dd.style.display = "block";
}

function ShowContent2FF(d, posContent) 
{
    if(d.length < 1) 
    { 
        return; 
    }
    var dd = document.getElementById(d);
    if(posContent)
    {
        AssignPositionFF(dd);
    }
    dd.style.visibility = "visible";
}

function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
//AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}


function RegisterValidate()
{
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
    if (d('txtUsername').value == "")
	{
		alert('Username cannot be empty');
		return;
	}	
	else if (!filter.test(d('txtEmail').value))
	{
		alert('Please enter a valid email address.');
		return;
	}
    else if (d('txtPassword').value == "")
	{
		alert('Password cannot be empty');
		return;
	}	
	else if (d('txtPassword').value != d('txtConfirmPassword').value)
	{
		alert('Passwords do not match.');
		return;
	}	
		
	d('lblError').innerHTML = 'Registering...';
    s('lblError').display = '';
	var data = "a=register&tc=1&u=" + d('txtUsername').value + "&p=" + d('txtPassword').value + "&e=" + d('txtEmail').value;	
	SendData(data);
}




var httpreq = null;
var httpreqGet = null;

function start()
{
	httpreq = new getHTTPObject();
	if (httpreq == null)
	{
		alert("Sorry your browser does not support XMLHTTPObject");
		document.location = "about:blank";
	}
	else
	{
	}
}

function getHTTPObject()
{
	var xmlhttp = null;
	var ie5 = document.all && document.getElementById;
	var ns6 = document.getElementById && !document.all;
	if(ns6)
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch(e)
		{
			xmlhttp = null;
		}
	}
	else
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			xmlhttp = null;
		}
	}
	return xmlhttp;
}

function Login()
{	
    d('ml_error').innerHTML = 'Logging in';
    s('ml_error').display = '';
	var data = "a=login&tc=1&u=" + d('ml_username').value + "&p=" + d('ml_password').value;	
	SendData(data);
}



function RequestPassword()
{
    d('fp_msg').innerHTML = 'Validating username...';
    s('fp_msg').display = '';
	var data = "a=RequestPwd&tc=1&u=" + d('fp_username').value;
	SendData(data);
}

function SendData(params)
{
    try
    {
        if (httpreq.readyState === 4 || httpreq.readyState === 0) 
        {               
            var lRand = Math.random();
            httpreq.open("POST", uri + "?r=" + lRand, true);
            httpreq.onreadystatechange = ReadyHandler;
            httpreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
            httpreq.send(params);            
        }
    }
    catch(e)
    {
        //throw e;
    }
}

function ReadyHandler()
{
	if (httpreq.readyState == 4)
	{
		if (httpreq.status == 200) 
		{			
			str = httpreq.responseText;
			str = str.replace(/\</g, "&lt;");
			str = str.replace(/\>/g, "&gt;");
			try
			{
			    eval(httpreq.responseText);
			    
			}
			catch (e)
			{
				//throw e;
			}
		}
		else
		{
		}		
	}
	return;
}



function showloginarea()
		{
			var login = document.getElementById('login')
			var forgotpwd = document.getElementById('forgotpwd')
			var signup = document.getElementById('signup')
			login.style.display="block";
			forgotpwd.style.display="none";
			signup.style.display="none";
		}


	function showsignuparea()
		{
			var login = document.getElementById('login')
			var forgotpwd = document.getElementById('forgotpwd')
			var signup = document.getElementById('signup')
			login.style.display="none";
			forgotpwd.style.display="none";
			signup.style.display="block";
		}


	function showforgotpwdarea()
		{
			var login = document.getElementById('login')
			var forgotpwd = document.getElementById('forgotpwd')
			var signup = document.getElementById('signup')
			login.style.display="none";
			forgotpwd.style.display="block";
			signup.style.display="none";
		}

	function gotoskrbl()
		{
			//alert("start skrbl")
			document.location.href = '/start?';
		}


	function gotofeedback()
			{
				alert("go to feedback ")
		}

	function gotoblog()
				{
					alert("go to blog ")
			}
	function d(tag_id)
    {
	    return document.getElementById(tag_id);
    }		
    
    function s(tag_id)
    {
	    return document.getElementById(tag_id).style;
    }

    function submit_ml()
    {        
        d('actionField').value='login';
        d('homepage').submit();
    }
    
    function OpenAltSessionID()
    {
        if(d('altSessionID').value == "")
        {
            alert("Please enter a session ID");
        }
        else
        {
            document.location.href = '/'+ d('altSessionID').value;
        }
    }
    
    function OpenAltSessionID2()
    {
        if(d('altSessionID2').value == "")
        {
            alert("Please enter a session ID");
        }
        else
        {
            document.location.href = '/'+ d('altSessionID2').value;
        }
    }
    
    function SubmitSessionPwd()
    {
        document.cookie='wb_pwd=' + d('ppSkrblPwdText').value + ';path=/';
        document.location.href = document.location.href;
    }
    
    function startNewSkrbl()
    {
        var userid = "";
        if(getCookieValue('AppUsername'))
        {
            userid = getCookieValue('AppUsername');
        }
        
        var expireStr = 'expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
        try{document.cookie = 'tokenHostGuid=;'+ expireStr;}catch(e){}
        
        document.location.href = '/start?appid=skrbl&appuserid=' + userid;
    }
    
    function userNotHost()
    {
    }
    
    /*==============================================================================
    http://www.braemoor.co.uk/software/cookies.shtml
    Routine to get the current value of a cookie
        Parameters:
            cookieName        Cookie name    
        Return value:
            false             Failed - no such cookie
            value             Value of the retrieved cookie

       e.g. if (!getCookieValue("pans") then  {
               cookieValue = getCoookieValue ("pans2);
            }
    */

    function getCookieValue (cookieName) 
    {
      var exp = new RegExp (escape(cookieName) + "=([^;]+)");
      if (exp.test (document.cookie + ";")) {
        exp.exec (document.cookie + ";");
        return unescape(RegExp.$1);
      }
      else return false;
    }
    