function newQuoteValidation2(this_form)
{
	var flag_submit = 0;
	var error_field;
	
	with (this_form)
	{	
		if(!validateText(Name.id))
		{
			flag_submit++;
			error_field = Name;
		}
			
		if(!validateText(Phone.id))
		{
			flag_submit++;
			if(!error_field)
				error_field = Phone;
		}
		
		if(!validateEmail(Email.id))
		{
			flag_submit++;
			if(!error_field)
				error_field = Email;
		}
			
		if(!validateText(Website.id))
		{
			flag_submit++;
			if(!error_field)
				error_field = Website;
		}
		
		if(!validateText(Website.id))
		{
			flag_submit++;
			if(!error_field)
				error_field = Website;
		}
		
		
		if(flag_submit == 0)
			newQuoteSubmit(this_form);
		else
			error_field.focus();

	}
	
}


function tell_a_friend_validation(this_form)
{
	var flag_submit = 0;
	var error_field;
	
	with (this_form)
	{	
		if(!validateText(sender_name.id))
		{
			flag_submit++;
			error_field = sender_name;
		}
			
		if(!validateEmail(sender_email.id))
		{
			flag_submit++;
			if(!error_field)
				error_field = sender_email;
		}
			
		if(!validateText(friend_name1.id))
		{
			flag_submit++;
			if(!error_field)
				error_field = friend_name1;
		}
			
		if(!validateEmail(friend_email1.id))
		{
			flag_submit++;
			if(!error_field)
				error_field = friend_email1;
		}
		
		if(!validateText(message.id))
		{
			flag_submit++;
			if(!error_field)
				error_field = friend_email1;
		}
		
		
		if(flag_submit == 0)
			tell_a_friend(this_form);
		else
			error_field.focus();

	}
}
	

function newQuoteValidation(this_form)
{
	with (this_form)
	{
	
		if(isEmpty(Name.value))
			{ setError(this_form, Name, "Please enter your Name"); return false; }
		
		if(isEmpty(Phone.value))
			{ setError(this_form, Phone, "Please enter your Phone Number"); return false; }

		if(isEmpty(Email.value))
			{ setError(this_form, Email, "Please enter your Email"); return false; }
		else
			if (!isValidEmail(Email.value))
				{ setError(this_form, Email, "Invalid Email"); return false; }
		
		if(PreferredContactMethod.value == 0)
			{ setError(this_form, PreferredContactMethod, "Please select a contact method"); return false; }	
		
		if(isEmpty(Description.value))
			{ setError(this_form, Description, "Please enter your Project Description"); return false; }	
		
		if(isEmpty(Security.value))
			{ setError(this_form, Security, "Please enter the security code !"); return false; }
	}
	
}


function newTestimonialValidation(this_form)
{
	with (this_form)
	{
	
		if(isEmpty(txtname.value))
			{ setError(this_form, txtname, "Please enter your Name"); return false; }
		
		if(isEmpty(txtemail.value))
			{ setError(this_form, txtemail, "Please enter your Email"); return false; }
		else
			if (!isValidEmail(txtemail.value))
				{ setError(this_form, txtemail, "Invalid Email"); return false; }
		
		if(isEmpty(url.value))
			{ setError(this_form, url, "Please enter your the URL"); return false; }
			
		if(!isEmpty(upfile.value))
			if(!isValidFileFormat(upfile.value))
				{ setError(this_form, upfile, "Invalid Image File Format !"); return false; }

		if(isEmpty(testimonial.value))
			{ setError(this_form, testimonial, "Please enter the Testimonial"); return false; }
		
		if(isEmpty(security_code.value))
			{ setError(this_form, security_code, "Please enter the security code !"); return false; }
	}
	
}


function newQuestionValidation(this_form)
{
	with (this_form)
	{
	
		if(isEmpty(txtname.value))
			{ setError(this_form, txtname, "Please enter your Name"); return false; }
		
		if(isEmpty(txtemail.value))
			{ setError(this_form, txtemail, "Please enter your Email"); return false; }
		else
			if (!isValidEmail(txtemail.value))
				{ setError(this_form, txtemail, "Invalid Email"); return false; }
		
		if(isEmpty(txtquestion.value))
			{ setError(this_form, txtquestion, "Please enter your Question"); return false; }
			
		if(isEmpty(security_code.value))
			{ setError(this_form, security_code, "Please enter the security code !"); return false; }
	}
	
}

function checkEmail(email) {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))){
			alert("Invalid E-mail Address! Please re-enter.")
			return (false)
		} else {
			return true;
		}	
	}	
	function contactFormValidation(this_form) {
		var frm='document.emailform';		
		
		if(document.emailform.txtName.value=='') {
			alert("Please Enter The Name");
			document.emailform.txtName.focus(); 
			return false; 
		}
				
		if(document.emailform.txtMail.value=='') {
			alert("Please Enter Mail Address");
			document.emailform.txtMail.focus(); 
			return false; 
		} else if(!(checkEmail(document.emailform.txtMail.value))) { 
			document.emailform.txtMail.value='';
			document.emailform.txtMail.focus(); 
			return false;
		}
	}

