// (C) 2000-2007
// Written by Roberto Cisternino
// Compliance Level:	W3C DOM Standard Browsers
//						Internet Explorer non standard (layers)
//						Netscape Navigator non standard (layers)
//						Opera (base compliance)
var agent=navigator.userAgent.toLowerCase();
var ie4=document.all? true : false;
// Detect IE5+ and Firefox (including NS6+) [Modern Browser with DOM support]
var W3C=(typeof(document.getElementById) != 'undefined') ? true : false;
// Detect Firefox (and NS6+) exclusively
var FFox = W3C && !document.all;
var ns4=document.layers? true : false;
var MOZ5 = ((agent.indexOf('mozilla')==0) && (agent.charAt(8) >= 5) && (agent.indexOf('compatible')<0));
// Detect Opera 6+ exclusively
var OP = agent.indexOf('opera')>=0;	// window.opera && window.print
var mLeft;	// Mouse X
var mTop;	// Mouse Y
var contentType = 'HTM';
var keyCode;		// Key pressed
var ctxBack;		// Context Back URL

/* Keyboard <CR> Focus Change, Auto Focus Change
 * The <CR> is changed to <TAB> on condition
 */
/*
function CRasTAB(e) {
	var sysKeys=new Array(8,9,16,17,18,20,27,33,34,35,36,37,38,39,40,45,46,92,112,113,114,115,116,117,118,119,120,121,122,123,144);
	keyCode = (ns4 || MOZ5) ? ((e.keyCode) ? e.keyCode : e.which) : window.event.keyCode;
	var tgt = (ns4 || MOZ5) ? e.target : window.event.srcElement;
	var isFull = (tgt.type=='text' && tgt.maxLength && tgt.value.length==tgt.maxLength && ArraySearch(sysKeys, keyCode)==-1);
	// Enter is pressed and/or select-one (combobox) is empty or text input is full
	if ((keyCode==13 && !(tgt.type=='select-one' && tgt.value=='') && tgt.type!='submit') || isFull==true) {
		if (ns4 || MOZ5)
			e.which = 9;
		else
			window.event.keyCode = 9;
	} 
	return true;
}
*/
function CRasTAB(nextInput, e) {
	var sysKeys=new Array(8,9,16,17,18,20,27,33,34,35,36,37,38,39,40,45,46,92,112,113,114,115,116,117,118,119,120,121,122,123,144);
	keyCode = (ns4 || MOZ5) ? ((e.keyCode) ? e.keyCode : e.which) : window.event.keyCode;
	var tgt = (ns4 || MOZ5) ? e.target : window.event.srcElement;
	var isFull = (tgt.type=='text' && tgt.maxLength && tgt.value.length==tgt.maxLength && ArraySearch(sysKeys, keyCode)==-1);
	var currInput;
	// Enter is pressed and/or select-one (combobox) is empty or text input is full
	if ((keyCode==13 && !(tgt.type=='select-one' && tgt.value=='') && tgt.type!='submit') || isFull==true) {
		if (isFull==true && nextInput) {
			nextInput.select();
		} else {
			if (ns4 || MOZ5)
				e.which = 9;
			else
				window.event.keyCode = 9;
		}
	} 
	return true;
}

if (ns4 || MOZ5) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
//document.onkeydown = keyDown; // work together to analyze keystrokes

// Keyboard Edit control
var keybYN = new keybEdit('yn','Valid values are \'Y\' or \'N\'.');
var keybNumeric = new keybEdit('-0123456789','Numeric input only.');
var keybAlpha = new keybEdit('abcdefghijklmnopqrstuvwxyz ','Alpha input only.');
var keybAlphaNumeric = new keybEdit('abcdefghijklmnopqrstuvwxyz-0123456789 ','Alpha-numeric input only.');
var keybDecimal = new keybEdit('-0123456789.','Decimal input only.');
var keybDate =  new keybEdit('0123456789/','Date input only');
var keybYNNM = new keybEdit('yn');
var keybNumericNM = new keybEdit('-0123456789');
var keybAlphaNM = new keybEdit('abcdefghijklmnopqrstuvwxyz ');
var keybAlphaNumericNM = new keybEdit('abcdefghijklmnopqrstuvwxyz-0123456789 ');
var keybDecimalNM = new keybEdit('-0123456789.');
var keybDateNM = new keybEdit('0123456789/');
// Common Regex strings
var nameRegex = "^[A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]+$";
var emailRegex = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
function testRegex(field, msg, rule) {
	var reg = new RegExp(rule);
	if (reg.test(field.value))
		return true;
		
	window.alert(msg);
	field.focus();
	return false;
}
function keybEdit(strValid, strMsg) {
	/*	Function:		keybEdit
		Creation Date:	October 11, 2001
		Programmer:		Edmond Woychowsky
		Purpose:		The purpose of this function is to be a constructor for
						the keybEdit object.  keybEdit objects are used by the
						function editKeyBoard to determine which keystrokes are
						valid for form objects.  In addition, if an error occurs,
						they provide the error message.
						
						Please note that the strValid is converted to both
						upper and lower case by this constructor.  Also, that
						the error message is prefixed with 'Error:'.
						
						The properties for this object are the following:
							valid	=	Valid input characters
							message	=	Error message
							
						The methods for this object are the following:
							getValid()	=	Returns a string containing valid
											characters.
							getMessage()=	Returns a string containing the
											error message.

		Update Date:	Programmer:			Description:
	*/

	//	Variables
	var reWork = new RegExp('[a-z]','gi');		//	Regular expression

	//	Properties
	if(reWork.test(strValid))
		this.valid = strValid.toLowerCase() + strValid.toUpperCase();
	else
		this.valid = strValid;

	if((strMsg == null) || (typeof(strMsg) == 'undefined'))
		this.message = '';
	else
		this.message = strMsg;

	//	Methods
	this.getValid = keybEditGetValid;
	this.getMessage = keybEditGetMessage;
	
	function keybEditGetValid() {
	/*	Function:		keybEdit
		Creation Date:	October 11, 2001
		Programmer:		Edmond Woychowsky
		Purpose:		The purpose of this function act as the getValid method
						for the keybEdit object.  Please note that most of the
						following logic is for handling numeric keypad input.

		Update Date:		Programmer:			Description:
	*/

		return this.valid.toString();
	}
	
	function keybEditGetMessage() {
	/*	Function:		keybEdit
		Creation Date:	October 11, 2001
		Programmer:		Edmond Woychowsky
		Purpose:		The purpose of this function act as the getMessage method
						for the keybEdit object.

		Update Date:	Programmer:			Description:
	*/
	
		return this.message;
	}
}

