
/*

Event.observe(window,'load', initLightbox);

$('hoverNav').observe('click', function () {
    $('lightbox').remove();
});


*/
var numInCart = 0;

Event.observe(window, 'load', function(){

		
		var args_serialized	= 'page_title='+document.title;		
		
		if($('Cart')) {
				new Ajax.Updater(
					{success: 'Cart'},
					'/store/aj_mini_cart.php',
					{
						method: 'get',
						parameters: args_serialized,
						onFailure: function(){ alert('Could not get mini cart!') 
						}
					}
				);
		}
});

Event.observe(window, 'load', function(){
		if($('mycart')) {
				var args_serialized	= 'page_title='+document.title;		
				new Ajax.Updater(
					{success: 'mycart'},
					'/store/aj_my_cart.php',
					{
						method: 'get',
						parameters: args_serialized,
						onFailure: function()	{ 
							alert('Could not get full cart!');
						}
					}
				);
		}
});


Event.observe(window, 'load', function () {
	
	if ( $('test-accordion') ) 
	{
		var accordionpanes  = $A($$('.accordion-content'));
		var	accordioncount	= 0;
		
		accordionpanes.each(function(accordion) {
			var accordion_id = accordion.id;
	
			if ( accordioncount > 0 ) 
				$(accordion_id).hide();
			else 
				$('at_shipping_1').addClassName('accordion-toggle-active');
			
			
			accordioncount++;
		});
	}

	if($('add_to_cart')) 
	{ 
    $('add_to_cart').observe('click', function() {
    		
    		
        //add the amount to cart - check any options if the item is complex
        if(IsNumeric($F('quantity')))
        {
        	var qty = $F('quantity');
            //get complexity if it's set right here
          	var args_serialized = $('wrap_product_form').serialize();
            //do ajaxy goodness    
            //alert(args_serialized);
            new Ajax.Request('/store/aj_add_to_cart.php', { 
            		method: 'get', 
            		parameters: args_serialized, 
            		onFailure: function(){ 
            			alert('Could not add to cart! Please try again!');
            		},
            		onComplete: function () {
			            new Ajax.Updater({success: 'Cart'},'/store/aj_mini_cart.php',{onFailure: function(){ alert('Could not get mini cart from add!') }});
			            $('wrap_mini_cart').show();
			            qty++; qty--;
			            numInCart = numInCart + qty;
			            $('added_to_cart').highlight().show().innerHTML = numInCart + " added to cart!";
			            
			            //setTimeout("$('added_to_cart').hide();", 500);
			            /*new Effect.Fade('added_to_cart', { duration: 2.0, 
			            		afterFinish: function() { 
			            				$('added_to_cart').innerHTML = ""; 
			            				$('added_to_cart').show(); }  }); */
			            				
									if ( $('wrap_continue_link') )	$('wrap_continue_link').show();
            		}
            });     
      
            $('quantity').value = 1;
        }
        else
            alert('Please insert only numeric values in the Quantity box.');
    });
	}



	var productImgs = $A($$('.prod_footer_pics'));

	productImgs.each(function(productImg) {
			//alert($(productImg).src);
			$(productImg).observe('mouseover', function () {
					var revimg  = $('prod_main_id').src;
					var imgsrc  = $(productImg).src; 
					$('prod_main_id').src = imgsrc;
					$('main_pic_box').href = imgsrc;
					$(productImg).src = revimg;
					$(productImg).href = revimg;
					//$('prod_main_id').setAttribute({'href': imgsrc});
					//alert(imgsrc); 
			});

	});


	if($('show_hide_cart')){
    $('show_hide_cart').observe('click', function() {
      if (!$('cart_items').visible()) {
      			$('show_hide_cart').innerHTML = 'hide';
            new Effect.BlindDown($('cart_items'));
           // $('hs').innerHTML = "-";
        }
    });
    $('show_hide_cart').observe('click',function() {
        if ($('cart_items').visible()) {
        		$('show_hide_cart').innerHTML = 'show';
            new Effect.BlindUp($('cart_items'));
           // $('hs').innerHTML = "+";
        }
    });
	}



	
	/*
	if ( $('wrap_mini_cart') )
	{
		var li_items	= $A($$('.li_cart_item'));
		
		li_items.each(function (li_item) {
			var li_item_id	= li_item.id;
			
			alert(li_item_id);
		
		});
	}
	*/



	if( $('search_box') ) {
    $('search_box').observe('keyup', function() {
    	//do the ajax call for the search bawks
    	var searchtxt = $('search_box').value;
    	if(searchtxt != '')
    	{
        	var ajax = new Ajax.Updater({success: 'search_suggest'},'/store/aj_search_suggest.php',{method: 'get', parameters: {search: searchtxt}, onFailure: function(){ alert('Could not suggest!') }});     
    		$('search_suggest').setStyle({display: 'inline'});
    		if($('search_suggest').innerHTML == '') //this forces the user to put in two letters before it works for some reason
    			$('search_suggest').setStyle({display: 'none'});
    	}
    	else
    	{
    		$('search_suggest').innerHTML = '';
    		$('search_suggest').setStyle({display: 'none'});
    	}
    });
	}

	if($('calc_ship')){ 
    $('calc_ship').observe('click', function() {
    
    	$('shipping_cost').innerHTML = "<center>Loading Shipping Calculation <br /><br /> <img src='/gather/ajax-loader.gif'></center>";
    	//do the ajax call for the search bawks
    	var fn = $('fn').value;
    	var ln = $('ln').value;
    	var street 	= $('street').value;
    	var city 		= $('city').value;
    	var state 	= $('state').value;
    	var zip 		= $('zip').value;
    	var apt 		= '';
    	apt 				= $('apt').value;
    	var type_str = $('type').value;
    	
    	if(IsNumeric(zip))
    	{
				if(street != '' && city != '' && state != '' && zip != '')
				{
						new Ajax.Updater({success: 'shipping_cost'},'/store/aj_calc_ship.php',{method: 'get', parameters: {fn: fn, ln: ln, street: street, apt: apt, city: city, state: state, zip: zip, type: type_str}, onFailure: function(){ alert('Could not calculate shipping!') }});     
					
				}
				else
				{
					//display message to the user for not filling in all the values
					$('shipping_cost').innerHTML = "<span class='card_errors'>Please correct your shipping address and submit again.</span>";
				}
			}
			else
			{
					//display message to the user for not filling in all the values
					$('shipping_cost').innerHTML = "<span class='card_errors'>Please correct your zip code and submit again.</span>";
			}

    });
 
    }


//TESTING FOR NEW CHECKOUT!!!!!
	if($('step_one')){ 
    $('step_one').observe('click', function() {
    	
    	//$('shipping_cost').innerHTML = "<center>Loading Shipping Calculation <br /><br /> <img src='/gather/ajax-loader.gif'></center>";
    	//do the ajax call for the search bawks
    	var fn = $('fn').value;
    	var ln = $('ln').value;
    	var street 	= $('street').value;
    	var city 		= $('city').value;
    	var state 	= $('state').value;
    	var zip 		= $('zip').value;
    	var apt 		= '';
    	apt 				= $('apt').value;
    	//var type_str = $('type').value;
    	var b_fn 			= $('c_fn').value;
    	var b_ln 			= $('c_ln').value;
    	var b_email 	= $('c_email').value;
    	var b_street 	= $('c_street').value;
    	var b_apt 		= $('c_apt').value;
    	var b_city 		= $('c_city').value;
    	var b_state 	= $('c_state').value;
    	var b_zip 		= $('c_zip').value;
    	var phone 	  = $('c_phone').value;

    	if(IsNumeric(zip) && street != '' && city != '' && state != '' && zip != '' && b_street != '' && b_city != '' && b_state != '' && b_zip != '' && emailCheck(b_email))
    	{
			//process the ship 
			//	$('at_shipping_2').innerHTML = "<center><br /><br /><br />Preparing Next Step <br /><img src='/gather/ajax-loader.gif'><br /><br /></center>";
			
			$('cont_2').innerHTML = "<span style='float:right; margin-right: 15px;'><center>Processing... <img src='/gather/ajax-loader.gif'></center></span>";
			$('button_1').setStyle({display: 'none'});
				new Ajax.Request('/store/aj_ship_bill_prep.php', {
							method: 'get', 
							parameters: {fn: fn, ln: ln, street: street, apt: apt, city: city, state: state, zip: zip, 
														b_fn: b_fn, b_ln: b_ln, b_email:b_email, b_street: b_street, b_apt: b_apt, b_city: b_city,
														b_state: b_state, b_zip:b_zip, phone:phone},
							onComplete: function (transport) {
								//in here see what needs to be done
								
								var aj_process		= transport.responseText;
								var regex_pattern = new RegExp('error');
								
								if( regex_pattern.test(aj_process))
								{
							
								  $('shipping_error').innerHTML = "<span class='card_errors'>Please correct your zip code!</span>";
								  $('button_1').setStyle({display: 'inline'});
							    $('cont_2').innerHTML = '';
								}
						    else
						    {
								  $('shipping_total_info').innerHTML = aj_process;
								  next_step("at_summary", "at_shipping"); 
								  $('button_1').setStyle({display: 'inline'});
							      $('cont_2').innerHTML = '';
							      $('shipping_error').innerHTML = "";
							  }
							}//,
							//onFailure: function(){ alert('Could not process card at this time!'); }
				});
			}
			else //tell them what was jacked up
			{
				$('shipping_error').innerHTML = "<span class='card_errors'>Please fill out the form completely. <br />(Name, Email, Address)</span>";	
			}
    });
    }


//END TESTING FOR NEW CHECKOUT!!!!

    if($('submit_payment')){ 
    $('submit_payment').observe('click', function() {
    	
    	//var formdata = $('complex_select').serialize();
    	
    	//do the ajax call for the search bawks
    	var go_int 	= 1;
    	var fn 			= $('c_fn').value;
    	var ln 			= $('c_ln').value;
    	var email 	= $('c_email').value;
    	var street 	= $('c_street').value;
    	var apt 		= $('c_apt').value;
    	var city 		= $('c_city').value;
    	var state 	= $('c_state').value;
    	var zip 		= $('c_zip').value;
    	var card 		= $('c_card').value;
    	var exp_m 	= $('c_exp_m').value;
    	var exp_y 	= $('c_exp_y').value;
    	var cv 			= $('c_cv').value;
    	
    	
    	if($('member'))
    		var member = $('member').value;
    	else
    		var member = 'no';
    	//need to make sure all the fields are entered
    	if(fn == '') {
    		$('card_errors').innerHTML += 'Please enter the first name of the card holder!<br /><br />'; go_int = 0; }
    	if(ln == ''){
    		$('card_errors').innerHTML += 'Please enter the last name of the card holder!<br /><br />'; go_int = 0; }
    	if(email == ''){
    		$('card_errors').innerHTML += 'Please enter a valid email address for the reciept!<br /><br />'; go_int = 0; }
    	if(street == ''){
    		$('card_errors').innerHTML += 'Please enter the street address of the card holder!<br /><br />'; go_int = 0; }
    	if(city == ''){
    		$('card_errors').innerHTML += 'Please enter the city of the card holder!<br /><br />'; go_int = 0; }
    	if(state == ''){
    		$('card_errors').innerHTML += 'Please enter the state of the card holder!<br /><br />'; go_int = 0; }
    	if(zip == ''){
    		$('card_errors').innerHTML += 'Please enter the zip code of the card holder!<br /><br />'; go_int = 0; }
    	if(card == ''){
    		$('card_errors').innerHTML += 'Please enter the credit cart number of the card holder!<br /><br />'; go_int = 0; }
    	if(exp_m == '' && exp_y != ''){
    		$('card_errors').innerHTML += 'Please enter the expiration of the credit card!<br /><br />'; go_int = 0; }
    	if(cv == ''){
    		$('card_errors').innerHTML += 'Please enter the CVV of the credit card!<br /><br />'; go_int = 0; }
    	
    	if(go_int != 0)
    	{
    	 $('pay_2').innerHTML = "<span style='float:right; margin-right: 15px;'><center>Processing... <img src='/gather/ajax-loader.gif'></center></span>";
    	 $('pay_3').setStyle({display: 'none'});
				new Ajax.Request('/store/aj_process_payment.php', {
						method: 'get', 
						parameters: {fn: fn, ln: ln, email:email, street: street, apt: apt, city: city, state: state, zip:zip, card: card, exp_m: exp_m, exp_y: exp_y, cv: cv, member: member},
						onComplete: function (transport) {
							//in here see what needs to be done
							
							
							var aj_process		= transport.responseText;
							var regex_pattern = new RegExp('ERROR');

							$('confirmation').innerHTML = transport.responseText;
							
							 
							if( !regex_pattern.test(aj_process) )
							{
								new Ajax.Request('/store/aj_finish.php', {
									method: 'get',
									parameters: 'x=x',
									onComplete: function (transport) {
										$('confirmation').insert(transport.responseText, {position: 'after'});

										new Effect.Parallel( [
											Effect.BlindUp("at_payment_2", { duration: 1 }, { sync: true }),
											Effect.BlindDown("at_confirm_2", { duration: 1 }, {sync: true })
										]);
								
										
										
								
										$('at_confirm_1').addClassName('accordion-toggle-active');
										$('at_payment_1').removeClassName('accordion-toggle-active');
										$('at_payment_1').addClassName('accordion-toggle'); 
									
									} 
								
								
								});
							
							

								
								//need to prepare the checkout page and then show it
								

								
								
								new Ajax.Updater({success: 'Cart'},'/store/aj_mini_cart.php',{onFailure: function(){ alert('Could not get cart on payment!') }});     

							}
							else
							{
								//error happened
								//Please make verbose
								
								
								$('card_errors').innerHTML = "You credit card has been declined. Please check to see if there were any errors when typing it in and try again. If this problem persists, please contact your credit card company."
                
                //transport.responseText;
								$('pay_2').innerHTML = '';
								$('pay_3').setStyle({display: 'inline'});
							}	
							

						}//,
						//onFailure: function(){ alert('Could not process card at this time!'); }
				});	
    	}
    	else
    	{
    		//display message to the user for not filling in all the values
    	}
    });
 
    }

});

