function validateOnSubmit(spamVal) {
    var elem;
    var errs=0;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
    
    if (!validatePresents(document.forms.ContactForm.spam, 'inf_spam', spamVal)) errs += 1; 
    if (!validatePresent(document.forms.ContactForm.model,   'inf_model'))       errs += 1;
    if (!validatePresent(document.forms.ContactForm.addytype,'inf_addytype'))    errs += 1;
    if (!validateEmail  (document.forms.ContactForm.email,   'inf_email', true)) errs += 1; 
    if (!validateTelnr  (document.forms.ContactForm.phone,   'inf_phone', true)) errs += 1; 
    if (!validatePresent(document.forms.ContactForm.zip,     'inf_zip'))         errs += 1;
    if (!validatePresent(document.forms.ContactForm.state,   'inf_state'))       errs += 1;
    if (!validatePresent(document.forms.ContactForm.city,    'inf_city'))        errs += 1; 
    if (!validatePresent(document.forms.ContactForm.name,    'inf_name'))        errs += 1;

    if (errs>1)  {
    alert('There are '+ errs +' fields which need correction before sending');
    return false;
    }

    else if (errs==1) {
      alert('There is a field which needs correction before sending');
      return false;
     } else {
    	document.form.ContactForm.Submit.disabled=true;
    	document.form.ContactForm.Submit.value = 'Thank You!';
    	
    	return true;
     }
}


function validateOnSubmitUB(spamVal) {
    var elem;
    var errs=0;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.

    if (!validatePresents(document.forms.ContactForm.spam, 'inf_spam', spamVal)) errs += 1; 
    if (!validateEmail  (document.forms.ContactForm.email,   'inf_email', true)) errs += 1; 
    if (!validateTelnr  (document.forms.ContactForm.phone,   'inf_phone', true)) errs += 1; 
    if (!validatePresent(document.forms.ContactForm.zip,     'inf_zip'))         errs += 1;
    if (!validatePresent(document.forms.ContactForm.state,   'inf_state'))       errs += 1;
    if (!validatePresent(document.forms.ContactForm.city,    'inf_city'))        errs += 1; 
    if (!validatePresent(document.forms.ContactForm.name,    'inf_name'))        errs += 1;

    if (errs>1)  {
    alert('There are '+ errs +' fields which need correction before sending');
    return false;
    }

    else if (errs==1) {
      alert('There is a field which needs correction before sending');
      return false;
     } else {
    	document.form.ContactForm.Submit.disabled=true;
    	document.form.ContactForm.Submit.value = 'Thank You!';
    	
    	return true;
     }
}


// You can change the messages that are displayed in the Shadowbox from right here:

function displayM(addy){
	if(addy=="Residential"){var txt = "<div id='sb'><h4>Notice:</h4>Residential delivery is often approximately $75 more than the commercial rate. You can save by using a commercial address with a business name.</div>";}
	if(addy=="Commercial"){var txt = "<div id='sb'><h4>Notice:</h4>Commercial delivery is usually the best delivery option if you have a business with a commercial address. Save approximately $75 over the residential rate!</div>";}
	if(addy=="Terminal"){var txt = "<div id='sb'><h4>Notice:</h4>Terminal pickup is usually the best option if you do NOT have a business with a commercial address. Terminal pickup often offers about the same rate as the commercial rate and your cooker will be unloaded for you.</div>"}
	if(addy=="liftgate"){var txt = "<div id='sb'><h4>Notice:</h4>You have chosen to add a liftgate to the truck. Some of our cookers are too large for the liftgate and may be disabled in the models drop-down menu.</div>";}

    Shadowbox.open({
        player:     'html',
        content:    txt,
        height:     200,
        resizeDuration: 0,
        animate:	false,
        animateFade: false,
     // autoDimensions: true,
        width:      300
    });
}


function addystat(sel){
  	// Display Correct LightBox
  	displayM(sel);
  	
  	// Make sure the combination is correct
  	var lif = document.getElementById('liftgate')
  	if(sel == "Terminal") {
  		lif.disabled = true
  		lif.checked = false
  		removeModels();
  	} else {
  		lif.disabled = false
  		removeModels();
  	}
 }


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/	
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};


