// *** Global Page Variables **********
var CurPos = 0;
var PopUpOnLeft = false;

// *** Preload images *****************
var RollOut  = new Array();
var RollIn = new Array();
RollOut[0] = "images/about-out.jpg"
RollIn[0] = "images/about-in.jpg";
RollOut[1] = "images/condolence-out.jpg";
RollIn[1] = "images/condolence-in.jpg";
RollOut[2] = "images/album-out.jpg";
RollIn[2] = "images/album-in.jpg";
RollOut[3] = "images/candle-out.jpg";
RollIn[3] = "images/candle-in.jpg";
RollOut[4] = "images/videos-out.jpg";
RollIn[4] = "images/videos-in.jpg";
RollOut[5] = "images/piTitle1-out.jpg";
RollIn[5] = "images/piTitle1-in.jpg";
RollOut[6] = "images/piTitle2-out.jpg";
RollIn[6] = "images/piTitle2-in.jpg";
RollOut[7] = "images/piTitle3-out.jpg";
RollIn[7] = "images/piTitle3-in.jpg";
RollOut[8] = "images/piTitle4-out.jpg";
RollIn[8] = "images/piTitle4-in.jpg";
RollOut[9] = "images/piTitle5-out.jpg";
RollIn[9] = "images/piTitle5-in.jpg";
RollOut[10] = "images/piTitle6-out.jpg";
RollIn[10] = "images/piTitle6-in.jpg";

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 "IsBlankErr":
			strText = "This box cannot be left blank.<br>Please fill in the requested information (if the requested information<br>is not relevant or unknown, please enter 'N/A'."
			break;
		case "EmailAddrErr":
			strText = "Please enter a valid email address."
			break;
		case "s1":
			strText = "AJS can help you with your claim if you<br>have been involved in a Car Accident as a<br>driver or passenger, pedestrian or cyclist."
			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);
}

//*** 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";               
	}
	}
}
