//  2 params for the popup template
var childWin;
var childOpen = false;

// Used to dynamically load a page selected in a dropdown box
//function getPage(Field) {
//	var page = Field.options[Field.selectedIndex].value;//page is the published path/filename
//	self.location = page;
//}

function getPage() {
	var page = document.form.list.options[document.form.list.selectedIndex].value;//page is the published path/filename
	self.location = page;
}

function getPage1() {
	var page = document.form1.list1.options[document.form1.list1.selectedIndex].value;//page is the published path/filename
	self.location = page;
}

function getPage2() {
	var page = document.form2.list2.options[document.form2.list2.selectedIndex].value;//page is the published path/filename
	self.location = page;
}

function getPage3() {
	var page = document.form3.list3.options[document.form3.list3.selectedIndex].value;//page is the published path/filename
	self.location = page;
}

// Function to open images in pop-up, appending imageType (Zoom or DPI to file name)
// Title attribute can NOT contain any spaces or special chars
function openImageZoomDPI(imageType, filepath, windowWidth, windowHeight) {
	
	//use the length as a base reference for parsing purposes 
	var pathLength = filepath.length; 
	//get the inex value for the last index of "/"
	var index = filepath.lastIndexOf('/');
	//get the file name
	var filename = filepath.substring(index+1, pathLength-4); 
	// Append Image type, Zoom or DPI
	var title = filename +'_'+ imageType;
	
	// Adding default windowsize (800 by 600 as per ST's Magic Ticket #109490).
	// Date: 06-06-2007 - Author: W. van den Besselaar (DELT ICT Services)
	windowWidth = 800;
	windowHeight = 600;

	var newWindow = window.open("", title, "width="+windowWidth+",height="+windowHeight+",toolbar=no,menubar=no,directories=no,resizable=yes,scrollbars=auto,location=no,status=no");
	newWindow.document.open();
	newWindow.document.write("<HTML><HEAD><TITLE>"+title+"</TITLE></HEAD><BODY leftMargin=0 topMargin=0 marginheight=0 marginwidth=0><IMG border=0 src="+filepath+"></BODY></HTML>");
	newWindow.document.close();
	newWindow.focus();
}


