/*
 * Copyright (c) 1999, by SonicWALL, Inc.
 * 5400 Betsy Cross Road, Suite 206, Santa Clara, CA 95054, USA
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of SonicWALL, Inc. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with SonicWALL, Inc.
 */
 
 /******************************************************************
 ** enocdeTxt()
 *******************************************************************/
function encodeTxt(str) {
	var result = "";
	
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	
	return escape(result);
}
/***************************************************************
** pos() - object that represents the x and y offset
***************************************************************/
function pos(x, y)
{
	this.x = x;
	this.y = y;
}

/***************************************************************
** getPositionBelowObject() - given an HTML object, returns a position
**						      where a popup/div can be displayed
***************************************************************/
function getPositionBelowObject(displayBelowThisObject)
{
	var p = getPositionOnObject(displayBelowThisObject);
	
  	var x = displayBelowThisObject.offsetLeft;
  	var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
  	// deal with elements inside tables and such
  	var parent = displayBelowThisObject;
  	while (parent.offsetParent) {
    	parent = parent.offsetParent;
    	x += parent.offsetLeft;
    	y += parent.offsetTop ;
  	}
  	x += p.x;
  	y += p.y;
	
	return new pos(x,y);
}

/***************************************************************
** getPositionOnObject() - given an HTML object, returns a position
**						   where a popup/div can be displayed
***************************************************************/
function getPositionOnObject(displayBelowThisObject)
{
	var leftPos = window.screenLeft - document.body.scrollLeft;
	var topPos = window.screenTop - document.body.scrollTop;
	if (!(navigator.appName == 'Microsoft Internet Explorer')) {
		leftPos = window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
		topPos = window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset;
	}
	if (topPos < 0)
		topPos = 0;
	return new pos(leftPos, topPos);
}

/***************************************************************
** getPositionForFWUIWindow() - given an HTML object, returns a position
**						        where a popup/div can be displayed
***************************************************************/
function getPositionForFWUIWindow(displayBelowThisObject)
{
	var leftPos = window.screenLeft;
	var topPos = window.screenTop;
	if (!(navigator.appName == 'Microsoft Internet Explorer'))
	{
		leftPos = window.screenX + 4;
		var offset = (navigator.userAgent.indexOf("Firefox") != -1) ? 24 : 21;
		topPos = window.screenY + (window.outerHeight - (offset) - window.innerHeight) - window.pageYOffset;
	}
	if (topPos < 0)
		topPos = 0;
	
	return new pos(leftPos, topPos);
}

/***************************************************************
** replaceChars() - replaces all occurrences of inChar
**					in entryString with outChar
***************************************************************/
function replaceChars(formTextElement, inChar, outChar)
{
	var entryString = formTextElement.value;
	var temp = "" + entryString; // temporary holder

	while (temp.indexOf(inChar) >- 1) {
		pos = temp.indexOf(inChar);
		temp = "" + (temp.substring(0, pos) + outChar + 
				temp.substring((pos + inChar.length), temp.length));
	}
	formTextElement.value = temp;
}

function replaceString(strSearch, strLookup, strReplace)
{
	var str = "";
	var strChanged = strSearch;
	var bReturn = false;
	for (var i = 0; !bReturn;)
	{
		var index = strSearch.toLowerCase().indexOf(strLookup.toLowerCase(), i);
		if (index != -1)
		{
			str += strSearch.substring(i, index) + strReplace;
			i = index + strLookup.length;
		}
		else
		{
			str += strSearch.substring(i);
			bReturn = true;
		}
	}
	if (str.length > 0)
		strChanged = str;
	
	return strChanged;
}

/***************************************************************
** isBlank()
***************************************************************/
function isBlank(formTextElement, desc)
{
	testValue = formTextElement.value;
	if (testValue.length > 0) {
		while(testValue.substring(0,1) == " " && testValue.length-1>0)
			testValue=testValue.substring(1,testValue.length);
		// after loop need to check the very last one
		if (testValue.substring(0,1) ==" ")
			testValue = "";
	}
	if (testValue.length > 0) 
		return false;
	else {
		if (desc && desc.length > 0)
			alert("'"+desc+"' is blank.\nPlease fill a value in.");
		formTextElement.value = '';	// force a pure empty field
		try 
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return true;
	}
}

/***************************************************************
** isPos() - called internally by isPosInteger() and validIP()
**           assume the string passed is non-blank
***************************************************************/
function isPos(testValue)
{
	var inputStr = testValue.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (oneChar < "0" || oneChar > "9")
			return false;
	}
	return true
}

/***************************************************************
** isPosInteger()
***************************************************************/
function isPosInteger(formTextElement, desc)
{
	if (isBlank(formTextElement,desc))
		return false;
	if (isPos(formTextElement.value))
		return true;
	if (desc && desc.length > 0)
		alert("'" + desc + "' is not a positive integer.\nPlease fill a positive integer.");
	try
	{
		formTextElement.focus();
		formTextElement.select();
	}
	catch(er)
	{
	}
	return false
}

