xMousePos=0;
yMousePos=0;
xMousePosMax=0;
yMousePosMax=0; 
function captureMousePosition(e) {
        if (document.layers) {
                // When the page scrolls in Netscape, the event's mouse position
                // reflects the absolute position on the screen. innerHight/Width
                // is the position from the top/left of the screen that the user is
                // looking at. pageX/YOffset is the amount that the user has
                // scrolled into the page. So the values will be in relation to
                // each other as the total offsets into the page, no matter if
                // the user has scrolled or not.
                xMousePos = e.pageX;
                yMousePos = e.pageY;
                xMousePosMax = window.innerWidth+window.pageXOffset;
                yMousePosMax = window.innerHeight+window.pageYOffset;
        } 
        else if (document.all) {
                // When the page scrolls in IE, the event's mouse position
                // reflects the position from the top/left of the screen the
                // user is looking at. scrollLeft/Top is the amount the user
                // has scrolled into the page. clientWidth/Height is the height/
                // width of the current page the user is looking at. So, to be
                // consistent with Netscape (above), add the scroll offsets to
                // both so we end up with an absolute value on the page, no
                // matter if the user has scrolled or not.
                //
                //NB. we are in standards compliant mode, so instead of using document.body, we must use document.body.parentNode, i.e. the HTML element
                if ( window.event && window.event.clientX ) {
                     if ( document.body ) {
                        xMousePos = window.event.clientX+document.body.parentNode.scrollLeft;
                        yMousePos = window.event.clientY+document.body.parentNode.scrollTop;
       
                        xMousePosMax = document.body.clientWidth+document.body.parentNode.scrollLeft;
                        yMousePosMax = document.body.clientHeight+document.body.parentNode.scrollTop;
                     }
                }
        } 
        else if (document.getElementById) {
                // Netscape 6 behaves the same as Netscape 4 in this regard
                xMousePos = e.pageX;
                yMousePos = e.pageY;
                xMousePosMax = window.innerWidth+window.pageXOffset;
                yMousePosMax = window.innerHeight+window.pageYOffset;
        }

}
//element geometry functions
function getElementLeft(myEl) {
        var parentLeft = 0;
        var total = 0;
        if (myEl.parentNode != null) {
                parentLeft = getElementLeft(myEl.parentNode);
                total = parentLeft + myEl.offsetLeft;
        } else {
                return 0;
        }
        return total;
}
function getElementTop(myEl) {
        var parentTop = 0;
        var total = 0;
        if (myEl.parentNode != null) {
                parentLeft = getElementTop(myEl.parentNode);
                total = parentTop + myEl.offsetTop;
        } else {
                return 0;
        }
        return total;
}
function myWidth() {
  var myWidth = 0
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if ( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if ( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}
function myHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
function showPopUpAt(document, popup, el, x, y) {
   var s = el.style;
   document.getElementById(popup).style.left = x + "px";
   document.getElementById(popup).style.top = y + "px";
   document.getElementById(popup).style.display = 'block';
}
function showPopUpAtElement(document,popup, el, addOffSet) {
  var p = getAbsolutePos(el);
  var y_coord = p.y + el.offsetHeight;
  if ( addOffSet == 0 ) {
     y_coord = p.y;	      
  } 
  showPopUpAt(document, popup, el,p.x, y_coord);
}
function getAbsolutePos(el) {
  var r = { x: el.offsetLeft, y: el.offsetTop };
  if (el.offsetParent) {
     var tmp = getAbsolutePos(el.offsetParent);
     r.x += tmp.x;
     r.y += tmp.y;
  }
  return r;
}
function showPopOverHelp(doc_name, e, message) {
        if ( !doc_name.getElementById('popOverHelp') ) {
            return 0;
        }
	var x, y;
	if (doc_name.all) {
		x = window.event.clientX + document.body.scrollLeft;
		y = window.event.clientY + document.body.scrollTop;
	} else {
		x = e.pageX;
		y = e.pageY;
	}
	doc_name.getElementById('popOverHelp').style.left = (x + 15) + 'px';
	doc_name.getElementById('popOverHelp').style.top = (y + 15) + 'px';
	if (message != null) doc_name.getElementById('popOverHelp').innerHTML = message;
	doc_name.getElementById('popOverHelp').style.width = 'auto';
	if (myWidth() - parseInt(doc_name.getElementById('popOverHelp').style.left) < 100) {
		doc_name.getElementById('popOverHelp').style.left = (parseInt(doc_name.getElementById('popOverHelp').style.left) - 100) + 'px';
		doc_name.getElementById('popOverHelp').style.width = '50px';
	}
	if (myHeight() - parseInt(doc_name.getElementById('popOverHelp').style.top) < 100) {
		doc_name.getElementById('popOverHelp').style.top = (parseInt(doc_name.getElementById('popOverHelp').style.top) - 100) + 'px';
	}
	doc_name.getElementById('popOverHelp').style.display = 'block';
        if ( doc_name.getElementById('popupmenushadow') ) {
	doc_name.getElementById('popupmenushadow').style.left = (parseInt(doc_name.getElementById('popOverHelp').style.left) + 25) + 'px';
	doc_name.getElementById('popupmenushadow').style.top = (parseInt(doc_name.getElementById('popOverHelp').style.top) + 25) + 'px';
	if (myWidth() - parseInt(doc_name.getElementById('popupmenushadow').style.left) < 100) {
		doc_name.getElementById('popupmenushadow').style.left = (parseInt(doc_name.getElementById('popupmenushadow').style.left) - 100) + 'px';
		doc_name.getElementById('popupmenushadow').style.width = '15px';
	}
	if (myHeight() - parseInt(doc_name.getElementById('popupmenushadow').style.top) < 100) {
		doc_name.getElementById('popupmenushadow').style.top = (parseInt(doc_name.getElementById('popupmenushadow').style.top) - 100) + 'px';
	}
	doc_name.getElementById('popupmenushadow').style.display = 'block';
        }
	return true;
}
function editorPopOverHelp(doc_name, e, message) {
        captureMousePosition(e);
        doc_name.getElementById('popOverHelp').style.left = xMousePos - 10 + 'px'; 
        doc_name.getElementById('popOverHelp').style.top  = yMousePos - 10 + 'px';
        if (message != null) doc_name.getElementById('popOverHelp').innerHTML = message;
        var detect = navigator.userAgent.toLowerCase();
        if ( ( detect.indexOf('msie') + 1 ) == 0 ) {
           doc_name.getElementById('popOverHelp').style.width = 'auto';
        }
        doc_name.getElementById('popOverHelp').style.display = 'block';
        return true;
}
function hidePopOverHelp(doc_name) {
        if ( doc_name.getElementById('popOverHelp') ) {
	   doc_name.getElementById('popOverHelp').style.display = 'none';
	}		
        hideSubMenu(doc_name);
	return true;
}
function hideSubMenu(doc_name) {
        if ( doc_name.getElementById('submenu') ) {
           doc_name.getElementById('submenu').style.display = 'none';
        }         
                        return true;
}
function pageList(anchor, current_page, maxpage, thisURI, id ) {
   var work_str = '';
   if ( current_page == 0 && maxpage == 1 ) {
      return '';
   }
   var className = 'navNumber';
   for ( i=0; i<maxpage; i++) {
     className= 'navNumber';
     if ( i == current_page ) {
        className= 'navNumberOn';
     }
     if ( !thisURI ) {
        thisURI = '';
     }
     if ( anchor ) {
        work_str = work_str+' <a class="'+className+'" href="'+thisURI+'?id='+id+'&pa='+i+'#'+anchor+'">'+(i+1)+'</a>';
     }
     else {
        work_str = work_str+' <a class="'+className+'" href="'+thisURI+'?id='+id+'&pa='+i+'">'+(i+1)+'</a>';
     }
   }
   return work_str;
}
function html_entity_decode(str) {
  var ta=document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  return ta.value;
}
function fos(fn,ln,em,oid,imgsrc,phrase){
   if ( em) {
   var d=document;
   var aref=d.createElement("a");
   aref.style.border="none";
   var name=html_entity_decode(fn+' '+ln);
   var l = 'mailto:'+name+leftAngletag()+e_de_code(em)+rightAngletag()+'?subject=WWW-Email:';
   aref.setAttribute("href",l);
   if ( imgsrc && imgsrc !='' ) {
      var img=d.createElement("img");
      img.style.border="none";
      img.src=imgsrc;
      img.alt=e_de_code(em);
      img.title=img.alt;
      aref.appendChild(img);
   }
   else {
     if (phrase ) {
        if(phrase=='default'){phrase='send an email'}
        text1=d.createTextNode(phrase);
     }
     else {
        text1 = d.createTextNode(name);
     }
     aref.appendChild(text1);
   }
   d.getElementById(oid).appendChild(aref);
   }
}
function e_de_code(e, v, q) {
     if ( q ) { 
        q = '?'+q;
     }
     else {
        q = '';
     }
     if ( e && e.length && v && v.length) {
        var stub = "\u006d\u0061\u0069\u006c\u0074\u006f\u003a";
        document.write("<a href="+'"'+stub+e+q+'"'+">"+v+"</a>");
     }
     else if ( e && e.length ) {
        return e;
     }
}
function leftAngletag() {
   var tag = "\u003c";
   return tag;
}
function rightAngletag() {
   var tag = "\u003e";
   return tag;  
}
function u_de_code(l, u, v) {
     if ( !l ) {
        l = '';
     } 
     if ( u && u.length ) {
        document.write("<a href="+'"'+l+u+'">'+v+"</a>");
     }
}

function elink(name,domain,phrase,asText) {
   var args = domain.split('/') // parse out domain parts
   var tmp = args.join(".");
   if ( !asText ) {
      document.write('<a href="mailto:'+name+'@'+tmp+'?subject=WWW-Email:">'+phrase+'</a>');
   }
   else {
      return name+'@'+tmp;
   }
}

function ord(string){return (string+'').charCodeAt(0);}
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
/* Finally, let's start trying to figure out if the supplied address is
   valid. */
/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	//alert("Not a recognised form of email address.")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]
// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("Not a recognised form of email address.")
    return false
}
/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        //alert("Not a recognised form of email address.")
		return false
	    }
    }
    return true
}
// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("Not a recognised form of email address.")
    return false
}
/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */
/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   //alert("Not a recognised form of email address.")
   return false
}
// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="Not a recognised form of email address."
   //alert(errStr)
   return false
}
// If we've gotten this far, everything's valid!
return true;
}
clearCookie = function() {
	var now = new Date();
	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
	this.setCookie('co'+this.obj, 'cookieValue', yesterday);
	this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};
