// Setup Global Frameset Object
var oFrameSet;

function Init () {
	//oFrameSet = window.FrameSet1;
	oFrameSet = window.document.getElementById('FrameSet1');
}


function Load_Page (strURL) {
	// Check if the referring page is htm_images.asp, htm_images_2005.asp or htm_images_win2004.asp.  
	// htm_images.asp, htm_images_2005.asp and htm_images_win2004.asp are special pages because they don't use a frame to hold the flash nav - instead the flash nav is embedded 
	// into the file itself (i.e. htm_images.asp) which has no frames of its own.  Normally, the flash nav is held in the 'nav' frame (on the left), 
	// and content pages are displayed in the 'content' frame (on the right).  Normally when a user selects a link from the flash
	// nav, the content frame reloads with the destination page, and the nav frame reloads the corresponding 'background image' 
	// behind the flash nav, so that it matches the destination pages' background image.
	
	// When the user is on any page other than htm_images.asp, htm_images_2005.asp, or htm_images_win2004.asp, and they click the 'images' link on the flash nav, the following 
	// events occur:
	// 1. The 'nav' frame holding the flash nav is resized - pushed off the left of the screen so that it is invisible, and the 
	//    content frame takes up the entire screen.
	// 2. htm_images.asp, htm_images_2005.asp or htm_images_win2004.asp is loaded into the content frame.  (as mentioned above, htm_images.asp has it's own embedded copy 
	//    of the flash nav and htm_images.asp, htm_images_2005.asp and htm_images_win2004.asp does not use any frames of its own.)
	// 3. So now there is the previous pages' flash nav in the 'nav' frame, which is hidden off the left of the screen, and the 
	//    'content' frame contains htm_images.asp, htm_images_2005.asp or htm_images_win2004.asp which contains its own embedded flash nav.

	// PROBLEM: 
	// If the user now clicks any link on the flash nav in htm_images.asp, htm_images_2005.asp or htm_images_win2004.asp, it will resize the frameset, bringing the 'nav' 
	// frame (which holds the previous pages flash nav background image) back into view, and the 'content' frame which 
	// contained htm_images.asp, htm_images_2005.asp or htm_images_win2004.asp will be reloaded with the destination page (whatever link they clicked on. eg. htm_lookbook.asp) 
	// This is a problem because the flash nav needs to reload a 'background image' that corresponds to the page being viewed 
	// in the content frame (as mentioned earlier).  
	// Normally the one flash nav file is used in all pages, and sits in the 'nav' frame, and onclick of a flash nav link, 
	// the flash nav background reloads to match the destination pages' background. However, the flash nav embedded in 
	// htm_images.asp, htm_images_2005.asp or htm_images_win2004.asp has no way of telling the flash nav in the hidden 'nav' frame (which will become visible when the 
	// destination page loads in content frame) what link the user clicked, and therefore what background image to load 
	// when the destination page is loaded.
	
	// So, we need to have code that checks if the referring page is htm_images.asp, htm_images_2005.asp or htm_images_win2004.asp, and if so, load the correct flash nav 
	// background (that corresponds to the destination page being loaded into the 'content' frame) into the 'nav' frame. 

	var strNavURL;
	var strReferrerPage;
	
	// Initialise variables.
	strReferrerPage = window.frames.content.location.href;
	
	//alert('Referrer: ' + strReferrerPage);
	//alert('Destination: ' + strURL);
		
	// strReferrerPage will look something like : 'http://www.bettinaliano.com.au/cpa/htm/htm_filename.asp'
	// We just need to know if it contains 'htm_images.asp, htm_images_2005.asp or htm_images_win2004.asp' or 'blank.html', and if so, perform the nav reloading described in the massive
	// comment above.
	
	// -----------------  SPECIAL NOTE: ----------------------
	// If the referrer is blank.html, then that is because the user arrived at the site via clicking a subscription update/confirm
	// link within thier email.  In this case we also need to correctly dislpay the loading page and reload both nav and content pages.
		
	if ((strReferrerPage.indexOf('htm_movie.asp') > -1) || (strReferrerPage.indexOf('htm_images.asp') > -1) || (strReferrerPage.indexOf('htm_images_win2004.asp') > -1) || (strReferrerPage.indexOf('htm_images_2005.asp') > -1) || (strReferrerPage.indexOf('htm_images_win2006.asp') > -1) || (strReferrerPage.indexOf('blank.html') > -1) || (strURL.indexOf('htm_home') > -1)) {
		
		// The referrer page is htm_images.asp, htm_images_2005.asp, htm_images_win2004.asp, htm_images_win2006.asp, or blank.html, or the user has clicked the 'home' link (strURL is htm_homexxx.asp)
		// so dynamically determine the associated nav file name to load.
		// Conveniently, the nav files share the same base name as the content files.  Example:
		// htm_lookbook.asp  has assocaited nav file nav_lookbook.asp.  htm_home-01.asp has nav file nav_home-01.asp.
		
		//alert('referrer is images, blank, or home was clicked');

	/*	
	// THIS CODE WAS USED BEFORE THE HAXOR CODE BENEATH IT.
		// ensure that the strURL contains 'htm_', otherwise we dont' want to touch it.
		if (strURL.indexOf('htm_') > -1) {
			// form the name of the nav file based on the characters in strURL that come AFTER the 'htm_' part.
			// example: if strURL is htm_lookbook.asp, then get everything after '_', which will be 'lookbook.asp'.
			// Then add 'nav_' at the start, to form the nav file 'nav_lookbook.asp'.
			strNavURL = 'nav_' + strURL.substring(strURL.indexOf('htm_') + 4,strURL.length);		
			alert (strNavURL);	
			// Reload the 'nav' frame with the strNavURL, and 'content' frame with strURL.		
			setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"; window.frames.nav.location.href = \"" + strNavURL + "\"",2000);
		
		}
	*/
		// ------------------ (0MM3N(3 (-)4X0R ------

		// If the destination page (strURL) is htm_images.asp, htm_images_2005.asp, htm_images_win2004.asp or htm_images_win2006.asp, then load a blank page into the hidden 'nav' frame, 
		// because it will never be seen and does not need to be used again when the user leaves the htm_images.asp page (as described in code above)
		if ((strURL == 'htm_movie.asp') || (strURL == 'htm_images.asp') || (strURL == 'htm_images_win2004.asp') || (strURL == 'htm_images_win2006.asp') || (strURL == 'htm_images_2005.asp')) {
			// User has clicked to view the 'images' section of the site.  load a blank page in the hidden 'nav' frame. 
			// This will save system resources as otherwise the hidden animated flash nav in the 'nav' frame slows the rest
			// of the site down because it has to run the hidden flash in the 'nav' frame, plus the flash nav in htm_images.asp (htm_images_win2004.asp, htm_images_2005.asp),
			// plus the flash image viewer in htm_images.asp (htm_images_win2004.asp, htm_images_2005.asp).
			setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"; window.frames.nav.location.href = 'blank.html'",2000);
		} 	
		else if (strURL.indexOf('htm_shop_enter.asp') > -1) {
			// HACK 
			// The client wanted to remove the htm_shop_enter.asp landing page, and instead link straight to the product list page.  So if we are trying to view
			// the shop landing page, just redirect to the product list page instead.
			strNavURL = 'nav_shop-02.asp';	
			strURL = '../mod_store/htm/htm_store_product_list.asp';
			setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"; window.frames.nav.location.href = \"" + strNavURL + "\"",2000);	
		}		
		// ensure that the strURL contains 'htm_', otherwise we dont' want to touch it.
		else if (strURL.indexOf('htm_') > -1) {
			// form the name of the nav file based on the characters in strURL that come AFTER the 'htm_' part.
			// example: if strURL is htm_lookbook.asp, then get everything after '_', which will be 'lookbook.asp'.
			// Then add 'nav_' at the start, to form the nav file 'nav_lookbook.asp'.
			strNavURL = 'nav_' + strURL.substring(strURL.indexOf('htm_') + 4,strURL.length);		
			//alert (strNavURL);	
			// Reload the 'nav' frame with the strNavURL, and 'content' frame with strURL.		
			setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"; window.frames.nav.location.href = \"" + strNavURL + "\"",2000);
		
		}

		// ------------------ 3N|) (-)4X0R ------


	}
