/*<![CDATA[*/
		   
/*****************************************************************************
//-> START General Functions
*****************************************************************************/

// --> FORM pre-submit callback
function showRequest(formData, jqForm, options) {

	var form = jqForm[0];

	if (!form.name.value) {
	
		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='/images/attention.png' width='11' height='11' alt='' /> Please fill in your name.");
		form.name.focus();
		
		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});

		return false;
	}

	if (!echeck(form.email.value)) {
		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='/images/attention.png' width='11' height='11' alt='' /> Please fill in a valid email address.");
		form.email.focus();
		
		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
		
		return false;
	}
		

	if (!form.comments.value) {
	
		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='/images/attention.png' width='11' height='11' alt='' /> Please fill in the content of your message.");
		form.comments.focus();
		
		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
		
		return false;
	}

	if (!verify(form.verify.value)) {
	
		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='/images/attention.png' width='11' height='11' alt='' /> Please answer the question, we need to check that you'r human...");
		form.verify.focus();
		
		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
		
		return false;
	}
	
	$('.msg').fadeIn(500).html("<img src='/images/loadinfo.gif' width='16' height='16' alt='' /> Please wait, processing form...");
	$('#contactform').slideUp();
	
}


// --> post-submit callback
function showResponse()  {
	$('.msg').fadeIn(500).html("<img class='png_bg' src='/images/success.png' width='16' height='16' alt='' /> <strong>Message sent successfully!<\/strong><br \/>Thanks for contacting us. We’ll get back to you as quickly as possible.");
	$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
	
}

// --> removing the status message with a 5sec timer activated
function removeMsg() {
	$('.msg').oneTime(4000,function() {
		$(this).slideUp(500);
		//console.debug($('.msg').oneTime());
	});
}

// --> Email Validation function
function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail ID")
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail ID")
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail ID")
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail ID")
		return false;
	 }
	 return true;					
}

// --> START CAPTCHA
var flag = false;
var a = Math.ceil(Math.random() * 10);
var b = Math.ceil(Math.random() * 10);

function verify(){

	if(!flag){
		var c = a + b;
		var d = $("#verify:input").val();
		
		//$("label.verify").html("What is "+ a + " + " + b +"? ");
		$('label.verify').append("What is "+ a + " + " + b +"? ");
		flag = true;
		return false;
	}
	
	var c = parseInt($("#aVal:input").val()) + parseInt($("#bVal:input").val());
	var d = $("#verify:input").val();

	if (flag && c == d) {
		return true; 
	}else{
		return false;
	}
	return false;	
}

/*****************************************************************************
//-> END General Functions
*****************************************************************************/

/*****************************************************************************
//-> START Window Load
*****************************************************************************/

$(window).load(function () {

// --> START CONTACT FORM
	var options = {
		url:			"/email.asp",
		beforeSubmit:  showRequest,  // pre-submit callback
		success:       showResponse,  // post-submit callback
		clearForm: true,        // clear all form fields after successful submit
		resetForm: true        // reset the form after successful submit
	};
	
	$('#contactform').submit(function() { 
		$(this).find("input#submit").after('<img src="/images/ajax-loader.gif" class="loader" />')
		
		// --> replacing the "enter" with "<br />" on the textarea
		var txtStr = document.getElementById("comments").value;
		document.getElementById("comments").value = txtStr.replace(/\n/gi, "<br />");

									  
		$(this).ajaxSubmit(options);
		 return false;
	}); 
	
// --> Init CAPTCHA
	$('#contactform').find("fieldset").append('<input type="hidden" name="aVal" id="aVal" value="" /><input type="hidden" name="bVal" id="bVal" value="" />');
	$("#aVal:input").val(a);
	$("#bVal:input").val(b);

	verify()		

});

/*****************************************************************************
//-> END Window Load
*****************************************************************************/

/*]]>*/
