var sString = 'string';

/*
	makeKey
	Parameters:
		id: ID of item.
		name: Name of item.
	Returns:
		String.
		Name formatted to match form field name format.

	Formats form field names for multiple record submission.
*/
function makeKey(strID, strName) {
	var C_PADLENGTHLIMIT = 8; // Anything longer than this is not padded.

	var strID = "" + strID;
	while (strID.length < C_PADLENGTHLIMIT) {
		// Zero pad.
		strID = "0" + strID;
	}

	return "fd_" + strID + "_" + strName;
}

/*
	Opens a new browser window, often for checking a URL.
	Parameters: absolute YRL to display, name of opened window.
*/
function popUpURL(strURL, strName) {
	var w = window.open(strURL, strName);
	w.focus();
}

function blnAreYouSureDialog(strMessage) {
	var strPrompt = "Click OK to proceed, or Cancel to abort.";
	return confirm(strMessage + "\n\n" + strPrompt);
}

function openWindow(theURL,winName,iWidth, iHeight) {
	var LeftPos=(screen.width)?(screen.width-iWidth)/2:100;
    var TopPos=(screen.height)?(screen.height-iHeight)/2:100;
	features= 'width=' + iWidth + ',height=' + iHeight + ',top=' + TopPos + ',left=' + LeftPos + ' ,scrollbars=yes';
	window.open(theURL,winName,features);
}

/*	Called on text-fields to perform a task such as moving to the next field,
	or automatically submitting the form. */
function doCallOnEnter(myEvent, srcCtrl, myFunc) {
	var keyValue, node;

	myEvent = (myEvent) ? myEvent : ((window.event) ? window.event : null);
	node = (myEvent.target) ? myEvent.target : ((myEvent.srcElement) ? myEvent.srcElement : null);
	keyValue = myEvent.keyCode;

	if ((myEvent.keyCode == 13)) { // && (node.type=="text")) {
		myFunc(srcCtrl);
		return false;
	}
	else return true;

	//if (myEvent.which) keyValue = myEvent.which;
	//else if (window.event) keyValue = window.event.keyCode;
}

/*	Gives the form-control that follows the specified form-control, focus.
	The parameter is the actual form-control object. */
function focusOnNextFormControl(objCtrl) {
	var i, iMax;
	iMax = document.forms[0].length;
	for (i = 0; i < iMax; i++){
		if (document.forms[0][i].name == objCtrl.name){
			i = ((i + 1) >= iMax) ? 0 : (i + 1);
			document.forms[0][i].focus();
		}
	}
}

/*	Usually called from the 'body' tag 'onLoad' event,
	and used to give a particular field default focus
	without the user having to select the field with the mouse first.
	Supplied parameter is the string name of the field name to focus on. */
function focusOnFormControl(sCtrlName) {
	document.forms[0][sCtrlName].focus();
}

/*  Usually called from a 'submit' button hyperlink.
	Submits the first form found on the page. */
function submitForm(){
//	do_escape();
	document.forms[0].submit();			
}

/*	Usually called from a 'reset' button hyperlink.
	Resets the first form found on the page. */
function resetForm(){
	document.forms[0].reset();
}

function submitForm1(){
	do_escape1();
	document.forms[0].submit();			
}
/*  Usually called from a 'submit' button hyperlink.
	Submits the first form found on the page. */
function submitFormX(){
	
	//do_escapeX(); Commented out, need to do it from backend
	document.forms[0].submit();			
}
/*	Usually called from a 'reset' button hyperlink.
	Resets the first form found on the page. */
function resetForm(){
	document.forms[0].reset();
}

function do_escape()
{
/* if a single quotes found escapes it */
	var txtsearchterm; 
	var txtlocation;
	txtsearchterm = window.document.forms[0].txtSearchTerm.value;
	txtlocation = window.document.forms[0].txtLocation.value;
	
	var pos = txtsearchterm.indexOf("'")
	if (pos>=0)
	{
		window.document.forms[0].txtSearchTerm.value = escape(txtsearchterm);			
	}
	pos ="";
	pos = txtlocation.indexOf("'")
	if (pos>=0)
	{
		window.document.forms[0].txtLocation.value = escape(txtlocation);				
	}		

}

function do_escapeX()
{
/* if a single quotes found escapes it */
	var txtsearchterm; 
	var txtlocation;
	txtsearchterm = window.document.forms[0].phrase.value;
	txtlocation = window.document.forms[0].location.value;
		
	var pos = txtsearchterm.indexOf("'")
	if (pos>=0)
	{		
		window.document.forms[0].phrase.value = escape(txtsearchterm);			
	}
	pos ="";
	pos = txtlocation.indexOf("'")
	if (pos>=0)	
	{		
		window.document.forms[0].location.value = escape(txtlocation);				
	}	
}

