   function Dragger(elem, gripElem) {
 	this.element = elem;
 	this.gripElement = gripElem;
 	this.sniffer = new BrowserSniffer();
 	
    this.drag = function(event) {
		var x, y;
 	 	// Get cursor position with respect to the page.
		if (this.sniffer.isIE()) {
    		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  		}
	   if (this.sniffer.isFirefox()) {
    		x = event.clientX + window.scrollX;
   			y = event.clientY + window.scrollY;
  		}
  	  	this.element.style.left = (this.element.startLeft + x - this.element.startX) + "px";
  		this.element.style.top  = (this.element.startTop  + y - this.element.startY) + "px";
  		if (this.sniffer.isIE()) {
   			window.event.cancelBubble = true;
    		window.event.returnValue = false;
  		}
  		if (this.sniffer.isFirefox()) {
  			event.preventDefault();
  		}
  	}
  	
  	this.stopDrag = function(event) {
		// Stop capturing mousemove and mouseup events.
		
		//this.element.onmousemove = null;
	  	//this.element.onmouseup = null;
		if (this.sniffer.isIE()) {
    		document.detachEvent("onmousemove", this.dragger);
    		document.detachEvent("onmouseup",   this.dragStopper);
  		}
  		if (this.sniffer.isFirefox()) {
    		document.removeEventListener("mousemove", this.dragger,   true);
    		document.removeEventListener("mouseup",   this.dragStopper, true);
  		}
	}
 	
 	this.startDrag = function(event) {
	 	var x;
	 	var y;
	 	if (this.sniffer.isIE()) {
	 		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
	    	y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	 	}
	 	else if(this.sniffer.isFirefox()) {
	 		x = event.clientX + window.scrollX;
	    	y = event.clientY + window.scrollY;
	 	}
	 	this.element.startX = x;
	  	this.element.startY = y;
	  	this.element.startLeft  = parseInt(this.element.style.left, 10);
	  	this.element.startTop   = parseInt(this.element.style.top,  10);
	 	if (isNaN(this.element.startLeft)) {
	 		 this.element.startLeft = 0;
	 	}
	  	if (isNaN(this.element.startTop)) {
	  		 this.element.startTop = 0;	
	  	}
	  	this.element.style.zIndex = 300;
	  	//this.element.onmousemove = callback(this, this.drag);
	  	//this.element.onmouseup = callback(this, this.stopDrag);
	  	if (this.sniffer.isIE()) {
	    	document.attachEvent("onmousemove", this.dragger);
	     	document.attachEvent("onmouseup",   this.dragStopper);
	    	window.event.cancelBubble = true;
	    	window.event.returnValue = false;
	  	}
	  	if (this.sniffer.isFirefox()) {
	    	document.addEventListener("mousemove", this.dragger ,   true);
	    	document.addEventListener("mouseup", this.dragStopper , true);
	    	event.preventDefault();
	  	}
 	}
  	
  	this.gripElement.onmousedown = callback(this, this.startDrag);
  	this.dragger = callback(this, this.drag);
  	this.dragStopper = callback(this, this.stopDrag);

 }


function openPrintWindow(url)
{
	window.open(url, "printlabels", "width=600,height=400,resizable=no,minimizable=no,close=no");
}

function submitPrintForm()
{
	document.forms[1].submit();
}


 function checkSubmissions(evt) {

   var evt  = (evt) ? evt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13) && (node.type=="text")) {
	   	return false;
   	}
  }

