/** 
 * @fileoverview JS functionality of common functions
 */
 
/**
 * It is used to allow only Alpahabets,Numbers
 * @class 
 * @constructor
 * @param <int> pmKeyType : key Type [1 - Alphabets, 2 - Numeric, 3 - Alphanumeric, 4 - Email, 5 - Phone]
 */
function gNulAlNumSplKeys(pKeyType)
{
	/*Function that allows only Alpahabets,Numbers 
	This is to be called 
	in the "KeyPress" event of a Text control."this" 
	reference is to be passed.	*/
	
	/* pKeyType  - 1 (Only Alphabets) and some special character  "white space - / ,'"
	   pKeyType  - 2 (Only Numeric)
	   pKeyType  - 3 (For Alphanumeric)
	   pKeyType  - 4 (For Email)
	   pKeyType -  5 (For Phone) */
	
	//alert(window.event.keyCode);
	// Variable to store the value of "KeyCode".
	pNumKeyCode = window.event.keyCode;
	
	// Check if the "KeyCode" is from "A" to "Z".
	if((pNumKeyCode > 64 && pNumKeyCode < 91) && (pKeyType == 1 || pKeyType == 3 || pKeyType == 4))
	{
		window.status ="Done";
		window.event.keyCode = pNumKeyCode; 
	}
	// Check if the "KeyCode" is from "a" to "z".
	else if((pNumKeyCode > 96 && pNumKeyCode < 123) && (pKeyType == 1 || pKeyType == 3 || pKeyType == 4))
	{
		window.status = "Done";
		window.event.keyCode = pNumKeyCode; 
	}
	// Check if the "KeyCode" is from "0" to "9".
	else if((pNumKeyCode > 47 && pNumKeyCode < 58) && (pKeyType == 2 || pKeyType == 3 || pKeyType == 4 || pKeyType == 5))
	{
		window.status ="Done";
		window.event.keyCode = pNumKeyCode; 
	}
	// Check if the "KeyCode" is  "()-"
	else if(((pNumKeyCode == 40) || (pNumKeyCode == 41) || (pNumKeyCode == 45)) && (pKeyType == 5))
	{
		window.status ="Done";
		window.event.keyCode = pNumKeyCode; 
	}
	// Check if the "Keycode" is "white space - / '"
	else if((pNumKeyCode == 32 || pNumKeyCode == 47 || pNumKeyCode == 45 || pNumKeyCode == 39 || pNumKeyCode == 44) && (pKeyType == 1 || pKeyType == 3))
	{
		window.status ="Done";
		window.event.keyCode = pNumKeyCode; 
	}
	// Check if the "KeyCode" is "@._"
	else if(((pNumKeyCode == 64) || (pNumKeyCode == 46) || (pNumKeyCode == 95)) && (pKeyType == 4))
	{
		window.status ="Done";
		window.event.keyCode = pNumKeyCode; 
	}
	// Check if the "KeyCode" is anyother character, mentioned above.
	else 
	{
		window.status = "Invalid Character."
		window.event.keyCode = 0; 
	}
}
/* ----------------------------------------------------------------------------------------- */

/**
 * Check whether the string is proper or not
 * @class 
 * @constructor
 * @param string String : String to be checked
 * @return True on valid string, false on invalid string
 */
function isproper(string)
{
   if (!string) return false;
   var ichars = "*|,\":<>[]{}`\';()@&$#%";

   for (var i = 0; i < string.length; i++) {
	  if (ichars.indexOf(string.charAt(i)) != -1)
		 return false;
   }
   return true;
}
/**
 * Check whether the string is proper text or not
 * @class 
 * @constructor
 * @param string String : String to be checked
 * @return True on valid string, false on invalid string
 */
function isproperText(string)
{
   if (!string) return false;
   var ichars = "~!*^|+-?,\":<>[]{}`\/;()@&$#%=";

   for (var i = 0; i < string.length; i++) {
	  if (ichars.indexOf(string.charAt(i)) != -1)
		 return false;
   }
   return true;
}

/**
 * Check whether the email id is valid or not
 * @class 
 * @constructor
 * @param string pmemail : Email to check
 * @return True on valid email, false on invalid email
 */