/*
	// If the referrer page is htm_shop_enter.asp and the strURL is 'htm_store_product_list.asp', the user has clicked the 'enter' button in 
	// htm_shop_enter.asp, and the following needs to happen:
	// 1. Display the loading screen.
	// 2. Load the appropriate shop nav in the 'nav' frame.
	// 3. Load htm_store_product_list.asp in the 'content' frame.
	else if ((strReferrerPage.indexOf('htm_shop_enter.asp') > -1) && (strURL.indexOf('htm_store_product_list.asp') > -1)) {

		strNavURL = 'nav_shop-02.asp';
		setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"; window.frames.nav.location.href = \"" + strNavURL + "\"",2000);
	
	}
*/
	else if (strURL.indexOf('htm_shop_enter.asp') > -1) {
		// HACK 
		// The client wanted to remove the htm_shop_enter.asp landing page, and instead link straight to the product list page.  So if we are trying to view
		// the shop landing page, just redirect to the product list page instead.
		strNavURL = 'nav_shop-02.asp';	
		strURL = '../mod_store/htm/htm_store_product_list.asp';
		setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"; window.frames.nav.location.href = \"" + strNavURL + "\"",2000);
		
	}

	// If the referrer page is htm_form_response.asp and the strURL is '../mod_subscribe/htm/htm_subscribe.asp', the user has clicked the 
	// 'subscribe here' link on the form response page. The following needs to happen:
	// 1. Display the loading screen.
	// 2. Load the appropriate shop nav in the 'nav' frame.
	// 3. Load htm_store_product_list.asp in the 'content' frame.
	else if ((strReferrerPage.indexOf('htm_form_response.asp') > -1) && (strURL.indexOf('../mod_subscribe/htm/htm_subscribe.asp') > -1)) {

		strNavURL = 'nav_subscribe.asp';
		setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"; window.frames.nav.location.href = \"" + strNavURL + "\"",2000);
	
	}

	else {
		// If the destination page (strURL) is htm_images.asp, htm_images_2005.asp, htm_images_win2004.asp or htm_images_win2006.asp, then load a blank page into the hidden 'nav' frame, 
		// because it will never be seen and does not need to be used again when the user leaves the htm_images.asp page (as described in code above)
		if ((strURL == 'htm_movie.asp') || (strURL == 'htm_images.asp') || (strURL == 'htm_images_win2004.asp') || (strURL == 'htm_images_win2006.asp') || (strURL == 'htm_images_2005.asp')) {
			// User has clicked to view the 'images' section of the site.  load a blank page in the hidden 'nav' frame. 
			// This will save system resources as otherwise the hidden animated flash nav in the 'nav' frame slows the rest
			// of the site down because it has to run the hidden flash in the 'nav' frame, plus the flash nav in htm_images.asp (htm_images_win2004.asp, htm_images_2005.asp),
			// plus the flash image viewer in htm_images.asp (htm_images_win2004.asp, htm_images_2005.asp).
			setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"; window.frames.nav.location.href = 'blank.html'",2000);
		}
		else {		
		
		//window.frames.content.location.href = strURL;
		setTimeout("Hide_Frames (); window.frames.content.location.href = \"" + strURL + "\"",1000);
		}
	}
}


