var userErrorRoutine
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false


function getObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId);
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId);
	} else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId];
	} else {
		return false;
	}
}

function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId];
	} else {
		return false;
	}
} // getStyleObject

function expand(element,ulId) {
	var styleObject = getStyleObject(ulId);
	var object = getObject(ulId);
	if(styleObject) {
		if(styleObject.display == "block") {
			styleObject.display = "none";
		}else{
			styleObject.display = "block";
		}
		return true;
	} else {
		return false;
	}
}

//=================================================================================================
// Verify that the passed value is numeric
function isNumeric ( inputValue ) {
	oneDecimal = false
	inputStr = inputValue.toString()
	for ( var i = 0 ; i < inputStr.length ; i++ ) {
		var oneChar = inputStr.charAt(i)
		if ( i == 0 && oneChar == '-' )
		{
			continue
		}
		if ( oneChar < '0' || oneChar > '9' ) {
			return false
		}
	}
	return true
}
//=================================================================================================
// Verify that the passed field contains data
function isEmpty ( inputValue ) {

	if ( inputValue == null || inputValue == '' )  {
		return true
	}
		return false
}
//=================================================================================================
// Verify that the value in the passed input field is numeric. Remove it automatically if it isnt
function vaValidateNumeric ( inputField ) {
	if ( !(isEmpty ( inputField.value ))) {
		if ( isNumeric ( inputField.value )) {
			return true } }
	if ( !(isEmpty ( inputField.value ))) {
		var temp = inputField.value;
        inputField.value = temp.substring(0,temp.length-1);
		inputField.focus();
		return false
	}
	return false
}
//=================================================================================================
// Display the error using the 'alert' method or execute a userErrorRoutine if
// available
function vaReportError ( errorString ) {
	if ( userErrorRoutine != null ) {
		eval ( userErrorRoutine )
	}
	else {
		alert ( errorString ) }
	}
//=================================================================================================
// Verify that the user input is a value between min and max
function vaValidateNumericRange ( inputField, min, max ) {
	var lowNum , highNum
	if ( vaValidateNumeric ( inputField ) ) {
		lowNum = parseFloat ( min )
		highNum = parseFloat ( max )
		if ( vaValidateRange ( inputField , lowNum, highNum )) {
			return true }
		// clear the field coz of netscape bugs
		if (ns4) inputField.value = ""
		inputField.focus()
		inputField.select()
		return false
	} return false
	}
//=================================================================================================
// Verify that the user input is a value between min and max and not null
function vaValidateNumericRangeRequired ( inputField, min, max)
{
	var lowNum , highNum
	if (isEmpty ( inputField.value ))
	{
		vaReportError ( 'Field CANNOT be blank. Please Enter a number into the field' )
		inputField.focus()
		inputField.select()
		return false

	}
	if ( vaValidateNumeric ( inputField ) )
	{
		lowNum = parseFloat ( min )
		highNum = parseFloat ( max )
		if ( vaValidateRange ( inputField , lowNum, highNum ))
		{
			return true
		}
		// clear the field coz of netscape bugs
		if (ns4) inputField.value = ""
		inputField.focus()
		inputField.select()
		return false
	}
	return false;
}
//=================================================================================================
// Return true if value falls between min and max
function vaValidateRange ( inputField , min , max )
{
	if ( vaValidateMin ( inputField , min ))
	{
		if ( vaValidateMax ( inputField , max ))
		{
			return true
		}
	}
	if (ns4) inputField.value = ""
	inputField.focus()
	inputField.select()
	return false
}
//=================================================================================================
function vaValidateRange2( inputField , min , max ) {
  if ( !(isEmpty(inputField.value)) && isNumeric(inputField.value)) {
    if ( vaValidateMin(inputField,min) && vaValidateMax(inputField,max) ){
      return true ;
    }
    document.getElementById(inputField.name).focus();
    document.getElementById(inputField.name).select();
  }
  return false;
}
//=================================================================================================
// Verify that the passed value is greater than min
function vaValidateMin ( inputField , min ) {
	if ( inputField.value >= min ) {
		return true }

	if (document.getElementById(inputField.name)==null){
    	document.getElementById(inputField.id).value="";
		document.getElementById(inputField.id).focus();
	}else{
    	document.getElementById(inputField.name).value="";
		document.getElementById(inputField.name).focus();
	}

	vaReportError ( 'Please enter a value greater than or equal to ' + min )
	return false
}
//=================================================================================================
// Verify that the passed value is less than max
function vaValidateMax ( inputField , max ) {
	if ( inputField.value <= max ) {
		return true }

      document.getElementById(inputField.name).value="";
	document.getElementById(inputField.name).focus();
	vaReportError ( 'Please enter a value less than or equal to ' + max )
	return false }