void function editKeyBoard(objForm, objKeyb) {
	/*	Function:		editKeyBoard
		Creation Date:	October 11, 2001
		Programmer:		Edmond Woychowsky
		Purpose:		The purpose of this function is to edit edit keyboard input
						to determine if the keystrokes are valid.
	
		Update Date:		Programmer:			Description:
	*/
	keyCode = (ns4 || MOZ5) ? e.which : window.event.keyCode ;

	strWork = objKeyb.getValid();
	strMsg = '';							// Error message
	blnValidChar = false;					// Valid character flag

	if (!keyCode) {
		return;
	}
	
	// Part 1: Validate input
	if(!blnValidChar)
		for(i=0;i < strWork.length;i++) {
			if(keyCode == strWork.charCodeAt(i)) {
				blnValidChar = true;

				break;
			}
		}

	// Part 2: Build error message
	if(!blnValidChar) {
		if(objKeyb.getMessage().toString().length != 0)
			alert('Error: ' + objKeyb.getMessage());

		if (!ns4 && !MOZ5)
			window.event.returnValue = false;		// Clear invalid character

		objForm.focus();						// Set focus
	}
}
function validateMandatoryInput(field, msg) {
	if (!field.disabled && field.type != 'hidden' && (field.type=='select-one' ? field.selectedIndex <= 0 : field.value.length < 1)) {
		window.alert(msg);
		field.focus();
		return false;
	}
	return true;
}
function _SetMouseCoordinate(e) {
	if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mLeft = e.pageX;
      mTop = e.pageY;
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mLeft = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      mTop = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }	
}

function _GetWindowWidth(w) {
	var theWidth = 0;

	if (w.innerWidth)
	{
		theWidth = w.innerWidth
	}
	else if (w.document.documentElement && w.document.documentElement.clientWidth)
	{
		theWidth = w.document.documentElement.clientWidth
	}
	else if (w.document.body)
	{
		theWidth = w.document.body.clientWidth
	}
	return theWidth;
}

function _GetWindowHeight(w) {
	var theHeight = 0;

	if (w.innerHeight)
	{
		theHeight = w.innerHeight
	}
	else if (w.document.documentElement && w.document.documentElement.clientHeight)
	{
		theHeight = w.document.documentElement.clientHeight
	}
	else if (w.document.body)
	{
		theHeight = w.document.body.clientHeight
	}
	return theHeight;
}

function _GetHorzScrollOffset(w) {
	var pos = 0;
	if (w.pageXOffset)
	{
		  pos = w.pageXOffset
	}
	else if (w.document.documentElement && w.document.documentElement.scrollLeft)
	{
		pos = w.document.documentElement.scrollLeft
	}
	else if (w.document.body)
	{
		  pos = w.document.body.scrollLeft
	}
	return pos;
}

function _GetVertScrollOffset(w) {
	var pos = 0;

	if (w.pageYOffset)
	{
		  pos = w.pageYOffset
	}
	else if (w.document.documentElement && w.document.documentElement.scrollTop)
	{
		pos = w.document.documentElement.scrollTop
	}
	else if (w.document.body)
	{
		  pos = w.document.body.scrollTop
	}
	return pos;
}

function LTrim(str) {
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;

		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;

		s = s.substring(j, i);
	}

	return s;
}

function RTrim(str) {
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;       // Get length of string

		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;

		s = s.substring(0, i+1);
	}

	return s;
}

