﻿/*<![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("כמה זה "+ 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;
}

// --> Via Url Toolbox - (scripts.all.js)
var pathname = $(document).url();

// --> START EXTEND VALIDATION FOR CAPTCHA
$.validator.methods.equal = function(value, element, param) {
	return value == param;
};

// --> FORM pre-submit callback
function showRequest(formData, jqForm, options) {
	$('.msg').fadeIn(500).html("<img src='images/loadinfo.gif' width='16' height='16' alt='' /> אנא המתן, הטופס בשליחה...");
	$('#contact-form').slideUp();
}

// --> FORM post-submit callback
function showResponse2()  {
	$('#contact-form').hide("fast", function(){
		$('.msg').fadeIn(500).html('<img class="png_bg" src="images/success.png" width="16" height="16" alt="" /><strong>הודעתך נקלטה!</strong><br />נציגנו יצור אתך קשר בקרוב.');
	});
}
// --> FORM post-submit callback
function showResponse()  {
	if (pathname.attr('query') != null){
		document.location=pathname+"&s=1";
	}else{
		document.location=pathname+"?s=1";
	}
}

/*****************************************************************************
//-> END GENERAL FUNCTIONS
*****************************************************************************/

/*****************************************************************************
//-> START Window Load
*****************************************************************************/

$(window).load(function () {

// --> START FORM VALIDATION
    $("#contact-form").validate({

		meta: "validate",

        showErrors: function(errorMap, errorList) {
        	this.defaultShowErrors();
        },

		submitHandler: function(form) {

    		// --> replacing the "enter" with "<br />" on the textarea
    		var txtStr = document.getElementById("Message").value;
    		document.getElementById("Message").value = txtStr.replace(/\n/gi, "<br />");

			// Send the form via ajax form
			jQuery(form).ajaxSubmit({
        		url:              "/send_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
			}
		}
	});

// --> Init CAPTCHA
	$('#contact-form').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
*****************************************************************************/

/*]]>*/

