/*
 JQUERY CUSTOM STUFF
*/

var successForForm = false;


jQuery(document).ready(
	function(){
		jQuery(".itemHiddenContent").hide();
		jQuery("#OrderForm_OrderForm_action_processOrder").click(
			function() {
				return confirm("Have you checked all your details? Submitting an order here means you can not make any further changes, do you want to continue?")
			}
		);
		jQuery(".itemShowMore").click(
			function() {
				jQuery(this).next().slideToggle();
			}
		);


		jQuery(".checkoutSectionShowMore").click(
			function() {
				var className = ".section" + jQuery(this).attr("rel")
				jQuery(".checkoutSection").slideUp();
				jQuery(className).slideDown();
				return false;
			}
		);
		if(orderProcessed == true) {
			jQuery(".checkoutSection").slideUp();
			jQuery(".section3").slideDown();
		}
		if(jQuery("#openLeftOrder").length > 0 && jQuery("#Email span.validation").length == 0) {
			//jQuery("#LeftOrder").hide();
			//jQuery("#OrderForm_OrderForm_action_processOrder").parent().hide();
			jQuery("#openLeftOrder").click(
				function() {
					jQuery("#LeftOrder").show(500,
						function() {
							jQuery("#OrderForm_OrderForm_action_processOrder").parent().show();
						}
					);
				}
			);
		}
		var options = {
			target:  '#formOutput',
			beforeSubmit:  showRequest,
			success: showResponse,
			dataType:  'script'
		}
		successForForm = false;
		jQuery("#OrderModifierForm_AdditionalFieldsModifier").ajaxForm(options);

		loadAjax('OrderInformation_Editable', 'home/ajaxGetCheckout/');
    // bind to the form's submit event

	}
);

function showResponse(responseText, statusText)  {
	jQuery("#formOutput").html("&nbsp;");
	if(successForForm) {
		jQuery(".checkoutSection").slideUp();
		jQuery(".section3").slideDown();
	}
	else {
		alert("Please complete all required fields and submit again.");
		return false;
	}
}


function showRequest(formData, jqForm, options) {
    // formData is an array; here we use $.param to convert it to a string to display it
    // but the form plugin does this for you automatically when it submits the data
    //var queryString = jQuery.param(formData);
    // jqForm is a jQuery object encapsulating the form element.  To access the
    // DOM element for the form do this:
    // var formElement = jqForm[0];
	jQuery("#formOutput").html("saving your data now... please wait");
	return true;
	/*
	var dataArray = new Array();
	var i = 0;
	for(i = 0; i < formData.length; i++) {
		alert(formData[i].name);
		array[formData[i].name] = formData[i].value;
		//formData[i].value = "china";
		var str = formData[i].name.substr(0,14);
		//alert(str);
		/*
		if (!formData[i].value) {
				alert('Please enter a value for both Username and Password');
				return false;
		}

	}
	//check if everything is there
	return true;
	*/
}


function statusMessage (a, b) {
	jQuery(".required").css("color", "red");
	successForForm = false;
}