
// Begin Cart Effects

var cart_turned_on = false;
									 
function effects_start() { 
	 
	update_cart_onopen();  // Run Ajax
	
	// set the background to be able to show
	$('modal_window_background').show({ queue: 'front' });
	
	// and fade in the background
	new Effect.Opacity('modal_window_background', { from: 0, to: 0.7, duration: 0.5, queue: 'end' });
		
	// check if IE or not...
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
	// fade in the main box
		new Effect.Opacity('modal_window_box', { from: 0, to: 1.1, duration: 0.6, queue: 'end' });
	} else {
	// fade in the main box ( but in 0 time so its not there on start and has to fade in before the slide in next)
		new Effect.Opacity('modal_window_box', { from: 0, to: 1.1, duration: 0, queue: 'end' });
	}
	// slide in box
	new Effect.SlideDown('modal_window_box');
	
	cart_turned_on = true;
	
	Effect.ScrollTo('modal_window_background');
	
}	

function effects_end() { // removing the modal window
		
	Effect.Queues.get('modal_window_background').interval = 200;
		
	// slide up the	main box
	new Effect.SlideUp('modal_window_box', { queue: 'front' });
	Effect.Fade('modal_window_box');
	
	// finaly hide the window
	Effect.Fade('modal_window_background');
	
	cart_turned_on = false;
}	

<!--// Update The Cart As It Opens Ajax Script //--> 
function update_cart_onopen(){ 

	var session_id = '77487104';
	
 	var url = 'includes/cart/update_cart_onopen.inc.php' + '?session_id=' + session_id

	new Ajax.Request(url, { 
			method:'get',  
			onLoading: function(){ 

				$('cart_update_box').innerHTML = 'Loading <img src="images/4-1.gif"/>';
			},
			onSuccess: function(transport){ 

				setTimeout(function() {
					var response = transport.responseText || " No response text found, please try again ";
					$('cart_update_box').innerHTML = response; 

					// Update Cart Summary
					refresh_cart_content();
				}, 100);
			},
			onFailure: function(){ 

				setTimeout(function() {
					$('cart_update_box').innerHTML = '<p> Sorry, but there was a problem with this request, please try again </p>'; 
				}, 100);
			}
	});	
	
} 

// this function watches for the user to press the ESC key 
 function keyPressHandler(e) {
      var kC  = (window.event) ?    // MSIE or Firefox?
                 event.keyCode : e.keyCode;
      var Esc = (window.event) ?   
                27 : e.DOM_VK_ESCAPE // MSIE : Firefox
      if(kC==Esc) {
      
	    if(cart_turned_on == true) { // if the modal cart is open currently, then close it on click of ESC 
			 effects_end();
		}
      
	    if(lightboxImageGalOn == true) { // if the modal image window is open currently, then close it on click of ESC 
			 closeLightboxImageGal();
		}
	  }
   }

// Add to wish list 
var itemId;
function add_to_wish_list(itemId) {
	
 	var url = 'includes/shop/wish_lists/add_to_wish_list.inc.php?itemId=' + itemId;

	new Ajax.Request(url, { 
			method:'get',
			onLoading: function(){ 

				$('wish_update_box').innerHTML = 'Loading... <img src="images/4-1.gif"/>';
			},
			onSuccess: function(transport){ 

					var response = transport.responseText || " No response text found, please try again ";
					$('wish_update_box').innerHTML = response; 
					new Effect.Highlight('wish_update_box');
					
			},
			onFailure: function(){ 

					$('wish_update_box').innerHTML = '<p> Sorry, but there was a problem with adding this item to your wish list, please try again </p>'; 
			}
	});	
}

// Add to compare list 
var itemId;
function add_to_compare_list(itemId) {
	
 	var url = 'includes/shop/compare/add_to_compare.inc.php?itemId=' + itemId;

	new Ajax.Request(url, { 
			method:'get',
			onLoading: function(){ 

				$('compare_update_box').innerHTML = 'Loading... <img src="images/4-1.gif"/>';
			},
			onSuccess: function(transport){ 

					var response = transport.responseText || " No response text found, please try again ";
					$('compare_update_box').innerHTML = response; 
					new Effect.Highlight('compare_update_box');
					
			},
			onFailure: function(){ 

					$('compare_update_box').innerHTML = '<p> Sorry, but there was a problem with adding this item to your compare list, please try again </p>'; 
			}
	});	
}


   // loop a bundle of products by there ids into the cart 
   var bundle;
   var bundle_array = new Array();
   function loop_bundle_array_cart(bundle) {
   
   		bundle_array = bundle.split(",");
				
   		for(var i=0; i<bundle_array.length; i++) {
  			
			//alert(bundle_array[i]);
			
			var includePath = "includes/cart/add_to_cart.inc.php?js=true";
			
			new Ajax.Request(includePath,
			  {
				method:'get',  
				parameters: {
					product_id: bundle_array[i], 
					quantity: '1'
				},
				onLoading: function(){ },
				onSuccess: function(transport){	},
				onFailure: function(){ }
			});
					
		}

		setTimeout(function(){
			// Open Modal Window
			effects_start();
			// Update Cart Summary
			refresh_cart_content();
			}, 200);
	}
   
var cart_content; 
var product_id;
var quantity;
var typeOfInput;
var op_string;
function update_cart_content(product_id,quantity,typeOfInput){ 
	
	// Product Id
	if(product_id == undefined) {
		product_id = $('product_id').value;
	}	
		
	// Quantity 
	if(quantity == undefined) {
		quantity = $('quantity').value;
	}
	
	if(typeOfInput != 'direct') { 
			
		var op_string = "";
		
			for (var i=0; i<4; i++) {
				if ($("os"+i)) {
			
					var option = $("os"+i).value;
					
					if(option != '') {
				
						var option_name = $("on"+i).value;
						var op_string = op_string + '&' + option_name + '=' + option;
					}
			
				}
			} 	
	
	
		}
	else { op_string = '' }
	
	var includePath = "includes/cart/add_to_cart.inc.php?js=true" + op_string;

	new Ajax.Request(includePath,
		  {
			method:'get',  
			parameters: {
				product_id: product_id, 
				quantity: quantity
			},
			onLoading: function(){
			
				if($('result_box')) { 
			 		$('result_box').innerHTML = "<img src='images/4-1.gif' alt='Loading...' title='Loading...' align='middle' /> Loading Please Wait... ";
				}
			},
			onSuccess: function(transport) { 
			
				setTimeout(function(){ 
						
					if($('result_box')) {
						var response = transport.responseText || " No response text found, please try again ";
						$('result_box').innerHTML = response; 
					}
					// Open Modal Window 
					effects_start(); 
									
				},300); // give 300 miliseconds to make sure all the functions definetly finished before result happens 
	
			},
			onFailure: function(){ 
			
				if($('result_box')) {
					$('result_box').innerHTML = '<p> Sorry, but there was a problem adding this item to your cart, please try again </p>'; 
				}
			}
	});

	// Update Cart Summary
	refresh_cart_content()

} 


var radioObj;
function getCheckedValue(radioObj) {

	var radioGrp = document['forms']['addcartform'][radioObj];
	
	for(i=0; i < radioGrp.length; i++){
		if (radioGrp[i].checked == true) {
			var radioValue = radioGrp[i].value;
		}
	 }
	 
	 return radioValue;
}


/** add a product to the cart and reload the page */
var prods_ids;
function addAndReloadPage(prods_ids) {
	
	// use the loop to cart function 
	loop_bundle_array_cart(prods_ids);
	
	// and reload the page 
	setTimeout(function() { 
		location.reload(); 
	}, 400);
}