function Trim(str) {
	return RTrim(LTrim(str));
}

function warningRedirect() {
	self.location.href = "/default.jsp?doc=template.jsp&ctx=/icons/warning.gif&msg=This operation is currently unavailable due to technical reasons,<BR>please be advised our technical staff is already taking the required actions to fix the problem.<BR>Thank you.&title=Warning&img=/icons/warning.gif&backOption=2";
}

function _PreloadImages() {
  var d=document; if(d.images){ if(!d._p) d._p=new Array();
    var i,j=d._p.length,a=_PreloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d._p[j]=new Image; d._p[j++].src=a[i];}}
}
function _ShowObj(lId)
{
  var ob;ob=new Array;
  if (W3C)
  {
    ob[lId] = document.getElementById(lId).style;	//getAttribute('style');

    if (ob[lId]) {
        ob[lId].visibility = "visible";
        ob[lId].display = "";
    }
  } else if (ns4)
  {
    w_str = "document." + lId;ob[lId] = eval(w_str);
    if (!ob[lId]) ob[lId] = _FindObj(document, lId);
    if (ob[lId]) {
    	ob[lId].visibility = "show";
        ob[lId].display = "";
    }
  } else if (ie4)
  {
    w_str = "document.all.item(\"" + lId + "\").style";
    ob[lId] = eval(w_str);
    ob[lId].visibility = "visible";
    ob[lId].display = "";
  }
}

function _HideObj(lId)
{
  var ob;ob=new Array;
  if (W3C)
  {
    ob[lId] = document.getElementById(lId).style;	//getAttribute('style');

    if (ob[lId]) {
        ob[lId].visibility = "hidden";
        ob[lId].display = "none";
    }
  } else if (ns4)
  {
    w_str = "document." + lId;ob[lId] = eval(w_str);
    if (!ob[lId]) ob[lId] = _FindObj(document, lId);
    if (ob[lId]) {
       ob[lId].visibility = "hide";
       ob[lId].display = "none";
    }
  } else if (ie4)
  {
    w_str = "document.all.item(\"" + lId + "\").style";ob[lId] = eval(w_str);
    ob[lId].visibility = "hidden";
    ob[lId].display = "none";
  }
}
// Tested with IE 7 and Firefox 2.0.0.2
function _isVisible(lId)
{
  var ob;ob=new Array;
  if (W3C)
  {

    ob[lId] = document.getElementById(lId).style;	//getAttribute('style');

    if (ob[lId] && (ob[lId].visibility == "visible" && ob[lId].display == "")) {
    	return 1;
    }
  } else if (ns4)
  {
    w_str = "document." + lId;ob[lId] = eval(w_str);
    if (!ob[lId]) ob[lId] = _FindObj(document, lId);
    if (ob[lId] && (ob[lId].visibility == "show" && ob[lId].display == "")) {
    	return 1;
    }
  } else if (ie4)
  {
    w_str = "document.all.item(\"" + lId + "\").style";ob[lId] = eval(w_str);
    
    if (ob[lId].visibility == "visible" && ob[lId].display == "") {
    	return 1;
    }
  }
  return 0;
}

function _GetObject(lId, targetframe)
{
  var ob;ob=new Array;
  if (W3C) {
    ob[lId] = eval(targetframe).document.getElementById(lId);
  } else if (ns4) {
    w_str = targetframe + ".document." + lId;
    ob[lId] = eval(w_str);
    if (!ob[lId]) ob[lId] = _FindObj(eval(targetframe + ".document"), lId);
  } else if (ie4) {
    w_str = targetframe + ".document.all.item(\"" + lId + "\")";
    ob[lId] = eval(w_str);
  }
  return ob[lId];
}

function _ShowObjAt(lId, targetframe, atX, atY)
{
  var ob;ob=new Array;
  if (W3C)
  {
    ob[lId] = eval(targetframe).document.getElementById(lId).style;	//getAttribute('style');

    if (ob[lId]) {
        ob[lId].left = atX+"px";
        ob[lId].top = atY+"px";
        ob[lId].visibility = "visible";
        ob[lId].display = "";
    }
  } else if (ns4)
  {
    w_str = targetframe + ".document." + lId;ob[lId] = eval(w_str);
    if (!ob[lId]) ob[lId] = _FindObj(document, lId);
    if (ob[lId]) {
        ob[lId].top = atY;
        ob[lId].left = atX;
        ob[lId].visibility = "show";
        ob[lId].display = "";
    }
  } else if (ie4)
  {
    w_str = targetframe + ".document.all.item(\"" + lId + "\").style";

    ob[lId] = eval(w_str);
    ob[lId].top = atY;
    ob[lId].left = atX;
    ob[lId].visibility = "visible";
    ob[lId].display = "";
  }
}

