/*************************************************************
Following functions are available
isEmail		-> Check the entered eamil id is valid email
**************************************************************/
	function isEmail(pmStr)
	{
		/******************************
		// @pmStr = String contain email
		******************************/
	
		pmStr = trim(pmStr);	//#-- trim the string
		pmStr  = pmStr.replace('\r\n',"");
		pmStr  = pmStr.replace('\n',"");
		if (pmStr == "") return false;
		if (pmStr.length > 50) return false;
		if (!isRegExpSupported()) return (pmStr.indexOf(".") > 2) && (pmStr.indexOf("@") > 0);	//#-- is regular expressions supported
		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));
	}

	/**********************************************************************
	// Function to Check for valid email. User can check multiple email ids
	**********************************************************************/
	function isEmailMulti(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++)
			{
				if (!isEmail(aEmailIds[vLoopEmail]))
				{
					vResValidate = false;
					break;
				}
			}
		}
		else vResValidate = isEmail(pmStr)	
		return vResValidate;
	} //#-- close of isEmailMulti()
	//#-- Created by vimala
	function isEmailExists(pmStr)
	{
		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);
			if(vEmail != "") 
			{
				if(vExists.indexOf("|" + vEmail + "|") == -1)
				{
					vExists = vExists + "|" + vEmail + "|,";
					vPreValue = vExists;
				}
				else
				{
					document.frmTellafriend.txtFrndEmail.value = vPreValue.replace(/\|/g,'');
					return false;
				}
				
			}
		}
		return true;
	} //#-- close of isEmail()
	
	
	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 (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)
	
	function trim(str)
	{
			return str.replace( /^ +/, "" ).replace( / +$/, "" );
	}
	/*******************************************************
	// Function to Check whether regular expression supported
	*******************************************************/
	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 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;
	}
	function isproperName(string)
	{
	   if (!string) return false;
	   var ichars = "~-_!*^|+?,.\":<>[]{}`\;@$#%=1234567890 ";
	   for (var i = 0; i < string.length; i++)
	   {
		  if (ichars.indexOf(string.charAt(i)) != -1)
			 return false;
	   }
	   return true;
	}
	function isProperCity(string)
	{
	   if (!string) return false;
	   var ichars = "~-'!*^|+?,.\":<>[]{}`\;@$#%=1234567890";
	   for (var i = 0; i < string.length; i++)
	   {
		  if (ichars.indexOf(string.charAt(i)) != -1)
			 return false;
	   }
	   return true;
	}
	function isproper(string,pmChars)
	{
	   if (!string) return false;
	  // var ichars = "~!*^|+-?,\":<>[]{}`\/;()@&$#%=12345678990 ";
	
	   for (var i = 0; i < string.length; i++)
	    {
		  if (pmChars.indexOf(string.charAt(i)) != -1)
			 return false;
		}
	   return true;
	}
	function ispassword(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;
	}
	function isProperString(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-Z '.#@&,-_/ %]+)?)$";	//#-- 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 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '.";
		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 isValidNumber(pmStr)
	{
		var vFlag = 0;
		pmStr = trim(pmStr);
		var vPattern = "0123456789$-,. ";
		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;
			else
				if((vFlag == 0) && (pmStr.charAt(i) == '.') && (pmStr.indexOf(".") > 0))
				{
					vFlag = 1;
					vStringNew = pmStr.substr(i+1, pmStr.length);
				}
				else if((vFlag == 1) && (pmStr.charAt(i) == '.') && (vStringNew.indexOf(".") > 0))
					return false;
		return true;
	}
	
	function isZipcode(string,pmChars)
	{
		var num = 0;
	   if (!string) return false;
	  var ichars = "~!*^|+?,.~\":<>[]{}`\/;()@&$#%=_ ";
	   for (var i = 0; i < string.length; i++)
	   {
		   if (ichars.indexOf(string.charAt(i)) != -1)
			 return false;
			var c = string.charAt(i); 
			if(!isNaN(c))
			num++;
	   }
	   if(num >0)
	   return true;
	   else
	   return false;
	}
	
	/************************************
	// Function to check for valid United States Zip Code
	************************************/
	function isValidUSZip(pmZipCode)
	{
		/****************************
		// pmZipCode = Zip Code that to validated
		****************************/
		
		//#--Write Regular expression to check valid US Zip Code
		var vRegExp = new RegExp("^[0-9]{5}([- /]?[0-9]{4})?$");
		
		//#-- return true if it is valid zip or false for invalid zip code
		return (vRegExp.test(pmZipCode));
	}
	function isValidZip(pmZipCode)
	{
		/****************************
		// pmZipCode = Zip Code that to validated
		****************************/
		
		//#--Write Regular expression to check valid US Zip Code
		var vRegExp = new RegExp("^[0-9]{6}([- /]?[0-9]{5})?$");
		
		//#-- return true if it is valid zip or false for invalid zip code
		return (vRegExp.test(pmZipCode));
	}
	// Function to check for valid US Phone number format with extension 
	// format 777-777-7777
	function isValidUSPhone(pmPhoneNumber)
	{
		/****************************
		// pmPhoneNumber = Phone Number that to be validated
		****************************/
		
		//#--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));
	}
	function checkName(pmStr) {

		var illegalChars =/[\(\)\<\>\;\ \@\%\^\&\_\~\,\#\+\{\}\=\|\?\*\$\:\!\\\/\"\[\]]/; 
		//	str=pmStr.substring(0,1)
		if (illegalChars.test(pmStr)){//|| pmStr.indexOf("_")==0)  {
		  return false
		}
		else
			return true
	}
	//# function to allow only letters and numbers in password and in phone or zipcode

	function checkStr(pmStr)
	{
	
		var illegalChars = /[\W_]/; 
		if (illegalChars.test(pmStr)) {
		  return false
		}
		else
			return true
	}
	function gNulAlNumKeys()
	{
		/*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.	*/
		
		// 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 || pNumKeyCode==13 || pNumKeyCode==45)
		{
			window.status ="";
			window.event.keyCode = pNumKeyCode; 
		}
		// Check if the "KeyCode" is from "a" to "z".
		else if(pNumKeyCode > 96 && pNumKeyCode < 123 || pNumKeyCode==13 || pNumKeyCode==45)
		{
			window.status = "";
			window.event.keyCode = pNumKeyCode; 
		}
		// Check if the "KeyCode" is from "0" to "9".
		else if(pNumKeyCode > 47 && pNumKeyCode < 58 || pNumKeyCode==13 || pNumKeyCode==45)  
		{
			window.status ="";
			window.event.keyCode = pNumKeyCode; 
		}
		else
		{	
			window.status = "Invalid Character. Only Characters and Numbers Are Allowed.";
			window.event.keyCode = 0;
		}
	}
	function gNumKeys()
	{
		/*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 value of "KeyCode".
		pNumKeyCode = window.event.keyCode;
		
		// Check if the "KeyCode" is from "0" to "9".
		if(pNumKeyCode > 47 && pNumKeyCode < 58 || pNumKeyCode==13 || pNumKeyCode==45)  
		{
			window.status ="";
			window.event.keyCode = pNumKeyCode; 
		}
		else
		{	
			window.status = "Invalid Character. Only Numbers Are Allowed.";
			window.event.keyCode = 0;
		}
	}
	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 CreateControl(flashStr,DivID)
	{  
	  var d = document.getElementById(DivID);
	  d.innerHTML = flashStr;  
	}
/*	function CreateFlashControl(DivID, CLSID, ObjectID,CodeBase,allowScriptAccess,movie,LoadId,xmlPath,BgColor,Width,Height,EmbedName)
	{ 
	//alert('inner function');
	var d = document.getElementById(DivID);
	d.innerHTML = '<object classid=' + CLSID + ' id=' + ObjectID + ' codebase=' + CodeBase +' width="'+Width+'" height="'+Height+'" id=" ' +EmbedName+' " align="middle"> <param  name="allowScriptAccess" value=' + allowScriptAccess + ' /> <param name="movie" value=' + movie + ' /> <Param Name="FlashVars" Value="load_pid='+LoadId+'&xml_path='+xmlPath+'" /> <param name="quality" value="high" />  <param name="bgcolor" value=' + BgColor + ' />  <embed src='+movie+' quality="high" bgcolor="'+BgColor+'" width="'+Width+'" height="'+Height+'" name="'+EmbedName+'" FlashVars="load_pid='+LoadId+'&xml_path='+xmlPath+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></OBJECT>';  
	
	}*/

	function CreateFlashControl(DivID, CLSID, ObjectID,CodeBase,allowScriptAccess,movie,LoadId,xmlPath,BgColor,Width,Height,EmbedName)
	{ 
/*		var bname 			= 	navigator.appName;
		var system_name = navigator.userAgent;
		if(system_name.toLowerCase().indexOf("safari") != -1)
		{
			wait(6000);
		}*/
		var d = document.getElementById(DivID);
		d.innerHTML = '<object classid=' + CLSID + ' id=' + ObjectID + ' codebase=' + CodeBase +' width="'+Width+'" height="'+Height+'" id=" ' +EmbedName+' " align="middle"> <param  name="allowScriptAccess" value=' + allowScriptAccess + ' /> <param name="movie" value=' + movie + ' /> <Param Name="FlashVars" Value="load_pid='+LoadId+'&xml_path='+xmlPath+'" /> <param name="quality" value="high" />  <param name="bgcolor" value=' + BgColor + ' />  <embed src='+movie+' quality="high" bgcolor="'+BgColor+'" width="'+Width+'" height="'+Height+'" name="'+EmbedName+'" FlashVars="load_pid='+LoadId+'&xml_path='+xmlPath+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></OBJECT>';  
	}
	function isValidPersonName(pmString)
	{
		/*************************************************
			@pmString = to be tested
				checks allowed string characters "A" to "Z", "a" to "z", "spaces" and "'"
		************************************************/
		//#-- trim starting and ending white spaces 
		var vPersonName = trim(pmString);
		
		//#-- check if the string is empty
		if(vPersonName == "")
			return false;
		//#-- check if the browser support regular expersion	
		if(isRegExpSupported()) //#-- is regular experssion supported
		{	
			//#-- build the allowed character pattern
			var vPattern = "(^([a-zA-Z ']+)?)$";	//#-- set the pattern
			var vRegExp = new RegExp(vPattern);		//#-- create a new regular experson object
			return (vRegExp.test(vPersonName));		//#-- test and return status
		} //#-- end of regular experssion support
		
		//#-- build the character patern
		var vPattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '";
		
		for(var vI = 0; vI < vPattern.length ; vI ++)
			if(vPattern.indexOf(vPersonName.charAt(vI)) == -1) //#-- test and return status
				return (false);
		return (true);
				
	}//#-- End of the isValidPersonName() function
	function isValidCity(pmString)
	{
		/*************************************************
			@pmString = to be tested
				checks allowed string characters "A" to "Z", "a" to "z" and  "spaces"
		************************************************/
		//#-- trim starting and ending white spaces 
		var vCity = trim(pmString);
		
		//#-- check if the string is empty
		if(vCity == "")
			return (false);
		//#-- check if the browser support regular expersion	
		if(isRegExpSupported()) //#-- is regular experssion supported
		{	
			//#-- build the allowed character pattern
			var vPattern = "(^([a-zA-Z ]+)?)$";	//#-- set the pattern
			var vRegExp = new RegExp(vPattern);		//#-- create a new regular experson object
			return (vRegExp.test(vCity));		//#-- test and return status
		} //#-- end of regular experssion support
		
		//#-- build the character patern
		var vPattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
		
		for(var vI = 0; vI < vPattern.length ; vI ++)
			if(vPattern.indexOf(vCity.charAt(vI)) == -1) //#-- test and return status
				return (false);
		return (true);
	}
	
	function isValidZipcode(pmString)
	{
		/***************************************************
			@pmString = to be tested
				checks allowed characters "A" to "Z", "a" to "z" and "-"				
		***************************************************/
		
		var vZipcode = trim(pmString);//#--  trim the string
		var vNumFound = 0; 		//#-- initialize the flag value
		
		if(vZipcode == "") 		//#-- check empty and return value
			return (false);
				
		if(isRegExpSupported()) //#-- is regular experssion supported
		{
			//#-- loop check interger found in  the string
			for(var i=0; i < vZipcode.length; i++)
			{
				if(parseInt(vZipcode.indexOf(i)) != -1)
				{
					var vNumFound = 1; //#-- set flag value 
					break;
				}
			
			}
			if(vNumFound == 1)//#-- check the flag value
			{
				var vPattern = "(^([a-zA-Z0-9-]+)?)$"; //#-- set the pattern
				var vRegExp = new RegExp(vPattern); 	//#-- create a new regular exp
				return (vRegExp.test(vZipcode))			//#-- test and return value
			}
			else
				return (false); //#-- interger not found return false
		}
		//#-- regular experssion not supported
		vPattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxys0123456789-"; //#-- set the pattern
		for(var vI = 0; vI < vPattern.length; vI++)
		{
			if(parseInt(vZipcode.indexOf(vI)) != -1) //#-- integer found 
				var vNumFound = 1; //#-- set flag value 
			if(vPattern.indexOf(vZipcode.charAt(vI)) == -1 )//#-- parse the string and return value
				return false
		}
		return(vNumFound)?true:false; //#-- check the flag status and return value
				
	} //#-- end of isValidZibcode() function
	
	function wait(delay)
	{
		setTimeout("",delay);
	}


	function Keylock()
	{
		window.event.keyCode=0;
	}	
	function popup()
	{
		window.open();
	}
	
	function funNotAllowSpace(e)
	{
		var pNumKeyCode = (window.event) ? event.keyCode : e.keyCode;
		if (pNumKeyCode==32)
		{ //if the key isn't the backspace key (which we should allow)
			window.event.keyCode=0;
			return false //disable key press
		}
	}


	function CharCheck(pmString)
	{
		
		var num = 0;
	   for(var i = 0; i < pmString.length; i++)
	   {
		var c = pmString.charAt(i); 
		if(c == '.')
		num++;
	   }
	   if(num >1)
	   return false;
	   else
	   return true;
	}	