// JavaScript Document
 var scNAMEJDates="startingdates";
 var scNAMESWeeks="studyweeks";
 var scNAMESWeekslist="studyweekslist";
 var scNAMEModules="modules"; 
 var scNAMEUnit="unit";
 var scNAMELevel="englishlevel";
 var scSeperate= "=>"
 var scARRVLDate="arrivaldate"
 var scMYARRVLDate="myarrivaldate"
 var scLNGTHStay="lengthofstay"
 var scDATECTRLType="datecontroltype"
 var icCNTXT_ACCOMMODATION=32
 function sendForm(oform) {

oform.submit();
}
 function sendacctypeForm(oform) {
oform.contextid.value=oform.contextid.value - icCNTXT_ACCOMMODATION
oform.submit();
}

function validatecourse(oform) {

	var bNotHit=true;
	var iCount=0
	var bPrm = false;
	var smodules=""
	var breturnvalue=0;

	if (oform.Courses.length)
	{
		for (var i=0; i<oform.Courses.length; i++)
		{
			if (oform.Courses[i].checked)
			{
				bNotHit=false;
				iCount=iCount+1;
			}
		}
	}
	else
	{
		if (oform.Courses.checked)
			{
				bNotHit=false;
				iCount=iCount+1;
			}
	}

		
	if (bNotHit)
	{
		alert("You must choose a course to continue.");
		return false;
		
	}
	
	if (oform.Courses.length)
	{	
		for (var j=0; j<oform.Courses.length; j++)
		{
			if (oform.Courses[j].checked)
			{
				var sValue=oform.Courses[j].value;
				breturnvalue=checkmodules(oform,sValue);
				
				if (breturnvalue) 
				{
					if (bPrm) {smodules=smodules + ", "}
					smodules=smodules + breturnvalue
					bPrm=true;
				}
				if (breturnvalue==false)
				{
				
					return false;
				}
	
			}
		}
	}
	else
	{
		if (oform.Courses.checked)
			{
				var sValue=oform.Courses.value;
				breturnvalue=checkmodules(oform,sValue);
		
				if (breturnvalue) 
				{
					if (bPrm) {smodules=smodules + ", "}
					smodules=smodules + breturnvalue
					bPrm=true;
				}
				if (breturnvalue==false)
				{
				
					return false;
				}
			}
	
	}
	
oform.modules.value=smodules

sendForm(oform);
return 0;
}
 
function checkmodules(oform,sname) 
{ 
	var bPrm=false;
	for (var i=1; i<oform.length; i++)
	{
	
		var a = oform.elements[i].name;
		if  (a == sname + scNAMEModules)
		{

			var sValue =oform.elements[i].value ;
			if (sValue=='0')
			{
				alert("You must choose a module continue.");
				oform.elements[i].focus();
				return false;
			}
			else
			{
				return sValue;
			}
		}
	}

}



