// this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {
 
    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
          var ths = trs[i].getElementsByTagName("th");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
          
          // and iterate through them...
          for (var j = 0; j < ths.length; j++) {
        
            var myth = ths[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(myth) &&
                ! myth.style.backgroundColor) {
        
              myth.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }

          
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }
  
  function checkoutForm() {
  	var error = '';
  	var typeValue = Form.getInputs('checkout_form','radio','payment_terms').find(function(radio) { return radio.checked; }).value;
  	
  	alert('cc_type = ' + $('cc_type').value);
  	return false;
  	
  	if (typeValue == 'CC') {
  		if ( $('cc_type').value == '' || $('cc_name').value == '' || $('cc_num').value == '' || $('cc_code').value == '') {
  			var error = 'Please fill in all your Credit Card information.';
  			alert(error);
  			return false;
  		}
  	}
  	
  	if ( $('ship_to_name').value == '' || $('ship_to_address').value == '' || $('ship_to_city').value == '' || $('ship_to_state').value == '' || $('ship_to_zip').value == '') {
  		var error = 'Please fill in all required shipping fields. Click "Same as Billing" if going to billing address.';
  		alert(error)
  		return false;
  	}
  	
  	return true;
  	
  }
  
  function clearSearch(searchField) {
  	if (searchField == 'searchMain') {  
	  	$('searchField').value = '';
	} else if (searchField == 'searchCat') {
		$('searchCat').value = '';
	} else if (searchField == 'oneClickField') {
		$('oneClickField').value = '';
	}
  }
  
  function fillOneClick(inputValue) {
  	$('oneClickField').value = inputValue;
  }
  
  function returnSearch() {
  	$('searchField').value = 'search website';
  }
  
  
	function OnSubmitForm()
	{
		var buttonValue = document.pressed;
		var is_delete = document.pressed.indexOf('Delete|');
					
		if(buttonValue == 'Update Quantities')
		{
			document.shopping_cart.action ="/cart";
  		} else if ( is_delete == 0) {
  			var deleteKey = buttonValue.split('|');
  			//alert(deleteKey[1]);
  			window.location = "https://www.olympiachimney.com/cart/remove/" + deleteKey[1];
  			return false;
  			//document.shopping_cart.delval.value = deleteKey[1];
  			//document.shopping_cart.action = "/cart/remove/" + deleteKey[1];
		}
	
		return true;
	}
	
	function OnSubmitFormB()
	{
		var buttonValue = document.pressed;
		var is_delete = document.pressed.indexOf('Delete|');
					
		if(buttonValue == 'Update Quantities')
		{
			document.shopping_cart.action ="/cart/index_test";
  		} else if ( is_delete == 0) {
  			var deleteKey = buttonValue.split('|');
  			//alert(deleteKey[1]);
  			window.location = "https://www.olympiachimney.com/cart/remove/" + deleteKey[1];
  			return false;
  			//document.shopping_cart.delval.value = deleteKey[1];
  			//document.shopping_cart.action = "/cart/remove/" + deleteKey[1];
		}
	
		return true;
	}
	


	function trigger(header) {
		var body = $(header.id+'Body');
		var h3 = $(header.id+'H3');
		if(body.hasClassName('bodyClosed'))
		{
			// open
			new Effect.BlindDown(body);
			body.addClassName('bodyOpen');
			body.removeClassName('bodyClosed');
			h3.addClassName('arrowdown');
			h3.removeClassName('arrow');
		}
		else
		{
			// close
		new Effect.BlindUp(body);
		body.addClassName('bodyClosed');
		body.removeClassName('bodyOpen');
		h3.addClassName('arrow');
		h3.removeClassName('arrowdown');
		}
	}
	
	function checkComments(formid) {
		//alert(formid);
		var comments = $('comment_enter').value;
		//alert(comments);
		if ( comments != '') {
			document.forms[formid].comments.value = comments;
			//document.formid.comments = comments;
		}
		return true;
	}


  function checkVentis() {
		//alert(formid);
		var liner = $('liner').value;
		//alert(comments);
		if ( liner == 'Ventis Class-A Chimney System 304L Inner Pipe' || liner == 'Ventis Class-A Chimney System 316L Inner Pipe') {
		  $('insulation').value = 'None';
			$('insulation').disabled = true;
			//document.formid.comments = comments;
		} else {
		  $('insulation').disabled = false;
		}
		return true;
	}
	
	function checkForm_Warranty() {
    
    $('insulation').disabled = false;
    return true;
    
  }
	
