// JavaScript Document
jQuery.noConflict();
jQuery(document).ready(function() {
	/*jQuery('').click(function(){
	
	});*/
	
	jQuery('.p-thickbox').click(function(){
		return false;
	});
	/*jQuery('.wpsc_buy_button').click(function(){
		alert("Sorry for the inconvenience, Purchase Transaction is temporarily unavailable. For more information, please contact us at (800)736-9805 or (847)294-5877 or email us at famanon@familiesanonymous.org");
		jQuery('#fancy_notification_content').append("<p class='donate_note'>Sorry for the inconvinience, Purchase Transaction is temporarily unavailable. For more information, please contact us at (800)736-9805 or (847)294-5877 or email us at <a href='famanon@familiesanonymous.org'>famanon@familiesanonymous.org</a></p>");
		jQuery('.products-page .tempo').remove();
		jQuery('.products-page').append("<p class='donate_note tempo'><br />Sorry for the inconvenience, Purchase Transaction is temporarily unavailable. For more information, please contact us at (800)736-9805 or (847)294-5877 or email us at <br /><br /><a href='famanon@familiesanonymous.org'>famanon@familiesanonymous.org</a></p>");
	});*/
	
	jQuery('#gocheckout').click(function(){
		//window.location = jQuery('.checkout-url').html();
		jQuery('#fancy_notification_content, #widget_fancy_note').html();
		jQuery('#widget_fancy_note').show('fast');
		jQuery('#widget_fancy_note').html("<img src='" + jQuery('.spin-wheel').html() + "' alt='spin-wheel' />&nbsp;Updating...");
		form_values = "wpsc_ajax_action=add_donate_amount&ajax=true";
		jQuery.post( 'index.php', form_values, function(returned_data) {
		if(returned_data.length < 87){
			window.location = jQuery('.checkout-url').html();
		} else {
			jQuery('#widget_fancy_note').html("<p class='donate_note'>Would you like to include a 7th Tradition Donation to your literature order?</p>" + returned_data + "<p class='donate_input_url'><a href='" + jQuery('.donate-url').html() + "' class='donate-yes'>Yes</a>&nbsp;<a href='" + jQuery('.checkout-url').html() + "' class='donate-no'>No, go to Checkout</a></p>");
			//<p class='donate_note'>Sorry for the inconvenience, Purchase Transaction is temporarily unavailable. For more information, please contact us at (800)736-9805 or (847)294-5877 or email us at <a href='famanon@familiesanonymous.org'>famanon@familiesanonymous.org</a></p>
			}
		});

		//jQuery('#widget_fancy_note').html("<p class='donate_note'>Would you like to include a 7th Tradition Donation to your literature order?</p>" + jQuery('.donation-btn').html() + "<p class='donate_input_url'><a href='" + jQuery('.donate-url').html() + "' class='donate-yes'>Yes</a>&nbsp;<a href='" + jQuery('.checkout-url').html() + "' class='donate-no'>No, go to Checkout</a></p>");
		
		jQuery('#widget_fancy_note').css({'min-height':'175px'});
		return false;
	});
	
	
	//alert(jQuery('.current_region').val() + " ");
	//alert(jQuery(".current_region option:selected").val());
	//jQuery('wpsc_checkout_form_8, .wpsc_checkout_form_11, wpsc_checkout_form_12, wpsc_checkout_form_13, wpsc_checkout_form_14, wpsc_checkout_form_15, wpsc_checkout_form_16, wpsc_checkout_form_17, wpsc_checkout_form_18').focus(function(){
																																																											 
	jQuery('#current_country').change(function(){
		countryCode = jQuery(this).val();
		var chkRegion = document.getElementById("region");
		if(chkRegion == null){
			jQuery('#current_country').after("<p><span id='region-text'>Select a State: </span><select name='region'  id='region' onchange='submit_change_country(); return false;' ></select></p>");
		}
		jQuery('#region-text').html("<span style='color:red;font-weight:bold;font-size:.85em;background:#e2e2e2;text-decoration:blink;'> Updating... </span>").show();
		form_values = "wpsc_ajax_action=get_shipping_state&ajax=true&country_code=" + countryCode;
		jQuery.post( 'index.php', form_values, function(returned_data) {
			//alert(returned_data.length);
			if(returned_data.length < 0){
				jQuery('#region').hide();
				jQuery('#region-text').html('Select a State: ').hide();
				//setTimeout(function(){ jQuery('input[title="shippingcountry"]').val(jQuery('#current_country').val()) }, 5000);
			} else {
				jQuery('#region').show();
				jQuery('#region-text').html('Select a State: ').show();
				jQuery('#region').html(returned_data);
				//setTimeout(function(){ jQuery('input[title="shippingcountry"]').val(jQuery('#current_country').val()) }, 5000);
			}
		});
	});
																																																											 
																																																											 	jQuery('.table-2 .text, #shippingSameBilling').focus(function(){
		if( (jQuery(".current_region option:selected").val() == -1 || jQuery(".current_region option:selected").val() == null) && jQuery('#current_country option:selected').val() == 'US' ){
			alert("Please select a Billing State...");
			jQuery('.current_region').focus().css({'color':'red'});
		} else {
			jQuery('.current_region').css({'color':'#000'});
		}
	});
	
	jQuery('.current_region').change(function(){
		jQuery('.double-check').html(' <= Check Shipping').css({'color':'red', 'font-size':'0.65em', 'text-decoration':'blink'});
	});
	jQuery('#region').change(function(){
		//alert(jQuery('select[title="billingstate"] option:selected').val() + " | " + jQuery('select[title="billingstate"] option:selected').text());
		//alert(jQuery('#region').val() + " | " + jQuery('#region option:selected').text());
		jQuery('input[title="shippingstate"]').val(jQuery('#region').val());
		jQuery('.shipping_region_name').html(jQuery('#region option:selected').text());
		jQuery('#shipquote_update').remove();
		jQuery('input[name="wpsc_submit_zipcode"]').after("<span id='shipquote_update' style='color:red;font-weight:bold;font-size:.85em;background:none;text-decoration:blink;'> <= Click to Update shipping..</span>");
	});
	jQuery('#zipcode').blur(function(){
		jQuery('input[title="shippingpostcode"]').val(jQuery(this).val());
		jQuery('#shipquote_update').remove();
		jQuery('input[name="wpsc_submit_zipcode"]').after("<span id='shipquote_update' style='color:red;font-weight:bold;font-size:.85em;background:none;text-decoration:blink;'> <= Click to Update shipping..</span>");
	});
																																																												
	//alert(jQuery('select[title="billingstate"] option:selected').text());
	//jQuery('input[title="billingpostcode"]').val(jQuery('#zipcode').val());
	jQuery('input[title="shippingpostcode"]').val(jQuery('#zipcode').val());
	jQuery('input[title="shippingstate"]').val(jQuery('#region').val());
	jQuery('.shipping_region_name').html(jQuery('#region option:selected').text());
	//jQuery('.shipping_region_name').html(jQuery('select[title="billingstate"] option:selected').text());
	//jQuery('select[title="billingstate"] option[value="'+jQuery('#region').val()+'"]').attr('selected', 'selected');
	//jQuery('input[title="shippingcountry"], input[title="billingcountry"]').val(jQuery('#current_country').val().attr('selected', 'selected'));
	jQuery('#shippingSameBilling').click(function(){
		if(jQuery(this).attr('checked') == 'checked'){
			//alert(jQuery('#region').val());
			jQuery('.same_as_info').show();
			var billCountry =  jQuery('select[title="billingcountry"]').val();
			var shipCountry =  jQuery('#current_country').val();
			var billCity =  jQuery('select[title="billingstate"]').val();
			var shipCity =  jQuery('#region').val();
			var isShipping = document.getElementById("ups_0");
			if(billCity == null){
				if( billCountry == shipCountry  && isShipping != null ){
				} else {
					if( isShipping == null ){
					} else {
						jQuery('.same_as_info').html("*** Please click the CALCULATE Button <br />to re-calculate Shipping Rates  **</span>");
					}
				}				
			} else {
				if( billCity == shipCity && billCountry == shipCountry  ){
				} else {
					if( isShipping == null ){
					} else {
				jQuery('.same_as_info').html("**** Please click the CALCULATE Button <br />to re-calculate Shipping Rates  **</span>");
					}
				}
			}
			//jQuery('#current_country option[value="'+jQuery('select[title="billingcountry"]').val()+'"]').attr('selected', 'selected');
			//jQuery('#zipcode').val(jQuery('#wpsc_checkout_form_8').val());
			//jQuery('#region').remove();
			//jQuery('#zipcode').val(jQuery('input[title="billingpostcode"]').val());
			//jQuery('#region').val(jQuery('select[title="billingstate"]').val()).attr('selected', 'selected');
			//jQuery('#current_country').val(jQuery('select[title="billingcountry"]').val());
			//jQuery('.same_as_shipping_row td').append("<span class='wpsc_change_country' style='color:red;font-weight:bold;background:#e2e2e2;text-decoration:blink;'>** Please click the CALCULATE Button <br />to re-calculate Shipping Rates  **</span>");
			//jQuery('#zipcode').focus();
			//
		} else {
			jQuery('.same_as_info').hide();
		}
		//jQuery(this).attr('checked', false);
		//alert(jQuery('#region').val());
		jQuery('.billing_instructions').toggle('fast');
	});

	jQuery('.current_region, .current_country').mouseout(function(){
		jQuery('.double-check').html(" <= Check Shipping");
		jQuery('.double-check').css({'color':'red', 'font-size':'.65em', 'font-weight':'normal', 'text-decoration':'blink'});
	});
	
	var gatewayValue = jQuery(".custom_gateway:checked").val();
	if(gatewayValue == "wpec_auth_net"){
		jQuery('.paymentType').show('fast');
	}


});

