
var DHTML = (document.getElementById || document.all || document.layers);

//-------------------------------------------------------------------------------------------------------------------------

function submitForm(form_name, form_action, form_task) {
	var form = document.forms[form_name];
	if (form_action) {
		form.action = form_action;
	}
	if (form_task) {
		form.task.value = form_task;
	}
	
	form.submit();
}

//-------------------------------------------------------------------------------------------------------------------------

function getObj(name) {
	if (document.getElementById) {
	      this.obj = document.getElementById(name);
	      this.style = document.getElementById(name).style;
	}
	else if (document.all) {
	      this.obj = document.all[name];
	      this.style = document.all[name].style;
	}
	else if (document.layers) {
	      this.obj = document.layers[name];
	      this.style = document.layers[name];
	}
}

//-------------------------------------------------------------------------------------------------------------------------

function swapImg() {
	this.node_to_update.src = this.image_directory + this.file_name;
	this.node_to_update.width = this.full_width;
	this.node_to_update.height = this.full_height;
}

//-------------------------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------------------------

//==================================================
// BEGIN FORM VALIDATION FUNCTIONS
//==================================================
function validateForm_BillShip(the_form) {
	
	var is_valid = true;	// we assume it is a valid form
	// custom code can be added to this fucntion if form specific actions are required
	
	// call the standard form validation function
	is_valid = validateForm(the_form);
	
	return is_valid;

}


//==================================================
// END FORM VALIDATION FUNCTIONS
//==================================================



//==================================================
// BEGIN BILL SHIP INFO 
//==================================================

var billInputs = new Array('fname', 'lname', 'address', 'address2', 'city', 'zip', 'phone');
var billSelects = new Array('state');
var shipInputs = new Array('shipFirst', 'shipLast', 'shipAddress', 'shipAddress2', 'shipCity', 'shipZip', 'shipPhone');
var shipSelects = new Array('shipState');


function fillShipInfo(obj) {
	if (obj.checked == true) {
		setShipInfo('bill');
	} else {
		setShipInfo('reset');
	}
}

//------------------------------------------------------------------------------------------------------------------------------------

function setShipInfo(data) {
	var form = document.orderForm;
	var limitInputs = billInputs.length;
	var limitSelects = billSelects.length;
	if(data == 'bill'){
		for(var x=0; x<limitInputs; x++) {
			form[ shipInputs[x] ].value = form[ billInputs[x] ].value;
		}
		for(var x=0; x<limitSelects; x++) {
			form[ shipSelects[x] ].options.selectedIndex = form[ billSelects[x] ].options.selectedIndex
		}
	}else{
		for(var x=0; x<limitInputs; x++) {
			form[ shipInputs[x] ].value = '';
		}
		for(var x=0; x<limitSelects; x++) {
			form[ shipSelects[x] ].options.selectedIndex = 0;
		}
	}
}

//==================================================
// END BILL SHIP INFO 
//==================================================


function validateComparisonForm(the_form) {
	var num_selected = 0;
	var limit = the_form.elements.length;
	for(x=0; x<limit; x++) {
		if (  (the_form.elements[x].type == 'checkbox')  &&  the_form.elements[x].checked  ) {
			num_selected++;
		}
	}
	
	if (num_selected > 3) {
		alert('You can only compare 3 items. Please deselect ' + (num_selected - 3) + ' item(s).' );
		return false;	
	} else if (num_selected < 2) {
		alert('You must select at least 2 items.' );
		return false;	
	}
	
	return true;
}

	