function next_step(open_str, close_str)
{
	//new Ajax.Updater({success: 'total_cost'},'/store/calc_total.php',{method: 'get', parameters: {go_int: 1}, onFailure: function(){ alert('Could calculate total!') }});     
	
	
	/*Ajax.Request('xhr_handler.php', {
		method: 'get', 
		parameters: params,
		onComplete: function (transport) {
			alert(transport.responseText);
		}
	
	}); */
	//Effect.BlindUp(close, { duration: 1 });
	
	if ( open_str == 'at_payment' )
	{
	  //check to see if they had entered a coupon code
	  if($('coupon_code').value != '' && $('coupon_code').value != "INVALID CODE" && $('coupon_code').value != 'Coupon not valid on items' && $('coupon_code').value != "Coupon Accepted!")
	  {
      var coupon_code = $('coupon_code').value;
      var ship1 = $('ground_cost').value;
      var ship2 = $('air_cost').value;
      var ship3 = $('nextday_cost').value;
    	var savings = $('addtional_savings').value;
    	var orig_sub = $('orig_sub').value;
    	var member_save = $('member_save').value;
    	var activity_save = $('activity_save').value;
    	
    	//do the checking
    	new Ajax.Request('/store/aj_coupon.php', {
							method: 'get', 
							parameters: {
                            coupon:coupon_code, 
                            ship1:ship1, 
                            ship2:ship2,
                            ship3:ship3,
                            savings:savings, 
                            orig_sub:orig_sub, 
                            member_save:member_save, 
                            activity_save:activity_save
                          }
				});
    }
		$('c_fn').value 			= $('fn').value;
		$('c_ln').value 			= $('ln').value;
		$('c_street').value 	= $('street').value;
		$('c_apt').value 			= $('apt').value;
		$('c_city').value 		= $('city').value;
		$('c_state').value 		= $('state').value;
		$('c_zip').value 			= $('zip').value;
		new Ajax.Updater({success: 'paypal_button'},'/store/aj_paypal.php',{method: 'get', onFailure: function(){ alert('Could not get Paypal button!') }});     
	}
	
	
	
	
	
	new Effect.Parallel( [
		Effect.BlindUp(close_str+"_2", { duration: 1 }, { sync: true }),
		Effect.BlindDown(open_str+"_2", { duration: 1 }, {sync: true })
	]); 
	
	//alert('close: ' + close_str + ' problem open: ' + open_str);
	
	$(open_str+'_1').addClassName('accordion-toggle-active');
	$(close_str+'_1').removeClassName('accordion-toggle-active');
	$(close_str+'_1').addClassName('accordion-toggle');
}