function goToCheckout(param){
	//alert("Donation Alert Window: goToCheckout function");
	jQuery('#fancy_notification_content, #widget_fancy_note').html();
	jQuery('#fancy_notification_content').html("<img src='" + jQuery('.spin-wheel').html() + "' alt='spin-wheel' />&nbsp;Updating...");
	form_values = "wpsc_ajax_action=add_donate_amount&ajax=true";
	jQuery.post( 'index.php', form_values, function(returned_data) {
		if(returned_data.length < 87){
			window.location = jQuery('.checkout-url').html();
		} else {
			jQuery('#fancy_notification_content').html("<p class='donate_note'>Would you like to include a 7th Tradition Donation to your literature order?</p>" + returned_data + "<p class='donate_input_url'><a href='" + jQuery('.donate-url').html() + "' class='donate-yes'>Yes</a>&nbsp;<a href='" + jQuery('.checkout-url').html() + "' class='donate-no'>No, go to Checkout</a></p>");
		}
	});

	//jQuery('#fancy_notification_content').html("<p class='donate_note'>Would you like to include a 7th Tradition Donation to your literature order?</p>" + jQuery('.donation-btn').html() + "<p class='donate_input_url'><a href='" + jQuery('.donate-url').html() + "' class='donate-yes'>Yes</a>&nbsp;<a href='" + jQuery('.checkout-url').html() + "' class='donate-no'>No, go to Checkout</a></p>");
}

