<!--

function DisplayForm( Form ) {
  j = Form.elements.length;
  var s = new String;
  for(i=0;i<j;i++) s = s + i + ', ' + Form.elements[i].name + ': ' + Form.elements[i].value + '\n';
  s = s + 'Action: ' + Form.action + '\n';
  alert(s);
}

function UnMouse() {
  document.onmousedown=click;
  if (document.layers) window.captureEvents(Event.MOUSEDOWN);
  window.onmousedown=click;
  function click(e) {
    if (navigator.appName == 'Netscape') if (e.which != 1) return false;
    if (navigator.appName == "Microsoft Internet Explorer") if (event.button != 1) return false;
  }
}

function DisplayTime() {
  now = new Date();
  hour = now.getHours();
  minute = now.getMinutes();
  second = now.getSeconds();
  if( hour < 10 ) hour = '0' + hour;
  if( minute < 10 ) minute = '0' + minute;
  if( second < 10 ) second = '0' + second;
  alert('Time: ' + hour + ':' + minute + ':' + second);
}

//// CURRENCY
max_length=12;                         //max_length= length of text input
spacing="$               ";            // if $ sign is not wanted, remove it from spacing string.

// strips an input of any wierd characters and excessive decimal places, and puts a $ sign in front
// e.g.) <input type=text size=12 onchange='clean(this)'>
function clean (w){
    spacing="$               ";
    max_length=12;
	if(!w){
	    alert("missing input after "+ w2.name);         
	    return(0);
	}
	y="0"+w.value;                          //0 to prevent NaN
	yl=y.length;
	for(z=0;z<yl;z++){
		if(y.charAt(z)<"." || y.substring(z,z+1)>"9" || y.substring(z,z+1)=="/"){
			y=(y.substring(0,z) + y.substring(z+1));
			z--;
			yl--;
		}
	}
	y=parseFloat(y);
	x=Math.floor(y);
	xx=y-x;
	xx=xx+"00.00"                 //xx=the cents only (with zeroes).
	a=xx.indexOf(".");
	q=x+xx.substring(a,a+3);

	ql= (q.length < max_length)?(max_length-q.length):0;
	w.value=(y)?spacing.substring(0,ql)+q:"";
	r=parseFloat(q);                            //should be dddd.dd
	w2=w;
	return (r);
}

// converts it into a dollar format
// e.g.) <input type=text size=12 onchange='document.frusin.gst.value=tidy(clean(this)*0.125)'>
function tidy (y){
    max_length=12;                         //max_length= length of text input
    spacing="$               ";
    x=Math.floor(y);
    xx=y-x;
    xx=xx+"00.00"                 //xx=the cents only (with zeroes).
    a=xx.indexOf(".");
    q=x+xx.substring(a,a+3);
    ql= (q.length<max_length)?(max_length-q.length):0;   
    r=(y)?spacing.substring(0,ql)+q:"";
    return (r);
}

// display: tidy() prepares input for display leaving 2 decimal places
// like tidy, without the $ sign, or the spacing to align the decimal points
function display(numb){
  if (parseFloat(numb)){
    if (numb== Math.round(numb)){
      return ( numb + ".00")
    }
    else {
      numb=(numb + "0");
      return (numb.substring(0,(numb.indexOf(".")+3)))
    }
  }
  else{
    return "0.00"
  }
}

// complement to display, similar in function to clean. It removes commas and spaces (but not other characters) from an input
// e.g.) <input type=text name=k size=12 onchange='this.form.o=display(trim(this)/11)'>
function trim(w){
	if(!w){
	    return(0);
	}
	y=w.value;                          //0 to prevent NaN
	yl=y.length;
	for(z=0;z<yl;z++){
		if(y.charAt(z)=="," || y.substring(z,z+1)==" " || y.substring(z,z+1)=="/"){
			y=(y.substring(0,z) + y.substring(z+1));
			z--;
			yl--;
		}
	}
	numb=parseFloat(y);
	if (isNaN(numb)){
	    w.value='';
	    return 0}	
    if (numb== Math.round(numb)){
        w.value= numb + ".00"
        return parseFloat( numb + ".00")
    }
    else {
        numb=(numb + "0");
        w.value=numb.substring(0,(numb.indexOf(".")+3))
        return parseFloat(numb.substring(0,(numb.indexOf(".")+3)))
    }
}

//// END CURRENCY

function SearchReplace(str, oldChar, newChar) {
  var oldString = new String;
  var newString = new String;
  oldString = str;
  newString = '';
  len = oldString.length;
  for(i=0;i<len;i++) {
    temp = oldString.charAt(i);
    if( temp == oldChar ) { temp = newChar; }
    newString = newString + temp;
  }
  return newString;
}

function SearchReplaceEN(str) {
  var pattern = /\b\/en\/\b/gi;
  var newString = str.replace(pattern,'/fr/');
  return newString;
}

function SearchReplaceFR(str) {
  var pattern = /\b\/fr\/\b/gi;
  var newString = str.replace(pattern,'/en/');
  return newString;
}