function _ShowObjAtCursor(lId, targetframe, shiftX, shiftY)
{
  var ob;ob=new Array;
  var w_width;w_width = _GetWindowWidth(eval(targetframe));
  var ob_width;
  var delta;

  if (W3C)
  {
    ob[lId] = eval(targetframe).document.getElementById(lId).style; //getAttribute('style');

    if (ob[lId]) {
        ob_width = _GetObjWidth(ob[lId]);
	delta = ((mLeft + ob_width > w_width) ? (mLeft + ob_width - w_width) : 0);
        ob[lId].left = mLeft - delta + shiftX+"px";
        ob[lId].top = mTop + shiftY+"px";
        ob[lId].visibility = "visible";
        ob[lId].display = "";
    }
  } else if (ns4)
  {
    w_str = targetframe + ".document." + lId;
    ob[lId] = eval(w_str);

    if (!ob[lId]) ob[lId] = _FindObj(document, lId);
    if (ob[lId]) {
        ob_width = _GetObjWidth(ob[lId]);
	delta = ((mLeft + ob_width > w_width) ? (mLeft + ob_width - w_width) : 0);
        ob[lId].left = mLeft - delta + shiftX;
        ob[lId].top = mTop + shiftY;
        ob[lId].visibility = "show";
        ob[lId].display = "";
    }
  } else if (ie4)
  {
    w_str = targetframe + ".document.all.item(\"" + lId + "\").style";

    ob[lId] = eval(w_str);
    if (ob[lId]) {
        ob_width = _GetObjWidth(ob[lId]);
	delta = ((mLeft + ob_width > w_width) ? (mLeft + ob_width - w_width) : 0);
        ob[lId].left = mLeft - delta + shiftX;
        ob[lId].top = mTop + shiftY;
        ob[lId].visibility = "visible";
        ob[lId].display = "";
    }
  }

}

function _FindObj(doc, lId)
{
  for (var i=0; i < doc.layers.length; i++)
  {
    var w_str = "doc.layers[i].document." + lId;
    var obj;obj=new Array;
    obj[lId] = eval(w_str);
    if (!obj[lId]) obj[lId] = _FindObj(doc.layers[i], lId);
    if (obj[lId]) return obj[lId];
  }
  return null;
}

function _GetLeft(daObj){
        var returnVal;
        // set left if auto-calculated (left=0) or if not specified in-line/with style sheet
        if(W3C){
            if(typeof(daObj.style.left)=='undefined' || daObj.style.left==''){
				if (daObj.currentStyle)
					daObj.style.left = daObj.currentStyle['left']+"px";
				else
					daObj.style.left = document.defaultView.getComputedStyle(daObj, '').getPropertyValue('left')+"px";
            }
            returnVal = parseInt(daObj.style.left);
        }
        else if(ns4){ returnVal = daObj.left; } // daObj.pageY if undef
        else{ returnVal = daObj.style.pixelLeft; } // daObj.offsetLeft if undef
        return returnVal;
}

function _SetLeft(daObj, newLeft){
        if (W3C) { daObj.style.left = newLeft + 'px'; }
        else if (ns4) { daObj.left = newLeft; }
        else { daObj.style.pixelLeft = newLeft; }
}

function _GetTop(daObj){
        var returnVal;
        if(W3C){
            if(typeof(daObj.style.top)=='undefined' || daObj.style.top=='') {
				if (daObj.currentStyle)
					daObj.style.top = daObj.currentStyle['top'];
				else
					daObj.style.top = document.defaultView.getComputedStyle(daObj, '').getPropertyValue('top');
            }
            returnVal = parseInt(daObj.style.top);
        }
        else if(ns4){ returnVal = daObj.top; } // daObj.pageX if undef
        else{ returnVal = daObj.style.pixelTop; } // daObj.offsetTop if undef
        return returnVal;
}

function _SetTop(daObj, newTop){
        if(W3C){ daObj.style.top = newTop + 'px'; }
        else if(ns4){ daObj.top = newTop; }
        else{ daObj.style.pixelTop = newTop; }
}

function _GetObjHeight(daObj){
	var returnVal;

	if(W3C) {
		if(typeof(daObj.height) == 'undefined' || daObj.height=='') {
			if (daObj.currentStyle)
				daObj.height = daObj.currentStyle['height'];
			else
				daObj.height = document.defaultView.getComputedStyle(daObj, '').getPropertyValue('height');
		}
		returnVal = parseInt(daObj.height);
        } else if (ie4) {
		if (typeof(daObj.pixelHeight) == 'undefined') {
			if (typeof(daObj.clientHeight) == 'undefined') {
				returnVal = daObj.offsetHeight;
			} else {
				returnVal = daObj.clientHeight;
			}
		} else {
			returnVal = daObj.pixelHeight;
		}
        } else {
		returnVal = daObj.clip.height;
	}

    return returnVal;
}