function goToCheckoutWidget(param){
	//alert("Donation Alert Window: goToCheckout function");
	//window.location = jQuery('.checkout-url').html();
	jQuery('#fancy_notification_content, #widget_fancy_note').html();
	jQuery('#widget_fancy_note').html("<img src='" + jQuery('.spin-wheel').html() + "' alt='spin-wheel' />&nbsp;Updating...");
	form_values = "wpsc_ajax_action=add_donate_amount&ajax=true";
	jQuery.post( 'index.php', form_values, function(returned_data) {
		if(returned_data.length < 87){
			window.location = jQuery('.checkout-url').html();
		} else {
			jQuery('#widget_fancy_note').html("<p class='donate_note'>Would you like to include a 7th Tradition Donation to your literature order?</p>" + returned_data + "<p class='donate_input_url'><a href='" + jQuery('.donate-url').html() + "' class='donate-yes'>Yes</a>&nbsp;<a href='" + jQuery('.checkout-url').html() + "' class='donate-no'>No, go to Checkout***</a></p>");
		}
	});

	//jQuery('#widget_fancy_note').html("<p class='donate_note'>Would you like to include a 7th Tradition Donation to your literature order?</p>" + jQuery('.donation-btn').html() + "<p class='donate_input_url'><a href='" + jQuery('.donate-url').html() + "' class='donate-yes'>Yes</a>&nbsp;<a href='" + jQuery('.checkout-url').html() + "' class='donate-no'>No, go to Checkout</a></p>");
	jQuery('#widget_fancy_note').css({'min-height':'175px'});
}
