$(document).ready(function(){
$("div.menu-LINK").each(
	function() 
	{
		var $container = $(this);
		if ($container.attr('id') != "boldMenu")
			{
			$container.mouseover(function() 
			{
				$container.attr('id','boldMenu');
			});  
			$container.mouseout(function() 
			{
				$container.attr('id','');
			});
		}
    }
)

company = $("#leadbox").val();
/////////// This part is in changing the Finexo Leadboxbuttons and content
var $current_id = $("."+company+"_Leadbox_Bottuns").attr("id");
var was_clicked = false;
$("#contact_"+company+" img").each(function(){
		var $the_id = $(this).attr('rel');
		
		//mouseover
		$(this).bind("mouseover",function(){
		$("."+company+"_Leadbox_Bottuns").attr("id",$the_id);
		});
		
		//mouse out
		$(this).bind("mouseout",function(){
		if (was_clicked == false)
			$("."+company+"_Leadbox_Bottuns").attr("id",$current_id);
		else
			was_clicked = false;
		});
		
		//click
		$(this).bind("click",function(){
			was_clicked = true;
			var $the_id = $(this).attr('rel');
			$("."+company+"_Leadbox_Bottuns").attr("id",$the_id);
			$current_id = $("." + company + "_Leadbox_Bottuns").attr("id");
			if ($the_id == "Accunt_" + company)
			{
				var $text_3 = "ניסיון במסחר:<br><select name='" + company +"_experience' id='"+company+"_experience' style='width: 161px'><option value='ללא ניסיון'>ללא ניסיון</option><option value='ניסיון מועט'>ניסיןו מועט</option><option value='ניסיון רב'>ניסיון רב</option></select>";
				if (company == "finexo")
					$("#leadbox_text_row").html("פתח חשבון באמצעות טופס פשוט, והתחל לסחור עוד היום.");
				else if (company == "yozma")
					$("#leadbox_text_row").html("פתח חשבון עם קבוצת יוזמה, ותהנה מליווי צמוד ומקצועי לכל אורך הדרך.");
				$("#leadbox_text_td img").attr("src","/images/"+ company +"/Accunt_" + company + ".png");
				$("#leadbox_text_3").html($text_3);
			}
			else if ($the_id == "reg_"+company)
			{
				var $text_3 = "אימייל:<br><input name='finexo_email' id='finexo_email' style='width: 161px' type='text'>";
				if (company == "finexo")
					$("#leadbox_text_row").html("הרשם עכשיו לפניקסו, וקבל לומדת מסחר מקצועית במתנה!");
				else if (company == "yozma")
					$("#leadbox_text_row").html("הרשם עכשיו ליוזמה וקבל איתותי מסחר לשבועים חינם!");
				$("#leadbox_text_td img").attr("src","/images/"+ company +"/reg_" + company + ".png");
				$("#leadbox_text_3").html($text_3);
				
			}
			else if ($the_id == "contact_"+company)
			{
				var $text_3 = "טלפון נוסף:<br><input name='finexo_phone_2' id='finexo_phone_2' maxlength='7' style='width: 112px' type='text'><select id='finexo_pre_phone_code_2' name='finexo_pre_phone_code_2' style='margin-right: 5px; width: 56px;'><option value=''></option><option value='02'>02</option><option value='03'>03</option><option value='04'>04</option><option value='08'>08</option><option value='09'>09</option><option value='050'>050</option><option value='052'>052</option><option value='054'>054</option><option value='057'>057</option><option value='073'>073</option><option value='076'>076</option><option value='077'>077</option><option value='078'>078</option><option value='079'>079</option></select>";
				$("#leadbox_text_row").html("מלא את פרטיך ונציגנו יחזרו אליך טלפונית");
				$("#leadbox_text_td img").attr("src","/images/"+ company +"/"+ company +"-infoPhone.png");
				$("#leadbox_text_3").html($text_3);
			}
		});
	})
});
// End of finexo leadbox part


