
// constants
var SUCCESS = 0;
var NO_IMAGES = 1;
var SOAP_ERROR = 2;
var NO_POSES = 3;
var INVALID_POSE = 4;
var MISSING_PARAM = 5;
var SITE_STUDIO = 0;
var SITE_CHURCH = 1;

// variables
var onsubmit_lookup_pose = false;

var error_messages = new Array();
error_messages[SUCCESS] = "Success!";
error_messages[NO_IMAGES] = "This does not appear to be a valid <strong>sitting</strong> number.  Please try again.";
error_messages[SOAP_ERROR] = "There was a problem validating your pose number.  Please try again.";
error_messages[NO_POSES] = "This images are not yet available for this sitting number.";
error_messages[INVALID_POSE] = "This does not appear to be a valid <strong>pose</strong> number.  Please try again.";
error_messages[MISSING_PARAM] = "Please submit a sitting number and pose number.";

// functions
function add_to_cart(product_form)
{
	if (onsubmit_lookup_pose)
	{
		var orderno = document.getElementById('sitting_number').value;
		var pose = document.getElementById('pose_number').value;
		document.getElementById('add_to_cart_status').style.display = "none";
		document.getElementById('add_to_cart_status').style.backgroundColor = "#EEEEEE";

		var pose_query = new Ajax();
		//pose_query.dbg = true;
		pose_query.url = "http://shop.olanmills.com/ax/pose_lookup.php";
		pose_query.post = "orderno=" + orderno + "&pose=" + pose + "&username=COPTIX";

		pose_query.complete = function(response)
		{
			// reset the status info
			document.getElementById('status_indicator').style.display = "none";
			document.getElementById('status_text').style.display = "none";
			document.getElementById('status_text').innerHTML = "";

			if (response == SUCCESS)
			{
				document.getElementById('add_to_cart_status').style.display = "none";
				product_form.submit();
			}
			else
			{
				document.getElementById('status_instructions').style.display = "block";
				document.getElementById('add_to_cart_status').style.backgroundColor = "#FFD0DC";
				document.getElementById('status_instructions').innerHTML = "<strong>ERROR:</strong> " + error_messages[response];
			}
		}

		pose_query.waiting = function()
		{
			document.getElementById('status_instructions').style.display = "none";
			document.getElementById('status_indicator').style.display = "block";
			document.getElementById('status_text').style.display = "block";
			document.getElementById('add_to_cart_status').style.display = "block";
			document.getElementById('status_text').innerHTML = "Validating pose number...";
		}

		pose_query.send();
	}
	else
	{
		product_form.submit();
	}
}


function check_for_panel(which_site)
{
	var which_site;
	if (check_for_panel.arguments.length > 0)
	{
		which_site = check_for_panel.arguments[0];
	}

	if (which_site != SITE_CHURCH)
	{
		var product_options_size = document.getElementById('product_options_size');
		var product_options_id = product_options_size.options[product_options_size.selectedIndex].value;

		for (i = 0; i < panel_array.length; i++)
		{
			if (panel_array[i] == product_options_id)
				{
					alert('Please note: Frames for 10x20 and 20x20 portraits must be purchased separately.');
				}
		}
	}

	return true;
}
