/**	Basic Document Functions*	addDIV (divName) - adds a div element to the document* 	showLooading		- shows the loading message*	hideLoading			- hides the loading message*   destroyDIV				- removes the div from the document*	getSelectedValue 	- retrieves the value that is selected from a select item*	selectValue			- sets a specific value in the select field as selected* 	closeAllOpenDIVs	- Close all of the open divs on the page*	calculateOffset 		- Work out where to place the DIV*	positionDIV			- Place the div at the co-ordinates*   searchForDocument - calls an agent to perform a search for the user*	Sean Power 26th August 2007*/var openDIVs = new Array(); // this is a list of current open divs, this way i can close/remove them when ever i do something elsevar openCount = 0; 			//number of open divsvar documentList;				//array of document objects we have retievedvar productOpen = false;		// specifies if a product is open, we check this and close as needed//should be called when ever we need to reset the screen - ie close any open divs or anything like thatfunction resetScreen (){	//if we have a 'product open' then close it and reset the field	if (productOpen)	{		hideProductBox ();	}	//reset the content div height	setContentDIVHeight ();		//if we aren't logged in then we need to display the login details	if (currentUser == 'Anonymous')	{		showLogin ();	}else	{		hideLogin ();	}		//hide the document box if it's up	hideDocumentBox ();		scroll (0,0);	}function setContentDIVHeight (){	//reset firefox's height to inner first up - this is because it doesn't expand or contract like i need it too	if (typeof(window.innerHeight) == 'number')  	{    		document.getElementById ("content").style.height = window.innerHeight -60;	}	//then get the full hieght	document.getElementById ("content").style.height = getWindowHeight () - 60;}function addDIV (divName){  	// get the div. If such a div doesn't yet exist on the HTML  	// document we're working with, add one.  	if (!document.getElementById(divName)) {    		// don't use innerHTML to update the body, because it can cause global variables    		// that are currently pointing to objects on the page to have bad references     	var newNode = document.createElement("div");    		newNode.setAttribute("id", divName);    		newNode.setAttribute("class", divName);    		newNode.setAttribute("style", "visibility: hidden;");   		document.body.appendChild(newNode);   		   		openDIVs [openCount] = divName;   		openCount += 1;  	}}//add hidden to the classes of an element - hiding it!function addHiddenClass (elId){	if (document.getElementById (elId))	{		var el = document.getElementById (elId);		var tClass = "hidden";				if (el.className.indexOf ("hidden") < 0)		{			//if the element doesn't have a class already then just add it			if (el.className == "")			{				el.className = tClass;				}else			{				//there must be something else so we need to add a space between them				el.className += " " + tClass;			}		}	} //end if element exists} //end addHiddenClass//remove 'hidden' from the class of an element, un hidding itfunction removeHiddenClass (elId){	if (document.getElementById (elId))	{		var el = document.getElementById (elId);		//try removing it with a space at the start first		el.className = el.className.replace(' hidden', '');				//then incase that didn't work (ie hidden is the only thing there) we can just remove it with out a space		el.className = el.className.replace('hidden', '');			} //end if element exists} //end removeHiddenClassfunction showLogin (){	removeHiddenClass ("Login");}function hideLogin (){	addHiddenClass ("Login");}function showDocumentBox (){	removeHiddenClass ("DocumentDetails-Box");} //end showDocumentBoxfunction hideDocumentBox (){	addHiddenClass ("DocumentDetails-Box");} //end hideDocumentBoxfunction showLoading (){	removeHiddenClass ("loading-area");} //end showLoadingfunction hideLoading (){	addHiddenClass ("loading-area");} //end hideLoadingfunction destroyDIV (DIVName){     //check if this div even exists     if (document.getElementById(DIVName))     {		document.body.removeChild(document.getElementById(DIVName));		openDIVs.remove (DIVName);		if ( openCount >0 )		{					openCount --;		}	}} //end destroyDIV  //trim function to remove leading and trailing whitespaceString.prototype.trim = function () {    return this.replace(/^\s*/, "").replace(/\s*$/, "");}//remove function for arraysArray.prototype.remove=function(s){  for(i=0;i<this .length;i++){    if(s==this[i]) this.splice(i, 1);  }}//remove an element from an arrayArray.prototype.removeElement = function (elNum){	this.splice (elNum, 1);}//Gets the selected value from a select itemfunction getSelectedValue (selectField){  var selection;  var selectValue = "";  for (var i=0; i<selectField.length; i++)	{    		selection = selectField[i];    		if (selection.selected)    		{       		//drop out of the loop - return the value if there is one other wise the text       		if (selection.value != "")       		{       			selectValue = selection.value;       		}else       		{       			selectValue = selection.text;       		}      		i = selectField.length;    		}	}	return selectValue;} //end getSelectedValue//Selects a specific value in a select fieldfunction selectValue (selectField, value){	  for (var i=0; i<selectField.length; i++)	{		if (selectField[i].value == value || selectField[i].text == value)		{			selectField[i].selected = true;		}else		{			selectField[i].selected = false;			}	}} // end select value//Close all of the open divs on the pagefunction closeAllOpenDIVs (){	for( x in openDIVs)	{		if (openDIVs[x] != "")		{			if (document.getElementById(openDIVs[x]))			{			document.body.removeChild(document.getElementById(openDIVs[x]));			openCount -= 1;			}		}	}} // end closeAllOpenDIVs//Work out where to place the DIVfunction calculateOffset (displayField, displayBelow){     var cursor = {x:0,y:0};     cursor.x = displayField.offsetLeft;     cursor.y = displayField.offsetTop;      if (displayBelow == true){         cursor.y+= displayField.offsetHeight;      }       // deal with elements inside tables and such       var parent = displayField;       while (parent.offsetParent) {                 parent = parent.offsetParent;                 cursor.x += parent.offsetLeft;                 cursor.y += parent.offsetTop;       }    return cursor;} //end calculate offset//Place the div at the co-ordinatesfunction positionDIV (cursor, divElement){  	divElement.style.position = "absolute";  	divElement.style.left = cursor.x + "px";  	divElement.style.top = cursor.y + "px";  	divElement.style.visibility = "visible";  	divElement.style.display = "block";  	divElement.style.zIndex = 10000;} // end positionDIVfunction getWindowHeight() {	var windowHeight = 0;	var iHeight = 0;  	if (typeof(window.innerHeight) == 'number')  	{    		iHeight = window.innerHeight;	}  	if (document.documentElement && document.documentElement.clientHeight)     		windowHeight = document.documentElement.clientHeight;	else {     		if (document.body && document.body.clientHeight)        				windowHeight = document.body.clientHeight; }; 			if (iHeight > windowHeight)		{			windowHeight = iHeight;		}  	return windowHeight;} //end getWindowHeight//retrieves all document information and displays it - either buy a new window or inside a div on this page//useDIV specifies wether to use a div or wether to launch a new window.//poisitonElement allows an element name to be entered that we can use to position the divfunction loadDocument (unid, useDIV, divID, positionElement){	var cDoc;	for (var i = 0; i<documentList.length; i++)	{		if (documentList[i].unid == unid)		{			cDoc = documentList[i];			i = documentList.length;		}	}		if (!cDoc)	{		alert ("An error has occured trying to load the selected document, we are unable to process this request.");	}	if (useDIV) 	{		var containerDIV = document.getElementById (divID + "-Box"); //this will be a div with atable and stuff to give it some back ground etc		var docData = document.getElementById (divID);		//set the field values of the current document				docData.innerHTML = cDoc.generateDocumentHTML ();				//display the div		if (positionElement) 		{			if (document.getElementById (positionElement))			{				var cursor = calculateOffset (document.getElementById (positionElement), false);				containerDIV.style.left = cursor.x + "px";		 	 	containerDIV.style.top = cursor.y + "px";			}		}		removeHiddenClass (containerDIV.id);		productOpen = true;	}else	{		window.open (webPath + "/x/" + unid + "?OpenDocument");			}	} // end load document function//hide the product divfunction hideProductBox (){	addHiddenClass ("ProductDetails-Box");	productOpen = false;}//format currencyfunction formatCurrency(num) {	num = num.toString().replace(/\$|\,/g,'');	if(isNaN(num))	num = "0";	sign = (num == (num = Math.abs(num)));	num = Math.floor(num*100+0.50000000001);	cents = num%100;	num = Math.floor(num/100).toString();	if(cents<10) cents = "0" + cents;	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)	num = num.substring(0,num.length-(4*i+3))+','+	num.substring(num.length-(4*i+3));	return (((sign)?'':'-') + '$' + num + '.' + cents);}function searchForDocument (){ 	if (	document.getElementById ("SearchFor").value == "") return false;	var xmlhttp = new XMLHttpRequest ();		xmlhttp.open ("POST", "(ag.Eastend.Web.Search)?OpenAgent", true) //open the view ready to send the request		//Add a listener so we know when the agent has finished retrieving information	function searchHandler ()	{		if (xmlhttp.readyState == 4)		{		if(xmlhttp.responseXML.getElementsByTagName ("Error").length >0 ){		 // construct a human readable error description			alert ( xmlhttp.responseXML.getElementsByTagName ("Error")[0].firstChild.nodeValue);		}else{			//check if there were results - if not put up a no results message			if (xmlhttp.responseXML.getElementsByTagName ("NoResults").length >0)			{				var viewData = document.getElementById ("ViewData");				viewData.innerHTML = "No Documents found for the requested search.";			}else{				//else get the search folder and call the viewnavigator stuff to get the docs				viewName = xmlhttp.responseXML.getElementsByTagName ("SearchFolder")[0].firstChild.nodeValue.trim();				vPosition = 1;				retrieveViewDocuments ("");			}		}			hideLoading ();		}	}	//tell the http request what to run when we're ready	xmlhttp.onreadystatechange = searchHandler;		//Draw the loading DIV so the user knows we're doing something	showLoading ();     xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');    	xmlhttp.send(getSearchString());}function getSearchString (){	var searchString;		//get the search type	searchString = "&SEARCHTYPE=" + getSelectedValue (document.getElementById ("SearchType")); 	searchString += "&PARAMS=" + document.getElementById ("SearchFor").value.replace (/&/g, "~amp;"); //i seperate the params by & so i need to make it something different	searchString += "&USERNAME=" + currentUser;	return (searchString);}//Check image load - un hide it if we've loaded correctly, if it's 'missing' then we leave it hiddenfunction checkImageFound (img){	img.className = img.className.replace('hidden', '');}