// JavaScript Document
function validateform()
{
	var cname=document.make_appt.cname.value	
	var csurname=document.make_appt.csurname.value
	var address3=document.make_appt.chomeaddress3.value
	var address3=document.make_appt.chomeaddress3.value
	var address4=document.make_appt.chomeaddress4.value
	var mobileno=document.make_appt.cmobilenumber.value
	var age=document.make_appt.cage.value;
	var travel=document.make_appt.travel.value;
	var query=document.make_appt.query.value;
	var email=document.make_appt.cemail.value;
	var emailLength = email.length;
	var atPos = email.indexOf('@');
	var firstDotPos = email.indexOf('.');
	var lastDotPos = email.lastIndexOf('.');		
	var CV=document.make_appt.CVup.checked;
	var file=document.make_appt.cuploadcv.value;
	var legal=document.make_appt.legal.checked;
	var cguidancelocation1=document.make_appt.cguidancelocation1.value;
	var cguidancelocation2=document.make_appt.cguidancelocation2.value;
	var fdate=document.make_appt.first_preferred_date.value;	
	var firstdate = fdate.split("-");
	var firstdate = firstdate[1] + "/" + firstdate[0] + "/" + firstdate[2];
	var firstdate = new Date(firstdate);
	var firstlistavail = document.getElementById('firstlistavail');
	var secondlistavail = document.getElementById('secondlistavail');
	var firstlist = document.make_appt.firstlist;
	var secondlist = document.make_appt.secondlist;
	var sdate = document.make_appt.second_preferred_date.value;
	var seconddate = sdate.split("-");
	var seconddate = seconddate[1] + "/" + seconddate[0] + "/" + seconddate[2];
	var seconddate = new Date(seconddate);
	
	var date3 = new Date();
	var date4 = date3.getMonth()+1 + "/" + date3.getDate() + "/" + date3.getFullYear();
	var currentDate = new Date(date4);
	
		
	if(cname=="" || cname==null)
	{
		alert("Please enter First Name.");
		document.make_appt.cname.focus();
		return false;
	}
	if(csurname=="" || csurname==null)
	{
		alert("Please enter Surname.");
		document.make_appt.csurname.focus();
		return false;
	}
	if(address3=="" || address3==null)
	{
		alert("Please enter Home Address Line 3.");
		document.make_appt.chomeaddress3.focus();
		return false;
	}
	if(address4=="" || address4==null)
	{
		alert("Please select County.");
		document.make_appt.chomeaddress4.focus();
		return false;
	}
	if(mobileno=="" || mobileno==null)
	{
		alert("Please enter mobile no.");
		document.make_appt.cmobilenumber.focus();
		return false;
	}
	
	if(email=="" || email==null)
	{
	alert ("Email should not be blank");
	document.make_appt.cemail.focus();
	return false;
	}
	if (emailLength < 7)
	{
	alert("Not valid Email!!");
	document.make_appt.cemail.focus();
	return false;                // minimum email address length ("x@xx.xx")
	}
	if (atPos < 1)
	{
	alert("Not valid Email!!");
	document.make_appt.cemail.focus();
	return false;                    // traps for no @, or @ as first character
	}
	if (firstDotPos < 1)
	{
	alert("Not valid Email!!");
	document.make_appt.cemail.focus();
	return false;                // traps for no ., or . as first character
	}
	if (atPos == emailLength-1)
	{
	alert("Not valid Email!!");
	document.make_appt.cemail.focus();
	return false;        // traps for @ as penultimate or last character
	}
	if (lastDotPos >= emailLength-2)
	{
	alert("Not valid Email!!");
	document.make_appt.cemail.focus();
	return false;    // traps for too few digits after last . (must be at least 2)
	}
		// traps for @ character next to . character
    if (email.charAt(atPos-1) == '.' || email.charAt(atPos+1) == '.')
	{
	alert("Not valid Email!!");
	document.make_appt.cemail.focus();
	return false;
	}
	
	if(age=="" || age=="null")
	{
		alert("Please enter your age.");
		document.make_appt.cage.focus();
		return false;
	}
	if(CV == true && file == "")
	{
		alert("Please upload your CV");
		document.make_appt.cuploadcv.focus();
		return false;
	}	
	if(firstdate!="" && firstdate < currentDate)
	{
		alert("First Preferred Date should not be less than current date.");
		document.make_appt.first_preferred_date.focus();
		return false;	
	}
	if(seconddate!="" && seconddate < currentDate)
	{
		alert("Second Preferred Date should not be less than current date.");
		document.make_appt.second_preferred_date.focus();
		return false;	
	}
	if(travel=="" || travel=="null")
	{
		alert("Please enter your \"How do you intent getting to your appointment (for example, lift with parents or friend, bus, train, etc)\".");
		document.make_appt.travel.focus();
		return false;
	}
	if(query=="" || query=="null")
	{
		alert("Please enter your \"Please insert a synopsis of your career query\".");
		document.make_appt.query.focus();
		return false;
	}
	if(cguidancelocation1=="" || cguidancelocation1=="null")
	{
		alert("Please select \"Select your preferred career guidance counsellor and location:\".");
		document.make_appt.cguidancelocation1.focus();
		return false;
	}	
	if(firstlistavail.value == "yes")
	{
		var felength = firstlist.length;		
		if(isNaN(felength))
		{
			if(firstlist.checked == true)
			{
				var firstche = "yes";
			}
		}
		else
		{
			for(var i = 0; i < felength; i++)
			{			
				if(firstlist[i].checked == true)
				{
					var firstche = "yes";
				}
			}
		}
		if(firstche != "yes")
		{
			alert("Please select \"Select your preferred career guidance counsellor:\".");
			document.make_appt.cguidancelocation1.focus();
			return false;		
		}
	}
	if(cguidancelocation2=="" || cguidancelocation2=="null")
	{
		alert("Please select \"Select your 2nd preferred career guidance counsellor and Location\".");
		document.make_appt.cguidancelocation1.focus();
		return false;
		
	}
	if(secondlistavail.value == "yes")
	{	
		var selength = secondlist.length;
		if(isNaN(selength))
		{
			if(secondlist.checked == true)
			{
				var secondche = "yes";
			}
		}
		else
		{
			for(var i = 0; i < selength; i++)
			{			
				if(secondlist[i].checked == true)
				{
					var secondche = "yes";
				}
			}
		}
		if(secondche != "yes")
		{
			alert("Please select \"Select your 2nd preferred career guidance counsellor\".");
			document.make_appt.cguidancelocation2.focus();
			return false;		
		}
	}
	if(legal != true)
	{
		alert("Please check on 'Please ensure you have read the website legal notices'.");
		document.make_appt.legal.focus();
		return false;
	}	
	
return true;
}
//Toggle Box
function ToogleTextbox(pValue)
{
	
		var text = document.getElementById("CV");
		if(text.style.display == "none")
		{	
			text.style.display = "block";
		}
		else
		{
			text.style.display = "none";
		}
	
}