function generalEnquiryValidation(this_form)
{
	with (this_form)
	{
	
		if(title.value == 0)
			{ setError(this_form, title, "Please select a Title"); return false; }
			
		if(isEmpty(forename.value))
			{ setError(this_form, forename, "Please enter your Forename"); return false; }
			
		if(isEmpty(surname.value))
			{ setError(this_form, surname, "Please enter your Surname"); return false; }
		
		if(isEmpty(phone.value))
			{ setError(this_form, phone, "Please enter your Phone Number"); return false; }
			
		if(isEmpty(email.value))
			{ setError(this_form, email, "Please enter your Email"); return false; }
		else
			if (!isValidEmail(email.value))
				{ setError(this_form, email, "Invalid Email"); return false; }
		
		if(reply_required.value == 0)
			{ setError(this_form, reply_required, "Please select an option for Reply Required"); return false; }
			
		if(contact_method.value == 0)
			{ setError(this_form, contact_method, "Please select your preferred Contact method"); return false; }
			
		if(isEmpty(comments.value))
			{ setError(this_form, comments, "Please enter your Message"); return false; }
		
		if(isEmpty(security_code.value))
			{ setError(this_form, security_code, "Please enter the security code !"); return false; }
	}
	
}


function votePollValidation()
{

		var vote_casted = false;
		var polldata = "";
		
		var vote_length = document.getElementById("optcount").value;
		
		for (var i=0; i < vote_length; i++) 
       	{
			if (document.getElementById("pollopt"+i).checked)
			{
				vote_casted = true;
				polldata += "1|"
			}
			else
				polldata += "0|"
			
		}
		
		polldata = polldata.substr(0, polldata.length-1);
		
		if(vote_casted == false)
			{ alert("Please select a Poll Option"); return false; }
		else
			 update_vote(document.getElementById("poll_id").value, polldata);
		
			
}


function newSurveyValidation(this_form)
{
	with (this_form)
	{
	
		if(isEmpty(txtname.value))
			{ setError(this_form, txtname, "Please enter your Name"); return false; }
		
		if(isEmpty(txtemail.value))
			{ setError(this_form, txtemail, "Please enter your Email"); return false; }
		else
			if (!isValidEmail(txtemail.value))
				{ setError(this_form, txtemail, "Invalid Email"); return false; }
		
		if(isEmpty(security_code.value))
			{ setError(this_form, security_code, "Please enter the Security Code"); return false; }	
		

		var q_count = document.getElementById("question_count").value ;
		var fill_flag = false;
		
		for(var i=0;i<q_count; i++)
			if(document.getElementById("txtsurvey"+i).value != "")
				fill_flag = true;
				
		if(fill_flag == false)
		{
			alert("Please fill the Survey !");
			return false;
		}
	
	}
	
}


function setError(this_form, field, msg)
{
	with(this_form)
	{
		field.focus();
		alert(msg);
		return false;
	}
}


function isValidFileFormat(file_name)
{
	var file_extension = file_name.substring(file_name.lastIndexOf('.'), file_name.length);
	
	if( (file_extension == ".jpg") || (file_extension == ".JPG") || (file_extension == ".jpeg") || (file_extension == ".JPEG") || (file_extension == ".GIF") || (file_extension == ".gif") || (file_extension == ".PNG") || (file_extension == ".png"))
		return true;
	else
		return false;
}
var url = 'captcha/captcheck.php?code=';
var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed

function getHTTPObject()
{
try {
req = new XMLHttpRequest();
} catch (err1)
{
try {
req = new ActiveXObject("Msxml12.XMLHTTP");
} catch (err2)
{
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (err3)
{
req = false;
}
}
}
return req;
}

var http = getHTTPObject(); // We create the HTTP Object        
        
function handleHttpResponse() {
if (http.readyState == 4) {
	captchaOK = http.responseText;
	if(captchaOK != 1) {
	  alert('The entered code was not correct. Please try again');
	  document.frmOrder.code.value='';
	  document.frmOrder.code.focus();
	  return false;
	  }
	  document.frmOrder.submit();
   }
}
function checkEmail(email) {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))){
			alert("Invalid E-mail Address! Please re-enter.")
			return (false)
		} else {
			return true;
		}	
	}	
	function validation() {
		var frm='document.frmOrder';		
		
		if(document.frmOrder.txtName.value=='') {
			alert("Please Enter The Name");
			document.frmOrder.txtName.focus(); 
			return false; 
		}
		/*if(document.getElementById('txtName').value=='') {
			document.getElementById('txtName').value="Please Enter the name";
			document.getElementById('txtName').style.color="red";
			return false; 
		}*/
		
		
		if(document.frmOrder.intPhone.value=='') {
			alert("Please Enter Phone No");
			document.frmOrder.intPhone.focus(); 
			return false; 
		} else if(isNaN(document.frmOrder.intPhone.value)) {
			alert(" Enter numbers only.");
		    document.frmOrder.intPhone.focus();
			document.frmOrder.intPhone.value="";
	    	return false;
		}
	
		
		if(document.frmOrder.txtMail.value=='') {
			alert("Please Enter Mail Address");
			document.frmOrder.txtMail.focus(); 
			return false; 
		} else if(!(checkEmail(document.frmOrder.txtMail.value))) { 
			document.frmOrder.txtMail.value='';
			document.frmOrder.txtMail.focus(); 
			return false;
		}
				
		if(document.frmOrder.txtMessage.value=='') {
			alert("Please Enter Project Descriptions");
			document.frmOrder.txtMessage.focus(); 
			return false; 
		}
		
		if(document.frmOrder.txtCaptcha.value=='') {
			alert("Please Enter Security Code");
			document.frmOrder.txtCaptcha.focus(); 
			return false; 
		} else {		
			// Now the Ajax CAPTCHA validation
        	checkcode(document.frmOrder.txtCaptcha.value);
        	return false;
		}		
	}

function checkcode(thecode) {
	//alert(url + escape(thecode));	
	http.open("GET", url + escape(thecode), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}        
     