function freegift()
{
	var gift 		= $('gift').value;
	var orderid = $('order_id').value;

	if(gift != '')
	{
			new Ajax.Updater({success: 'free_gift_box'},'/store/aj_free_gift.php',{method: 'get', parameters: {gift: gift, orderid: orderid}, onFailure: function(){ alert('Could not get gift!') }});     
	    $('free_gift_sel').innerHTML = "";
  }
	else
	{
		//display message to the user for not filling in all the values
		$('free_gift_box').innerHTML = "Please select a gift to receive.";
	}
}
function addToMiniCart(qty, id) {
	updateMiniCart(qty, id);
}

function updateMiniCart(this_qty, this_id)
{
		var args_serialized	= 'prod_id='+this_id+'&quantity='+this_qty;
    	
    	//this only does one complexity
    	if($('complex_'+this_id))
    	{
    		var complex_id = $('complex_'+this_id).value;
    		var complex_val = $(complex_id).value
    		args_serialized = args_serialized + '&' + complex_id + '=' + complex_val;
    	}
		
		//alert(args_serialized);
		
		//do ajaxy goodness    
		new Ajax.Request(
			'/store/aj_add_to_cart.php',
			{
				method: 'get', 
				parameters: args_serialized, 
				onComplete: function () {
					if ( $('mycart') ) {
						new Ajax.Updater({success: 'mycart'},'/store/aj_my_cart.php',{onFailure: function(){ alert('Could not get full cart on remove!') }});
						miniUpdateShip();
					}
					var dialog = 'added_to_cart_' + this_id;
					//alert(dialog);
					if($(dialog))
					{
						
						$(dialog).highlight().show().innerHTML = "Added!";
						//setTimeout("$('added_to_cart').hide();", 500);
			      setTimeout(hideAddedFlags, 800);
					}
					
					new Ajax.Updater({success: 'Cart'},'/store/aj_mini_cart.php',{onFailure: function(){ alert('Could not get mini cart from add!') }});
					$('wrap_mini_cart').show();
					
					var continue_link	= 'wrap_continue_link_'+ this_id;
					
					if ( $(continue_link) )	$(continue_link).show();
				}
			}
		);  
}


