// function to trim leading & trailing spaces
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

/*
1. PHONE NUMBER VALIDATION
Usage: 
Element � name of the control, like frm.phone
Message � Field Name that we want to display in alert message.
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

 if(!isValidPhone(frm.phone,'Phone Number','yes'))
 return;
*/

function isValidPhone(element, msg, required)
{	
	var VarPhone = element.value;
	if (VarPhone== "")
	{	
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}
	if (VarPhone != "")
	{
		var Phno;
		Phno=VarPhone;
		var valid = "-0123456789()";
		var hyphencount = 0;
		for (var i=0; i < Phno.length; i++) 
		{
			temp = "" + Phno.substring(i, i+1);
			if (valid.indexOf(temp) == "-1")
			{
				alert("Invalid characters in your "+msg+". Please try again.");
				element.focus();
				return false;
			}
		}
     } 
	 return true;      
}

/*
2. NUMBER VALIDATION
Usage:
Element � name of the control, like frm.number
Message � Field Name that we want to display in alert message.
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

 if(!isValidNumber(frm.num,'Roll Number','yes'))
 return;
*/
function isValidNumber(element, msg, required)
{  
	var VarNumber = element.value;
	if(VarNumber == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}
	if (VarNumber != "")
	{
		var Num;
		Num=VarNumber;
		var valid = "-0123456789";
		var hyphencount = 0;
		
		for (var i=0; i < Num.length; i++) 
		{
			temp = "" + Num.substring(i, i+1);
			if (valid.indexOf(temp) == "-1")
			{
			  alert("Invalid characters in your "+msg+".  Please try again.");
			  element.focus();
			  return false;
			}
	   } // end for loop
	   
		if(VarNumber < 1)
		{
			alert(msg+" is not a valid number");
			element.focus();
			return false;
		}
    }   // end if
    return true; 
}  // end function

/*
3. EMAIL ADDRESS VALIDATION

Usage: 
Element � name of the control, like frm.email
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

	 if(!isValidEmail(frm.email,'yes'))
	 return;
*/

function isValidEmail(element, required)
{
	var VarEmail = element.value;
	if(VarEmail == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter email address");
			element.focus();
			return false;
		}
	}	
	if(VarEmail != "")
	{
		var emailStr = VarEmail;
		 
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var firstChars=validChars
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom="(" + firstChars + validChars + "*" + ")"
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) 
		{
			 alert("Email address seems to be incorrect (check @ and .'s)");
			 element.focus();
			 return false;
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		if (user.match(userPat)==null) 
		{
			alert("The username doesn't seem to be valid.");
			element.focus();
			return false;
		}
		
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) 
		{
			for (var i=1;i<=4;i++) 
			{
				if (IPArray[i]>255) 
				{
					 alert("Destination IP address is invalid!");
					 element.focus();
					 return false;
				}
			}
		}
		var domainArray=domain.match(domainPat)
		if (domainArray==null) 
		{
			alert("The domain name doesn't seem to be valid.");
			element.focus();
			return false;
		}
		var atomPat=new RegExp(atom,"g");
		var domArr=domain.match(atomPat);
		var len=domArr.length;
		if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
		{
		   alert("The address must end in a three-letter domain, or two letter country.");
		   element.focus();
		   return false;
		}
		if (domArr[domArr.length-1].length==2 && len<2) 
		{
			var errStr = "This address ends in two characters, which is a country";
			errStr    += " code.  Country codes must be preceded by ";
			errStr	  += "a hostname and category (like com, co, pub, pu, etc.)";
			alert(errStr);
			element.focus();
			return false;
		}
		if(domArr[domArr.length-1] == 'ru')
		{
			alert("The domain name doesn't seem to be valid.");
			element.focus();
			return false;
		}
		if (domArr[domArr.length-1].length==3 && len<2) 
		{
			 var errStr="This address is missing a hostname!";
			 alert(errStr);
			 element.focus();
			 return false;
		}
	}
	return true;
}

