function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}


//------------random quote--------------------
function makeArray(len){
	for (var i = 0; i < len; i++) this[i] = null;
	this.length = len;
}

headpic = new makeArray(50);
headpic[0] = "<img src='../images/pics/wide/pic001.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[1] = "<img src='../images/pics/wide/pic002.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[2] = "<img src='../images/pics/wide/pic003.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[3] = "<img src='../images/pics/wide/pic004.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[4] = "<img src='../images/pics/wide/pic005.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[5] = "<img src='../images/pics/wide/pic006.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[6] = "<img src='../images/pics/wide/pic007.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[7] = "<img src='../images/pics/wide/pic008.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[8] = "<img src='../images/pics/wide/pic009.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[9] = "<img src='../images/pics/wide/pic010.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[10] = "<img src='../images/pics/wide/pic011.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[11] = "<img src='../images/pics/wide/pic012.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[12] = "<img src='../images/pics/wide/pic013.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[13] = "<img src='../images/pics/wide/pic014.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[14] = "<img src='../images/pics/wide/pic015.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[15] = "<img src='../images/pics/wide/pic016.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[16] = "<img src='../images/pics/wide/pic017.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[17] = "<img src='../images/pics/wide/pic018.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[18] = "<img src='../images/pics/wide/pic019.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[19] = "<img src='../images/pics/wide/pic020.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[20] = "<img src='../images/pics/wide/pic021.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[21] = "<img src='../images/pics/wide/pic022.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[22] = "<img src='../images/pics/wide/pic023.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[23] = "<img src='../images/pics/wide/pic024.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[24] = "<img src='../images/pics/wide/pic025.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[25] = "<img src='../images/pics/wide/pic026.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[26] = "<img src='../images/pics/wide/pic027.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[27] = "<img src='../images/pics/wide/pic028.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[28] = "<img src='../images/pics/wide/pic029.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[29] = "<img src='../images/pics/wide/pic030.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[30] = "<img src='../images/pics/wide/pic031.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[31] = "<img src='../images/pics/wide/pic032.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[32] = "<img src='../images/pics/wide/pic033.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[33] = "<img src='../images/pics/wide/pic034.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[34] = "<img src='../images/pics/wide/pic035.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[35] = "<img src='../images/pics/wide/pic036.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[36] = "<img src='../images/pics/wide/pic037.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[37] = "<img src='../images/pics/wide/pic038.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[38] = "<img src='../images/pics/wide/pic039.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[39] = "<img src='../images/pics/wide/pic040.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[40] = "<img src='../images/pics/wide/pic041.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[41] = "<img src='../images/pics/wide/pic042.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[42] = "<img src='../images/pics/wide/pic043.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[43] = "<img src='../images/pics/wide/pic044.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[44] = "<img src='../images/pics/wide/pic045.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[45] = "<img src='../images/pics/wide/pic046.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[46] = "<img src='../images/pics/wide/pic047.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[47] = "<img src='../images/pics/wide/pic048.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[48] = "<img src='../images/pics/wide/pic049.jpg' width='107' height='69' hspace='1' vspace='2'>";
headpic[49] = "<img src='../images/pics/wide/pic050.jpg' width='107' height='69' hspace='1' vspace='2'>";

var pic1="";
var pic2="";
var pic3="";
var pic4="";

function rand(n) {
	seed = (0x015a4e35 * seed) % 0x7fffffff;
	return (seed >> 16) % n;
}
        
var now = new Date();
var seed = now.getTime() % 0xffffffff;

function generate(){
	pic1=rand(headpic.length);
	pic2=rand(headpic.length);
	pic3=rand(headpic.length);
	pic4=rand(headpic.length);
	if (pic1==pic2 | pic1==pic3 | pic1==pic4 | pic2==pic3 | pic2==pic4 | pic3==pic4){
		generate();
	} else {
		document.write(headpic[pic1]);
		document.write(headpic[pic2]);
		document.write(headpic[pic3]);
		document.write(headpic[pic4]);
	}	  
}

//ezine subscription
function validateSubscribe() {
	if(document.subscribeForm.mb-name.value==""){
		alert("Please enter your Name.");
		document.subscribeForm.mb-name.focus();
		return false;
	} else if(document.subscribeForm.mb-qi-qi.value==""){
		alert("Please enter a valid E-mail Address.");
		document.subscribeForm.mb-qi-qi.focus();
		return false;
	} else {
		return true;
	}
}

//ezine subscription
function validateNavSubscribe() {
	if(document.nav_subscribe.firstname.value==""){
		alert("Please enter your First Name.");
		document.nav_subscribe.firstname.focus();
		return false;
	} else if(document.nav_subscribe.email.value==""){
		alert("Please enter a valid E-mail Address.");
		document.nav_subscribe.email.focus();
		return false;
	} else {
		return true;
	}
}

function navSubscribe_firstname(){
	if(document.nav_subscribe.firstname.value=="First Name"){
		document.nav_subscribe.firstname.value="";
	} else if(document.nav_subscribe.firstname.value==""){
		document.nav_subscribe.firstname.value="First Name";
	}
}