//=================================================================================================
// Convert the text in the passed field to upper case and replace its 'value'
// with the upper cased string
function vaConvertToUpperCase ( inputField ) {
	if ( !(isEmpty (inputField.value ))) {
		inputField.value = inputField.value.toUpperCase() } }
//=================================================================================================
// Convert the text in the passed field to lower case and replace its 'value'
// with the lower cased string
function vaConvertToLowerCase ( inputField ) {
	if ( !(isEmpty (inputField.value ))) {
		inputField.value = inputField.value.toLowerCase() } }
//=================================================================================================
// Verify that the user has entered at least minChars
function vaValidateMinChars ( inputField , minChars ) {
	if ( inputField.value.length >= minChars ) {
		return true }
	vaReportError ( 'Please enter at least ' + minChars + ' characters into this field.' )
	inputField.focus()
	inputField.select()
	return false
}
//=================================================================================================
function isDecimalField ( inputValue )
{
	oneDecimal = false;
	inputStr = inputValue.toString()
	for ( var i = 0 ; i < inputStr.length ; i++ )
	{
		var oneChar = inputStr.charAt(i)
		if ( i == 0 && oneChar == '-' ) continue
		if ( oneChar == '.' && !oneDecimal )
		{
			oneDecimal = true;
			continue
		}
		if ( oneChar < '0' || oneChar > '9' ) return false
	}
	return true;
}
//=================================================================================================
function isCurrencyField ( inputValue )
{
	oneDollar = false;
	oneDecimal = false;

	inputStr = inputValue.toString()
	for ( var i = 0 ; i < inputStr.length ; i++ )
	{
		var oneChar = inputStr.charAt(i)
		if (oneChar == ',' ) continue
		if ( i == 0 && oneChar == '-' ) continue
		if ( oneChar == '.' && !oneDecimal )
		{
			oneDecimal = true;
			continue
		}
		else if ( oneChar == '$' && !oneDollar )
		{
			oneDollar = true
			continue
		}
		if ( oneChar < '0' || oneChar > '9' ) return false
	}
	return true;
}
//=================================================================================================
function _formatCurrencyField ( inputFld )
{
	negative=false;
	// carry on
	num = inputFld.value;
	if (num.charAt(0) == "-")  negative = true;			// check it negative number
	num = num.toString().replace(/\$|\,/g,'');			//
	if(isNaN(num)) num = "0";
	abs_num = Math.abs(num);						// use absolute value to cater for negatives
	cents = Math.floor((abs_num* 100 + 0.5) % 100);			// retrieve the cents
	num = Math.floor((abs_num * 100+ 0.5) / 100).toString();	// retrieve dollars

	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));
	if (negative)inputFld.value = "-$" + num + '.' + cents;	// neg
	if (!negative)inputFld.value = "$" + num + '.' + cents;	// pos
	return true;
}
//=================================================================================================
function validateFormatCurrency(inputFld)
{
	if ( !(isEmpty ( inputFld.value )))
	{
		// check if currency first
		if (!isCurrencyField(inputFld.value))
		{
			vaReportError ( 'Please enter a VALID currency value into this field \n eg $###.## or ### or ###.##' )
			// clear the field coz of netscape bugs
			if (ns4) inputFld.value = "";
			inputFld.focus();
			inputFld.select();
			return false;
		}
		_formatCurrencyField ( inputFld ) // format the field

	}
	return true;
}
//=================================================================================================
function validateCurrencyRange(inputFld, min, max)
{
	negative = false;
	if ( !(isEmpty ( inputFld.value )))
	{
		// check if currency first
		if (!isCurrencyField(inputFld.value))
		{
			vaReportError ( 'Please enter a VALID currency value into this field \n eg $###.## or ### or ###.##' )
			// clear the field coz of netscape bugs
			if (ns4) inputFld.value = "";
			inputFld.focus();
			inputFld.select();
			return false;
		}
		// now check the ranges
		var num = 0.00;
		var lowNum = 0.00;
		var highNum = 0.00;
		input_num = inputFld.value;
		input_num = input_num.toString().replace(/\$|\,/g,'');			// remove all formatting
		num = parseFloat ( input_num )		// input
		lowNum = parseFloat ( min )		// low range
		highNum = parseFloat ( max )		// higher range
		if (num < lowNum )
		{
			vaReportError ( 'Please enter a VALID currency value greater than or equal to ' + min )
			// clear the field coz of netscape bugs
			if (ns4) inputFld.value = "";
			inputFld.focus();
			inputFld.select();
			return false;
		}
		if (num > highNum )
		{
			vaReportError ( 'Please enter a VALID currency value less than or equal to ' + max )
			// clear the field coz of netscape bugs
			if (ns4) inputFld.value = "";
			inputFld.focus();
			inputFld.select();
			return false;
		}
		// all is cool, carry on
		_formatCurrencyField ( inputFld ) // format the field

	}
	return true;
}

