/** Used in Login Screen.
*/
function Getstats() 
{
  window.status=('Attempting to Login to user area.')
  
  var Uname;
  var Upwd;
  var FieldCheck = true;
  Upwd  = document.LoginScreen.UPasswd.value;
  Uname = document.LoginScreen.UserName.value;	
                 
     if (Upwd == "" || Uname == "")
     { 
         alert('Login ERROR\n\nYou must enter Valid Username and Password.\n');
         window.status=('You will need a password and username to proceed further. Check spelling and Ensure names are in correct case.')
	 FieldCheck = false;
     } 
     else 
     if ((Uname.search(/[,<.>?\/'";:\\|\]}\[{=+\-)(*&^%$#@!`~ ]/)) != -1)		
     {
	  alert('Login Error\n\nYou have entered invalid username that contains one or more of following ' +
		'characters:\n\t\t(,<.>?\/\'";:\\|\]}\[{=+-_)(*&^%$#@!`~).\n\n Please use the valid username ' +
		'and make sure that username does not contain any blank space.');	         
                    FieldCheck = false;	
     }
     else
       if ((Upwd.search(/[,\<.\>?\/'";:\\|\]}\[{=+\-_)(*&^%$#@!`~ ]/)) != -1)   
     {
	   alert('Login Error\n\nYou have entered invalid password that contains one or more of following ' +
		'characters:\n\t\t(,<.>?\/\'";:\\|\]}\[{=+\-_)(*&^%$#@!`~).\n\n Please use the valid password ' +
		'and make sure that password does not contain any blank space.');	         
                    FieldCheck = false;	
     }
	window.status=('Requires a valid username and password');
	return FieldCheck;
	
}
/** Used in Assigned Rate Search Screen Screen.
*/
function GetValidation()
{
	window.status=('Attempting to get the class code information.')
 var CCode;
 var FieldCheck = true; 
	CCode = document.ARRates.classcode.value;
 	if (CCode == "")
	{
		alert('Class Code ERROR\n\nYou must enter valid class code.\n');
		window.status=('Missing or Invalid Data');
		FieldCheck = false;
	}
 	else 
	if (CCode.length != 4)
	{
		alert('Class Code ERROR\n\nYou must enter four digit number for class code.\n');
		window.status=('check Class Code and try again');
		FieldCheck = false;
	}
 	else 
	if ((CCode.search(/[a-zA-Z']/)) != -1)
	{
		alert('Class Code ERROR\n\nYou must enter four digit number for class code.\n');
		window.status=('check Class Code and try again');
		FieldCheck = false;
	}
		return FieldCheck;
}
/** Used in Assigned Risk Depop Search Screen.
*/
function GetArdepopValidation()
{
	window.status=('Attempting to get the Assigned Risk Depopulation information.');
 var CCode;
 var FieldCheck = true; 
 var Zcode;
	CCode   = document.ardepopscreen.classcode.value;	
        Zcode 	= document.ardepopscreen.zipcode.value; 	
        Prem	= document.ardepopscreen.premium.value;
	SMonth  = document.ardepopscreen.month.selectedIndex;	

		if ((CCode.search(/[a-zA-Z']/)) != -1)
		{
			alert('Assigned Risk Depop Error\n\nYou must enter four digit number for class code.\n');
			window.status=('check Class Code and try again');
			FieldCheck = false;
		}
		if ((Zcode.search(/[']/)) != -1)
		{ 	
			alert('Assigned Risk Depop Error\n\nZip Code should not contain single quote(\'). Please remove it and try  again.\n');
			window.status=('Missing or Invalid Data');
			FieldCheck = false;
		} 
		if ((Prem.search(/[a-zA-Z']/)) != -1)
		{
			alert('Assigned Risk Depop Error\n\nYou must enter number for premium amount.\n');
			window.status=('check premium amount and try again');
			FieldCheck = false;
		}
		return FieldCheck;
}
/** Used in Employer Lookup Search Screen.
*/
function GetEmployerLookupValidation()
{
	
 window.status=('Attempting to get the employer information');
 var Ename;
 var Stype;
 var FieldCheck = true; 

	Ename = document.EmpScreen.EmpName.value;
	Stype = document.EmpScreen.srchtype.selectedIndex;
/** 
 * If search is done by "By Name" then do the validation.
 */
        if (Stype == "0") {
 	    if (Ename == "") {
		alert('Experience Modification History Search Error\n\nEmployer name field can not be empty. You must enter valid employer name.\n');
		window.status=('Missing or Invalid Data');
		FieldCheck = false;
	    } 	
	    if ((Ename.search(/[']/)) != -1) { 	
		alert('Experience Modification History Search Error\n\nEmployer Name should not contain single quote(\'). Please remove it and try again.\n');
		window.status=('Missing or Invalid Data');
		FieldCheck = false;
	    } 
 	  }

/** 
 * If search is done by "By File Number" then do the validation.
 */
	if (Stype == "1") {
 	  if ((Ename.search(/[a-zA-Z]/)) != -1) {
		alert('Experience Modification History Search Error\n\nThe file Number must contain 5 Numbers and no Alph characters.\n');
		window.status=('Remove Alpha character and try again');
		FieldCheck = false;
	  } else 
	  if (Ename.length < 5) {
		alert('Experience Modification History Search Error\n\nThe File Number too short, File numbers must be 5 digits long.Please add leading ZEROS to expand your file number to 5 Digits.\n');
		window.status=('Enter 5 Digits into the File Number and try again');
		FieldCheck = false;
	  }
	}

/** 
 * If search is done by "Contains" then do the validation.
 */
	if (Stype == "2") {
 	  if (Ename == "") {
		alert('Experience Modification History Search Error\n\nEmployer name field can not be empty. You must enter valid employer name.\n');
		window.status=('Missing or Invalid Data');
		FieldCheck = false;
	  } else	
	  if ((Ename.search(/[']/)) != -1) { 	
		alert('Experience Modification History Search Error\n\nEmployer Name should not contain single quote(\'). Please remove it and try again.\n');
		window.status=('Missing or Invalid Data');
		FieldCheck = false;
	  } else 
	  if (Ename.length < 5) {
		alert('Experience Modification History Search Error\n\nPlease enter at least five characters to do a “Contains” search.  A Contains search will return a listing if any portion of the name contains the characters you enter.  If you enter only a few characters, the list will be unmanageably large.\n\n\n');
		window.status=('Enter 5 character for Employer Name');
		FieldCheck = false;
	  }
	}

		return FieldCheck;

}
/**
 * Used to open the link in new browser wondow.
 */
function DocumentLink(url) { 
w = window.open(url,'Help','width=600,height=500,resizable=yes,scrollbars=yes,menubar=yes'); 
w.focus(); 
} 

/**
 * Used to open the link in new browser wondow.
 */
function DocumentLink1(url) { 
w = window.open(url,'Help','width=600,height=500,resizable=yes,scrollbars=yes,menubar=yes'); 
w.focus(); 
} 



/** Used for the ratesheet screen validation.
 *
 */
function EmpRatesheetValidation(f)
{

var FieldCheck = false;
var i;

	for (i = 0; i < f.length;i++)
	{
		var e = f.elements[i];
		if (e.type == "radio")
		{
		    if (e.checked)
		    {
		    	FieldCheck = true;
		    	break;
		    }
		}
	}

		if (FieldCheck == false)
			    alert('You must select the desired ratesheet');
	return FieldCheck;
}


/**
 * Used to validate class code search.
 */
function MCI_GetValidation()
{
	window.status=('Attempting to get the Class Code description information.')
 var CCvar;
 var FieldCheck = true; 
	CCvar = document.MCIscreen.MCIvar.value;	



	if ((CCvar.search(/[']/)) != -1)
	{ 	
		alert('Search String Error\n\The search string should not contain quotes(\'). Please remove it and try again.\n');
		window.status=('Missing or Invalid Data');
		FieldCheck = false;
	} 
 	if (CCvar == "")
	
	{
		alert('Screen Error: Class Code Description Search\n\nYou must enter valid search string\n');
		window.status=('Missing or Invalid Data');
		FieldCheck = false;
	} 	
        
        if (CCvar !== "" ) 
	if (CCvar.length < 3) 
	{
		alert('Search String ERROR\n\nYou must enter at least 3 letters for class code description search.\n');
		window.status=('check Class Code and try again');
		FieldCheck = false;
	}

	if ((CCvar.search(/[0-9]/)) != -1)
	{
		alert('Search String ERROR\n\nPlease do not include NUMBERS in the search string.\n');
		window.status=('check Class Code and try again');
		FieldCheck = false;
	}

		return FieldCheck;
}

/** 
 * Following function is used to validate the informatio on web account application screen.
 */
function WA_GetValidation(form)
{
    var fieldCheck = true;
    var textElement = 0;
    var message = '';
    var emailAddress = 'nothing';
    var emailAddress1;

/**
 First check to see all the field have been entered by the user.
*/
   
    for (var i = 0; i < form.length; i++) {	
	if ((form.elements[i].type == "text") ||
		(form.elements[i].type == "password")) {
	    if (isblank(form.elements[i].value)) {
		message = message + '\t' + form.elements[i].name + '\n';
	     	textElement++;
	     	fieldCheck = false;
	    }
	 	if (form.elements[i].name == "EmailAddress") {
		    emailAddress =  form.elements[i].value;
	 	}
	}
     }
	    

	if (!fieldCheck) {
		alert('Web Application Error\n\nAll fields on this page are required:\n\n');
		return fieldCheck;
        }

 /**
   lets check the validation for email address.
  */
	      
	 if (!checkEmailAddress(emailAddress)) {
		alert('Web Application Error\n\nYour email address is not in correct format.');
		fieldCheck = false;
		return fieldCheck;
	 }

	  
	var NoOfEmailAddresses = form.NoEmailAddress.value;

	for (var i =0; i < NoOfEmailAddresses; i++) {
		emailAddress1 = 'form.EmailAddress' +(i + 1) + '.value';		
		emailValue = eval(emailAddress1);
		if (!checkEmailAddress(emailValue)) {
			alert('Web Application Error\n\nYour email address is not in correct format.');
			fieldCheck = false;
			return fieldCheck;
	 	}
			
	}


/** 
 Check to make sure username and password are not the same and also password hint is not same as password.
 */
		var username 		= form.UserName.value;
		var password 		= form.Password.value;
		var passwordhint 	= form.PasswordHint.value;

		if ((username.length < 6) || (password.length < 6)) {
			alert('Web Application Error\n\nUsername/Password requirements: 6 characters minimum ');
			fieldCheck = false;
			return fieldCheck;
	 	}

		if ((username.search(/[,<.>?\/'";:\\|\]}\[{=+\-)(*&^%$#@!`~ ]/)) != -1)	{
			 alert('Web Application Error\n\nYou have entered invalid username that contains one or more of following ' +
				'characters:\n\t\t(,<.>?\/\'";:\\|\]}\[{=+-_)(*&^%$#@!`~).\n\n Please use the valid username ' +
				'and make sure that username does not contain any blank space.');	         
                   	 fieldCheck = false;	
			 return fieldCheck;
		}

		if ((password.search(/[,<.>?\/'";:\\|\]}\[{=+\-)(*&^%$#@!`~ ]/)) != -1)	{
			 alert('Web Application Error\n\nYou have entered invalid password that contains one or more of following ' +
				'characters:\n\t\t(,<.>?\/\'";:\\|\]}\[{=+-_)(*&^%$#@!`~).\n\n Please use the valid password ' +
				'and make sure that password does not contain any blank space.');	         
                   	 fieldCheck = false;	
			 return fieldCheck;
		}
			

		if (username == password) {
			alert('Web Application Error\n\nUsername and Password can not be the same. Please enter the username and password again and they should not be identical.');
			fieldCheck = false;	
			return fieldCheck;
		}
		
		if (passwordhint == password) {
			alert('Web Application Error\n\nPassword and PasswordHint can not be the same.');
			fieldCheck = false;	
			return fieldCheck;
		}
		
			
/** 
 Check to make sure carrid is 5 digit number.
 */

		var membershipType = form.mvalue.value;
		
		if (membershipType == "MPR") {
		  var carrid = form.CarrID.value;
		     if ((carrid.length != 5) || (isletter(carrid))) {
			alert('Web Application Error\n\nYou must enter five(5) digit number for Carrier code.');
			fieldCheck = false;	
			return fieldCheck;
		     }
		}
		
			
    return fieldCheck;   

}

/**
 * Helper functions.
 */

function isblank(s)
{
	for (var i=0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t'))
			return false;
	}
			return true;
}
function isletter(n)
{
	if ((n.search(/[a-zA-Z]/)) != -1)	
		return true;
		return false;
}
function checkEmailAddress(emailaddr)
{
   var x = trimAll(emailaddr);
   var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;

   if (filter.test(x)) 
       return true;
   else
       return false;
}

function trimAll(sString) 
{ 
	while (sString.substring(0,1) == ' ') 
	{ 
		sString = sString.substring(1, sString.length); 
	} 
	while (sString.substring(sString.length-1, sString.length) == ' ') 
	{ 
		sString = sString.substring(0,sString.length-1); 
	} 
	return sString; 
} 




/** 
 * Following function is used to validate the information on web account application screen.
 */

function getRadioValue(strFormName,strElementName)
{

   var noOfEmailAddresses;

   var fieldStatus = false;
   noOfEmailAddresses = document.formMain.NoEmailAddress.value;

   var url = "/inquiries/WebAccount/AcctSetup.jsp?action=MemberType&mvalue=";
   

  nRadioLength  = eval('document.'+strFormName+'.'+strElementName+'.length');
  strRadioValue = '';
  

  for(var nCurrent = 0; nCurrent < nRadioLength; nCurrent++)
  {
    if ( eval('document.'+strFormName+'.'+strElementName+'[nCurrent].checked') ) { 
	strRadioValue = eval('document.'+strFormName+'.'+strElementName+'[nCurrent].value'); 
	fieldStatus = true;
	break;
    }
      
  }
    

   if (fieldStatus) {
	url = url + strRadioValue +  "&NoEmailAddress=" + noOfEmailAddresses;
    	location = url;	
   }
   else
	alert('You must select the Web Account Type.');

	return fieldStatus;
   
}

/** 
 * Following function is used to validate the information on web account application screen.
 */

function getSelected()
{
   var sRadioValue = '';
       sRadioValue = getRadioValue('formMain','MembershipType');	
       
//	alert("radiovalue " + sRadioValue);
    return sRadioValue;	
}  

/**
 * Helper Function
 */
function isNotNumber(n)
{
	if ((n.search(/[a-zA-Z,<.>?\/'";:\\|\]}\[{=+\-)(*&^%$#@!`~ ]/)) != -1)	
		return true;
		return false;
}

/**
 * Used to validate the information on basic mod calculator screen.
 */
function MC_Validator(theForm)
{
  
  var checkOK = true;
  var incurredLosses  = theForm.AIL.value;
  var primaryLosses   = theForm.APL.value;
  var expectedLosses  = theForm.EL.value;
  var expectedPlosses = theForm.EPL.value;
  var expectedPlosses = theForm.EPL.value;
  var mcpapFctr	      =  theForm.Mcpap_Factor.value;

  var message = '';
  
/** Check to see no fields are missing.
*/
	if (isblank(incurredLosses)) {
	   message = message + '\t' + 'Actual Incurred Losses' + '\n';
	   checkOK = false
	}

	if (isblank(primaryLosses)) {
	   message = message + '\t' + 'Actual Primary Losses' + '\n';
	   checkOK = false
	}

	if (isblank(expectedLosses)) {
	   message = message + '\t' + 'Expected Losses' + '\n';
	   checkOK = false
	}

	if (isblank(expectedPlosses)) {
	   message = message + '\t' + 'Expected Primary Losses' + '\n';
	   checkOK = false
	}
	
	if (isblank(mcpapFctr)) {
	   message = message + '\t' + 'MCPAP Factor' + '\n';
	   checkOK = false
	}


	if (!checkOK) {
		alert('Mod Calculator Error\n\nFollowing fields are missing:\n\n' + message);
		return checkOK;
        }
	
	
/** Check to see all the reqired fields are number.
*/	

	if (isNotNumber(incurredLosses)) {
	   alert('Mod Calculator Error\n\nYou must enter number for Actual Incurred Losses.');
	   checkOK = false;	
	   return checkOK;
	}
	if (isNotNumber(primaryLosses)) {
	   alert('Mod Calculator Error\n\nYou must enter number for Actual Primary Losses.');
	   checkOK = false;	
	   return checkOK;
	}
	if (isNotNumber(expectedLosses)) {
	   alert('Mod Calculator Error\n\nYou must enter number for Expected Losses.');
	   checkOK = false;	
	   return checkOK;
	}
	if (isNotNumber(expectedPlosses)) {
	   alert('Mod Calculator Error\n\nYou must enter number for Expected Primary Losses.');
	   checkOK = false;	
	   return checkOK;
	}
	if ((mcpapFctr.search(/[a-zA-Z,<>?\/'";:\\|\]}\[{=+\-)(*&^%$#@!`~ ]/)) != -1)	 {
	   alert('Mod Calculator Error\n\nYou must enter number for MCPAP Factor.');
	   checkOK = false;	
	   return checkOK;
	}
	
  return (checkOK);
}
/**
 * Used to validate the information on advance calculator.
 */
function AC_GetValidation()
{
 
 window.status=('Attempting to validate the information.')
 var FieldCheck 	= true; 
 var payroll   		= document.ModCalcSetup.numberpayroll.value;
 var lostTimeLosses	= document.ModCalcSetup.numberlostTime.value;
 var medOnlyLosses	= document.ModCalcSetup.numberMedicalOnly.value;
 var message = "";

/** Check to see no fields are missing.
*/
	if (isblank(payroll)) {
	   message = message + '\t' + 'classifications field' + '\n';
	   FieldCheck = false
	}

	if (isblank(lostTimeLosses)) {
	   message = message + '\t' + 'lost-time claims field' + '\n';
	   FieldCheck = false
	}

	if (isblank(medOnlyLosses)) {
	   message = message + '\t' + 'medical-only claims field' + '\n';
	   FieldCheck = false
	}
	
	
	if (!FieldCheck) {
		alert('Mod Calculator Error\n\nFollowing fields are missing:\n\n' + message);
		return FieldCheck;
        }

/** Check to see all the reqired fields are number.
*/	
	
	if (isNotNumber(payroll) || (payroll.length > 2)) {
	   alert('Mod Calculator Error\n\nYou must enter 1 or 2 digit number for classifications field.');
	   FieldCheck = false;	
	   return FieldCheck;
	}
	if (isNotNumber(lostTimeLosses) || (lostTimeLosses.length > 2)) {
	   alert('Mod Calculator Error\n\nYou must enter 1 or 2 digit number for lost-time claims field.');
	   FieldCheck = false;
	   return FieldCheck;
	}
	if (isNotNumber(medOnlyLosses) || (medOnlyLosses.length > 2)) {
	   alert('Mod Calculator Error\n\nYou must enter 1 or 2 digit number for Actual medical-only claims field.');
	   FieldCheck = false;	
	   return FieldCheck;
	}


 	
	location = "/inquiries/ModCalculator?nopayroll="+payroll+"&lostTimeLosses="+lostTimeLosses+
			"&medOnlyLosses="+medOnlyLosses+"&source=setuppage";

}
/**
 * Used to validate the information on advance calculator (Payroll Screen)
 */
function AC_Validator(form)
{
 var fieldCheck = true;
 var message = '';
 var totItems = form.length;
 var currentScreen = form.current.value;
  
//  alert('the current screen is ' + currentScreen);
   
	if (currentScreen == 'payroll') {
	   var noOfPayroll = form.nopayroll.value;
	     for (var i=0; i < noOfPayroll; i++)  {	
	      
	        var className = 'form.class' + i + '.value';
	        var payrollName = 'form.payroll' + i + '.value';
		var classValue = eval(className);
		var payrollValue = eval(payrollName);


                  if (isblank(classValue) || isblank(payrollValue)) {
			message = 'You must enter every class code and payroll field on this form.';
			fieldCheck = false;
			break;
                  }

		  if (classValue.length != 4) {
			message = 'You must enter 4 digit number for class code.';
			fieldCheck = false;
			break;
                  }

		  if (isNotNumber(classValue) || isNotNumber(payrollValue)) {
			message = 'You must enter number for both class code and payroll.';
			fieldCheck = false;
			break;
                  }
             }
         }

/**
 * Following validation is for Loss screen(Tab).
 * All the fields must be entered, and must be number.
 * Aggregate total for lost-time and medical losses must be less than 5000.
 * "$5000 & over List Individually" must be 5000 and over and that applies on both Lost-Time and Medical-only losses.
 * 
 */

	
       if (currentScreen == 'loss') {
	   var lostTimeUnder5000 = form.L5000.value;
	   var medcialunder5000  = form.M5000.value;
		
/*	   if (isblank(lostTimeUnder5000) || isblank(medcialunder5000) ||
			isNotNumber(lostTimeUnder5000) || isNotNumber(medcialunder5000) ||
			(lostTimeUnder5000 >= 5000) || (medcialunder5000 >= 5000)) {
		message = 'You must enter "under $5000 for aggregate total" for lost-time and medical losses\n ' +
			  'and total must be less than $5000.';
	        fieldCheck = false;	       
	   }
*/

	   if (fieldCheck) {			   
       	   	var noOfLostTimeLosses = form.lostTimeLosses.value;
	   	var noOfMedOnlyLosses  = form.medOnlyLosses.value;
          		
		   for (var j=0; j < noOfLostTimeLosses; j++)  {
		      

	              var lostTime = 'form.LTover' + j + '.value';	 		
		      var lostTimeValue = eval(lostTime);	

		        if (isblank(lostTimeValue) || isNotNumber(lostTimeValue) || 
				isNotNumber(lostTimeValue) || (lostTimeValue < 5000))  {

			   message = 'You must enter $5000 and over for "$5000 & over List Individually" for Lost-Time Losses.';
			   fieldCheck = false;
			   break;
		        } //end of if statement
                   } // end of for

		
		    for (var k=0; k < noOfMedOnlyLosses; k++)  {
	
	      	   //   alert ('noOfLostTimeLosses ' + noOfLostTimeLosses);
		    //  alert ('screen name ' + currentScreen);

	              var medLosses = 'form.Mover' + k + '.value';	 		
		      var medValue  = eval(medLosses);	

		        if (isblank(medValue) || isNotNumber(medValue) || 
				isNotNumber(medValue) || (medValue < 5000))  {

			   message = 'You must enter $5000 and over for "$5000 & over List Individually" for Medical-only Losses.';
			   fieldCheck = false;
			   break;
		        } //end of if statement
                   } // end of for


             } // end of outer if (!fieldCheck)
		
	}  //if (currentScreen == 'loss')


/**
 * Following validation is for Results screen(Tab).
 * Mcpap Factor must be between .7 and 1.
 * 
 */

//	alert('the current screen is ' + currentScreen);
	if (currentScreen == 'results') {
		var mcpapFactor = valueOf(form.Mcpap_Factor.value);
		alert('mcpap ' + mcpapFactor);
		if ((mcpapFactor < .7) || (mcpapFactor > 1.00) ||
			isblank(mcpapFactor) || isNotNumber(mcpapFactor)) {
		     message = 'Mcpap Factor must be between .7 and 1';
		     fieldCheck = false;
                }
        }
    
	if (!fieldCheck) {
		alert('Mod Calculator Error\n\n' + message);
		return fieldCheck;
        }

 
	
  return (fieldCheck);
}
/**
 * Helper function and used to reset the form fields. (MCPAP and others)
 */
function resetValue(form) 
{
	var resetCheck = false;

	
    for (var i = 0; i < form.length; i++) {	
	if (form.elements[i].type == "text") {
	    if (!isblank(form.elements[i].value)) {
		form.elements[i].value = "";		
	     	resetCheck = false;
	    }	 
	}
     }

	return resetCheck;
}
/**
 * Used to validate the information on lost password (LP) screen.
 */
function LP_GetValidation()
{
        window.status=('Attempting to locate the lost password.')
        var LostPWvar;
        var SelectIndex; 
        var FieldCheck = true; 

        LostPWvar   = document.LostPWscreen.PWvar.value;        
	SelectIndex = document.LostPWscreen.srchtype.selectedIndex;


        if (LostPWvar == "")
        
        {
                alert('No Data has been entered!\n\nPlease enter your User Name or Account Number\n');
                window.status=('Missing or Invalid Data');
                FieldCheck = false;
        }       


        if (SelectIndex == "1")
        if ((LostPWvar.search(/[a-zA-Z']/)) != -1)
        {
            alert('ERROR\n\nYour MWCIA account number should contain only NUMBERS.\n\nPlease enter the MWCIA account number and try again\n');
            window.status=('Account number error');
            FieldCheck = false;
        }


        if (SelectIndex == "0")
        if ((LostPWvar.search(/[']/)) != -1)
        {       
                alert('Search String Error\n\The MWCIA User Name should not contain quotes(\'). Please remove it and try again.\n');
                window.status=('Missing or Invalid Data');
                FieldCheck = false;
        } 
        
        if (LostPWvar !== "" ) 
        if (LostPWvar.length < 4) 
        {
                alert('Search String ERROR\n\nPlease enter the ENTIRE User Name or Account Number.\n');
                window.status=('Please re-enter your information and try again');
                FieldCheck = false;
        }



        return FieldCheck;
}

/**
 * Used for object focus on lost password (LP) screen.
 */
function LP_setFocus()
{
        document.LostPWscreen.PWvar.focus();
        document.LostPWscreen.PWvar.select();
}

function isblank(s)
{
	for (var i=0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t'))
			return false;
	}
			return true;
}
/**
 * Used to validate the information on Ratemaking Report Request Form.
 */
function RMR_GetValidation(form)
{
 window.status=('Attempting to validate the information.');
 var FieldCheck = true; 

/* First load the form data into local variables. 
*/
 var cName 	= form.CustomerName.value;
 var cCompany 	= form.CustomerCompany.value;
 var cAddress	= form.CustomerAddress.value;
 var cCity	= form.CustomerCity.value;
 var cState	= form.CustomerState.value;
 var cZip	= form.CustomerZip.value;
 var cEmail	= form.CustomerEmail.value;
 var cPhone	= form.CustomerPhone.value;
 var mesg	= 'You have not provided the following required field(s):';
        
/* Now check to make sure all the requires fields are there.
*/

		if (isblank(cName)) {
		     mesg = mesg + "\n\tMissing name field";
		     FieldCheck= false;
		} 
		if (isblank(cCompany)) {
		     mesg = mesg + "\n\tMissing company field";
		     FieldCheck = false;
                }
		if (isblank(cAddress)) {
		     mesg = mesg + "\n\tMissing address field";
		     FieldCheck = false;
                }
		if (isblank(cCity)) {
		     mesg = mesg + "\n\tMissing city field";
		     FieldCheck = false;
                }
		if (isblank(cState)) {
		     mesg = mesg + "\n\tMissing state field";
		     FieldCheck = false;
                }
		if (isblank(cZip)) {
		     mesg = mesg + "\n\tMissing zip field";
		     FieldCheck = false;
                }
		if (isblank(cEmail)) {
		     mesg = mesg + "\n\tMissing email field";
		     FieldCheck = false;
                } else {		     
		     if (!checkEmailAddress(cEmail)) {
		        FieldCheck = false;
		        mesg = mesg + "\n\tInvalid Email Address: " + cEmail;
                     }
		}
		     		
		if (isblank(cPhone)) {
		     mesg = mesg + "\n\tMissing phone field";
		     FieldCheck = false;
                }
		
		if (!FieldCheck) 
		  alert(mesg);

		return FieldCheck;
}
function getRadioButtonVAlue(strFormName,strElementName)
{
	nRadioLength  = eval('document.'+strFormName+'.'+strElementName+'.length');
  	var strRadioValue = '';

	for(var nCurrent = 0; nCurrent < nRadioLength; nCurrent++)
  	{
    		if ( eval('document.'+strFormName+'.'+strElementName+'[nCurrent].checked') ) { 
			strRadioValue = eval('document.'+strFormName+'.'+strElementName+'[nCurrent].value'); 			
			break;
    		}	
      
  	}

	return strRadioValue;
}
/**
 * This function is used for MCPAP online. (Company.jsp)
 */
function DocumentLink1(url) { 
  var employerName = document.mcpapForm.txtName.value;
  var nameFound = true;
   if (employerName == "") {
	alert('MCPAP Application Error\n\nYou must enter the employer name for AFN lookup');
	nameFound = false;
   }

  if (nameFound) {	
  	url = url + '?EmpName=' + employerName;
  	var w;
        w = window.open(url,'','width=800,height=800,resizable=yes,scrollbars=yes,menubar=no'); 
	w.focus(); 
  }
} 
/**
 * This function is used to validate the MCPAP data online. (submit.jsp)
 */

function validate_And_submit(callfor,callfrom) {
 
	var validation_flag = true;
	var tabName = callfrom;

// commented out for testing purpose. 
         validation_flag = Validator(callfrom);

// if it is true then call the appropriate page(JSP) through the servlet.

	  if (validation_flag) {	
	     document.mcpapForm.method = "post";
	     document.mcpapForm.callfor.value  = callfor;
	     document.mcpapForm.callfrom.value = callfrom;
	     document.mcpapForm.action="/inquiries/McpapController";
	     document.mcpapForm.submit();
	     return true;       
	  }
	  
	
	return false;
}

/**
 * This function is used to validate the MCPAP data online. (submit.jsp)
 */

function Validator(tabName)
{
 var fieldCheck = true;
 var message =  '';
  
// Do the validation based on the the screen(tab).
// If the tab/screen name is "Employer Info" then we must validate the user up front. 

	if (tabName == 'company') {
	   var empName	= document.mcpapForm.txtName.value;
	   var cvgID   	= document.mcpapForm.txtAFN.value;
	   var address  = document.mcpapForm.txtAddress.value;
	   var city   	= document.mcpapForm.txtCity.value;
	   var state   	= document.mcpapForm.txtState.value;
	   var zip   	= document.mcpapForm.txtZip.value;
	
	   if ((isblank(cvgID) || isblank(address)) || (isblank(city) || isblank(state) || isblank(empName) ||
			isblank(zip))) {
	        message = 'You must enter all information on Employer Info screen.';
		fieldCheck = false;
           }	
	}

	if (tabName == "data") {
	
	    if (!getRadioValue1("mcpapForm","Acknowldge")) {
		message =  'Please tell us if the Application includes data for all commonly owned businesses.';
		fieldCheck = false;	
	    } else {

	
	    var noOfEntries = document.mcpapForm.moreCode.value;
	    var noOfLines   = 0; // used to tracke how many lines(code,wages paid and hours wokred) are filled by the user. 
				 // user must enter data in at least one row.

	      for (var i=0; i < noOfEntries; i++)  {	
	   
	         var fieldNamecode 	= 'document.mcpapForm.WCCode'	+ (i + 1) + '.value';
	         var fieldNamePaid 	= 'document.mcpapForm.Paid' 	+ (i + 1) + '.value';
	         var fieldNameHour 	= 'document.mcpapForm.HRWorked'	+ (i + 1) + '.value';

	         var fieldCodeValue 	= eval(fieldNamecode);
	         var fieldPaidValue 	= eval(fieldNamePaid);
	         var fieldHoursvalue	= eval(fieldNameHour);

// Users will not fill every single text box for MCPAP data. Once we check for code numbers, if it has been entered
// by user then we will check for the corresponding values(Wages Paid and Hours Worked). If code is not entered then 
// we wont run our validation even corresponding fields may have been entered.
//

	         if (!isblank(fieldCodeValue) || (!isblank(fieldPaidValue)) || (!isblank(fieldHoursvalue))) {

// Let check the code validation.

		      if ((fieldCodeValue.length != 4) || isNotNumber(fieldCodeValue)) {
		   	 message = 'You must enter a 4 digit number for class code.';
		    	 fieldCheck = false;
		    	 break;
                      }

		      if (isblank(fieldPaidValue) || isblank(fieldHoursvalue) || isblank(fieldCodeValue) ) {
		    	 message = 'You must enter the WC codes, wages paid and hours worked.';
		         fieldCheck = false;
		         break;
                      }
	         
	              if (isNotNumber(fieldPaidValue) || isNotNumber(fieldHoursvalue)) {
		    	 message = 'Wages paid and hours worked must be whole number(DO NOT INCLUDE THE DECIMAL POINTS,COMMAS,DOLLAR SIGNS).';
		    	 fieldCheck = false;
		    	 break;
                      }
			
		      if ((fieldPaidValue == 0) || (fieldHoursvalue == 0)) {
			 message = 'Wages paid and hours worked values cannot be Zero. Please enter the value again';
		    	 fieldCheck = false;
		    	 break;
		      }
			
			 noOfLines = noOfLines + 1;
		  }  // end of !isblank(fieldCodeValue)

              }	// end of for loop

		
		if (fieldCheck) {	
	    	var strButtonValue = getRadioButtonVAlue("mcpapForm","Acknowldge");
	      	  if (strButtonValue == 'N') {
		    message =  'Data must be submitted for all commonly owned businesses .';
		    fieldCheck = false;
	          }		    
	        }

             }

// User must enter data for at least one row. If that is not the case, user should not be allowed to go to other screen.
			if (noOfLines == 0 && fieldCheck ) {
			    message = 'You must enter data for at least one row otherwise your application will not be accepted.';
		    	    fieldCheck = false;		    	    
	 		}
          		
	 }  // end of (tabName == "data") 		

		
	if (tabName == 'submit') {
	   var contact		= document.mcpapForm.txtSign.value;
	   var phoneNo  	= document.mcpapForm.txtPhone.value;
	   var position 	= document.mcpapForm.txtPosition.value;
//	   var enteredDate   	= document.mcpapForm.txtCity.value;
	   var emailAddress  	= document.mcpapForm.txtEmail.value;
	
	   if ((isblank(contact) || isblank(phoneNo)) || (isblank(position) || isblank(emailAddress))) {
	        message =  'You must enter all information on Submit/Print screen.';
		fieldCheck = false;
           }
	
	   if (!checkEmailAddress(emailAddress) && (fieldCheck)) {
			message = '\n\nYour email address is not in the correct format.';
			fieldCheck = false;
	   }	
	}

	
	
	if (!fieldCheck) {
		alert('MCPAP Application Error\n\n' + message);
		return fieldCheck;
        }
  	return (fieldCheck);
}
function getRadioValue1(strFormName,strElementName)
{


   var fieldStatus = false;   

  nRadioLength  = eval('document.'+strFormName+'.'+strElementName+'.length');
  strRadioValue = '';
  

  for(var nCurrent = 0; nCurrent < nRadioLength; nCurrent++)
  {
    if ( eval('document.'+strFormName+'.'+strElementName+'[nCurrent].checked') ) { 
	strRadioValue = eval('document.'+strFormName+'.'+strElementName+'[nCurrent].value'); 
	fieldStatus = true;
	break;
    }
      
  }
   
	return fieldStatus;
   
}

/**
 * Used for validation on Ratesheet screen.
 */
function EmpRatesheetValidation(f)
{

var FieldCheck = false;
var i;

	for (i = 0; i < f.length;i++)
	{
		var e = f.elements[i];
		if (e.type == "radio")
		{
		    if (e.checked)
		    {
		    	FieldCheck = true;
		    	break;
		    }
		}
	}

		if (FieldCheck == false)
			    alert('You must select the desired ratesheet');
	return FieldCheck;
}

