// Move an element directly on top of another element (and optionally
            // make it the same size)
            function Cover(bottom, top, ignoreSize) {
                var location = Sys.UI.DomElement.getLocation(bottom);
                top.style.position = 'absolute';
                top.style.top = location.y + 'px';
                top.style.left = location.x + 'px';
                if (!ignoreSize) {
                    top.style.height = bottom.offsetHeight + 'px';
                    top.style.width = bottom.offsetWidth + 'px';
                }
            }

function changeCamera(data, ip)
{
	var camType = data.substring(0,data.indexOf('+'));
	var URL = "vsf.vsftransportation.com:800" + data.substring(data.indexOf('+')+1,data.indexOf('~'));
	var camText = data.substring(data.indexOf('~')+1,data.length);

	if (ip.substring(0, 9) == '127.0.0.1' || ip.substring(0, 10) == '192.168.1.') {
	    var i = data.substring(data.indexOf('+') + 1, data.indexOf('~')) - 1;
	    URL = "192.168.1.5" + i;
	}
  if (camType == 'AXIS'){
	// Set the BaseURL to the URL of your camera
	
	var BaseURL = "http://" + URL + "/";

	// DisplayWidth & DisplayHeight specifies the displayed width & height of the image.
	// You may change these numbers, the effect will be a stretched or a shrunk image
	var DisplayWidth = "640";
	var DisplayHeight = "480";

	// This is the path to the image generating file inside the camera itself
	var File = "axis-cgi/mjpg/video.cgi?resolution=640x480&compression=50&clock=0&date=0";
	// No changes required below this point
	var output = "";
	var AppletDir = BaseURL + "java";
	var Cache_Version = "0.13.1.0";
	var Code = "";
	if (!(data.substring(data.indexOf('+') + 1, data.indexOf('~')) == '1')) {
	    AppletDir = AppletDir + "/ama"
	    Cache_Version = "0.91.0.0";
	    Code = "ama.";
	}
	var VideoPath = "axis-cgi/mjpg/video.cgi?resolution=";
	var restOfPath = "&compression=50&clock=0&date=0";
	var VideoURL = BaseURL + VideoPath;
    
	output = '<APPLET archive="ama.jar" codeBase="';
	output += AppletDir + '"';
	output += ' code="' + Code + 'MediaApplet" height=';
	output += DisplayHeight;
	output += ' width=';
	output += DisplayWidth;
	output += '>';
	output += '<PARAM NAME="code" VALUE="' + Code + 'MediaApplet">';
	output += '<PARAM NAME="archive" VALUE="ama.jar">';
	output += '<PARAM NAME="codebase" VALUE="';
	output += AppletDir + '">';
	output += '<PARAM NAME="ama_cgi-path" VALUE="axis-cgi">';
	output += '<PARAM NAME="cache_archive" VALUE="ama.jar">';
	output += '<PARAM NAME="cache_version" VALUE="' + Cache_Version + '">';
	output += '<PARAM NAME="ama_plugins" VALUE="">';
	output += '<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">';
	output += '<PARAM NAME="ama_url" VALUE="';
	output += VideoURL;
	output += DisplayWidth + 'x' + DisplayHeight;
	output += restOfPath + '">';
	output += '</APPLET>'
	/*document.write(output);*/
	
	WriteLayer('cam',null,output);
}
	else{
		WriteLayer('cam',null,'No camera selected. Please select a camera to view.');
       }
}

function WriteLayer(ID,parentID,sText) {
 if (document.layers) {
   var oLayer;
   if(parentID){
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
   }else{
     oLayer = document.layers[ID].document;
   }
   oLayer.open();
   oLayer.write(sText);
   oLayer.close();
 }
 else if (parseInt(navigator.appVersion)>=5&&navigator.
appName=="Netscape") {
   document.getElementById(ID).innerHTML = sText;
 }
 else if (document.all){
	document.all[ID].innerHTML = sText;
	//document.all[ID].Player.ToolbarConfiguration = "play,+snapshot,+fullscreen"
}

} 


function MM_swapImgRestore() 
{ //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}

function MM_preloadImages() 
{ //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#")
{
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  }
 }
}

function MM_swapImage() 
{ //v2.0
	
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) 
{
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) 
{
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  }
 }
  document.MM_swapImgData = swapArray; //used for restore
  	
}

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); return x;
}

function PNN() {
var load = window.open('http://www.vsftransportation.com/PNNWebForm.aspx','mywindow','left=0,top=0,width=400,height=720,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes');
}

function ShowMyModalPopup(loadid)
{ 
 var modal = $find('_ctl0_ContentPlaceHolder1_ModalPopupExtender1'); 
 
 modal.show(); 
 
 vsf.web.WebService.FetchOneLoad(loadid,DisplayResult);
}

function DisplayResult(result)
{
  var label=document.getElementById('_ctl0_ContentPlaceHolder1_Label1'); 
        label.innerHTML=result; 
        document.getElementById('_ctl0_ContentPlaceHolder1_Label1').value=result; 
}

 function HideModalPopup()
{
  var modal = $find('_ctl0_ContentPlaceHolder1_ModalPopupExtender1');
  var label=document.getElementById('_ctl0_ContentPlaceHolder1_Label1'); 
        label.innerHTML='Loading...'; 
        document.getElementById('_ctl0_ContentPlaceHolder1_Label1').value='Loading...'; 
  modal.hide();
}

function ViewLoadDetails(loadid)
{
    var load = window.open('view_load_details.aspx?loadid=' + loadid,'myload','width=400,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes');
}