function isvalidemail(pmemail)
{
	return !(pmemail == "" || pmemail.indexOf('@',1) == -1 || pmemail.indexOf('.',3) == -1)
}

//restriction of textarea entry
var ctextlength	
ctextlength = 2000;

/**
 * Check character length
 * @class 
 * @constructor
 * @param object pmessage : Message to check the length
 * @param object pmessagecount : Message length
 * @returns Boolean value
 */
function cremainingcharacters(pmessage,pmessagecount)
{
	if (pmessage.value.length > ctextlength)
	{
		pmessage.value = pmessage.value.substring(0,(ctextlength))
		pmessage.blur()
		top.alert("maximum length for a message (" + ctextlength + ") has been reached.  please shorten your message and try again.")
		rc = false
	}
	else
	{
		rc = true
	}
	pmessagecount.value = ctextlength - (pmessage.value.length)
	return rc
}


/***********************************************************
// function to allow the character up to the given character
***********************************************************/
/**
 * function to allow the character up to the given character
 * @class 
 * @constructor
 * @param object vObject : text area control name
 * @param object vAllowedLength : Length of character should be in text area
 * @returns Boolean value
 */
function allowedCharacter(vObject, vAllowedLength)
{
	/****************************
	// vObject 			= text area control name
	// vAllowedLength 	= Length of character should be in text area
	****************************/
	
	// Check whether the character entered in the text area is greater then the given Allowed length
	if (trim(vObject.value).length > vAllowedLength)
	{
		// Cut the remaining character which exceeds the Allowed length
		vObject.value = vObject.value.substring(0,(vAllowedLength));
		return false;	// return value
	}
	return true;	// return value
} //#-- close of allowedCharacter(vObject, vAllowedLength)


// website entry validation
/**
 * Check whether the url isis valid or not
 * @class 
 * @constructor
 * @param string pmUrl : Url to check
 * @return True on valid email, false on invalid email
 */
function isvalidurl(pmurl)
{
	var vstr = new string
	var visvalid
	var vlen
	pmurl = pmurl.toLowerCase()
	vstr = "1234567890qwertyuiopasdfghjklzxcvbnm_./-"
	visvalid = true
	for (vloop=0;vloop<=pmurl.length;vloop++)
	{
		symbol =  pmurl.substr(vloop,1)
		if (vstr.indexOf(symbol,1) < 0)
		{
			visvalid = false
			return(visvalid)				
			break;
		}
	}
	return(visvalid)
}

/**
 * Set focus to specified object
 * @class 
 * @constructor
 * @param object pmcontrol : object name to focus
 */
function setfocus(pmcontrol)
{
	if(pmcontrol.disabled == false)
		pmcontrol.focus();
}

/**
 * To trim the string
 * @class 
 * @constructor
 * @param string pmString : string to be trimmed
 * @return Trimmed String
 */
function trim(str)
{
		//return str.replace( /^ +/, "" ).replace( / +$/, "" );
		return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}


// Common window open function
// Example - comm_window_open('album_info.php?album_id=21', 'album_info', 220, 400, 'no', 150, 200);
/**
 * To open window to view page
 * @class 
 * @constructor
 * @param string open_page : page url
 * @param string page_name : page name
 * @param string pg_height : window height
 * @param string pg_width : window width
 * @param string pg_scroll : window scroll length
 * @param string pg_top : window top length
 * @param string pg_left : window left length
 */
function comm_window_open(open_page, page_name, pg_height, pg_width, pg_scroll, pg_top, pg_left)
{
	var d = new Date();
	d = Date.parse(d);
	window.open(open_page,page_name+d, "height="+pg_height+",width="+pg_width+",scrollbars="+pg_scroll+",top="+pg_top+",left="+pg_left);
}


/*******************************************************
// Function to Check whether regular expression supported
*******************************************************/
/**
 * Check whether the regular expression is supported or not
 * @class 
 * @constructor
 * @return True on success, false on failure
 */
function isRegExpSupported()
{
	//#-- are regular expressions supported?
		if (window.RegExp)
		{
			//#-- assign expression
				var vTempStr = "a";
				var vTempReg = new RegExp(vTempStr);
			
			//#-- return status
				return (vTempReg.test(vTempStr));
		}
	
	//#-- return status
		return (false);
} //#-- close of isRegExpSupported()


