
//fxn to trim white spaces
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

//fxn to validate blank fields,  no blank allowed
function validateBlank(fldname)
{
	var check="ok";
	var tfld = trim(document.getElementById(fldname).value); // value of field with whitespace trimmed off
	
	 if (document.getElementById(fldname).value == "") 
	{
        check = "Please Enter "+document.getElementById(fldname).title;
    } 
    return check;
}

//fxn to validate first and last name,  just single word only
function validateName(flname)
{
	var check="ok";
	var nameRegex = /^\s*[a-zA-z]{1,}\s*$/;
	var tfld = trim(document.getElementById(flname).value); // value of field with whitespace trimmed off
	
	 if (document.getElementById(flname).value == "") 
	{
        check = "Please Enter "+document.getElementById(flname).title;
    } else if (!nameRegex.test(tfld)) 
	{              //test email for illegal characters
        check = "Invalid "+document.getElementById(flname).title;
    }
    return check;
}

//fxn to validate fullname,  just two words only
function validateFullName(fullname)
{
	var check="ok";
	var fullnameRegex = /^\s*[(a-zA-z){1,}\s]+[a-zA-Z]{1,}\s*$/;
	var tfld = trim(document.getElementById(fullname).value); // value of field with whitespace trimmed off
	
	 if (document.getElementById(fullname).value == "") 
	{
        check = "Please Enter Fullname";
    } else if (!fullnameRegex.test(tfld)) 
	{              //test email for illegal characters
        check = "Invalid First Fullname";
    }
    return check;
	
}

//fxn to validate phone number starting with 0 or 1
function validatePhone(phone) {
    
	
	var check="ok";
	var phoneRegex = /^[0-9]{8,}$/;
	var tfld = trim(document.getElementById(phone).value); // value of field with whitespace trimmed off
	
	 if (document.getElementById(phone).value == "") 
	{
        check = "Please Enter Phone Number";
    } else if (!phoneRegex.test(tfld)) 
	{              //test email for illegal characters
        check = "Invalid Phone Number";
    }
    return check;
	
}

//fxn to validate email addresses
function validateEmail(email) {
	var check="ok";
    var tfld = trim(document.getElementById(email).value); // value of field with whitespace trimmed off
    //var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
   //var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	var emailRegex= /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
   
    if (document.getElementById(email).value == "") 
	{
        check = "Please Enter Email Address";
    } 
	else if (!emailRegex.test(tfld)) 
	{              //test email for illegal characters
        check = "Invalid Email Address";
    }
	/*else if (document.getElementById(email).value.match(illegalChars)) 
	{
        check = "Invalid Email Address\nValid Email Format: abcd@xyz.com";
    }
	*/
    return check;
}

function validateSelectList(listID,listText)
{
	var check="ok";
	if(document.getElementById(listID).selectedIndex==0)
		check = "Please select "+listText;
	
	return check;
}

function validateCaptcha(recapt_hash,recapt_input)
{
	var check="ok";
	hash = hex_md5(document.getElementById(recapt_input).value);
	if(document.getElementById(recapt_hash).value!=hash)
		check = "Invalid Security Text";
	
	return check;

}