//=================================================================================================
function trim(str) {
   retval = str.replace(/^\s*/, '').replace(/\s*$/, '');

   return retval;
}

//=================================================================================================
function checkrequired(which)
{
// "REQUEST_SUBMITTED" IS A GLOBAL VARIABLE SETUP IN THE SERVLET
var pass=true;
var submitted=false;
var radio_check_pass=true; // used for radio / checkboxes
if (document.images){
	var formname = which.name;
	// we will check if there is only only submit happening for each form. Some forms like the quick search on the logo don't refresh
	// so we will skip this check if no formname provided
	if (!(isEmpty ( formname)))	submitted = REQUEST_SUBMITTED
	if (submitted){
		alert ('Processing your previous Request. Please Wait...');
		return false;
	}else{
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i];
			var objectname = tempobj.name;
			if (objectname.substring(0,8)=="required" || objectname.substring(0,10)=="O_required"){	// test field, testarea, file
				if ((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file" ) && (trim(tempobj.value)=='')){
					pass=false;
					break;
	      	      }
				if ( tempobj.type.toString().charAt(0)=="s" ){ // select box
				    //var val = ;
				    if ( tempobj.options.length > 1 && tempobj.options[1].value=="" && tempobj.selectedIndex < 2){
							pass=false;
							break;
						}
		    }

				if (tempobj.type=="checkbox"||tempobj.type=="radio"){
					var obj_length = eval("document." + formname + "." + objectname + ".length");
					radio_check_pass = false;
					for (x=0;x< obj_length;x++){
						var obj_checked = eval("document." + formname + "." + objectname + "[" + x + "].checked");
						if (obj_checked){
							radio_check_pass=true;
							break;
						}
					}
					if (!radio_check_pass){
						pass=false;
						break;
					}
				}
			}
		}
	}
}
if (!pass){
	if (tempobj.id && tempobj.id!=""){
		alert("Please make sure the "+tempobj.id+" field was properly completed.");
	}else{
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
		if (shortFieldName.substring(0,4)=="FLD_")
			shortFieldName = shortFieldName.substring(4,shortFieldName.length);
		alert("Please make sure the "+shortFieldName+" field was properly completed.");
	}
	tempobj.focus();
	return false;
}
else
	if (!(isEmpty ( formname))) REQUEST_SUBMITTED = true;
	return true;
}

