function globalOnLoad() {
    // Assign link events
    for (var i = 0; i < document.links.length; i++) {
        if (document.links[i].className.match('External')) {
            document.links[i].onclick = function() { offsitePopup(this.href); return false; }
        }
        if (document.links[i].className.match('Enlargement')) {
            document.links[i].onclick = function() { enlargementPopup(this.href, this.title); return false; }
        }
    }

    // Run page onLoad function, if it exists
    if (typeof onLoad != 'undefined') {
        onLoad();
    }

}

function offsitePopup(url) {
    var popUp = window.open(url, 'offsiteWindow', 'width=750,height=500,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes');
    if (typeof popUp == 'object') {
        popUp.focus();
    }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function hover(img_name,img_src) {
	document[img_name].src=img_src;
}

function base(img_name,img_src) {
	document[img_name].src=img_src;
}

addLoadEvent(globalOnLoad);

function checkPriceBoundsmin(minPriceObj) {

	maxPriceObj = document.getElementById('maxPrice');
	var minPrice = parseInt(minPriceObj.options[minPriceObj.selectedIndex].value);
	var maxPrice = parseInt(maxPriceObj.options[maxPriceObj.selectedIndex].value);
	if(isNaN(maxPrice)) {
		maxPrice = 0;
	}
	var newSelected = false;

	var newMax = minPriceObj.options[minPriceObj.selectedIndex + 1].value;
	if(maxPrice > newMax) {
		newMax = maxPrice;
	}

	for (var i=1;i<minPriceObj.options.length; i++) {
		//"Enable" options which are less than the new max.
		if(parseInt(minPriceObj.options[i].value) > minPrice) {
			minPriceObj.options[i].style.color='#999999';  // set it grey
		} else if(parseInt(minPriceObj.options[i].value) <= newMax) {
			minPriceObj.options[i].style.color='#000000';
		} else {
			break;
		}
	}

	for (var i=maxPriceObj.options.length - 1;i>=0; i--) {
		if(parseInt(maxPriceObj.options[i].value) < minPrice) {
			maxPriceObj.options[i].style.color = '#999999';
			if(!newSelected && maxPrice < minPrice) {
				if( (i + 2) < maxPriceObj.options.length) {					
					if(maxPriceObj.selectedIndex != 0) {
						maxPriceObj.options[i + 2].selected = true;
					}
					newSelected = true;
				}
			}
		} else {
			maxPriceObj.options[i].style.color='#000000';
		}
	}

}

function checkPriceBoundsmax(maxPriceObj) {
	minPriceObj = document.getElementById('minPrice');

	var minPrice = parseInt(minPriceObj.options[minPriceObj.selectedIndex].value);
	var maxPrice = parseInt(maxPriceObj.options[maxPriceObj.selectedIndex].value);
	if(isNaN(minPrice)) {
		minPrice = 0;
	}

	for (var i=minPriceObj.options.length - 1;i>=0; i--) {
		if(parseInt(minPriceObj.options[i].value) >= maxPrice) {
			minPriceObj.options[i].style.color='#999999';
			if( minPrice > maxPrice) {
				minPriceObj.options[i - 1].selected = true;	
				minPriceObj.options[i - 1].style.color = '#000000';
			}
		} else if(parseInt(minPriceObj.options[i].value) >= minPrice) {
			minPriceObj.options[i].style.color='#000000';
		}
	}

}

function getHeight() {

	if (document.body.offsetHeight) { //ns6 syntax
		height = document.body.offsetHeight-191;
	} else if (document.body.scrollHeight) {  //ie5+ syntax
		height = document.body.scrollHeight-191;
	}

	if (height < 409) height = 448;
	
	document.getElementById("pageHeight").value = height;
	document.searchForm.submit();
}