/*

	DO NOT EDIT THIS FUNCTION
	
*/
function hoverUpdateMiniCart(this_qty, this_id)
{
		var args_serialized	= 'typeOf=mini&item_id='+this_id+'&quantity='+this_qty;
    
		
		//alert(args_serialized);
		
		//do ajaxy goodness    
		new Ajax.Request(
			'/store/aj_update_cart.php',
			{
				method: 'get', 
				parameters: args_serialized, 
				onComplete: function (transport) {
				
					if ( transport.responseText == 'success' )
					{
						if ( $('mycart') ) {
							new Ajax.Updater({success: 'mycart'},'/store/aj_my_cart.php',{onFailure: function(){ alert('Could not get full cart on remove!') }});
							miniUpdateShip();
						}

						new Ajax.Updater({success: 'Cart'},'/store/aj_mini_cart.php',{onFailure: function(){ alert('Could not get mini cart from add!') }});
						$('wrap_mini_cart').show();
					}
				}
			}
		);  
}


function hideAddedFlags()
{
	var add_flags	= $A($$('.add_flag'));
	add_flags.invoke('hide');
}
function removeFromMiniCart(item_id)
{
		//pass to php to handle removing from the cart and bring back the updated contents
    new Ajax.Request(
    	'/store/aj_remove_from_cart.php',
    	{
    		method: 'get', 
    		parameters: {item_id: item_id},
    		onComplete: function() {
					if ( $('mycart') ) {
						new Ajax.Updater({success: 'mycart'},'/store/aj_my_cart.php',{onFailure: function(){ alert('Could not get full cart on remove!') }});
					}
					miniUpdateShip();
    			new Ajax.Updater({success: 'Cart'},'/store/aj_mini_cart.php',{onFailure: function(){ alert('Could not get mini cart on remove!') }});
					
    	}, onFailure: function(){ alert('Could not remove from cart! Please try again!') }});  
}