/**********************************************************************
// Function to Check for valid email. User can check multiple email ids
**********************************************************************/
/**
 * Function to Check for valid email. User can check multiple email ids
 * @class 
 * @constructor
 * @param string pmStr : String contain email
 * @param string pmMultiple : TURE or FALSE. Whether this email string contains multiple emails
 * @return True on success, false on failure
 */
function isEmailMulti(pmStr, pmMultiple)
{
	/*********************************************************************************
	// @pmStr = String contain email
	// @pmMultiple = TURE or FALSE. Whether this email string contains multiple emails
	*********************************************************************************/
	vResValidate = false;
	if (pmMultiple)
	{
		pmStr     = trim(pmStr).replace(/;/g, ',');
		aEmailIds = trim(pmStr).split(",");
		vResValidate = true;
		for(vLoopEmail = 0; vLoopEmail < aEmailIds.length; vLoopEmail++)
		{
			vEmail  = trim(aEmailIds[vLoopEmail]);
			vEmail  = vEmail.replace(";", ','); 
			vEmail  = vEmail.replace(/\r\n|\r|\n/g, ''); 
			vEmail  = vEmail.replace(/\r\n/g,'');
			vEmail  = vEmail.replace(/\r/g,'');
			vEmail  = vEmail.replace(/\n/g,'');
			vEmail	= trim(vEmail);
			if(vEmail != "") 
			{
				if(!isEmail(vEmail))
				{
					vResValidate = false;
					break ;
				}
			}
		}
	}
	else vResValidate = isEmail(pmStr)	
	return vResValidate;
} //#-- close of isEmail()

/***************************************************************************************************
// Function to Check for valid email with name. User can check multiple email ids with names entered
***************************************************************************************************/
/**
 * Function to Check for valid email with name. User can check multiple email ids with names entered
 * @class 
 * @constructor
 * @param string pmStr : String contain email
 * @param string pmMultiple : TURE or FALSE. Whether this email string contains multiple emails
 * @return True on success, false on failure
 */
function isEmailMultiWithName(pmStr, pmMultiple)
{
	/*********************************************************************************
	// @pmStr = String contain email
	// @pmMultiple = TURE or FALSE. Whether this email string contains multiple emails
	*********************************************************************************/
	vResValidate = false;
	if (pmMultiple)
	{
		aEmailIds = pmStr.split(",")
		vResValidate = true;
		for(vLoopEmail = 0; vLoopEmail < aEmailIds.length; vLoopEmail++)
		{
			aData = aEmailIds[vLoopEmail].split("(");
			vEmail = aData[0];
			vName = typeof(aData[1]) != 'undefined' ? aData[1].replace(")","") : "";

			if (!isEmail(vEmail) || !isPersonName(vName))
			{
				vResValidate = false;
				break ;
			}
		}
	}
	else 
	{
		aData = pmStr.split("(");
		vEmail = aData[0];
		vName = typeof(aData[1]) != 'undefined' ? aData[1].replace(")","") : "";
		
		vResValidate = isEmail(vEmail) && isPersonName(vName);
	}
	return vResValidate;
} //#-- close of isEmail()
 
