function windowload()
{    
    if (bUseLDAPAuth)
    {
        document.getElementById("FLDTABLE_ForgotPWD").style.display = 'none';
    }
    if (document.getElementById("SelectLang") != null)
    {
        var arrID = strLangID.split(",");
        var arrName = strLangName.split(",");
        
        var oOption;
        for (i=0; i < arrID.length-1; i++)
        {
            oOption = document.createElement("OPTION");
            oOption.text = arrName[i];
            oOption.value = arrID[i];
            
            try
            {
               document.getElementById("SelectLang").add(oOption, null); // standards compliant; doesn't work in IE
             }
            catch(ex)
            {
                document.getElementById("SelectLang").add(oOption); // IE only
            }            
            
            if (oOption.value == strLanguageUsedInLoginPage)
            {
                document.getElementById("SelectLang").selectedIndex = i;
            }
        }         
    }
    
    if (validationError != "")
	{
	   ShowInfoSpaceMsg(GetMerlinMsg(11156), validationError, 'Critical') ;
	   validationError = "";
	   
	   if(getCookie ("_LoginID") != null && getCookie ("_LoginID") != 'undefined' && document.getElementById("emagicloginid") != null)
	        document.getElementById("emagicloginid").value = getCookie ("_LoginID")
	   
	   if(getCookie("_Chkbxval") != null && document.getElementById("Remember") && getCookie ("_Chkbxval") != 'undefined')
	   {
	       if (getCookie("_Chkbxval") == "true")
		        document.getElementById("Remember").checked = true;
	        else
	            document.getElementById("Remember").checked = false;
	   }
	   
	   var expdate = new Date ();
	   expdate.setTime (expdate.getTime() + (-1 * 60 * 60 * 24 * 31));
	   setCookie ("_LoginID", "", expdate);
	   setCookie ("_Password", "", expdate);
	   setCookie ("_Chkbxval", "", expdate);
	   
	    if (bUseIntegratedLogin && !bUseLDAPAuth) 
		{
		    if (strNAMCSUsersFlag != "CS")
	        {
	            document.getElementById('divWIASSDHTM').style.display = "block";/*HTML content for WIA with SSD license*/
	            document.getElementById('Welcome').innerText = "Login Error";
	        }
		}
		else
		{
		     if (document.getElementById("emagicloginid") != null)
		        document.getElementById("emagicloginid").focus();
		}
    }    
	else if (loggingOff)
	{
	    if (bUseIntegratedLogin && !bUseLDAPAuth) 
		{
	        if (document.getElementById('divWIASSDHTM') != null)
	        {
	            document.getElementById('divWIASSDHTM').style.display = "block";/*HTML content for WIA with SSD license*/	            
	        }
	        document.getElementById('Welcome').innerHTML = "Welcome " + strClientID;
	    }
		ShowInfoSpaceMsg(GetMerlinMsg(11158), GetMerlinMsg(11157), 'Information') ;
		loggingOff = false;
		BodyOnLoad();/*Bug fix 48500*/
	}
	else if (timingOut)
	{
	    if (bUseIntegratedLogin && !bUseLDAPAuth) 
		{
	        if (document.getElementById('divWIASSDHTM') != null)
	        {
	            document.getElementById('divWIASSDHTM').style.display = "block";/*HTML content for WIA with SSD license*/	            
	        }
	        document.getElementById('Welcome').innerHTML = "Welcome " + strClientID;
	    }

		ShowInfoSpaceMsg(GetMerlinMsg(11158),  GetMerlinMsg(11159), 'Information') ;
		timingOut = false;
		BodyOnLoad();/*Bug fix 48500*/
	}
	else if (validationError == "") 
	{
		if (bUseIntegratedLogin && !bUseLDAPAuth) 
		{
		    if (strNAMCSUsersFlag != "CS")
		    {
		        Login();
		    }
			else 
			{
			    if (arrID.length <= 2)  //if only 1 lang to select do auto login
			    {
			        Login();
			    }
			    if (document.getElementById('Welcome') != null)
			    {
			        document.getElementById('Welcome').innerHTML += strClientID;
			    }
			}
		} 
		else 
		{
			if (eval(document.getElementById("bodybgcolor")) != null)
				document.body.style.backgroundColor =  document.getElementById("bodybgcolor").value
			if (eval(document.getElementById("emagicloginid")) != null)
				document.getElementById ("emagicloginid").focus();
			BodyOnLoad()
		}
	}
	
	if (eval(document.getElementById("emagicloginid")) != null)
		document.getElementById ("emagicloginid").maxLength=nClientIdLen;	//Sri:45245
	if (document.getElementById("TOOLBUTTON_Submit") != null)
	    document.getElementById("TOOLBUTTON_Submit").removeAttribute("type");

	adjustLoginPage()
	if ((typeof(autoLangSelect) != "undefined") && (autoLangSelect))
	    OKClicked();
}

