var strBrowserType = GetBrowserType()

// this functions returns a browser type string
function GetBrowserType()
{
	if (parseInt(navigator.appVersion) >= 4)
	{
		if (navigator.appName == "Netscape")
		{
			if ( document.getElementById && !document.all )
				return "NC6"
			else
				return "NC" // Currently using Netscape Communicator 4.76
		}
		else
			return "IE" // Currently using MS Internet Explorer IE 5.01
	}
}

// custom javascript trim function to truncate 
// leading and trailing spaces of a string 
function TrimString(strtotrim)
{ 
   var strtemp = "" + strtotrim;
   strtemp = strtemp.replace(/&nbsp/g, "").replace(/;/g,""); //Sridhar-30488:Added this to eliminate "&nbsp;" appearing in Netscape
   return strtemp.replace(/^\s*(.*\S+)\s*$/,"$1");
}

// saves a cookie value and expiration date
function setCookie (name, value, expires) 
{
    if (!expires) expires = new Date()
    document.cookie = name + "=" + escape (value) +     
    "; expires=" + expires.toGMTString() +  "; path=/"; 
}                                                       

//to read data off of the Cookie
function getCookie (name) 
{
	var dcookie = document.cookie; 
	var cname	= name + "=";
	var clen	= dcookie.length;
	var cbegin	= 0;
	
	while (cbegin < clen) 
	{
		var vbegin = cbegin + cname.length;
	    if (dcookie.substring(cbegin, vbegin) == cname) 
	    { 
			var vend = dcookie.indexOf (";", vbegin);
	        if (vend == -1) vend = clen;
			return unescape(dcookie.substring(vbegin, vend));
	    }
		cbegin = dcookie.indexOf(" ", cbegin) + 1;
	    if (cbegin == 0) break;
	}
	return "";
}

// deletes an existing cookie
function delCookie (name) 
{
    var expireNow = new Date();
    document.cookie = name + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

function SaveSettings()
{
	//Changed by Amit Fix 20385
	if (eval(document.getElementById("Remember")) != null)
	{
		var remeval		= document.getElementById("Remember").value
		var eloginid	= document.getElementById("emagicloginid").value
		var epasswd		= document.getElementById("emagicpasswd").value
	
		// save the above values as cookies for period of 31 days
		var expdate = new Date ();
		expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 31));
	    
		setCookie ("_LoginID",	 eloginid, expdate);
		setCookie ("_Password",  epasswd,  expdate);
		setCookie ("_Chkbxval",	 remeval,  expdate);
	}
	
}

function BodyOnLoad()
{
	if (eval(document.getElementById("Remember")) != null)
	{
		document.getElementById("Remember").value = getCookie ("_Chkbxval")
	
		if (document.getElementById("Remember").value == 1 )
		{
			document.getElementById("Remember").disabled	= false
			document.getElementById("Remember").checked		= true
			document.getElementById("emagicloginid").value	= getCookie ("_LoginID")
			document.getElementById("emagicpasswd").value	= getCookie ("_Password")
		}
		else
		{
			document.getElementById("emagicloginid").value	= ""
			document.getElementById("emagicpasswd").value	= ""
		}	
	}	
	if (eval(document.getElementById("LANUSED")) != null)
		document.getElementById("LANUSED").value = strLanguageUsedInLoginPage

	// if NT Authentication is on
	if ( (strNTLoginID !="") && (strClientErrors == "") && (strclientdatacount>0) )
	{	
		document.getElementById("emagicloginid").value = strNTLoginID
		document.getElementById("emagicpasswd").value  = strNTLoginPasswd
		document.defaultfrm.submit()
	}
}

// enables remeber settings checkbox
function enablechbx()
{
	if (eval(document.getElementById("Remember")) != null)
	{
		var strloginidval = document.getElementById("emagicloginid").value
		if (strloginidval.length > 0) document.getElementById("Remember").disabled = false
	}
}

