function doNothing(){
}

function toggle(n){
	subMenu = document.getElementById(n);
	if (subMenu.style.display == "none"){
		subMenu.style.display = "block";
	} else {
		subMenu.style.display = "none";
	}		
}

function toggleMe( targetId, gfx ){
  if (document.getElementById){
        target = document.getElementById( targetId );
		gfx = document.getElementById( gfx );
           if (target.style.display == "none"){
              target.style.display = "";
			  gfx.src = "images/close.gif";
			  gfx.alt = "Click to close details";
           } else {
              target.style.display = "none";
			  gfx.src = "images/open.gif";
			  gfx.alt = "Click to view details";
           }
     }
}
var delegateArray = new Array(10);
delegateArray[1] = "st";
delegateArray[2] = "nd";
delegateArray[3] = "rd";
delegateArray[4] = "th";
delegateArray[5] = "th";
delegateArray[6] = "th";
delegateArray[7] = "th";
delegateArray[8] = "th";
delegateArray[9] = "th";
delegateArray[10] = "th";


function delegatePriceCheck(g){
	if(document.courseBookingForm['Number Of Delegates'].value == "0"  && (document.courseBookingForm.Membership[0].checked==true || document.courseBookingForm.Membership[1].checked==true)){
		document.courseBookingForm['Course Total Cost'].value = "Course cost can not be calculated as number of delegates has not been specified";
	}
}


function delegateCheck(){
	
	if(document.courseBookingForm['Price Quoted'].value != ""){
		if(document.courseBookingForm['Price Quoted'].value != "None Quoted"){
			var coursePrice = document.courseBookingForm['Price Quoted'].value;
			var delegates = parseFloat(document.courseBookingForm['Number Of Delegates'].value);
			var outputText = "<h3>Calculated Price</h3>Total course price <strong>excluding VAT</strong> is \u00A3" + parseFloat(coursePrice) + "<br />X " + delegates + " Delegates<br />= <strong>\u00A3" + parseFloat(coursePrice) * delegates + "</strong>";
			document.getElementById('calcPrice').innerHTML = outputText;
		} else {
			document.getElementById('calcPrice').innerHTML = "<h3>Calculated Price</h3>Unable to calculate total course price. <br /><strong>See course description for details.</strong>";
		}
	}
	
	delegateNo = parseFloat(document.courseBookingForm['Number Of Delegates'].value);
	for (i=delegateNo+1;i<11;i++){
		target = document.getElementById( "delegate" + i );
		target.style.display = "none";
		formTarget = i + delegateArray[i];
		document.courseBookingForm[formTarget + ' delegate title'].value = "Please select";
		document.courseBookingForm[formTarget + ' delegate surname'].value = "";
		document.courseBookingForm[formTarget + ' delegate forename'].value = "";
		document.courseBookingForm[formTarget + ' delegate position'].value = "";
	}
	for (i=1;i<=delegateNo;i++){
		target = document.getElementById( "delegate" + i );
		target.style.display = "block";
	}
}

function delegateReset(){
	for (i=1;i<11;i++){
		target = document.getElementById( "delegate" + i );
		target.style.display = "none";
		formTarget = i + delegateArray[i];
		document.courseBookingForm[formTarget + ' delegate title'].value = "Mr";
		document.courseBookingForm[formTarget + ' delegate surname'].value = "";
		document.courseBookingForm[formTarget + ' delegate forename'].value = "";
		document.courseBookingForm[formTarget + ' delegate position'].value = "";
	}
	document.getElementById('calcPrice').innerHTML = "";
}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


function priceCheck(y){
	
	if(document.courseBookingForm['Number Of Delegates'].value == "0"){
		document.getElementById('calcPrice').innerHTML = "<h3>Calculated Price</h3>Course cost can not be calculated as number of delegates has not been specified";
		if(IsNumeric(y)){
			document.courseBookingForm['Price Quoted'].value = parseFloat(y);
		} else {
			document.courseBookingForm['Price Quoted'].value = "None Quoted";
		}
	} else {
		if(IsNumeric(y)){
			// course price is a standard price
			document.courseBookingForm['Price Quoted'].value = parseFloat(y);
			var delegates = parseFloat(document.courseBookingForm['Number Of Delegates'].value);
			var outputText = "<h3>Calculated Price</h3>Total course price <strong>excluding VAT</strong> is \u00A3" + parseFloat(y) + "<br />X " + delegates + " Delegates<br />= <strong>\u00A3" + parseFloat(y) * delegates + "</strong>";
			document.getElementById('calcPrice').innerHTML = outputText;
		} else {
			// course price contains other information
			document.courseBookingForm['Price Quoted'].value = "None Quoted";
			document.getElementById('calcPrice').innerHTML = "<h3>Calculated Price</h3>Unable to calculate total course price. <br /><strong>See course description for details.</strong>";
		}
	}
}

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 YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

function onlineMap(){
	GP_AdvOpenWindow('online-map.htm','Map','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no',800,600,'center','ignoreLink','',0,'');
}