function removeFromCart(item_id)
{
		$('mycart').innerHTML = "<center><br /><br /><br />Removing From Cart <br /><img src='/gather/ajax-loader.gif'><br /><br /></center>";
    //pass to php to handle removing from the cart and bring back the updated contents
    new Ajax.Request(
    	'/store/aj_remove_from_cart.php',
    	{
    		method: 'get', 
    		parameters: {item_id: item_id},
    		onComplete: function() {
    			new Ajax.Updater({success: 'mycart'},'/store/aj_my_cart.php',{onFailure: function(){ alert('Could not get full cart on remove!') }});
					new Ajax.Updater({success: 'Cart'},'/store/aj_mini_cart.php',{onFailure: function(){ alert('Could not get mini cart on remove!') }});
					
    	}, onFailure: function(){ alert('Could not remove from cart! Please try again!') }});  
}

function updateCart(item_id)
{
	var qty = $('quantity_' + item_id).value;
	if(IsNumeric(qty))
	{
		if(qty == 0)
				removeFromCart(item_id);
		else
		{
			//pass to php to handle removing from the cart and bring back the updated contents
			new Ajax.Request(
				'/store/aj_update_cart.php',
				{
					method: 'get', 
					parameters: {item_id: item_id, quantity: qty}, 
					onFailure: function(){ alert('Could not update cart! Please try again!') },
					onComplete: function () {
						new Ajax.Updater({success: 'mycart'},'/store/aj_my_cart.php',{onFailure: function(){ alert('Could not full get cart on update!') }});
						new Ajax.Updater({success: 'Cart'},'/store/aj_mini_cart.php',{onFailure: function(){ alert('Could not mini get cart on update!') }});
					}
			});  
		}
	}
}