/***************************************************************
** inRange()
***************************************************************/
function inRange(formTextElement, lowValue, highValue, desc)
{
	if (isBlank(formTextElement,desc))
		return false;
	if (lowValue >=0 && highValue >= 0) {
		if (!isPosInteger(formTextElement,desc))
			return false;
	}
	testValue = formTextElement.value;
	inputStr = testValue.toString()
	num = parseInt(inputStr);
	if (num < lowValue || num > highValue) {
		if (desc && desc.length > 0)
			alert("'" + desc + "' is not in the valid range of [" + lowValue + ".." + highValue + "].\nPlease fill a number within this range.");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	return true
}

/***************************************************************
** invalidEmailAlert() - called by validEmail() to display alert
***************************************************************/
function invalidEmailAlert(formTextElement, desc)
{
	if (desc && desc.length > 0)
		alert("'" + desc + "' is not a valid email address.\nPlease provide a valid email address.");
	try
	{
		formTextElement.focus();
		formTextElement.select();
	}
	catch(er)
	{
	}
	return false;
}

/***************************************************************
** validEmail()
***************************************************************/
function validEmail(formTextElement, desc)
{
	// is it blank ?
	if (isBlank(formTextElement,desc))
		return false;

	testValue = formTextElement.value;
	email = testValue.toString()
	
	// does it contain any invalid characters ?
	invalidChars = " /:,;";
	for (i = 0; i < invalidChars.length; i++)
		if (email.indexOf(invalidChars.charAt(i),0) > -1)
			return invalidEmailAlert(formTextElement,desc);
	
	// there must be one @ symbol
	if ((atPos = email.indexOf("@",1)) == -1)
		return invalidEmailAlert(formTextElement,desc);

	// there cannot be any more @ symbol
	if (email.indexOf("@",atPos+1) != -1)
		return invalidEmailAlert(formTextElement,desc);
	
	// there must be at least one period after "@"
	if ((periodPos = email.indexOf(".",atPos)) == -1)
		return invalidEmailAlert(formTextElement,desc);

	// there must be atleast 2 characters after the "."
	if (periodPos+3 > email.length)
		return invalidEmailAlert(formTextElement,desc);
	return true;
}

/***************************************************************
** validEmailStringBlankAllowed()
** 	-- checks if an email address is valid or not, based on 
**	   the string, rather than the contents of a form text element;
**	   useful if a text element contains multiple email addresses
**	   formTextElement is still needed as a parameter to be able
**	   to focus the input field after displaying the error message
***************************************************************/
function validEmailStringBlankAllowed(formTextElement, email, desc)
{	 
	// is it blank ?
	if ((email == "") || (email == " "))
		return true;	//blank allowed
		
	// does it contain any invalid characters ?
	invalidChars = " /:,;";
	for (i = 0; i < invalidChars.length; i++)
		if (email.indexOf(invalidChars.charAt(i),0) > -1)
			return invalidEmailAlert(formTextElement,desc);
	
	// there must be one @ symbol
	if ((atPos = email.indexOf("@",1)) == -1)
		return invalidEmailAlert(formTextElement,desc);

	// there cannot be any more @ symbol
	if (email.indexOf("@",atPos+1) != -1)
		return invalidEmailAlert(formTextElement,desc);
	
	// there must be at least one period after "@"
	if ((periodPos = email.indexOf(".",atPos)) == -1)
		return invalidEmailAlert(formTextElement,desc);

	// there must be atleast 2 characters after the "."
	if (periodPos+3 > email.length)
		return invalidEmailAlert(formTextElement,desc);
	return true;
}
/***************************************************************
** validEmailBlankAllowed()
***************************************************************/
function validEmailBlankAllowed(formTextElement, desc)
{	 
	testValue = formTextElement.value;
	email = testValue.toString();
	return validEmailStringBlankAllowed(formTextElement, email, desc);
}

/***************************************************************
** validMultipleEmailAddressess()
**     	validates an email address textbox entry, based on a separator
**		and if blank is valid or not. Eg call is:-
**		validMultipleEmailAddressess(document.thisForm.textElement, ';', true, "Target email address");
***************************************************************/
function validMultipleEmailAddressess(formTextElement, separator, blankAllowed, desc)
{	 
	var email = formTextElement.value.toString();
	// is it blank ?
	if ((email == "") || (formTextElement.value == " ")) {
		if (blankAllowed)
			return true;	//blank allowed
		else
			return invalidEmailAlert(formTextElement,desc);
	}
	
	// separate into multiple email addresses based on the separator
	var searchIndex = 0;
	var pos = -1;
	while ((pos = email.indexOf(separator, searchIndex)) > -1) {
		// now check for each email address if it is valid or not
		emailAddress = email.substring(searchIndex, pos);
		if (!validEmailStringBlankAllowed(formTextElement, emailAddress, desc))
			return false;
		searchIndex = pos + 1;
	}
	// and then, check for the rest of the string
	emailAddress = email.substring(searchIndex, email.length);
	if (!validEmailStringBlankAllowed(formTextElement, emailAddress, desc))
		return false;
	return true;
}

/***************************************************************
** trimSpaces()
***************************************************************/
function trimSpaces(text)
{
	newText = "";
	// Leading spaces
	for (i = 0; i < text.length; i++)
	{
		if (text.charAt(i) == ' ')
			newText = text.substring(i + 1, text.length);
		else
			break;
	}
	if (newText.length != 0)
		text = newText;
	else if (i == text.length)
		text = '';
	
	// Trailing spaces
	for (i = text.length - 1; i > -1; i--)
	{
		if (text.charAt(i) == ' ')
			newText = text.substring(0, i);
		else
			break;
	}
	if (newText.length != 0)
		text = newText;
	
	return text;
}

/***************************************************************
** invalidIPAlert() - called by validIP() to display alert
***************************************************************/
function invalidIPAlert(formTextElement, desc)
{
	if (desc && desc.length > 0)
		alert("'" + desc + "' is not a valid IP address.\n\nPlease provide a valid IP address of the form:\n\n    [0-255].[0-255].[0-255].[0-255]");
	try
	{
		formTextElement.focus();
		formTextElement.select();
	}
	catch(er)
	{
	}
		
	return false;
}

/***************************************************************
** validIP()
**	an IP is basically n1.n2.n3.n4, where each n is between 0
**  and 255. a blank field can be interpreted as a valid IP
**  if blankIsValid is set to true - this can be useful when
**  the user can leave an IP field empty (such as DNS Server.)
***************************************************************/
function validIP(formTextElement, desc, blankIsValid)
{
	// if blankIsValid, then blank field is a valid IP field (such as in DNS)
	if (blankIsValid && blankIsValid==true && isBlank(formTextElement))
		return true;
		
	// is it blank ?
	if (isBlank(formTextElement,desc))
		return false;

	var testValue = formTextElement.value;
	// should have 3 and only 3 '.' characters
	var myIntArray = testValue.split(".");
	if (myIntArray.length !=4)
		return invalidIPAlert(formTextElement,desc);
	// each element of the array should be an integer of the range 0 and 255
	for (var i = 0; i < 4; i++) {
		if (myIntArray[i].length == 0 || !isPos(myIntArray[i]))
			return invalidIPAlert(formTextElement,desc);
		var inputStr = myIntArray[i].toString();
		var num = parseInt(inputStr);
		if (num < 0 || num > 255)
			return invalidIPAlert(formTextElement,desc);
	}
	return true;
}

/***************************************************************
** invalidIPNameAlert() - called by validIPName() to display alert
***************************************************************/
function invalidIPNameAlert(formTextElement, desc)
{
	if (desc && desc.length > 0)
		alert("The '" + desc + "' you entered is not valid.\nPlease provide a valid IP Address or Domain Name.");
	try
	{
		formTextElement.focus();
		formTextElement.select();
	}
	catch(er)
	{
	}

	return false;
}

/***************************************************************
** validIPName(): returns true, if the address is fine 
**                (eg: www.california.com is valid,
**                     ww@adkf.akf.com is invalid)
**                algorithm: checks for spaces, tabs, @ etc. in
**                           the string, returns false if it finds
**                           any such character
**  a blank field can be interpreted as a valid IP Name
**  if blankIsValid is set to true - this can be useful when
**  the user can leave an IP field empty (such as Syslog Server.)
***************************************************************/
function validIPName(formTextElement, desc, blankIsValid)
{
	// if blankIsValid, then blank field is a valid IP field (such as in DNS)
	if (blankIsValid && blankIsValid==true && isBlank(formTextElement))
		return true;

	// is it blank ?
	if (isBlank(formTextElement,desc))
		return false;
		
	testValue = formTextElement.value;
	ipName = testValue.toString()
	
	invalidChars = " /,~$#!&*()+=;@";
	for (i = 0; i < invalidChars.length; i++)
		if (ipName.indexOf(invalidChars.charAt(i),0) > -1)
			return invalidIPNameAlert(formTextElement,desc);
	return true;
}

/***************************************************************
** validIPVariable(): returns true, if the address is fine 
**                (eg: LAN_IP)
***************************************************************/
function validIPVariable(formTextElement)
{
	// is it blank ?
	if (isBlank(formTextElement,""))
		return false;
		
	testValue = formTextElement.value;
	ipName = testValue.toString()
	
	if ((ipName == 'LAN_IP') || (ipName == 'WAN_IP'))
        	return true;
        	
        // Masked variable should have 1, 2, or 3 '.' characters
        var octetArray = testValue.split(".");
	if ((octetArray.length < 2) || (octetArray > 4))
		return false;
	// element 0 should be a valid variable name
	if ((octetArray[0] != 'LAN_IP') && (octetArray[0] != 'WAN_IP'))
		return false;
	// All other elements should be an integer of the range 0 and 255
	for (var i = 1; i < octetArray.length; i++)
	{
		if (!isPos(octetArray[i]))
			return false;
	}
        return true;
}
      
/***************************************************************
** validIPorVariable(): returns true, if the address is fine 
**                (eg: xxx.xxx.xxx.xxx or LAN_IP)
***************************************************************/
function validIPorVariable(formTextElement, desc, blankIsValid)
{
	// if blankIsValid, then blank field is a valid IP field (such as in DNS)
	if (blankIsValid && blankIsValid==true && isBlank(formTextElement))
		return true;
	var addressIsFine = validIP(formTextElement, "", false);
	if (!addressIsFine)
		addressIsFine = validIPVariable(formTextElement);
	if (!addressIsFine)
		invalidIPNameAlert(formTextElement,desc);
	return addressIsFine;
}
  
/***************************************************************
** validIPAddress(): returns true, if the address is either a
**                   valid number notation ip_address or a
**                   named ip_address
**  a blank field can be interpreted as a valid IP Name
**  if blankIsValid is set to true - this can be useful when
**  the user can leave an IP field empty (such as Syslog Server.)
***************************************************************/
function validIPAddress(formTextElement, desc, blankIsValid)
{
	// if blankIsValid, then blank field is a valid IP field (such as in DNS)
	if (blankIsValid && blankIsValid==true && isBlank(formTextElement))
		return true;
	var addressIsFine = validIPName(formTextElement, "", false);
	if (!addressIsFine)
		addressIsFine = validIP(formTextElement, "", false);
	if (!addressIsFine)
		addressIsFine = validIPVariable(formTextElement);
	if (!addressIsFine)
		invalidIPNameAlert(formTextElement,desc);
	return addressIsFine;
}

/***************************************************************
** invalidDateAlert() - called by isValidDate() to display alert
***************************************************************/
function invalidDateAlert(formElementDay, desc)
{
	if (desc && desc.length > 0)
		alert("'" + desc + "' is not a valid day of the month.\n\nPlease select another day");
	try
	{
		formElementDay.focus();
	}
	catch(er)
	{
	}
		
	return false;
}


/***************************************************************
** validIPAddressArray() - validates multiple IP address values separated by assuming it is not blank;
***************************************************************/
function validIPAddressArray(formTextElementValue,desc)
{
  var array = formTextElementValue.split(";");
  for(x in array)
  {
	// should have 3 and only 3 '.' characters
	var myIntArray = array[x].split(".");
	if (myIntArray.length !=4)
	{
	   alert("'" + desc + "' is not a valid IP address array.\n\nPlease provide a valid IP address of the form:\n\n    [0-255].[0-255].[0-255].[0-255]\n\n Multiple values can be entered separated by ;");
	   return false;
	}
	// each element of the array should be an integer of the range 0 and 255
	for (var i = 0; i < 4; i++) 
	{
	 if (myIntArray[i].length == 0 || !isPos(myIntArray[i]))
	 {
	   alert("'" + desc + "' is not a valid IP address array.\n\nPlease provide a valid IP address of the form:\n\n    [0-255].[0-255].[0-255].[0-255]\n\n Multiple values can be entered separated by ;");
	   return false;
	 }
	 var inputStr = myIntArray[i].toString();
	 var num = parseInt(inputStr);
	 if (num < 0 || num > 255)
	 {
	   alert("'" + desc + "' is not a valid IP address array.\n\nPlease provide a valid IP address of the form:\n\n    [0-255].[0-255].[0-255].[0-255]\n\n Multiple values can be entered separated by ;");
	   return false;
	 }
	}

   }
   return true;
}

/***************************************************************
** isValidDate() : returns true if date is valid
**		parameters: month (1..12) day (1..31) year (nnnn), desc
***************************************************************/
function isValidDate(month, day, year, formElementDay, desc)
{
	if (month < 1 || month > 12 || day < 1 || day > 31 || year < 0)
		return invalidDateAlert(formElementDay,desc);	// should never come here, since UI takes care of it
	if (day < 29)	// every month has atleast 28 days
		return true;
	if (day > 29 && month==2)	// feb can have at the most 29 days
		return invalidDateAlert(formElementDay,desc);
	if (day==31 && (month==4  || month==6 || month==9 || month==11))	// these months can have at the most 30 days
		return invalidDateAlert(formElementDay,desc);
	// now, check for leap year
	if (day==29 && month==2) {
		// return false if this is not a leap year
		if (year%4==0) {
			if (year%100==0) {
				if (year%400==0)
					return true;
				return invalidDateAlert(formElementDay,desc);
			}
			return true;
		}
		return invalidDateAlert(formElementDay,desc);
	}
	return true;
}

/***************************************************************
** validURL()
**	rudimentary: look for spaces and semicolons basically!
**				 we will make it more sophisticated later
***************************************************************/
function validURL(formTextElement, desc, blankIsValid)
{
	// if blankIsValid, then blank field is a valid IP field (such as in DNS)
	if (blankIsValid && blankIsValid==true && isBlank(formTextElement))
		return true;
		
	// is it blank ?
	if (isBlank(formTextElement,desc))
		return false;

	var testValue = formTextElement.value;
	var url = testValue.toString()
	
	// does it contain any invalid characters ?
	var invalidChars = " ;";
	for (var i = 0; i < invalidChars.length; i++) {
		if (url.indexOf(invalidChars.charAt(i),0) > -1) {
			if (desc && desc.length > 0)
				alert("'" + desc + "' is not a valid URL.\n\nPlease enter a valid URL.");
			try
			{
				formTextElement.focus();
				formTextElement.select();
			}
			catch(er)
			{
			}
			return false;
		}
	}

	return true;
}

/***************************************************************
** validLength()
**	  : looks for minimum length specified
**				 
***************************************************************/
function validLength(formTextElement,desc,length)
{
	var ilength=formTextElement.value.length;
	
	if(ilength<length){
		if(desc && desc.length > 0)
		   alert("'" + desc + "' must contain at least'"+length+"' characters.");
		 try
		 {
			 formTextElement.focus();
			 formTextElement.select();
		 }
		 catch(er)
		 {
		 }
		 return false;
		}

		return true;
}


/***************************************************************
** validString()
**	  : looks whether String entered is IPAddress Or IPName
**				 
***************************************************************/
function validString(formTextElement,desc,IPVal)
{
	
	   for(var i=0;i<formTextElement.value.length;i++)
	   {
	     	if (IPVal.indexOf(formTextElement.value.charAt(i)) == -1)
		{
			if(desc && desc.length > 0)
			{
				alert("'"+desc+"'must contain hexcharacters Only");
				try
				{
					formTextElement.focus();
					formTextElement.select();
				}
				catch(er)
				{
				}
				return false;
			}

		   return false;
		}
	    }
		
	
	  return true;
}

/***************************************************************
** validHexNumber() - cannot start with a 0
***************************************************************/
function validHexNumber(formTextElement, minLen, maxLen, desc)
{
	if (isBlank(formTextElement,desc))
		return false;
	var valString = formTextElement.value;
	if (valString.length < minLen) {
		if (desc && desc.length > 0)
			alert('"'+desc+"' should have at least " + minLen + " digits.");
			try
			{
				formTextElement.focus();
				formTextElement.select();
			}
			catch(er)
			{
			}
			return false;
	}
	if (valString.length > maxLen) {
		if (desc && desc.length > 0)
			alert('"'+desc+"' should have maximum " + maxLen + " digits.");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	var inputStr = formTextElement.value.toString();
	var firstChar = inputStr.charAt(0);
	if (firstChar == "0") {
		if (desc && desc.length > 0)
			alert('"'+desc+"' cannot start with a 0.");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if ((oneChar >= "0" && oneChar <= "9") ||
			(oneChar >= "a" && oneChar <= "f") ||
			(oneChar >= "A" && oneChar <= "F")) ;
		else {
			if (desc && desc.length > 0)
				alert('"'+desc+"' is not a valid hexadecimal number.");
			try
			{ 
				formTextElement.focus();
				formTextElement.select();
			}
			catch(er)
			{
			}
			return false;
		}
	}
	return true;
}

/***************************************************************
** validHexNumberZeroOk() - can start with 0
***************************************************************/
function validHexNumberZeroOk(formTextElement, minLen, maxLen, desc)
{
	if (isBlank(formTextElement,desc))
		return false;
	var valString = formTextElement.value;
	if (valString.length < minLen) {
		if (desc && desc.length > 0)
			alert('"'+desc+"' should have at least " + minLen + " digits.");
			try
			{
				formTextElement.focus();
				formTextElement.select();
			}
			catch(er)
			{
			}
			return false;
	}
	if (valString.length > maxLen) {
		if (desc && desc.length > 0)
			alert('"'+desc+"' should have maximum " + maxLen + " digits.");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	var inputStr = formTextElement.value.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if ((oneChar >= "0" && oneChar <= "9") ||
			(oneChar >= "a" && oneChar <= "f") ||
			(oneChar >= "A" && oneChar <= "F")) ;
		else {
			if (desc && desc.length > 0)
				alert('"'+desc+"' is not a valid hexadecimal number.");
			try
			{ 
				formTextElement.focus();
				formTextElement.select();
			}
			catch(er)
			{
			}
			return false;
		}
	}
	return true;
}

/***************************************************************
** validAlphaNumeric()
***************************************************************/
function validAlphaNumeric(formTextElement, minLen, maxLen, desc)
{
	if (isBlank(formTextElement,desc))
		return false;
	var valString = formTextElement.value;
	if (valString.length < minLen) {
		//if (desc && desc.length > 0)
		//	alert('"'+desc+"' should have at least " + minLen + " characters in length.");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	if (valString.length > maxLen) {
		//if (desc && desc.length > 0)
		//	alert('"'+desc+"' should have maximum " + maxLen + " characters in length.");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}

	var inputStr = formTextElement.value.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if ((oneChar >= "0" && oneChar <= "9") ||
			(oneChar >= "a" && oneChar <= "z") ||
			(oneChar >= "A" && oneChar <= "Z")) ;
		else {
			//if (desc && desc.length > 0)
			//	alert('"'+desc+"' is not valid. Only alphanumeric input is allowed.");
			try
			{ 
				formTextElement.focus();
				formTextElement.select();
			}
			catch(er)
			{
			}
			return false;
		}
	}
	return true;
}

/***************************************************************
** validAlphaNumericString()
***************************************************************/
function validAlphaNumericString(valString, minLen, maxLen, desc)
{
	if (valString.length < minLen) {
		if (desc && desc.length > 0)
			alert('"'+desc+"' (" + valString + ") should have at least " + minLen + " characters.");
			return false;
	}
	if (valString.length > maxLen) {
		if (desc && desc.length > 0)
			alert('"'+desc+"' should have maximum " + maxLen + " characters.");
		return false;
	}

	for (var i = 0; i < valString.length; i++) {
		var oneChar = valString.charAt(i)
		if ((oneChar >= "0" && oneChar <= "9") ||
			(oneChar >= "a" && oneChar <= "z") ||
			(oneChar >= "A" && oneChar <= "Z")) ;
		else {
			if (desc && desc.length > 0)
				alert('"'+desc+"' (" + valString + ") is not valid. Only alphanumeric input is allowed."); 
			return false;
		}
	}
	return true;
}

/***************************************************************
** checkForInvalidCharacter()
**	  : checks if the given character exists in the given text element
**      if so, we alert the user
***************************************************************/
function checkForInvalidCharacter(formTextElement, desc, testChar)
{
	if (formTextElement.value.indexOf(testChar) != -1) {
		alert(desc);
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	return true;
}

/***************************************************************
** validDecimalNumber()
**	  : checks if the number in the form's element is a valid decimal
**	    number and constructs it(if needed) in the form xxx.yyy restricting
**		number of digits after decimal dot as specified.
**	  : checks if the number is less than the minimum value specified.
**
***************************************************************/
function validDecimalNumber(formTextElement, desc, maxDecimalDigits, minValue)
{
	if(isBlank(formTextElement, desc))
		return false;
	
	var testValue = formTextElement.value.toString();
	var integerNumPart = "";
	var valBeforeDecimal;
	
	var decimalPos = testValue.indexOf(".");
	if(decimalPos != -1)
	{
		// we have a decimal dot and some value before it
		if(decimalPos != 0)
			integerNumPart = testValue.substring(0, decimalPos);
	}
	// we just have only the integral part as the inputted number
	else
		integerNumPart = testValue;
	
	// check if the value before the decimal dot is valid
	while(integerNumPart.length > 0 && integerNumPart.substring(0, 1) == " " && integerNumPart.length-1 > 0)
		integerNumPart = integerNumPart.substring(1, integerNumPart.length);
	
	// we either have a blank value or no value before the decimal dot
	if(integerNumPart.substring(0, 1) == " " || decimalPos == 0)
		valBeforeDecimal = "";
	else
	{
		// we have some value before the decimal dot
		if(decimalPos > 0)
			valBeforeDecimal = testValue.substring(0, decimalPos);
		// input number does not contain a decimal part
		else
			valBeforeDecimal = testValue;
		
		// check if the value inputted before the decimal dot is valid positive number
		var ignoreLeadingSpace = true;
		var valWithNoLeadingSpace = "";
		for(var i = 0; i < valBeforeDecimal.length; i++)
		{
			var oneChar = valBeforeDecimal.charAt(i);
			if(oneChar == " " && ignoreLeadingSpace == true)
				continue;
			
			if(oneChar < "0" || oneChar > "9")
			{
				alert("'" + desc + "' is not a valid positive number.\nPlease fill a value in.");
				try
				{
					formTextElement.focus();
					formTextElement.select();
				}
				catch(er)
				{
				}
				return false;
			}
			else
			{
				valWithNoLeadingSpace += oneChar;
				ignoreLeadingSpace = false;
			}
		}
		
		if(valWithNoLeadingSpace.length > 0)
			valBeforeDecimal = valWithNoLeadingSpace;
	}
	
	// check if the value entered after the decimal dot is valid and does not exceed 'maxDecimalDigits'
	// number of digits
	var valAfterDecimal = "";
	if(decimalPos != -1)
	{
		// we have some value after the decimal dot
		if(!(decimalPos == (testValue.length -1)))
		{
			var decimalPart = testValue.substring(decimalPos+1);
			
			// check if value is blank
			while(decimalPart.substring(0,1) == " " && decimalPart.length-1 > 0)
				decimalPart = decimalPart.substring(1,decimalPart.length);
				
			// we have some value after the decimal dot
			if(!(decimalPart.substring(0,1) == " "))
			{
				valAfterDecimal = testValue.substring(decimalPos+1);
				for(var i = 0; i < valAfterDecimal.length; i++)
				{
					var oneChar = valAfterDecimal.charAt(i)
					if(oneChar < "0" || oneChar > "9")
					{
						alert("'" + desc + "' is not a valid positive number.\nPlease fill a value in.");
						try
						{
							formTextElement.focus();
							formTextElement.select();
						}
						catch(er)
						{
						}
						return false;
					}
				}
				
				// check for number of digits after decimal dot 
				if(valAfterDecimal.length > maxDecimalDigits)
				{
					if(desc && desc.length > 0)
						alert("'" + desc + "' can contain at most '"+maxDecimalDigits+"' digits after the decimal dot.");
					try
					{
						formTextElement.focus();
						formTextElement.select();
					}
					catch(er)
					{
					}
					return false;
				}
				// pad zeroes to have 'maxDecimalDigits' number of digits after decimal dot
				else if(valAfterDecimal.length != maxDecimalDigits)
				{
					var len = valAfterDecimal.length;
					for(var i = 0; i < maxDecimalDigits - len; i++)
						valAfterDecimal += "0";
				}
			}
		}
	}
	
	// disallow zero value
	/*if(valBeforeDecimal == 0 && valAfterDecimal == 0)
	{
		alert("'" + desc + "' is invalid. Please input a value greater than 0.000");
		formTextElement.focus();
		formTextElement.select();
		return false;
	}
	else*/ if(valBeforeDecimal.length == 0 && valAfterDecimal.length != 0)
		valBeforeDecimal = "0";
	else if(valBeforeDecimal.length != 0 && valAfterDecimal.length == 0)
	{
		for(var i = 0; i < maxDecimalDigits; i++)
			valAfterDecimal += "0";
	}
	
	var finalValue = valBeforeDecimal + "." + valAfterDecimal;
	if(parseFloat(finalValue) < parseFloat(minValue))
	{
		alert("'" + desc + "' must be at least " + minValue + "Kbps.");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	formTextElement.value = finalValue;
	
	return true;
}



/************************************************************************************
**function validateDate(fieldName, dateStr)
**
** Checks if the date is of the form mm/dd/yyyy
************************************************************************************/ 
function validateDate(fieldName, dateStr)
{
	if ((dateStr == "null") || (dateStr == ""))
	{
		alert(fieldName + ": No date provided. \nPlease provide a valid date of the form mm/dd/yyyy");
		return false;
	}

	if (dateStr.length != 10)
	{
		alert(fieldName + ": Wrong Date Format. \nPlease provide a valid date of the form mm/dd/yyyy");
		return false;
	}

	var index = dateStr.indexOf("/");
	if (index == -1)
	{
		alert(fieldName + ": Wrong Date Format. \nPlease provide a valid date of the form mm/dd/yyyy");
		return false;
	}

	var month = dateStr.substring(0, index);
	if ((month.length != 2) || (month <= 0) || (month > 12)) 
	{
		alert(fieldName + ": Wrong month value in the date. \nPlease provide a valid date of the form mm/dd/yyyy");
		return false;
	}

	dateStr = dateStr.substring(index+1, dateStr.length);
	index = dateStr.indexOf("/");
	if (index == -1)
	{
		alert(fieldName + ": Wrong Date Format. \nPlease provide a valid date of the form mm/dd/yyyy");
		return false;
	}
	var day = dateStr.substring(0, index);
	if ((day.length != 2) || (day <= 0) || (day > 31)) 
	{
		alert(fieldName + ": Wrong day value in the date. \nPlease provide a valid date of the form mm/dd/yyyy");
		return false;
	}
	
	var year = dateStr.substring(index+1, dateStr.length);
	if(isNaN(year))
	{
		alert(fieldName + ": Wrong year value in the date. \nPlease provide a valid date of the form mm/dd/yyyy");
		return false;
	}
	// all years, previous and after previous are valid
	var prevYear = (new Date()).getYear() - 1;
	if(year < prevYear)
	{
		alert(fieldName + ": Wrong year value in the date. \nThe year value should be newer than " + (prevYear-1));
		return false;
	}

	return true;
}

/************************************************************************************
** validateTime(formTimeElement, desc)
**		:checks if the time is of the form hr:min:sec
************************************************************************************/
function validateTime(formTimeElement, desc)
{
	if(isBlank(formTimeElement, desc))
		return false;
	
	var timeStr = formTimeElement.value;
	if(timeStr.length != 8)
	{
		alert(desc + ": Wrong Time Format. \nPlease provide a valid time of the form:\n        [0-23]:[0-59]:[0-59]");
		try
		{
			formTimeElement.focus();
			formTimeElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	var index = timeStr.indexOf(":");
	if(index == -1)
	{
		alert(desc + ": Wrong Time Format. \nPlease provide a valid time of the form:\n        [0-23]:[0-59]:[0-59]");
		try
		{
			formTimeElement.focus();
			formTimeElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	var hour = timeStr.substring(0, index);
	if(hour.length != 2 || hour < 0 || hour > 23 || isNaN(hour-0))
	{
		alert(desc + ": Wrong hour value in the time. \nPlease provide a valid time of the form:\n        [0-23]:[0-59]:[0-59]");
		try
		{
			formTimeElement.focus();
			formTimeElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	timeStr = timeStr.substring(index+1, timeStr.length);
	index = timeStr.indexOf(":");
	if(index == -1)
	{
		alert(desc + ": Wrong Time Format. \nPlease provide a valid time of the form:\n        [0-23]:[0-59]:[0-59]");
		try
		{
			formTimeElement.focus();
			formTimeElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	var minute = timeStr.substring(0, index);
	if(minute.length != 2 || minute < 0 || minute > 59 || isNaN(minute-0))
	{
		alert(desc + ": Wrong minute value in the time. \nPlease provide a valid time of the form:\n        [0-23]:[0-59]:[0-59]");
		try
		{
			formTimeElement.focus();
			formTimeElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	var second = timeStr.substring(index+1, timeStr.length);
	if(second.length != 2 || second < 0 || second > 59 || isNaN(second-0))
	{
		alert(desc + ": Wrong second value in the time. \nPlease provide a valid time of the form:\n        [0-23]:[0-59]:[0-59]");
		try
		{
			formTimeElement.focus();
			formTimeElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	return true;
}

/*********************************************************************************
** escapeColonsInString()
** Escapes all occurence of ":" in the string with "_COLON_" before sending it
** to the backend for processing.
*********************************************************************************/
function escapeColonsInString(text)
{
	var escapedText = "";
	for (var i = 0; i < text.length; i++)
	{
		if (text.charAt(i) == ':')
			escapedText += "_COLON_";
		else
			escapedText += text.charAt(i);
	}
	return escapedText;
}

/**********************************************************************************
** validateEthernetAddressWithColon()
** validateEthernetAddressWithColon : 00:40:ab:12:34:56
** Ethernet address should contain only 12 hexadecimal charaters separated by colon
***********************************************************************************/
function validateEthernetAddressWithColon(formTextElement, desc)
{
	var text = formTextElement.value;
	if (isBlank(formTextElement, desc))
		return false;
	
	var plainText = "";
	var count = 0;
	var subCharCount = 0;
	var invalidAlert = false;
	
	for (var i = 0; i < text.length; i++)
	{
		if (text.charAt(i) == ':')
		{
			if (subCharCount == 2)
			{
				count += 1;
				subCharCount = 0;
			}
			else
				invalidAlert = true;
		}
		else
		{
			plainText += text.charAt(i);
			subCharCount += 1;
		}
	}
	
	if ((count == 5) && (plainText.length == 12) && !invalidAlert)
	{
	    var inputStr = plainText.toString();
		for (var i = 0; i < inputStr.length; i++)
		{
			var oneChar = inputStr.charAt(i)
			if ((oneChar >= "0" && oneChar <= "9") ||
				(oneChar >= "a" && oneChar <= "f") ||
				(oneChar >= "A" && oneChar <= "F")) ;
			else 
				invalidAlert = true;
		}
	}
	else
		invalidAlert = true;
	
	if (invalidAlert)
	{
		if (desc && desc.length > 0)
			alert("The '" + desc + "' you entered is not valid.\nPlease provide Ethernet Address in valid format,\neg: 00:40:ab:12:34:56, only hexadecimal characters allowed");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	return true;
}

/**********************************************************************************
** validateEthernetAddressNoColon()
** validateEthernetAddressNoColon : 0040ab123456
** Ethernet address should contain only 12 hexadecimal
***********************************************************************************/
function validateEthernetAddressNoColon(formTextElement, desc)
{
	var plainText = formTextElement.value;
	if (isBlank(formTextElement, desc))
		return false;
	
	var invalidAlert = false;
	if ((plainText.length == 12) && !invalidAlert)
	{
		for (var i = 0; i < plainText.length; i++)
		{
			var oneChar = plainText.charAt(i)
			if ((oneChar >= "0" && oneChar <= "9") ||
				(oneChar >= "a" && oneChar <= "f") ||
				(oneChar >= "A" && oneChar <= "F")) ;
			else 
				invalidAlert = true;
		}
	}
	else
		invalidAlert = true;
	
	if (invalidAlert)
	{
		if (desc && desc.length > 0)
			alert("The '" + desc + "' you entered is not valid.\nPlease provide Ethernet Address in valid 12 digit format,\neg: 0040ab123456, only hexadecimal characters are allowed");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	return true;
}

/***************************************************************
**  checkForDHCPServerAndPassThroughEnable()
***************************************************************/
function checkForDHCPServerAndPassThroughEnable(checkBoxElem, caller, standard)
{
	var f = document.thisForm;
	if (f.DHCP_CONFLICT_DETECT != null) {
		if (f.enableDHCP.checked)
			enableIt(f.DHCP_CONFLICT_DETECT);
		else
			disableIt(f.DHCP_CONFLICT_DETECT);
	}
	if (f.enablePassDHCP == null)
		return;
	if(document.thisForm.enablePassDHCP.checked && document.thisForm.enableDHCP.checked)
	{
		var msg = "'DHCP Server' and 'DHCP Pass Through' cannot be enabled at the same time.";
		if (caller == '0')
			msg += "\nIf 'DHCP Server' needs to be enabled, disable 'DHCP Pass Through'.";
		else
			msg += "\nIf 'DHCP Pass Through' needs to be enabled, disable 'DHCP Server'.";
		alert(msg);
			
		checkBoxElem.checked = false;
		return;
	}
	else if (document.thisForm.enablePassDHCP.checked)
	{
		if (standard != 1)
		{
			alert("'DHCP Pass Through' works only in Standard/Transparent mode.");
			document.thisForm.enablePassDHCP.checked = false;
			return;
		}
	}
}

/***************************************************************
**  limitTextAreaSize()
***************************************************************/
function limitTextAreaSize(textAreaControl, maxLen)
{
	var msg = textAreaControl.value;
	var msgLen= msg.length;
	if (msgLen >= maxLen)
	{
		textAreaControl.value = msg.substring(0,maxLen);
	}

}

/*************************************************************
** validateItemAddedToList()
**************************************************************/
function validateItemAddedToList(formTextElement, desc, compareStr)
{
	if (formTextElement != null &&((formTextElement.value == '') ||
		    (formTextElement.value == compareStr)))
	{
			alert("Not a valid " + desc +",\nPlease enter a valid " + desc);
			try
			{
				formTextElement.focus();
				formTextElement.select();
			}
			catch(er)
			{
			}
			return false;
	}
	return true;
}

/**************************************************************
** ifNewItemListAddedExists()
***************************************************************/
function newItemListAddedExists(fromTextElement, existingList, desc)
{
    var newNameAddedLower = fromTextElement.value.toLowerCase();
	var existingNameLower;
	for (i = 0; i < existingList.length; i++)
	{
		existingNameLower = existingList[i].toLowerCase();
		if (newNameAddedLower == existingNameLower)
		{
			alert(desc + " name already exists.");
			try
			{
				fromTextElement.select();
				fromTextElement.focus();
			}
			catch(er)
			{
			}
			return true;
		}
	}
	return false;
}

/***************************************************************
** isTextLenInRange()
***************************************************************/
function isTextLenInRange(formTextElement, minLen, maxLen, desc)
{
	var testValue = formTextElement.value;
	if((testValue.length < minLen) || (testValue.length > maxLen))
	{
		alert("'"+desc+"' should have number of characters in range[" + minLen + "-" + maxLen + "].\nPlease fill a valid value in.");
		try
		{
			formTextElement.focus();
			formTextElement.select();
		}
		catch(er)
		{
		}
		return false;
	}
	
	return true;
}

/***************************************************************
** trim()
***************************************************************/
function trim(str)
{
	if(str)
	{
		// trim white space from the left
		str = str.replace(/^[\s]+/,"");
		// trim white space from the right
		str = str.replace(/[\s]+$/,"");
	}
	
    return str;
}



/********************************************************************************************
* function sortListBoxContents()
*
* Sorts a list box contents based on the values of the options or the text of the options
*
* An example call to this function would be 
* 	sortListBoxContents('thisForm', 'serviceNameInRule', 'text', 3, 10); 
* where 'thisForm' is the name of the form
*       'serviceNameInRule' is the name of the list box
* 		'text' specifies the list box is to be sorted by text of the options, not value
* 		'sortStartIndex' is the starting index of the elements to be sorted (index starts from 1, not 0)
*		'sortEndIndex' is the ending index of the elements to be sorted (index starts from 1, not 0)
* 		(0 or "" can be specified for start and end indicies where the whole array needs to be sorted)
* 		(start and end indicies are used so we can ignore special options in the list, such as All, None, etc.)
*
********************************************************************************************/
function sortListBoxContents(formName, listBoxName, sortOption, sortStartIndex, sortEndIndex) 
{		 
 	var df = document.forms[formName];
 	var dfs = df.elements[listBoxName]; 		 
 	var contents = new Array();  		 		 
 	
 	var startIndex = 0;	
 	var endIndex = dfs.length;  	
 	if ((sortStartIndex != "") && (sortStartIndex > 0) && (sortStartIndex < dfs.length))
 		startIndex = sortStartIndex;
 	if ((sortEndIndex != "") && (sortEndIndex > 0) && (sortEndIndex < dfs.length))
 		endIndex = sortEndIndex;
 	
 	var count = 0;
 	for (var i = startIndex; i < endIndex; i++) 
 	{ 		
 		if (sortOption == 'text')
  			contents[count] = dfs.options[i].text; 
  		else
  			contents[count] = dfs.options[i].value;
  		count++; 			 
 	} 
 	
 	// Sort using the alphaCmpObj function
 	contents.sort(alphaCmpObj);
   	
 	count = 0;	 		
 	for (i = startIndex; i < endIndex; i++)
  	{
     	var tmp = contents[count];     		     		
     	var txt = "";
     	var val = "";
     	for (j = startIndex; j < endIndex; j++)
     	{
     		if ((sortOption == 'text') && (tmp == dfs[j].text))
     		{     				        			 
       			txt =  dfs[i].text;
          		val =  dfs[i].value;          			          			
          		dfs[i].text = dfs[j].text;
          		dfs[i].value = dfs[j].value;          			
          		dfs[j].text = txt;
          		dfs[j].value = val;     			 
     		}
     		else if ((sortOption != 'text') && (tmp == dfs[j].value))
     		{     				     			 
       			txt =  dfs[i].text;
          		val =  dfs[i].value;          			          			
          		dfs[i].text = dfs[j].text;
          		dfs[i].value = dfs[j].value;          			
          		dfs[j].text = txt;
          		dfs[j].value = val;     			 
     		}
     	}
     	count++;
  	} 		 	 
}

/********************************************************************************************
* function alphaCmpObj()
*********************************************************************************************/
function alphaCmpObj(obj1, obj2)
{
	if (obj1.toLowerCase() < obj2.toLowerCase())
		return -1;

	if (obj1.toLowerCase() > obj2.toLowerCase())
		return 1;

	return 0;
}

	function showDivInline(id) {
		if (document.getElementById) {
			var o = document.getElementById(id);
			if (o) o.style.display = 'inline';
		}
	}
	
	function showDiv(id) {
		if (document.getElementById) {
			var o = document.getElementById(id);
			if (o) o.style.display = 'block';
		}
	}
	function hideDiv(id) {
		if (document.getElementById) {
			var o = document.getElementById(id);
			if (o) o.style.display = 'none';
		}
	}
/** function to show/hide rows in a table based on the table id name and row id name ; show = 0 => show, else hide **/
function showRows(tableName, trName, show)
{
	var myDocumentElements = document.getElementsByTagName("body");
	var myBody = myDocumentElements.item(0);
	var tables = myBody.getElementsByTagName("table")
	for (var i = 0; i < tables.length; i++) {
		var theTable = tables.item(i);
		if (theTable.getAttribute("id") == tableName) {
			// now, traverse the rows for the specified tag
			var rows = theTable.getElementsByTagName("tr");
			for (var j = 0; j < rows.length; j++) {
				var theRow = rows.item(j);
				var rowId = theRow.getAttribute("id");
				if (rowId != null && rowId == trName) {
					if (show == "1")
						theRow.className="showRows";
					else
						theRow.className="hideRows";
				}
			}
		}
	}
}

function isValidPort(portValue)
{	 
	return isNaN(portValue) == false && portValue >=0 && portValue <= 65535;		
}

/**************************************************************/
// StringBuffer in JavaScript: taken from http://www.softwaresecretweapons.com/jspwiki/Wiki.jsp?page=JavascriptStringConcatenation
/**************************************************************/
function StringBuffer()
{ 
   this.buffer = []; 
} 

StringBuffer.prototype.append = function append(string) { 
   this.buffer.push(string); 
   return this; 
}; 

StringBuffer.prototype.toString = function toString() { 
   return this.buffer.join(""); 
}; 


/**************************************************************/
// 3 State Checkbox
/**************************************************************/
var CHECKBOX_UNCHECKED = 0;
var CHECKBOX_CHECKED = 1;
var CHECKBOX_PARTIALLY_CHECKED = 2;
var CHECKBOX_DISABLED = 3;

var cbImage = new Array();
cbImage[0] = new Image(); 
cbImage[0].src = "images/cb0.gif";	
cbImage[1] = new Image(); 
cbImage[1].src = "images/cb1.gif";	
cbImage[2] = new Image(); 
cbImage[2].src = "images/cb2.gif";	
cbImage[3] = new Image(); 
cbImage[3].src = "images/cb.gif";	

function getCBImageSrc(index)
{
	return cbImage[index].src;
}
/**************************************************************/

function isValidPassword(password, isPCIEnabled) {	
	var len = trimSpaces(password.value).length;
	if( len == 0)
		return false;
	if( len > 15 )
		return false;
	if( isPCIEnabled && len < 7 )
		return false;
	return true;
}
