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 = document.getElementById(which_leadbox +"_fullname");
	var phone = document.getElementById(which_leadbox +"_phone");
	var email = document.getElementById(which_leadbox +"_email");
	var pre_phone_code = document.getElementById(which_leadbox +"_pre_phone_code");
	var pre_phone_code_alert = document.getElementById(which_leadbox +"_pre_phone_code_alert");

	// Get into objects the alerts messages

	var fullname_alert = document.getElementById(which_leadbox +"_fullname_alert");
	var pre_phone_alert = document.getElementById(which_leadbox +"_pre_phone_alert");
	var phone_alert = document.getElementById(which_leadbox +"_phone_alert");
	var phone_alert_2 = document.getElementById(which_leadbox +"_phone_alert_2");
	var email_alert = document.getElementById(which_leadbox +"_email_alert");

	fullname_alert.style.display="none";
	phone_alert.style.display="none";
	phone_alert_2.style.display="none";
	email_alert.style.display="none";
	pre_phone_alert.style.display="none";

	if (fullname.value == "")
	{
		fullname.focus();
		fullname_alert.style.display="block";
		return;
	}

	if (pre_phone_code.value == "")
	{
		
		pre_phone_code.focus();
		pre_phone_alert.style.display="block";
		return;
	}
	
	if (phone.value == "")
	{
		phone.focus();
		phone_alert.style.display="block";
		return;
	}
	
	if (!validPhone(which_leadbox + "_phone",which_leadbox))
	{
		phone.focus();
		phone_alert_2.style.display="block";
		return;
	}
		
	document.getElementById(which_leadbox + "_leadbox_form").submit();

}

function help_user_leadbox(user_input,input_id,which_leadbox,which_ind)
{ 

	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 != "")
		{
			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_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_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_alert.style.display="none";
		}
	}
	*/
}