function _GetObjWidth(daObj) {
        var returnVal;

        if (W3C) {
                if (typeof(daObj.width) == 'undefined' || daObj.width==''){
                	if (daObj.currentStyle)
	                	daObj.width = daObj.currentStyle['width'];
	                else
                        daObj.width = document.defaultView.getComputedStyle(daObj, '').getPropertyValue('width');
                }
                returnVal = parseInt(daObj.width);
        } else if (ie4) {
		if (typeof(daObj.pixelWidth) == 'undefined') {
			if (typeof(daObj.clientWidth) == 'undefined') {
				returnVal = daObj.offsetWidth;
			} else {
				returnVal = daObj.clientWidth;
			}
		} else {
			returnVal = daObj.pixelWidth;
		}
        } else {
		returnVal = daObj.clip.width;
	}

        return returnVal;
}
function _GetHTML(id_element) {
	if (W3C) {
		if (document.getElementById(id_element) == null)
			return '';
		return document.getElementById(id_element).innerHTML;
	} else if (ie4) {
		if (document.all[id_element] == null)
			return '';
		return document.all[id_element].innerHTML;
	} else {
		return '';
	}
}
function _FillElement(id_element, content, addToTarget) {
	if (isEmpty(id_element))
		return;
	if (W3C) {
		if (document.getElementById(id_element) == null)
			return;
		if (addToTarget)
			document.getElementById(id_element).innerHTML += content;
		else
			document.getElementById(id_element).innerHTML = content;
	} else if (ie4) {
		if (document.all[id_element] == null)
			return;
		if (addToTarget)
			document.all[id_element].innerHTML += content;
		else
			document.all[id_element].innerHTML = content;
	} else if (ns4 && document.layers[id_element] != null) with (document.layers[id_element].document) {
		// addToTarget is not supported
		write(content);
		close();
	} else {
		return;
	}
	 _ShowObj(id_element);
}
function getFooterText() {
	// Footer Javascript Include
	var txt = '';
	txt += '<TABLE width="99%" border="0" cellspacing="2" cellpadding="0" style="margin: 0px; padding: 0px">';
	txt += '<TBODY><TR><TD height="1" align="center" bgcolor="#000066" class="text"	colspan="3"><IMG src="/images/spacer.gif" height="1"></TD></TR>';
	txt += '<TR><TD height="20" align="left"><FONT size="1" face="arial">Copyright &copy; 2002-2007<BR>Contship Italia S.p.A., All rights reserved.</FONT></TD>';
	txt += '<TD height="20" align="left"><FONT size="1" face="arial">Registered Office: 16121 - Genova, Via Malta 2/9<BR>P.IVA:&nbsp;02960210108</FONT></TD>';
	txt += '<TD height="20" align="right" valign="top"><FONT size="1" face="arial"><A href="/privacy/privacy.html" target="_self"><FONT color="#000000"><U>Terms of Service and Privacy Policy</U></FONT></A>.</FONT></TD></TR></TBODY></TABLE>';
	return txt;
}
function _Help(ctx, msg) {
	var help = '';

	if (!ctx) ctx = 'Help Context';
	if (!msg) msg = 'Help Message';
	if (msg == 'null') msg = 'N/A';

	help = '<TABLE border="0" bgcolor="#FFFFFF" cellpadding="3" cellspacing="1" width="100%"><TBODY>' +
		'<TR><TD rowspan="2" align="center" valign="top" bgcolor="#CFD1DA" width="18"><IMG src="/images/info.gif"></TD>' +
		'<TD bgcolor="#323A68" align="left" valign="top"><FONT color="#FFFFFF" size="1" face="Arial">&nbsp;' + ctx + '&nbsp;</FONT></TD></TR>' + 
		'<TR><TD bgcolor="#e1e2e8"><FONT color="#000099" size="1" face="Arial">' + msg + '</FONT></TD></TR></TBODY></TABLE>';

	if (W3C) {
		document.getElementById('HelpContext').setAttribute('innerHTML', help);
	} else if (ie4) {
		document.all.HelpContext.innerHTML = help;
	} else if (ns4) with (document.layers['HelpContext'].document) {
		write(help);
		close();
	}

	 _ShowObjAtCursor('HelpContext', 'this', -5, -5);
}

function _HelpNoImage(ctx, msg) {
	var help = '';

	if (!ctx) ctx = 'Help Context';
	if (!msg) msg = 'Help Message';
	if (msg == 'null') msg = 'N/A';

	help = '<TABLE border="0" bgcolor="#FFFFFF" cellpadding="3" cellspacing="1" width="100%"><TBODY>' +
		'<TR><TD bgcolor="#323A68" align="left" valign="top"><FONT color="#FFFFFF" size="1" face="Arial">&nbsp;' + ctx + '&nbsp;</FONT></TD></TR>' + 
		'<TR><TD bgcolor="#e1e2e8"><FONT color="#000099" size="1" face="Arial">' + msg + '</FONT></TD></TR></TBODY></TABLE>';

	if (W3C) {
		document.getElementById('HelpContext').setAttribute('innerHTML', help);
	} else if (ie4) {
		document.all.HelpContext.innerHTML = help;
	} else if (ns4) with (document.layers['HelpContext'].document) {
		write(help);
		close();
	}

	 _ShowObjAtCursor('HelpContext', 'this', -5, -5);
}

