function populateDefaults(selector)
{
	control_counter = 0;
	$(selector).each(function (key, value){
		control_counter ++;
		if (typeof(default_array) != 'undefined'){
			var default_value = default_array[this.id];
			if (undefined == default_value) default_value = '';
			var item_value = this.value;
			if (!item_value) item_value = default_value;
			$(this).attr("defaultValue", default_value).val(item_value).addClass(item_value == default_value ? "emptyField" : "idleField");
		}
		if (control_counter == 1){
			if (undefined != $.validationEngine) $(this).closest('form').validationEngine();
			if (typeof(default_array) != 'undefined'){
				$(this).closest('form').submit(function(){
					$(selector).each(function (key, value){
						if (this.value == this.defaultValue && this.type != "hidden") this.value = '';
					});
				});
			}
		}
	});
}


function handleInputFocus(inputElement)
{
	element_id = inputElement.id;
	if (typeof(default_array) != 'undefined'){
		$(inputElement).removeClass("emptyField").removeClass("idleField").addClass("focusField");  
		if (inputElement.value == inputElement.defaultValue){
			inputElement.value = '';  
		}else{
			if(inputElement.type.substring(0, 6) != 'select') inputElement.select();
		}
	}

	if (undefined != $.validationEngine) $.validationEngine.closeToolTip(inputElement.id);
	
	help_exists = false;
	help_box = $('#helpMessage');
	if (typeof(help_array) != 'undefined') help_exists = element_id in help_array;
	
	if (help_box && help_exists){
		$('#helpMessageContent').attr('innerHTML', help_array[element_id]);
		eleOffset = $(inputElement).offset();
		help_box.css('left', (eleOffset.left + $(inputElement).width() + 130) + 'px').css('top', eleOffset.top + 'px').css('display', 'block');
	}
}

function handleInputBlur(inputElement)
{

	if (typeof(default_array) != 'undefined'){
		$(inputElement).removeClass("focusField").removeClass("idleField").removeClass("emptyField").addClass(
			(inputElement.value == inputElement.defaultValue || inputElement.value == '' ? "emptyField" : "idleField")
		);
		if (inputElement.value == '') inputElement.value = inputElement.defaultValue;  
	}
	
	element_id = inputElement.id;
	help_box = document.getElementById('helpMessage');
	if (help_box) help_box.style.display = 'none';
}


function copyBToS()
{
	//louise replaced: $('shipping_first_name').value = $F('billing_first_name'); <- conflicting with jquery modal window
	
	document.getElementById('shipping_first_name').value = document.getElementById('billing_first_name').value;
	document.getElementById('shipping_last_name').value = document.getElementById('billing_last_name').value;
	document.getElementById('shipping_address').value = document.getElementById('billing_address').value;
	document.getElementById('shipping_city').value = document.getElementById('billing_city').value;
	document.getElementById('shipping_state').value = document.getElementById('billing_state').value;
	document.getElementById('shipping_zip_code').value = document.getElementById('billing_zip_code').value;
	document.getElementById('shipping_phone').value = document.getElementById('billing_phone').value;

}

function copyBToSAdmin()
{
	var billing  = document.getElementById('billingForm');
	var shipping = document.getElementById('shippingForm');
	
	for (i=0; i<billing.childNodes.length; i++){
		if (billing.childNodes[i].nodeName == 'UL')
		{
			bUL = billing.childNodes[i];
		}
	}

	for (i=0; i<bUL.childNodes.length; i++){
		if (bUL.childNodes[i].tagName == 'LI' && bUL.childNodes[i].childNodes[0].nodeName != 'STRONG'){
			if (bUL.childNodes[i].childNodes[2].nodeName == 'INPUT' || bUL.childNodes[i].childNodes[2].nodeName == 'SELECT'){
				bFormEl = bUL.childNodes[i].childNodes[2];
			} else {
				bFormEl = bUL.childNodes[i].childNodes[1];
			}
			
			if ((bFormEl.tagName == "INPUT" || bFormEl.tagName == "SELECT") && bFormEl.id != "billing_email" && bFormEl.id != "billing_company_name"){
				bFormElId = bFormEl.id;
				if (sFormEl = document.getElementById(bFormElId.replace(/billing/, "shipping"))) {
					sFormEl.value = bFormEl.value;
				}
			}
		}
	}
}