//check to see if the cached files on the browser are in sync with the server files.
function Login()
{
	ifrmVersionCheck = document.createElement("iframe");
	ifrmVersionCheck.style.display = 'none';
	ifrmVersionCheck.id = "ifrmVersionCheck";
	document.body.appendChild(ifrmVersionCheck);
	ifrmVersionCheck.src = "cachecheck.asp";
}

function PostLogin()
{
   	// Saroj (20-Apr-2006): Fix for bug #41699. In case of SSHD, Set the value of "emagicloginid" 
	// element to the LoginID (ClientID) before submitting the form (in case of SSHD).
	if ((bUseIntegratedLogin && !bUseLDAPAuth) && document.getElementById("emagicloginid") != null && strNAMCSUsersFlag != "CS") 
	{
		document.getElementById("emagicloginid").value = strClientID;
	}

//Sridhar:LDAP blank pwd issue<--	
	if(!CheckBlankPwdLDAP())
	{
        ShowInfoSpaceMsg(GetMerlinMsg(11156), GetMerlinMsg(11120), 'Critical') ;
        if(document.getElementById("emagicpasswd"))
        {
            document.getElementById("emagicpasswd").focus();
        }
	    return false;
	}
//-->
	
	document.defaultfrm.submit();
}

function adjustLoginPage()
{
	var strleft, strwidth, strheight
	if(navigator.appName != "Microsoft Internet Explorer")
	{
		var tagArray = document.getElementsByTagName("FIELDSET");
		for(Index=0; Index < tagArray.length;Index++)
		{
			strleft = tagArray[Index].style.left.replace(/px/,"");
			strleft = parseInt(strleft) - 2;
			tagArray[Index].style.left = strleft;
			strwidth = tagArray[Index].style.width.replace(/px/,"");
			strwidth = parseInt(strwidth) - 19;
			tagArray[Index].style.width = strwidth;
			
		}
		
		tagArray = document.getElementsByTagName("INPUT");
		for(Index=0; Index < tagArray.length;Index++)
		{
			if (tagArray[Index].type == "checkbox")
			{
				strwidth = tagArray[Index].style.width.replace(/px/,"");
				strwidth = parseInt(strwidth) - 6;
				tagArray[Index].style.width = strwidth;
				strheight = tagArray[Index].style.height.replace(/px/,"");
				strheight = parseInt(strheight) - 6;
				tagArray[Index].style.height = strheight;
			}		
		}
	}
}

function ShowInfoSpaceMsg(headerText, message, errorType/*Critical, Warning, Information*/)
{
    document.getElementById("plcInfospaceHolder").style.display = 'block';
    document.getElementById('divHeader').innerHTML  = headerText;
    document.getElementById('divMessage').innerHTML  = message;    
    document.getElementById("plcInfospaceHolder").className = 'BMCStatusHeader' + errorType;
}

function HideInfoSpace()
{
    document.getElementById("plcInfospaceHolder").style.display = 'none';
}

function Save()
{
//Sridhar:LDAP blank pwd issue<--	
	if(!CheckBlankPwdLDAP())
	{
        ShowInfoSpaceMsg(GetMerlinMsg(11156), GetMerlinMsg(11120), 'Critical') ;
        if(document.getElementById("emagicpasswd"))
        {
            document.getElementById("emagicpasswd").focus();
        }
	    return false;
	}
//-->
	//Added by Amit for fix 20385
	SaveSettings();
	Login();
}

