function adjustLayout(){

	//Get natural heights
	var cHeight = xHeight("body_index");
	var dHeight = xHeight("body");
	var rHeight = xHeight("info")+302;
	
	//Find Maximum height
	var maxHeight = Math.max(Math.max(cHeight, rHeight),dHeight);
	
	//Apply the height to all columns
	xHeight("body_index", maxHeight);
	xHeight("body", maxHeight);
	xHeight("info", maxHeight-302);

}


/* Standard Functions */


function checkPayment(){

	//Adjust fields by removing invalid characters
	document.payment_details.cardnumber.value=validateNum(document.payment_details.cardnumber.value);
	document.payment_details.cardname.value=validateAlpha(document.payment_details.cardname.value);
	//document.payment_details.cardsecurity.value=validateNum(document.payments_details.cardsecurity.value);
	document.payment_details.cardissue.value=validateNum(document.payment_details.cardissue.value);
	
	//Set up vairables
	var error="";

	//Check all fields
	//Card Number
	if(document.payment_details.cardnumber.value==""){
		error += "Please enter a valid card number.\n";
	} else {
		if(!luhnCheck(document.payment_details.cardnumber.value)){
			error += "Your card number appears invalid, please check.\n";
		}
	}
	//Card Name
	if(document.payment_details.cardname.value==""){
		error += "Please enter the Cardholders name as printed on the card.\n";
	}
    //Card Security
    if(document.payment_details.cardsecurity.value==""){
		error += "Please enter the 3 or 4 digit card security number.\n";
	}
    //Terms acceptance
    if(!document.payment_details.conditions.checked){
		error += "\nYou need to accept our terms and conditions to proceed.\n";
	}
		
    //Validate the submittion and flag errors if applicable
	if(error==""){
		//valid - sumit
		return true;
	} else {
		//invalid - flag errors
		alert("You have the following errors, please check and resubmit:-\n\n"+error);
		return false;
	}
}

function checkBooking(){

	document.booking_details.email.value=validateEmail(document.booking_details.email.value);

	//Set up vairables
	var error="";

	//Check all fields
	//Card Number
	if(document.booking_details.name.value==""){
		error += "...Please enter your name.\n";
	}
	if(document.booking_details.address.value==""){
		error += "...Please enter your address.\n";
	}
	if(document.booking_details.town.value==""){
		error += "...Please enter your town/city.\n";
	}
	if(document.booking_details.county.value==""){
		error += "...Please enter your county.\n";
	}
	if(document.booking_details.postcode.value==""){
		error += "...Please enter your postcode.\n";
	}
	if(document.booking_details.country.value==""){
		error += "...Please enter your country.\n";
	}
	if(document.booking_details.email.value==""){
		flag=1; error += "...Please enter an email address to proceed\n";
	} else {
		if(document.booking_details.email.value.indexOf("@")==-1 && document.booking_details.email.value.indexOf(".")==-1){
			flag=1; error += "...Please check your email address, it appears invalid\n";
		}
	}
	
    //Validate the submittion and flag errors if applicable
	if(error==""){
		//valid - sumit
		return true;
	} else {
		//invalid - flag errors
		alert("You have the following errors, please check and resubmit:-\n\n"+error);
		return false;
	}
}





	
function validateNum(string){
    for (var i=0, output='', valid="1234567890"; i<string.length; i++)
    if (valid.indexOf(string.charAt(i)) != -1)
    output += string.charAt(i)
    return output;
} 
	
function validateAlpha(string){
    for (var i=0, output='', valid="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "; i<string.length; i++)
    if (valid.indexOf(string.charAt(i)) != -1)
    output += string.charAt(i)
    return output;
}
	
function validateEmail(string){
    for (var i=0, output='', valid="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.@+"; i<string.length; i++)
    if (valid.indexOf(string.charAt(i)) != -1)
    output += string.charAt(i)
    return output;
} 

function changecardtype(){
	//Solo or Switch (Issue number required)
	if(document.payment_details.cardtype.options[4].selected||document.payment_details.cardtype.options[3].selected){
		document.payment_details.cardissue.disabled=false;
	}
	//Regular cards (Issue number not required)
	if(document.payment_details.cardtype.options[0].selected||document.payment_details.cardtype.options[1].selected||document.payment_details.cardtype.options[2].selected){
		document.payment_details.cardissue.value="";
		document.payment_details.cardissue.disabled=true;
	}
    //Credit Cards (Valid From date not required)
	if(document.payment_details.cardtype.options[0].selected||document.payment_details.cardtype.options[1].selected){
		document.payment_details.validmonth.options[0].selected=true;
		document.payment_details.validyear.options[0].selected=true;
		document.payment_details.validmonth.disabled=true;
		document.payment_details.validyear.disabled=true;
	}
    //Debit Cards (Valid From date required)
	if(document.payment_details.cardtype.options[2].selected||document.payment_details.cardtype.options[3].selected||document.payment_details.cardtype.options[4].selected){
		document.payment_details.validmonth.disabled=false;
		document.payment_details.validyear.disabled=false;
		document.payment_details.validmonth.options[1].selected=true;
		document.payment_details.validyear.options[1].selected=true;
	}
}
	
function luhnCheck(CardNumber){
	if(CardNumber<10000||CardNumber==""){
		return false;
	}
	var no_digit = CardNumber.length;
	var oddoeven = no_digit & 1;
	var sum = 0;
	for (var count = 0; count < no_digit; count++){
		var digit = parseInt(CardNumber.charAt(count));
		if (!((count & 1) ^ oddoeven)){
			digit *= 2;
			if (digit > 9)
				digit -= 9;
			}
			sum += digit;
		}
	if (sum % 10 == 0){
		return true;
	} else {
	return false;
	}
}


//Image Swap script
function ChangePic(img_name,img_src){
    document[img_name].src=img_src;
    }
	
function NewWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
	}


function show_image_library(item) {
	//Popup date picker window
	vWinCal = window.open("image_library.php"+item,"browser","width=800,height=600,status=no,resizable=no");
	vWinCal.opener=self;
}


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 == '');
}


