function checkform(theform){
	var why = "";
	 
	if(theform.txtInput.value == ""){
		why += "- Security code should not be empty. \n Please enter it again. Thanks. \n";
	}
	if(theform.txtInput.value != ""){
		if(ValidCaptcha(theform.txtInput.value) == false){
			why += "- Security code did not match.\n";
		}
	}
	if(theform.name.value == ""){
		why += "- Name should not be left blank. \n Please enter it and try again. \n";
	}
	if(theform.phone.value == ""){
		why += "- Phone number should not be left blank. \n Please enter it and try again. \n";
	}
	if(theform.email.value == ""){
		why += "- Email should not be left blank. \n Please enter it and try again. \n";
	}
	if(why != ""){
		alert(why);
		return false;
	}
	 
	
}

function validateEmail(txtEmail){
   var a = document.getElementById(txtEmail).value;
   var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{1,4}$/;
    if(filter.test(a)){
        return true;
    }
    else{
        return false;
    }
}


//Generates the captcha function    
	var code = '';
	for(i=0; i<=4; i++){
		code += Math.ceil(Math.random() * 9) + '';
	}
	document.getElementById("txtCaptcha").value = code;
	document.getElementById("txtCaptchaDiv").innerHTML = code;	
	

// Validate the Entered input aganist the generated security code function   
function ValidCaptcha(){
	var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
	var str2 = removeSpaces(document.getElementById('txtInput').value);
	if (str1 == str2){
		return true;	
	}else{
		return false;
	}
}

// Remove the spaces from the entered and generated code
function removeSpaces(string){
	return string.split(' ').join('');
}
