// *** Global Page Variables **********
var CurPos = 0;
var PopUpOnLeft = false;

// *** Preload images *****************
var RollOut = new Array();
var RollIn  = new Array();
// NOTE: **DO NOT** renumber these array elements. By all means add on new elements
//                  but don't renumber the existing ones. Some of these numbers are
//                  hardcoded in the code-behind files.
RollOut[0]  = "images/form0-out.gif"
RollIn[0]   = "images/form0-in.gif";
RollOut[1]  = "images/form1-out.gif";
RollIn[1]   = "images/form1-in.gif";
RollOut[2]  = "images/form2-out.gif";
RollIn[2]   = "images/form2-in.gif";
RollOut[3]  = "images/form3-out.gif";
RollIn[3]   = "images/form3-in.gif";
RollOut[4]  = "images/form4-out.gif";
RollIn[4]   = "images/form4-in.gif";
RollOut[5]  = "images/form5-out.gif";
RollIn[5]   = "images/form5-in.gif";
RollOut[6]  = "images/form6-out.gif";
RollIn[6]   = "images/form6-in.gif";
RollOut[7]  = "images/form7-out.gif";
RollIn[7]   = "images/form7-in.gif";
RollOut[8]  = "images/form8-out.gif";
RollIn[8]   = "images/form8-in.gif";
RollOut[9]  = "images/form9-out.gif";
RollIn[9]   = "images/form9-in.gif";
RollOut[10] = "images/form10-out.gif";
RollIn[10]  = "images/form10-in.gif";
RollOut[11] = "images/form11-out.gif";
RollIn[11]  = "images/form11-in.gif";
RollOut[12] = "images/form12-out.gif";
RollIn[12]  = "images/form12-in.gif";
RollOut[13] = "images/form13-out.gif";
RollIn[13]  = "images/form13-in.gif";
RollOut[20] = "images/formPrev-out.gif";
RollIn[20]  = "images/formPrev-in.gif";
RollOut[21] = "images/formNext-out.gif";
RollIn[21]  = "images/formNext-in.gif";
RollOut[22] = "images/savelogout-out.gif";
RollIn[22]  = "images/savelogout-in.gif";
RollOut[23] = "images/savesubmit-out.gif";
RollIn[23]  = "images/savesubmit-in.gif";
RollOut[24] = "images/save-out.gif";
RollIn[24]  = "images/save-in.gif";
RollOut[25] = "images/logout-out.gif";
RollIn[25]  = "images/logout-in.gif";
RollOut[26] = "images/add-out.gif";
RollIn[26]  = "images/add-in.gif";
RollOut[30] = "images/btnHome-out.jpg";
RollIn[30]  = "images/btnHome-in.jpg";
RollOut[31] = "images/btnEmail-out.jpg";
RollIn[31]  = "images/btnEmail-in.jpg";
RollOut[32] = "images/btnLogin-out.jpg";
RollIn[32]  = "images/btnLogin-in.jpg";
RollOut[33] = "images/btnRegister-out.jpg";
RollIn[33]  = "images/btnRegister-in.jpg";
RollOut[34] = "images/btnAbout-out.jpg";
RollIn[34]  = "images/btnAbout-in.jpg";
RollOut[35] = "images/btnChurch-out.jpg";
RollIn[35]  = "images/btnChurch-in.jpg";
RollOut[36] = "images/submit-out.gif";
RollIn[36]  = "images/submit-in.gif";
RollOut[37] = "images/edit-out.gif";
RollIn[37]  = "images/edit-in.gif";
RollOut[38] = "images/copyicon-out.gif";
RollIn[38]  = "images/copyicon-in.gif";
RollOut[39] = "images/deleteicon-out.gif";
RollIn[39]  = "images/deleteicon-in.gif";
RollOut[40] = "images/viewicon-out.gif";
RollIn[40]  = "images/viewicon-in.gif";
RollOut[41] = "images/printicon-out.gif";
RollIn[41]  = "images/printicon-in.gif";
RollOut[42] = "images/closeicon-out.gif";
RollIn[42]  = "images/closeicon-in.gif";
RollOut[43] = "images/openicon-out.gif";
RollIn[43]  = "images/openicon-in.gif";
RollOut[44] = "images/printicon2-out.gif";
RollIn[44]  = "images/printicon2-in.gif";
RollOut[45] = "images/pdficon-out.gif";
RollIn[45]  = "images/pdficon-in.gif";
RollOut[46] = "images/addtoshop-out.gif";
RollIn[46] = "images/addtoshop-in.gif";