function Hide_Frames () {

	oFrameSet.cols = '0,0,*';

}

function Show_Frames () {
	// Check that page has finished loading by looking at boolean variable state in frameset page.
	if(blLoaded) {
		setTimeout("oFrameSet.cols = '200,824,*'",4000);
	}
}

function Hide_Image_Frames () {
	// Create a delay of 2 seconds to allow the flash nav to animate before redirecting.
	setTimeout("oFrameSet.cols = '0,1024,*'",2000);

}


var objBasketWindow;
function openBasketWindow (strURL) {

	// open basket window if it's not already open.  Check the window opener and the shop basket object variable objBasketWindow
	// to determine the state of the basket.  Also, since the user can close the basket window with the 'x' button in the 
	// window frame (and there is no way of capturing this event specifically) we have to perform a objBasketWindow.closed check
	if (objBasketWindow && !objBasketWindow.closed) {
		// basket is already open, so refresh it.
		objBasketWindow.location.reload();
		// focus on open basket window.
		objBasketWindow.focus();
	}
	else {
		// basket isn't open, so open it centred on screen.
		var xPos;
		var yPos;
		var wndHeight;
		var wndWidth;
		
		// Initialise variables 
		wndHeight = 678;  // px subtracted to compensate for status borders.
		wndWidth = 1014;  // px subtracted to compensate for window borders.

		// when the basket window is launched.
		yPos = ((screen.availHeight/2) - ((wndHeight)/2)) - 30;
		xPos = (((screen.availWidth - 10)/2) - (wndWidth/2));

		objBasketWindow = window.open (strURL + "/cpa/mod_store/htm/htm_store_basket.asp","basket","width=" + wndWidth + ",height=" + wndHeight + ",left=" + xPos + ",top=" + yPos + ",resize=0,status=1,toolbar=0,menubar=0,scrollbars=0");
	}
}


