function same_as_billing()
{
	
	var checkbox_status = document.forms[0].elements['shippingsame'].checked;
	
	if ( !checkbox_status )
	{

/*		
		document.forms[0].elements['shippingname'].value = '';
		document.forms[0].elements['shippingaddress1'].value = '';
		document.forms[0].elements['shippingaddress2'].value = '';
		document.forms[0].elements['shippingcity'].value = '';
		document.forms[0].elements['shippingstate'].value = '';
		document.forms[0].elements['shippingzip'].value = '';
		document.forms[0].elements['shippingphone'].value = '';
		document.forms[0].elements['shippingemail'].value = '';
*/	
	}


	else
	{
	
		//document.forms[0].elements['shippingsame'].checked = checkbox_status;
		document.forms[0].elements['shippingname'].value = document.forms[0].elements['billingname'].value;
		document.forms[0].elements['shippingaddress1'].value = document.forms[0].elements['billingaddress1'].value;
		document.forms[0].elements['shippingaddress2'].value = document.forms[0].elements['billingaddress2'].value;
		document.forms[0].elements['shippingcity'].value = document.forms[0].elements['billingcity'].value;
		document.forms[0].elements['shippingstate'].value = document.forms[0].elements['billingstate'].value;
		document.forms[0].elements['shippingzip'].value = document.forms[0].elements['billingzip'].value;
		document.forms[0].elements['shippingphone'].value = document.forms[0].elements['billingphone'].value;
//		document.forms[0].elements['shippingemail'].value = document.forms[0].elements['billingemail'].value;
	
	}

}


// -----------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// -----------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
};



function validateOrderForm() {
	if (checkIfEmpty() == true && checkFrontSide() == true) {
	
		return true;
	}
	else {
		return false;
	}
	
	
}

// Checks to see if they entered any data at all.
// If not, they get a msg box asking why.
function checkIfEmpty() {
	
	
	var fields = new Array(5);
		
	fields[0] = trim(document.orderform.first.value);
	fields[1] = trim(document.orderform.middle.value);
	fields[2] = trim(document.orderform.last.value);
	fields[3] = trim(document.orderform.frontname.value);
	fields[4] = trim(document.orderform.backtext.value);
	
	
	var all = '';
	for(i = 0; i < fields.length; i++) {
		all = all + fields[i]
	}
	


	if (trim(all) == '') {
		if(!confirm('This bracelet has not been personalized with a custom engraving.')) {
			return false;
		}
		else {
			return true;
		}

	}
	else {
		return true;
	}

	
}

// Checks to see if the monogram fields AND the first name field have been filled out.
// Returns false if so, and shows error msg.
// Otherwise returns true.
function checkFrontSide() {

var first = trim(document.orderform.first.value);
var middle = trim(document.orderform.middle.value);
var last = trim(document.orderform.last.value);

var monogram = first+middle+last;

var frontname = trim(document.orderform.frontname.value);

if (monogram != '' && frontname != '') {
	location.hash = '#front';
	//document.orderform.first.focus();
	alert('Sorry, you can engrave a monogram OR a name on the front side of the bracelet, but not both. Fill out either the monogram fields or the name field and try again.');
	return false;
}


return true;

}



/* setVisibility(objId, sVisibility)
* Parameters: 
* objId - the id of an element (case sensitive)
* sVisibility - "visible" | "inherit" | "none" (case insensitive)
*
* USAGE: 
* Show div1:
* onclick='setVisibility("div1","visible")' 
*
* Inherit the visibility of div2's parentNode:
* onblur='setVisibility("div2", "inherit")' 
*
* Hide span3:
* onblur='setVisibility("span3", "hidden")'
*/          

function setVisibility(objId, sDisplay) {

        var obj = document.getElementById(objId);

         obj.style.display = sDisplay;
}




// Focuses on the first <input> or <select> field in the specified form
function focusForm(formId) {
var elements = (formId)
? document.getElementById(formId).getElementsByTagName('*')
: document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
var input = elements[i];
if (input.tagName.toLowerCase() == 'input' ||
input.tagName.toLowerCase() == 'select') {
input.focus();
break;
}
}
return true;
}


/*
// Focuses on the field 'nextFieldID' in form 'formID' when the calling field (currentFieldID)'s string length = 'length'.
function gotoNextField(formID, currentFieldID, nextFieldID, length) {
	var currentlength = myLengthCheck(formID, currentFieldID);
	if (currentlength == length) {
		eval('document.' + formID + '.' + nextFieldID + '.focus()');
	}
}



// Returns the string length of formID.fieldID
function myLengthCheck(formID, fieldID) {
	var currentlength = new String();
	eval('currentlength = ' + 'document.' + formID + '.' + fieldID + '.value.length');
	return currentlength;
}
*/