//=================================================================================================
function checkRequiredArray(arr){
	var pass=true;
	var submitted=false;
	var radio_check_pass=true; // used for radio / checkboxes

	if (document.images){
		//var formname = which.name;
		submitted = REQUEST_SUBMITTED
		if (submitted){
			alert ('Processing your previous Request. Please Wait...');
			return false;
		}else{
			for (i=0;i<arr.length;i++){
				var tempobj=document.getElementById(arr[i]);
				var objectname = tempobj.name;
				if ((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file" || tempobj.type=="password" ) && (trim(tempobj.value)=='')){
					pass=false;
					break;
				}

				if ( tempobj.type.toString().charAt(0)=="s" ){ // select box
					//var val = ;
					if (tempobj.value < 1){
							pass=false;
							break;
					}
				}


/*COMMENT OUT SINCE NOT USED AND NEEDS TESTING!!
				if (tempobj.type=="checkbox"|| tempobj.type=="radio"){
					var obj_length = eval("document.getElementById("++").length");
					radio_check_pass = false;
					for (x=0;x< obj_length;x++){
						var obj_checked = eval("document." + formname + "." + objectname + "[" + x + "].checked");
						if (obj_checked){
							radio_check_pass=true;
							break;
						}
					}
					if (!radio_check_pass){
						pass=false;
						break;
					}
				}
*/

			}
		}
	}

	if (!pass){
		alert("Please make sure the "+tempobj.id+" field was properly completed.");
		tempobj.focus()
		return false;
	}else{
		REQUEST_SUBMITTED = true;
		return true;
	}

}

//=================================================================================================
function setField ( inputField, data ){
	inputField.value = data
	return true
}
//=================================================================================================
// for new messages attachments
function AttachmentFocus(inputField){
	inputField.blur()
	window.alert("You cannot manually change this information.  Please Click 'Edit Attachments' to add/remove files");
	return false;
}

//=================================================================================================
// opens the attachment window
var remote=null;
function openWindow(n,u,w,h,x){
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;

	var tmp = u.substring(u.lastIndexOf("."),u.length);
	if (tmp==".doc" || tmp==".xls"){
		args="width="+w+",height="+h+",top="+wint+",left="+winl+",resizable=yes,scrollbars=yes,menubar=1,status=0";
	}else{
		args="width="+w+",height="+h+",top="+wint+",left="+winl+",resizable=yes,scrollbars=yes,status=0";
	}

  remote=window.open(u,n,args);

  if (remote != null)  {
    if (remote.opener == null)
      remote.opener = self;
  }

  if (x == 1) { return remote; }

}
//=================================================================================================
var awnd=null;
function Attachments(url){
  awnd=openWindow('Attachments',url,370,480,1);
  awnd.focus();
}
//=================================================================================================
// help window
var hwnd=null;
function openNewWindow(url, title, width, height){
  hwnd=openWindow(title,url,width, height, 1);
  hwnd.focus();
}
//=================================================================================================
//opens a standard new window with all menus etc...
function openWindow1(u, n, w, h){
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
	args="resizable=1,scrollbars=1,menubar=1,addressbar=1,toolbar=1,titlebar=1,status=1,width="+w+",height="+h+",top="+wint+",left="+winl;

	hwnd=window.open(u,n,args);
  	if (hwnd!=null) hwnd.focus();
}
//=================================================================================================
// for hiding and showing elements
function hide(id){
	if (ns4) document.layers[id].visibility = "hide"
	else if (ie4) document.all[id].style.visibility = "hidden"

	document.getElementById(id).style.visibility="hidden";
}
//=================================================================================================
function show(id){
	if (ns4) document.layers[id].visibility = "show"
	else if (ie4) document.all[id].style.visibility = "visible"

	document.getElementById(id).style.visibility="visible";
}
//
//=================================================================================================
function checkCharCount(field, maxlimit){
  if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit);
}
//=================================================================================================
function updateSpinNumber(fld, action, max, min){
	var maxValue = parseInt(max);
	var minValue = parseInt(min);
	var intValue = 0;
	fld.value=eval(fld.value+action);
	intValue = parseInt(fld.value);
	if (intValue > max) fld.value=minValue ;
	if (intValue < min) fld.value=maxValue;
	intValue = parseInt(fld.value);
	if (intValue < 10 ) fld.value = "0" + fld.value;

}
//=================================================================================================
// Verify that the value in the passed input field does not have a space in it other Issue an error
function isSpaceEmbedded ( inputValue ){
	oneDecimal = false
	inputStr = inputValue.toString()
	for ( var i = 0 ; i < inputStr.length ; i++ ){
		var oneChar = inputStr.charAt(i)
		// if in the middle of the string
		if ( oneChar == ' ' && i < inputStr.length - 1) return false
	}
	return true;
}
//=================================================================================================
function vaNoSpacesEmbedded ( inputField ){
	if (isSpaceEmbedded ( inputField.value )) return true;

	vaReportError ( 'Field CANNOT have space(s) embedded. Please remove the space(s)' )
	// clear the field coz of netscape bugs
	if (ns4) inputField.value = ""
	inputField.focus()
	inputField.select()
	return false;
}

//=================================================================================================
function switchImage(imageName,imageSrc){
 self.document.images[imageName].src=imageSrc;
}

//===========================================================================================================
function getFrameByName(name){
 for (var i=0; i < parent.frames.length; i++) {
  if(parent.frames[i].name == name){
    return parent.frames[i];
  }
 }
 return null;
}