function removeModels(where){
	var dis = getElementsByClassName('lift')
	
	if(document.getElementById('liftgate').checked == false){
		for (var i=0; i<dis.length; ++i){
			dis[i].disabled = false
		}
	} else {
		if(where=="cb"){displayM('liftgate')};
		for (var i=0; i<dis.length; ++i){
			dis[i].disabled = true
		}
  	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function addRowToTable(targettbl)
{
  var tbl = document.getElementById(targettbl);
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  cellLeft.className = 'label';
  var textNode = document.createTextNode("Options:");
  cellLeft.appendChild(textNode);
  
  // right cell
  var cellRight = row.insertCell(1);
  var el = document.createElement('textarea');
  el.className = 'wide';
  el.name = 'options_' + iteration;
  el.id = 'options_' + iteration;
  el.size = 40;
  cellRight.appendChild(el);
  
  // select cell
 row.insertCell(2);
  
  var row2 = tbl.insertRow(lastRow);
  
  
    // left cell
  var cellLeft = row2.insertCell(0);
  cellLeft.className = 'label';
  var textNode = document.createTextNode("Model:");
  cellLeft.appendChild(textNode);
  
    // select cell
  var cellRightSel = row2.insertCell(1);
  var sel = document.createElement('select');
	sel.name = 'model_' + iteration;
	sel.options[0] = new Option('PR36', 'PR36');
	sel.options[1] = new Option('PR42', 'PR42');
	sel.options[2] = new Option('PR60', 'PR60');
	sel.options[3] = new Option('PR60G', 'PR60G');
	sel.options[4] = new Option('PR60T', 'PR60T');
	sel.options[5] = new Option('PR60GT', 'PR60GT');
	sel.options[6] = new Option('PR72', 'PR72');
	sel.options[7] = new Option('PR72G', 'PR72G');
	sel.options[8] = new Option('PR72T', 'PR72T');
	sel.options[9] = new Option('PR72GT', 'PR72GT');
	sel.options[10] = new Option('BBQ26', 'BBQ26');
	sel.options[11] = new Option('BBQ26S', 'BBQ26S');
	sel.options[12] = new Option('BBQ42', 'BBQ42');
	sel.options[13] = new Option('BBQ96', 'BBQ96');
	sel.options[14] = new Option('BBQ144', 'BBQ144');
	sel.options[15] = new Option('BBQ36', 'BBQ36');
	sel.options[16] = new Option('BBQ60', 'BBQ60');
	sel.options[17] = new Option('BBQ60G', 'BBQ60G');
	sel.options[18] = new Option('CD108', 'CD108');
	sel.options[19] = new Option('CD108G', 'CD108G');
	sel.options[20] = new Option('CD120', 'CD120');
	sel.options[21] = new Option('CD120G', 'CD120G');
	sel.options[22] = new Option('SQ36', 'SQ36');
	sel.options[23] = new Option('TS60', 'TS60');
	sel.options[24] = new Option('TS120', 'TS120');
	sel.options[25] = new Option('TS120P', 'TS120P');
	sel.options[26] = new Option('TS250', 'TS250');
	sel.options[27] = new Option('TS500', 'TS500');
	sel.options[28] = new Option('3 Bowl Stainless Steel Sink', '3BSSS');
	sel.options[29] = new Option('4 Bowl Stainless Steel Sink', '4BSSS');
	
	//Idetify the ones that have to be disabled...
	sel.options[6].className = "lift"
	sel.options[7].className = "lift"
	sel.options[8].className = "lift"
	sel.options[9].className = "lift"
	sel.options[13].className = "lift"
	sel.options[14].className = "lift"
	sel.options[18].className = "lift"
	sel.options[19].className = "lift"
	sel.options[20].className = "lift"
	sel.options[21].className = "lift"
	sel.options[24].className = "lift"
	sel.options[26].className = "lift"
	sel.options[27].className = "lift"
	sel.options[28].className = "lift"
	sel.options[29].className = "lift"
	
	
  cellRightSel.appendChild(sel);

  // Insert the last cell...
  row2.insertCell(2)
  
  // Make sure that all the new dropdowns have the items disabled...
  removeModels()
}


function addRowToUltimateTable(targettbl)
{
  var tbl = document.getElementById(targettbl);
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  cellLeft.className = 'label';
  var textNode = document.createTextNode("Options:");
  cellLeft.appendChild(textNode);
  
  // right cell
  var cellRight = row.insertCell(1);
  var el = document.createElement('textarea');
  el.className = 'wide';
  el.name = 'options_' + iteration;
  el.id = 'options_' + iteration;
  el.size = 40;
  cellRight.appendChild(el);
  
  // select cell
 row.insertCell(2);
  
  var row2 = tbl.insertRow(lastRow);
  
  
    // left cell
  var cellLeft = row2.insertCell(0);
  cellLeft.className = 'label';
  var textNode = document.createTextNode("Model:");
  cellLeft.appendChild(textNode);
  
    // select cell
  var cellRightSel = row2.insertCell(1);
  var sel = document.createElement('select');
	sel.name = 'model_' + iteration;
	sel.options[0] = new Option('PR36', 'PR36');
	sel.options[1] = new Option('PR42', 'PR42');
	sel.options[2] = new Option('PR60', 'PR60');
	sel.options[3] = new Option('PR60G', 'PR60G');
	sel.options[4] = new Option('PR72', 'PR72');
	sel.options[5] = new Option('PR72G', 'PR72G');
	sel.options[6] = new Option('BBQ26', 'BBQ26');
	sel.options[7] = new Option('BBQ26S', 'BBQ26S');
	sel.options[8] = new Option('BBQ42', 'BBQ42');
	sel.options[9] = new Option('BBQ96', 'BBQ96');
	sel.options[10] = new Option('BBQ144', 'BBQ144');
	sel.options[11] = new Option('BBQ36', 'BBQ36');
	sel.options[12] = new Option('BBQ60', 'BBQ60');
	sel.options[13] = new Option('BBQ60G', 'BBQ60G');
	sel.options[14] = new Option('CD108', 'CD108');
	sel.options[15] = new Option('CD108G', 'CD108G');
	sel.options[16] = new Option('CD120', 'CD120');
	sel.options[17] = new Option('CD120G', 'CD120G');
	sel.options[18] = new Option('SQ36', 'SQ36');
	sel.options[19] = new Option('TS60', 'TS60');
	sel.options[20] = new Option('TS120', 'TS120');
	sel.options[21] = new Option('TS120P', 'TS120P');
	sel.options[22] = new Option('TS250', 'TS250');
	sel.options[23] = new Option('TS500', 'TS500');
	sel.options[24] = new Option('3 Bowl Stainless Steel Sink', '3BSSS');
	sel.options[25] = new Option('4 Bowl Stainless Steel Sink', '4BSSS');
	
  cellRightSel.appendChild(sel);

  // Insert the last cell...
  row2.insertCell(2)
}