// JavaScript Document

function selectQuantity(rack,selVal,qID)
{//Automatic select 1 in quantity, when choose the option
	oID = document.getElementById(rack)
	if (document.getElementById(qID).value == "0")
	{ 
	document.getElementById(qID).selectedIndex = 1;
	}
	if (selVal == "0")
	{
	document.getElementById(qID).selectedIndex = 0;
	}
}

function checkDropDown(rack,selVal,qID)
{
 
if (document.getElementById('qty').value == "0")
  {	
    alert("Please enter Quantity for Rack Frames before proceeding. For accessories only click on Rack Accessories from the left menu.");
	document.getElementById('qty').focus();
	document.getElementById(rack).selectedIndex = 0;
    return false;
  }

else if (document.getElementById(rack).options[document.getElementById(rack).selectedIndex].value == "0" && document.getElementById(qID).options[document.getElementById(qID).selectedIndex].value != "0")
  {	
	document.getElementById(qID).selectedIndex = 1;
	return false;
  } 
}

function checkDropDownQty(qtyID,selVal)
{
 var ok = true;
if (document.getElementById('qty').value == "0")
  {	
    alert("Please enter Quantity for Rack Frames before proceeding.");
	document.getElementById('qty').focus();
	document.getElementById(qtyID).selectedIndex = 0;
	ok = false
  }
else if (document.getElementById(selVal).options[document.getElementById(selVal).selectedIndex].value == "0")
  {	
    alert("Please select an item from the list before selecting the Quantity.");
	document.getElementById(selVal).focus();
	document.getElementById(qtyID).selectedIndex = 0;
	ok = false
  } 
else if (document.getElementById(selVal).options[document.getElementById(selVal).selectedIndex].value != "0" && document.getElementById(qtyID).options[document.getElementById(qtyID).selectedIndex].value == "0")
  {	
	document.getElementById(selVal).selectedIndex = 0;
	ok = false
  } 

  return ok
}

function enterNewOptionRack (select, field) {
//alert("slect is " + select)
  //alert("Please Enter the quantity on the text filed. If you want to change the quantity again, please select \" 5+ \" from the quantity list.")				  
  field.select = select
  if (select.style) {
    select.style.display = 'none';
	field.style.display = '';
  }
  field.focus();
 
}


function enterNewOption (select, field, option, sel) {

  var check;
  check = checkDropDownQty(select.id,option);
   
  if (check)
  {
  if (sel == "new")
  {
  //alert("Please Enter the quantity on the text filed. If you want to change the quantity again, please select \" more \" from the quantity list.")				  
  field.select = select
  if (select.style) {
    select.style.display = 'none';
	field.style.display = '';
  }
  field.focus();
  }
  }
  
}
function setNewOption (s,f) {

	oCombo = document.getElementById(s).name;
	oEditable = document.getElementById(f).value;
  	sel2 = oEditable;
	if(oEditable.value != "" && oEditable.value != "0" && IsNum(sel2)) {
		// Add new one
		document.getElementById(s)[0].value = "0";
		document.getElementById(s)[0].text = "";
		document.getElementById(s)[1].value = sel2;
		document.getElementById(s)[1].text = sel2;
		document.getElementById(s).selectedIndex = 1;
	}
	
	else
	{ 
		alert("The quantity you entered was not valid. Please enter a valid Number.")
		document.getElementById(s).selectedIndex = 0;
		document.getElementById(f).value = "";
	}
  
 	document.getElementById(f).style.display = 'none';
	document.getElementById(s).style.display = '';
 
}


function enterNewOptionAccessories(select, field) {

  //var check;
  //check = checkDropDownQty(select.id,option);
    sel = select.id
if (document.getElementById('qty').value == "0")
  {	
    alert("Please enter Quantity for Rack Frames before proceeding.");
	document.getElementById('qty').focus();
	document.getElementById(sel).selectedIndex = 0;
  }
  else if (select.value == "new")
  {
  //alert("Please Enter the quantity on the text filed. If you want to change the quantity again, please select \" more \" from the quantity list.")				  
  field.select = select
  if (select.style) {
    select.style.display = 'none';
	field.style.display = '';
  }
  field.focus();

  }
  
}

function checkOptions()
{
if (document.getElementById('mr').options[document.getElementById('mr').selectedIndex].value != "0" && document.getElementById('mrqty').options[document.getElementById('mrqty').selectedIndex].value == "0")
  {
  	alert("Please select Quantity for \" Mounting Rails\" option.")	
	document.getElementById('mrqty').focus();
	return false;
  }    

}//function
