// Declaring required variables
	var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;

	function isInteger(s) {   
		var i;
    	for (i = 0; i < s.length; i++)  {   
	        // Check that current character is number.
    	    var c = s.charAt(i);
        	if (((c < "0") || (c > "9"))) return false;
    	}
    	// All characters are numbers.
    	return true;
	}

	function stripCharsInBag(s, bag) {   
		var i;
	    var returnString = "";
    	// Search through string's characters one by one.
	    // If character is not in bag, append to returnString.
    	for (i = 0; i < s.length; i++)  {   
	        // Check that current character isn't whitespace.
    	    var c = s.charAt(i);
        	if (bag.indexOf(c) == -1) 
				returnString += c;
    	}
    	return returnString;
	}

	function checkInternational(strPhone) {
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}

	function validateId(str) {
		n=str.length;
		if(str=="") {
	  	 return false;
		}
		for(i=0;i<n;i++) {
			v=str.charCodeAt(i);
			if((v>=48 && v<=57) || (v>=65 && v<=90) || (v>=97 && v<=122) || v==95) {
			} else {
				 return false;
				 break;
			}
		}
	}

	function validateText(str, must_have_value) {
		var v,n,i;
		n=str.length;
		
		if(str=="")	{
			if(must_have_value)
			  	return false;
			else
				return true;
		}
		if ( isInteger(str) )	
		   return false;

		for(i=0;i<n;i++)	{
			v=str.charCodeAt(i);
			if((v>=48 && v<=57) || (v>=65 && v<=90) || (v>=97 && v<=122) || v==95 || v==32 || v==39 || v==45 || v==35 || v==44 || v==46 || v==47 || v==13 || v==10 || v==3 || v==43) { 
			} else {
				return false;
			}
		}
		return true;
	}

	function validateName(str, must_have_value) {
		var v,n,i;
		n=str.length;
		if (str=="")	{
			if(must_have_value)
		  		return false;
			else
				return true;
		}
	
		for (i=0;i<n;i++)	{
			v=str.charCodeAt(i);
			if ((v>=48 && v<=57) || (v>=65 && v<=90) || (v>=97 && v<=122) || v==95 || v==32 || v==39 || v==45 || v==44) { 
			} else {
				return false;
			}
		}
		if(isNaN(str)){
			return true;
		} else {
			return false;
		}	
	}//function end

	function validatePass(str, must_have_value) {
		var v,n,i;
		n=str.length;
		if (str=="")	{
			if(must_have_value)
		  		return false;
			else
				return true;
		}
	
		for (i=0;i<n;i++)	{
			v=str.charCodeAt(i);
			if ((v>=48 && v<=57) || (v>=65 && v<=90) || (v>=97 && v<=122) || v==95 || v==39 || v==45 || v==44) { 
			} else {
				return false;
			}
		}
		if(isNaN(str)){
			return true;
		} else {
			return false;
		}	
	}//function end

	function validateNumber(str, must_have_value) {
		n=str.length;

		if(str=="" || parseInt(str) == 0)	{
			if(must_have_value)
			  	return false;
			else
				return true;
		}

		for(i=0;i<n;i++) {
			v=str.charCodeAt(i);
			if ( v>=48 && v<=57 ){
			} else
			   return false;
		}
		return true;
	}

	function validateFloat(str, must_have_value) {
		n=str.length;
		if(str=="" || parseInt(str) == 0)	{
			if(must_have_value)
			  	return false;
			else
				return true;
		}

		for(i=0;i<n;i++) {
			v=str.charCodeAt(i);
			if (( v>=48 && v<=57 ) || v==46){
			}
			else
			   return false;
		}
		return true;
	}


    function validateEmail(str, must_have_value) {
    
    	var email = str.toLowerCase();
    	var valid = "y";
    	
    	if (email==""){
    		if(must_have_value)
    			return false;
    		else
    			return true;
    	}
    	
    	if (email != "") {
    		if (email.length < 7 || 
    			email.indexOf("@.") != -1 ||
    			email.indexOf("-.") != -1 ||
    			email.indexOf("_.") != -1 ||
    			email.indexOf("..") != -1 ||
    			email.indexOf("._") != -1 ||
    			email.indexOf(".-") != -1 ||
    			email.indexOf(".@") != -1 ||
    			email.indexOf("@-") != -1 ||
    			email.indexOf("-@") != -1 ||
    			email.indexOf("@_") != -1 ||
    			email.indexOf("_@") != -1 ||
    			email.indexOf("@") != email.lastIndexOf("@") ||
    			email.indexOf("@") == -1 ||
    			email.indexOf(".") == -1 ||
    			(email.length - (email.lastIndexOf(".") + 1)) < 2) {
    				valid = "n";
    				return false;
    			} else {
    				a = "abcdefghijklmnopqrstuvwxyz0123456789@-_.";
    				b = 0;
    				while (b < email.length) {
    					if (a.indexOf(email.charAt(b)) == -1) {
    						valid = "n";
    						return false;
    						b = email.length;
    				}
    				b = b + 1;
    			}
    		}
    	}
    	
    	if (valid == "y") {
    		return true;
    	}
    
    }//function end

	function validatePhone(str,must_have_value) {
		var n = str.length;
		var temp = str;
		var j = 0;
		numbers_array = new Array();
		if(str=="")	{
			if(must_have_value)
			  	return false;
			else
				return true;
		}
		pre_position = 0;
		while(1){
			curr_position = temp.indexOf(',');
			if (curr_position <= 0){
				numbers_array[j] = temp.substring(pre_position,(temp.length));
				break;
			}
			numbers_array[j] = temp.substring(pre_position,curr_position);
			temp = temp.substring(curr_position+1,(temp.length));
			j++;
		}
        for(j = 0;;)
        {
	        m = 0;
			for(i=0;i<numbers_array[j].length;i++)
    	    {
        		v = numbers_array[j].charCodeAt(i);
		        if (( v>=48 && v<=57 ) || v==32 || v==40 || v==41 || v==45 || v==44 || v==43) {}
    		    else
        		   return false;
	        	if( v>=48 && v<=57 )
    		    	m = m+1;
        	}
	        if(m < 3)
				return false;
			if(++j == numbers_array.length)
    		    return true;
        }
	}
	
	function y2k(number) { return (number < 1000) ? number + 1900 : number; }

    function isDate (day,month,year) {
    // checks if date passed is valid
    // will accept dates in following format:
    // isDate(dd,mm,ccyy), or
    // isDate(dd,mm) - which defaults to the current year, or
    // isDate(dd) - which defaults to the current month and year.
    // Note, if passed the month must be between 1 and 12, and the
    // year in ccyy format.
    
        var today = new Date();
        year = ((!year) ? y2k(today.getYear()):year);
        month = ((!month) ? today.getMonth():month-1);
        if (!day) return false
        var test = new Date(year,month,day);
        if ( (y2k(test.getYear()) == year) &&
             (month == test.getMonth()) &&
             (day == test.getDate()) )
            return true;
        else
            return false
    }

    function validateURL(url,must_have_value) {
   /*   var re = /^(file|http|ftp):\/\/\S+\.(com|net|org|info|biz|ws|us|tv|cc)$/i; */
//      var re = /^(file|http|ftp):\/\/\S+\.([a-zA-Z0-9\-\.])$/i;

		var re = /^(file|http|ftp):\/\/\S+\.(com|net|org|info|biz|ws|us|tv|cc)$/i;	
	
//	var expression = new RegExp("^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\\\\+&%\$#\=~_\-]+))*$", "i");	  
//var re  = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)/i;

		if(url=="")	{
			if(must_have_value)
			  	return false;
			else
				return true;
		}

      if (re.test(url)) 
    	 return true;
      else 	
    	 return false;
    }

	function isFloat(str) {
		n=str.length;
		for(i=0;i<n;i++) {
			v=str.charCodeAt(i);
			if (v==46){
				return true;
			}
		}
		return false;
	}
