// JavaScript Document
function validateLeads(formName){
	if ($("#firstname").val() == ""){
		alert("Firstname required");
		$("#firstname").focus();
		return true;
	} else if($("#surname").val() == ""){
		alert("Surname required");
		$("#surname").focus();
		return true;
	} else if($("#emails").val() == ""){
		alert("Email required");		
		$("#emails").focus();
		return true;
	} else if (($("#emails").val().indexOf(".") < 2) || ($("#emails").val().indexOf("@") < 0)){
			alert("Email not valid");
			$("#emails").focus();
			return true;
	} else if($("#conact_number").val() == ""){
		alert("Conact Number required");
		$("#conact_number").focus();
		return true;
	} else if($("#location").val() == ""){
		alert("Location required");
		$("#location").focus();
		return true;	
	} else if($("#message").val() == ""){
		alert("Message required");
		$("#message").focus();
		return true;	
	} else if($("#roland_contact").val() == ""){
		alert("Select Option required");
		$("#roland_contact").focus();
		return true;
	} else if($("#captchastring").val() == ""){
		alert("Security Code required");
		$("#captchastring").focus();
		return true;
	} else if($("#captchastring").val() != ""){
		// check valid
		$.post("leads_wrap.php",{
			 tCaptchaString: $("#captchastring").val(),
			 action: "captcha"
		 }, function(xml) {
			 xmlDate = $("date",xml).text();
			 contentData = $("content",xml).text();
			 status = $("status",xml).text();
			if (status == "failed"){ 		
				alert("Security Code Not Valid");
				$("#captchastring").focus();
				return true;
			}
		 });
		document.formName.submit();	
	} else {
		document.formName.submit();
	}
}
function validateSubmitBrief(formName){
	$('.theError').hide();
	var isError = 0;
	if ($("#companyName").val() == ""){
		$("#errorCompany").show();
		isError = 1;
	} 
	if($("#tagLine").val() == ""){
		$("#errorTagline").show();
		isError = 1;
	} 
	if($("#looking_for").val() == ""){
		$("#errorLookingfor").show();
		isError = 1;
	} 
	if($("#dont_want").val() == ""){
		$("#errorAvoid").show();
		isError = 1;
	} 
	if($("#telp").val() == ""){
		$("#errorTelephone").show();
		isError = 1;
	}
	if($("#vehicle").val() == ""){
		$("#errorVehicle").show();
		isError = 1;
	}
	if ($("#contact_firstname").val() == ""){
		$("#errorFirstname").show();
		isError = 1;
	} 
	if($("#contact_lastname").val() == ""){
		$("#errorLastname").show();
		isError = 1;
	} 
	if($("#contact_email").val() == ""){
		$("#errorContactemail").show();
		isError = 1;
	} 
	if (($("#contact_email").val().indexOf(".") < 2) || ($("#contact_email").val().indexOf("@") < 0)){
			$("#errorContactemail").show();
			isError = 1;
	} 
	if($("#contact_telp").val() == ""){
		$("#errorContacttelp").focus();
		isError = 1;
	} 
	if($("#contact_cell").val() == ""){
		$("#errorContactcell").focus();
		isError = 1;
	} 
	if($("#agree").is(':checked') == ""){
		$("#errorAgree").show();
		isError = 1;
	} 
	if($("#author").is(':checked') == ""){
		$("#errorAuthor").show();
		isError = 1;
	} 
	if($("#captchastring").val() == ""){
		$("#errorCaptcha").show();
		isError = 1;
	} 
	if($("#captchastring").val() != ""){
		// check valid
		$.post("submit_wrap_brief.php",{
			 tCaptchaString: $("#captchastring").val(),
			 action: "captcha"
		 }, function(xml) {
			 xmlDate = $("date",xml).text();
			 contentData = $("content",xml).text();
			 status = $("status",xml).text();
			if (status == "failed"){ 		
				//alert("Security Code Not Valid");
				$("#errorCaptcha").show();
				isError = 1;
			}
		});	

	}
	if(isError == 1){
		alert ('Please Check your input form');
		return false;
	}else{
		return true;
	}
}
function showDetail(showId){
	//$('.someSidebar').hide('0', function(){
		$('#'+showId).slideToggle('slow');
	//});
}
function sendData(){
	$.post("leads_wrap.php",{
		 tCaptchaString: $("#captchastring").val(),
		 action: "captcha"
	 }, function(xml) {
		 xmlDate = $("date",xml).text();
		 status = $("status",xml).text();
		if (status == "failed"){ 		
			return true;
		} else {
			return false;
		}
	 });
}
function changeContent(id_file, id_text){
	var filename = $('#'+id_file).val();
	$('#'+id_text).val(filename);
}