function do_unescape()
{
/* script to unescape the string */
	var txtsearchterm; 
	var txtlocation;
	txtsearchterm = window.document.forms[0].txtSearchTerm.value;
	txtlocation = window.document.forms[0].txtLocation.value;
	window.document.forms[0].txtSearchTerm.value = unescape(txtsearchterm);		
	window.document.forms[0].txtLocation.value = unescape(txtlocation);		
}

function do_unescapeX()
{		
/* script to unescape the string */
	var txtsearchterm; 
	var txtlocation;
	txtsearchterm = window.document.forms[0].phrase.value;
	txtlocation = window.document.forms[0].location.value;
	window.document.forms[0].phrase.value = unescape(txtsearchterm);		
	window.document.forms[0].location.value = unescape(txtlocation);		
}

function do_escape1()
{
/* if a single quotes found escapes it */
	var txtsearchterm; 
	var txtlocation;
	txtsearchterm = window.document.forms[0].phrase.value;
	txtlocation = window.document.forms[0].location.value;
	
	var pos = txtsearchterm.indexOf("'")
	if (pos>=0)
	{
		window.document.forms[0].phrase.value = escape(txtsearchterm);			
	}
	pos ="";
	pos = txtlocation.indexOf("'")
	if (pos>=0)
	{
		window.document.forms[0].location.value = escape(txtlocation);				
	}		

}

function do_unescape1()
{
/* script to unescape the string */
	var txtsearchterm; 
	var txtlocation;
	txtsearchterm = window.document.forms[0].phrase.value;
	txtlocation = window.document.forms[0].location.value;
	window.document.forms[0].phrase.value = unescape(txtsearchterm);		
	window.document.forms[0].location.value = unescape(txtlocation);		
}

/**************************************************************
 Left: Returns a String containing a specified number of 
       characters from the left side of a string.

 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 

 Returns: String
***************************************************************/
function Left(String, Length)
{
	if (String == null)
		return (false);

	return String.substr(0, Length);
}

/***********************************************************************************************************

				 THE IMAGESWAPPER
	
************************************************************************************************************/
function imgswap(pic,imageName){
	
	/*This function takes images names that have "N" for normal or "H" for highlighted as the last
	letter in the images name and also a suffix (".gif" etc) must be present also 
	All images must be in a folder named "images" unless otherwise explicitly stated in all references
	to the images within the HTML page.
	If the image rolled over changed a different image than itself on the same page then add the name of 
	the swapped image as the second parameter (imageName) otherwise leave it blank */
	

	if (pic.indexOf("images")==-1){
		pic = "images/"+pic;
	}
	
	var suffix = pic.slice(pic.length-5,pic.length);
	
  	var picstartpos = pic.indexOf("images/");
	var picname = pic.substring(picstartpos+7,pic.length-5);
				

	if (typeof(imageName)!="undefined"){
		picname=imageName;}

  	if (document.all){	
		document.all(picname).src=pic;
  	}
  
  	if (document.layers){
  
  	var theString = document.images[picname].src;
  	
  	/*This finds the second to last delimiter to obtain the whole image address for Netscape
  	or just gives it the ../name string which appears to work*/
  	
  	if (pic.charAt(0)==".") {
  	  	document.images[picname].src=pic;
  	} else {
		var lastPos = (theString.slice(0,theString.lastIndexOf("/")-1).lastIndexOf("/")+1);
		document.images[picname].src=theString.slice(0,lastPos)+(pic);
 	}
  }
}

/***********************************************************************************************************
				 Pgnet searc script	
************************************************************************************************************/
function PgnetSearch(term,loc)
{
	window.document.frmSearchRes.txtLocation.value = loc;
	window.document.frmSearchRes.txtSearchTerm.value = term;
	window.document.frmSearchRes.submit();
}

function PgnetSearchX(term,loc)
{
	window.document.frmSearchRes.location.value = loc;
	window.document.frmSearchRes.phrase.value = term;
	window.document.frmSearchRes.submit();
}

/***********************************************************************************************************
				Replaces the characters.
************************************************************************************************************/

function replaceChars(from,to,val) {
	temp = "" + val; // temporary holder
	while (temp.indexOf(from)>-1) {
		pos= temp.indexOf(from);
		temp = "" + (temp.substring(0, pos) + to + 
		temp.substring((pos + from.length), temp.length));		
		}
		return temp;		
	}	


function checkEnter()
{
 	if (window.document.all){
	  if (window.event.keyCode == 13){
	   window.event.returnValue=false;
	   window.event.cancel = true;
	  }
	 }
	 else if (window.document.getElementById){
	  if (window.event.which == 13){
	   window.event.returnValue=false;
	   window.event.cancel = true;
	  }
	 }
	 else if(window.document.layers){
	  if(window.event.which == 13){
	   window.event.returnValue=false;
	   window.event.cancel = true;
	  }
	 }
}