var PreLoadOut = new Array();
var PreLoadIn = new Array();
var l = RollOut.length;
for (i=0;i<l;i++){
	PreLoadOut[i] = new Image();
	PreLoadOut[i].src = RollOut[i];
	
	PreLoadIn[i] = new Image();
	PreLoadIn[i].src = RollIn[i];
}

function UseFullPath(FullPath){
	for (i=0;i<l;i++){
		PreLoadOut[i] = new Image();
		PreLoadOut[i].src = FullPath + RollOut[i];
		
		PreLoadIn[i] = new Image();
		PreLoadIn[i].src = FullPath + RollIn[i];
	}
}

function Swap(ImgNo, InOrOut){
	if (ImgNo<0 || ImgNo > PreLoadOut.length)
		return null;
	if (InOrOut == "in")
		return PreLoadIn[ImgNo].src;
	else
		return PreLoadOut[ImgNo].src;
}
//************************************

function LHSPopUp(){
	PopUpOnLeft = true;
}

function ShowPopUp(PopUpName, e){
	var strText = new String()

	switch(PopUpName){
		case "UserID":
			strText = "A User ID can be 4 to 15 characters long<br>and is not case sensitive."
			break;
		case "UserIDErr":
			strText = "Please enter a User Name<br>that is from 4 to 15 characters long."
			break;
		case "Password":
			strText = "A Password can be from 4 to 15 characters long<br>and is not case sensitive"
			break;
		case "Password1Err":
			strText = "Please enter a Password<br>that is from 4 to 15 characters long."
			break;
		case "Password2Err":
			strText = "The repeated password does not match the first one."
			break;
		case "DOBErr":
			strText = "Please enter a valid date in the format 'dd/mm/yyyy'."
			break;
		case "IsBlankErr":
			strText = "If the requested information is not relevant or is unknown, please tick 'Not Applicable'."
			break;
		case "EmailAddrErr":
			strText = "Please enter a valid email address."
			break;
		case "NA":
			strText = "<b>Not Applicable or Unknown</b><br>If a question is not applicable or the answer<br>to the question is unknown, please tick this option."
			break;
		case "PGF":
			strText = "<b>PGF = Paternal Grand Father</b><br>This applies/applied to your Father's Father."
			break;
		case "PGM":
			strText = "<b>PGM = Paternal Grand Mother</b><br>This applies/applied to your Father's Mother."
			break;
		case "UF":
			strText = "<b>UF = Uncle on Father's Side</b><br>This applies/applied to your Father's Brother(s)."
			break;
		case "AF":
			strText = "<b>AF = Aunt on Father's Side</b><br>This applies/applied to your Father's Sister(s)."
			break;
		case "CF":
			strText = "<b>CF = Cousin on Father's Side</b><br>This applies/applied to a Cousin on your Father's side."
			break;
		case "MGF":
			strText = "<b>MGF = Maternal Grand Father</b><br>This applies/applied to your Mother's Father."
			break;
		case "MGM":
			strText = "<b>MGM = Maternal Grand Mother</b><br>This applies/applied to your Mother's Mother."
			break;
		case "AM":
			strText = "<b>AM = Aunt on Mother's Side</b><br>This applies/applied to your Mother's Sister(s)."
			break;
		case "UM":
			strText = "<b>UM = Uncle on Mother's Side</b><br>This applies/applied to your Mother's Brother(s)."
			break;
		case "CM":
			strText = "<b>CM = Cousin on Mother's Side</b><br>This applies/applied to a Cousin on your Mother's side."
			break;
		case "S":
			strText = "<b>S = Sister</b><br>This applies/applied to your Sister(s)."
			break;
		case "B":
			strText = "<b>B = Brother</b><br>This applies/applied to your Brother(s)."
			break;
		case "F":
			strText = "<b>F = Father</b><br>This applies/applied to your Father."
			break;
		case "M":
			strText = "<b>M = Mother</b><br>This applies/applied to your Mother."
			break;
		case "SELF":
			strText = "<b>S = Self</b><br>This applies to You."
			break;
		case "FS":
			strText = "<b>FS = Father's Side</b><br>This applies/applied to a relative or relatives on your Father's Side."
			break;
		case "MS":
			strText = "<b>MS = Mother's Side</b><br>This applies/applied to a relative or relatives on your Mother's Side."
			break;
		case "SB":
			strText = "<b>SB = Siblings</b><br>This applies/applied to your brother(s) and/or sister(s)."
			break;
		default:
			strText = PopUpName
			break;
	}

	ShowMessage(strText, e);
}