function enableMouseCoordinates(enable) {
	if (enable == 1) {
		if (ns4)
			document.captureEvents(Event.MOUSEMOVE);

		document.onmousemove = _SetMouseCoordinate;
	} else {
		if (ns4)
			document.releaseEvents(Event.MOUSEMOVE);

		document.onmousemove = null;
	}
}

//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
// 08/03/2004 - Updated by Roberto Cisternino
//*****************************************************************************

// Global object to hold drag information.
var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {
  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (ie4)
      dragObj.elNode = window.event.srcElement;
    else
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (ie4) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  } else {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (ie4) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  } else {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (ie4) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  } else {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (ie4) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  } else {
    event.preventDefault();
  }
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (ie4) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  } else {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

function evalObj(id) {
  var obj;
  var _begin;
  var _end;
  if (ie4) {
    _begin = "";
    _end = ".style";
  }
  else {
    _begin = "document.";
    _end = "";
  }
  return eval(_begin + id + _end);
}

/* DHTML and iFrame Choice based on multicolumn tables
 * Author: Roberto Cisternino
 */
var cell;	// Selected Cell
var choice;	// Active Choice object

function setCell(value) {
	cell.value = value;
	cell.style.backgroundColor = '#e1e2e8';
	_HideObj(choice);
	choice = null;
}
function setPCell(value) {
	parent.setCell(value);
}
function _undoChoice() {
	cell.style.backgroundColor = '#e1e2e8';
	_HideObj(choice);
	choice = null;
}
function _iChoice(svc, cellObj) {
	document.getElementById('dataFrame').setAttribute('src', '/empty.html');
	_Choice('intFrame', cellObj);
	document.getElementById('dataFrame').setAttribute('src', svc);
}
function _Choice(id, cellObj) {
	var minX, minY;
	var x, y;

  	if (choice)
		return;
	cell = cellObj;
	cell.style.backgroundColor = 'lightyellow';
	choice = id;
	
	if (ie4) {
		minX = document.documentElement.scrollLeft + document.body.scrollLeft;
		minY = document.documentElement.scrollTop + document.body.scrollTop;
		x = Math.max(minX, window.event.clientX + minX - 150);
		y = Math.max(minY, window.event.clientY + minY - document.getElementById(id).getAttribute('scrollHeight'));
	} else {
		minX = window.scrollX;
		minY = window.scrollY;
		x = Math.min(minX, event.clientX + minX - 150);
		y = Math.max(minY, event.clientY + minY - document.getElementById(id).getAttribute('scrollHeight'));
	}

	_ShowObjAt(id, 'this', x, y);
}
function getStyleObject(x){
if(x.currentStyle)
    return(x.currentStyle);
if(document.defaultView.getComputedStyle)
    return(document.defaultView.getComputedStyle(x,''));
return(null);
}
function getStyleProp(x,prop){
if(x.currentStyle)
    return(x.currentStyle[prop]);
if(document.defaultView.getComputedStyle)
    return(document.defaultView.getComputedStyle(x,'')[prop]);
return(null);
} 
function contextBack() {
	if (ctxBack) {
		self.location.href=ctxBack;
	} else {
		history.go(-1);
	}
}
/**************************************************************************
* Name    : ArraySearch
* Purpose : Searches an array for a specified value by traversing array.
* Input   : Value to be searched.
* Output  : Index number of the value found. -1 if value is not found.
***************************************************************************/
function ArraySearch(vArray, vValue)
{
	for (var kCnt=0;kCnt < vArray.length;kCnt++)
		if (vArray[kCnt] == vValue)
		{
			// This is just for statistics, can be removed.
			iLoopCount = kCnt + 1;
			return kCnt;
		}
	
	// This is just for statistics, can be removed.
	iLoopCount = kCnt;
	return -1;
}
/**************************************************************************
* End Of Function
**************************************************************************/

/**************************************************************************
* Name    : FastArraySearch
* Purpose : Searches an array for a specified value using shortest path.
*		    It can be used for char string as well as number searches also.
*           But the array to be searched must be sorted in asc/desc order.
* Input   : Value to be searched. The array should be sorted alphabetically
* Output  : Index number of the value found. -1 if value is not found.
***************************************************************************/
function FastArraySearch(vArray, vValue)
{
	var iStartIndex, iEndIndex, iMiddleIndex;

	iStartIndex = 0;
	iMiddleIndex = -1;
	iEndIndex = vArray.length - 1;		
		
	while (true)
	{		
		iMiddleIndex = iStartIndex + Math.ceil((iEndIndex - iStartIndex) / 2);
		
		switch(vValue)
		{
		case vArray[iStartIndex]: return iStartIndex;
		case vArray[iMiddleIndex]: return iMiddleIndex;
		case vArray[iEndIndex]: return iEndIndex;
		}	
		
		if (iStartIndex == iMiddleIndex || iEndIndex == iMiddleIndex) return -1;
		
		if (vValue > vArray[iMiddleIndex])
		{
			iStartIndex = iMiddleIndex + 1;
		}
		else if (vValue < vArray[iMiddleIndex])
		{
			iEndIndex = iMiddleIndex - 1;
		}
		
		// This is just for statistics, can be removed.
		iLoopCount++;
	}
	return -1;
}
function getReqParam2(p, d) {
var query = document.location.search;
var i1 = query.indexOf(p + '=');
var i2 = -1;
var res = d;
if (i1 != -1) {
	i1 += p.length + 1;
	i2 = query.indexOf('&', i1);
	if (i2 != -1)
		res = query.substring(i1, i2);
	else
		res = query.substring(i1);
}
return res;
}
function getReqParam(p) {
return (p, 'unknown');
}
function endsWith(s1, s2) {
return s1.substring(s1.length - s2.length)==s2;
}
function getXMLHttpRequest() {
    var xmlReq = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        xmlReq = new XMLHttpRequest();

        if (xmlReq.overrideMimeType) {
            xmlReq.overrideMimeType('text/xml;charset=UTF-8');
        }
    } else if (window.ActiveXObject) { // IE
        try {
        	// 5.5 or previous
            xmlReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            	// 5.5 or later
                xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                xmlReq = false;
            }
        }
    } else if (window.createRequest) {	// IceBrowser
        try {
            xmlReq = window.createRequest();
        } catch (e) {
            xmlReq = false;
        }
    }

	if (!xmlReq) {
		alert("ERROR: Your browser do not support AJAX or Javascript technology is not fully enabled\nplease contact your technical support !");
	}
	return xmlReq;
}
function isEmpty(v) {
	return typeof(v) == 'undefined' || v == null;
}
function execXMLHttpAction(xmlReq, url, act, async, fn, postData) {
	if (xmlReq) {
        xmlReq.open(act, url, async);
        if (act == 'POST' && !isEmpty(postData)) {
        	xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlReq.setRequestHeader('Content-length', postData.length);
			xmlReq.setRequestHeader('Connection', 'close');
	    }
        xmlReq.onreadystatechange = fn;
        if (isEmpty(postData))
	        xmlReq.send(null);
		else
			xmlReq.send(postData);
        if (!async && window.XMLHttpRequest && typeof(fn) != 'undefined') // Mozilla, Safari,...
			fn();
    }
}
function checkURLExistance(url) {
	return checkURLExistance(url, null, null);
}
// An URL existence is tested using Ajax, however in case a browser is not ajax compliant this test will be always true.
function checkURLExistance(url, redUrl, redFrame) {
    var xmlReq = getXMLHttpRequest();

	execXMLHttpAction(xmlReq, url, 'HEAD', false, function() {
		return checkURLCallback(xmlReq, url, redUrl, redFrame);
    });
    return (xmlReq && xmlReq.status==200 ? true : (xmlReq ? false : true));
}
function checkURLCallback(xmlReq, url, redUrl, redFrame) {
	if (xmlReq.readyState==4) {
		if (xmlReq.status==200) {
			return true;
	    } else if (xmlReq.status==404 || xmlReq.status==500) {
	    	if (redUrl)
		    	redFrame.document.location.href=redUrl;
			return false;
	    } else {
	    	alert('Unable to reach ' + url + '\n\n' + xmlReq.statusText + ' (' + xmlReq.status + ')');
	    	if (redUrl)
				redFrame.document.location.href=redUrl;
			return false;
		}
    }
    return false;
}
// Send asynchronously a form query using AJAX
function postFormData(url, target, formData, linkUserFunction, retry) {
    var xmlReq = getXMLHttpRequest();

	for (var ri = 0; ri < 3; ri++) {
		try {
			execXMLHttpAction(xmlReq, url, 'POST', true, function() {
				return getPostFormDataCallback(xmlReq, url, target, linkUserFunction);
	    	}, formData);
	    	break;
	    } catch (err) {
	    	if (err.message.substring(0, 13)!='#Error#Retry#')
	    		alert(err.message);
	    }
	}
}
// Retrieve asynchronously an URL content using AJAX
function getURLData(url, target, userFunction, userMethod, addToTarget) {
    var xmlReq = getXMLHttpRequest();
//	alert(url);
	execXMLHttpAction(xmlReq, url, 'GET', true, function() {
		return getURLCallback(xmlReq, url, target, userFunction, userMethod, addToTarget);
    });
}
// A User Callback can be used (as a function or class)
function getURLCallback(xmlReq, url, target, userCallback, userMethod, addToTarget) {
	if (xmlReq.readyState==4) {
		if (xmlReq.status==200) {
			if (target != null) {
				_FillElement(target, xmlReq.responseText, addToTarget);
				
				if (userCallback) {
					/**
					 * The user Callback function is a JS function/class generated by this 
					 * asynchronous process which is required to be available on the final page.
					 * The function is automatically linked to the page for subsequent use (moved to head).
					 * JS functions generated after page is loaded are not reachable until these are moded on the page head.
					 */				
					linkJSFunction(document, userCallback);

					try {			
						if (userMethod) {
							eval('var userObj = new ' + userCallback + '();');
							eval('userObj.' + userMethod + '()');
						}
						else
							eval(userCallback + '()');
					}
					catch(err) {
//						alert('AJAX Runtime Error\n\n' + userCallback + ' has not been generated successfully\n\n' + err.message);
						return false;
					}
				}
			}
			return true;
	    } else if (xmlReq.status==404 || xmlReq.status==500) {
	    	alert('AJAX Runtime Error\n\n' + xmlReq.statusText + '(' + xmlReq.status + ')');
//			_FillElement(target, 'AJAX Error:<BR>' + xmlReq.statusText + '(' + xmlReq.status + ')');
			return false;
	    } else {
	    	alert('Unable to reach ' + url + '\n\n' + xmlReq.statusText + '(' + xmlReq.status + ')');
			return false;
		}
    }
    return false;
}
function getPostFormDataCallback(xmlReq, url, target, linkUserCallback) {
	if (xmlReq.readyState==4) {
		if (xmlReq.status==200) {
			if (target != null) {
//			alert(xmlReq.responseText);
				if (!isEmpty(xmlReq.responseText) && xmlReq.responseText.length > 7 && Trim(xmlReq.responseText).substring(0, 7)=='#Error#')
					_FillElement('errors', Trim(xmlReq.responseText).substring(7));
				_FillElement(target, xmlReq.responseText);
//				if (linkUserCallback) {
					/**
					 * When the User Callback function is generated during this 
					 * asynchronous request it is automatically linked to the page (moved to head)
					 */
//					linkJSFunction(document, 'userPostAJAX');
//					userPostAJAX();
//				}
			}
			return true;
	    } else if (xmlReq.status==404 || xmlReq.status==500) {
	    	alert('AJAX Runtime Error\n\n' + xmlReq.statusText + ' (' + xmlReq.status + ')');
//			_FillElement(target, 'AJAX Error:<BR>' + xmlReq.statusText + '(' + xmlReq.status + ')');
			return false;
/*
   12029       ERROR_INTERNET_CANNOT_CONNECT
               The attempt to connect to the server failed.
   12030       ERROR_INTERNET_CONNECTION_ABORTED
               The connection with the server has been terminated.
   12031       ERROR_INTERNET_CONNECTION_RESET
               The connection with the server has been reset.
*/
	    } else if (xmlReq.status==12029 || xmlReq.status==12030 || xmlReq.status==12031) {
    		throw('#Error#Retry#Unable to reach ' + url + '\n\n' + xmlReq.statusText + ' (' + xmlReq.status + ')');
	    } else {
	    	alert('Unable to reach ' + url + '\n\n' + xmlReq.statusText + ' (' + xmlReq.status + ')');
			return false;
		}
    }
    return false;
}
function checkCSIPortalService(url) {
	return checkURLExistance(url, '/viewer.html?doc=/serviceUnavailable.html&ctx=/services/services&title=Support', top.mainFrame);
}
// This function moves generated scripts with a given function/class name to the page head.
function linkJSFunction(node, fname)
{
  var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
  var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
  var bMoz = (navigator.appName == 'Netscape');
  var sClass = 'function ' + fname;		// matches a function or class name
  var test;
  
  if (!node)
  	return;
  
  try {
  	test = eval(fname);
  } catch (e) {	// If function is undefined the following code tries to find it and link it.
  /* IE wants it uppercase */
  var st = node.getElementsByTagName('SCRIPT');
  var strExec = '';

  for(var i=0;i<st.length; i++)
  {
    if (bSaf) {
      strExec += st[i].innerHTML;     
      if (strExec.indexOf(sClass)!=-1) {
	      st[i].innerHTML = "";
	      break;
	  }
    } else if (bOpera) {
      strExec += st[i].text;
      if (strExec.indexOf(sClass)!=-1) {
	      st[i].text = "";
	      break;
	  }
    } else if (bMoz) {
      strExec += st[i].textContent;
      if (strExec.indexOf(sClass)!=-1) {
	      st[i].textContent = "";
	      break;
	  }
    } else {
      strExec += st[i].text;
      if (strExec.indexOf(sClass)!=-1) {
	      st[i].text = "";
	      break;
	  }
    }
//    alert(strExec);
  }

  try {
      var newScript = document.createElement("script");
      newScript.type = "text/javascript";

      /* In IE we must use .text! */
      if ((bSaf) || (bOpera) || (bMoz))
        newScript.innerHTML = strExec;
      else newScript.text = strExec;

      if (document.getElementsByTagName("head")[0])
        document.getElementsByTagName("head")[0].appendChild(newScript);
  } catch(e) {
      alert(e);
  }
  }
}
function getRandom(max) {
	var rand = Math.floor(Math.random() * max);
    return rand;
}
// An onLoad trigger that could be enabled by defining the init() method into the embedded page
function doOnLoad() {
	// Load footer include
	_FillElement('footer', getFooterText());

	// Load a user initialization function init() when available
	if (typeof(init) != "undefined") {
		init();
	}
}
//enableMouseCoordinates(1);