/* 
4. ZIPCODE/PINCODE  VALIDATION

Usage:
	Element � name of the control, like frm.zipcode
	Required � Set this to �yes� if the field is mandatory, otherwise �no�.

	if(!isValidZipcode(frm.zip,'yes'))
	return;
*/
function isValidZipcode(element,required) 
{
	var valid = "0123456789-";
	var hyphencount = 0;
	var field = element.value;
	var str   = required;
	if(field == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter postcode");
			element.focus();
			return false;
		}
	}	
	if (field != "")
	{
		if (field.length!=6 && field.length!=5 && field.length!=10) 
		{
			alert("Postcode length should be 6( forIndia) , or 5 (without hyphens) or 10 with Including Hyphens ( for USA)....");
			element.focus();
			return false;
		}
		for (var i=0; i < field.length; i++) 
		{
			temp = "" + field.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1")
			{
				alert("Invalid characters in your post code.  Please try again.");
				element.focus();
				return false;
			}
			if ((hyphencount > 1) || ((field.length==10) && "" + field.charAt(5)!="-")) 
			{
				alert("The hyphen character should be used with a properly formatted 5 digit+four post code, like '12345-6789'.   Please try again.");
				element.focus();
				return false;
			}
		}
	}
	return true;
}

/*
5. ALPHA VALIDATION
//to find if the field contains alphabets only
usage:
Element � name of the control, like frm.firstname
Message � Field Name that we want to display in alert message.
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

 if(!isValidAlphabet(frm.firstname,'First Name','yes'))
 return;
*/

function isValidAlphabet(element, msg, required)
{
	var i=0;
	var ValidData="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._- ";
	var Data=element.value;
	if(element.value == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}	
	if(element.value != "")
	{
		for(i=0;i<Data.length;i++)
		{
			if(ValidData.indexOf(Data.charAt(i))==-1)
			{
				alert("PLease enter Non-Numeric Data Only");
				element.focus();
				return false;
			}
		}
	}
    return true;
}

/*
6. ALPHANUMERIC VALIDATION
//to check if the field contains both alphabets and numbers
usage:
Element � name of the control, like frm.firstname
Message � Field Name that we want to display in alert message.
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

 if(!isValidAlphaNumeric(frm.firstname,'First Name','yes'))
 return;
*/

function isValidAlphaNumeric(element, msg, required)
{
	var i=0;
	var ValidData=". ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/_- ";
	var Data=element.value;
	
	if(element.value == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}	
	if(element.value != "")
	{
		for(i=0;i<Data.length;i++)
		{
			if(ValidData.indexOf(Data.charAt(i))==-1)
			{
				alert("Invalid entry.\t\t");
				element.focus();
				return false;
			}
		}
	}
	return true;
}

function isValidAlphaNumericForNames(element, msg, required)
{
	var i=0;
	var ValidData=".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/_- ";
	var Data=element.value;

	if(element.value == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}	
	if(element.value != "")
	{
		for(i=0;i<Data.length;i++)
		{
			if(ValidData.indexOf(Data.charAt(i))==-1)
			{
				alert("Invalid entry.\t\t");
				element.focus();
				return false;
			}
		}
	}
	return true;
}

/*
7. URL VALIDATION

Usage:
Element � name of the control, like frm.url
Message � Field Name that we want to display in alert message.
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

	 if(!isValidURL(frm.url, "URL", "yes")) 
	 return;
*/
function isValidURL(element, msg, required)
{
	if(element.value == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}
	if(element.value != "")
	{
		var oRegExp = /[^:]+:\/\/[^:\/]+(:[0-9]+)?\/?.*/;
		if (!oRegExp.test(element.value))
		{
			alert('\r\n The URL you have entered is invalid.\n Please check it for accuracy.');
			element.focus();
			element.select();
			return false;
		}
	}
	return true;
}