/* function isEmail(pmStr)
{
	/******************************
	// @pmStr = String contain email
	******************************/ /*
	var str = pmStr.toUpperCase();
	var com = 'COM';
	var lcom=str.indexOf(com);
	pmStr  = trim(pmStr);	//#-- trim the string
	pmStr  = pmStr.replace(/\r\n|\r|\n/g, ''); 
	pmStr  = pmStr.replace(/\r\n/g,'');
	pmStr  = pmStr.replace(/\r/g,'');
	pmStr  = pmStr.replace(/\n/g,''); 
	if (pmStr == "") return false;
	if (pmStr.length > 50) return false;
	if (!isRegExpSupported()) return (pmStr.indexOf(".") > 2) && (pmStr.indexOf("@") > 0);	//#-- is regular expressions supported
	//if the email does not have @ and . then return false
	if(pmStr.indexOf('@') == -1 || pmStr.indexOf('.') == -1 || pmStr.indexOf(' ') != -1)
		return false;
	//###################################################################
	vSubStr = pmStr.split('@'); //#-- split the email 
	vDomain = vSubStr[1].split('.'); //#-- split the domain extension 
	
	
	//###################################################################
	for(vI = 0; vI < vDomain.length ; vI++)
	{
			if(vDomain[vI].length <= 1)
			{
				return (false) //#-- test and return value
			}
	}
	
	pmStr = trim(pmStr);
	var vPattern = "^[A-Za-z0-9](([_\\.\\-]?[a-zA-Z0-9_]+)*)@([A-Za-z0-9]+)(([\\_.\\-]?[a-zA-Z0-9]+)*)\\.([A-Za-z]{2,})$";
	var vRegExp = new RegExp(vPattern);
	return (vRegExp.test(pmStr));
} */

/**
 * Check whether the email is valid or not
 * @class 
 * @constructor
 * @param string pmStr : Emai id to check
 * @return True on success, false on failure
 */
function isEmail(pmStr)
{
	/******************************
	// @pmStr = String contain email
	******************************/
	var str = pmStr.toUpperCase();
	var com = 'COM';
	var lcom=str.indexOf(com);
	
	pmStr  = trim(pmStr);	//#-- trim the string
	pmStr  = pmStr.replace(/\r\n|\r|\n/g, ''); 
	pmStr  = pmStr.replace(/\r\n/g,'');
	pmStr  = pmStr.replace(/\r/g,'');
	pmStr  = pmStr.replace(/\n/g,''); 
	if (pmStr == "") return false;
	if (pmStr.length > 50) return false;
	
	if (!isRegExpSupported()) return (pmStr.indexOf(".") > 2) && (pmStr.indexOf("@") > 0);	//#-- is regular expressions supported
	//if the email does not have @ and . then return false
	
	if(pmStr.indexOf('@') == -1 || pmStr.indexOf('.') == -1 || pmStr.indexOf(' ') != -1)
		return false;
	
	//###################################################################
	vSubStr = pmStr.split('@'); //#-- split the email 
	vDomain = vSubStr[1].split('.'); //#-- split the domain extension 
	//###################################################################
			
	for(vI = 0; vI < vDomain.length ; vI++)
	{
			if(vDomain[vI].length <= 0)
			{
				return (false) //#-- test and return value
			}
	}
	for(uI = 1; uI < vDomain.length ; uI++)
	{
		if(vDomain[uI].length >3)
		{
			return (false) //#-- test and return value
		}
	}
	
	//#-- end of addition by P.Sivamurugan  
	//#######################################################################
	//#-- end of addition by senthil 
	//#######################################################################
	pmStr = trim(pmStr);
	var vPattern = "^[A-Za-z0-9](([_\\.\\-]?[a-zA-Z0-9_]+)*)@([A-Za-z0-9]+)(([\\_.\\-]?[a-zA-Z0-9]+)*)\\.([A-Za-z]{2,})$";
	var vRegExp = new RegExp(vPattern);
	return (vRegExp.test(pmStr));		
}

/**
 * Check whether the phone number is valid or not
 * @class 
 * @constructor
 * @param string pmPhNo : Phone Number
 * @param int pmMinLength : Min Length
 * @param int pmMaxLength : Max Length
 * @return True on success, false on failure
 */
function isValidPhoneNo(pmPhNo,pmintMinLen,pmintMaxLen)
{   var i;
	var returnString = "";
	var phoneNumberDelimiters = "0123456789()-+,  ext.";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < pmPhNo.length; i++)
	{   
		// Check that current character isn't whitespace.
		var c = pmPhNo.charAt(i);
		if(c == "-")
			pmintMinLen++;
		if (phoneNumberDelimiters.indexOf(c) == -1) 
			return false;
	}
	if(pmPhNo.length>pmintMaxLen || pmPhNo.length<pmintMinLen)
		return false;
	else	
		return true;
}

/**
 * Check whether the phone number is valid or not
 * @class 
 * @constructor
 * @param string pmPhNo : Phone Number
 * @param int pmMinLength : Min Length
 * @param int pmMaxLength : Max Length
 * @return True on success, false on failure
 */