function ShowMessage(MsgToShow, e){
	if (!e) e = window.event;
	var x = e.clientX;
	var y = e.clientY;
	var sT = (window.pageYOffset) ? window.pageYOffset : 
		(document.documentElement && document.documentElement.scrollTop) ? 
		document.documentElement.scrollTop : document.body.scrollTop;
	var sL = (window.pageXOffset) ? window.pageXOffset : 
		(document.documentElement && document.documentElement.scrollLeft) ? 
		document.documentElement.scrollLeft : document.body.scrollLeft;
	
	var strText = new String();
	strText = MsgToShow.replace(" ", "&nbsp;");
	if (strText.length != 0){
		// This loop is to ensure proper left and right margin spacing
		while (strText.indexOf("<br>") != -1){
			strText = strText.replace("<br>", "&nbsp;<br />&nbsp;");
		}
		var d = document.getElementById("lblPopUp")
		d.innerHTML = "&nbsp;" + strText + "&nbsp;";
		d.style.visibility = "visible";
		d.style.left = x + sL + (PopUpOnLeft ? -(d.offsetWidth) : 12);
		d.style.top = y + sT + 10;
	}
	PopUpOnLeft = false;
}

function HidePopUp(){
	document.getElementById("lblPopUp").style.visibility = "hidden"
}

function WinPopUp(URL, w, h) {
	day = new Date();
	id = day.getTime();
	//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=600');");
	window.open(URL, id, 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=' + w + ',height=' + h);
}

function Agreed(){
	if (!document.getElementById("chkAgree").checked){
		alert("Please agree to the waiver, Terms and Conditions and Privacy Policy by ticking the box on the right hand side of this form");
		return false;
	}
}

//*** This code is copyright 2004 by Gavin Kistner, gavin@refinery.com
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt
//*** Reuse or modification is free provided you abide by the terms of that license.
//*** (Including the first two lines above in your source code mostly satisfies the conditions.)


// Rounds a number to a specified number of decimals (optional)
// Inserts the character of your choice as the thousands separator (optional)
// Uses the character of your choice for the decimals separator (optional)
//
// It's not a highly optimized speed demon, but it gives the right result...
// ...do you really care how speedy it is? :)
//
// !!Note!! IEWin gets (-0.007).format(2) WRONG, claiming that it's "0.00"
// This is a bug in IEWin's Number.toFixed() function.


Number.prototype.format=function(decimalPoints,thousandsSep,decimalSep){
	var val=this+'',re=/^(-?)(\d+)/,x,y;
	if (decimalPoints!=null) val = this.toFixed(decimalPoints);
	if (thousandsSep && (x=re.exec(val))){
		for (var a=x[2].split(''),i=a.length-3;i>0;i-=3) a.splice(i,0,thousandsSep);
		val=val.replace(re,x[1]+a.join(''));
	}
	if (decimalSep) val=val.replace(/\./,decimalSep);
	return val;
}
if (typeof Number.prototype.toFixed!='function' || (.9).toFixed()=='0' || (.007).toFixed(2)=='0.00') Number.prototype.toFixed=function(f){
	if (isNaN(f*=1) || f<0 || f>20) f=0;
	var s='',x=this.valueOf(),m='';
	if (this<0){ s='-'; x*=-1; }
	if (x>=Math.pow(10,21)) m=x.toString();
	else{
		m=Math.round(Math.pow(10,f)*x).toString();
		if (f!=0){
			var k=m.length;
			if (k<=f){
				var z='00000000000000000000'.substring(0,f+1-k);
				m=z+m;
				k=f+1;
			}
			var a = m.substring(0,k-f);
			var b = m.substring(k-f);
			m = a+'.'+b;
		}
	}
	if (m=='0') s='';
	return s+m;
}

// var x = 1234567.89532;
// x.format()                  => 1234567.89532
// x.format(2)                 => 1234567.90
// x.format(2,',')             => 1,234,567.90
// x.format(0,',')             => 1,234,568
// x.format(null,',')          => 1,234,567.89532
// x.format(null,' ',',')      => 1 234 567,89532
// x.format(2,' ',',')         => 1 234 567,90

function showHide(panelID)
{
	var panel = document.getElementById(panelID);
	if (panel != null){
		if (panel.style.visibility == "hidden"){
			panel.style.display = "block";
			panel.style.visibility = "visible";
		}
		else {
			panel.style.display = "none";
			panel.style.visibility = "hidden";               
		}
	}
}