function swapProductImage(this_img_id)
{
	alert(this_img_id);
}

function IsNumeric(int_val) 
{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;

	if (int_val.length == 0) return false;

	//  test int_val consists of valid characters listed above
	for (i = 0; i < int_val.length && blnResult == true; i++)
		{
		strChar = int_val.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			 {
			 blnResult = false;
			 }
		}
	return blnResult;
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}
//Click function
function setSearch(value) {
	document.getElementById('search_box').value = value;
	document.getElementById('search_suggest').innerHTML = '';
	$('search_suggest').setStyle({display: 'none'});
}

function member_signup()
{
	if($('member').value == "yes")
	{
		$('new_member').setStyle({display: 'inline'});
	}
	else
	{
		$('new_member').setStyle({display: 'none'});
	}
}

function miniUpdateShip()
{
	if($('calc_ship')){ 
    	//do the ajax call for the search bawks
    	var fn = $('fn').value;
    	var ln = $('ln').value;
    	var street 	= $('street').value;
    	var city 		= $('city').value;
    	var state 	= $('state').value;
    	var zip 		= $('zip').value;
    	var apt 		= '';
    	apt 				= $('apt').value;
    	var type_str = $('type').value;
    	
    	if(IsNumeric(zip))
    	{
    		$('shipping_cost').innerHTML = "<center>Loading Shipping Calculation <br /><br /> <img src='/gather/ajax-loader.gif'></center>";
				if(fn != '' && ln != '' && street != '' && city != '' && state != '' && zip != '')
				{
						new Ajax.Updater({success: 'shipping_cost'},'/store/aj_calc_ship.php',{method: 'get', parameters: {fn: fn, ln: ln, street: street, apt: apt, city: city, state: state, zip: zip, type: type_str}, onFailure: function(){ alert('Could not calculate shipping!') }});     
					
				}
    	} 
    }
}