// Function to open images in pop-up
// Title attribute can NOT contain any spaces
function openImageInPopUp(title, filename, windowWidth, windowHeight) {
	var newWindow = window.open("", title, "width="+windowWidth+",height="+windowHeight+",toolbar=no,menubar=no,directories=no,resizable=yes,scrollbars=auto,location=no,status=no");
	newWindow.document.open();
	newWindow.document.write("<HTML><HEAD><TITLE>"+title+"</TITLE></HEAD><BODY leftMargin=0 topMargin=0 marginheight=0 marginwidth=0><IMG border=0 src="+filename+"></BODY></HTML>");
	newWindow.document.close();
	newWindow.focus();
}

		// General function to open files in pop-up (eg. PDF), title attribute can be ""
		// =======================================================

		function openFileInPopUp(title, filename, windowWidth, windowHeight) {
			//variable for adapting the windowheight
			windowHeightNew = windowHeight *.667;
			windowWidthNew = windowWidth *.667;


			//variable to hold variable
			var fullUrl = filename;

			//use the length a a base reference for parsing purposes
			var urlLength = fullUrl.length;

			//get the 3 digit extension
			var OleExtension = fullUrl.substring(urlLength - 3, urlLength);

			//get the base reference for evaluating that url is or is not internal
			var slashes = fullUrl.indexOf("//");
			var externalUrl = fullUrl.substring(slashes + 2, slashes + 12);

			// If the following condition is true, open a new window, else open link in current window
			// If file extension is neither htm nor pl (perl) OR URL is not referencing current site open new window
			// (must cater for http://voyager:82/business/page.htm and ../business/page.htm)

			if (OleExtension != ".pl" ||
					((externalUrl != "voyager:82") && (slashes > -1 )) ){

				if (fullUrl.indexOf("http://") == 0)
				{
					var newWindow = window.open(filename, title,"width="+windowWidthNew+",height="+windowHeightNew+", top=0, left=106 ,toolbar=yes,menubar=yes,directories=no,resizable=yes,scrollbars=yes,location=yes,status=yes");
					newWindow.focus();					
					return;
				}
				
				if (fullUrl.indexOf("mailto")==0)
				{
					self.location = filename;
					return;	
				}
				
				var mustPopup = false;
				
				if(filename.indexOf("pop-up:")==0){
					//Set flag, strip out popup: bit
					mustPopup = true;
					filename = filename.substr(filename.lastIndexOf("pop-up:") + 7,filename.length);					
					
				}
				filename = checkExtension(filename);
				if(filename.indexOf('/')==0){
					
			    		var vLocaleExists= localeCheck(filename);
			    		if (vLocaleExists == false)
			    		{
			    			filename = buildLocalePath(filename);
			    		}
			    	}
			    	if (mustPopup)
			    	{
			    		childOpen = true;			   
			    		var newWindow = window.open(filename, title,"width="+windowWidthNew+", height="+windowHeightNew+", top=0, left=106 ,toolbar=no,menubar=no,directories=no,resizable=yes,scrollbars=no,location=no,status=no");
			    		//vReturnValue = window.showModalDialog(filename ,title, "dialogHeight:"+windowHeightNew+"px; dialogLeft:106px;scroll:no");
				}
				else
				{
					self.location = filename;
				}
			}
			else
			{ // http window
				self.location = filename;
			}
		}

		// A function that builds the url based upon the following rules for Internal Links
		// =========================================================
		function localeCheck(filename){

				
				// set locales
				var test=false;
				var vlocale= new Array();
								 vlocale[0]  = "de_DE";
								 vlocale[1]  = "en_GB";
								 vlocale[2]  = "en_US";
								 vlocale[3]  = "es_CL";
								 vlocale[4]  = "es_ES";
								 vlocale[5]  = "es_PE";
								 vlocale[6]  = "fr_BE";
								 vlocale[7]  = "fr_FR";
								 vlocale[8]  = "it_IT";
								 vlocale[9]  = "nl_BE";
								 vlocale[10] = "nl_NL";
								 vlocale[11] = "pt_PT";

				// starts with a slash
				if (filename.indexOf("/") == 0){

					
					// check locale
						for(var i=0;i<vlocale.length;i++){
											// if we find a locale
							if (filename.indexOf(vlocale[i])>0) {
									// open in a new window
									test = true;
							} // end if

						} // end for
				} // end if
				
				return test;

			} // end localeCheck

			// check the extension
			// ===============
			function checkExtension(filename) {

				// alert (filename);
				// check for ? as this contains GET
				var suffPos = filename.lastIndexOf("?");

				if (suffPos>0){

					// if '?' is found read back to first occurance of '/'

					// from the / +1 to the ? -1 is the filename
					var shortName = filename.substr(filename.lastIndexOf("/")+1,(filename.length-filename.lastIndexOf("/")+1)-(filename.length-suffPos+2));
					// alert(shortName);
				    if (shortName.indexOf(".")<=0){
				    	shortName+=".htm"

				    	filename = filename.substr(0,filename.lastIndexOf("/")+1) + shortName + filename.substr(suffPos,filename.length-suffPos);
				    	//alert (filename);

				    } // end if - check for suffix

				} else if ((suffPos = filename.indexOf('.xml')) > 0) {
					filename = filename.substring(0,filename.length -4);
					filename += '.htm';
				}
				else {
					// no GET is found
					var lastSlash = filename.lastIndexOf("/");
					var shortname = filename.substr(lastSlash+1, filename.length - lastSlash);
					//alert (shortname);
					if (shortname.indexOf(".")<=0){
						shortname+=".htm"
						//alert(filename.substr(0,filename.lastIndexOf("/")+1));
						filename = filename.substr(0,filename.lastIndexOf("/")+1) + shortname;
						//alert(filename);
					} // end if - check for suffix

				} // end if check for GET

				return filename;

			} // End function
			
			
			// build the path with the local prefixed at the beginning
			//========================================
			function buildLocalePath(filename){					
				if (filename.indexOf("/downloads") != -1)
				{
					return "/en_US" + filename;
				}
				var strUrl = document.location.href;
				var index1 = strUrl.indexOf("//");
				index1 = strUrl.indexOf('/',index1 + 2);
				var index2 = strUrl.indexOf('/',index1 + 1);
				var strLocale = strUrl.substring(index1 +1, index2);
				return	"/" +strLocale + filename;

			} // end build Locale path

// General function that takes the full url and returns the the string between the last slash and the extension
function getFileName(fullUrl) { 
	
	//use the length a a base reference for parsing purposes 
	var urlLength = fullUrl.length; 
	//get the inex value for the last index of "/"
	var index = fullUrl.lastIndexOf('/');
	//get the file name
	var filename = fullUrl.substring(index+1, urlLength-4); 
	
	return filename;
	
} 
