// This function allows us to post to other forms rather than postback as expected
// in ASP.NET 1.1
function noPostBack(sNewFormAction)
{
    if(document.layers) //The browser is Netscape 4
    {
        document.layers['Content'].document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
        document.layers['Content'].document.forms[0].action = sNewFormAction;
    }
    else //It is some other browser that understands the DOM
    {
        var theForm = document.getElementById('Form1');
	    theForm.action = sNewFormAction;
	    theForm.__VIEWSTATE.name = 'NOVIEWSTATE';
	    document.forms[0].submit();	    
    }
}

// This function only returns true if the character passed is valid for the MSISDN field
function isValidMSISDNCharacter(keyEvent)
{           
	var charCode = (keyEvent.which) ? keyEvent.which : keyEvent.keyCode
	
    // Check to see if the character code is the representation for one of the numbers, 0-9.
    if (charCode == 13 || charCode == 3)
    {
        handleLogin();
        return false;
    }

    return true; //Doan Doan Doan make sure return all alphanumeric
    if (charCode > 31 && (charCode < 48 || charCode > 57)) 
    {
		if(charCode == 189 || charCode==45)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else if (charCode == 8 || charCode == 46)
	{
			return true;
	}
	else
	{
	return true;
	}

}

// This function swaps the passed TextBox to a Password Box.
function changeTextToPass (textId,passId)
{
	// Get Reference to the existing TextBox
	var theTextBox = document.getElementById(textId);
	var thePassBox = document.getElementById(passId);
    
	if(theTextBox==null || thePassBox==null)
	{
		return;
	}
	else
	{
		thePassBox.onkeypress = function (e) 
    		{ 
        		// Call Validation Function on Enter KeyPress
        		if (!e) {e = window.event; }
        		var charCode = (e.keyCode || e.charCode);
      
        	if (charCode == 13 || charCode == 3)
        	{
           		 e.cancelBubble = true;
            		 e.returnValue = false;
            		 handleLogin();
            		// Return False prevents the search box event handler from picking up the keypress.
            		return false;
        	}
            
    		}
    
    		theTextBox.style.display = 'none';
    		thePassBox.style.display = 'block';
    		thePassBox.focus(); 
	
	}

    
}

// This function restores the password box back to a text box

function restorePassToText (passId, textId)
{
   
    // Get Reference to the existing PassBox
	var thePassBox = document.getElementById(passId);
	var theTextBox = document.getElementById(textId);

	if(thePassBox==null || theTextBox==null)
	{
		return;
	}
	else
	{
		// If the passbox has no content, then change it back to a TextBox.
		if (thePassBox.value == "")
		{
	 	  theTextBox.style.display = 'block'; //hidden RememberMeSet="True"
      	  	  thePassBox.style.display = 'none';  //display		
		}
	}
	
	
}


// This function Moves the focus to the password field after there are ten characters in the MSIDISN field.			
function AutoFocus()
{
        var Msisdn = document.getElementById('txtLoginID').value;
       	var thePassBox = document.getElementById('txtPassword');
       	if (Msisdn.length == 13)
        {
            thePassBox.focus();
        }
}

// This function returns true if the MSIDISN field and password fields both pass validation.
function ValidateMsisdnPassword()
{
	
	var msisdn;
	var password;
	var errMessage;
	var agt = navigator.userAgent.toLowerCase();	
    var logintable; 
    
	msisdn = document.getElementById('txtLoginID');
	password = document.getElementById('txtPassword');
	errMessage = document.getElementById('errMessage');
	logintable = document.getElementById('loginTable');
	
	// Stupid Hack to fix this in Safari. Steve Jobs Fix your browser!
	if (agt.indexOf("safari") != -1) 
	{
	    logintable.style.paddingLeft = "95px";
	}
	
	if (msisdn.value == "" ||  msisdn.value == " Login ID" || msisdn.value == " Password")
	{
	    // Msisdn is not entered, check password value to determine error message to display
	    if (password.value == "" || password.value == " password" || password.value == "password")
		{
			/*errMessage.innerHTML = "Please enter phone number & password."; 
			errMessage.style.display = 'block'; Hung 20080604*/
			return false;
		}
		else
		{
			/* errMessage.innerHTML = "<span style='padding-right:65px;'>Please enter phone number.</span>"; 
			errMessage.style.display = 'block';  Hung 20080604*/
			return false;
		}
			
	}
	else if (msisdn.value.length < 10)
	{
		// Msisdn Entered is not valid.
		
		// Stupid Hack to fix this in Safari. Steve Jobs fix your browser!
	    if (agt.indexOf("safari") != -1) 
		{   
		    logintable.style.paddingLeft = "100px";
		}
		
		/*errMessage.innerHTML = "Your phone number should be 10 digits. For example: 4445551212";
		errMessage.style.display = 'block'; Hung 20080604*/
		return false;
	}		
	else
	{
		// Valid Msisdn has been entered, check for password.
		if (password.value == "" || password.value == " password")
		{
		    /*errMessage.innerHTML = "Please enter password.";
		    errMessage.style.display = 'block'; Hung 20080604*/
		}
		else
		{
		    // Valid Msisdn and a Password has been entered. Validation passed.
		    /*errMessage.style.display = 'none'; Hung 20080604*/
		    return true;
		}
	}
}


// This function is called by either the enter keypress in the password field, or by clicking the login button.
function handleLogin()
{
   
    if (ValidateMsisdnPassword())
    {
	    // Note: LoginUrl is a global variable passed into the script block from the masthead framework.
	
	    var theForm = document.getElementById('Form1');
	    /*theForm.action = loginUrl; Hung 20080604*/
	    theForm.__VIEWSTATE.name = 'NOVIEWSTATE';   
	    document.forms[0].submit();	 
	    return true;
	}
	else
	{
	    return false;
	}	
}

function safariFix()
{
    // Stupid Hack to fix this in Safari. Steve Jobs fix your browser!
    
    var agt = navigator.userAgent.toLowerCase();	
    if (agt.indexOf("safari") != -1) 
    {   
		var phoneCell = document.getElementById('phonecell');
		phoneCell.style.paddingRight = '3px';
	}
	
}

// Needed because Safari does not execute window.onload after the DOM is parsed like other browsers.
setTimeout("safariFix();",500);

window.onload = function ()
{
    //setFooter(80,75); //Hung
    
    // IE6 Fix, will be removed as soon as we can correct the codebehind.
	if (navigator.appName == "Microsoft Internet Explorer") 
	{
	    var submitbutton = document.getElementById('btnLogin');
	    if(submitbutton==null)
	    {
	        return;
	    }
	    else
	    {
	        submitbutton.href = "#";
	    }    
	}
}

function LanguageOnClick(varLanguage){	   	    			   			    
    document.getElementById('lanENVN').value = varLanguage;
    document.Form1.submit();			    		    		    			    			    
}





