/*<![CDATA[*/
		   
/*****************************************************************************
//-> START GENERAL FUNCTIONS
*****************************************************************************/
// --> Start label2value
this.label2value = function(){
	// function
	jQuery("label.side").each(function(){
		obj = document.getElementById(jQuery(this).attr("for"));
		if((jQuery(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){
			//jQuery(obj).addClass(inactive);
			var text = jQuery(this).text();
			jQuery(this).css("display","none");
			jQuery(obj).val(text);
			jQuery(obj).focus(function(){
				//jQuery(this).addClass(focused);
				//jQuery(this).removeClass(inactive);
				//jQuery(this).removeClass(active);
				if(jQuery(this).val() == text) jQuery(this).val("");
			});
			jQuery(obj).blur(function(){
				//jQuery(this).removeClass(focused);
				if(jQuery(this).val() == "") {
					jQuery(this).val(text);
					//jQuery(this).addClass(inactive);
				} else {
					//jQuery(this).addClass(active);
				};
			});
		};
	});
};
// --> Via Url Toolbox - (scripts.all.js)
var pathname = $(document).url();


// --> START EXTEND VALIDATION FOR LABEL AS VALUE
jQuery.validator.addMethod(
	"checkLabels",
	function(value, element) {
		var check = false;
			var inputVal = value;
			var labelVal = jQuery(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) {
	jQuery('div.warning').remove();
	jQuery('.msg').fadeIn(500).html("<img src='/images/loadinfo.gif' width='16' height='16' alt='' /> אנא המתן, הבקשה בשליחה...");
	jQuery('#side-contact').slideUp();
}


// --> FORM post-submit callback
function showResponse2()  {
	$('#side-contact').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.href=pathname+"&fs=1";
	}else{
		document.location.href=pathname+"?fs=1";
	}
}

/*****************************************************************************
//-> END GENERAL FUNCTIONS
*****************************************************************************/

/*****************************************************************************
//-> START Window Load
*****************************************************************************/

jQuery(window).load(function () {
    
// --> START FORM VALIDATION
	
	// Init Form Validation
    jQuery("#side-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:              "/qcontact.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
			});
		}
	});

// --> Init Label2Value
	label2value();

});

/*****************************************************************************
//-> END Window Load
*****************************************************************************/

/*]]>*/
