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 createEventListenerMethodReference(object, methodName) {
    return function (event) {
        object[methodName].call(object, event || window.event);
    };
}

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() {
		if(this.div) {
			this.div.style.display = "block";
		}
		if(this.image) {
			this.image.src = this.collapseImage;
		}
		this.state = this.STATE_EXPANDED;
	}
	
	this.collapse = function() {
		if(this.div) {
			this.div.style.display = "none";
		}
		if( this.image) {
			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();
		}
	}
	if(this.image) {	
		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 getRequestParam( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

  /**
   * Changes the cursor style of the given src element to "move"
   **/  
  function grab(src) {
  	src.style.cursor = 'move';
  }
  
   /**
   * Changes the cursor style of the given src element to "hand/pointer"
   **/  
  function point(src) {
  	src.style.cursor = 'hand';
  	src.style.cursor = 'pointer';
  }

  
  /**
   * Changes the cursor style of the given src element to "default"
   **/  
  function release(src) {
  	src.style.cursor = 'release';
  }
  
  function mouseOnClose( button ) {
	button.src='images/close_hover.gif';
	button.className = 'cursor_pointer'; 
}

function mouseOffClose(button) {
	button.src='images/close.gif'
	button.className = 'cursor_default';
}




function cubicWeight() {
	var trs = getElementsByClass("goods_row");
	for(var i=0; i<trs.length; i++) {
		var width = 0;
		var height = 0;
		var depth = 0;
		var inputs = trs[i].getElementsByTagName("INPUT");
		for(var idx=0; idx<inputs.length; idx++) {
			if( inputs[idx].id == "width") {
				width = inputs[idx].value;
			}
			else if( inputs[idx].id == "height") {
				height = inputs[idx].value;
			}
			else if( inputs[idx].id == "depth") {
				depth = inputs[idx].value;
			}
		}
		var cubicWeightSpan;
		var spans = trs[i].getElementsByTagName("SPAN");
		for(var idx=0; idx<spans.length; idx++) {
			if( spans[idx].id == "cubic_weight") {
				cubicWeightSpan = spans[idx];
			}
		}
		
		var cWeight = (width * height * depth)/divider;
		if( !cWeight ) {
			cubicWeightSpan.innerHTML = "0";
		}
		else {
			cubicWeightSpan.innerHTML = parseFloat(cWeight).toFixed(0);
			}
	}
}


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

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


   /**
   * Changes the cursor style of the given src element to "hand/pointer"
   **/  
  function point(src) {
  	src.style.cursor = 'hand';
  	src.style.cursor = 'pointer';
  }

  
  /**
   * Changes the cursor style of the given src element to "default"
   **/  
  function release(src) {
  	src.style.cursor = 'release';
  }


/* 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;
  }


function sortTrackingResults(sortOrder, headerId) {
	var sortActionElem = document.getElementById("sortAction");
	var sortOrderElem = document.getElementById("sortOrder");
	var sortHeaderIdElem = document.getElementById("sortHeaderId");
	sortActionElem.value = "sort";
	noValidation();
	sortOrderElem.value = sortOrder;
	sortHeaderIdElem.value = headerId;
	document.forms[0].submit();
}

function setSuburbSearch(val) {
	var searchMarker = document.getElementById("suburb_search");
	if(searchMarker) {
		searchMarker.value = val;
}
}

function imposeMaxLength(Event, Object, MaxLen) {
	return (Object.value.length <= MaxLen)||(Event.keyCode == 8 ||Event.keyCode==46||(Event.keyCode>=35&&Event.keyCode<=40))
}