/*<![CDATA[*/
		   
/*****************************************************************************
//-> START GENERAL FUNCTIONS
*****************************************************************************/
// --> Start label2value
this.label2value = function(){
	// function
	$("label.hp").each(function(){
		obj = document.getElementById($(this).attr("for"));
		if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){
			//$(obj).addClass(inactive);
			var text = $(this).text();
			$(this).css("display","none");
			$(obj).val(text);
			$(obj).focus(function(){
				//$(this).addClass(focused);
				//$(this).removeClass(inactive);
				//$(this).removeClass(active);
				if($(this).val() == text) $(this).val("");
			});
			$(obj).blur(function(){
				//$(this).removeClass(focused);
				if($(this).val() == "") {
					$(this).val(text);
					//$(this).addClass(inactive);
				} else {
					//$(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 = $(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='' /> אנא המתן, הבקשה בשליחה...");
	$('#hp-contact').slideUp();
}

// --> FORM post-submit callback
function showResponse2()  {
	$('#hp-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
*****************************************************************************/

$(window).load(function () {
    
// --> START FORM VALIDATION
	
	// Init Form Validation
    $("#hp-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",
                //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
			});
		}
	});

// --> Init Label2Value
	label2value();

});

/*****************************************************************************
//-> END Window Load
*****************************************************************************/

/*]]>*/
