//var uri = "/Default.aspx";
var uri = "/DefaultProxy3.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})+$/;
    
    var re = /^\w+$/;
    
    if (d('txtUsername').value == "")
	{
		alert('Username cannot be empty');
		return;
	}
	else if (!re.test(d('txtUsername').value))
	{
	    alert("Username can contain only letters, numbers and underscores.");
	    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 re_2 = /^\w+$/;
    function RegisterGroupValidate()
    {
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;        
        var re = /^\w+$/; //alphanum and underscores
        var re2 =/[0-9A-Za-z]*/; //alphanum
         if (d('txtGroupname').value == "")
	    {
		    alert('Group name cannot be empty');
		    return;
	    }
	    else if (!re.test(d('txtGroupname').value))
	    {
	        alert("Group name can contain only letters and numbers.");
	        return;
	    }
        else if (d('txtUsernameT').value == "")
	    {
		    alert('Username cannot be empty');
		    return;
	    }
	    else if (!re.test(d('txtUsernameT').value))
	    {
	        alert("Username can contain only letters, numbers and underscores.");
	        return;
	    }
	    else if (d('txtPasswordT').value == "")
	    {
		    alert('Password cannot be empty');
		    return;
	    }	
	    else if (d('txtPasswordT').value != d('txtConfirmPasswordT').value)
	    {
		    alert('Passwords do not match.');
		    return;
	    }
	    
	    else if (!filter.test(d('txtEmailT').value))
	    {
		    alert('Please enter a valid email address.');
		    return;
	    }	    
	    else if(!d('chbTerms').checked)
	    {
	        alert('Agree to terms to continue.');
		    return;
	    }
        	
    		
	    //d('lblErrorT').innerHTML = 'Registering...';
        //s('lblErrorT').display = '';
	    var data = "a=groupregister&tc=1&u=" + d('txtUsernameT').value 
	    + "&p=" + d('txtPasswordT').value 
	    + "&e=" + d('txtEmailT').value	
	    + "&gpn=" + d('txtGroupname').value
	    + "&cpn=" + d('txtOrgname').value
	    + "&actype=" + "T0" + "&skypeID=" + ""; //d('txtSkypeID').value;
	    SendData(data, '/TeamProxy.aspx');
    }


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, postTo)
{
    try
    {
        if (httpreq.readyState === 4 || httpreq.readyState === 0) 
        {               
            var lRand = Math.random();
            if(postTo == null)
            {
                httpreq.open("POST", uri + "?r=" + lRand, true);
            }
            else
            {
                httpreq.open("POST", postTo + "?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('currentSessionId').value + '=' + d('ppSkrblPwdText').value + ';path=/';
        document.location.href = document.location.href;
    }
    
    function readCookie(name)
    {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++)
	    {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	    }
	    return null;
    }
    
    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;
    }

    var skrbl_server = "http://www.skrbl.com/";
    function embedcode()
    {
        var imgHtml = '<img alt="skrbl now" src="'+ skrbl_server +'sn.gif" style="cursor:pointer;" onclick="window.open(' + "'" + skrbl_server + 'skrblnow' + "'" + ');"/>';
//        d('btn_code').value = GetSplitString(imgHtml, 39);
            d('btn_code').value = imgHtml;
    }    
    
    function GetSplitString(msg, cutOffValue)
    {
        var returnStr = "";
        var txtObjVal = msg;
        var txtObjLength = msg.length;
        
        if(txtObjLength > cutOffValue)
        {
            while(txtObjLength > cutOffValue)
            {
                returnStr += txtObjVal.substring(0, cutOffValue) + "\n";
                var temp=  txtObjVal.substring(cutOffValue);
                txtObjVal = temp;
                txtObjLength = temp.length;
            }
        }
        
        if(txtObjLength < cutOffValue)
        {
            returnStr += txtObjVal;
        }
        
        if(returnStr > cutOffValue)
        {
            return "\n" + returnStr
        }
        else
        {
            return returnStr;
        }
    }
    
    function ShowLoginDivArea()
    {
        s('fp_table').display ='none';
        s('lgn_table').display ='';
        s('LoginLinkDiv').display = 'none';
        s('formTitleDiv').display ='';
        s('rightLinkDiv').display ='';        
    }
    
    function ShowFPDivArea()
    {
        s('lgn_table').display ='none';
        s('fp_table').display ='';        
        s('formTitleDiv').display ='none';
        s('rightLinkDiv').display ='none';
        s('LoginLinkDiv').display = '';
        
    }
    