function validPhone(phone_field,which_leadbox)
{	
	var which_leadbox = which_leadbox;
	var area_codes = "02,03,04,08,09,072,073,076,077,078,079,050,052,054,057";
	var phone_number = document.getElementById(phone_field).value;
	var pre_code = document.getElementById(which_leadbox +"_pre_phone_code").value; // need to see there is no hitnagshot here

	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;
}

function validEmail(which_leadbox)
{	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var email_address = document.getElementById(which_leadbox +"_email").value;
	if(reg.test(email_address) == false) 
	  return false;
	else
		return true;
}

function check_leadbox_details(which_leadbox)
{

	// Get into objects the inputs
	var $fullname = $("#"+which_leadbox +"_fullname");
	var $phone = $("#"+which_leadbox +"_phone");
	var $email = $("#"+which_leadbox +"_email");
	var $pre_phone_code = $("#"+which_leadbox +"_pre_phone_code");
	var $pre_phone_code_alert = $("#"+which_leadbox +"_pre_phone_code_alert");

	var $fullname_alert = $("#"+which_leadbox +"_fullname_alert");
	var $phone_alert = $("#"+which_leadbox +"_phone_alert");
	var $email_alert = $("#"+which_leadbox +"_email_alert");
	var $pre_phone_alert =$("#"+which_leadbox +"_pre_phone_alert");

	$fullname_alert.hide();
	$phone_alert.hide();
	$email_alert.hide();
	$pre_phone_alert.hide();

	if ($fullname.val() == "")
	{
		$fullname.focus();
		$fullname_alert.show();
		return;
	}

	if ($pre_phone_code.val() == "")
	{
		$pre_phone_code.focus();
		$pre_phone_alert.show();
		return;
	}
	
	if (!validPhone(which_leadbox + "_phone",which_leadbox))
	{
		//phone.style.border= alert_border_settings;
		$phone.focus();
		$phone_alert.show();
		return;
	}

	$("#" + which_leadbox + "_leadbox_form").submit();

}

function help_user_leadbox(user_input,input_id,which_leadbox,which_ind)
{ 
	var normal_border_settings = "medium solid #000000";
	if (which_leadbox == "bonus" || which_leadbox == "borsa")
		var normal_border_settings = "thin solid";
	input_id_obj = document.getElementById(input_id);
	input_id_obj_alert = document.getElementById(input_id + "_alert");
	
	if (which_ind == "pre_phone_code")
	{
		if(input_id_obj.value != "")
		{
			document.getElementById(which_leadbox + "_pre_phone_code_alert").style.border = normal_border_settings;
			input_id_obj.style.color="green";
			document.getElementById(which_leadbox + "_pre_phone_alert").style.display="none";
		}
	}
	else if (which_ind == "phone")
	{
		if (!validPhone(input_id,which_leadbox))
			input_id_obj.style.color="red";
		else
		{
			input_id_obj.style.color="green";
			input_id_obj.style.border = normal_border_settings;
			input_id_obj_alert.style.display="none";
		}
	}

	else if (which_ind == "fullname")
	{
		if (input_id_obj.value.length < 2)
			input_id_obj.style.color="red";
		else
		{
			input_id_obj.style.color="green";
			input_id_obj.style.border = normal_border_settings;
			input_id_obj_alert.style.display="none";
		}
	}
	else if (which_ind == "email")
	{
		if (!validEmail(which_leadbox))
			input_id_obj.style.color="red";
		else
		{
			input_id_obj.style.color="green";
			input_id_obj.style.border = normal_border_settings;
			input_id_obj_alert.style.display="none";
		}
	}
}

function chose_clips(the_swf)
{
	var the_clip = document.getElementById("the_clip");
	the_clip.innerHTML = "<object style='height: 228px; width: 283px'><param name='movie' value='"+ the_swf +"'></param><param name='allowFullScreen' value='true'>	</param>	<param name='allowscriptaccess' value='always'>	</param>	<embed allowfullscreen='true' allowscriptaccess='always' height='228' src='"+ the_swf +"' type='application/x-shockwave-flash' width='283'>	</embed></object>"
}

