// Javascript utilities for VM Foundry "best practice" HTML forms
// This script should be included at the BOTTOM of form pages, right before the closing body tag,
// to ensure that the DOM is fully loaded.

// the URL of the "wait" animated gif
var waitImage = "/sites/all/themes/corepoint/images/waiting-loader.gif";







// When the doc initializes, do some things
function initDoc() {

	// preload "wait" image
	waitImagePreload = new Image(); 
	waitImagePreload.src = waitImage;

	// attach the replaceSubmitButton to the button HOLDER, not the button itself
	document.getElementById('myForm').onsubmit = submitForm;

	// hide the "pay by PO" div, if there is one
	var podiv = document.getElementById('payment_po');

	if(podiv) {
	podiv.style.display = 'none';
	}

}






// replace the submit button image with a "please wait" image.
function replaceSubmitButton() {
	
	document.getElementById('submit_button_holder').innerHTML = '<span class="form_wait_message"><img src="' + waitImage + '"> <p>Your information is being submitted. Please wait...</p></span>';
	
}





// submit the form
function submitForm() {

	replaceSubmitButton();
	return true;

}





function toggleBillingSection() {
	
	var checkbox = document.getElementById('billing_same');
	var onoff;
	var fieldbgcolor;
	var fieldtextcolor;
	
	if(checkbox.checked == true) {
		onoff=true;
		fieldbgcolor="#ebebeb";
		fieldtextcolor="#999999";
	} else {
		onoff=false;
		fieldbgcolor="#ffffff";
		fieldtextcolor="#333333";
	}
	
	var field1 = document.getElementById('billing_first_name');
	var field2 = document.getElementById('billing_last_name');
	var field3 = document.getElementById('billing_company');
	var field4 = document.getElementById('billing_address');
	var field5 = document.getElementById('billing_city');
	var field6 = document.getElementById('billing_state');
	var field7 = document.getElementById('billing_country');
	var field8 = document.getElementById('billing_zip');
	var field9 = document.getElementById('billing_phone');
	
	field1.disabled=onoff;
	field1.style.backgroundColor = fieldbgcolor;
	field1.style.color = fieldtextcolor;
	
	field2.disabled=onoff;
	field2.style.backgroundColor = fieldbgcolor;
	field2.style.color = fieldtextcolor;
	
	field3.disabled=onoff;
	field3.style.backgroundColor = fieldbgcolor;
	field3.style.color = fieldtextcolor;
	
	field4.disabled=onoff;
	field4.style.backgroundColor = fieldbgcolor;
	field4.style.color = fieldtextcolor;
	
	field5.disabled=onoff;
	field5.style.backgroundColor = fieldbgcolor;
	field5.style.color = fieldtextcolor;
	
	field6.disabled=onoff;
	field6.style.backgroundColor = fieldbgcolor;
	field6.style.color = fieldtextcolor;
	
	field7.disabled=onoff;
	field7.style.backgroundColor = fieldbgcolor;
	field7.style.color = fieldtextcolor;
	
	field8.disabled=onoff;
	field8.style.backgroundColor = fieldbgcolor;
	field8.style.color = fieldtextcolor;
	
	field9.disabled=onoff;
	field9.style.backgroundColor = fieldbgcolor;
	field9.style.color = fieldtextcolor;
	
}


function togglePaymentSection(whichmode) {
	
	var itemPO = document.getElementById('payment_po');
	var itemCC = document.getElementById('payment_cc');


            if (whichmode == 'PO') {
				itemPO.style.display = 'block';
            	itemCC.style.display = 'none';
            } else  {
          		itemCC.style.display = 'block';
				itemPO.style.display = 'none';
            }
   
   
}



// run the initdoc function
initDoc();