function copyShipping()
{
  if($('bill_same').checked)
  {
		$('c_fn').value 			= $('fn').value;
		$('c_ln').value 			= $('ln').value;
		$('c_street').value 	= $('street').value;
		$('c_apt').value 			= $('apt').value;
		$('c_city').value 		= $('city').value;
		$('c_state').value 		= $('state').value;
		$('c_zip').value 			= $('zip').value;
		//$('c_email').focus();
	}
	else
	{
		$('c_fn').value 			= "";
		$('c_ln').value 			= "";
		$('c_street').value 	= "";
		$('c_apt').value 			= "";
		$('c_city').value 		= "";
		$('c_state').value 		= "";
		$('c_zip').value 			= "";

  }
}

function shippingMethod(type, cost)
{ 
	sub_total = $('sub_total').value;
	new Ajax.Request('/store/aj_shipping_method.php', {
							method: 'get', 
							parameters: {method: type, cost: cost, sub_total: sub_total},
							onComplete: function (transport) {
								//in here see what needs to be done
								$('shipping_total').innerHTML = "$" + cost.toFixed(2);
								$('order_total').innerHTML = transport.responseText;
								//$('pp_ship').value = cost.toFixed(2);				
							}
				});
}

function couponCode()
{
  var coupon_code = $('coupon_code').value;
  var ship1 = $('ground_cost').value;
  var ship2 = $('air_cost').value;
  var ship3 = $('nextday_cost').value;
  var savings = $('addtional_savings').value;
  var orig_sub = $('orig_sub').value;
  var member_save = $('member_save').value;
  var activity_save = $('activity_save').value;
  var chal_save = $('chal_save').value;

  new Ajax.Request('/store/aj_coupon.php', {
							method: 'get', 
							parameters: {coupon:coupon_code, ship1:ship1, ship2:ship2,ship3:ship3,savings:savings, orig_sub:orig_sub, member_save:member_save, activity_save:activity_save, chal_save:chal_save},
							onComplete: function (transport) {
								//in here see what needs to be done
							   if(transport.responseText != '' && transport.responseText != 'too small')
								  $('summary_holder').innerHTML = transport.responseText;
								 else if(transport.responseText == 'too small')
								 	$('coupon_code').value = "Coupon not valid on items";
								 else 
								 	$('coupon_code').value = "INVALID CODE";							
							}
				});

/*	new Ajax.Updater({success: 'summary_holder'},
      '/store/aj_coupon.php',
      { 
        method: 'get', parameters: {coupon:coupon_code, ship1:ship1, ship2:ship2,ship3:ship3},
        onFailure: function(){ alert('Could not apply coupon! Try again!') }
      }); */ 
}

function emailCheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
	
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){

		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){

		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){

		    return false
		 }

 		 return true					
	}

