
// Standard Macromedia window resize function.

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

//Print page alert
// Modified in 2004 from code on original site by Mike Nicol at DestiNet Limited.

window.onerror = fel
function fel(){return true}

function printPage() {
if (window.print) {
agree = confirm('Please use mininum A4 paper size.\n\nSet ORIENTATION to LANDSCAPE\nin the Printer dialog box.\n\nClick OK to continue');
if (agree) window.print(); 
   }
}

// Standard Macromedia Find Objects function - needed for validation

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

// Validate forms function

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;
	switch(nm)
	{
		// General Contact, Download Brochure
		case "mail_Contact#00":
			nm = "Contact";
			break;
		case "mail_Company_Position#01":
			nm = "Company Position";
			break;
		case "mail_Company_Name#02":
			nm = "Company Name";
			break;
		case "mail_Address1#03":
			nm = "Address";
			break;
		case "mail_Town_City#05":
			nm = "Town/City";
			break;
		case "mail_Postcode#07":
			nm = "Postcode";
			break;
		case "mail_Email_Address#08":
			nm = "Email Address";
			break;
		case "mail_Phone_Number#09":
			nm = "Phone Number";
			break;
			// Booking Form
		case "mail_Course_Title#00":
			nm = "Course Title";
			break;
		case "mail_Date#01":
			nm = "Date";
			break;
		case "mail_Booking_Contact#04":
			nm = "Booking Contact";
			break;
		case "mail_Company_Name#06":
			nm = "Company Name";
			break;
		case "mail_Email_Address#12":
			nm = "Email Address";
			break;
		default:
			nm = nm;
}
	if ((val=val.value)!="") {
	  if (val.indexOf('@') >= 0 && test.indexOf('isEmail')==-1) { if (errors.indexOf('@ symbol') < 1 ) { errors+='Only Email Address should contain @ symbol.\n'; } }
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='please enter a valid email address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='please enter a valid telephone number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) 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('Please check the details you have entered:\n'+errors);
  document.MM_returnValue = (errors == '');
  }
  else
  {
	  if (document.getElementById)
	  {
	  	document.getElementById("Send_form").submit();
	  }
  }
}

function DN_ValidateFields()
{
	MM_validateForm('mail_Contact#00','','R','mail_Company_Position#01','','R','mail_Company_Name#02','','R','mail_Address1#03','','R','mail_Town_City#05','','R','mail_Postcode#07','','R','mail_Email_Address#08','','RisEmail','mail_Phone_Number#09','','R','mail_Course_Title#00','','R','mail_Date#01','','R','mail_Booking_Contact#04','','R','mail_Company_Name#06','','R','mail_Email_Address#12','','RisEmail');
	return document.MM_returnValue;
}



// 'Date last modified' function. 
// Modified in 2004 from code on original site by Mike Nicol at DestiNet Limited.

function initArray() 
{
  this.length = initArray.arguments.length
  for (var i = 0; i < this.length; i++)
  this[i+1] = initArray.arguments[i]
}

function writeDate(){
var DOWArray = new initArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var MOYArray = new initArray("January","February","March","April","May","June","July","August","September","October","November","December");
var LastModDate = new Date(document.lastModified);

//document.write(LastModDate);
document.write("Last updated on ");
document.write(DOWArray[(LastModDate.getDay()+1)],", ");
document.write(MOYArray[(LastModDate.getMonth()+1)]," ");
document.write(LastModDate.getDate(),", ",(LastModDate.getYear()));
document.write(".");
}


// 'Anchor links' function. Cross-browser internal link creator that uses
// image Alt tag to create image id.
// Created by Darren Curnow November 2004 at DestiNet Limited. 
// Modified on same day by Mike Nicol at DestiNet Limited.

function anchorLink() 
{ 
var totalImages = (document.images.length);
	for (i = 0; i < totalImages; i++)
	{
		 if ((document.images[i].src.indexOf('bullet_circle.gif')!=-1) || (document.images[i].src.indexOf('bullet_circle2lines.gif')!=-1) || (document.images[i].src.indexOf('bullet_circle3lines.gif')!=-1) || (document.images[i].src.indexOf('bullet_square.gif')!=-1) || (document.images[i].src.indexOf('bullet_exclaim.gif')!=-1))
		 {
		 	document.images[i].id=document.images[i].alt;
		 }
	}
}

//Check 'terms and conditions' are agreed/all relevent details are included.
// Created by Darren Curnow February 2005 at DestiNet Limited.
// Modified by Mike Nicol March 2005 at DestiNet Limited.

function checkAgree()
{
	if(document.getElementById("checkboxAgree").checked == false)
	{
		alert("you must agree to the terms and conditions to continue this transaction");
		returnValue=false;
	}
	else
	{
		submitForm();
	}
}

//form submission - eComm_deposit, eComm_invoice

function submitForm()
{
	// Check all required details are completed
	bAllFieldsCompleted = 0;
	bAllFieldsCompleted += checkDetails( "form_OrderReference" );
	bAllFieldsCompleted += checkDetails( "form_OrderAmount" );
	bAllFieldsCompleted += checkDetails( "form_CardHolderName" );
	bAllFieldsCompleted += checkDetails( "form_Address1" );
	bAllFieldsCompleted += checkDetails( "form_City" );
	bAllFieldsCompleted += checkDetails( "form_Postcode" );
	bAllFieldsCompleted += checkDetails( "form_TelNo" );
	bAllFieldsCompleted += checkDetails( "form_EmailAddress" );
	bAllFieldsCompleted += checkDetails( "form_CardType" );
	bAllFieldsCompleted += checkDetails( "form_CardNumber" );
	bAllFieldsCompleted += checkDetails( "form_ExpiryDateMonth" );
	bAllFieldsCompleted += checkDetails( "form_ExpiryDateYear" );

	if ( bAllFieldsCompleted > 0 )
	{
		alert("Please ensure all fields marked with an asterisk ( * ) are completed.");
	}
	else
	{
		if ( cleanPhoneNumber( "form_TelNo" ).length > 0 )
		{
			document.getElementById("Send_form").submit()
		}
		else
		{
			alert("You have not entered a valid phone number, please do so before submitting this form.\n\nWithout a valid phone number, we are not able to contact you if there is a problem with your payment,\nor to obtain any additional information that may be required to properly advise you.");	
		}
	}
}

function checkDetails( strField )
{
	bDataMissing = 0;
	if ( document.getElementById( strField ).value == "" ) bDataMissing = 1;
	return bDataMissing;
}

function cleanPhoneNumber( strField )
{
	if ( document.getElementById( strField ).value != "" )
	{
		strCleanData = stripNonNumeric( document.getElementById( strField ).value );
		document.getElementById( strField ).value = strCleanData;
		return strCleanData;
	}
}

// This function removes non-numeric characters 
function stripNonNumeric( str ) 
{ 
	str += ''; 
	var rgx = /^\d|\.|-$/; 
	var out = ''; 
	for( var i = 0; i < str.length; i++ ) 
	{ 
		if( rgx.test( str.charAt(i) ) )
		{ 
			if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) || ( str.charAt(i) == '-' && out.length != 0 ) ) )
			{ 
				out += str.charAt(i); 
			} 
		} 
	} 
	return out; 
}