function gup( name ){
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec( window.location.href );
        if( results == null )   {
                //alert('No Zimbra Error');
                return "";
        }else{
                //alert('Zimbra Error');
                return results[1];
        };
}

function check4ZimbraError(){

 if(gup('Zimbra') != ''){
        //alert('show zimbra error');
        if(document.getElementById('webmailError')){
           document.getElementById('webmailError').style.display = 'block';
	   document.verify.kbutton.style.paddingTop="30px";
        }
 }else{
        //alert('no zimbra error');
        if(document.getElementById('webmailError')){
          document.getElementById('webmailError').style.display = 'none';
	  document.verify.kbutton.style.paddingTop="0px";
        }
 }

}

function clearDefault(el)
{
	if (el.defaultValue==el.value) el.value = "";
}

function CheckKey(f,fieldObj) 
{
	var whichKey = (window.Event) ? f.which : f.keyCode;
        if (whichKey == '13') 
	{
        	submitFunction();
        }
}

function submitFunction() 
{
	var bad = 1;
        var amperLoc = 0;
        var userName;
	var emailAddr;
	

        for(var i=0; i<document.forms[1].elements.length; i++)
	{
        	if(document.forms[1].elements[i].type=="text")
		{
                	for(var n=0; n<document.forms[1].elements[i].value.length;n++)
			{
                        	if(document.forms[1].elements[i].value.charAt(n) == "@")
				{
                                	bad = 0;
                                        amperLoc = n;
                                }
                       	}
                        if(bad) 
			{
                        	document.forms[1].elements[i].value += "@missingDomain.com";
                                alert("You must login with your entire email address.");
                        }
			else
			{
                        	userName = document.forms[1].elements[i].value.substring(0, amperLoc);
				document.verify.user.value = userName;
				//alert("email:"+document.verify.username.value);
				emailAddr = document.verify.username.value;
				//alert("user:"+document.verify.user.value);
				document.verify.domain.value = emailAddr.substring(emailAddr.indexOf('@')+1, emailAddr.length);
                                //alert("domain:"+document.verify.domain.value);

                                document.forms[1].submit();
                        }
		}
	}
}

