/*<![CDATA[*/
		   
/*****************************************************************************
//-> START GENERAL FUNCTIONS
*****************************************************************************/
// --> START CAPTCHA
var flag = false;
var a = Math.ceil(Math.random() * 10);
var b = Math.ceil(Math.random() * 10);
var c = a+b;

function verify(){

	if(!flag){
		var c = a + b;
		var d = $("#verify:input").val();
		
		$('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;	
}

// --> START EXTEND VALIDATION FOR LABEL AS VALUE
jQuery.validator.addMethod(
	"checkLabels",
	function(value, element) {
		var check = false;
			var inputVal = value;
			var labelVal = $(element).prev("label").text();
			//console.log("inputVal: "+inputVal + "  labelVal: "+labelVal);
			if(inputVal != labelVal)
				check = true;
			else
				check = false;
		return this.optional(element) || check;
	}, 
	"Please Enter Value"
);

// --> FORM pre-submit callback
function showRequest(formData, jqForm, options) {
	$('div.warning').remove();
	$('.msg').fadeIn(500).html("<img src='images/loadinfo.gif' width='16' height='16' alt='' /> Please wait, sending request...");
	$('#quick-contact').slideUp();
}

// --> FORM post-submit callback
function showResponse()  {
	$('.msg').fadeIn(500).html('<img class="png_bg" src="images/success.png" width="16" height="16" alt="" /> <strong>Thank You!</strong><br />Your message has been sent successfully.');
}

/*****************************************************************************
//-> END GENERAL FUNCTIONS
*****************************************************************************/

/*****************************************************************************
//-> START Window Load
*****************************************************************************/

$(window).load(function () {
    
// --> START FORM VALIDATION
	
	// Init Form Validation
    $("#quick-contact").validate({
		
		errorElement: "small",
		errorClass: "error",
		meta: "validate",
		//debug:true,

        showErrors: function(errorMap, errorList) {
        	this.defaultShowErrors();
        },
		submitHandler: function(form) {
    		// --> replacing the "enter" with "<br />" on the textarea
    		var txtStr = document.getElementById("text").value;
    		document.getElementById("text").value = txtStr.replace(/\n/gi, "<br />");
			
			// Send the form via ajax form
			jQuery(form).ajaxSubmit({
        		url:              "/email.asp",
                //target:           ".msg2",        // Get the server response here
                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
			});
		},            
		rules: {
			verify: {
                equal: c
			}
		}
	});

	verify();
});

/*****************************************************************************
//-> END Window Load
*****************************************************************************/

/*]]>*/
