function validate_required(field)
{
	with (field)
	{
	if (value==null||value=="")
	  {
	  	return false;
	  }
	else {
		return true;
	}
	}
}


function validate_form(thisform)
{

	alerttxt="Portions of your Application Form are missing:";

	with (thisform)
	{
	ok = true; 
	
	if (validate_required(Payroll_No)==false)
	{
		alerttxt = alerttxt + "\n    Please confirm your Payroll/Employee number";
		ok = false;
	}
	
	if (validate_required(First_Name)==false)
	{
		alerttxt = alerttxt + "\n    Please confirm your First Name";
		ok = false;
	}
	if (validate_required(Last_Name)==false)
	{
		alerttxt = alerttxt + "\n    Please confirm your Last Name";
		ok = false;
	}
	
		
	//Check that the user has supplied a Contact Type
	
	for (var i=0; i<document.contact_payroll.Contact_Type.length; i++){
	
	if(document.contact_payroll.Contact_Type[i].checked)
	{
		var checked_contact = true;
		var contact_me = document.contact_payroll.Contact_Type[i].value;
		break;
	}
	}
	
	if (!checked_contact){
		alerttxt = alerttxt + "\n    Please confirm your Contact Type";
		ok = false;
	}
	
	//Check that the user has supplied a Hear About Us
	
	if(contact_me=="Email"){
	
		if (validate_required(Email_Me)==false)
		{
			alerttxt = alerttxt + "\n    Please confirm your Email Address";
			ok = false;
		}		
	}
	else if(contact_me=="Phone"){
		if (validate_required(Phone_Me)==false)
		{
			alerttxt = alerttxt + "\n    Please confirm your Phone Number";
			ok = false;
		}
	}
	if (validate_required(Payroll_Query)==false)
	{
		alerttxt = alerttxt + "\n    Please provide your Payroll query.";
		ok = false;
	}
	if (ok==true){
		return true;
	}
	else{
		alert(alerttxt); 
		return false;
	}

}
}

//Function to limit the text box area on the contact_payrolls.asp page to a number of chars

var max=0;
function showChar(obj)
{
	var obj3=document.getElementById("char");
	if(max==0)
	{
		max=obj3.firstChild.nodeValue*1;
	}
	len=obj.value.length;
	var cur=max*1;
	cur=cur-len;
	if(cur<0)
	{
		var obj2=document.forms[0].elements['Payroll_Query'];
		var str=obj2.value.substring(0,max*1);
		obj2.value=str;

		var lang = document.contact_payroll.language.value;


			switch(lang){
				case "EN":				
					alert('Input limit has been reached.');
				break;
				default:
					alert('The maximum text limit has been reached..');
				break;				
			}
		showChar(obj2,max);					
		return false;
	}
	else
	{
		var obj2=document.getElementById('char');
		var str=document.createTextNode(cur);
		obj2.replaceChild(str,obj2.firstChild);
		return true;
	}
}		