function validatedates(oform,vtravelflag) {
	var sDates="";
	var sWeeks="";
	var bPrm=false
	var bPrm1=false;
	for (var i=1; i<oform.length; i++)
	{
		var a = oform.elements[i].name;
		if  (a.substring(a.length - scNAMEJDates.length,a.length) == scNAMEJDates && a.length > scNAMEJDates.length )
		{
			var sValue =oform.elements[i].value ;
			
			if (check_date(oform.elements[i])>0 )
			{
				alert("You must choose/type a Valid Starting date to continue.");
				return false;
			}
			else
			{
				
				if (bPrm) { sDates=sDates+ ", "}
				var re = new RegExp("=>");
				//sValue=sValue.substring(0,sValue.search(re));
				sDates=sDates + sValue;
				bPrm=true;
			}
		}
		if  (a.substring(a.length - scNAMESWeeks.length,a.length) == scNAMESWeeks && a.length > scNAMESWeeks.length )
		{
			var sValue =oform.elements[i].value ;
			if (sValue <'1')
			{
				alert("You must choose a Number of weeks to continue.");
				return false;
			}
			else
			{
				if (bPrm1) { sWeeks=sWeeks+ ", " }
				sWeeks=sWeeks + sValue;
				bPrm1=true;
			}
			
		}
		if  (a == scNAMELevel )
		{
			var sValue =oform.elements[i].value ;
			if (sValue.length <3)
			{
				alert("You must choose Your level of English to continue.");
				oform.elements[i].focus();
				return false;
			}
		}


	}		


oform.joiningdates.value=sDates;
oform.units.value=sWeeks;
if  (vtravelflag == 1 )
	{
	oform.action ="travel00_Booking.asp?page=3";
	}
else
	{
	oform.action ="courses00_Booking.asp?page=3";
	}
sendForm(oform);
return 0;
}
function validateaccskip(oform)
{

if (oform.accrequired[0].checked)
{	
oform.action ="courses00_Booking.asp?page=4";
}
if (oform.accrequired[1].checked)
{	
oform.action ="courses00_Booking.asp?page=8";
}



sendForm(oform);
return 0;
}
function validatetravel(oform) {
var coursefee;
var course;
	if (oform.firstname.value=="" ){
			alert("You must enter your name ");
			oform.firstname.focus();
		return false;
	}

	if (oform.lastname.value=="" ){
			alert("You must enter your name ");
			oform.lastname.focus();
		return false;
	}

	if (oform.email.value=="" ){
			alert("You must enter your email address ");
			oform.email.focus();
		return false;	}
if ( oform.ba1.checked==false && oform.ba2.checked==false && oform.galileo.checked==false){
			alert("You must select a course ");
		return false;
	}



var amount=parseInt(oform.amount1.value)
 if (isNaN(amount)  ){
			alert("You must a valid amount for payment");
			oform.amount1.focus();
		return false;
		}
 if (amount<50  ){
			alert("You must pay at least the deposit (£50) amount ");
			oform.amount1.focus();
		return false;
		}

oform.amount.value=amount*100;

	if (oform.paymenttype[0].checked )
	oform.action ="https://securetrading.net/authorize/form.cgi"; 
	else {
	oform.action ="travbanktransfer.asp";}

sendForm(oform);
return 0;
}
function calculatetravel(oform){
 if (oform.ba1.checked  ){
   coursefee=370;
	course="BA Level 1 -";}
	else {course=""; coursefee=0;}
 if (oform.ba2.checked  ){
   coursefee=coursefee + 370 ;
		course= course + "- BA Level 2 ";}
 if (oform.galileo.checked ){
   coursefee=coursefee + 275 ;
   course= course + "- Galileo ";}
  if (coursefee==1015 ) { coursefee=975; }
oform.amount1.value=coursefee;
oform.coursefee.value=coursefee;
oform.course.value=course;
oform.orderref.value=course;
return 0;

}

function Getmaxunit(sValue) {
var mystr=sValue;
var re=/>/i;

	if (mystr.length>1){
		var x=mystr.substring(mystr.search(re)+1,mystr.length);
		return(x);
	}
return 0;
}