/*
8. DATE VALIDATION

Usage:
Element � name of the control, like frm.date
Message � Field Name that we want to display in alert message.
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

Valid date formats are MM-DD-YYYY, MM/DD/YYYY and MM.DD.YYYY  

	 if(!isValidDate(frm.startdate, "Started Date", "yes")) 
	 return;
*/
function isValidDate(element, msg, required) 
{
	var dateStr = element.value;
	var valid = "0123456789-/.";
	var temp = "";
	var hyphencount = 0 ;
	var slashcount = 0 ;
	var dotcount = 0 ;
	if(element.value == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}
	if(element.value != "")
	{
		for (var i=0; i < dateStr.length; i++)
		{
			temp = "" + dateStr.substring(i, i+1);
			 if  (temp == "-")  { hyphencount++; }
				else  if (temp == "/")  {  slashcount++; }
				   else  if (temp == ".") { dotcount++; }
			if ( ( hyphencount == 2 ) || ( slashcount == 2 ) || ( dotcount == 2 ) )
			{
				t=dateStr.substring(6,10);
				if(t.length==4)
				{
					if(t<1900)
					 {
						alert("the century of date should be greater than or equal to 1900.");
						element.focus();
						return false;
					 }
				}
			}          
			if (valid.indexOf(temp) == "-1")
			{
				alert("Invalid characters in your date.  Please try again.");
				element.focus();
				return false;
			}
		} //end of for loop   
		//alert ( "hyphen  " + hyphencount + " slash " + slashcount + " dot " + dotcount )  ; 
		if ( ( hyphencount== 2) & (slashcount !=2) && (dotcount !=2) ) {}
		else if ( ( hyphencount!= 2) & (slashcount ==2) && (dotcount !=2) ) {}
		else if ( ( hyphencount!= 2) & (slashcount !=2) && (dotcount ==2) ) {}
		else 
		{	
			alert("The hyphen or slashes character should be used with a properly formatted. Please try again.");
			element.focus();
			return false;
		}
		   
		if (dateStr.length == 8 || dateStr.length == 10 )
		{
			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
			var matchArray = dateStr.match(datePat); // is the format ok?
			if (matchArray == null) 
				return true;
	
			month = matchArray[1]; // parse date into variables
			day = matchArray[3];
			year = matchArray[4];
			//alert(matchArray[1]);
			//alert(matchArray[3]);
			//alert(matchArray[4]);
			
			if (month < 1 || month > 12) 
			{ // check month range
				alert("Month must be between 1 and 12.");
				element.focus();
				return false; 
			}
			if (day < 1 || day > 31) 
			{
				alert("Day must be between 1 and 31.");
				element.focus();
				return false; 
			}
			if ((month==4 || month==6 || month==9 || month==11) && day==31) 
			{
				alert("Month "+month+" doesn't have 31 days!")
				element.focus();
				return false; 
			}
			if (month == 2) 
			{ // check for february 29th
				var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
				if (day>29 || (day==29 && !isleap))
				{
					alert("February " + year + " doesn't have " + day + " days!");
					element.focus();
					return false;
				}
			} // end of month = 2 condition
		} // end of date string length = 8 or length = 10 condition
		else 
		{
		   alert("Entered date is invalid format, Date should be 8 to 10 chars. length.");
		   element.focus();
		   return false;
		} 
	}
	return true;  // date is valid
}