//========================================================
function getFrame(name){
	 for (var i=0; i < top.window.frames.length; i++) {
	 	  frm = top.window.frames[i];
		  if(frm.name == name){
				return top.window.frames[i];
		  }else{
				rf= findFrame(top.window.frames[i],name);
				if (rf != null) return rf;
		  }
	 }
	 return null;
}

function findFrame(afrm,name){
	var rf = null;
	 for (var i=0; i < afrm.frames.length; i++) {
	 	  frm = afrm.frames[i];
		  if(afrm.frames[i].name == name){
				return afrm.frames[i];
		  }else{
	 			ff = findFrame(afrm.frames[i],name);
	 			if (ff != null) return ff;
		  }
	 }
	 return null;
}

//========================================================
function updateBsk(frameName, sessid, page){
	bskframe = getFrame(frameName);
//	if (bskframe.location.length > 0)
//		bskframe.location.reload();
	if (bskframe != null)
		bskframe.location='/servlet/Srv.Ecos_Process_HTML_File?CMD=BSKSTAT&AI='+sessid+'&P1='+page;
}


//========================================================
function fireUpdate(frameName, sessid){
//  var topfram = getFrameByName(frameName);

	topfram = eval(frameName);

//OLD version
//topfram.window.document.getElementById('bskUpdate').src = '/servlet/Srv.Ecos_BasketStatusUpdate?AI='+sessid;

//NEW version for IE only!!
//topfram.window.document.getElementById('bskUpdate').src = '/servlet/Srv.Ecos_Process_HTML_File?AI='+sessid+'&P1=basketstatus.htm';

//NEW version for both IE and NS
  if (topfram != null){
		var bskframe = topfram.document.getElementById('bskUpdate');
		if (bskframe != null){
			bskframe.src='';
			bskframe.src='/servlet/Srv.Ecos_Process_HTML_File?CMD=BSKSTAT&AI='+sessid+'&P1=basketstatus.htm';
		}
		var sidebskframe = parent.document.getElementById('sidebasket');
		if (sidebskframe != null){
			sidebskframe.src='';
			sidebskframe.src='/servlet/Srv.Ecos_Process_HTML_File?AI='+sessid+'&P1=sidebasket.htm';
		}
  }
}
//===========================================================================================================
function size(img,xh,xw){

  var w = img.width;
  var  h = img.height;

//alert(w +":"+h);


  var maxh = xh * 0.95;
  var maxw = xw * 0.95;

  if (w > maxw) {
    j = w/maxw;
    w = w/j;
    h = h/j;
  }
  if (h > maxh) {
    j = h/maxh;
    w = w/j;
    h = h/j;
  }

	img.width = w;
	img.height = h;
}
//===========================================================================================================
function getAspectDimensions(w, h, maxw, maxh, restrictSize) {
  if(restrictSize) {
    if(maxw > w) {
      maxw = w;
    }
    if(maxh > h) {
      maxh = h;
    }
  }

  var x1 = maxw/w;
  var x2 = maxh/h;
  if(x2 < x1) {
    x1 = x2;
  }
  w = w*x1;
  h = h*x1;

  return [Math.round(w), Math.round(h)];
}
//===================================================
function sizeBigPic(aimg,imgNm){
  var img = getObject(imgNm);
  img.src = aimg.src;

  var w = "";
  var h = "";
  if(aimg.width > img.width) {
    w = aimg.width;
    h = aimg.height;
  }
  //MACINTOSH IE 5.17 TRICK
  else{
    w = img.width;
    h = img.height;
    getObject("tablebigpic").className = "avisible";
  }

  if (navigator.appName=="Netscape") {
    xw = window.innerWidth-50;
    xh = window.innerHeight-50;
  }else{
    xh = document.body.offsetHeight-50;
    xw = document.body.offsetWidth-50;
  }

  var maxh = xh * 0.90;
  var maxw = xw * 0.90;

  var aspect = getAspectDimensions(w, h, maxw, maxh, false);

  img.width = aspect[0];
  img.height = aspect[1];

  getObject("tablebigpic").className = "avisible";
}
//===================================================
function resizeImage(imgName, newImgSrc, maxh, maxw, sessId) {

	//newImgSrc = newImgSrc + '?' + Math.round(Math.random()*1000000);
	newImgSrc = newImgSrc + '?' + sessId;

	img = document.images[imgName];
	img.src = newImgSrc;

	size(img,maxh,maxw);

	img.className='avisible';
}
//===================================================
/* IMAGE PRELOADER CODE */
function ImagePreloader(images,suffix,maxw,maxh) {

// store the callback
	this.callback = null;
	if(suffix=="bigpic"){
		this.callback = sizeBigPic;
	}else{
		this.callback = resizeNow;
	}

	this.displayTable = "table" + suffix;
	this.imgName = "img" + suffix;
	this.maxw = maxw;
	this.maxh = maxh;
	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array();
	// record the number of images.
	this.nImages = images.length;
	// for each image, call preload()
	for (var i = 0; i < images.length; i++)
		this.preload(images[i]);
}

