/////////////////////////////////////////////////////////////////////////////////////
//Login form Validation
////////////////////////////////////////////////////////////////////////////////////
function validateForm(form)
{	
	//check email field
	if(!checkEmail( form.user_email))
	{
		return false;
	}
	
	//for check empty e.g. Name,Address etc.
	if(!valid(form.pass,"Please fill Password"))
	{
		return false;
	}
	
	
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Search form Validation
///////////////////////////////////////////////////////////////////////////////
function validateSearchForm(form)
{	
		
	//for check empty e.g. Name,Address etc.
	if(!valid(form.searchtxt,"Please enter your serch keyword"))
	{
		return false;
	}
	
	
return true;
}
////////////////////////////////////////////////////////////////////////////////
//validation for empty field of Texbox,Textarea
function valid(theField,msg)
{
	if(theField.value.length==0)
	{
	     alert(msg);
	     theField.focus();
	     return false;
        }
        else
 	{
	     return true;
 	}

}
////////////////////////////////////////////////////////////////////////////////
//data is number or not

function IsNum(theField,fieldname)
{
var i;
   for (i = 0; i < theField.value.length; i++)
   {
        
        var c = theField.value.charAt(i);
        if (!IsDigitval(c)) 
        {
          
          theField.focus();
          alert(fieldname+" Field Must be Numeric");
          return false;
	}
   }
   return true;

}
function IsDigitval (c)
{   
	return (((c >= "0") && (c <= "9"))||(c == "."))
}

//////////////////////////////////////////////////////////////////////////////////////
//email check
var defaultEmptyOK = false;
var sEmail = "Email";
var iEmail = "This field must be a valid email address (like me@here.com). Please re-enter it now.";
var pEmail = "valid email address (like foo@bar.com).";

function isEmpty(s)
{   return ((s == null) || (s.length == 0));
}

function checkEmail (theField, emptyOK)
{ 
if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isValidEmail(theField.value))
       return warnInvalid (theField, iEmail);
    else return true;
}

function isEmail (emailStr)
{
    if (isEmpty(emailStr))
    if (isEmail.arguments.length == 1) return defaultEmptyOK;
    else return (isEmail.arguments[1] == true);

    emailStr = emailStr.replace(/^ +/,"");	//trim spaces from beginning
    emailStr = emailStr.replace(/ +$/,"");	//trim spaces from end
    

	var checkTLD=0;
    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=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) {
			return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}
	if (user.match(userPat)==null) {

		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			//alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name.  Check if it's valid.
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			//alert("The domain name does not seem to be valid.");
			return false;
		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
			domArr[domArr.length-1].search(knownDomsPat)==-1) {
			//alert("The address must end in a well-known domain or two letter " + "country.");
			return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
	//alert("This address is missing a hostname!");
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
	//  End -->
}

function warnInvalid (theField, s)
{   theField.focus();
    theField.select();
    alert(s);
    return false;
}


function isValidEmail (s)
{
	return isEmail(s);
}
//end email check