/*
***************************************
* ChangePagePic
***************************************
*/

// Use this variable the time we wait before alerting the usre that their image
// is not loading correctly. Set the timer to 0 to disable the timer facility
var iTimerSeconds	= 30;

// Use this variable to set whether or not the script should attempt to look
// at the users current resolution and resize the enlarged picture so that
// it will fit on their screen
var bDynamicResize = true;

// Use this variable to set whether debug mode is on or not. It will issue many
// alerts that cover what is happening as the script is executed
var bDebugMode = false;

function ChangePagePic(sPicURL) {
	//ensure our previous picture has been hidden before loading this one
	HideChangePagePic();

	var iDivWidth, iDivHeight;
	var sImage;

	//hide our div that holds some existing images
	document.getElementById("ChangePicExistingImage").style.display = "none";

	//set up our main image details
	sImage = '<img src="' + sPicURL + '" alt="" border="0" id="ChangePagePicImage" />';

	//transfer the details to the form
	document.getElementById("ChangePagePicImageDiv").innerHTML = sImage;

	if ( bDebugMode ) alert("ChangePagePicPic :: Just set main image src"); 
	
	//show our loading image
	document.getElementById("ChangePagePicLoadingPic").style.display = "";

	if ( bDebugMode ) alert("ChangePagePicPic :: Just showed loading image"); 

	//unhide our div to show the loading image
	document.getElementById("ChangePagePic").style.display = "";

	//check to see if the image that we are showing has been fully loaded yet
	setTimeout('CheckChangePagePicPic(0)',500);

	if ( bDebugMode ) alert("ChangePagePicPic :: just 'checkeded' popup layer pic"); 
}

function CheckChangePagePicPic(iCount) {

	if ( bDebugMode ) alert("CheckChangePagePicPic :: start"); 
	if ( bDebugMode ) alert("CheckChangePagePicPic :: complete? " + document.getElementById("ChangePagePicImage").complete);
	if ( bDebugMode ) alert("CheckChangePagePicPic :: src > 0? " + (document.getElementById("ChangePagePicImage").src.length > 0));
	if ( bDebugMode ) alert("CheckChangePagePicPic :: counter :: " + iCount);

	var bStop		= false;
	var sMessage	= "";

	//Check that our user hasn't been waiting more than 30 seconds
	if ( iCount > iTimerSeconds*2 && iTimerSeconds != 0 ) {
		if ( bDebugMode ) alert("CheckChangePagePicPic :: counter too large - asking question");

		sMessage = sMessage + "The image appears to be taking a considerable amount of time to load.\n\n";
		sMessage = sMessage + "It is possible that the image path is not valid and that the image will never load successfully.\n\n";
		sMessage = sMessage + "Do you wish to continue to wait?";

		//Check to see if our user wants to exit
		if ( !confirm(sMessage) ) {
			//Remove the source from the image and hide the layer
			document.getElementById("ChangePagePicImage").src = "";
			HideChangePagePic();

			bStop = true;
		}
		else {
			iCount = 0;
		}
	}

	//Continue processing unless we have been requested to stop processing
	if ( !bStop ) {
		iCount++;

		//check to see if our main pic has loaded or not
		if ( document.getElementById("ChangePagePicImage").complete && document.getElementById("ChangePagePicImage").src.length > 0 ) {
			if ( bDebugMode ) alert("CheckChangePagePicPic :: is complete and have src"); 

			//our pic has loaded, show the image
			ShowChangePagePicPic();
		}
		else {
			//Wait and check to see if it is loaded in 0.5 seconds
			setTimeout('CheckChangePagePicPic(' + iCount + ')',500);
		}
	}
}

function ShowChangePagePicPic() {
	if ( bDebugMode ) alert("ShowChangePagePicPic :: start"); 

	//hide our loading image
	document.getElementById("ChangePagePicLoadingPic").style.display = "none";

	//show our main image and text
	document.getElementById("ChangePagePicImageDiv").style.display = "";
}

function HideChangePagePic () {
	//hide our main image and text
	document.getElementById("ChangePagePicImageDiv").style.display = "none";

	//show our loading image
	document.getElementById("ChangePagePicLoadingPic").style.display = "";

	//hide our div
	document.getElementById("ChangePagePic").style.display = "none";
}