function FillNoofWeeks(oform, icid,iunit) {
	for (var i=0; i<oform.length; i++)
	{
		var a = oform.elements[i];
		if  (a.name == icid+scNAMEJDates )
			{
			var myoctrrl2=oform.elements[i];
			var myimax=Getmaxunit(myoctrrl2.value);
			}
	}
	for (var i=0; i<oform.length; i++)
	{
		var a = oform.elements[i];
		if  (a.name == icid+scNAMESWeeks )
			{
			var myoctrrl=oform.elements[i];
			}
	}
	for (var i=0; i<oform.length; i++)
	{
		var a = oform.elements[i];
		if  (a.name == icid+scNAMEUnit )
			{
			var sUnit=oform.elements[i].value;
			}

	}
	
	z=myoctrrl.options.length
	for (var j=0; j<z; j++)
	{
		myoctrrl.options.remove(0);
	}
	var oOption = document.createElement("OPTION");
	myoctrrl.options.add(oOption);
	oOption.innerText =  "Number of " + sUnit
	oOption.value = 0;				
	for (var j=iunit; j<=myimax; j++)
	{
		var oOption = document.createElement("OPTION");
		myoctrrl.options.add(oOption);
		oOption.innerText =  j + " " + sUnit + "(s)"
		oOption.value = j;
		if (j==iunit){ oOption.selected=true;}
	}

	return 0;

}
function ReFillNoofWeeks(oform) {
	for (var i=1; i<oform.length; i++)
	{
		var a = oform.elements[i].name;
		var re = new RegExp("studyweeks");
		if  (a.search( re)>0 )
			{
			var b=a.substring(0,a.search( re));
			FillNoofWeeks(oform, b,oform.elements[i].value)
			}
	}
	return 0;

}
function FillAccNoofWeeks(oform, iunit,iminunit) {
var myimax=0
	for (var i=1; i<oform.length; i++)
	{
		var a = oform.elements[i];
		if  (a.name == scMYARRVLDate && oform.datecontroltype.value==1 )
			{
			var myoctrrl2=oform.elements[i];
			var myimax=Getmaxunit(myoctrrl2.value);
			}
		if  (a.name == scLNGTHStay )
			{
			var myoctrrl=oform.elements[i];
			}
		if  (a.name == scDATECTRLType )
			{
			cmbtype=oform.elements[i].value;
			}
	}
	if (myimax==0){
		myimax=48;
	}
	var sUnit="Week";
	z=myoctrrl.options.length
	for (var j=0; j<z; j++)
	{
		myoctrrl.options.remove(0);
	}
	var oOption = document.createElement("OPTION");
	myoctrrl.options.add(oOption);
	oOption.innerText =  "Number of " + sUnit
	oOption.value = 0;				
	for (var j=iminunit; j<=myimax; j++)
	{
		var oOption = document.createElement("OPTION");
		myoctrrl.options.add(oOption);
		oOption.innerText =  j + " " + sUnit + "(s)"
		oOption.value = j;
		if (j==iunit){ oOption.selected=true;}
	}

	return 0;

}

function validateacc(oform) {
var i=getSelectedButton(oform.acccategory);
if (i==-1)
{
alert("You must choose an accommodation to continue. Thank you");
return false;
}

oform.action ="courses00_Booking.asp?page=5";
sendForm(oform);
return 0;
}

function validateaccdates(oform) {
var combotype=oform.datecontroltype.value

if (combotype==1 )
{
	var sDate=oform.myarrivaldate.value;
	if ( sDate.length<3  )
		{
			alert("Arrival Date is required ");
			oform.myarrivaldate.focus();
			return false;
		}
		var re = new RegExp("=>");
		sDate=sDate.substring(0,sDate.search(re));
}
else
{ 
	
	if (check_date(oform.myarrivaldate)>0 )
		{
			alert("Arrival Date is required/wrong ");
			oform.myarrivaldate.focus();
			return false;
		}
	var sDate=oform.myarrivaldate.value;
}
if ( oform.lengthofstay.value<'1' )
	{
		alert("Length of Stay is required ");
		oform.lengthofstay.focus();
		return false;
	}


if (oform.shared.value==1 )
	{
	if (oform.sharename.value.length==0)
		{
		alert("Please enter the name of the person with whom you wish to share. ");
		oform.sharename.focus();
		return false;
		}
	}

		
oform.arrivaldate.value=sDate;

sendForm(oform);
return 0;
}
function validatetransferskip(oform)
{

if (oform.transferrequired[0].checked)
{	oform.action ="courses00_Booking.asp?page=7";}
if (oform.transferrequired[1].checked)
{	oform.action ="courses00_Booking.asp?page=8";}

sendForm(oform);
return 0;
}


