(function() {
    if (window.addEventListener) window.addEventListener("load", init, false);
    else if (window.attachEvent) window.attachEvent("onload", init);

    function init() {
        var inputtags = document.getElementsByTagName("input");
        for(var i = 0 ; i < inputtags.length; i++) {
            var tag = inputtags[i];
            if (tag.type != "text" && tag.type != "password") continue;
            
            if (tag.addEventListener)
                tag.addEventListener("keypress", Handle_UserName, false);
            else {
                tag.onkeypress = Handle_UserName;
            }
        }
    }
    
    function Handle_UserName(event) 
    {
        var e = event || window.event;
        var code = e.charCode || e.keyCode;
	
	if (code==13 && this.getAttribute("id")=="txtUserName")
	{
		document.getElementById("txtPassword").focus();
	}
	if (code==13 && this.getAttribute("id")=="txtPassword")
	{
		//fetchLogin(document.getElementById("txtUserName").value,document.getElementById("txtPassword").value);
		fetchLogin(txtUserName.value,txtPassword.value);
	}
	
        // If this keystroke is a function key of any kind, do not filter it
        if (e.charCode == 0) return true;       // Function key (Firefox only)
        if (e.ctrlKey || e.altKey) return true; // Ctrl or Alt held down
        if (code < 32) return true;             // ASCII control character
        
        // Convert the character code to a character
        var c = String.fromCharCode(code);
        
    }
})();