function isPhoneNo(pmPhNo,pmintMinLen,pmintMaxLen)
{   var i;
	var returnString = "";
	var phoneNumberDelimiters = "0123456789()-,  ext.";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < pmPhNo.length; i++)
	{   
		// Check that current character isn't whitespace.
		var c = pmPhNo.charAt(i);
		if(c == "-")
			pmintMinLen++;
		if (phoneNumberDelimiters.indexOf(c) == -1) 
			return false;
	}
	if(pmPhNo.length>pmintMaxLen || pmPhNo.length<pmintMinLen)
		return false;
	else	
		return true;
}

/**
 * Check whether the zip code is valid or not
 * @class 
 * @constructor
 * @param string pmZipCode : zip code
 * @return True on success, false on failure
 */
function isZipcode(pmStr)
{
	string=trim(pmStr);
	if (!string) return false;
		var ichars = "!!*|,\":<>[]{}`\';()@&$#%";
	
	for (var i = 0; i < string.length; i++) 
	{
		if (ichars.indexOf(string.charAt(i)) != -1)
		return false;
	}
	return true;
}

function isUSZipcode(pmStr)
{
	string=trim(pmStr);
	
	if(string.length > 5)
		return false;
	
	if (!string) return false;
		var ichars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!!*|,\":<>[]{}`\';()@&$#%";
	
	for (var i = 0; i < string.length; i++) 
	{
		if (ichars.indexOf(string.charAt(i)) != -1)
		return false;
	}
	return true;
}

/**
 * Check whether the given string is special character or not
 * @class 
 * @constructor
 * @param string pmStr : string content
 * @returns Boolean value
 */
function isSpeacilChar(pmStr)
{
	string=trim(pmStr);
	if (!string) return false;
		var ichars = "~!*|,\":<>[]{}`\';()@&$#%=-\:?,/";
	
	for (var i = 0; i < string.length; i++) 
	{
		if (ichars.indexOf(string.charAt(i)) != -1)
		return false;
	}
	return true;
}


/***********************************************
// Function to Check whether given name is valid
***********************************************/
/**
 * Function to Check whether given name is valid
 * @class 
 * @constructor
 * @param string pmStr : String to be tested
 * @return True on success, false on failure
 */
function isPersonName(pmStr)
{
	/**********************************************************************************************
	// @pmStr = String to be tested
	// Checks the allowed string be "A to Z", "a to z", "space" and "'."
	**********************************************************************************************/
	
	pmStr = trim(pmStr);
	if (pmStr == "") return false;
	if (isRegExpSupported())	//#-- is regular expression supported
	{
		var vPattern = "(^([a-zA-Z0-9 '.'-]+)?)$";	//#-- set the pattern
		var vRegExp = new RegExp(vPattern);									//#-- create regular expression object
		return (vRegExp.test(pmStr));										//#-- test and return status
	} //#-- close of if (isRegExpSupported())
	var vPattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 '.";
	if (!pmStr.length) return false;	//#-- check for empty string
	for (var i = 0; i < pmStr.length; i++) if (vPattern.indexOf(pmStr.charAt(i)) == -1) return false;
	return true;
} //#-- close of isName(pmStr)

/**
 * Function to Check whether given city is valid
 * @class 
 * @constructor
 * @param string pmStr : String to be tested
 * @return True on success, false on failure
 */
function isCity(pmStr)
{
	string=trim(pmStr);
	if (!string) return false;
		var ichars = "~!*^|+-?,.\"':<>[]{}`\/;\()@&$#%=12345678990 ";
	
	for (var i = 0; i < string.length; i++) 
	{
		if (ichars.indexOf(string.charAt(i)) != -1)
		{
			return false;
		}
	}
	return true;
}

/**
 * Function to Check whether given name is valid
 * @class 
 * @constructor
 * @param string pmStr : String to be tested
 * @return True on success, false on failure
 */