// [Cookie] Sets value in a cookie
setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');

};
// [Cookie] Gets a value from a cookie
getCookie = function(cookieName) {
	var cookieValue = '';

	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));

	}

	return (cookieValue);
};
function highlight(thisObject,type) {
   var thisClassName = 'formInputMissing';
   if ( type == 'text' ) { 
      thisClassName = 'formInputMissingTxt';
   }	 
   if ( thisObject.className ) {	 
      var wrkClassName = thisObject.className;
     if ( wrkClassName.indexOf(thisClassName) == -1) {
         thisObject.className = thisObject.className+' '+thisClassName;
      }
   }   
   else {
      thisObject.className = thisClassName;
   }
}
function unhighlight(thisObject,type) {
   var myRegExp = /formInputMissing/;
   if ( type == 'text' ) { 
      myRegExp = /formInputMissingTxt/;
   }	 
    if ( thisObject.className ) {	 
      var wrkClassName = thisObject.className;
      wrkClassName = wrkClassName.replace(myRegExp,'');
      thisObject.className = wrkClassName;
   }
}
function highlightLabel(thisObject,type) {
   var thisClassName = 'formLabelError';
   if ( document.getElementById(thisObject.id+'Label') && document.getElementById(thisObject.id+'Label').className ) {
      var wrkClassName = document.getElementById(thisObject.id+'Label').className;
     if ( wrkClassName.indexOf(thisClassName) == -1) {
         document.getElementById(thisObject.id+'Label').className = thisObject.className+' '+thisClassName;
      }
   }
   else {
      document.getElementById(thisObject.id+'Label').className = thisClassName;
   }
}
function unhighlightLabel(thisObject,type) {
   var myRegExp = /formLabelError/;
    if ( document.getElementById(thisObject.id+'Label') ) {
      var wrkClassName = document.getElementById(thisObject.id+'Label').className;
      wrkClassName = wrkClassName.replace(myRegExp,'');
      document.getElementById(thisObject.id+'Label').className = wrkClassName;
   }
}
// Generic form validation function.
// Expects to be called with an ARRAY of field objects to be validated
// We then check they have data, based upon the input control (text, radio, checkbox )
// All errors are hightlighted by;
// 1) The class name of the control/parentNode is modified to have an additional class added 
// 2) An error message is formatted. We look for a div with the same id as the form+'errorBox'
//    If we find no div we just pop up an alert window 
function validateForm(theForm,requiredFields,debug,noSubmit,modifier) {
    if ( !theForm ) {
       theForm = document.getElementById('thisForm');
       if ( !theForm ) {
          alert('Form Not Specified in call to validateForm');
          return 0;
       }
    }
    var fieldCount = requiredFields.length;
    if ( !fieldCount ) {
       return 1;
    }   
    if ( document.getElementById(theForm.id+'Errors') ) {
       document.getElementById(theForm.id+'Errors').style.display='none';
    }
    var indexCount = 0;
    var thisField;
    var errorFields = new Array();
    var errorMessages = new Array();
    for (indexCount = 0; indexCount < fieldCount; indexCount++) {
    	// Check the control id actually exists, if not we fail
	thisField = requiredFields[indexCount];
        var thisType = thisField.tagName;
	unhighlight(thisField);
        unhighlightLabel(thisField, thisType);
        if ( !thisType ) {
           thisType = '[object NodeList]';
        }
	switch ( thisType ) {
	   case 'TEXTAREA': {
             if (  thisField.value.length <= 0 ) {
	     	errorFields[errorFields.length] = thisField.id;
		highlight(thisField);
                
		if ( document.getElementById(thisField.id+'Label') ) {
		   errorMessages[errorMessages.length] = document.getElementById(thisField.id+'Label').innerHTML+' is a required field';
                   highlightLabel(thisField, thisType);
		}
		else {
		     errorMessages[errorMessages.length]  = thisField.id+' is a required field';
		}		
              }
	      continue;
           };	
	   case 'INPUT': {

	     // Is this an email field??

             if ( thisField.type && thisField.type == 'checkbox' ) {
	        unhighlight(thisField.parentNode);
	        if (  !thisField.checked ) {
	           errorFields[errorFields.length] = thisField;
		   highlight(thisField.parentNode);
		   if ( document.getElementById(thisField.id+'Label') ) {
                      highlightLabel(thisField, thisType);
		      errorMessages[errorMessages.length] = 'Please check '+document.getElementById(thisField.id+'Label').innerHTML;
		   }
		   else {
                      // Hack
		      // Get the parent Nodes innerHTML but strip out the checkbox
		      var thisHTML = thisField.parentNode.innerHTML;
		      var parts = thisHTML.split('<input ');
		      errorMessages[errorMessages.length] = 'Please check '+parts[0]; 
		   }
	        };	
		continue;	     	
	     
	     }

             if (  thisField.value.length <= 0 ) {
	     	errorFields[errorFields.length] = thisField.id;
		highlight(thisField);
		if ( document.getElementById(thisField.id+'Label') ) {
                   highlightLabel(thisField, thisType);
		   errorMessages[errorMessages.length] = document.getElementById(thisField.id+'Label').innerHTML+' is a required field';
		}
		else {
		     errorMessages[errorMessages.length]  = thisField.id+' is a required field';
		}		
              }
	      continue;
	     };	
              
	   case 'checkbox' : {
             if (  thisField.selectedIndex == 0 ) {
	     	errorFields[errorFields.length] = thisField;
		highlight(thisField);
		if ( document.getElementById(thisField.id+'Label') ) {
                   highlightLabel(thisField, thisType);
		   errorMessages[errorMessages.length] = document.getElementById(thisField.id+'Label').innerHTML;
		}
	     };	
	     continue;
             }
           case 'SELECT' : {
             if (  thisField.selectedIndex == -1 || thisField.options[thisField.selectedIndex].value=='') {
		highlight(thisField);
	     	errorFields[errorFields.length] = thisField;
		if ( document.getElementById(thisField.id+'Label') ) {
                   highlightLabel(thisField, thisType);
		   errorMessages[errorMessages.length] = document.getElementById(thisField.id+'Label').innerHTML+' is a required field';
		}
		else {
		   errorMessages[errorMessages.length] = thisField.id+' is a required field';
                }
	     };	
	     continue;
	     }
	       	    

	   case '[object NodeList]' : {
	      	     var radioItems = thisField.length;
		     if ( radioItems ) {
		     	var is_valid_rb=0;
			var workStr = '';
                        var separator = '/';
                    	unhighlight(thisField[0].parentNode);
                        for (i=0; i<radioItems; i++ ) {
        	 	   if ( thisField[i].checked ) {	
                             is_valid_rb = 1;
          		     continue;
                           }
			   if ( i > 0 ) {
			      workStr = workStr+'/';
                           }
    	                   workStr = workStr+thisField[i].value;

	                };	
	                if ( !is_valid_rb ) {
                          highlight(thisField[0].parentNode);
                          errorFields[errorFields.length] = thisField;
                          if (modifier='survey') {
                             if ( document.getElementById(thisField[0].id+'Label') ) {
                                var qStr = document.getElementById(thisField[0].id+'Label').innerHTML;
                                var qStrArray = qStr.split('.');
                                if ( qStrArray[0].length) {
                                   errorMessages[errorMessages.length] = 'Choose an option for question '+qStrArray[0];
                                }
                                else {errorMessages[errorMessages.length] = 'Choose an option for Question '+qStr};
                                document.getElementById(thisField[0].id+'Label').className+=' SurveyError';
                             }
                          }
                          else {
                             errorMessages[errorMessages.length] = 'Choose an option from the following '+workStr;
                          }
	                }
                    }
		    continue;
             }


        }

    }


    // We may also have some email fields on the form which are not mandatory
    // We therefore get an ARRAY of objects
    // and if we have not already validated them we do so here
    // className='emailAddressField'
    var myEmailFields = getFormElementsByClass(document,"emailAddressField",'input');
    if ( myEmailFields.length ) {
       var i=0;
       for (i = 0; i < myEmailFields.length; i++) {
    	// Check the control id actually exists, if not we fail
	thisField = myEmailFields[i];
        unhighlight(thisField);
        if ( thisField.value && !emailCheck( thisField.value ) ) {
	   errorFields[errorFields.length] = thisField.id;
	   highlight(thisField);
	   if ( document.getElementById(thisField.id+'Label') ) {
              highlightLabel(thisField, thisType);
	      errorMessages[errorMessages.length] = document.getElementById(thisField.id+'Label').innerHTML+' is not a valid email address';
	   }	   
	   else {
	      errorMessages[errorMessages.length]  = thisField.id+' is not a valid email address';
	   }		
	}
	}
     }


    if ( errorFields.length > 0 ) {
      var workStr = '';
      var separator = ""; 
      var separator1 = "\n"; 
      if ( document.getElementById(theForm.id+'Errors') ) {
         separator = '<li>';
         separator1 = '</li>';
      }
      for ( i=0; i<errorFields.length;i++ ) {
	  workStr += separator+errorMessages[i]+separator1;
      }
      if ( document.getElementById(theForm.id+'Errors') ) {
         document.getElementById(theForm.id+'Errors').innerHTML = '<br/><br/>Please check and fix the following problems with the information entered.</br><ul>'+workStr+'</ul>';
	 document.getElementById(theForm.id+'Errors').style.display='block';
      }   
      else {
         alert(workStr);
      }
      document.location="#thisFormErrors";
      return 0;
    }   

    if ( !noSubmit ) {
       theForm.submit();
    }	
    return 1;
}