ImagePreloader.prototype.preload = function(image) {
	// create new Image object and add to array
	var oImage = new Image;
	//this.aImages.push(oImage);
	this.aImages[this.aImages.length] = oImage;

	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;
	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;
	// assign the .src property of the Image object
	oImage.src = image;
}

ImagePreloader.prototype.onComplete = function() {
	this.nProcessed++;
	if (this.nProcessed == this.nImages ){
		if(this.callback==sizeBigPic){
			this.callback(this.aImages[0],this.imgName);
		}else{
			this.callback(this.aImages,this.displayTable,this.imgName,this.maxw,this.maxh);
		}
  }
}

ImagePreloader.prototype.onload = function() {
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onerror = function() {
	this.bError = true;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function() {
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}
/* END IMAGE PRELOADER CODE */

//===================================================
function resizeNow(aImages,displayTable,imgName,maxw,maxh) {
  var img = getObject(imgName);
  img.src = aImages[0].src;

  var w = "";
  var h = "";
  if(aImages[0].width > img.width) {
    w = aImages[0].width;
    h = aImages[0].height;
  }
  //MACINTOSH IE 5.17 TRICK
  else{
    w = img.width;
    h = img.height;
  }

  var maxw = maxw * 0.95;
  var maxh = maxh * 0.95;

  var aspect = getAspectDimensions(w, h, maxw, maxh, true);

  img.width = aspect[0];
  img.height = aspect[1];

  getObject(displayTable).className = "avisible";
}
//===================================================
function preloadImages() {
  if (document.images) {
    if (typeof(document.preload) == 'undefined'){
      document.preload = new Object();
    }
    document.preload.loadedImages = new Array();
    for(i = 0; i < preloadImages.arguments.length; i++) {
      document.preload.loadedImages[i] = new Image();
      document.preload.loadedImages[i].src = preloadImages.arguments[i];
    }
  }
}//end function preloadImages
//===================================================
function imageSwap(imgName,imgSrc){
  var objStr,obj;
  if(document.images){
    if (typeof(imgName) == 'string') {
      objStr = 'document.' + imgName;
      obj = eval(objStr);
      obj.src = imgSrc;
    } else if ((typeof(imgName) == 'object') && imgName && imgName.src) {
      imgName.src = imgSrc;
    }
  }
}//end function imageSwap
//===================================================
function logoff(sessid){
	frm = getFrameByName('mainframe');
	frm.location.href = '/servlet/Srv.Ecos_Signon?AI='+sessid+'&CMD=LO';
	frm.location.href = '';
	frm.location.href = '/servlet/Srv.Ecos_Signon?AI='+sessid+'&CMD=LO';
}
//===================================================
//used for framesets that don't have a mainframe
function logoff_now(sessid,frame){
	frm = getFrameByName(frame);
	frm.location.href = '/servlet/Srv.Ecos_Signon?AI='+sessid+'&CMD=LO';
	frm.location.href = '';
	frm.location.href = '/servlet/Srv.Ecos_Signon?AI='+sessid+'&CMD=LO';
}
//===================================================
function numericOnly(e){
	var keynum;	var keychar; var numcheck;
	if(window.event){ // IE
		keynum = e.keyCode
	}else if(e.which){ // Netscape/Firefox/Opera
		keynum = e.which;
	}
	if 	(keynum < 45 || keynum > 57){
		return false;
	}else{
		return true;
	}
}
//===================================================
function hasValue(fldId){
		 fld = document.getElementById(fldId);
		 if (isEmpty(fld.value)){
		 	fld.focus(); return false;
		}else return true;
}
//=================================================================================================
function isEmail(str){
	// are regular expressions supported?
	 var supported = 0;
	if (window.RegExp)	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	 if (!supported)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^[a-zA-Z0-9\\'\\_\\-\\.']+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
//===================================================
/*
function checkEachEmail(ar){
	var flag = true;
	for (i=0;i<ar.length;i++){
	   if(!isEmail(ar[i])){
			flag = false;
	   }
	}
	return flag
}
*/
function checkEachEmail(ar){
	var flag = true;
	for (i=0;i<ar.length;i++){
		if (ar[i].length>0){
		   if(!isEmail(trim(ar[i]))){
				flag = false;
		   }
	  	}
	}
	return flag
}

//===================================================
function checkMultiEmail(str){
	var arr = str.split(',');
	if (arr.length>1){
		return checkEachEmail(arr);
	}else{
		arr = str.split(';');
		if (arr.length>1){
			return checkEachEmail(arr);
		}else{
			arr = str.split(' ');
			if (arr.length>1){
				return checkEachEmail(arr);
			}else{
				return isEmail(str);
			}
		}
	}
	return isEmail(str);
}

//===================================================
/*
function checkEmail(inputFld){
	if (inputFld.value.length > 0)	{
		   if(!isEmail(inputFld.value))	   {
				alert('Please enter a valid email address e.g user@domain.co.nz ');
				inputFld.focus();
				inputFld.select();
				return false;
		   }else return true;
	  }
}
*/

//===================================================
function checkEmail(inputFld){
	if (inputFld.value.length > 0)	{
		   if(!checkMultiEmail(inputFld.value)){
				alert('Please enter a valid email address e.g user@domain.co.nz ');
				inputFld.focus();
				inputFld.select();
				return false;
		   }else return true;
	  }
	  return false;
}
//===================================================
function checkEmailOptional(inputFld){
	if (inputFld.value.length > 0)	{
		   if(!checkMultiEmail(inputFld.value)){
				alert('Please enter a valid email address e.g user@domain.co.nz ');
				inputFld.focus();
				inputFld.select();
				return false;
		   }else return true;
	}else {
		return true;
	}
}

//=================================================================================================
var hexVals = new Array("0","1","2","3","4","5",".","7","8","9","A","B","C","D","E","F");
var unsafeString = "&#<>%\^[]`";
function isURLok(compareChar){ // part of URL Encode
 if (unsafeString.indexOf(compareChar) == -1 && compareChar.charCodeAt(0) > 32 && compareChar.charCodeAt(0) < 123){
   return true;
 }else{
   return false;
 }
}
//===================
function decToHex(num, radix){ // part of URL Encode
 var hexString = "";
 while (num >= radix){
   temp = num % radix;
   num = Math.floor(num / radix);
   hexString += hexVals[temp];
 }
 hexString += hexVals[num];
 return reversal(hexString);
}
//===================
function reversal(s){ // part of URL Encode
 var len = s.length;
 var trans = "";
 for (i=0; i<len; i++){
   trans = trans + s.substring(len-i-1, len-i);
 }
 s = trans;
 return s;
}
//===================
function URLEncode(val){
 var state= 'urlenc';
 var len= val.length;
 var backlen = len;
 var i= 0; var newStr= "";
 var frag= "";
 var encval= "";
 for (i=0;i<len;i++){
   if (isURLok(val.substring(i,i+1))){
     newStr = newStr + val.substring(i,i+1);
   }else{
     tval1=val.substring(i,i+1);
     newStr = newStr + "%" + decToHex(tval1.charCodeAt(0),16);
   }
 }
 return newStr;
}

function showDetail(id){
	obj = document.getElementById(id);
	if (obj.className=='shown'){
		obj.className='hidden';
	}else{
		obj.className='shown';
	}
}

function toggleImg(id,a,b){
	obj = document.getElementById(id);
	if (obj.src.indexOf(a)>-1){
		obj.src=b;
	}else{
		obj.src=a;
	}
}

//---------------------------------------------------------------
function stopEnter(field, event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode==13){
		event.keyCode ? event.keyCode = 0 : event.which ? event.which = 0 : event.charCode = 0;
	}
}

//---------------------------------------------------------------
function rollOver_ab(i,flag){
	myDivA = document.getElementById('div_a'+i);
	myDivB = document.getElementById('div_b'+i);
	if(flag=='OVER'){
		myDivA.className='ab_box2_ov';
		myDivB.className='ab_box3_ov';
	}else{
		myDivA.className='ab_box2';
		myDivB.className='ab_box3';
	}
}
