var formaction = "";

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(selectProduct);
addLoadEvent(createPopups);
addLoadEvent(fixformaction);

function selectProduct() {
    if (document.getElementById("productselect")) {
        var select = document.getElementById("productselect");
		var gobutton = select.parentNode.getElementsByTagName("a")[0];
		gobutton.onclick = function(){
			if(select.value!=0){
				location.href = select.value;
			}
			else{
				return false;
			}
		
		}
    }
}

function createPopups() {
	//get anchors
	var anchors = document.getElementsByTagName("a");
	//find anchors that should popup
	for(var i=0; i<anchors.length; i++){
		if(anchors[i].rel=="quote-popup")
		{
			//if rel is set to quote-popup then attach popup function
			anchors[i].onclick = quotePopup;
		}
	}
}

function quotePopup(){
	var screenWidth = Math.floor(screen.width*.9);
    var screenHeight = screen.height;
	window.open(this.href,"quoteWindow","status=1,scrollbars=1,toolbar=0,location=0,menubar=1,history=0,resizable=1,screenX=0,screenY=0,top=0,left=0,height="+screenHeight+",width="+screenWidth);
	return false;
}

function fixformaction(){
	formaction = document.forms[0].action;
	formaction = formaction.replace(":8081","");
	document.forms[0].action = formaction;
}