function valid2(str) {
	for(var i = 0; i < str.length; i++) {
		var charcode = str.charCodeAt(i);

		/* A-Z */
		if(charcode >= 0x41 && charcode <= 0x5A) {
			continue;
		}

		/* a-z */
		if(charcode >= 0x61 && charcode <= 0x7A) {
			continue;
		}

		/* 0-9 */
		if(charcode >= 0x30 && charcode <= 0x39) {
			continue;
		}

		/* . - _ */
		if(charcode == 0x2D || charcode == 0x2E || charcode == 0x5F) {
			continue;
		}

		return false;
	}

	return true;
}

function validEmail(email) {
	var atpos = email.indexOf("@");

	if(atpos == -1) {
		return false;
	}

	if(atpos == 0) {
		return false;
	}

	var dotpos = email.indexOf(".", atpos+2);

	if( dotpos == -1) {
		return false;
	}

	if(dotpos == (email.length - 1) ) {
		return false;
	}

	var fpart = email.substring(0,atpos);
	var host = email.substring(atpos + 1, dotpos);
	var domain = email.substr(dotpos +1);

	if(!( valid2(fpart) && valid2(host) && valid2(domain))) {
    
		return false;
	}

	var afterat = email.substr(atpos + 1);
	if(afterat.lastIndexOf(".") == (afterat.length - 1)) {
		return false;
	}

	for(var i = 1; i < afterat.length; i++) {
		if(afterat.charAt(i) == "." && afterat.charAt(i-1) == ".") {
			return false;
		}
	}

	return true;
}

function checkIt(evt)
{
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}




function valid(){

if(document.contact.fname.value=="" || document.contact.fname.value.length < 2){
window.alert('please fill your first name.');
return false;
}

if(document.contact.lname.value=="" || document.contact.lname.value.length < 3){
window.alert('please fill your last name.');
return false;
}

if(document.contact.title.value=="0"){
window.alert('please select your title.');
return false;
}

if(document.contact.company.value=="" || document.contact.company.value.length < 2){
window.alert('please fill your company name.');
return false;
}


if(document.contact.jobtitle.value=="" || document.contact.jobtitle.value.length < 2){
window.alert('please fill your jop title.');
return false;
}



if(document.contact.email.value=="" || document.contact.email.value.length < 3){
window.alert('please fill your email.');
return false;
}



if(!validEmail(document.contact.email.value)){
window.alert('please fill your email correctly.');
return false;
}


if(document.contact.phone.value=="" || document.contact.phone.value.length < 5){
window.alert('please fill your phone.');
return false;
}

if(document.contact.message_type.value=="0"){
window.alert('please select message topic.');
return false;
}

if(document.contact.message.value=="" || document.contact.message.value.length < 7){
window.alert('please fill your message.');
return false;
}



}



function Qvalid(){

if(document.contact.Pricing.value=="0"){
window.alert('please select your pricing request.');
return false;
}

if(document.contact.title.value=="0"){
window.alert('please select your title.');
return false;
}

if(document.contact.fname.value==""){
window.alert('please fill your first name.');
return false;
}

if(document.contact.lname.value==""){
window.alert('please fill your last name.');
return false;
}


if(!validEmail(document.contact.email.value)){
window.alert('please fill your email correctly.');
return false;
}


if(document.contact.phone.value==""){
window.alert('please fill your phone.');
return false;
}



if(document.contact.country.value=="0"){
window.alert('please select your country.');
return false;
}



if(document.contact.city.value==""){
window.alert('please fill your city.');
return false;
}


if(document.contact.Position.value==""){
window.alert('please fill your Job title/Position.');
return false;
}


if(document.contact.Company.value==""){
window.alert('please fill your company name.');
return false;
}

if(document.contact.businessType.value=="0"){
window.alert('please select your Business type');
return false;
}

if(document.contact.compNo.value==""){
window.alert('please fill the number of completed interviews per country');
return false;
}

if(document.contact.Countries.value==""){
window.alert('please fill countries needed');
return false;
}

if(document.contact.Target.value==""){
window.alert('please fill target Population');
return false;
}

if(document.contact.questionsNo.value==""){
window.alert('please fill number of Questions');
return false;
}

}


//validate email in news letter

function newsletterValid(){

if(document.newsL.t1.value==""){
window.alert('please fill your first name.');
return false;
}

if(document.newsL.t4.value==""){
window.alert('please fill your last name.');
return false;
}



if(document.newsL.t2.value==""){
window.alert('please fill your company name.');
return false;
}


if(document.newsL.t3.value=="" || validEmail(document.newsL.t3.value) == false){
window.alert('please fill a valid email.');
return false;
}

}


//validate email in news letter
function verifyEmail()
{
     
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (document.nls_up.t3.value.search(emailRegEx) == -1) {
          alert("Please enter a valid email address.");
          return false;
     }
     else 
     {
  document.nls_up.submit();
     }
    
}