/*
8. DATE VALIDATION - 2

Usage:
Element � name of the control, like frm.date
Message � Field Name that we want to display in alert message.
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

Valid date formats are DD-MM-YYYY, DD/MM/YYYY and DD.MM.YYYY  

	 if(!isValidDate(frm.startdate, "Started Date", "yes")) 
	 return;
*/
function isValidDate2(element, msg, required) 
{
	var dateStr = element.value;
	var valid = "0123456789-/.";
	var temp = "";
	var hyphencount = 0 ;
	var slashcount = 0 ;
	var dotcount = 0 ;
	if(element.value == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}
	if(element.value != "")
	{
		for (var i=0; i < dateStr.length; i++)
		{
			temp = "" + dateStr.substring(i, i+1);
			 if  (temp == "-")  { hyphencount++; }
				else  if (temp == "/")  {  slashcount++; }
				   else  if (temp == ".") { dotcount++; }
			if ( ( hyphencount == 2 ) || ( slashcount == 2 ) || ( dotcount == 2 ) )
			{
				t=dateStr.substring(6,10);
				if(t.length==4)
				{
					if(t<1900)
					 {
						alert("the century of date should be greater than or equal to 1900.");
						element.focus();
						return false;
					 }
				}
			}          
			if (valid.indexOf(temp) == "-1")
			{
				alert("Invalid characters in your date.  Please try again.");
				element.focus();
				return false;
			}
		} //end of for loop   
		//alert ( "hyphen  " + hyphencount + " slash " + slashcount + " dot " + dotcount )  ; 
		if ( ( hyphencount== 2) & (slashcount !=2) && (dotcount !=2) ) {}
		else if ( ( hyphencount!= 2) & (slashcount ==2) && (dotcount !=2) ) {}
		else if ( ( hyphencount!= 2) & (slashcount !=2) && (dotcount ==2) ) {}
		else 
		{	
			alert("The hyphen or slashes character should be used with a properly formatted. Please try again.");
			element.focus();
			return false;
		}
		   
		if (dateStr.length == 8 || dateStr.length == 10 )
		{
			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
			var matchArray = dateStr.match(datePat); // is the format ok?
			if (matchArray == null) 
				return true;
	
			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
			//alert(matchArray[1]);
			//alert(matchArray[3]);
			//alert(matchArray[4]);
			
			if (month < 1 || month > 12) 
			{ // check month range
				alert("Month must be between 1 and 12.");
				element.focus();
				return false; 
			}
			if (day < 1 || day > 31) 
			{
				alert("Day must be between 1 and 31.");
				element.focus();
				return false; 
			}
			if ((month==4 || month==6 || month==9 || month==11) && day==31) 
			{
				alert("Month "+month+" doesn't have 31 days!")
				element.focus();
				return false; 
			}
			if (month == 2) 
			{ // check for february 29th
				var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
				if (day>29 || (day==29 && !isleap))
				{
					alert("February " + year + " doesn't have " + day + " days!");
					element.focus();
					return false;
				}
			} // end of month = 2 condition
		} // end of date string length = 8 or length = 10 condition
		else 
		{
		   alert("Entered date is invalid format, Date should be 8 to 10 chars. length.");
		   element.focus();
		   return false;
		} 
	}
	return true;  // date is valid
}

/*
9. SELETC VALIDATION

Usage:
Element � name of the control, like frm.firstname
Message � Field Name that we want to display in alert message.

if(!isValidSelect(frm.country,'Country'))
return;
*/
function isValidSelect(element,msg) 
{
	if(element.value == "0") 
	{
		alert("Please select "+msg+" from the list");
		element.focus();
		return false;
	}
	return true;
}

/*
10. FUNTION SELECTALL CHECK BOXES

Usage:
frm � name of the form

SelectAll(frm);
*/

function SelectAll(frm) {
	 //alert(frm.selectall.checked);
	   if(frm.selectall.checked == true) {
	   
		 for(sel=0;sel<frm.elements.length;sel++) {
		   if((frm.elements[sel].type == "checkbox") && (frm.elements[sel].name != "selectall")) {
			 frm.elements[sel].checked = true;
		   } // if statement
		 } // for loop
	   }
	   else if(frm.selectall.checked == false) {
		
		  for(sel=0;sel<frm.elements.length;sel++) {
			 if((frm.elements[sel].type == "checkbox") && (frm.elements[sel].name != "selectall")) {
			   frm.elements[sel].checked = false;
			 } // if statement
		  } // for loop
	   } // if - else - if condition
	} // closing the function SelectAll()
	
/*
11. IS LEAP YEAR

Usage:  Y � year
If the given year is a leap year, this function will return true. otherwise false.
isLeapYear('2004');

*/
function isLeapYear(y) 
{
	if( y % 4 == 0) 
	{
		if( y % 100 == 0 ) 
		{
			if( y % 400 == 0) 
			{
				return true;
			}
			else 
			{
				return false;
			}
		}
		else 
		{
			return true;
		}
	}
	else 
	{
		return false;
	}
} // closing the function isLeapYear()

/*
12. CONFIRM PASSWORD

Usage:
Element1� name of the first control like frm.password.
Element2� name of the second control like frm.confirmpassword.

if(!isValidConfirmPassword(frm.pwd, frm.conpwd))
return;
*/
function isValidConfirmPassword(element1,element2) 
{
	if(element1.value != element2.value)
	{
		alert("Retype Password doesn't match");
		element2.focus();
		return false;
	}
	else
		return true;
} // closing the function PassValidation()