function Save()
{	 	
	 if (Pwdflag == 1 && document.getElementById("53").value=="" ) {
		if (eval(document.getElementById("FLDLBL_53")) != null) document.getElementById("FLDLBL_53").style.fontWeight = "bold"
		//Rashmi - Added for Fix of Issue #25278     
		var ret = MerlinSystemMsg(11059,64)
		if (ret)
		{
			document.getElementById("53").focus();
			return false;
		}
		else
		{
			Redirect();			  
			return false;
		}
	  //Rashmi      		
		}

	var ret = verifypwd()
	if (ret)
	{
		//Added by Amit Fix 20385			
		SaveSettings();	
		document.newclientfrm.submit()
	}
	else //Rashmi - Added for Fix of Issue #25278
		return false;
}

//Rashmi - Added for Fix of Issue #25278
function Redirect()
{	
	var strURL = 'PreLogin.asp?langsettings=' + strHelpLanUsed;	
	window.location.href = strURL;
}
//Rashmi

function verifypwd()
{
    if(document.getElementById("9").value=="")
    {
      //alert("(11056) Please Enter First Name") 
      
      //Rashmi - Added for Fix of Issue #25278     
      var ret = MerlinSystemMsg(11056,64)
      if (ret)
      {
		document.getElementById("9").focus();
		return false;
	  }
	  else
	  {
		Redirect();			  
		return false;
	  }
	  //Rashmi      
    }
   
	if(document.getElementById("11").value==""){
      //alert("(11057) Please Enter Last Name")
      //Rashmi - Added for Fix of Issue #25278     
      var ret = MerlinSystemMsg(11057,64)
      if (ret)
      {
		document.getElementById("11").focus();
		return false;
	  }
	  else
	  {
		Redirect();			  
		return false;
	  }
	  //Rashmi       
    }
	
	  if(document.getElementById("8").value==""){
      //alert("(11058) Please Enter Client ID")
       //Rashmi - Added for Fix of Issue #25278     
      var ret = MerlinSystemMsg(11058,64)
      if (ret)
      {
		document.getElementById("8").focus()
		return false;
	  }
	  else
	  {
		Redirect();			  
		return false;
	  }
	  //Rashmi        
    }
    //Added by Amit for fix 25959
    if (eval(document.getElementById("24"))!=null){
			var sMail=document.getElementById("24").value
			if(sMail !="" && sMail != null)
			{
				if ((sMail.indexOf("@")!= -1) && (sMail.indexOf(".")!= -1))	//Check SMTP format
				{
					if (sMail.indexOf("{") == -1 && sMail.indexOf("}") == -1)
					document.getElementById("24").value="SMTP:{" + sMail + "}" + sMail
					else
						document.getElementById("24").value = sMail
				}
				else
				{
					//alert("(10080) Invalid SMTP Email Address.  When using SMTP Email, the Email Address must be in the following format:  jdoe@yahoo.com")
					//Rashmi - Added for Fix of Issue #25278     
					var ret = MerlinSystemMsg(11110,64)
					if (ret)
					{
						document.getElementById("24").focus()
						return false;
					}
					else
					{
						Redirect();			  
						return false;
					}
					//Rashmi 					
				}
			}
		}	
	//End Amit	
	return true
}

function alterddlist()
{
   if (Pwdflag == 1 && document.getElementById("53").value=="" ) {
		if (eval(document.getElementById("FLDLBL_53")) != null) document.getElementById("FLDLBL_53").style.fontWeight = "bold"
  }
  if (eval(document.getElementById("LBL2")) != null) document.getElementById("LBL2").innerHTML = ""
}


function OpenHelp()
{
   var strHelpFilename;
   if(CommonModuleObj.FormSeq=="11") 
      strHelpFilename="NewClientRegistration_";
	else 
       strHelpFilename=CommonModuleObj.ViewName+"_";
   callHelp(strHelpFilename, strHelpLanUsed);
}




