
  /**** Create Array Of Colors in Animated Block ******************/

    var Color_Array = new Array("0254A6","247AC7");    


  /**** "mouseOver" Function to Change the Color Of The Block *****/

  function change_Block_Color(td_Element) {   
    /* Doesn't Work In Firefox */
    td_Element.id = 1-td_Element.id; 
    td_Element.style.background = Color_Array[td_Element.id];
 
  }	

  /**** FUNCTION THAT POSTS THE VARIABLES FROM "index.php" to "view_products.php" *****/
  
  function click_Product(product_sup_id, product_t1_code,product_t1_desc,product_t2_code,product_t2_desc,product_t3_code,product_t3_desc) {   
    
    document.formSend.product_sup_id.value = product_sup_id;
    
    document.formSend.product_t1.value = product_t1_code;
    document.formSend.product_t2.value = product_t2_code;
    document.formSend.product_t3.value = product_t3_code;
    
    
    document.formSend.product_t1_desc.value = product_t1_desc;
    document.formSend.product_t2_desc.value = product_t2_desc;
    document.formSend.product_t3_desc.value = product_t3_desc;
    
    document.formSend.submit();
	}			
	
	function drawBlock() {
    document.write("<table width=\"477\" height=\"88\">");
    for (i=1; i < 4; i++) {
      document.write("<tr>");
      for (j=1; j < 17; j++) {
        random_Color = Math.floor(2*Math.random());
        document.write("<td id=\"" + random_Color + "\" onMouseOver=\"change_Block_Color(this)\" bgcolor=\"#" + Color_Array[random_Color] + "\" ></td>");			
      }
      document.write("</tr>")
    }
    document.write("</table>");  	
	}
	
	/* Add Option to SelectBox */
  function addSelectOption(selectbox,value,text)
  {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
  }
  
  /* Remove all options from selectbox */
  function removeAllOptions(selectbox)
  {
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
      selectbox.remove(i);
    }
  }
  
  /*Add array to SelectBox */
  function addArrToSelectBox(SelectBox,ArrId,ArrName)
  {       
    for (var i=0; i < ArrId.length;++i){
      eval('addSelectOption(document.frm.'+ SelectBox + ',"' + ArrId[i] + '","' +  ArrName[i] + '");');      
    }     
  }
  
  function productSelectBoxChange(selectBox)
  {
    var selectBoxId = selectBox.id;
    var selectBoxValue = selectBox.value;   
    
    var selectBoxL2_ProdInd = 0;
    var selectBoxL3_ProdInd = 0;
    
    if (selectBoxId == 'prodl1') {
      if (document.frm.prodl1.options[0].value == "-1") { document.frm.prodl1.remove(0);}
    
      /* Update Product Level 2 */
      removeAllOptions(document.frm.prodl2);
      for (var i=0; i < ArrProdL2_Value.length;++i){
        
        id = ArrProdL2_Value[i].split('`');                
        if (id[0] == selectBoxValue) {      
          eval('addSelectOption(document.frm.prodl2,"' + ArrProdL2_Value[i] + '","' +  ArrProdL2_Text[i] + '");');  
          selectBoxL2_ProdInd = 1;
        }       
      }   
      if (selectBoxL2_ProdInd == 0) {
        eval('addSelectOption(document.frm.prodl2,"NA","N/A");');  
      }  
      
      /* Update Product Level 3 */
      removeAllOptions(document.frm.prodl3);
      for (var i=0; i < ArrProdL3_Value.length;++i){
        
        id = ArrProdL3_Value[i].split('`');                
        if ((id[0] + '`'+ id[1]) == document.frm.prodl2.options[0].value) {      
          eval('addSelectOption(document.frm.prodl3,"' + ArrProdL3_Value[i] + '","' +  ArrProdL3_Text[i] + '");');  
          selectBoxL3_ProdInd = 1;
        }       
      }    
      if (selectBoxL3_ProdInd == 0) {
        eval('addSelectOption(document.frm.prodl3,"NA","N/A");');  
      }                      
    }
    
    if (selectBoxId == 'prodl2') {
      /* Update Product Level 3 */
      removeAllOptions(document.frm.prodl3);
      for (var i=0; i < ArrProdL3_Value.length;++i){
        
        id = ArrProdL3_Value[i].split('`');                
        if ((id[0] + '`'+ id[1]) == selectBoxValue) {      
          eval('addSelectOption(document.frm.prodl3,"' + ArrProdL3_Value[i] + '","' +  ArrProdL3_Text[i] + '");');  
          selectBoxL3_ProdInd = 1;
        }       
      }    
      if (selectBoxL3_ProdInd == 0) {
        eval('addSelectOption(document.frm.prodl3,"NA","N/A");');  
      }       
    }
      
    /* Determine Rollup Id */
    var rollupId;
    var selectBoxProdL1Opt =  document.frm.prodl1.options;
    var ProdL1selectedValue = selectBoxProdL1Opt[selectBoxProdL1Opt.selectedIndex].value;
    
    var selectBoxProdL2Opt =  document.frm.prodl2.options;
    var ProdL2selectedValue = selectBoxProdL2Opt[selectBoxProdL2Opt.selectedIndex].value;
    
    var selectBoxProdL3Opt =  document.frm.prodl3.options;
    var ProdL3selectedValue = selectBoxProdL3Opt[selectBoxProdL3Opt.selectedIndex].value;       
    
    if (ProdL3selectedValue == "NA") {
      if (ProdL2selectedValue == "NA") {
        idArrL1 = ProdL1selectedValue.split('`'); 
        rollupId = idArrL1[0];      
      }
      else {
        idArrL2 = ProdL2selectedValue.split('`'); 
        rollupId = idArrL2[1];
      }
    }
    else 
    {
        idArrL3 = ProdL3selectedValue.split('`'); 
        rollupId = idArrL3[2];
    }
    document.frm.rollupId.value = rollupId;        
  }  
    
  function validateAddNewSubmit() {
    var Errors = 0;
    var NumberToTest = document.frm.order.value;
    var IsFound = /^-?\d+$/.test(NumberToTest);
     
     /* Test Name */
    if (document.frm.name.value.split(' ').join('') == "") {
      document.getElementById("ErrName").innerHTML = "* Enter name";  
      Errors = 1;
    }     
    else {
      document.getElementById("ErrName").innerHTML = "&nbsp;";  
    }
     
    /* Test Selected Product Category */
    if (document.frm.prodl1.options[0].value == "-1") {
      document.getElementById("ErrCategory").innerHTML = "* Select category";     
      if (document.frm.rollupId.value == "") {
        Errors = 1;
      }
      document.frm.rollupId.value = "";
    }
    else {
      document.getElementById("ErrCategory").innerHTML = '&nbsp;';
    }    
          
    /* Test Sort Order */ 
    if (!IsFound) {
      document.getElementById("ErrOrder").innerHTML = '* Invalid number';   
      Errors = 1;   
    } 
    else {
      document.getElementById("ErrOrder").innerHTML = '&nbsp;';
    }       
    document.frm.error.value = Errors;            
  }
	
	

