/* Author: Gabe Shepard

*/

var RecaptchaOptions = { theme: 'blackglass' };

function displayGalleryItem(item) {
	var $dialog = $('#'+item);
	$('.flashcontainer').hide();
  $dialog.dialog({
	  modal: false,
    title: "View Item",
    width: 800,
		autoResize: true,
		hide: "fade",
		show: "fade",
		beforeClose: function(event, ui) {  $('.flashcontainer').show(); },
		buttons: [{ text: "Close", click: function() { $(this).dialog("close");  } }]
  }).show();

}

function displayCaptcha() {
	$('#captcha_div').dialog({
		modal: true,
		title: "CAPTCHA Check",
		width: 400,
		height: 200,
		hide: "fade",
		show: "fade"
	}).show();		
}

function submitSignup() {
	var name = $('#signup_name').val();
	var email = $('#signup_email').val();
	var zip = $('#signup_zip').val();
	var recaptcha_challenge_field = $('#recaptcha_challenge_field').val();
	var recaptcha_response_field = $('#recaptcha_response_field').val();
	
	$.post('/ajax.php', { 'action': 'submit_signup', 'name': name, 'email': email, 'zip': zip, 'recaptcha_challenge_field': recaptcha_challenge_field, 'recaptcha_response_field': recaptcha_response_field },
  function(response) {
		switch(response) {
			case 'SUCCESS':
				$('#captcha_div').dialog("destroy").hide();
        Recaptcha.destroy();
        showRecaptcha('captcha_container');
				$('#captcha_error_text').hide();
				$('#signup_success').dialog({
					modal: true,
					title: "",
					width: 400,
					height: 200,
					hide: "fade",
					show: "fade"
				}).show();		
				break;
			case 'CAPTCHAERROR':
				$('#captcha_div').dialog("destroy").hide();
        Recaptcha.destroy();
        showRecaptcha('captcha_container');
				$('#captcha_error_text').show();
				$('#captcha_div').dialog({
					modal: true,
					title: "CAPTCHA Check",
					width: 400,
					height: 300,
					hide: "fade",
					show: "fade"
				}).show();
				break;

			default:		
				alert(response);
		}
	});
}

function submitFlatRate() {
	var name = $('#name').val();
	var email = $('#email').val();
	var phone = $('#phone').val();
	var inquiry = $('#inquiry').val();
	var recaptcha_challenge_field = $('#recaptcha_challenge_field').val();
	var recaptcha_response_field = $('#recaptcha_response_field').val();
	
	$.post('/ajax.php', { 'action': 'submit_flat_rate', 'name': name, 'email': email, 'phone': phone, 'inquiry': inquiry, 'recaptcha_challenge_field': recaptcha_challenge_field, 'recaptcha_response_field': recaptcha_response_field },
  function(response) {
		switch(response) {
			case 'SUCCESS':
				$('#captcha_div').dialog("destroy").hide();
        Recaptcha.destroy();
        showRecaptcha('captcha_container');
				$('#captcha_error_text').hide();
				$('#signup_success').dialog({
					modal: true,
					title: "",
					width: 500,
					height: 500,
					hide: "fade",
					show: "fade"
				}).show();		
				break;
			case 'CAPTCHAERROR':
				$('#captcha_div').dialog("destroy").hide();
        Recaptcha.destroy();
        showRecaptcha('captcha_container');
				$('#captcha_error_text').show();
				$('#captcha_div').dialog({
					modal: true,
					title: "CAPTCHA Check",
					width: 500,
					height: 600,
					hide: "fade",
					show: "fade"
				}).show();
				break;

			default:		
				alert(response);
		}
	});
}

function popup(url, name, height, width) {
  window.open(url, name, 'height='+height+',width='+width+',scrollbars=yes');
}

function addToCart(id, quantity, media) {
	
	$.post('/ajax.php', { 'action': 'addtocart', 'id': id, 'quantity': quantity, 'media': media },
  function(response) {
		switch(response) {
			case 'SUCCESS':
        var $dialog = new jQuery('<div>Item added!</div>');
        $dialog.dialog({
	        modal: true,
          title: "Success",
          width: 400,
					hide: "fade",
					show: "fade",
					buttons: [{ text: "Close", click: function() { $(this).dialog("close");  } }],
          close: function() {
            $dialog.dialog("destroy");
            $dialog.hide();
  	      }
        }).show();
				break;
			case 'ERROR':
        var $dialog = new jQuery('<div>Sorry, an error has occurred!  The site administrator has been notified.</div>');
        $dialog.dialog({
	        modal: true,
          title: "Error!",
          width: 400,
					hide: "fade",
					show: "fade",
					buttons: [{ text: "Close", click: function() { $(this).dialog("close");  } }],
          close: function() {
            $dialog.dialog("destroy");
            $dialog.hide();
  	      }
        }).show();
				break;
			default:		
				alert(response);
		}
	});
}