function fixupEventsForNetscape()
{


   
   var index;
   if(navigator.appName=="Netscape")
   {

      //special netscape only handling
      fixupPasswordFieldForNetscapeOnLoad();
   
      var tagInputArray=document.getElementsByTagName("INPUT");
      for(index=0; index < tagInputArray.length;index++)
      {
         if (tagInputArray[index].getAttribute("onchange") == "FieldTabOut()"){
            tagInputArray[index].setAttribute("onchange","FieldTabOut(event)");
          }
         else if (tagInputArray[index].getAttribute("onchange") == "ValidateData()")
         {
            tagInputArray[index].setAttribute("onchange","ValidateData(event)");
         }
      }
      
      var tagArray=document.getElementsByTagName("IMG");
      for(index=0; index < tagArray.length;index++)
      {
         var strClick=tagArray[index].getAttribute("onclick");
         if ((null == strClick) || '' == strClick)
            continue;
         if(strClick && strClick.indexOf("OpenPopup")>=0)
         {
            tagArray[index].setAttribute("onclick","OpenPopup(event)");
         }
         if(strClick && strClick.indexOf("SelectValidatedData")>=0)
         {
            tagArray[index].setAttribute("onclick","SelectValidatedData(event)");
         }
         if(strClick.indexOf("SelectDate")>=0)
         {
            tagArray[index].setAttribute("onclick","SelectDate(event)");
         }
         if(strClick.indexOf("OpenEMail")>=0)
         {
            tagArray[index].setAttribute("onclick","OpenEMail(event)");
         }
      }

      var tagArray=document.getElementsByTagName("BUTTON");
      for(index=0; index < tagArray.length;index++)
      {
         var strClick=tagArray[index].getAttribute("onclick");
         if ((null == strClick) || '' == strClick)
            continue;

         if(strClick.indexOf("Save")>=0)
            tagArray[index].setAttribute("onclick","Save(event)");
         else if (strClick.indexOf("Clear")>=0)
            tagArray[index].setAttribute("onclick","Clear(event)");
         else if (strClick.indexOf("Close")>=0)
            tagArray[index].setAttribute("onclick","Close(event)");

      }
   } //end of netscape only if

   var tagTextAreaArray=document.getElementsByTagName("TEXTAREA");
   for(index=0; index < tagTextAreaArray.length;index++)
   {
      if (tagTextAreaArray[index].getAttribute("onchange") == "ValidateData()")
      {
         tagTextAreaArray[index].setAttribute("onchange","ValidateData(event)");
      }
   }
}


/********************************
 * The following code is all to work around a netscape issue involving
 * the cursor being in a field (in this case the password field) and the submit
 * button being clicked when the current fields onchange creates a new window.
 *
 * Regardless of what is done in the submit button code, netscape always
 * submits the form.
 * 
 * Only workaround is to diable submit button.
 * 
 * Issue found and fixed with Netscape 7.1
 *
 */


/**
 * NOTE: getPasswordFieldForNetscape returns null if wrong module.
 */
function getPasswordFieldForNetscape()
{
   if (!(window['CommonModuleObj'] && "10" == CommonModuleObj.ViewName))
      return null;

   var inField = document.getElementById("53");
   return inField;
}   

function getPasswordSubmitButton()
{
   return document.getElementById('TOOLBUTTON_Submit');
}


var PasswordFieldForNetscapeFocusOrigColor = '';
function fixupPasswordFieldForNetscapeFocus()
{
   var button = getPasswordSubmitButton();

   if (null == button)
      return;
   PasswordFieldForNetscapeFocusOrigColor = button.style.color;
   button.style.color = 'grey';
   button.disabled = true;
}

function fixupPasswordFieldForNetscapeBlur()
{
   var button = getPasswordSubmitButton();
   if (null == button)
      return;
   button.style.color = PasswordFieldForNetscapeFocusOrigColor;
   button.disabled = false;
}


function fixupPasswordFieldForNetscapeOnLoad()
{
   var inField = getPasswordFieldForNetscape();
   if (null == inField)
      return;
   inField.setAttribute("onfocus", "fixupPasswordFieldForNetscapeFocus()");
   inField.setAttribute("onblur", "fixupPasswordFieldForNetscapeBlur()");
}
