// For preventing users clicking 'continue' buttons before page has loaded entirely...
/*
   NOTE: Ordinarily, pageLoaded should be set to false here. However, since this
   variable and the setLoadVars() function have been added as a proof-of-concept
   test for CR4483 and the associated 'onload=setLoadVars()' calls added only to
   pages in Pay As You Go on the DEV box, pageLoaded=false here will disable HT
   and AT on the DEV box. So we reset it to 'true' for now. Chris D, 19-08-2003
pageLoaded = false;
*/
pageLoaded = true;
function setLoadVars() { pageLoaded = true; }

// Get query string of parent document. Might need to pass it to quit popup call...
var qStr = document.location.search;
if ((document.location.search.indexOf("redirected_from") == -1) && (document.location.search.indexOf("reclaim") == -1)) { qStr = ""; }

// Bespoke function for textual 'PRINT' links
function printLink() {
	if (isMac) { theHref = "javascript:alert('Please hit \\\'Apple + P\\\' to print this page.');";  }
	else {
		if (window.print) { theHref = "javascript:window.print();"; }
		else              { theHref = "javascript:alert('Please hit \\\'Ctrl + P\\\' to print this page.');"; }
	}
	document.write('<a href="' + theHref + '" class="link"><u>print</u></a>');
}

// Bespoke function for payment details pages - shows an alert box to the user
function displayPaymentAlert() {
    var msg  = "";
        msg += "It'll now take just a couple of minutes to set up your account.\n\n";
        msg += "Please do not click on your browser's 'forward', 'back', 'refresh' or 'stop' buttons,\nuntil we ask you to install your Any Time settings.\n\n";
        msg += "If you do not manage to download your Any Time settings then please\nretrieve your account via the CD or via www.orange.co.uk.\n\n";
        msg += "Thanks for your patience!";
    alert(msg);
}

var openWindows = new Array();

function orangePop(theURL,theWidth,theHeight,theScroll,theResize) {
// For accessibility reasons allow scrolling and resizing of windows (e.g. if user increases text size) unless otherwise specified
	
	if (!theScroll){theScroll="yes";}
	if (!theResize){theResize="yes";}
	
	var theProperties = "width=" + theWidth +",height=" + theHeight + ",scrollbars=" + theScroll + ",resizable=" + theResize+",top=10,left=10";
	orangePopWin = window.open(theURL,"orangePop",theProperties);   
	openWindows[0] = orangePopWin;
    if (window.focus) {orangePopWin.focus()};
}