function getFormElementsByClass(d,needle, tag) {
  if ( !tag ) { 
      tag = '*';
  } 

  var my_array = d.getElementsByTagName(tag);
  var retvalue = new Array();
  var i = 0;
  var j = 0;

  for (i = 0, j= 0; i < my_array.length; i++) {
    var c = " " + my_array[i].className + " ";
    if (c.indexOf(" " + needle + " ") != -1)
      retvalue[j++] = my_array[i];
  }
  return retvalue;
}

function add_tracking() {
   var qs = new Querystring();
   var d = document;
   var thisID = qs.get("qid");
   if ( thisID ) {
       var myLinks = d.getElementsByTagName("A");
       var id = '';
       for (i = 0, j= 0; i < myLinks.length; i++) {
        if ( myLinks[i].href.indexOf("/cms/billpay/") > 0 ) {
           if ( myLinks[i].href.substring(1,myLinks[i].href.length) == '/' ) {
               myLinks[i].href += '/';
           }
           myLinks[i].href += thisID;
            
        }
    }
   }
}

function print_quote() {
    var qs = new Querystring();
    var thisID = qs.get("print");
    if ( !thisID ) {
       alert('There was an error printing this page. Quote Reference Number is missing.');
       return 0;
    }
    var thisEmail = qs.get("email");
    if ( !thisEmail ) {
       alert('There was an error printing this page. Email address does not match.');
       return 0;
    }	  
    window.open('/cms/calculator/?print='+thisID+'&email='+thisEmail,'Print', 'top=160, left=20, width=540, height=550, scrollbars=no, resizable=yes');
}

