	function switchClass(id, classname){
		var td = document.getElementById(id) ; 
//		if (td.innerHTML == "Add to Cart"){
			td.className = classname ; 
//		}
	}

	function addToCart(id) {
		//alert('Add ' + id + '...') ; 
				
		qString = 'itemId=' + id ; 
		msg = '' ; 
		if (id != '') {DisplayMessage('Adding an item to cart...') ; }



		$.ajax({
		        url:  '/scripts/addToCart.php' ,
		        type: "GET",
		        data: qString, 
		        success: function(result){ 
							 
                          responseText = result ;
						  //responseText = "..." ; 
						  //alert(responseText) ; 

						  if (responseText == "0"){
							  msg = 'ALERT: The item you requested is no longer available.' ;
							  updateItemBtn(id, 'Out of Stock') ; 

						  } else if (responseText == "-1") {
						  	  msg = 'Our apologies, we are unable to process the order right now, please feel free to call us at 415-863-1104.';
						  } else if (responseText == "") {
						  	  msg = 'WARNING: Could not add the item you requested.  Please review your cart for more informtaion' ;
							  //updateItemBtn(id, 'Please see Cart') ; 	
						  }else {
	                		  
							  updateCartSummary(responseText) ; 
                              if(id != '') {addToCartAnimate(id) ; }
							  DisplayCart(false) ; 
							  //msg = 'The item has been sucessfully added to your shopping cart.' ;
							  //updateItemBtn(id, 'Added to Cart') ; 	
						  }                          

						  if (id != ''){
							DisplayMessage('') ; 
							if (msg != '') {
                                alert(msg) ; 
                            }
						  }
                      }, 
		        error: function(result){ 
							DisplayMessage('') ; 
							alert('Not able to add an item.') 
					  }   
		     });  
		
	}
    
    
    function addToCartAnimate(id){
        if (jQuery.browser.webkit)  {   $selector = "body"; }
            else                        {   $selector = "html"; }
            var $scrollTop = jQuery($selector).scrollTop();
            var $scrollLeft = jQuery($selector).scrollLeft();
            var $cart_offset = jQuery("#divCartSummary").offset();
            //var $image_offset = jQuery("#product_image_" + $id).offset();
            //var $image = jQuery("#product_image_" + $id).clone();
            var $image_offset = jQuery("#item_name_" + id).offset();
            var $image = jQuery("#item_name_" + id).clone();

            //alert($image_offset.top) ; 
            
            $image.css("z-index", "9999");
            $image.css("position", "fixed");
            $image.css("left", $image_offset.left - $scrollLeft);
            $image.css("top", $image_offset.top - $scrollTop);
            $image.css("opacity", ".80");

            //$image.prependTo(".product_view_" + $id);
            $image.prependTo("#item_name_" + id);
            $image.animate({
                top: $cart_offset.top - $scrollTop,
                left: $cart_offset.left - $scrollLeft,
                height: '0px'
                }, 800,  function() {
                    $image.remove();
                    //$button.css("background-color", $original_color);
                    //jQuery("li#cart-menu-item").css("background-color", "#000000");
                }
            );
        
    }

	function addToCart_X(id) {
		//alert('Add ' + id + '...') ; 
				
		qString = 'itemId=' + id ; 
		msg = '' ; 
		if (id != '') {DisplayMessage('Adding an item to cart...') ; }



		new Ajax.Request('/scripts/addToCart.php?' + qString ,
        //new Ajax.Request('/scripts/addToCart.php?' ,
                  {   
                      method:'post',   
                      onSuccess: function(transport){ 
							 
                          responseText = ''+transport.responseText;
						  //responseText = "..." ; 
						  //alert(responseText) ; 

						  if (responseText == "0"){
							  msg = 'ALERT: The item you requested is no longer available.' ;
							  updateItemBtn(id, 'Out of Stock') ; 

						  }else if (responseText == "") {
							  msg = 'WARNING: Could not add the item you requested.  Please review your cart for more informtaion' ;
							  //updateItemBtn(id, 'Please see Cart') ; 	
						  }else {
	                		  
							  updateCartSummary(responseText) ; 
							  DisplayCart(false) ; 
							  //msg = 'The item has been sucessfully added to your shopping cart.' ;
							  //updateItemBtn(id, 'Added to Cart') ; 	
						  }                          

						  if (id != ''){
							DisplayMessage('') ; 
							if (msg != '') {alert(msg) ; }
						  }
                      },     
                      onFailure: function(){ 
							DisplayMessage('') ; 
							alert('Not able to add an item.') 
					  }   
                  }); 
		
	}

	function removeItem(id, blnAtCheckout) {
		//alert('Add ' + id + '...') ; 
				
		qString = 'itemId=' + id + '&qty=0' ; 


		$.ajax({
			url:  '/scripts/addToCart.php' ,
		    type: "get",
		    data: qString, 
		    success: function(result){ 
				responseText = result ;
					
				if(blnAtCheckout){	                		  
					DisplayCheckout(); 
				}else{
					updateCartSummary(responseText) ; 
					DisplayCart(true, 'Recalculating cart...') ; 						  
					//updateItem(id) ; 

				}       				 
                          
			}, 
	        error: function(result){ 
				alert('Error removing an item.') 
				DisplayMessage('') ; 
			}   
		});  

		
		return false ; 
	}

	function updateItem(id){
		var td = document.getElementById('td_' + id) ; 
		td.innerHTML = 'Added to Cart' ; 
		td.onmouseover = '' ; 
		td.onmouseout = '' ; 
		td.onclick = '' ; 
		td.className = 'button_ro' ; 
	}

	function updateItemBtn(id, str){
		var td = document.getElementById('td_' + id) ; 
		td.innerHTML = str ; 
		td.onmouseover = '' ; 
		td.onmouseout = '' ; 
		td.onclick = '' ; 
		td.className = 'red_font' ; 
	}

	function ValidateItem(id){
		var txtQty = document.getElementById('intQty_' + id) ; 
		var originalQty = document.getElementById('originalQty_' + id) ; 
		if ((txtQty.value == "0") || (txtQty.value == "")){
			//if (confirm('Confirm removing this item from cart?')){
			//	txtQty.value = 0 ; 				
			//}else {				
			//	txtQty.value = originalQty.value ; 				
			//}
			txtQty.value = 0 ; 
		}else if (IsNumeric(txtQty.value)){

			var availableQty = document.getElementById('availableQty_' + id) ; 
			avaiQty = parseInt(availableQty.value) ; 
			intQty = parseInt(txtQty.value) ; 
//            if (avaiQty >= intQty){
            if (true){
				txtQty.value = intQty ; 
			}else {
				alert('Not enough quantity available.(Only ' + avaiQty + ' available.)') ; 
				txtQty.value = avaiQty ; 
			}
		}else {
			alert(txtQty.value + ' is an Invalid Quantity.  Please try again.') ; 
			txtQty.value = originalQty.value ; 
		}
	}

	function UpdateCart(blnAtCheckout){
		var hidIds = document.getElementById('hidIds') ; 
		var strIds = hidIds.value ; 
		var arIds = strIds.split(",")  ; 
		//alert(arIds.length) ; 
		var blnError = false ; 
		var i=0
		var cur = 0 ; 
		DisplayMessage('Updating cart (Item ' + (cur + 1) + ' of ' + arIds.length + ')...') ;                           

		for (i=0 ; i < arIds.length ; i++)
		{
			id = arIds[i] ; 
			var txtQty = document.getElementById('intQty_' + id) ; 
			//alert(txtQty.value) ; 
			qString = 'itemId=' + id + '&qty=' + txtQty.value  ; 

			$.ajax({
				url:  '/scripts/addToCart.php' ,
				type: "GET",
				data: qString, 
				success: function(result){ 
					responseText = result ;
					cur++ ; 
					  		  
					if (cur >= arIds.length){
						if (blnAtCheckout){
							DisplayCheckout(); 
						}else {
							updateCartSummary(responseText) ; 
							DisplayCart(true, 'Recalculating cart...') ; 
						}
					}else {
						DisplayMessage('Updating cart (Item ' + (cur + 1) + ' of ' + arIds.length + ')...') ;                           
					}
			                          						 
			                          
			    }, 
				error: function(result){ 
						
					DisplayMessage('') ; 
					alert('Not able to access data.') 						
					blnError = true ; 
			
			
				}   
			}); 

			if (blnError) {break;} 
		}
		

	    
	}

	function UpdateItemQty(id){
		//alert(id) ; 
		var txtQty = document.getElementById('intQty_' + id) ; 
		var originalQty = document.getElementById('orginalQty_' + id) ; 
		blnUpdate = false ; 
		intQty = 0 ; 
		//alert(id + ' ' + txtQty) ; 
		if ((txtQty.value == "0") || (txtQty.value == "")){
			if (confirm('Confirm removing this item from cart?')){
				intQty = 0 ; 
				blnUpdate = true ; 
			}else {
				
				txtQty.value = originalQty.value ; 
				
			}
		}else if (IsNumeric(txtQty.value)){
			blnUpdate = true ; 
			intQty = parseInt(txtQty.value) ; 
		}else {
			alert(txtQty.value + ' is an Invalid Quantity.  Please try again.') ; 
			txtQty.value = originalQty.value ; 
		}
		
		if (blnUpdate){
			
			qString = 'itemId=' + id + '&qty=' + intQty  ; 
			
			$.ajax({
				url:  '/scripts/addToCart.php' ,
				type: "GET",
				data: qString, 
				success: function(result){ 
					responseText = result ;
					                          
					updateCartSummary(responseText) ; 
					DisplayCart(true) ; 				 
			                          
			        }, 
				error: function(result){ 
					alert('Not able to access data.') ;
				}   
			}); 
		
		}
	}

	function updateCartSummary(str){
		//alert(str) ; 
		var divCartSummary = document.getElementById('divCartSummary') ; 
		var strCartSummary = document.getElementById('strCartSummary') ; 
		if (str != ''){
			divCartSummary.className = 'divCartSummary' ; 
		}else {
			divCartSummary.className = 'hidden' ; 
		}
		strCartSummary.innerHTML = str ; 

	}

	function DisplayCart(blnDisplay, msg){

		
		
		var divCartDetail = document.getElementById('divCartDetail') ; 
		if (blnDisplay){
			msg = (msg == null)  ? 'Retrieving cart...' : msg ; 
			DisplayMessage(msg) ; 


			$.ajax({
				url:  '/scripts/cartDetail.php' ,
				type: "GET",
				success: function(result){ 
					//alert(result) ; 
					DisplayMessage('') ; 						
					strCartDetail = result ;
					divCartDetail.innerHTML = strCartDetail ;
					divCartDetail.className = 'divCartDetail' ; 
			 		divCartDetail.style.left = (document.body.clientWidth/2) + 160 ;
					//alert(divCartDetail.innerHTML.length) ; 
					if (divCartDetail.innerHTML.length < 330) {updateCartSummary('');} 							 
			                          
			    }, 
				error: function(result){ 
					alert('Could not access cart. Please try again.') ;
			
				}   
			}); 



		}else {
			divCartDetail.innerHTML = '' ; 
			divCartDetail.className = 'hidden' ; 			

		}
		return false ; 
	}

	function GetCartDetail() {
		strCartDetail = '' ; 

		$.ajax({
			url:  '/scripts/cartDetail.php' ,
			type: "GET",
			success: function(result){ 
				strCartDetail = result ;				 
		                          
		        }, 
			error: function(result){ 
				alert('Not able to access data.') ; 
		
			}   
		}); 


		return strCartDetail ; 		
	}

	function IsNumeric(sText){
	   var ValidChars = "0123456789";
	   var IsNumber=true;
	   var Char;
	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
	      { 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1) 
	         {
	         IsNumber = false;
	         }
	      }
	   return IsNumber;
   
   }

	function DisplayMessage(str, blnCloseBtn){
		var divMsg = document.getElementById('divMessage') ; 
		var strMsg = document.getElementById('strMessage') ; 
		var img = document.getElementById('imgLoading') ; 

		//blnCloseBtn = true ; 

		img.style.visibility = (blnCloseBtn) ? 'hidden' : ''  ; 
		img.className = (blnCloseBtn) ? 'hidden' : ''  ; 

		//alert(str) ; 

		//alert(getOffsetTop()) ; 


		if (str != ''){
			//hideSelects() ; 
			divMsg.className = 'divMessage' ; 

			$("#divMessage").css("top", (($(window).height() -  $("#divMessage").outerHeight()) / 2) + $(window).scrollTop() + "px");
			$("#divMessage").css("left", (($(window).width() -  $("#divMessage").outerWidth()) / 2) + $(window).scrollLeft() + "px");

//			divMsg.style.left = (document.body.clientWidth/2) - 200 ;
//			divMsg.style.top = getOffsetTop() + 200 ; 
			str += (blnCloseBtn) ? '<p><input type="button" onclick="DisplayMessage(\'\');" value="Close" class="btnMessage"></p>' : '' ; 
			strMsg.className = (blnCloseBtn) ? 'divMessage_small' : '' ; 
		}else{
			divMsg.className = 'hidden' ; 
			//showSelects() ; 
			//divMsg.style.height = 0 ; 
			//divMsg.style.padding = 0 ; 
			//divMsg.style.visibility = 'hidden' ; 
		}


		strMsg.innerHTML = str ; 

		


	
	}

	function getOffsetTop(){
		if (window.innerWidth) { //if browser supports window.innerWidth
			return window.pageYOffset ; 
		} else if (document.all){ //else if browser supports document.all (IE 4+)
			return document.body.scrollTop ; 
		} else { 
			return 0 ; 
		}
	}

	function hideSelects(){
		var arSelect = document.getElementsByTagName("select"); 
		for (i = 0 ; i < arSelect.length ; i ++) {
			arSelect[i].style.visibility = 'hidden' ; 
		}
	}

	function showSelects(){
		var arSelect = document.getElementsByTagName("select"); 
		for (i = 0 ; i < arSelect.length ; i ++) {
			arSelect[i].style.visibility = 'visible' ; 
		}
	}

	function checkout(){

		document.location.href = 'checkout.php' ; 
	}
	
	