function writeBtn(pkg,btn,url,wd,hi,al){
	var theURL  = url;
	var imgsDir = "/images/shared/buttons/";
	var prefix  = "";
	var pkgName = "";
	var h       = "26";
	var align	=al;
	//default button alignment (3 arg function) is "right", but this can be changed for different button types
	//if a left or middle button alignment is needed, 6 args are needed
	if (!al){
	var align="right";
	}
	
	if (pkg == "h")      { pkgName = "HomeTime"; }
	else if (pkg == "a") { pkgName = "Any Time"; }
	else                 { pkgName = "Pay As You Go"; }

	// popup window width & height. Uses default dimensions of quit popup window
	if (!wd) { wd = "342"; }
	if (!hi) { hi = "180"; }
	i=imgsDir;
	
	if (btn=="accept") {
		i = i + "_accept.gif";
		a = "click here to accept our Terms of Use";
	}
	else if (btn=="add_help") {
		i = i + "add_help.gif";
		a = "click here for additional help";
	}
	else if (btn=="change") {
		i = i + "change_witharrow_w.gif";
		a = "click here to change your details";
	}
	else if (btn=="closewin") {
		if (!theURL) { theURL="javascript:self.close();"; }
		i = i + "close_w.gif";
		a = "click here to close this window";
	}
	else if (btn=="confirm") {
		i = i + "confirm_witharrow_w.gif";
		a = "confirm your details";
	}
	else if (btn=="finish") {
		i = i + "finish_witharrow_w.gif";
		a = "click here to finish";
	}
	else if (btn=="help") {
		theURL = "javascript:orangePop('" + theURL + "','" + wd + "','" + hi + "');";
		i = i + "help_w.gif";
		a = "click here for help";
	}
	else if (btn=="helpNoPop") {
		i = i + "help_w.gif";
		a = "click here for help";
	}
	else if (btn=="install") {
		i = i + "install_witharrow_w.gif";
		a = "click here to install";
	}
	else if (btn=="join") {
		i = i + "join_witharrow_w.gif";
		a = "click here to join";
	}
	else if (btn=="next") {
		i = i + "next_witharrow_w.gif";
		a = "click here to continue";
	}	
	else if (btn=="no") {
		i = i + "no_witharrow_w.gif";
		h = "26";
		a = "no - I do not want to quit";
	}
	else if (btn=="print") {
		if (!theURL) {
			if (isMac) { theURL = "javascript:alert('Please hit \\\'Apple + P\\\' to print this page');"; }
			else {
				if (window.print) { theURL = "javascript:window.print();"; }
				else              { theURL = "javascript:alert('Please hit \\\'Ctrl + P\\\' to print this page');"; }
			}
		}
		i = i + "print_w.gif";
		a = "click here to print this page";
	}
	else if (btn=="register") {
		i = i + "register_witharrow_w.gif";
		a = "click here to join";
	}

	// Three buttons here use the same graphic, but have different alt text. This is for /time/ret_rest_account.htm
	else if (btn=="retrieve") {
		i = i + "retrieve_account.gif";
		a = "click here to retrieve your account";
	}
	else if (btn=="restore") {
		i = i + "retrieve_account.gif";
		a = "click here to restore your settings";
	}
	else if (btn=="suspended") {
		i = i + "retrieve_account.gif";
		a = "click here to reactivate your account";
	}
	else if (btn=="yes") {
		i = i + "yes_witharrow_w.gif";
		h = "26";
		a = "yes - I want to quit";
	}



	//The options below are legacy options and will not work until the image is saved in signup/buttons-------------------------------------------------------------------



	else if (btn=="activate") {
		i = i + "_act.gif";
		a = "click here to activate HomeTime";
	}
    else if (btn=="anytime") {
		i = i + "_at_butt.gif";
		a = "Any Time";
	}
    else if (btn=="cancelHT") {
		i = i + "_cancel_ht.gif";
		a = "click here to cancel HomeTime";
	}
	else if (btn=="ccardHelp") {
		theURL = "javascript:orangePop('" + theURL + "','" + wd + "','" + hi + "');";
		i = i + "_ccard_help_butt.gif";
		a = "click here for help on payment by credit card";
	}
	else if (btn=="closewin_sml") {
		if (!theURL) { theURL="javascript:self.close();"; }
		i = i + "_close2.gif";
		a = "click here to close this window";
	}
	else if (btn=="confirm") {
		i = i + "_conf.gif";
		a = "click here to continue joining";
	}
	else if (btn=="done") {
		i = i + "_done.gif";
		a = "done";
	}
	else if (btn=="download") {
		i = i + "_download.gif";
		a = "download";
	}
	else if (btn=="exit") {
		if (!theURL) { theURL = "javascript:orangePop('q_" + prefix + "_popup.htm','342','180');"; }
		i = i + "_exit.gif";
		a = "exit";
	}
	else if (btn=="macins") {
		i = i + "_mac_finished.gif";
		a = "Mac finished";
	}
	
	else if (btn=="quit") {
		if (!theURL) { theURL = "javascript:orangePop('q_" + prefix + "_popup.cfm" + qStr + "','342','180');"; }
		i = i + "_quit.gif";
		a = "click here to quit";
	}
	else if (btn=="retry") {
		i = i + "_retry.gif";
        h = "26";
		a = "click here to try cancelling the HomeTime account again";
	}
	else if (btn=="return") {
		i = i + "_return.gif";
		a = "click here to cancel another HomeTime account";
	}
	else if (btn=="signup") {
		i = i + "_sign2.gif";
		a = "click here to sign up for a BT surf package";
	}
	else if (btn=="try") {
		i = i + "_try.gif";
		a = "click here to try joining again";
	}
	else if (btn=="upgrade") {
		i = i + "_upgrade.gif";
		a = "click here to upgrade your account";
	}
	else if (btn=="download_nn"){
		i = imgsDir + "time/paygmigration/btn_download.gif";
		h = "28";
		a = "download new number";
	}
	// Write a form submit (input=image) button, as opposed to regular image and href.
	// Input button format relies on an action attribute being set on the form to which
	// the submit button will apply.
	if (theURL=="inputBtn") { 
		document.write('<input type="image" src="' + i + '" height="' + h + '" border="0" alt="'+ a + '" align="' + align + '" onclick="return pageLoaded;"  />');
	}
	else {
		document.write('<a href="' + theURL + '" onclick="return pageLoaded;"><img src="' + i + '" height="' + h + '" border="0" alt="'+ a + '" align="' + align + '" /></a>');
	}
}