function new_window(theHREF) {
   if ( !theHREF.href ) {
      return false;
   }
   window.open(theHREF.href,'External Link', 'top=120, left=20, width=800, height=600, scrollbars=no, resizable=yes');
   return false;
}

function Querystring(qs) { // optionally pass a querystring to parse
   this.params = new Object()
   this.get=Querystring_get
   if (qs == null) qs=location.search.substring(1,location.search.length)
   if (qs.length == 0) return
// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
   qs = qs.replace(/\+/g, ' ')
   var args = qs.split('&') // parse out name/value pairs separated via &
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])
		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}
function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	var value=this.params[key]
	if (value==null) value=default_;
	return value
}
function popup_window(hrefObj,askUser) {
   if ( !hrefObj ) return;
   if ( askUser ) {
      var confirmed = confirm('The link you have followed belongs to an external website.'+"\n"+' and will open in a new window.'+"\n"+'We are not responsible for the content of external internet sites.'+"\n"+'Select OK to continue or Cancel to stop.'+"\n"); 
      if ( !confirmed ) return false;
   } 
   window.open(hrefObj.href,'_blank', 'top=160, left=20, width=700, height=550, scrollbars=yes, resizable=yes');   
   return false;
}
var startSz=1;
function initFontSize(){
 if (!document.getElementById) return;
 var trgt = 'body';
 var d = document,cEl = null,sz = startSz,i,j,cTags;
 if ( !( cEl = d.getElementById( trgt ) ) ) {cEl = d.getElementsByTagName( trgt )[ 0 ]};
 //cEl.style.display='none';
 var size=getCookie("fontSize");
 if ( size ) {
   //alert(size);
   switch ( size ) {
      case 'x-small': {startSz=0; break; };
      case 'small': {startSz=1; break;};
      case 'medium': {startSz=2;break;};
      case 'large': {startSz=3;break;};
   };

   var tgs = new Array( 'body');
   cEl.style.fontSize = size;
   for ( i = 0 ; i < tgs.length ; i++ ) {
      cTags = cEl.getElementsByTagName( tgs[ i ] );
      for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = size;
   }
 }
 //cEl.style.display='block';
}

if (window.attachEvent) { //attach load event
window.attachEvent("onload",initFontSize);}
else{window.addEventListener("load",initFontSize , true)}

