/*
$("#drop").hover(
		function(){
			$("#menuin").fadeIn("slow");
			},
		function(){
			$("#menuin").fadeOut("slow");
			}
	)
*/

function validEmail()
	{	
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var email_address = $("#email").val();
		if(reg.test(email_address) == false) 
		  return false;
		else
			return true;
	}
	
function check_leadbox2()
{
	$("#alert span").hide();
	
	var letters = /^[פםןוטארקףךלחיעכגדשץתצמנהבסזa-zA-Z0-9/\ ]+$/i;
	function validPhone()
	{	
	var area_codes = "02,03,04,08,09,072,073,076,077,078,079,050,052,054,057";
	var phone_number = document.getElementById("pre_phone").value;
	var pre_code = document.getElementById("pre_phone_code").value;

	phone_number = pre_code + phone_number;
	var valid = false;
	// Check for correct phone number
	 var rePhoneNumber = new RegExp(/^([0-9]{7})$/);
	 var phone_areas = area_codes.split(",");
	 for(area_code=0;area_code<phone_areas.length;area_code++)
	 {
		if(phone_number.substr(0, phone_areas[area_code].length) == phone_areas[area_code])
		{
			full_phone = phone_number.substr(phone_areas[area_code].length);
			if(rePhoneNumber.test(full_phone))
			{
				valid = true;
			}
		}//If area code found
	 }//For each area code in list
	return valid;
	}
	
	// Check Taz
	function check_taz(id) {
        if (isNaN(id))
        { return false; }
        if (id == '000000000')
        { return false; }
        //if ((id.length > 9) || (id.length < 5))
        if (id.length != 9)
        { return false; }
        if (id.length < 9) {
            while (id.length < 9)
          {
         id = '0' + id;
           }
        }
        var mone = 0, incNum;
        for (var i = 0; i < 9; i++) {
            incNum = Number(id.charAt(i));
            incNum *= (i % 2) + 1;
            if (incNum > 9)
                incNum -= 9;
            mone += incNum;
        }
        if (mone % 10 == 0) {
            return true;
        }
        else {
            return false;
        }
    }

	function isValid(pattern,str)
	{
		return pattern.test(str)	
	}

	if (!isValid(letters,$("#fullname").val()))
	{
		$("#fullname_alert").show();
		$("#fullname").focus();
		return false;
	}
	if ($("#fullname").val() == "")
	{
		$("#fullname_alert").show();
		$("#fullname").focus();
		return false;
	}
	// Check if fullname is more then 1 part:
	if ($("#fullname").val().split(" ").length < 2)
	{
		$("#fullname2_alert").show();
		$("#fullname").focus();
		return false;
	}
	// Define phone number
	var phone_number = $("#pre_phone").val();
	var pre_code = $("#pre_phone_code").val();
	phone_number = pre_code + phone_number;

	if (pre_code == "")
	{
			$("#pre_phone_code_alert").show();
			$("#pre_phone_code").focus();
			return false;
	}
	
	if (!validPhone())
	{
			$("#pre_phone_alert").show();
			$("#pre_phone").focus();
			return false;
	}
	
	if(!validEmail())
	{
		$("#email").focus();
		$("#email_alert").show();
		return;
	}
	
	if (!check_taz($("#taz").val()))
	{
		$("#taz").focus();
		$("#taz_alert").show();
		return;
	}
	
	if (!isValid(letters, $("#address").val()))
	{
		$("#address_alert").show();
		$("#address").focus()
		return false;
	}
	
	if ($("#address").val() == "" || $("#address").val() == "הכנס/י כתובת")
	{
		$("#address_alert").show();
		$("#address").focus()
		return false;
	}
	
	if ($("#home").val() == "" || $("#home").val() == "בחר/י מקום מגורים")
	{
		$("#home_alert").show();
		$("#home").focus()
		return false;
	}
	
	//alert('Got to check the mosdot part');
	
	var mosdot_checkbox = new Array();
	$("input[@name='mosdot[]']:checked").each(function(){

	if ($(this).attr("id") != "agree_ads")
		mosdot_checkbox.push($(this).val());
	});
	if (mosdot_checkbox.length == 0)
	{ 
		jAlert("<b>" + $('#fullname').val() + '</b>, כדי שנוכל לעזור לך, אנא בחר לפחות מוסד לימודים אחד.', 'בחר מוסד לימודים');
		//document.location.hash = "stepOne_a_name";
		return;
	}
	//alert('submit');
	$("#leadbox_form").submit();
}


/*
function choose_mosad(mosad_id){
	$("#" + mosad_id + "_img").show();
	$("#" + mosad_id + "_close").show();
}
function unchoose(mosad_id){
	setTimeout("$('#" + mosad_id + "_img').hide()",100);
	setTimeout("$('#" + mosad_id + "_close').hide()",100);
	// This needs to unchoose the checkbox attr checkbox
	//$("#" + mosad_id + "_td").find(":checkbox").attr("checked","");
}*/

/*
$(document).ready(function() {
	// Open more mosdot effect
	$('.more_mosdot').click(function() {
		$(this).next().toggle('slow');
		return false;
	})
	// Define for the mosdot chose buttons that it will do the checkbox
	// right now it disables the checkbox itself
	$(".mosad_td").click(function(e){
		if (e.target.tagName != "INPUT")
		{
			$(this).find(":checkbox").attr("checked","checked");

		}
	})
})
*/
$(document).ready(function() {
	$('#leadbox input:not(.checkbox)').one('focus', function(){
		  $(this).attr('value', '');
		  $(this).css({"color":"black","font-style":"normal"});
		});
	$(".mosad").each(function(){
		$(this).hover(
		//in
		function(){
			var mosad_id = ($(this).attr("rel"));
			$("#info_" + mosad_id).show();
		},
		//out
		function(){
			var mosad_id = ($(this).attr("rel"));
			$("#info_" + mosad_id).hide();
		}
		)
	})
	
	/*
	$('.checkbox').click(function(){
		jAlert('אנו ממליצים לבחור <b>לפחות 3</b> מוסדות לימוד כדי לקבל כמה שיותר מידע.', 'טיפ מ-Where2Learn:');
		$(this).attr("checked","checked");
		$(".checkbox").unbind("click");
		});
	*/
})
