/* Validation: Check Email */
function checkMail(field)
{
	var field;
	var mailFilter = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$|(\[?((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\]?)$/i

	if (mailFilter.test($(field).attr("value")))
	return true;
	else {
	return false;
	}
}

function popMeUp()
{
	var href = $(this).attr("href");
	var rel = $(this).attr("rel");
	var size = $(this).attr("rev");

	if (size == "big")
	{
		var width = 800;
		var height = 600;
	}

	if (size == "small")
	{
		var width = 350;
		var height = 210;
	}

	if (size == "medium")
	{
		var width = 600;
		var height = 430;
	}

	var x = (1024 - width)/2;
	var y = (768 - height)/2;

	if (screen)
	{
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}

	window.open(""+href+"", rel, "width="+width+", height="+height+", top="+y+", left="+x+", resizable=yes, status=no, scrollbars=1");
		return false;
}

$(document).ready(function(){

	
	// Toggle Div
	$(".toggle").click(function () {
		var show = $(this).attr("href");
		$("#"+show).toggle();
		return false;
	});

	// Bot Protection, rename submit button name for newsletter:
	$("input[name='newsletterSubmit_noBot']").attr("name", "newsletterSubmit");

	var clearedInptArray = new Array();

		// Open pop-up
		$(".popMeUp").click(popMeUp);

		$(".clr").focus(function(){
			var inptId = $(this).attr("name");
			$(this).val("");
		});

		// Add Scroller Object
		$jScroller.add("#newsScrollCont","#scroller","up", 3, true);

		// Start Autoscroller
		$jScroller.start();

	$("#newsletterSign").submit(function() {
		var Mail = "#newsletterSign [name=nlEmail]";
		var MailVal = $(Mail).val();

		var Name = "#newsletterSign [name=nlName]";
		var NameVal = $(Name).val();

		var error = 0;
		
		if (NameVal.length == 0 || NameVal == "")
		{
			$("#nUsernameError").text("חובה לספק שם.");
			error++;
		}
		else
		{
			$("#nUsernameError").text("");
		}

		if (MailVal.length == 0 || MailVal == "" || checkMail(Mail) == false)
		{
			$("#nEmailError").text("יש לספק אימייל תקין.");
			error++;
		}
		else
		{
			$("#nEmailError").text("");
		}

		if (error > 0)
		{
			return false;
		}

		// On Success, email information.

		else
		{
			// Submit newsletter.
			$.ajax({
				type: "POST",
				cache: false,
				url: "newsletter.php",
				data: "name="+NameVal+"&mail="+MailVal,
				dataType: "text",

				success: function(msg){
					$("#newsletterBox").html(msg);
				}
			});
		}
		
		return false;
	});
});
