//==============================================================================
/* GLOBAL VARIABLE DECLARATIONS HERE FOR COLORS*/
var GRAY			=	'#cccccc';	//Gray
var	PINK			=	'#f88080';	//Pinkish Red
var YELLOW			=	'#ffff00';	//Yellow
var WHITE			=	'#ffffff';	//White
var BLACK			=	'#000000';	//Black

var	badBgColor		=	'#f88080';	//Pinkish Red
var badFontColor	=	'#ffff00';	//Yellow
	
var goodBgColor		=	'#ffffff';	//White
var	goodFontColor	=	'#000000';	//Black

//Added Default value for EIN AND SSN for REALRemit -- Lakshmi M S
var DefaultEIN		=   'test99999'
var DefaultSSN		=   'test99999'

// checking for netscape
var IE
if (navigator.appName!='Netscape'){IE=true}

//==============================================================================
// Function Name:
//    formatAndValidate()
//
// Purpose:
//		Checks to see if the given form field object is valid depending on what type 
//		of value it is. Highlights an errorneous field if it is invalid in a Pinkish color
//		with yellow text
//
// Known Limitations:
//		You must use the 'return' feature in your eventhandler. Otherwise when a user
//		tabs to another field the cursor will move to the next field and the user
//		is allowed to continue on.
//
// Parameters:
//		in_obj		The form field object 
//		type		Type of field that is to be checked
//					Currently supported values are:
//						PHN		-	Phone number
//						Date	-	Date in the format MMDDYYYY
//						Alpha	-	Alphanumeric valuation check
//						SSN		-	Social Security Number
//						State	-	State Abbr code check
//						Zip		-	Postal codes 5 and 9 characters
//						Int		-	Postive Integers
//						Float	-	Float Point number to 2 decimal places
//						Money	-	Dollar format, 2 decimal place and commas 
//						EMail	-	Approves for valid e-mail addresses.
//						AlphaNS -	Alphanumeric valuation check, no spaces allowed.
//                      PlsMnsEq -  Plus, Minus, Equal valuation check
//						EIN     -   Employer Identification Number
//						FAX		-   Fax Number		
//						
//
// Returns:
//		true or false
//
// Errors/Exceptions:
//    None.
//
// Example:
//		<input type="text" name="state" onBlur=" return formatAndValidate(this, 'State');"/>
//
// 20 October 2000.  Teodoro Viteri <tviteri@ocwen.com>
//    Added type=='TaxID'
//
// 02/07/2001 Craig Newman cnewman@realtrans.com
// netscape crashes with the "style" object. i added a browser check before
// that object is called.
// 09/10/2003 Lakshmi M S <maralurl@ocwen.co.in>
// Added Validation for Employer Identification Number
// 23/12/2003 Lakshmi M S <maralurl@ocwen.co.in>
// Added Validation for Fax Number
//==============================================================================
function formatAndValidate(in_obj, type){
	var newval;
	
	if(type=='PHN'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidPhoneNumber(in_obj.value)){
				newval = FormatPhoneNumber(in_obj.value);
				if(IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor;
				  }
				in_obj.value = newval;
				return true;
			}
			else{
				alert('Please enter a valid phone number.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor; 
				}
				else {in_obj.value='';}				  
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 	
			  }
			return true;
		}
	}
			
	if(type=='FAX'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidPhoneNumber(in_obj.value)){
				newval = FormatPhoneNumber(in_obj.value);
				if(IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor;
				  }
				in_obj.value = newval;
				return true;
			}
			else{
				alert('Please enter a valid fax number.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor; 
				}
				else {in_obj.value='';}				  
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 	
			  }
			return true;
		}
	}
	
	if(type=='SSN'){
		if(!IsEmpty(in_obj.value)){
			if (in_obj.value == DefaultSSN)
			{
				if (IE){
					  in_obj.style.background = goodBgColor;
					  in_obj.style.color = goodFontColor; 		
					  }
				return true;
			}
			else{
				if(IsValidSocialSecurityNumberUS(in_obj.value)){
					newval = FormatSocialSecurityNumberUS(in_obj.value);
					if (IE){
					  in_obj.style.background = goodBgColor;
					  in_obj.style.color = goodFontColor; 		
					  }
					in_obj.value = newval;
					return true;
				}
				else{
					alert('Please enter a valid Social Security Number.');
					if (IE){
					  in_obj.style.background = badBgColor;
					  in_obj.style.color = badFontColor; 
					}
					else {in_obj.value='';}
					in_obj.focus();
					return false;
				}
		   }		
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 	
			  }
			return true;
		}
	}
	

	if(type=='TaxID'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidTaxIDNumberUS(in_obj.value)){
				newval = FormatTaxIDNumberUS(in_obj.value);
				if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				  }
				in_obj.value = newval;
				return true;
			}
			else{
				alert('Please enter a valid Tax ID Number.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor; 
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 	
			  }
			return true;
		}
	}	
	
	if(type=='SSNTaxID'){
		if(!IsEmpty(in_obj.value)){
		
			var number_in = in_obj.value;
			
		    // Strip out everything except digits '0' through '9'.
			number_in = StripInteger(number_in);
    
			// Test for correct length.
			if (9 != number_in.length) {
				alert('Please enter a valid Social Security or Tax ID Number.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor; 
			  }
			  else {in_obj.value='';}
				in_obj.focus();
				return false;
				}
			else {
				var strvalue = in_obj.value;
				if (strvalue.substr(2, 1) == '-') {
					formatAndValidate(in_obj,'TaxID');
				}
				else {
					formatAndValidate(in_obj,'SSN');
				}
			}
			}
		else {
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 	
			}
			return true;

		}
	}	

	
	if(type=='Alpha'){		
		if(!IsEmpty(in_obj.value)){
			if(hasNonAlphaNum(in_obj.value).length > 0){
			  if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				}
				
				//Changes made by Ananda Sreenivas
			    //Changed on 01/13/2005
			    //Added CheckInvalidChar Function to prevent entering special characters

				if (CheckInvalidChar(in_obj))
					return true;
				else
					return false;

			}
			else{
				alert('Invalid character used, No special characters please');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color =  badFontColor;			
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}	
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
	
	if(type=='AlphaNS'){		
		if(!IsEmpty(in_obj.value)){
			if(hasNonAlphaNumNS(in_obj.value).length > 0){
			  if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				}
				return true;
			}
			else{
				alert('Invalid character used. No special characters or spaces please.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color =  badFontColor;			
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}	
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
		
		if(type=='Date'){
		if(!IsEmpty( in_obj.value)){
			//if(Valid_Date( in_obj.value)){
			if(IsValidDate(in_obj.value)){	
				 in_obj.value = FormatDate(in_obj.value);	
				 if (IE){
				   in_obj.style.background = goodBgColor;
				   in_obj.style.color = goodFontColor; 		
				 }
				return true;
			}
			else{
				//AprilBuild - Anantha
				 alert('Please enter a valid Date (mm/dd/yyyy)');
				 if (IE){
				   in_obj.style.background =  badBgColor;
				   in_obj.style.color =  badFontColor;			
				 }
				 else {in_obj.value='';}
				 in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
	
	if(type=='State'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidState(in_obj.value)){
				in_obj.value = in_obj.value.toUpperCase();
				if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				}
				return true;
			}
			else{	
			  if (IE){	
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor;			
				  }
				  else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
			in_obj.value.toUpperCase();
			if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
	
	if(type=='Zip'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidPostalCodeUS(in_obj.value)){	
				//newval = FormatPostalCodeUS(in_obj.value); fixed 7/28/2000 by P. Rinehart prinehart@ocwen.com / per3@cornell.edu
				in_obj.value = FormatPostalCodeUS(in_obj.value);				
				if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				}
				return true;
			}
			else{			
				alert('The postal code you entered is not a Valid Postal Code.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor;			
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
	
	if(type=='Int'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidNumberFormat(in_obj.value, 'Int')){	
			  if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				}
				return true;
			}
			else{			
				alert('This is not a valid numeric integer value.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor;			
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
	
	if(type=='Float'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidNumberFormat(in_obj.value, 'Float')){	
				in_obj.value = FormatFloat(in_obj.value, 2);		
				if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				  }
				return true;
			}
			else{			
				alert('This is not a valid floating point number.');
				  if (IE){
				    in_obj.style.background = badBgColor;
				    in_obj.style.color = badFontColor;			
				  }
				  else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}

    if(type=='EIN'){
		if(!IsEmpty(in_obj.value)){			
			if(in_obj.value == DefaultEIN)
			{
				if (IE){
					  in_obj.style.background = goodBgColor;
					  in_obj.style.color = goodFontColor; 		
					  }
				return true;
			}
			else
			{
				if(IsValidEIN(in_obj.value))
				{	
					in_obj.value = FormatEIN(in_obj.value);		
					if (IE)
					{
					  in_obj.style.background = goodBgColor;
					  in_obj.style.color = goodFontColor;
					}	
					return true;
				}
				else
				{			
					alert('EIN must be 9 numeric characters.');
					if (IE)
					{
					  in_obj.style.background = badBgColor;
					  in_obj.style.color = badFontColor;			
					}
					else 
					{
					 in_obj.value='';
					}
					in_obj.focus();
					return false;
				}
			}
		}
		else
		{
		  if (IE)
		  {
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor;
			  in_obj.style.textAlign = "left";
		  }		
			return true;
		}
	}

	if(type=='Money'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidNumberFormat(in_obj.value, 'Money')){	
				in_obj.value = FormatCurrencyUS(in_obj.value);		
				if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor;
				  in_obj.style.textAlign = "right"; 
				}	
				return true;
			}
			else{			
				alert('This is not a valid dollar amount.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor;			
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor;
			  in_obj.style.textAlign = "right";
			}		
			return true;
		}
	}

	if(type=='EMail'){
		if(!IsEmpty(in_obj.value)){
			if(IsValidEmail(in_obj.value)){	
			  if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				}
				return true;
			}
			else{			
				alert('This is not a valid E-Mail address.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor;			
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
	
	if(type=='PlsMnsEq'){		
		if(!IsEmpty(in_obj.value)){
			if(hasPlsMnsEq(in_obj.value).length == 1){
			  if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				}
				return true;
			}
			else{
				alert('Invalid character used. Only plus, minus or equal sign please.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color =  badFontColor;			
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
	
	if(type=='SqFt'){
		if(!IsEmpty(in_obj.value)){
			if(isSqFt(in_obj.value)!=''){
				in_obj.value=isSqFt(in_obj.value);	
				if (IE){
				  in_obj.style.background = goodBgColor;
				  in_obj.style.color = goodFontColor; 		
				}
				return true;
			}
			else{			
				alert('The value you entered is not valid.');
				if (IE){
				  in_obj.style.background = badBgColor;
				  in_obj.style.color = badFontColor;			
				}
				else {in_obj.value='';}
				in_obj.focus();
				return false;
			}
		}
		else{
		  if (IE){
			  in_obj.style.background = goodBgColor;
			  in_obj.style.color = goodFontColor; 		
			}
			return true;
		}
	}
	
}
//===================================================================
// function name: formatAndValidateTime(objName, objAMPM, objHidden)
// Purpose: format and validate time
// Parameters: objName - input text box containing a string or integer 
//                       entered by a user
//             objAMPM - select containing AM or PM values
//             objHidden - hidden input box containing string repre-
//             senting the resulting time
// Returns: Boolean true is passed validation and saved values, false-
//             otherwise
// Example: <input name="time" onblur="formatAndValidateTime(this,am_pm,time_val);">
//          <select name="am_pm" onclick="formatAndValidateTime(time,this,time_val);">
//          <input type=hidden name="time_val" value="<*SOME_TAG*>" >
// Please note: the function needs to be called on both boxes: text and select

function formatAndValidateTime(objName, objAMPM, objHidden){
	if (!saveTime(objName, objAMPM, objHidden)) {
	  if (IE){
				objName.style.background = badBgColor;
				objName.style.color =  badFontColor;			
		}
		else {in_obj.value='';}
				objName.focus();
				objName.select();
				return false;
	   }
	else {
	  if (IE){
			objName.style.background = goodBgColor;
			objName.style.color = goodFontColor; 		
	 }
			return true;
	}   
}

////==============================================================================
// Function Name:
//    setBgColor()
//
// Purpose:
//		Mutator method used to set the background color for bad values. Should be used 
//	in an 'onLoad' eventhandler to set thes colors for the entire page	
//
// Parameters:
//		bgColor		The name of the color that is to be used
//
// Errors/Exceptions:
//    None.
//
// Example:
//		<body onLoad="setBgColor('gray');">
//
//==============================================================================

function setBgColor(bgColor){
	var bg	 = bgColor.toUpperCase();
	
	switch(bg) {
		case 'GRAY': 
			goodBgColor = GRAY;
			break;				
		case 'WHITE': 
			goodBgColor = WHITE;
			break;
		default:
			goodBgColor = WHITE;
			break;
	}
}



function formatAndValidateForCurrentDate(in_obj)
{
	if(formatAndValidate(in_obj,'Date') && !IsEmpty(in_obj.value))
	{
		d = new Date();
		currDate = (d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear();
		
		//Netscape cannot "Date.parse" a date formatted with dashes "-"; so remove them
		var newFormattedDate = in_obj.value
		var s
		for (s=1;s<=2;s++){
		    newFormattedDate = newFormattedDate.replace('-','/');
		}		
		
		if(Date.parse(newFormattedDate) >= Date.parse(currDate))
		{
			if (IE)
			{
				in_obj.style.background = goodBgColor;
				in_obj.style.color = goodFontColor; 	
			}
			return true;
		}
		else
		{
			in_obj.focus();
			alert('Due Date can not be less than the current Date.');
			if (IE)
			{
				in_obj.style.background =  badBgColor;
				in_obj.style.color =  badFontColor;			
			}
			else {in_obj.value='';}
			in_obj.focus();
			return false;
		}
	}
	else
	{
		return false;
	}
}
//Padmaja Has modified for 2373-0606, ORA-RMSI- Conformance with Ocwen Password Policy Date:07/28/2006
//====================================================================================================

function validatepassword(object,citiflag)
	{
	
		var newpassobj   
		var newpass      
		var CHARLENGTH   = 8
		//var validChars = "/[~\!\@\#\$\%\^\&\*]/"
		var InvalidChars = "/[\'\(\)\+\{\}\[\]\|\/\:\;\<\>\?\\\,\.]/"
		var charcheck    = false
		var b_numeric    = false
		var b_alpha      = false
		
		
		newpassobj = object
		newpass = newpassobj.value 
		//alert('citiflag: ' + citiflag);
		//return false;
		//Added by Venkobachar.T.G. for RFS 3168-0307 on 3/31/2009.
		if (citiflag == 1)//for citibroker portal.
		{
			if (newpass.length < 8 || newpass.length > 20 )
			{
				alert("The Password must have minimum of 8 characters and a maximum of 20.Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters")
				newpassobj.value = '';
				newpassobj.focus();
				return false;
			}
		
		}//End Venkobachar.T.G. 	
		else
		{
			if (newpass.length != CHARLENGTH)
			{
				alert("The Password should have exactly 8 characters.Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters")
				newpassobj.value = '';
				newpassobj.focus();
				return false;
			}
		}
//checking of all chars in password starts...			
		for (var i=0;i<=newpass.length;i++)
			{
				if (i > 0)
					{
						if ((newpass.charAt(i) == newpass.charAt(i-1)) && citiflag == 0 )
							{
							alert ("The password cannot contain two similar characters consecutively.For ex:Apple cannot be used as password as it has two p's simultaneously");
							newpassobj.value = '';
							newpassobj.focus();
							return false;
							}
					}
				if ((newpass.charAt(i)== "~") ||(newpass.charAt(i) == "!")||(newpass.charAt(i) == "@")||(newpass.charAt(i) == "#")||(newpass.charAt(i) == "$")||(newpass.charAt(i) == "%")||(newpass.charAt(i) == "^")||(newpass.charAt(i) == "*")||(newpass.charAt(i) == "&"))
								{
									charcheck = true ;
								}	
						
				for (var inv=0;inv < InvalidChars.length;inv++)
					{
						if (InvalidChars.charAt(inv) == newpass.charAt(i))
							{
						        alert("The Characters ' ( ) + { } [ ] | : ; < > ? \ , . are not allowed to use in password")
						        newpassobj.value='';
						        newpassobj.focus();
						        return false;
							}
						
					}	
					if (newpass.charCodeAt(i) == 32)
						{
							alert("Blank Spaces are not allowed in Password");
							newpassobj.value = '';
							newpassobj.focus();
							return false;
						}
				
					if ( newpass.charCodeAt(i) >= 48 &&  newpass.charCodeAt(i) <= 57 )
						{
							b_numeric = true;
						}

					if (( newpass.charCodeAt(i) >= 65 && newpass.charCodeAt(i)<=122))
						{
							b_alpha	= true;
						}	
					
			}
//end of checking of password chars			
	if(citiflag == 1)//Added by Venkobachar.T.G. for RFS 3168-0307 on 3/31/2009.
	{
		if  (b_alpha == false)
					{
				alert ('The Password must have minimum of 8 characters and a maximum of 20. Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters');
				newpassobj.value='';
				newpassobj.focus();
				return false;
			}
		
		if (b_numeric == false)
			{
				alert('The Password must have minimum of 8 characters and a maximum of 20. Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters');
				newpassobj.value = '';
				newpassobj.focus();
				return false;
			}
		if (charcheck == false)	
			{
				alert ("The Password must have minimum of 8 characters and a maximum of 20.Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters");
				newpassobj.value='';
				newpassobj.focus();
				return false;
			}
	}	//End Venkobachar.T.G. 
	else
	{
		if  (b_alpha == false)
					{
				alert ('The Password should have exactly 8 characters.Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters');
				newpassobj.value='';
				newpassobj.focus();
				return false;
			}
		
		if (b_numeric == false)
			{
				alert('The Password should have exactly 8 characters.Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters');
				newpassobj.value = '';
				newpassobj.focus();
				return false;
			}
		if (charcheck == false)	
			{
				alert ("The Password should have exactly 8 characters.Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters");
				newpassobj.value='';
				newpassobj.focus();
				return false;
			}
		
	}	
		return true;			
	}
	

//Venkobachar.T.G. Has added for 2901-0807 Date:03/31/2008
//====================================================================================================

function validateAdminpassword(object,minlen,maxlen)
	{
	
		var newpassobj   
		var newpass      
		var CHARLENGTH   = 8
		var MINCHARLENGTH   = minlen;
		var MAXCHARLENGTH   = maxlen;
		//var validChars = "/[~\!\@\#\$\%\^\&\*]/"
		var InvalidChars = "/[\'\(\)\+\{\}\[\]\|\/\:\;\<\>\?\\\,\.]/"
		var charcheck    = false
		var b_numeric    = false
		var b_alpha      = false
		
		
		newpassobj = object
		newpass = newpassobj.value 
		if (newpass.length <  MINCHARLENGTH ||  newpass.length >  MAXCHARLENGTH )
			{
				alert('The Password should have atleast ' +MINCHARLENGTH + ' and atmost ' +MAXCHARLENGTH+ ' characters.Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters')
				newpassobj.value = '';
				newpassobj.focus();
				return false;
			}
//checking of all chars in password starts...			
		for (var i=0;i<=newpass.length;i++)
			{
				if (i > 0)
					{
						if (newpass.charAt(i) == newpass.charAt(i-1))
							{
							alert ("The password cannot contain two similar characters consecutively.For ex:Apple cannot be used as password as it has two p's simultaneously");
							newpassobj.value = '';
							newpassobj.focus();
							return false;
							}
					}
				if ((newpass.charAt(i)== "~") ||(newpass.charAt(i) == "!")||(newpass.charAt(i) == "@")||(newpass.charAt(i) == "#")||(newpass.charAt(i) == "$")||(newpass.charAt(i) == "%")||(newpass.charAt(i) == "^")||(newpass.charAt(i) == "*")||(newpass.charAt(i) == "&"))
								{
									charcheck = true ;
								}	
						
				for (var inv=0;inv < InvalidChars.length;inv++)
					{
						if (InvalidChars.charAt(inv) == newpass.charAt(i))
							{
						        alert("The Characters ' ( ) + { } [ ] | : ; < > ? \ , . are not allowed to use in password")
						        newpassobj.value='';
						        newpassobj.focus();
						        return false;
							}
						
					}	
					if (newpass.charCodeAt(i) == 32)
						{
							alert("Blank Spaces are not allowed in Password");
							newpassobj.value = '';
							newpassobj.focus();
							return false;
						}
				
					if ( newpass.charCodeAt(i) >= 48 &&  newpass.charCodeAt(i) <= 57 )
						{
							b_numeric = true;
						}

					if (( newpass.charCodeAt(i) >= 65 && newpass.charCodeAt(i)<=122))
						{
							b_alpha	= true;
						}	
					
			}
//end of checking of password chars			
		if  (b_alpha == false)
					{
				alert ('The Password should have atleast '+ MINCHARLENGTH + ' and atmost '+MAXCHARLENGTH+' characters. Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters');
				newpassobj.value='';
				newpassobj.focus();
				return false;
			}
		
		if (b_numeric == false)
			{
				alert('The Password should have atleast '+MINCHARLENGTH+' and atmost '+MAXCHARLENGTH+' characters. Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters');
				newpassobj.value = '';
				newpassobj.focus();
				return false;
			}
		if (charcheck == false)	
			{
				alert ('The Password should have atleast ' +MINCHARLENGTH + ' and atmost ' +MAXCHARLENGTH+ ' characters. Should be combination of alphabets,numbers and any of these ~ ! @ # $ % ^ & * characters');
				newpassobj.value='';
				newpassobj.focus();
				return false;
			}
		return true;			
	}


//End Venkobachar.T.G.

	//Lavanya has modified for 2381-0606 Vendor Registration Enhancement; Date: 08/22/2006	
//************************************************************************************
function IsValidAlphabets(str)
{
	
	var strLength = str.length;
	
	for(var i=0; i<strLength; i++)
	{
	  var alphaa = str.charAt(i);
	  var hh = alphaa.charCodeAt(0);
	  //Only Alphabets(A-Z,a-z) and blank space.
	  if(!((hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh==32)))
	  return false;
	}
	return true;
}

function IsValidAlphabetsAndNumerics(str)
{
	
	var strLength = str.length;
	
	for(var i=0; i<strLength; i++)
	{
	  var alphaa = str.charAt(i);
	  var hh = alphaa.charCodeAt(0);
	  //Only Alphabets(A-Z,a-z), Numerics(0-9) and blank space.
	  if(!((hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh > 47 && hh<58) || (hh==32)))
	  return false;
	}
	return true;
}

function IsValidName(str)
{
	
	var strLength = str.length;
	
	for(var i=0; i<strLength; i++)
	{
	  var alphaa = str.charAt(i);
	  var hh = alphaa.charCodeAt(0);
	  //Only Alphabets(A-Z,a-z),dot and blank space.
	  if(!((hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh==46) || (hh==32)))
	  return false;
	}
	return true;
}

function formatAndValidateAnswer(challenge_id,in_obj)
{
	if(IsEmpty(in_obj.value))
	{
		alert("Please Enter Answer");
		if (IE)
		{		
			in_obj.style.background = goodBgColor;
			in_obj.style.color = goodFontColor; 		
		}
		in_obj.focus();
		return false;	
	}
	
	
	switch(challenge_id)
	{
		case "1":
		case "2":
		case "3":		
		case "11":
		case "12":
				
				if((in_obj.value).length <= 30)
				{
					
					if(IsValidAlphabets(in_obj.value))
					{	
						if(IE)
						{
							in_obj.style.background = goodBgColor;
							in_obj.style.color = goodFontColor; 		
						}
						return true;
					}
					else
					{			
						alert('Numerics and special characters not allowed.');
						
						if(IE)
						{
							in_obj.style.background = badBgColor;
							in_obj.style.color = badFontColor;			
						}
						else 
						{
							in_obj.value='';
						}
						in_obj.focus();
						return false;
					}
				}
				else
				{
					alert('Entered value length should not be greater than 30 characters.');
					
					if(IE)
					{
						in_obj.style.background = badBgColor;
						in_obj.style.color = badFontColor;			
					}
					else 
					{
						in_obj.value='';
					}
					in_obj.focus();
					return false;
				}
			
			break;
			
		case "4":			
			if(!formatAndValidate(in_obj,'Date'))
			{
				return false;
			}
			else
			{
				var DOB,s;
				DOB  = in_obj.value;				
				for (s=1;s<=2;s++)
				{
					DOB = DOB.replace('-','/');
				}
				
				var d,currDate;
				d = new Date();
				currDate = (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
				
				if(Date.parse(DOB) <= Date.parse(currDate))
				{
					if (IE)
					{
						in_obj.style.background = goodBgColor;
						in_obj.style.color = goodFontColor;	
					}
					return true;
				}
				else
				{
					in_obj.focus();
					alert('Date of Birth should not be a future date.');
					if (IE)
					{
						in_obj.style.background =  badBgColor;
						in_obj.style.color =  badFontColor;			
					}
					else 
					{
						in_obj.value='';
					}
					in_obj.focus();
					return false;
				}
			}
			break;
			
		case "5":
		case "6":
		case "9":
				if((in_obj.value).length <= 30)
				{
					if(IsValidAlphabetsAndNumerics(in_obj.value))
					{	
						if(IE)
						{
							in_obj.style.background = goodBgColor;
							in_obj.style.color = goodFontColor; 		
						}
						return true;
					}
					else
					{	
						alert('Invalid character used, No special characters please.');
						
						if(IE)
						{
							in_obj.style.background = badBgColor;
							in_obj.style.color = badFontColor;			
						}
						else 
						{
							in_obj.value='';
						}
						in_obj.focus();
						return false;
					}
				}
				else
				{
					alert('Entered value length should not be greater than 30 characters.');
					
					if(IE)
					{
						in_obj.style.background = badBgColor;
						in_obj.style.color = badFontColor;			
					}
					else 
					{
						in_obj.value='';
					}
					in_obj.focus();
					return false;
				}
			
			break;
		
		case "8":
				if((in_obj.value).length <= 30)
				{
					
					if(IsValidName(in_obj.value))
					{	
						if(IE)
						{
							in_obj.style.background = goodBgColor;
							in_obj.style.color = goodFontColor; 		
						}
						return true;
					}
					else
					{			
						alert('Please enter a valid Name.');
						
						if(IE)
						{
							in_obj.style.background = badBgColor;
							in_obj.style.color = badFontColor;			
						}
						else 
						{
							in_obj.value='';
						}
						in_obj.focus();
						return false;
					}
				}
				else
				{
					alert('Entered value length should not be greater than 30 characters.');
					
					if(IE)
					{
						in_obj.style.background = badBgColor;
						in_obj.style.color = badFontColor;			
					}
					else 
					{
						in_obj.value='';
					}
					in_obj.focus();
					return false;
				}
			
			break;
		
		case "10":			
				if((in_obj.value).length == 4)
				{
					if(IsPositiveInteger(in_obj.value))
					{	
						if(IE)
						{
							in_obj.style.background = goodBgColor;
							in_obj.style.color = goodFontColor; 		
						}
						return true;
					}
					else
					{	
						alert('Entered Value should be a 4 digit numeric.');
						
						if(IE)
						{
							in_obj.style.background = badBgColor;
							in_obj.style.color = badFontColor;			
						}
						else 
						{
							in_obj.value='';
						}
						in_obj.focus();
						return false;
					}
				}
				else
				{
					alert('Entered value should be a 4 digit numeric.');
					
					if(IE)
					{
						in_obj.style.background = badBgColor;
						in_obj.style.color = badFontColor;			
					}
					else 
					{
						in_obj.value='';
					}
					in_obj.focus();
					return false;
				}
			
			break;
			
		case "7":
				if((in_obj.value).length <= 50)
				{
					in_obj.style.background = goodBgColor;
					in_obj.style.color = goodFontColor; 		
					return true;
				}
				else
				{
					alert('Entered String length should not be greater than 50 characters.');
										
					if(IE)
					{
						in_obj.style.background = badBgColor;
						in_obj.style.color = badFontColor;			
					}
					else 
					{
						in_obj.value='';
					}
					in_obj.focus();
					return false;
				}
			
			break;
	}//End of switch statement
}

//***********************************************************************************