function callback(instance, method) {
    return function() {
        method.apply(instance, arguments);
    }
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/**
 * Expands and collapses the defined dif
 */
function DivSwitcher(divID, imageTagID, expandImageURL, collapseImageURL) {
	this.STATE_EXPANDED = 0;
	this.STATE_COLLAPSED = 1;
	
	this.div = document.getElementById(divID);
	this.image= document.getElementById(imageTagID);
	this.expandImage = expandImageURL;
	this.collapseImage = collapseImageURL;
	this.state = this.STATE_EXPANDED;


	this.expand = function() {
		this.div.style.display = "block";
		this.image.src = this.collapseImage;
		this.state = this.STATE_EXPANDED;
	}
	
	this.collapse = function() {
		this.div.style.display = "none";
		this.image.src = this.expandImage;
		this.state = this.STATE_COLLAPSED;
		
	}

	this.updateState = function(event) {
		if(this.state == this.STATE_COLLAPSED) {
			this.expand();
		}
		else if (this.state == this.STATE_EXPANDED) {
			this.collapse();
		}
	}	
	this.image.onclick =  callback(this, this.updateState);
	
	this.setState = function(st) {
		this.state = st;
		this.updateState();
	}
}


function TipBox(id, width) {
	this.box = document.getElementById(id);
	this.triggers = new Object();
	
	//this.closeLink = document.createElement("A");
	//this.closeLink.setAttribute("href", "#");
	//this.closeLink.appendChild(document.createTextNode("Close"));
	
	// Default box style. Use getBox method to access the div component if you want to tweak these values
	this.box.style.position = "absolute"
	this.box.style.borderColor = "#808080";
	this.box.style.borderWidth = "2px";
	this.box.style.borderStyle = "solid";
	this.box.style.zIndex = "100";
	this.box.style.backgroundColor = "white";
	this.box.style.fontSize = "11px";
	this.box.style.width = width + "px";
	this.box.style.padding = "5px;"
	this.box.style.margin = "0px";
	this.box.style.display = "none";
	
	
	
	this.getBox = function() {
		return this.box;
	}
	
	
	this.setTipText = function(txt) {
		this.box.innerHTML = txt;
		//this.box.appendChild(this.closeLink);
		
	}
	
	this.show = function() {
		this.box.style.display = "block";
	}
	
	this.hide = function() {
		this.box.style.display = "none";
	}
	
	
	this.addTrigger = function(elementID) {
		var elem = document.getElementById(elementID);
		elem.onclick = callback(this, this.toggleTipBox);
		this.triggers[elementID] = elem;
	}
	
	this.toggleTipBox = function() {
		if(this.box.style.display == "none") {
			this.show();
		}	
		else {
			this.hide();
		}
	}
}



String.prototype.equalsIgnoreCase = function(str) {
	if( this && str) {
		var str_source = new String(this.toLowerCase().trim());
		var str_comp = new String(str.toLowerCase().trim());
		return (str_source == str_comp);
	}
	return fals;
}

 String.prototype.trim = function () {
     var s = this.replace(/^\s*/, "");
     return s.replace(/\s*$/, "");
  }
  
  function BrowserSniffer() {
  	this.IE = "ie";
  	this.FIREFOX = "firefox";
  	this.browser;
  	if (navigator.appVersion.indexOf("MSIE")!=-1){
  		this.browser = this.IE;
	}
	else if(navigator.userAgent.indexOf("Firefox")!=-1){
		this.browser = this.FIREFOX;
	}
	
	this.getBrowser = function() {
		return this.browser;
	}
	
	this.isFirefox = function() {
		if( this.browser == this.FIREFOX) {
			return true;
		}
		return false;
	}

	this.isIE = function() {
		if( this.browser == this.IE) {
			return true;
		}
		return false;
	}
}

function getCheckedRadioValue(rbutton) {
	if(!rbutton) {
		return "";
	}
	var length = rbutton.length;
	if(length == undefined)
		if(rbutton.checked) {
			return radioObj.value;
		}
		else {
			return "";
		}
	for(var i = 0; i < length; i++) {
		if(rbutton[i].checked) {
			return rbutton[i].value;
		}
	}
	return "";
}

function setRadioValue(rbutton, value) {
	if(!rbutton) {
		return;
	}
	var length = rbutton.length;
	if(length == undefined) {
		if(rbutton.value == value) {
			rbutton.checked = true;
		}
	}
	for(var i = 0; i < length; i++) {
		if(rbutton[i].value == value) {
			rbutton[i].checked = true;
			break;
		}
	}
}

/* Helper function to get X coordinate of the given element*/
function findX(element)
  {
    var xCoord = 0;
    if(element.offsetParent) {
        while(true) {
          xCoord += element.offsetLeft;
          if(!element.offsetParent) {
	            break;
          }
          element = element.offsetParent;
        }
    }
    else if(element.x) {
        xCoord += element.x;
    }
    return xCoord;
  }

/* Helper function to get Y coordinate of the given element*/
  function findY(element)  {
    var yCoord = 0;
    var height = element.offsetHeight;
    if(element.offsetParent) {
        while(true)    {
          yCoord += element.offsetTop;
          if(!element.offsetParent) {
            break;
          }
          element = element.offsetParent;
        }
    }
    else if(element.y) {
        yCoord += element.y;
        }
    return yCoord + height;
  }
  

  /**
   * Finds and highlights a string on the page where it's called
   */
 var TRange=null
 
function findString (str) {
 if (parseInt(navigator.appVersion)<4) return;
 var strFound;
 if (navigator.appName=="Netscape") {

  // NAVIGATOR-SPECIFIC CODE

  strFound=self.find(str);
  if (!strFound) {
   strFound=self.find(str,0,1)
   while (self.find(str,0,1)) continue
  }
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {

  // EXPLORER-SPECIFIC CODE

  if (TRange!=null) {
   TRange.collapse(false)
   strFound=TRange.findText(str)
   if (strFound) TRange.select()	
  }
  if (TRange==null || strFound==0) {
   TRange=self.document.body.createTextRange()
   strFound=TRange.findText(str)
   if (strFound) TRange.select()
  }
 }
 if (!strFound) alert ("String '"+str+"' not found!")
}


function toggleElement(id) {
	var elem = document.getElementById(id);
	if(elem) {
		if( elem.style.display == 'none') {
			elem.style.display = 'block';
		}
		else {
			elem.style.display = 'none';	
		}
	}
}

function noValidation() {
	var disableValidationElem = document.getElementById("disableValidation");
	disableValidationElem.value = "true";
}

function doValidation() {
	var disableValidationElem = document.getElementById("disableValidation");
	disableValidationElem.value = "false";
}
 