/*
13. GET COUNT OF

Usage:
This can be used for any character validation.
For example in a valid date the count of - or / should not be more than 2
Likewise in a valid numer there should be only one.

*/
function getCountOf(vChr, txt)
{
	var i = 0;
	var iCount = 0;
	for( i=0; i < txt.length; i++ )
	{
		if( txt.charAt(i) == vChr )
		{
			iCount++;
		}
	}
	return iCount;
}

/*
14. IS BLANK
To check if trim(value) is blank
Usage:
	This fucntion can be used to check if a given text contains only spaces or 0 in length.

	INPUT: Text [txt]
				Minimum Length [minlen] optional
				Indicates that the text should be atleast 'minlen' in length


	OUTPUT: returns true if blank else false

*/	
function isBlank(txt, minlen)
{
	if( txt.length == getCountOf('\n', txt) )
	{
		// This condition avoids the entry of just newlines in text areas.
		return true;
	}
	if( txt.length == getCountOf(' ', txt) || txt.length == 0 )
	{
		return true;
	}
	else if( minlen > 0 )
	{
		if( txt.length < minlen )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
	return true;
}

/*
15. INCLUDE SPECIAL CHARACTER

In some cases, we want to validate whether a given value contains at 
least one special character or not. Below mentioned function will be useful 
for such situations.

Usage:
	Element � name of the control like frm.password.
	Message � Field Name that we want to display in alert message.

if(!isSplchar(frm.pwd, "Password"))
return;
*/
function isSplchar(element, msg)
{
	var alp = '!@#$%&*_1234567890';
	var count = 0;
	for (var i=0;i<element.value.length;i++)
	{
		temp=element.value.substring(i,i+1);
		if (alp.indexOf(temp)!= -1)
		{
			count = 1;
		}
	} // closing the for loop
	if(count == 0)
	{
	  alert(msg+" should contain atleast one special character (!,@,#,$,%,&,*, _  and numbers can be used).");
	  element.focus();
	  return false;
	}
	return true;
}
 
/*
16. isValidEntry

Usage:
	Element � name of the control like frm.password.
	Message � Field Name that we want to display in alert message.

if(!isValidEntry(frm.name, "Name"))
return;
*/
function isValidEntry(element,msg) 
{
	if(element.value.length == 0)
	{
		alert("Please enter the "+ msg);
		element.focus();
		return false;
	}
	else if(isBlank(element.value))
	{
		alert("Please enter the "+ msg);
		element.focus();
		return false;
	}
	return true;
} // closing the function GenValidation()

/*
17.  FUNCTION SPLCHARACTERS(element)
No speaicl Characters
This function will not accept any special characters.
Valid entries for this function are [a-z][A-Z][0-9][ _ ].
Usage:
	Element � name of the control like frm.password.

if(!noSplChars(frm.name))
return;
*/

function noSplChars(element) 
{
	var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
	for (var i=0;i<element.value.length;i++)
	{
		temp=element.value.substring(i,i+1);
		if (alp.indexOf(temp)==-1)
		{
			alert("No special characters\r\nValid entries are [a-z][A-Z][0-9][ _ ]");
			element.focus();
			return false;
		}
	} // closing the for loop
	 return true;
} // closing the function SplCharacters()

/*
18. SplCharactersSpace
Valid entries for this function are [a-z][A-Z][0-9][ space ].
Usage:
	Val � specify the value which we are going to validate.

if(!noSplCharsExSpace(frm.name.value))
return;
*/	
function noSplCharsExSpace(Val)
{
	var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";

	for (var i=0;i<Val.value.length;i++){
		temp=Val.value.substring(i,i+1);
		if (alp.indexOf(temp)==-1){
			alert("No special characters \nValid entries are [a-z][A-Z][0-9][ space ]");
			Val.focus();
			return false;
		}
	} // closing the for loop
	return true;
} // closing the function SplCharactersSpace()

/*

19. FUNCTION SPLNUMBERS(element) 

if(!SplNumbers(frm.num.value))
return;
*/
	
function SplNumbers(Val)
{
	var alp = "0123456789+-";
	for (var i=0;i<Val.value.length;i++)
	{
		temp=Val.value.substring(i,i+1);
		if (alp.indexOf(temp)==-1)
		{
			alert("No special characters \nValid entries are [0-9][ + - ]");
			Val.focus();
			return false;
		}
	} // closing the for loop
	return true;
} // closing the function SplNumbers()

/*
20.
	This function checks if the characters in a given text are part of a given character set.

	INPUT:	Text ti be verified [txt]
				String of character that forms the reference [charset]

	OUTPUT: Returns true if all of the characters in txt are part of charset, else false.

	USAGE:
	for example:

		checkInCharSet( "guru", "aeiouAEIOU" ) this fucntion returns false as "guru" contains 'g' and 'r'
		whcih are not part of "aeiouAEIOU".

		checkInCharSet( "abC", "abcdefABCDEF" ) this statement returns true as all "abC" contains characters
		that are present in "abcdefABCDEF"
*/
function checkInCharSet(txt, charset)
{
	var b = true;
	for(i = 0; i < txt.length; i++ )
	{
		if( charset.indexOf(txt.charAt(i)) == -1 )
		{
			b = false;
		}
	}
	return b;
}

/*
21. GET SELECTED INDEX
This can used while validating radio button groups. 
If none of the buttons is selected then the function	
returns -1 else the id.

E.g: frm is the name of a form and radSearchType is the radiobutton group name.

if( getSelectedIndex(frm.radSearchType) == -1 )
{
	alert("Please select search type." );
	frm.radSearchType[0].focus();
	return;
}

*/
function getSelectedIndex(radgroup)
{
	/* Returns back the id of selected radio button in a radio button group  */
	var re = -1;
 	if(radgroup.length)   
	{
		for( pe=0; pe < radgroup.length; pe++ )
		{
			if(radgroup[pe].checked)
			{
				re = pe;
			}
		}
	}
	return re;
}

/*
22. TextareaValidation(elem,msg,len)
This function can be used to validate the length of Text area's in forms.
For example...if the value of text area should not exceed 500 characters.

Arguments :
elem : The element(TextArea)
msg : Message to be alerted
	  For example "Description"
len : Noof characters not to be exceeded

E.g: frm is the name of a form and desc is a text area name.

Usage in form: 
if(!isValidTextarea(frm.desc,'Description',500))
return;
*/

function isValidTextarea(elem,msg,len) 
{
	if(elem.value.length > 0)
	{

		if(isBlank(elem.value)) 
		{
			alert("Please enter the value");
			elem.focus();
			return false;
		}
		else if(elem.value.length > len) 
		{
			alert(msg+" should not exceed "+len+" characters");
			elem.focus();
			return false;
		}	
	}
	return true;
} // closing the function TextareaValidation()

	/**
	 FUNCTION GENVALIDATION(element.message1,message2,spl) 
	 **/
	
	function GenValidation(Element,MessageLen0,MessageLen4,spl) {
		
		if(MessageLen0.length != 0)
		{
			if(Element.value.length == 0)
			{
				alert("Please Enter "+ MessageLen0+".");
				Element.focus();
				return 0;
			}
			else if(isBlank(Element.value))
			{
				alert("Please enter "+ MessageLen0+".");
				Element.focus();
				return 0;
			}
		}
	
		if(MessageLen4.length != 0)
		{
			if(Element.value.length < 4)
			{
				alert( MessageLen4 + " should be more than 4 characters");
				Element.focus();
				return 0;
			} // closing the if - else condtion for if(MessageLen4.length != 0)
		}
	
		if(spl == "spl")
		{
			if(SplCharacters(Element) == 0)
			return 0;
		}
		else if(spl == "space")
		{
			if(SplCharactersSpace(Element) == 0)
			return 0;
		}
	} // closing the function GenValidation()

function isValidPrice(element, msg, required)
{  
	var VarNumber = element.value;
	if(VarNumber == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}
	if (VarNumber != "")
	{
		var Num;
		Num=VarNumber;
		var valid = "0123456789.";
		var hyphencount = 0;
		
		for (var i=0; i < Num.length; i++) 
		{
			temp = "" + Num.substring(i, i+1);
			if (valid.indexOf(temp) == "-1")
			{
			  alert("Invalid characters in your "+msg+".  Please try again.");
			  element.focus();
			  return false;
			}
	   } // end for loop
	   
		if(VarNumber < 1)
		{
			alert(msg+" is not a valid number");
			element.focus();
			return false;
		}
    }   // end if
    return true; 
}  // end function

// for validation of radio buttons
function isRadioCheck(element,msg)
{
	flag = 0;
	for(var i = 0; i<element.length; i++)
	{
		if(element[i].checked == true)
		flag = 1 ;
	}
	if(!flag)
	{
		alert("Please choose the "+msg);
		return false;
	}
	else
		return true;
}

/*
ALPHA VALIDATION with out period(.)
//to find if the field contains alphabets only
usage:
Element � name of the control, like frm.firstname
Message � Field Name that we want to display in alert message.
Required � Set this to �yes� if the field is mandatory, otherwise �no�.

 if(!isValidPureAlphabet(frm.firstname,'First Name','yes'))
 return;
*/

function isValidPureAlphabet(element, msg, required)
{
	var i=0;
	var ValidData="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_- ";
	var Data=element.value;
	if(element.value == "")
	{
		var rval = trim(required);
		if (rval.toLowerCase() == "yes" || rval == 1)
		{
			alert("Please enter "+msg);
			element.focus();
			return false;
		}
	}	
	if(element.value != "")
	{
		for(i=0;i<Data.length;i++)
		{
			if(ValidData.indexOf(Data.charAt(i))==-1)
			{
				alert("PLease enter Non-Numeric Data Only");
				element.focus();
				return false;
			}
		}
	}
    return true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ShowHide(hide_div,show_div)
{
	if(hide_div != '')	
		document.getElementById(hide_div).style.display = "none";
	if(show_div != '')
		document.getElementById(show_div).style.display = "block";
}

//var xhReq = createXMLHttpRequest();	 


function displayTimes(user_ip,from_page,full_page_path,browser_type,mod_id,user_id,user_type) {
	
	//xhReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var requestpost = "user_ip="+user_ip+"&logon_time="+OnTimeValue+"&logoff_time="+OffTimeValue+"&time_on_page="+PageTimeValue+"&from_page="+from_page+"&full_page_path="+full_page_path+"&browser_type="+browser_type+"&module_id="+mod_id+"&user_id="+user_id+"&user_type="+user_type;
	
	xhReq.open("POST", gSitePath+"ajax/post_times.php?"+requestpost, true);
	xhReq.onreadystatechange = function(){};
	xhReq.send(null);
}

function getLogonTime() 
{
var now = new Date();
var Hours = now.getHours();
var Minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
var Seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
var month = now.getMonth()+1;
var toDayon = now.getFullYear()+"-"+month+"-"+now.getDate();
OnTimeValue =(toDayon+" "+Hours+Minutes+Seconds);
onHours = now.getHours();
onMinutes = now.getMinutes();
onSeconds = now.getSeconds();  
}

function getLogoffTime(user_ip,from_page,full_page_path,browser_type,mod_id,user_id,user_type)
{	
var now = new Date();
var Hours = now.getHours();
var Minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
var Seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
var month = now.getMonth()+1;
var toDayoff = now.getFullYear()+"-"+month+"-"+now.getDate();
OffTimeValue =(toDayoff+" "+Hours+ Minutes+ Seconds);
offHours = now.getHours();
offMinutes = now.getMinutes();
offSeconds = now.getSeconds();

//calculating time difference 
	if (offSeconds >= onSeconds)
	{ 
		logSeconds = offSeconds - onSeconds; 
	}
	else
	{
		offMinutes -= 1;
		logSeconds = (offSeconds + 60) - onSeconds;      
	}
	if (offMinutes >= onMinutes)
	{ 
		logMinutes = offMinutes - onMinutes;
	}
	else
	{
		offHours -= 1;
		logMinutes = (offMinutes + 60) - onMinutes;
	}
	logHours = offHours - onHours;
	logHours =  ((logHours < 10) ? "0" : ":") + logHours;
	logMinutes = ((logMinutes < 10) ? ":0" : ":") + logMinutes;
	logSeconds = ((logSeconds < 10) ? ":0" : ":") +logSeconds;
	PageTimeValue =(" "+ logHours+ logMinutes+ logSeconds);
	displayTimes(user_ip,from_page,full_page_path,browser_type,mod_id,user_id,user_type);
}

function keypress_int(e) {
	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if(e.which) {
		// netscape
		key = e.which; 
	}
	else {
		// no event, so pass through
		//return true;
	}
  keychar = String.fromCharCode(key);
  if(key == 8 || typeof(key) == 'undefined')
  	return true;
  if(!isInteger(keychar))
    		return false; // cancel event otherwise
}

function isInteger(s){
	var alp = "0123456789";
	for (var i=0;i<s.length;i++)
	{
		var c = s.charAt(i);
		temp=c.substring(i,i+1);
		if (alp.indexOf(temp)==-1)
			return false;
	} // closing the for loop
	return true;
}

function isUrlType(obj) {
	var regexphttp = /(.){0,}?http:\/\/?(.){0,}/;
	var regexpwww = /(.){0,}?w{3}?(.){0,}/;
 	if(regexphttp.test(obj.value) || regexpwww.test(obj.value))
	{
		alert("Should not be Allow the URLs");
		obj.focus();
		return false;
	}
	return true;
}
//Contador de caracteres.
function checkChar(obj, msg, maxchars) 
{
  var longitud=maxchars - obj.value.length;
  if(longitud <= 0) 
  {
    alert(msg+" should not exceeded more than "+maxchars+" chars");
	obj.value=obj.value.substr(0,maxchars-1);
	return false;
  }
  return true;
}
function add_fav(u_id)
{
	
	var url = gSitePath+'members/ajax/users_fav.php?user_id='+u_id+'&hid_act='+'add_to_rom';
	xhReq.open("GET", gSitePath+'members/ajax/ajx_favouriteusers.php?user_id='+u_id+'&hid_act='+'add_to_rom',true); 
	xhReq.onreadystatechange = onSumResponsefavouritedetails;
	xhReq.send(null);
	window.open (url,"newwindow","menubar=1,resizable=1,width=500,height=250");
}

function onSumResponsefavouritedetails()
{
	if (xhReq.readyState == 4) 
    { 
	 	var serverResponse = xhReq.responseText;
		document.getElementById("msg_div").innerHTML = serverResponse;
	}
}

function add_rom(u_id)
{
	var url = gSitePath+'members/ajax/users_rom.php?user_id='+u_id+'&hid_act='+'add_to_rom';
	xhReq.open("GET", gSitePath+'members/ajax/ajx_romanticusers.php?user_id='+u_id+'&hid_act='+'add_to_rom',true); 
	xhReq.onreadystatechange = onSumResponseromanticdetails;
	xhReq.send(null);
	window.open (url,"newwindow","menubar=1,resizable=1,width=500,height=250");
}

function onSumResponseromanticdetails()
{
	if (xhReq.readyState == 4) 
    { 
	 	var serverResponse = xhReq.responseText;
		document.getElementById("msg_div").innerHTML = serverResponse;
	}
}

//function to display the preview of the wink to be sent to the new user.
function wink_preview(frm,u_id,page)
{
	var path = frm.site_path.value;
	var url = path+'/members/'+page+'.php';
	frm.user_id.value = u_id;
	frm.action = url;
	frm.submit();
}

//function to display the Compose Mail feature when the user is fully subscribed user.
function goto_composemail(frm,u_id,page)
{
	var path = frm.site_path.value;
	var url = path+'/messages/'+page+'.php';
	frm.user_id.value = u_id;
	frm.action = url;
	frm.submit();
}

//function to open messenger window
function openMsgr()
{
	var url = gSitePath+'messenger/index.php';
	window.open (url,"msgrwindow","menubar=0,resizable=1,addressbar=0,width=200,height=350");
}

//function to display the list of videos when the user is fully subscribed user.
function display_allvideos(frm,u_id,page)
{
	var path = frm.site_path.value;
	var url = path+'/members/'+page+'.php';
	frm.user_id.value = u_id;
	frm.action = url;
	frm.submit();
}
<!-- -->