function isName(pmStr)
{
	string=trim(pmStr);
	if (!string) return false;
		//var ichars = "^~!*|\"<>[]{}`\;()@$#%/_-:\,.?'";
		var ichars = "~!*^|+-?,\:<>[]{}`\/;()@&$#%= ";
	
	for (var i = 0; i < string.length; i++) 
	{
		if (ichars.indexOf(string.charAt(i)) != -1)
		{
			return false;
		}
	}
	return true;
}

/**
 * Function to Check whether given name is valid
 * @class 
 * @constructor
 * @param string pmStr : String to be tested
 * @return True on success, false on failure
 */
function isName1(pmStr)
{
	string=trim(pmStr);
	if (!string) return false;
		var ichars = "^~!*|\"<>[]{}`\;()@$#%";
	
	for (var i = 0; i < string.length; i++) 
	{
		if (ichars.indexOf(string.charAt(i)) != -1)
		{
			return false;
		}
	}
	return true;
}

/**
 * Function to Check maximun lenght for text
 * @class 
 * @constructor
 * @param string fstrValue : String to be tested
 * @param int lintLength : String length
 * @return false on failure or window status
 */
function  gfuncMaxLenChk(fstrValue,lintLength)
{
	var lstrValue = fstrValue.value.length;
	window.status='Text Length-->'+lstrValue+ ' / '+ lintLength;

	if (lstrValue>=lintLength)
	{
		window.status = "Text cannot exceed " + lintLength + " characters";			
		window.event.keyCode=0;
		return false;			
	}
}

/* ***   FUNCTION THAT ALLOWS ONLY NUMBERS (WHOLE) INSIDE A TEXTBOX   *** */
/**
 * Function that allows only Numbers
 * @class 
 * @constructor
 * @return window status
 */
function gNulNumKeys()
{
	/*Function that allows only Numbers. This is to be 
	 called in the "KeyPress" event of a Text control. 
	 "this" reference is to be passed.*/
	// Variable to store the "KeyCode".
	var pNumKeyCode = window.event.keyCode;
	// Check what is the value of "KeyCode". If its valid
	// allow the value to be displayed, otherwise prompt.
	if(pNumKeyCode >= 47 && pNumKeyCode < 58)
	{
		window.status = "";
		window.event.keyCode = pNumKeyCode;	
	}
	else
	{	
		window.status = "Invalid Character. Only Numbers Are Allowed.";
		window.event.keyCode = 0;
	}
} 
// END FUNCTION gNulNumKeys
/**
 * This Function is used to validate for proper text
 * @class 
 * @constructor
 * @param string string : String to be validated
 * @return True on success, false on failure
 */
function properText(string)
{
   if (!string) return false;
   var ichars = "\~!*^|+?,\":<>[]{}'`\/;()&$#%=";

   for (var i = 0; i < string.length; i++) {
	  if (ichars.indexOf(string.charAt(i)) != -1)
		 return false;
   }
   return true;
}
/**
 * This Function is used to Remove leading blanks from text area.
 * @class 
 * @constructor
 * @param string str : String to be validated
 * @return trimed text value
 */
function textTrim(str)
/************************************************************************/
  //	PURPOSE: Remove leading blanks from text area.
 // 	INPUt: str - the string we want to check
/****************************************************************************/
{
	//#--	check condition
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	//#--	check white space
	if (whitespace.indexOf(s.charAt(0)) != -1) 
	{
		//#--	We have a string with leading blank(s)...
		var j=0, i = s.length;
		//#--	Iterate from the far left of string until we
		// #--	don't have any more whitespace...
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
		j++;
		//#--	Get the substring from the first non-whitespace
		//#--	character to the end of the string...
		s = s.substring(j, i);
	}
//#--	return value
  return s;
}

/************************************
// Function to check for valid US Phone number format with extension 
************************************/
/**
 * Check whether the US phone number is valid or not
 * @class 
 * @constructor
 * @param string pmPhNo : Phone Number
 * @return True on success, false on failure
 */