function formatDate(date) {
  time = 'am';
	year = date.substring(0,4);
	month = date.substring(5,7);
	day = date.substring(8,10);
	hour = date.substring(11,13);
	minutes = date.substring(14,16);
	seconds = date.substring(17,19);
  if(month.charAt(0) == '0') { month = month.charAt(1); }
  if(day.charAt(0) == '0') { day = day.charAt(1); }
  if(hour.charAt(0) == '0') { hour = hour.charAt(1); }
	switch (month) {
	  case '1':
			month = "January";
			break;
	  case '2':
			month = "February";
			break;
	  case '3':
			month = "March";
			break;
	  case '4':
			month = "April";
			break;
	  case '5':
			month = "May";
			break;
	  case '6':
			month = "June";
			break;
	  case '7':
			month = "July";
			break;
	  case '8':
			month = "August";
			break;
	  case '9':
			month = "September";
			break;
	  case '10':
			month = "October";
			break;
	  case '11':
			month = "November";
			break;
	  case '12':
			month = "December";
			break;
		default:
			break;
	}
	hour = parseInt(hour);
	if(hour > 0) {
  	if(hour == 12) { time = 'pm'; }
  	if(hour > 12) { time = 'pm'; hour = hour - 12; }
  	document.write(month + ' ' + day + ', ' + year + ' ' + hour + ':' + minutes + ' ' + time);
	} else document.write(month + ' ' + day + ', ' + year);
}

function openWindow(url,x,y) {
  mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + x + ',height=' + y + '');
}

function openWindow2(url,x,y) {
  mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + x + ',height=' + y + '');
}

function openWindow3(url,x,y) {
  mywin = window.open(url,"win",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=0,resizable=1,width=' + x + ',height=' + y + '');
}

function openWindow4(url,x,y) {
  mywin = window.open(url,"win",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=' + x + ',height=' + y + '');
}

function openWindow5(url,x,y) {
  mywin = window.open(url,"win",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=' + x + ',height=' + y + '');
}

// Added screen coordinates (Allen)
function openWindowXY(url,x,y,screenX,screenY,top,left) {
  mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + x + ',height=' + y + ',screenX=' + screenX + ',screenY=' + screenY + ',top=' + top + ',left=' + left);
}

function closewindow() { window.close(); }

function printPage() {
  if (window.print)
    window.print()
  else
    alert("Sorry, your browser doesn't support this feature.");
}

// Error Trap JavaScript Errors
function doNothing() {
  return true
}

window.onerror = doNothing

// function to set the Status Bar message
function setStatusBar(msg) {
  if (document.images) {
    window.status = msg
    return true
  }
  return false
}

// function to check for 'Enter' key
function checkForEnter(e) {
  e = (e) ? e : event
  var charCode = (e.which) ? e.which : e.keyCode
  if (charCode == 13) {
    return true
  }
  return false
}

function checkForNum(Form, e) {
  tempvalue = Form.value;
  e = (e) ? e : event;
  var charCode = (e.which) ? e.which : e.keyCode;
  // accept characters 0-9 and backspace
  if ((charCode >= 48 && charCode <= 58) || charCode >= 96 && charCode <= 105 || charCode == 8) {
    return true;
  }
  value = '';
  for(i=0;i<tempvalue.length-1;i=i+1) {
    value = value + tempvalue.charAt(i);
  }
  Form.value = value;
  return false;
}


///// JAVASCRIPT 1.2 ///////////////////
var highlightcolor="lightyellow";
var backgroundcolor="grey";
var previous='';
var eventobj;

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/;

//Function to check whether element clicked is form element
function checkel(which) {
  if (which.style&&intended.test(which.tagName)) {
    if (ns6&&eventobj.nodeType==3)
      eventobj=eventobj.parentNode.parentNode;
    return true;
  }
  else
  return false;
}

//function to dim form element
function dim(e) {
  eventobj=ns6? e.target : event.srcElement;
  if (previous!='') {
    if (checkel(previous))
      previous.style.backgroundColor='';
    previous=eventobj;
    if (checkel(eventobj))
      eventobj.style.backgroundColor=backgroundcolor;
  }
  else {
    if (checkel(eventobj))
      eventobj.style.backgroundColor=backgroundcolor;
    previous=eventobj;
  }
}


//function to highlight form element
function highlight(e) {
  eventobj=ns6? e.target : event.srcElement;
  if (previous!='') {
    if (checkel(previous))
      previous.style.backgroundColor='';
    previous=eventobj;
    if (checkel(eventobj))
      eventobj.style.backgroundColor=highlightcolor;
  }
  else {
    if (checkel(eventobj))
      eventobj.style.backgroundColor=highlightcolor;
    previous=eventobj;
  }
}




////////////////////// C O O K I E   C U T T I N G ///////////////////////

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
// example) setCookie('Nav1','',null,'/')
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
                  ((expires) ? "; expires=" + expires.toGMTString() : "") +
                  ((path) ? "; path=" + path : "") +
                  ((domain) ? "; domain=" + domain : "") +
                  ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
// example) getCookie('Nav1')
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  pattern = /\++/g;  // globally look for 1 or more '+'
  dc = dc.replace(pattern," ");  // replace all '+' with ' '
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
                      ((path) ? "; path=" + path : "") +
                      ((domain) ? "; domain=" + domain : "") + 
                      "; expires=Fri, 31 Dec 1999";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

//-->