//Sridhar: Added the check for blank password for LDAP authentication
function CheckBlankPwdLDAP()
{
    if (bUseLDAPAuth)
    {
        if(document.getElementById("emagicpasswd"))
            formPasswordValue = document.getElementById("emagicpasswd").value;
        if( UtilTrimStr(formPasswordValue) == "")
        {
            return false;
        }
    }
    return true;
}
//End Sridhar

//window.onload = windowload;

function onpresubmit()
{
	if (GetBrowserType()=="IE")
	{
	  var strClickedObjectsID = event.srcElement.id
	  
	  if (strClickedObjectsID == "TOOLBUTTON_Submit")
		return;
		
	  if ( (strClickedObjectsID == "Register") || (strClickedObjectsID == "ForgotPWD") || (strClickedObjectsID == "TroubleReg") )
	  {	
			if (GetBrowserType()=="IE")
			{
			    if (document.defaultfrm)
			    {
				    document.defaultfrm.style.cursor = "wait"
				}
				for (i=0; i<document.all.length; i++)
				{
					try
					{
						document.all(i).style.cursor = "wait"
					}
					catch(e){}
				}//for
			}
		}
	}
	
}

document.onclick =  onpresubmit;

function enterSubmit(e)
{
	// key press of enter key, submit the form.
	if (GetBrowserType()=="IE")
	{
		if (event.keyCode==13) document.defaultfrm.click()
	}
	else
	{	
		//if (e.which==0) document.defaultfrm.submit()
	}
}
document.onkeypress = enterSubmit;

function alinkclick()
{
    window.parent.location = "MiscPreLoginPages.asp?Module=NEWREG";
}

function clientclick()
{
        var a = "";
        
        if(document.getElementById ("emagicloginid"))
            a = document.getElementById ("emagicloginid").value.toUpperCase()
        
        var extraParams = "";
        if (a != "")
        {
            extraParams = "serviceid="+encodeURIComponent(a);
            window.parent.location = "MiscPreLoginPages.asp?Module=FORGOTPWD&ExtraParams=" + extraParams;
        }
        else
           window.parent.location = "MiscPreLoginPages.asp?Module=FORGOTPWD";
}

function MagicLink()
{
	window.location.href = "http://www.bmc.com/BMC/Common/Templates/hou_generic_tab/0,,19052_34830527,00.html"
}

function troubleregclick()
{
    window.parent.location = "MiscPreLoginPages.asp?Module=TROUBLEREG"
}

function OpenHelp()
{
  callHelp("SigninandRegistration_", strHelpLanUsed);
}

//the help button toggles between OpenHelp() and this one based on context.  
//This is set in cachecheck.asp
function OpenClearCacheHelp()
{	
		callHelp("sshdcachewin.htm", null);
}

function Languagechange(ddlSelectLang)
{
    var loginId;
    var remember;
    if (document.getElementById("emagicloginid"))
        loginId = document.getElementById("emagicloginid").value;
    
    if (document.getElementById("Remember"))
        remember = document.getElementById("Remember").checked;
        
    var langSeq = ddlSelectLang.options[ddlSelectLang.selectedIndex].value; 
      
    document.defaultfrm.action = "prelogin.asp?langsettings=" + langSeq + "&fromLanguageChange=true&loginID=" + loginId + "&remember=" + remember;
    document.defaultfrm.submit()
}

function OKClicked()
{
    Login();
}

function LoginFromNewReg()
{
    window.parent.location="prelogin.asp?langsettings=" + document.getElementById("LANUSED").value;
}

function clientIDSearch()
{
    window.parent.location = "MiscPreLoginPages.asp?Module=CLIENTIDREQ"
}
/* © Copyright 1998, 2004-2007 BMC Software, Inc. */
/* The source code embodied herein is a trade secret of BMC Software, Inc. All use, disclosure, and/or reproduction not specifically and expressly authorized, in writing, by BMC Software, Inc. is prohibited. */