function isValidUSPhone(pmPhoneNumber)
{
	/****************************
	// pmPhoneNumber = Phone Number that to be validated
	****************************/
	
		pos    = 0;
		vStart = pmPhoneNumber.substring(pos,pos+2);
		vPhone = pmPhoneNumber.substring(2,pmPhoneNumber.length);
		if(vStart.charAt(pos) == 1 && vStart.charAt(pos+1) == '-')
		{
			//#--Write Regular expression to check valid US Phone number
			var vPattern = '^(\\(?\\d\\d\\d\\)?)?( |-|\\.)?\\d\\d\\d( |-|\\.)?\\d{4,4}(( |-|\\.)?[ext\\.]+ ?\\d+)?$';
			var vRegExp = new RegExp(vPattern);
			//#-- return true if it is valid Phone number or false for invalid Phone number
			return (vRegExp.test(vPhone));
		}
		else 
		{
			//#--Write Regular expression to check valid US Phone number
			var vPattern = '^(\\(?\\d\\d\\d\\)?)?( |-|\\.)?\\d\\d\\d( |-|\\.)?\\d{4,4}(( |-|\\.)?[ext\\.]+ ?\\d+)?$';
			var vRegExp = new RegExp(vPattern);
			//#-- return true if it is valid Phone number or false for invalid Phone number
			return (vRegExp.test(pmPhoneNumber));
		}	
	
}
	
//#-- Created by vimala
//############################################################################
/**
 * Check whether the email is valid or not
 * @class 
 * @constructor
 * @param string pmStr : Emai id to check
 * @param object pmObject : Object
 * @return True on success, false on failure
 */
function isEmailExists(pmStr)
{
	var vFLag = 0;
	pmStr = pmStr.replace(/;/g,",");
	temp = pmStr;
	aTempEmailId = trim(temp).split(",");
	pmStr = pmStr.toUpperCase(); 
	aEmailIds = trim(pmStr).split(",");
	vExists = "";	
	for(vLoopEmail = 0; vLoopEmail < aEmailIds.length; vLoopEmail++)
	{
		vEmail  = trim(aEmailIds[vLoopEmail]);
		vEmail  = vEmail.replace(/\r\n|\r|\n/g, ''); 
		vEmail  = vEmail.replace(/\r\n/g,'');
		vEmail  = vEmail.replace(/\r/g,'');
		vEmail  = vEmail.replace(/\n/g,'');
		vEmail	= trim(vEmail);
		
		vTemp  = trim(aTempEmailId[vLoopEmail]);
		vTemp  = vTemp.replace(/\r\n|\r|\n/g, ''); 
		vTemp  = vTemp.replace(/\r\n/g,'');
		vTemp  = vTemp.replace(/\r/g,'');
		vTemp  = vTemp.replace(/\n/g,'');
		vTemp	= trim(vTemp);
		
		if(vEmail != "") 
		{
			if(vExists.toUpperCase().indexOf("|" + vEmail + "|") == -1)
			{
				vExists = vExists + "|" + vTemp + "|,";
				vPreValue = vExists;
			}
			else
			{
				vFLag = 1;
			}
		}
	}
	//#-- this part added by Senthil Kumar S.
	if(vFLag == 1)
	{
		document.frmShareAlbum.too.value = vPreValue.replace(/\|/g,'');
		return false;
	}
	//#--
	return true;
} //#-- close of isEmail()
//#################################################################################
/**
 * Check whether the check box is checked or not
 * @class 
 * @constructor
 * @param object ckbox : check box object
 * @param object form : form name
 */
function checkrememberme(ckbox,form)
{
	var obj = eval("document."+form+".ckRemember");
	if(ckbox.checked == true)
		obj.value = 1;
	else
		obj.value = 0;
}

/**
 * Function to set the cookie
 * @class 
 * @constructor
 * @param string name : cookie name
 * @param string value : cookie value
 */
function setCookie (name, value)
{
delCookie(name);
document.cookie = name + "=" + escape (value) + 
"; expires=" + expdate.toGMTString() +  "; path=/";
}

/**
 * Function to delete the cookie
 * @class 
 * @constructor
 * @param string name : cookie name
 */
function delCookie (name) 
{
var expireNow = new Date();
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}
//#################################################################################
//#!-- -------------------------------------------------------------------------------------------------------------------------
/**
 * Function to check name
 * @class 
 * @constructor
 * @param string pmStr : String to validated
 * @return True on success, false on failure
 */
