function moreInfo(url, name, w, h, x, y, winprops) {
 if (!w) w = 450;
 if (!h) h = 280;
 if (!x) x = 20;
 if (!y) y = 20;
 
 if(!winprops) {
  winprops = 'toolbar=no,location=no,' +
    'directories=no,status=no,menubar=no,scrollbars=no,' +
    'resizable=yes,copyhistory=no,width='+w+',height='+h+',' +
    'screenX='+x+',screenY='+y+',top='+x+',left='+y
 }
 else {
   winprops += ',width='+w+',height='+h+',screenX='+x+',screenY='+y+',top='+x+',left='+y
 }
  win = window.open(url, name, winprops)
 if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); if(x){return x;}else{return false;};
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_displayLayers() { //v3.0
var i,p,v,obj,args=MM_displayLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v='hide')?'none':v; }
obj.display=v; }
}

function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
obj.visibility=v; }
}

function returnShowHide(x){
var i,p,v,obj,args=MM_displayLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v='hide')?'none':v; }
obj.display=v; }
	
}

if (!Array.prototype.push) {  //Fix for older browsers
	function Array_push() {
	  var A_p = 0
	  for (A_p = 0; A_p < arguments.length; A_p++) {
	   this[this.length] = arguments[A_p]
	  }
	  return this.length
	}
	Array.prototype.push = Array_push
}

if(!Array.prototype.splice) { //fix for older browsers to the splice will work
    function array_splice(ind,cnt){
        if(arguments.length == 0) return ind;
        if(typeof ind != "number") ind = 0;
        if(ind < 0) ind = Math.max(0,this.length + ind);
        if(ind > this.length) {
            if(arguments.length > 2) ind = this.length;
            else return [];
        }
        if(arguments.length < 2) cnt = this.length-ind;
        cnt = (typeof cnt == "number") ? Math.max(0,cnt) : 0;
        removeArray = this.slice(ind,ind+cnt);
        endArray = this.slice(ind+cnt);
        this.length = ind;
        for(var i=2;i<arguments.length;i++){
            this[this.length] = arguments[i];
        }
        for(var i=0;i<endArray.length;i++){
            this[this.length] = endArray[i];
        }
        return removeArray;
    }
	Array.prototype.splice = array_splice;
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isFunction(a) {
    return typeof a == 'function';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getPosition(i){
	obj=MM_findObj(i);
	popupobj=MM_findObj('popup');
	
	x = findPosX(obj);
	y = findPosY(obj) - 115;

	
	popupobj.style.top = y+'px';
	popupobj.style.left = x+'px';
	
	
	MM_showHideLayers('popup','','show');
	
}

function setValues(){
	d = document.owner;
	var x = d.temp.value.split(":");
	//x[0] = site
	//x[1] = what layer deep in the hidden var
	
	var site = d[x[0]].value.split("|");
	
	//Now lets update that layer//
	state = d.location.options[d.location.selectedIndex].value;
	dest = d.destination.options[d.destination.selectedIndex].value;
	milesto = d.milesto.value;
	site[x[1]] = state+':'+dest+':'+milesto;
	var joinArray = site.join("|");
	d[x[0]].value = joinArray;
	
	//Now lets close the popup layer.//
	closePopup();
	
	//Now lets write the new changes to the page//
	writeLayer(x[0]);
	
	
}

function writeLayer(site){  //re-write the site layer when there is a change.

	//first lets get the text info from the hidden field//
	d = document.owner;
	milesto = '';
	name = '';
	var elementVal = new Array();
	elementVal = d[site].value.split("|");
	if(elementVal == ""){//write blank//
		_writeBlank(site);
	}else{
		
		for(i=0;i<elementVal.length;i++){
			var elementItem = new Array();
			elementItem = elementVal[i].split(":");
				
			//get destination from destination array//
			destX = destination[elementItem[0]];
			
			for(x=0;x<destination[elementItem[0]].length;x++){ //find in the destinations array the same number in the sites value
				dest = destX[x].split(":");
				if(dest[2] == elementItem[1]){
					name += dest[1]+':';
					break;
				}
			}
			
			milesto += elementItem[2]+':';
			//now that we have the name and miles we can write the html//
			
		}
			name = name.substr(0,name.length-1);
			milesto = milesto.substr(0,milesto.length-1);
		writeHTML = _writehtml(site, name, milesto);
		
		
	}
	
}

function deleteItem(site, x){

	d = document.owner;
	var elementVal = new Array();
	elementVal = d[site].value.split("|");
	elementVal.splice(x,1); //note: this returns the array that was removed
	d[site].value=elementVal.join("|");
	
	//write the layer again
	writeLayer(site);
	
}

function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	//alert(coordinates.x)
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

function initChecklist() {
    if (document.all && document.getElementById) {
        // Get all unordered lists
	   var lists = document.getElementsByTagName("ul");
        
        for (i = 0; i < lists.length; i++) {
            var theList = lists[i];
            
		  // Only work with those having the class "checklist"
            if (theList.className.indexOf("checklist") > -1) {
                var labels = theList.getElementsByTagName("label");
                
			 // Assign event handlers to labels within
                for (var j = 0; j < labels.length; j++) {
                    var theLabel = labels[j];
                    theLabel.onmouseover = function() { this.className += " hover"; };
                    theLabel.onmouseout = function() { this.className = this.className.replace(" hover", ""); };
                }
            }
        }
    }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function checkUncheckAll(theElement) {
   var form = theElement.form;
   for(i=0; i<form.elements.length; i++){
      if(form[i].type == 'checkbox' && form[i].name != 'checkall') {
         form[i].checked = theElement.checked;
      }
   }
}