var objPopupWindow;
function openPopupWindow (strURL) {
	// open popup window if it's not already open.  Check the window opener and the variable objPopupWindow
	// to determine the state of the popup.  Also, since the user can close the popup window with the 'x' button in the 
	// window frame (and there is no way of capturing this event specifically) we have to perform a objPopupWindow.closed check.
	if (objPopupWindow && !objPopupWindow.closed) {
		// popup is already open, so refresh it.
		objPopupWindow.location.reload();
		// focus on open popup window.
		objPopupWindow.focus();
	}
	else {
		// popup isn't open, so open it centred on screen.
		var xPos;
		var yPos;
		var wndHeight;
		var wndWidth;
		
		// Initialise variables 
		wndHeight = 580;  // px subtracted to compensate for status borders.
		wndWidth = 858;  // px subtracted to compensate for window borders.

		// add 30 px to ypos during calculation to compenstate for windows task bar at bottom of screen, which becomes visible
		// when the popup window is launched.
		yPos = ((screen.availHeight/2) - ((wndHeight)/2)) - 15;
		xPos = (((screen.availWidth - 10)/2) - (wndWidth/2));

		objPopupWindow = window.open (strURL,"bettinaliano","width=" + wndWidth + ",height=" + wndHeight + ",left=" + xPos + ",top=" + yPos + ",resize=0,status=1,toolbar=0,menubar=0,scrollbars=0");
	}
}

/*
Full Screen Window Opener Script- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

function fullwin(targeturl){

	window.open(targeturl,"","fullscreen,scrollbars")
}

//This function returns a random number equal or less than intMax, which is passed into it.
function getRandomNum(intMax) {

	var intRandomNumber;

	// Get the random number that falls within the intMax passed into the function.
	intRandomNumber = (Math.round(Math.random() * intMax));

	// Return the random number.
	return intRandomNumber;
}


// Function selects a random homepage file to load when the user clicks the 'home' link in the flash nav.
function randomHomepage() {
	var intRandNum;
	var strURL;
	var strNavURL;
	var arrFrameSet = new Array("htm_home-01.asp","htm_home-02.asp");
	
	// Get random number that will be used to reference a position in the above array.
	intRandNum = getRandomNum(1);
	
	// Select the file in the array corresponding to the intRandNum position, and redirect to that file.
	// Call the Load_Page function which will redirect with 2 second delay.
	//document.location.href = arrFrameSet[intRandNum];
	strURL = arrFrameSet[intRandNum];
	
	Load_Page(strURL);
		
}

// Function selects a random homepage FRAMESET to load, which occurs on entry to the site.  This function is called from
// the htm_frameselect.asp page (and possible others as development goes on).
function randomHomepageFrameset() {
	var intRandNum;
	var strURL;
	var strNavURL;
	var arrFrameSet = new Array("fs_home-01.asp","fs_home-02.asp");
	
	// Get random number that will be used to reference a position in the above array.
	intRandNum = getRandomNum(1);
	
	// Select the file in the array corresponding to the intRandNum position, and redirect to that file.
	strURL = arrFrameSet[intRandNum];
	//document.location.href = 'loading.html?url=' + strURL;
	document.location.href = strURL;
	
}
