﻿/*****************************************************************************
//-> START General Functions
*****************************************************************************/

// --> FORM pre-submit callback
function showRequest(formData, jqForm, options) {

	var form = jqForm[0];

	if (!echeck(form.email.value)) {
		alert("נא מלא כתובת אימייל תקינה.");
		form.email.focus();
		return false;
	}

	$('#exhibitionform').slideUp();
	$('.response').fadeIn(500).html("<img src='images/loadinfo.gif' width='16' height='16' alt='' /> אנא המתן, הרשמה מתבצעת...");
}


// --> post-submit callback
function showResponse()  {
	$('.response').fadeIn(500).html("<img class='png_bg' src='images/success.png' width='16' height='16' alt='' /> <strong>ההרשמה בוצעה בהצלחה!<\/strong>");
}

// --> 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;
}

/*
 * label2value
 * using form labels as text field values
 */
this.label2value = function(){

	// CSS class names
	// put any class name you want
	// define this in external css (example provided)
	//var inactive = "inactive";
	//var active = "active";
	//var focused = "focused";

	// function
	$("label").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);
				};
			});
		};
	});
};

/*****************************************************************************
//-> END General Functions
*****************************************************************************/

/*****************************************************************************
//-> START Window Load
*****************************************************************************/

$(window).load(function () {

// --> Start insert menu seperators
	$("ul#menu-exhibition li:not(:last)").each(function(){
		$(this).after('<li class="sep"> | </li>');
	});

// --> START CONTACT FORM
	var options = {
		url:			"exhibition-mailing.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
	};

	$('#exhibitionform').submit(function() {
		$(this).ajaxSubmit(options);
		 return false;
	});

// --> Init Label2Value
	label2value();

});


/*****************************************************************************
//-> END Window Load
*****************************************************************************/