function validatetarnsfer(oform) {
var i=getSelectedButton(oform.transfer);
if (i==-1)
{
alert("You must choose a transfer to continue. Thank you");
return false;
}
sendForm(oform);
return 0;
}
function validatepersonal(oform) {

	if (oform.first_name.value=="" ){
			alert("You must enter your first name ");
			oform.first_name.focus();
		return false;
	}
	if (oform.last_name.value=="" ){
			alert("You must enter your last name ");
			oform.last_name.focus();
		return false;
	}
	if (oform.nationality.value=="" ){
			alert("Nationality is required ");
			oform.nationality.focus();
		return false;
	}

	if (check_date(oform.dateofbirth)>0 )
		{
			alert("Date of birth is required/wrong ");
			oform.dateofbirth.focus();
			return false;
		}
	if (isemail (oform.email.value)==false ){
			alert("You must enter your valid email address ");
			oform.email.focus();
		return false;	}

	if (oform.h_no.value=="" ){
			alert("House No is required ");
			oform.h_no.focus();
		return false;
	}
	if (oform.street.value=="" ){
			alert("Street is required ");
			oform.street.focus();
		return false;
	}
	if (oform.city.value=="" ){
			alert("city is required ");
			oform.city.focus();
		return false;
	}
	if (oform.postcode.value=="" ){
			alert("Post Code is required ");
			oform.postcode.focus();
		return false;
	}
	if (oform.country.value=="" ){
			alert("Country is required ");
			oform.country.focus();
		return false;
	}

sendForm(oform);
return 0;
}
function validateenquiry(oform) {

	if (oform.firstname.value=="" ){
			alert("You must enter your first name ");
			oform.firstname.focus();
		return false;
	}
	if (oform.lastname.value=="" ){
			alert("You must enter your last name ");
			oform.lastname.focus();
		return false;
	}
	if (isemail (oform.email.value)==false ){
			alert("You must enter your valid email address ");
			oform.email.focus();
		return false;	}
	if (oform.age.value.length>0 && isnumber (oform.age.value)==false ){
			alert("You must enter your valid age i.e. numbers ");
			oform.age.focus();
		return false;	}
	if (oform.message.value.length>1000 ){
		 var msg = "Sorry, you have input "+oform.message.value.length+" characters into the "+
		   "Message text area. It can return no more than "+
		   1000+" characters to be processed. Please remove "+
		   "your text by at least "+(oform.message.value.length-1)+" characters";		
			alert(msg);
			oform.message.focus();
		return false;	}

sendForm(oform);
return 0;
}
function isemail(strvalue){
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(strvalue))
return true
else{
return false
}
}
function isnumber(strvalue){
var filter=/^\d+$/
if (filter.test(strvalue))
return true
else{
return false
}
}
function validatecheckout(oform,travelflag) {
/*if (parseInt(oform.amount.value)!= parseInt(oform.myamount.value) ){
oform.amount.value=oform.myamount.value;
}*/
var dummy=oform.minAmount.value;

if ( oform.tempamount.value=="" ){
	alert("You must pay at least a deposit of at  £" + dummy + " Thank you");
			oform.tempamount.focus();

	return false;
	}
 if (parseInt(oform.tempamount.value)<dummy ){
	alert("You must pay a deposit of at  £" + dummy + " Thank you");
			oform.tempamount.focus();

	return false;
	}	


oform.amount.value=oform.tempamount.value*100;

	if (oform.paymenttype[0].checked )
	{
	oform.action ="https://securetrading.net/authorize/form.cgi"; 
	}
	else
	{
		if (travelflag==1 )
		{
			oform.action ="travel00_Booking.asp?page=5";
		}
		else
		{
			oform.action ="courses00_Booking.asp?page=10";
		}
	}

sendForm(oform);
return 0;

}
function getSelectedButton(buttonGroup)
{
	if (buttonGroup.length>0)
	{
		for (var i=0; i<buttonGroup.length; i++)
		{
			if (buttonGroup[i].checked)
			{
				return i
			}
		}
	}
	else {
			if (buttonGroup.checked)
			{
				return i
			}
	
	}
	return -1;
}

function check_date(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = "-";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;

   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   //if (DateValue.length != 8) {
   //   return 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      return  (20);
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      return 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     return  22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      return 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      return 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      return 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
	DateField.value = day + seperator + month + seperator + year;
	return 0;
}

var highlightcolor="#ffffff"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
    function opengrammartest() {
        self.name = "main"; // names current window as "main"
                window.open("","grammaertest","width=850,height=600,resizable=yes,status=no,scrollbars=yes")
               }
                