/* slider javascript for commercial power Power Vault page */
var dragObject, offsetX, offsetY, isDragging=false;
document.onmousemove = mM;
document.onmouseup = mU;

function set_cursur(slider)
{
	if (navigator.userAgent.toUpperCase().indexOf("MSIE") > -1)
		slider.style.cursor = "hand";
	else
		slider.style.cursor = "pointer";
}

function mD(ob,e) {
	dragObject = ob;
	
	if (window.event) e=window.event;
	
	var dragX = parseInt(dragObject.style.left);
	
	var mouseX = e.clientX;
	
	offsetX = mouseX - dragX;
	
	isDragging = true;
	
	return false;
}

function mM(e) {
	var ruler_width = 320;
	if (!isDragging) return;
	
	if (window.event) e=window.event;
	
	var newX = e.clientX - offsetX;
	if (newX > ruler_width)
		newX = ruler_width;
	else if (newX < 0)
		newX = 0;
		
	if (dragObject.id == "max_hp")
	{
		if ((newX * (highest_max_hp / ruler_width)) < min_hp)
		{
			document.getElementById("max_hp").style.left = ((min_hp * ruler_width) / highest_max_hp) + "px";
			max_hp = min_hp;
			Tip('<strong>MAX:</strong> ' + max_hp + ' HP');
		}
		else
		{
			dragObject.style.left = newX + "px";
			max_hp = newX * (highest_max_hp / ruler_width);
			max_hp = Math.round(max_hp * 10) / 10;
			Tip('<strong>MAX:</strong> ' + max_hp + ' HP');
		}
		document.powerform.max_horsepower.value = max_hp;
	}
	else if (dragObject.id == "min_hp")
	{
		if ((newX * (highest_max_hp / ruler_width)) > max_hp)
		{
			document.getElementById("max_hp").style.left = ((max_hp * ruler_width) / highest_max_hp) + "px";
			min_hp = max_hp;
			Tip('<strong>MIN:</strong> ' + min_hp + ' HP');
		}
		else
		{
			dragObject.style.left = newX + "px";
			min_hp = newX * (highest_max_hp / ruler_width);
			min_hp = Math.round(min_hp * 10) / 10;
			Tip('<strong>MIN:</strong> ' + min_hp + ' HP');
		}
		document.powerform.min_horsepower.value = min_hp;
	}
	
	var hp_range = document.getElementById("hp_range");
	//hp_range.innerHTML = min_hp + ' - ' + max_hp + ' HP';
	hp_range.childNodes[0].nodeValue = min_hp + ' - ' + max_hp + ' HP';
	
	return false;
}

function mU() {
	if (!isDragging) return;
	
	isDragging = false;
	
	sendRequest("set_specs.cfm", "min_horsepower=" + min_hp + "&max_horsepower=" + max_hp, "set_form_vals");
	
	return false;
}