﻿// JScript File

// Firefox InnerText R.E.M 2006
// Credits: Matthias Hertel , Erik Arvidsson, check by jvance
// emulates IE's innertext on Firefox's Proprietary __defineGetter__ 
if (typeof HTMLElement != "undefined" && typeof HTMLElement.prototype.__defineGetter__ != "undefined") {
  HTMLElement.prototype.__defineGetter__("innerText", function () {    
  if (this.textContent) { return(this.textContent)   }    
  else { var r=this.ownerDocument.createRange(); r.selectNodeContents(this); return r.toString();}});
  
   HTMLElement.prototype.__defineSetter__("innerText", function (sText) {    
      if  (this.textContent!=null)  { return this.textContent = sText; }    
      else { return this.innerHTML = sText.replace(/\&/g, "&").replace(/>/g, ">");  }}  );
      
   
  HTMLElement.prototype.__defineGetter__(
  "pixelTop", function () {    
     return Number(this.style.top.replace("px", ""));
  }
  );
  
  HTMLElement.prototype.__defineSetter__(
  "pixelTop", function (pixels) {    
     this.style.top = pixels+ "px";
  }
  );
} else {
   //HTMLElement.prototype.forAll = function(){alert("This function is defined for all elements");};
   /*
document._createElement = document.createElement; 
document.createElement = function(tag) {
   var t=document._createElement(tag);

   t.appendText = function(txt) {
      return this.appendChild(document.createTextNode(txt)); 
   }

   t.appendTag = function(tag,txt) {
      var t=document.createElement(tag);
      if(txt) { t.appendText(txt) };
      return this.appendChild(t); 
   }
   return t;
}
   */

}

// opera innerText is broken
String.fixText = function($INPUT) {   
   return $INPUT.replace(/\&/g, "&").replace(/\</g, "<").replace(/\>/g, ">");
} 

//var opera = navigator.userAgent.indexOf('Opera') != -1;
//var ie = document.all!=null && opera==false;


if (typeof HTMLElement!="undefined" && typeof HTMLElement.prototype.insertAdjacentElement== "undefined") {
	HTMLElement.prototype.insertAdjacentElement = function (where, parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore (parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore (parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild (parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
            this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else 
			   this.parentNode.appendChild(parsedNode);
			break;
		}
	};

	HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	};


	HTMLElement.prototype.insertAdjacentText = function (where,txtStr) {
		var parsedText = document.createTextNode (txtStr)
		this.insertAdjacentElement (where, parsedText)
	};
}

if (typeof HTMLElement!="undefined" && typeof HTMLElement.prototype.SetCapture== "undefined") {
   HTMLElement.prototype.setCapture = function() {};
   HTMLElement.prototype.releaseCapture = function() {};
}

function strformat(templ) {
   var args = arguments;
   
   return templ.replace(/(\{\d+\})/g, function(found) {
      return args[ parseInt(found.substr(1)) +1 ];  //found is "{0}",  "{1}" etc. return appropriate param
   });
}

function press(img, id, md) {
   img.src = strformat("truckslist.aspx?li={0}&on={1}", id, md);
}

function press_old(img, ndx, part, md) {
   var modes = ["", "ON"];
   img.src = "images/btn"+ part +ndx+ modes[md]+ ".gif";
}

 
