function validPhone(phone_field)
{	

	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("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])
		{
			phone = phone_number.substr(phone_areas[area_code].length);
			if(rePhoneNumber.test(phone))
			{
				valid = true;
			}
		}//If area code found
	 }//For each area code in list
	return valid;
}

function check_inputs()
{
	fullname_obj = document.getElementById("fullname");
	phone_obj = document.getElementById("pre_phone");
	pre_phone_obj = document.getElementById("pre_phone_code");

	fullname_alert_obj = document.getElementById("fullname_alert");
	phone_alert_obj = document.getElementById("phone_alert");
	pre_phone_code_alert_obj = document.getElementById("pre_phone_code_alert");
	all_phone_alert_obj = document.getElementById("all_phone_alert");
		
	fullname_alert_obj.style.display="none";
	phone_alert_obj.style.display="none";
	pre_phone_code_alert_obj.style.display="none";
	all_phone_alert_obj.style.display="none";

	if (fullname_obj.value.length < 1)
	{	
	
		fullname_alert_obj.style.display="block";
		fullname_obj.focus();
		return;
	}
	else if (pre_phone_obj.value == "")
	{
		pre_phone_code_alert_obj.style.display="block";
		pre_phone_obj.focus();
		return;
	}
	else if (phone_obj.value == "")
	{
		phone_alert_obj.style.display="block";
		phone_obj.focus();
		return;
	}
	
	
	else if (!validPhone("pre_phone"))
	{
		all_phone_alert_obj.style.display="block";
		phone_obj.focus();
		return;
	}
	
	document.getElementById("leadbox_form").submit();
}