function checkName(pmStr)
{
	var illegalChars =/[\(\)\<\>\;\ \@\%\^\&\_\~\,\#\+\{\}\=\|\?\*\$\:\!\\\/\"\[\]]/; 
	//	str=pmStr.substring(0,1)
	if (illegalChars.test(pmStr)){//|| pmStr.indexOf("_")==0)  {
	  return false
	}
	else
		return true
}
//#!-- ------------------------------------------------------------------------------------------------------------------------
/**
 * Function to not allow space
 * @class 
 * @constructor
 * @param int e :  Code number for character
 * @return false on failure
 */
function funNotAllowSpace(e)
{	
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode==32)
	{ //if the key isn't the backspace key (which we should allow)
		return false //disable key press
	}
}
//#!-- ------------------------------------------------------------------------------------------------------------------------
	//# function to allow only letters and numbers in password and in phone or zipcode
/**
 * function to allow only letters and numbers in password and in phone or zipcode
 * @class 
 * @constructor
 * @param string pmStr :  string to be tested
 * @return True on success, false on failure
 */
function checkStr(pmStr)
{
	var illegalChars = /[\W_]/; 
	if (illegalChars.test(pmStr)) {
	  return false
	}
	else
		return true
}

/**
 * function to append atring in another string
 * @class 
 * @constructor
 * @param int pos :  position of the string
 * @param String str :  string to append
 * @param String ins :  string to inserted
 * @return appended string
 */
function SubstringDemo(pos, str,ins) 
{ 
	 var str1, str2; 
	 str1 = str.substring(0,pos-1);
	 str2 = str.substring(pos+1,str.length);
	 return(str1+ins+str2); 
} 

/**
 * function to check whether the given string contain zero or not
 * @class 
 * @constructor
 * @param String pmStr :  String to be tested
 * @return True on success, false on failure
 */
function ZeroValidation(pmStr)
{
	vReturnValue = 0
	for(vLoop=0;vLoop<pmStr.length;vLoop++)
	{

		if((pmStr.charAt(vLoop) > 0 ) && (pmStr.charAt(vLoop) !='-'))
				vReturnValue++;
	}
	if(vReturnValue>0)
		return true;
	else 
		return false;
}
//#  functions added by saravanan.T for the shopping cart module

/**
 * function to check whether the given address is valid or not
 * @class 
 * @constructor
 * @param String pmStr :  String to be tested
 * @return True on success, false on failure
 */
function isAddress(pmStr)
{
	/**********************************************************************************************
	// @pmStr = String to be tested
	// Checks the allowed string be "A to Z", "a to z", "space" and "'."
	**********************************************************************************************/
	
	/*pmStr = trim(pmStr);
	if (pmStr == "") return false;
	if (isRegExpSupported())	//#-- is regular expression supported
	{
		var vPattern = "(^([a-zA-Z0-9 '.'-]+)?)$:,\\";	//#-- set the pattern
		var vRegExp = new RegExp(vPattern);									//#-- create regular expression object
		return (vRegExp.test(pmStr));										//#-- test and return status
	} //#-- close of if (isRegExpSupported())*/
	var vPattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 '.:,\\+-#=\/";
	if (!pmStr.length) return false;	//#-- check for empty string
	for (var i = 0; i < pmStr.length; i++) if (vPattern.indexOf(pmStr.charAt(i)) == -1) return false;
	return true;
} //#-- close of isName(pmStr)

// Function used to get the radio value...   (ie checked radio button value)	
// object form Field         -->   document.frmproject.elements[strFieldName]

/**
 * Function used to get the radio value...   (ie checked radio button value)
 * @class 
 * @constructor
 * @param Object objFormField :  radio element object
 * @return string value
 */
function getRadialValue(objFormField)
{
	//   var objFormField = document.frmproject.elements[strFieldName]
   var objFormField;
   intControlLength = objFormField.length
   if(intControlLength)
   {
		for (i=0;i<intControlLength;i++)
		{
			if(objFormField[i].checked)
			{
				strValue = objFormField[i].value;
				return strValue;
			}
		}
		
		return false;
   }
   else
   {
		strValue=objFormField.value;
		return strValue;	
   }     
}