function navSubscribe_email(){
	if(document.nav_subscribe.email.value=="E-mail Address"){
		document.nav_subscribe.email.value="";
	} else if(document.nav_subscribe.email.value==""){
		document.nav_subscribe.email.value="E-mail Address";
	}
}

// competition validation
function validateComp() {
	if(document.comp.firstname.value==""){
		alert("Please enter your First Name.");
		document.comp.firstname.focus();
		return false;
	} else if(document.comp.surname.value==""){
		alert("Please enter your Last Name.");
		document.comp.firstname.focus();
		return false;
	} else if(document.comp.phone.value==""){
		alert("Please enter your Phone Number.");
		document.comp.phone.focus();
		return false;
	} else if(document.comp.email.value==""){
		alert("Please enter a valid E-mail Address.");
		document.comp.email.focus();
		return false;
	} else if(document.comp.verify.value==""){
		alert("Please copy the verification code exactly to complete this form (case sensitive).");
		document.comp.email.focus();
		return false;
	} else if(document.comp.style.value=="blank"){
		alert("Please select a Coaching Style.");
		document.comp.style.focus();
		return false;
	} else {
		return true;
	}
}





//EFT registration form

// VALIDATION
function validateEFTForm() {
	if(document.eftform.firstname.value==""){
		alert("Please enter your First Name.");
		document.eftform.firstname.focus();
		return false;
		
	} else if(document.eftform.surname.value==""){
		alert("Please enter your Surname.");
		document.eftform.surname.focus();
		return false;
		
	} else if(document.eftform.address1.value==""){
		alert("Please enter your Postal Address.");
		document.eftform.address1.focus();
		return false;
		
	} else if(document.eftform.suburb.value==""){
		alert("Please enter your Suburb/Town.");
		document.eftform.suburb.focus();
		return false;
		
	} else if(document.eftform.postcode.value==""){
		alert("Please enter your Postcode/Area Code.");
		document.eftform.postcode.focus();
		return false;
		
	} else if(document.eftform.state.value==""){
		alert("Please enter your State.");
		document.eftform.state.focus();
		return false;
		
		//CHECK:
	} else if(document.eftform.country.value=="Other" && document.eftform.country_other.value==""){
		alert("Please enter your Country.");
		document.eftform.country_other.focus();
		return false;
		
	} else if(document.eftform.phone.value==""){
		alert("Please enter your Phone Number.");
		document.eftform.phone.focus();
		return false;
		
	} else if(document.eftform.email.value==""){
		alert("Please enter a valid E-mail Address.");
		document.eftform.email.focus();
		return false;
		
	} else if(document.eftform.workshop.value=="blank"){
		alert("Please choose a Session/Workshop Date.");
		document.eftform.workshop.focus();
		return false;
		
	} else if(document.eftform.qty.value==""){
		alert("Please enter the quantity you wish to order.");
		document.eftform.qty.focus();
		return false;
		
	} else if(document.eftform.declare_fullname.value==""){
		alert("Please provide your Full Name as a digital signature.");
		document.eftform.declare_fullname.focus();
		return false;
		
	} else if(!document.eftform.declare_authorise.checked){
		alert("Please agree to all terms before submitting.");
		document.eftform.declare_authorise.focus();
		return false;
		
	} else if(!document.eftform.declare_privacy.checked){
		alert("Please agree to all terms before submitting.");
		document.eftform.declare_privacy.focus();
		return false;
		
	} else {
		return true;
	}
}


function selCountryOther(){
	// select country other adio button
}

//CALCULATION
function recalculateTotals(){
	document.eftform.subtotal.value = 0;
	document.eftform.early_bird.value = 0;
	
	document.eftform.postage_total.value = 0;
	document.eftform.postage_note.value = 0;
	
	document.eftform.grandtotal.value = 0;
}

function updateInvest(selObj){

	var selected = workshop.options[selObj.selectedIndex].value;
	var selected_invest = selObj.options[selObj.selectedIndex].invest;
	var selected_special = selObj.options[selObj.selectedIndex].special;
	var selected_early_bird = selObj.options[selObj.selectedIndex].early_bird;
	var selected_early_code = selObj.options[selObj.selectedIndex].early_code;
	var now10 = document.eftform.now10.value;
	var days_dif = (selected_early_code - now10)/60/60/24;
	
	if(selected_special=="special"){
		document.eftform.subtotal.value = selected_invest;
		document.eftform.early_bird.value = "* Special Price";
		
	} else if(days_dif>=9){
		document.eftform.subtotal.value = selected_early_bird;
		document.eftform.early_bird.value = "* Early Bird price";
		
	} else {
		document.eftform.subtotal.value = selected_invest;
		document.eftform.early_bird.value = "";
	}
}

//UNFOCUS UNEDITBLE TEXT FIELDS
function unfocus(){
	document.eftform.workshop.focus();
}
