//HANDLE PRODUCT CATEGORIES
var current_add_id = "";
var current_cat_id = "";

	function handleDivTag(divtag){
	   var divtag;
	   return divtag;
	}
	
   function createRequestObject() {
        var req;
        if(window.XMLHttpRequest){
            req = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            alert("There was a problem creating the XMLHttpRequest object");
        }
        return req;
    }
    
    // Make the XMLHttpRequest object
    var http = createRequestObject();
	var divhandler = new handleDivTag(null);
    var add_request_number = 0;
	var timeoutID = new Array();
	var timeoutID1 = new Array();
	var holder = "";
	var products_page = new Array();
	function set_holder() {
		if (document.getElementById("adding_layer")) holder = document.getElementById("adding_layer").innerHTML;
	}
    function sendRequest(more,divtag) {
		if (divtag == "mini_cart") {
			document.getElementById(divtag).innerHTML = "<div style='padding: 10px;'>Loading...</div>";
			http.open("get", "mini_cart.php?"+more);
		}
		if (divtag == "sample_cart") {
			document.getElementById(divtag).innerHTML = "<div style='padding: 10px;'>Loading...</div>";
			http.open("get", "sample_cart.php?"+more);
		}
		else if (divtag == "event_detail") {
			document.getElementById(divtag).innerHTML = "<div style='padding: 10px;'>Loading...</div>";
			http.open("get", "mini_email.php?"+more);
		}
        http.onreadystatechange = handleResponse;
		divhandler.divtag = divtag;
        http.send(null);   
    }

    function handleResponse() {
		//alert("in handle: "+http.status);
        if(http.readyState == 4 && http.status == 200){
            // Text returned FROM PHP script
            var response = http.responseText;
            if(response) {
                document.getElementById(divhandler.divtag).innerHTML = response;
				setTimeout("update_view()",50);
				if (divhandler.divtag == "event_detail") {
					if (document.getElementById("your_name")) document.getElementById("your_name").focus();
				}
				//REFRESH SIDE CART IF NECSSARY
				if (document.getElementById('quick_cart')) {
					refresh_quick_cart();
				}        
				//REFRESH SPA SIDE CART IF NECSSARY
				if (document.getElementById('partnership_cart')) {
					refresh_partnership_cart();
				}				
            }
        }
    }
	//cart functions:
	function update_product(mc_cart_product_id) {
	
		//alert(mc_cart_product_id);
	
		var prod_name = "prod_"+mc_cart_product_id;	
		if (document.getElementById(prod_name)) {
	
			//GET PROD ID
			var prod = document.getElementById(prod_name).value;
	
			//FIRST, VALIDATE INPUT QUANTITY
			var qty_name = "qty_"+mc_cart_product_id;
			var qty = document.getElementById(qty_name).value;
			if (validateInteger(qty) && qty) {
		
				var more = "action=update&";
				more += "mc_cart_product_id="+prod;
				more += "&qty="+qty;
				//alert(more);
				setTimeout("sendRequest('"+more+"', 'mini_cart')",50);
				//sendRequest(more,'mini_cart');
				//sendRequest('action=display','cart_total');

			}
		}
	}
	function remove_product(mc_cart_product_id) {
		var more = "action=remove&";
		more += "mc_cart_product_id="+document.getElementById("prod_"+mc_cart_product_id).value;
		//alert(document.getElementById("prod_"+mc_cart_product_id).value);
		setTimeout("sendRequest('"+more+"', 'mini_cart')",50);
		//sendRequest(more,'mini_cart');
	}
	function remove_product_partnership(quick_cart_product_id) {
		var more = "action=remove_partnership&";
		more += "quick_cart_product_id="+quick_cart_product_id;
		setTimeout("sendRequest('"+more+"', 'mini_cart')",50);
		//sendRequest(more,'mini_cart');
	}	
	function validateInteger( strValue ) {
	  var objRegExp  = /(^-?\d\d*$)/;
	  return objRegExp.test(strValue);
	}
	function qty_call(event, sku_id) {
		product = document.getElementById(sku_id).value;
		price_options(product);	
	}
	function price_options_all(product_ids) {
		if (product_ids.length>0) {
			//
			var more = "action=option_price&";
			var product_id_s = new Array();
			var var_line_id_s = new Array();
			var qty_id_s = new Array();
			var gift_wrap_id_s = new Array();
			for(z=0;z<product_ids.length;z++) {
				if (document.getElementById("form_"+product_ids[z])) {
					var form_obj = document.getElementById("form_"+product_ids[z]);
					var var_line = "";
					//
					
					for(i=0;i<form_obj.length;i++) {
						if (form_obj[i].name == "product_vo") {
							if (form_obj[i].value != "") var_line += form_obj[i].value +",";
						}
					}
					if (var_line != "") {
						var length = var_line.length;
						var_line = var_line.substring(0, length-1); 
					}
					//
					var temp_gift_wrap = "No";
					if (document.getElementById("gift_wrap_"+product_ids[z])) 
						if (document.getElementById("gift_wrap_"+product_ids[z]).checked == true) temp_gift_wrap = "Yes";
					var qty_product = 0;
					if (document.getElementById("qty")) qty_product = parseInt(document.getElementById("qty").value);
					//alert(qty_product);
					qty_id_s[z] = qty_product;
					var_line_id_s[z] = var_line;
					product_id_s[z] = product_ids[z];
					gift_wrap_id_s[z] = temp_gift_wrap;
				}
			}//end for loop
			//let's generate request for it
			var product_id = product_id_s.join(";");
			var product_vo = var_line_id_s.join(";");
			var gift_wrap = gift_wrap_id_s.join(";");
			var qty = qty_id_s.join(";");
			more +="product_id="+product_id+"&product_vo="+product_vo+"&gift_wrap="+gift_wrap+"&qty="+qty;
			var url = "filebin/xml/price_options_xml.php?"+more;
			var xml = new JKL.ParseXML(url);
			var data = xml.parse();
			if (data) {
				var prod_res = data.products.product;
				for (f=0;f<prod_res.length;f++) {
					if (document.getElementById("total_options_price_"+prod_res[f]["product_id"])) {
						var price_option_total = prod_res[f]["total_price"];
						if (price_option_total!="") 
							document.getElementById("total_options_price_"+prod_res[f]["product_id"]).innerHTML = "<span class='price'>Product Total: $"+price_option_total+"</span>";
					}
				}
			}
		}
	}
	function price_options(product_id) {
		if (document.getElementById("form_"+product_id)) {
			var form_obj = document.getElementById("form_"+product_id);
			var var_line = "";
			var more = "action=option_price&product_id="+product_id;
			for(i=0;i<form_obj.length;i++) {
				if (form_obj[i].name == "product_vo") {
					if (form_obj[i].value != "") var_line += form_obj[i].value +",";
				}
			}
			if (var_line != "") {
				var length = var_line.length;
				var_line = var_line.substring(0, length-1);
				more += "&product_vo="+var_line;
			}
			if (document.getElementById("gift_wrap_"+product_id)) {
				if (document.getElementById("gift_wrap_"+product_id).checked == true) more += "&gift_wrap=Yes";
				else more += "&gift_wrap=No";
			}
			else {
				more += "&gift_wrap=No";
			}
			var qty_product = 0;
			if (document.getElementById("qty")) qty_product = parseInt(document.getElementById("qty").value);
			if (document.getElementById("qty")) more += "&qty="+qty_product;
			if (qty_product != "NaN" && qty_product>0) {
				var url = "filebin/xml/price_option_xml.php?"+more;
				var xml = new JKL.ParseXML(url);
				var data = xml.parse();
				var price_option_total = data.total_price;
				if (document.getElementById("total_options_price_"+product_id)) {
					if (price_option_total!="") document.getElementById("total_options_price_"+product_id).innerHTML = "<span class='price'>Product Total: $"+price_option_total+"</span>";
				}
			}
		}
	}
	function price_options_text(product_id) {
		if (document.getElementById("form_"+product_id)) {
			//check/uncheck box:
			if (document.getElementById("gift_wrap_"+product_id)) {
				if (document.getElementById("gift_wrap_"+product_id).checked == true) document.getElementById("gift_wrap_"+product_id).checked = false;
				else document.getElementById("gift_wrap_"+product_id).checked = true;
			}
			var form_obj = document.getElementById("form_"+product_id);
			var var_line = "";
			var more = "action=option_price&product_id="+product_id;
			for(i=0;i<form_obj.length;i++) {
				if (form_obj[i].name == "product_vo") {
					if (form_obj[i].value != "") var_line += form_obj[i].value +",";
				}
			}
			if (var_line != "") {
				var length = var_line.length;
				var_line = var_line.substring(0, length-1);
				more += "&product_vo="+var_line;
			}
			if (document.getElementById("gift_wrap_"+product_id)) {
				if (document.getElementById("gift_wrap_"+product_id).checked == true) more += "&gift_wrap=Yes";
				else more += "&gift_wrap=No";
			}
			else {
				more += "&gift_wrap=No";
			}
			if (document.getElementById("qty")) more += "&qty="+document.getElementById("qty").value;
			var url = "filebin/xml/price_option_xml.php?"+more;
			var xml = new JKL.ParseXML(url);
			var data = xml.parse();
			var price_option_total = data.total_price;
			if (document.getElementById("total_options_price_"+product_id)) {
				if (price_option_total!="") document.getElementById("total_options_price_"+product_id).innerHTML = "<span class='price'>Product Total: $"+price_option_total+"</span>";
			}
		}
	}
	var gr = 0;
	function apply_price_options() {
		if (window.product_ids_arr) {
			price_options_all(product_ids_arr);
			//for(i=0;i<product_ids_arr.length;i++) {
			//	//alert(product_ids_arr[i]);
			//	setTimeout("price_options('"+product_ids_arr[i]+"')",50*i);
			//}
		}
	}
	
	function add_product(obj, sku_id, add_id, max, student) {
	
  	    if (checkIfCookie()) {

            if(!student){
                var student = 'false';
            }
        
            try {
                    
            //alert("page_loaded: "+page_loaded);					
                    
            if (page_loaded) {
        
                //PROVIDE USER FEEDBACK
                var add_area = "div_"+add_id;
                if (document.getElementById(add_area)) {
                    document.getElementById(add_area).innerHTML = "adding...";
                }
                
                //SET CURRENT ID FOR SINGLE PRODUCTS
                if (document.getElementById(sku_id)) {
                    current_id = document.getElementById(sku_id).value;
                    var current_array = current_id.split(":");
                    current_add_id = current_array[1];
                    current_cat_id = current_array[0];			
                            
                    //SET QTY AND PRODUCT FORM IDS
                    if (current_cat_id == "cat_0") { 
                        //PRODUCT
                        var qty_id = "qty_"+current_add_id;
                        var product_form_id = "product_form_"+current_add_id;
                    } else {
                        //CATEGORY
                        //alert(current_cat_id);
                        var qty_id = "qty_"+current_cat_id;			
                        var product_form_id = "product_form_"+current_cat_id;
                    }
                    
                }	
            
                if (page_loaded && current_add_id != "") {
                    if (current_add_id) {
                        product_id = current_add_id;
                        current_qty = document.getElementById(qty_id).value;
                        if (validateInteger(current_qty) && current_qty) {
                            
                            //CHECK IF MAX REACHED
                            if (max == 0) {
                                
                                //NO MAX - FINE TO ADD
                                var proceed = true;
                                
                            } else {
                                if (parseInt(current_qty) > parseInt(max)) {
                                
                                    //SELECTED IS OVER MAX - IMMEDIATELY BLOCK
                                    var proceed = false;
                                    alert("You cannot add "+current_qty+" product(s) to your cart.\nThere is a limit of "+max+".");
                                    
                                } else {
                                
                                    //RUN QUERY TO CHECK CART
                                    var url = "filebin/ajax/php/check_max_quantity.php?product_id="+current_add_id+"&cart=dollars";
                                    var xml = new JKL.ParseXML(url);
                                    var data = xml.parse();
                                    if (data.result) {
                                        var in_cart = data.result;
                                        
                                        //alert(parseInt(in_cart) + parseInt(current_qty));
                                        
                                        if ((parseInt(in_cart) + parseInt(current_qty)) > max) {								
                                        
                                            //COMBINATION IS TOO MANY
                                            var proceed = false;
                                            //alert("You cannot add "+current_qty+" product(s) to your cart.\nThere is a limit of "+max+" and you already have "+in_cart+" in your cart.");										
                                            if(student == 'true'){
                                            
                                                launch_pop_up('esStudentMax', current_qty, max, in_cart);
                                            
                                            } else {
                                            
                                                launch_pop_up('maxReachedWarn', current_qty, max, in_cart);
                                            
                                            }
                                                                                
                                        } else {
                                        
                                            //COMBINATION IS BELOW MAX
                                            var proceed = true;
                                    
                                        }
        
                                    } else {
                                        
                                        //DB ERROR - COULDN"T ACCESS CART
                                        var proceed = true;
                                    }
                                }
                            }
                            
                            //alert(proceed);
                            
                            //PROCEED IF MAX NOT REACHED
                            if (proceed) {
                            
                                //var product_id = document.getElementById("product_id").value;
                                var form_obj = document.getElementById(product_form_id);
                                var var_line = "";
                                var more = "action=add_product&product_id="+product_id+"&cat_id="+current_cat_id;
                                //if gift certificate
                                var gc = 0;
                                var gc_err = "";
                                if (form_obj.recipient_name) {
                                    gc = 1;
                                    if (form_obj.purchaser_name && form_obj.purchaser_name.value != "") more+="&purchaser_name="+encodeURIComponent(form_obj.purchaser_name.value);
                                    //else gc_err += "Please, provide Purchaser Name"+"\n";
                                    if (form_obj.recipient_name && form_obj.recipient_name.value != "") more+="&recipient_name="+encodeURIComponent(form_obj.recipient_name.value);
                                    else gc_err += "Please, provide Recipient Name"+"\n";
                                    if (form_obj.recipient_address && form_obj.recipient_address.value != "") more+="&recipient_address="+encodeURIComponent(form_obj.recipient_address.value);
                                    //else gc_err += "Please, provide Recipient Address"+"\n";
                                    if (form_obj.recipient_email && form_obj.recipient_email.value != "") more+="&recipient_email="+encodeURIComponent(form_obj.recipient_email.value);
                                    //else gc_err += "Please, provide Recipient Email"+"\n";
                                    
                                    if (form_obj.recipient_message && form_obj.recipient_message.value != "") more+="&recipient_message="+encodeURIComponent(form_obj.recipient_message.value);
                                    
                                    if (form_obj.tip && parseInt(form_obj.tip.value)>0) more+="&tip="+encodeURIComponent(parseInt(form_obj.tip.value));
                    
                                    if (form_obj.custom_price && parseInt(form_obj.custom_price.value)>0) {
                                        if (document.getElementById("gift_required_amount") && parseInt(form_obj.custom_price.value)>=parseInt(document.getElementById("gift_required_amount").innerHTML))
                                            more+="&custom_price="+encodeURIComponent(parseInt(form_obj.custom_price.value));
                                        else gc_err += "Please, provide right Amount for Certificate"+": "+parseInt(document.getElementById("gift_required_amount").innerHTML)+"\n";
                                    }
                                    else if (form_obj.custom_price) {
                                        gc_err += "Please, provide Amount for Certificate"+"\n";
                                    }
                                    //recipient_message
                                    //more+="&gc_delivery="+encodeURIComponent(form_obj.gc_delivery.value);
                                    //if (form_obj.gc_delivery.value == "Email" && form_obj.recipient_email.value == "") gc_err += "Please, provide Recipient Email"+"\n";
                                }
                                //+"&gift_message="+document.getElementById("gift_message_"+product_id).value;
                                //alert(more);
                    
                                if (document.getElementById(qty_id).value <= 10000) {
                                    //For var and objects
                                    var reqz = 1;
                                    for(i=0;i<form_obj.length;i++) {
                                        //alert(number[i].value);
                                        if (form_obj[i].name == "product_vo") {
                                            if (form_obj[i].value != "") var_line += form_obj[i].value +",";
                                            else reqz = 0;
                                            //alert(form_obj[i].name+" - "+form_obj[i].value);
                                            //k++;
                                        }
                                    }
                                    if (var_line != "") {
                                        var length = var_line.length;
                                        var_line = var_line.substring(0, length-1);
                                        more += "&product_vo="+var_line;
                                    }
                                    more += "&qty="+document.getElementById(qty_id).value;
                                    if (document.getElementById("gift_wrap_"+product_id)) {
                                        if (document.getElementById("gift_wrap_"+product_id).checked == true) more += "&gift_wrap=Yes";
                                        else more += "&gift_wrap=No";
                                    }
                                    else {
                                        more += "&gift_wrap=No";
                                    }
                        
                                    if (gc == 0) {
                                        //no gift certificate:
                                        if (reqz == 1) {
                                            
                                            //DON'T DISPLAY ADDING LAYER ON QUICK CART PAGE - DELETE IF NECESSARY
                                            if (!document.getElementById("quick_cart")) {
                                                display_adding_div(obj,product_id);
                                            }
                                            adding_id = product_id;
                                            setTimeout('sendRequest(\''+more+'\', \'mini_cart\')', 100);
                                            more = "";
                                        }
                                        if (reqz == 0) {
                                            alert("Please, select size...");
                                            more = "";
                                        }
                                    }
                                    else if (gc == 1) {
                                        //gift certificate
                                        if (gc_err == "") {
                                            product_id = current_add_id;
                                            display_adding_div(obj,product_id);
                                            adding_id = product_id;
                                            setTimeout("sendRequest('"+more+"', 'mini_cart')",100);
                                        }
                                        else if (gc_err != "") {
                                            alert(gc_err);
                                            more = "";
                                        }
                                    
                                    }
                                }
                            } //FROM PROCEED
                        }
                        else {
                            //document.getElementById("qty_"+product_id).style.color = 'red';
                        }
                    } else {
                        alert("Please select a product.");
                    }
                }
                setTimeout('restoreButton(\''+add_area+'\',\''+sku_id+'\',\''+add_id+'\',\''+max+'\')',500);		
            }
            }
            catch (e) {
                alert(e);
            }
        } else {
            alert('Browser cookies must be enabled to purchase items.');	
        }
    }


	function add_product_partner(obj, sku_id, add_id, price_id, max) {

	    if (checkIfCookie()) {
			
            if (page_loaded) {
            
                //PROVIDE USER FEEDBACK
                var add_area = "div_"+add_id;
                if (document.getElementById(add_area)) {
                    document.getElementById(add_area).innerHTML = "adding...";
                }
                
                //GET TYPE
                if (document.getElementById('cart_type')) {
                    var type = document.getElementById('cart_type').value;
                } else {
                    var type = "spa";
                }
                if (type == "sales") {
                    var label = "Support Dollars";
                } else {
                    var label = "Partnership Points";		
                }
                
                //SET CURRENT ID FOR SINGLE PRODUCTS
                if (document.getElementById(sku_id)) {
                    current_id = document.getElementById(sku_id).value;
                    var current_array = current_id.split(":");
                    current_add_id = current_array[1];
                    current_cat_id = current_array[0];			
                            
                    //SET QTY AND PRODUCT FORM IDS
                    if (current_cat_id == "cat_0") { 
                        //PRODUCT
                        var qty_id = "qty_"+current_add_id;
                        var product_form_id = "product_form_"+current_add_id;
                    } else {
                        //CATEGORY
                        //alert(current_cat_id);
                        var qty_id = "qty_"+current_cat_id;			
                        var product_form_id = "product_form_"+current_cat_id;
                    }
                                
                    if (page_loaded && current_add_id != "") {
                        if (current_add_id) {
                            product_id = current_add_id;
                            current_qty = document.getElementById(qty_id).value;
                            if (validateInteger(current_qty) && current_qty) {
                            
                                //CHECK IF MAX REACHED
                                if (max == 0) {
                                    
                                    //NO MAX - FINE TO ADD
                                    var proceed = true;
                                    
                                } else {
                                    if (parseInt(current_qty) > parseInt(max)) {
                                    
                                        //SELECTED IS OVER MAX - IMMEDIATELY BLOCK
                                        var proceed = false;
                                        alert("You cannot add "+current_qty+" product(s) to your cart.\nThere is a limit of "+max+".");
                                        
                                    } else {
                                    
                                        //RUN QUERY TO CHECK CART
                                        var url = "filebin/ajax/php/check_max_quantity.php?product_id="+current_add_id+"&cart=partnership";
                                        var xml = new JKL.ParseXML(url);
                                        var data = xml.parse();
                                        if (data.result) {
                                            var in_cart = data.result;
                                            
                                            //alert(parseInt(in_cart) + parseInt(current_qty));
                                            
                                            if ((parseInt(in_cart) + parseInt(current_qty)) > max) {								
                                            
                                                //COMBINATION IS TOO MANY
                                                var proceed = false;
                                                alert("You cannot add "+current_qty+" product(s) to your cart.\nThere is a limit of "+max+" and you already have "+in_cart+" in your cart.");
                                                
                                            } else {
                                            
                                                //COMBINATION IS BELOW MAX
                                                var proceed = true;
                                        
                                            }
            
                                        } else {
                                            
                                            //DB ERROR - COULDN"T ACCESS CART
                                            var proceed = true;
                                        }
                                    }
                                }
                            
                                //PROCEED IF MAX NOT REACHED - BASED ON QTY
                                if (proceed) {
                                
                                    //DETERMINE IF PRODUCT IS TOO MUCH - BASED ON POINTS
                                    if (document.getElementById('total_in_cart') && (document.getElementById('avail_points')) && (document.getElementById(price_id))) {
                                        var total_in_cart = parseFloat(document.getElementById('total_in_cart').value);
                                        var avail_points = parseFloat(document.getElementById('avail_points').value);
                                        var quantity = parseFloat(document.getElementById(qty_id).value);
                                        var price = parseFloat(document.getElementById(price_id).value);
                                        var new_add_price = parseFloat(price * quantity);
                            
                                        //alert(quantity+" * "+price+" = "+new_add_price);							
                                        //alert(total_in_cart+" + "+new_add_price+" <= "+avail_points);
                                        if ((total_in_cart + new_add_price) <= avail_points) { 
                                
                                            //var product_id = document.getElementById("product_id").value;
                                            var form_obj = document.getElementById(product_form_id);
                                            var var_line = "";
                                            var more = "action=add_product_partner&product_id="+product_id+"&cat_id="+current_cat_id+"&price_type="+type;
                                            //if gift certificate
                                            var gc = 0;
                                            var gc_err = "";
                                        
                                            if (document.getElementById(qty_id).value <= 10000) {
                                                //For var and objects
                                                var reqz = 1;
                                                for(i=0;i<form_obj.length;i++) {
                                                    //alert(number[i].value);
                                                    if (form_obj[i].name == "product_vo") {
                                                        if (form_obj[i].value != "") var_line += form_obj[i].value +",";
                                                        else reqz = 0;
                                                        //alert(form_obj[i].name+" - "+form_obj[i].value);
                                                        //k++;
                                                    }
                                                }
                                                if (var_line != "") {
                                                    var length = var_line.length;
                                                    var_line = var_line.substring(0, length-1);
                                                    more += "&product_vo="+var_line;
                                                }
                                                more += "&qty="+document.getElementById(qty_id).value;
                                                if (document.getElementById("gift_wrap_"+product_id)) {
                                                    if (document.getElementById("gift_wrap_"+product_id).checked == true) more += "&gift_wrap=Yes";
                                                    else more += "&gift_wrap=No";
                                                }
                                                else {
                                                    more += "&gift_wrap=No";
                                                }
                                    
                                                if (gc == 0) {
                                                    //no gift certificate:
                                                    if (reqz == 1) {
                                                        
                                                        //DON'T DISPLAY ADDING LAYER ON QUICK CART PAGE - DELETE IF NECESSARY
                                                        if (!document.getElementById("quick_cart") && !document.getElementById("partnership_cart")) {
                                                            display_adding_div(obj,product_id);
                                                        }
                                                        adding_id = product_id;
                                                        setTimeout('sendRequest(\''+more+'\', \'mini_cart\')', 100);
                                                        more = "";
                                                    }
                                                    if (reqz == 0) {
                                                        alert("Please, select size...");
                                                        more = "";
                                                    }
                                                }
                                            }
                                        } else {
                                            alert('You do not have enough '+label+' to make the purchase.');							
                                        
                                        }
                                    }
                                } //FROM PROCEED
                            }
                        } else {
                            alert("Please select a product.");
                        }	
                        
                    } else {
                        alert("Please select a product.");
                    }
                }
                setTimeout('restoreButtonPartner(\''+add_area+'\',\''+sku_id+'\',\''+add_id+'\',\''+price_id+'\',\''+max+'\')',500);		
            }
        } else {
            alert('Browser cookies must be enabled to purchase items.');	
        }
	}
	
	function addSample(id) {

		//CHECK IF ACTIVE
		var sampleElement = "sampleElement_"+id;
		if (document.getElementById(sampleElement)) {
			if (document.getElementById(sampleElement).className == "sample_cart_ind") {
		
				//PROVIDE FEEDBACK
				var sampleControl = "sampleControl_"+id;
				if (document.getElementById(sampleControl)) {
						document.getElementById(sampleControl).innerHTML = "<div class='sampleControl_adding'>Adding...</div>";
				}
			
				//GET DATA
				setTimeout("addSample_action('"+id+"')",100);
			}
		}
	}
	
	function addSample_action(id) {

		//ADD SAMPLE TO CART	
		var url = "filebin/ajax/php/addSample.php?id="+id+"&action=add";
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		if (data.result.success == "success") {

			//CHANGE BACKGROUND
			var sampleElement = "sampleElement_"+id;
			if (document.getElementById(sampleElement)) {
					document.getElementById(sampleElement).className = "sample_cart_ind_selected";
			}
	
			//RESET BUTTON
			var sampleControl = "sampleControl_"+id;
			if (document.getElementById(sampleControl)) {
					document.getElementById(sampleControl).innerHTML = "<div class='sampleControl_selected'>Added To Bag</div><a href='#' onclick='removeSample(\""+id+"\"); return false;' class='sampleRemoveButton'>Remove</a>";
			}
			
			//CHECK IF LIMIT IS REACHED AND CHANGE NON-SELECTED
			if (data.result.selected > 2 && data.result.nonselected) {
				var nonselected_arr = data.result.nonselected.split(",");
				for (var i = 0; i < nonselected_arr.length; i++) {

					//CHANGE NON-SELECTED
					var sampleControl = "sampleControl_"+nonselected_arr[i];
					if (document.getElementById(sampleControl)) {
							document.getElementById(sampleControl).innerHTML = "<div class='sampleControl_limit'>You Have Selected Your Three Samples</div>";
					}					

					//CHANGE  NON-SELECTED
					var sampleElement = "sampleElement_"+nonselected_arr[i];
					if (document.getElementById(sampleElement)) {
							document.getElementById(sampleElement).className = "sample_cart_ind_limit";
					}

				}
			}

		} else {

			//CHANGE BACKGROUND
			var sampleElement = "sampleElement_"+id;
			if (document.getElementById(sampleElement)) {
					document.getElementById(sampleElement).className = "sample_cart_ind";
			}

			//RESET BUTTON
			var sampleControl = "sampleControl_"+id;
			if (document.getElementById(sampleControl)) {
					document.getElementById(sampleControl).innerHTML = "<a href='#' onclick='addSample(\""+id+"\"); return false;'><img src='filebin/cart_images/add_cart_samples.gif' alt='Add to Bag' class='sampleAddButton' style='border: none;' /></a>";
			}
		
		}

	}	

	function removeSample(id) {

		//PROVIDE FEEDBACK
		var sampleControl = "sampleControl_"+id;
		if (document.getElementById(sampleControl)) {
				document.getElementById(sampleControl).innerHTML = "<div class='sampleControl_removing'>Removing...</div>";
		}
	
		//GET DATA
		setTimeout("removeSample_action('"+id+"')",100);

	}
	
	function removeSample_action(id) {

		//REMOVE SAMPLE FROM CART	
		var url = "filebin/ajax/php/addSample.php?id="+id+"&action=remove";
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		if (data.result.success == "success") {

			//CHANGE BACKGROUND
			var sampleElement = "sampleElement_"+id;
			if (document.getElementById(sampleElement)) {
					document.getElementById(sampleElement).className = "sample_cart_ind";
			}
	
			//RESET BUTTON
			var sampleControl = "sampleControl_"+id;
			if (document.getElementById(sampleControl)) {
					document.getElementById(sampleControl).innerHTML = "<a href='#' onclick='addSample(\""+id+"\"); return false;'><img src='filebin/cart_images/add_cart_samples.gif' alt='Add to Bag' class='sampleAddButton' style='border: none;' /></a>";
			}
			
			//CHECK IF LIMIT HAD BEEN REACHED AND CHANGE NON-SELECTED
			if (data.result.selected == 2 && data.result.nonselected) {
				var nonselected_arr = data.result.nonselected.split(",");
				for (var i = 0; i < nonselected_arr.length; i++) {

					//CHANGE NON-SELECTED
					var sampleControl = "sampleControl_"+nonselected_arr[i];
					if (document.getElementById(sampleControl)) {
							document.getElementById(sampleControl).innerHTML = "<a href='#' onclick='addSample(\""+nonselected_arr[i]+"\"); return false;'><img src='filebin/cart_images/add_cart_samples.gif' alt='Add to Bag' class='sampleAddButton' style='border: none;' /></a>";
					}					

					//CHANGE BACKGROUND
					var sampleElement = "sampleElement_"+nonselected_arr[i];
					if (document.getElementById(sampleElement)) {
							document.getElementById(sampleElement).className = "sample_cart_ind";
					}

				}
			}

		} else {

			//CHANGE BACKGROUND
			var sampleElement = "sampleElement_"+id;
			if (document.getElementById(sampleElement)) {
					document.getElementById(sampleElement).className = "sample_cart_ind_selected";
			}

			//RESET BUTTON
			var sampleControl = "sampleControl_"+id;
			if (document.getElementById(sampleControl)) {
					document.getElementById(sampleControl).innerHTML = "<div class='sampleControl_selected'>Added To Bag</div><a href='#' onclick='removeSample(\""+id+"\"); return false;' class='sampleRemoveButton'>Remove</a>";
			}
		
		}

	}	

	function removeSampleCart(id, sample_id) {

		//PROVIDE FEEDBACK
		var sampleControl = "sampleCartRemove_"+id;
		if (document.getElementById(sampleControl)) {
				document.getElementById(sampleControl).innerHTML = "<div class='sampleControlCart_removing'>Removing...</div>";
		}
	
		//GET DATA
		setTimeout("removeSampleCart_action('"+id+"','"+sample_id+"')",100);

	}
	
	function removeSampleCart_action(id, sample_id) {

		//REMOVE SAMPLE TO CART	
		var url = "filebin/ajax/php/addSample.php?id="+sample_id+"&action=remove";
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		if (data.result.success == "success") {

			//CHANGE ELEMENT
			var sampleElement = "cartSample_"+id;
			if (document.getElementById(sampleElement)) {
					document.getElementById(sampleElement).className = "blankSampleCart";
			}

			//CHANGE ELEMENT CONTENT
			var sampleElementImage = "sampleCartImage_"+id;
			if (document.getElementById(sampleElementImage)) {
					document.getElementById(sampleElementImage).innerHTML = "<table cellspacing='0' cellpadding='0' class='cartSampleTable'><tr><td valign='middle' align='center' width='144' height='78'><a href='#' onclick='jumpToSamples(); return false;' 	class='subtle'>Choose a FREE sample</a></td></tr></table>";
			}
	
			//CHANGE NUMBER CLASS
			var sampleNum = "sampleNum_"+id;
			if (document.getElementById(sampleNum)) {
				document.getElementById(sampleNum).className = "sampleNumBlank";
			}
			
			//CHANGE WARNING IF NECESSARY
			if (data.result.selected == 2 && data.result.nonselected) {
				if (document.getElementById('sampleWarning')) {
					document.getElementById('sampleWarning').innerHTML = "WAIT! Don't checkout before selecting your 3 FREE samples.";
				}
			}
			
		} else {

			//RESET BUTTON
			var sampleControl = "sampleCartRemove_"+id;
			if (document.getElementById(sampleControl)) {
					document.getElementById(sampleControl).innerHTML = "<a href='' onclick='removeSampleCart(\""+id+"\"); return false;'>Remove</a>";
			}
		
		}

	}	


	
	function restoreButtonPartner(add_area, sku_id, add_id, price_id, max) {
	
		//REPLACE ADD TO CART BUTTON
		//DETERMINE IF PRODUCT OR PRODUCT CAT
		if (document.getElementById(add_area)) {
			document.getElementById(add_area).innerHTML = "<a href='#' onclick='add_product_partner(this,\""+sku_id+"\",\""+add_id+"\",\""+price_id+"\",\""+max+"\"); return false;' id='"+add_id+"' title='Redeem with Points'><img src='filebin/cart_images/redeem_btn.gif' alt='Redeem with Points' border='0' /></a>";		
		}	
	
	}

	function restoreButton(add_area, sku_id, add_id, max) {
	
		//REPLACE ADD TO CART BUTTON
		//DETERMINE IF PRODUCT OR PRODUCT CAT
		if (document.getElementById(add_area)) {
			document.getElementById(add_area).innerHTML = "<a href='#' onclick='add_product(this,\""+sku_id+"\",\""+add_id+"\",\""+max+"\"); return false;' id='"+add_id+"' title='Add to Cart'><img src='filebin/cart_images/add_cart_btn.gif' alt='Add to Order' border='0' /></a>";		
		}	
	
	}

	function change_zip() {
		var more = "action=zip&zip="+document.getElementById("zip").value;
		//setTimeout("sendRequest('"+more+"', 'mini_cart')",100);
		sendRequest(more,'mini_cart');
	}
	
	function clear_cart() {
		var more = "action=clear_cart";
		sendRequest(more,'mini_cart');
	}
	
	function update_shipping() {
		var shipping_set = document.getElementsByName("shipping");
		var ship_value = "";
		if (shipping_set.length>0) {
			for (i=0;i<shipping_set.length;i++) {
				//alert(shipping_set[i].type+" "+shipping_set[i].checked+" "+shipping_set[i].value);
				if (shipping_set[i].type == "radio" && shipping_set[i].checked == true) ship_value = shipping_set[i].value;
			}
		}
		var more = "action=shipping&shipping="+ship_value;
		//setTimeout("sendRequest('"+more+"', 'mini_cart')",100);
		sendRequest(more,'mini_cart');
	}
	function display_cart() {
	    if (checkIfCookie()) {
            if (document.getElementById("mini_cart").style.display == "none") document.getElementById("mini_cart").style.display='block';
            else document.getElementById("mini_cart").style.display='none';
            //update_view();
        } else {
            alert('Browser cookies must be enabled to purchase items.');	
        }
    }
	function add_coupon() {
		if (document.getElementById("coupon").value != "") {
			var more = "action=coupon&coupon="+document.getElementById("coupon").value;
			sendRequest(more, "mini_cart");
		}
	}
	function update_view() {
		http.open("get", "cart_total.php");
		http.onreadystatechange = handleResponse1;
		http.send(null);
	}
	function add_info(prod_id,cat_id) {
		
		//DETERMINE IF PRODUCT OR PRODUCT CAT
		if (prod_id.substr(0,1)=="c") {
			var qty_id = "qty_"+cat_id;		
		} else {
			var qty_id = "qty_"+prod_id;		
		}
		
		var qty = document.getElementById(qty_id).value;
		http.open("get", "filebin/ajax/php/add_product_info.php?product_id="+prod_id+"&cat_id="+cat_id+"&qty="+qty);
		http.onreadystatechange = handleResponse2;
		http.send(null);
		
		//REFRESH SIDE CART IF NECSSARY
		if (document.getElementById('quick_cart')) {
			refresh_quick_cart();
		}
	}
	function refresh_quick_cart() {
		var url = "filebin/ajax/php/refresh_quick_cart.php";
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		if (data.result.side) {
			if (document.getElementById('quick_cart')) {
				document.getElementById('quick_cart').innerHTML = data.result.side;
			}
		}
		if (data.result.total) {
			if (document.getElementById('quick_cart_total')) {
				document.getElementById('quick_cart_total').innerHTML = data.result.total;
			}
		}
		
	}
	function refresh_partnership_cart() {
		if (document.getElementById('cart_type')) {
			var type = document.getElementById('cart_type').value;
		} else {
			var type = "spa";
		}
		var url = "filebin/ajax/php/refresh_partnership_cart.php?type="+type;
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		if (data.result.side) {
			if (document.getElementById('partnership_cart')) {
				document.getElementById('partnership_cart').innerHTML = data.result.side;
			}
		}
		if (data.result.total) {
			if (document.getElementById('partnership_cart_total')) {
				document.getElementById('partnership_cart_total').innerHTML = data.result.total;
			}
		}
		if (data.result.top) {
			if (document.getElementById('pointsHead')) {
				document.getElementById('pointsHead').innerHTML = data.result.top;
			}
		}
		//update head content
		if (document.getElementById('total_in_cart') && document.getElementById('avail_points')) {
			if (type == "sales") {
				total_in_cart = format_money(document.getElementById('total_in_cart').value);
				avail_points = format_money(document.getElementById('avail_points').value);		
				points_remain = (avail_points - total_in_cart)+'';				
				points_remain = format_money(points_remain);
			} else {
				total_in_cart = document.getElementById('total_in_cart').value;
				avail_points = document.getElementById('avail_points').value;	
				points_remain = avail_points - total_in_cart;
			}

			//refresh head content
			if (document.getElementById('pointsUsed')) {
				document.getElementById('pointsUsed').innerHTML = total_in_cart;
			}
			if (document.getElementById('pointsRemain')) {
				document.getElementById('pointsRemain').innerHTML = points_remain;
			}	
			if (document.getElementById('graphFront')) {
				var blocker_height = 229 - (229 * (total_in_cart/avail_points)); //HEIGHT OF BAR - 229 AT 100%
				document.getElementById('graphFront').style.height = blocker_height+"px";
			}				
		}
	}	
	function handleResponse2() {
	   if(http.readyState == 4 && http.status == 200){
		  var response = http.responseText;
		  if(response) {
			 if (document.getElementById("adding_layer")) document.getElementById("adding_layer").innerHTML = response;
		  }
	
	   }
	
	}
	function handleResponse1() {
	   if(http.readyState == 4 && http.status == 200){
		  var response = http.responseText;
		  if(response) {
			 // UPDATE ajaxTest content
			 if (document.getElementById("cart_total")) {
				 document.getElementById("cart_total").innerHTML = response;
			 }
			 if (current_add_id && current_add_id != "") {
				var pr_add_id = current_add_id;
				var pr_cat_id = current_cat_id;
				
				//RESET CHOICE
				current_add_id = "";
				current_cat_id = "";
				if (document.getElementById("current_price") && pr_cat_id != "cat_0") {
					document.getElementById("current_price").innerHTML = "Price:&nbsp;select&nbsp;a&nbsp;product";
				}
				var sku_reset = "skuDrop_"+pr_cat_id;
				if (document.getElementById(sku_reset)) {
					document.getElementById(sku_reset).selectedIndex=0;
				}					
				if (document.getElementById("adding_layer")) add_info(pr_add_id, pr_cat_id);
			 }
		  }
		  else {
			response = "something";  
		  }
	
	   }
	
	}
	function close_adding_layer() {
		if (document.getElementById("adding_layer")) {
			document.getElementById("adding_layer").style.display = "none";
			document.getElementById("adding_layer").innerHTML = holder;
			if (document.getElementById('overlay').style.display != 'none') hideOverlay();
			if (browser == 'Internet Explorer'){
				hideSelects('visible');
			}
			adding_id = "";
		}
	}
//


	function trimAll( strValue ) {
	 var objRegExp = /^(\s*)$/;
		//check for all spaces
		if(objRegExp.test(strValue)) {
		   strValue = strValue.replace(objRegExp, '');
		   if( strValue.length == 0)
			  return strValue;
		}
	   //check for leading & trailing spaces
	   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	   if(objRegExp.test(strValue)) {
		   //remove leading and trailing whitespace characters
		   strValue = strValue.replace(objRegExp, '$2');
		}
	  return strValue;
	}
	function validate_email() {
		var more = "email="+document.getElementById("email_reg").value;
		sendRequest(more,'check_email');
	}
	function clear_check() {
		document.getElementById("check_email").innerHTML = "&nbsp;";
	}
//registry suff here:
	var product_list_id = "";
	//keep current hml content in spec var
	var whishlist_html = "";
	function add_wishlist(product_id, mc_account_id, wishlist_id) {
		if (product_id == "") product_id = product_list_id;
		product_list_id = "";
		var more = "product_id="+product_id+"&wishlist_id="+wishlist_id;
		if (mc_account_id != "") {
			//get qty if not set to 1;
			var qty = 1;
			if (document.getElementById("qty")) qty = parseInt(document.getElementById("qty").value);
			//validateInteger(document.getElementById("qty_"+product_id).value)
			if (qty>0) {
					//For var and objects
					var form_obj = document.getElementById("form_"+product_id);
					var var_line = "";
					for(i=0;i<form_obj.length;i++) {
						//alert(number[i].value);
						if (form_obj[i].name == "product_vo") {
							if (form_obj[i].value != "") var_line += form_obj[i].value +",";
							//alert(form_obj[i].value);
							//k++;
						}
					}
					if (var_line != "") {
						var length = var_line.length;
						var_line = var_line.substring(0, length-1);
						more += "&product_vo="+var_line;
					}
					//end var and options
				
					more += "&qty="+qty;
					var url = "filebin/xml/add_wishlist_xml.php?"+more;
					var xml = new JKL.ParseXML(url);
					var data = xml.parse();
					var suc = data.instance.action;
					if (suc==1) {
						if (document.getElementById("registry_list")) {
							whishlist_html = document.getElementById("registry_list").innerHTML;
							document.getElementById("registry_list").innerHTML = data.instance.html_return;
						}
						else {
							alert("Product In Your Wish List!");
							close_reg();
						}
						//document.getElementById("wish_"+product_id).value = "In WL";
					}
					else {
						alert("Oops!");
						//document.getElementById("wish_"+product_id).value = "Add WL";
						//document.getElementById("wish_"+product_id).disabled = false;
					}
					//close_reg();
			}
			else {
				//document.getElementById("qty_"+product_id).style.color = 'red';
			}
		}
		else {
			alert("You have to login to your account first.");	
		}
	}

function show_registry(e, product_id) {
	if (page_loaded && document.getElementById("registry_list").style.display != "block") {
		var tempX = 0;
		var tempY = 0;
		var offset = 5;
		product_list_id = product_id;
		if (document.all) {
			tempX = event.clientX + document.documentElement.scrollLeft;//document.body.scrollLeft;
			tempY = event.clientY + document.documentElement.scrollTop;//document.body.scrollTop;
			//alert(event.clientY+" ScrollTop:"+document.documentElement.scrollTop);
		} 
		else {
			tempX = e.pageX;
			tempY = e.pageY;
		}

		// step 4
		if (tempX < 0){tempX = 0}
		if (tempY < 0){tempY = 0}
	
		document.getElementById("registry_list").style.left = tempX+"px";
		document.getElementById("registry_list").style.top = tempY+"px";
		//alert(tempX+" "+tempY);
		//lightbox action
		showOverlay();
		if (browser == 'Internet Explorer'){
			hideSelects('hidden');
		}
		//end light box action;
		document.getElementById("registry_list").style.display = "block";
		//event_d(id, page_id);
	}
  }
 
 function centerDiv(targetDiv, topMargin, divWidth) {

	//GET SCREEN SIZE
	var intH = 0;
	var intW = 0;

	if (self.innerHeight) {
	   intH = window.innerHeight;
	   intW = window.innerWidth;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			intH = document.documentElement.clientHeight;
			intW = document.documentElement.clientWidth;
		} else {
			if (document.body) {
				intH = document.body.clientHeight;
				intW = document.body.clientWidth;
			}
		}
	}
	
	//GET SCROLL POSITION FOR POP-UP Y-POSITION
	var spos = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	
	var ypos = parseInt(spos + parseInt(topMargin), 10); //INCLUDES TOP MARGIN
	var xpos = parseInt((intW - parseInt(divWidth)) / 2, 10); //INCLUDES WIDTH OF DIV

	document.getElementById(targetDiv).style.left = xpos+"px";
	document.getElementById(targetDiv).style.top = ypos+"px";

	//SHOW OVERLAY
	showOverlay();		

	//HIDE SELECTS
	if (browser == 'Internet Explorer'){
		hideSelects('hidden');
	}

	//SHOW TARGET DIV
	document.getElementById(targetDiv).style.display = "block";
 
 } 
 
  function centerDivFloat(targetDiv, topMargin, targetHolderDiv) {

	//SET TOP MARGIN, BUT ALWAYS TIE TO RIGHT EDGE OF SCREEN

	//GET SCREEN SIZE
	var intH = 0;
	var intW = 0;

	if (self.innerHeight) {
	   intH = window.innerHeight;
	   intW = window.innerWidth;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			intH = document.documentElement.clientHeight;
			intW = document.documentElement.clientWidth;
		} else {
			if (document.body) {
				intH = document.body.clientHeight;
				intW = document.body.clientWidth;
			}
		}
	}
	
	//GET SCROLL POSITION FOR POP-UP Y-POSITION
	var spos = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;

	//GET TOP OF TARGET DIV
	var coordHolder = findPos(document.getElementById(targetHolderDiv));

	var ypos = parseInt(spos + parseInt(topMargin), 10) - parseInt(coordHolder[1]); //INCLUDES TOP MARGIN - ACCOUNT FOR HEIGHT OF CONTAINER HEIGHT
	
	document.getElementById(targetDiv).style.top = ypos+"px";

	//SHOW OVERLAY
	showOverlay();		

	//HIDE SELECTS
	if (browser == 'Internet Explorer'){
		hideSelects('hidden');
	}

	//SHOW TARGET DIV
	document.getElementById(targetDiv).style.display = "block";
	
 } 
 
  function close_reg() {
	if (document.getElementById("registry_list") && document.getElementById("registry_list").style.display != "none") {
		document.getElementById("registry_list").style.display = "none";
		if 	(document.getElementById("registry_list")) {
			if (whishlist_html != "") {
				document.getElementById("registry_list").innerHTML = whishlist_html;
				whishlist_html = "";
			}
		}
		//lightbox close:
		if (document.getElementById('overlay').style.display != 'none') {
			hideOverlay();
			hideSelects('visible');
		}
		//
	}
  }
  function reg_on(obj) {
	  obj.className = "div_on";
  }
  function reg_off(obj) {
	  obj.className = "div_off";
  }
  //////////
	//////////
function event_d() {
	var more = "action=form_find";
	sendRequest(more,'event_detail');
}
function event_d_find(find_id) {
	var more = "action=form_find&find_id="+find_id;
	sendRequest(more,'event_detail');
}
function moveObject1(e) {

	if (browser == 'Internet Explorer'){
		hideSelects('hidden');
	}
   	centerDiv('event_detail', 100, 360); 	
	event_d();
}
  function moveObject_find(e, find_id) {
	if (page_loaded && document.getElementById("event_detail").style.display != "block") {
	  var tempX = 0;
	  var tempY = 0;
	  var offset = 5;
	
	  if (document.all) {
		tempX = event.clientX + document.documentElement.scrollLeft;//document.body.scrollLeft;
		tempY = event.clientY + document.documentElement.scrollTop;//document.body.scrollTop;
		//alert(event.clientY+" ScrollTop:"+document.documentElement.scrollTop);
	  } 
	  else {
		tempX = e.pageX;
		tempY = e.pageY;
	  }

	// step 4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}
  	tempY = tempY - 45;
	//document.getElementById("event_iframe").style.left = tempX+"px";
	//document.getElementById("event_iframe").style.top = tempY+"px";
	//alert(tempX+" "+tempY);
	//document.getElementById("event_iframe").style.display = "block";
	
	document.getElementById("event_detail").style.left = tempX+"px";
	document.getElementById("event_detail").style.top = tempY+"px";
	//alert(tempX+" "+tempY);
	document.getElementById("event_detail").style.display = "block";
	//lightbox action
	showOverlay();
	if (browser == 'Internet Explorer'){
		hideSelects('hidden');
	}
	//end light box action;
	event_d_find(find_id);
	}
  }
function moveObject(e) {
  var tempX = 0;
  var tempY = 0;
  var offset = 5;

  if (document.all) {
    tempX = event.clientX + document.documentElement.scrollLeft;//document.body.scrollLeft;
    tempY = event.clientY + document.documentElement.scrollTop;//document.body.scrollTop;
	//alert(event.clientY+" ScrollTop:"+document.documentElement.scrollTop);
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }

  // step 4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  	tempY = tempY - 45;
	document.getElementById("event_iframe").style.left = tempX+"px";
	document.getElementById("event_iframe").style.top = tempY+"px";
	//alert(tempX+" "+tempY);
	document.getElementById("event_iframe").style.display = "block";
	
	document.getElementById("event_detail").style.left = tempX+"px";
	document.getElementById("event_detail").style.top = tempY+"px";
	//alert(tempX+" "+tempY);
	document.getElementById("event_detail").style.display = "block";
	event_d();
  }
  
 function close_div() {
	if (document.getElementById("event_detail")) {
		if (document.getElementById("event_iframe")) document.getElementById("event_iframe").style.display = "none";
		//lightbox close:
		if (document.getElementById('overlay').style.display != 'none') {
			hideOverlay();
			hideSelects('visible');
		}
		//
		document.getElementById("event_detail").style.display = "none";
	}
 }
 function send_email() {
	obj = document.s_email;
	var more = "action=send_email";
	more += "&your_name="+encodeURI(obj.your_name.value);
	more += "&your_email="+encodeURI(obj.your_email.value);
	more += "&friend_name="+encodeURI(obj.friend_name.value);
	more += "&friend_email="+encodeURI(obj.friend_email.value);
	more += "&page_url="+location.href;
	sendRequest(more,'event_detail');
 }
 function send_find_email() {
	obj = document.s_email;
	var more = "action=send_find_email";
	more += "&your_name="+encodeURI(obj.your_name.value);
	more += "&your_email="+encodeURI(obj.your_email.value);
	more += "&page_url="+location.href+"?find_id="+encodeURI(obj.find_id.value);
	sendRequest(more,'event_detail');
 }
function printpage() {
	window.print();  
}
var https_bool = false;
if(location.protocol == "https:") https_bool = true;
addOnloadEvent(load_mini_cart);
addOnloadEvent(set_holder);

// TO set products total on Load use bellow
//addOnloadEvent(apply_price_options);
//set array to keep var and option
var var_opt_arr = new Array();

function load_mini_cart() {
	if (document.getElementById("mini_cart") && !https_bool) sendRequest("action=display", "mini_cart");
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function display_adding_div(obj,id) {
	if (obj) {
		var spec_objs = obj.getElementsByTagName("img");
		var img_obj = spec_objs[0];
		if (document.getElementById("productsContent_"+id)) {
			img_obj = document.getElementById("productsContent_"+id);
		}
		
		//OLD STYLE FOR DISPLAYING POP-UP LAYER
		/*var coor = findPos(img_obj);
		//set coordinat for adding layer
		if (document.getElementById("adding_layer")) {
			var obj_display = document.getElementById("adding_layer");
			if (browser == 'Internet Explorer'){
				//alert("Change");
				hideSelects('hidden');
			}
			if (obj_display.style.display == "block") {
				obj_display.style.display = "none";
				obj_display.innerHTML = holder;
			}
			if (document.getElementById("productsContent_"+id)) {
				coor[0] = coor[0] + (parseInt(document.getElementById("productsContent_"+id).offsetWidth) - 400) - 2;
				coor[1] = coor[1] + (parseInt(document.getElementById("productsContent_"+id).offsetHeight) - 100) - 2;
				//alert("Div: "+coor[0]+"  "+coor[1]);
			}
			else {
				//we are on a product page based on add to cart image button
				coor[0] = coor[0] + (parseInt(img_obj.width) - 345);
				coor[1] = coor[1] - 1;
				//alert("image: "+img_obj.width+" - "+img_obj.height);
			}
			showOverlay();
			obj_display.style.left = coor[0]+"px";
			obj_display.style.top = coor[1]+"px";
			obj_display.style.display = "block";
		}
		*/
		
		//NEW STYLE
    	centerDivFloat('adding_layer', 100, 'adding_layerHolder'); 
		
	}
	
}
function update_full_cart() {
	if (document.getElementById("FloatingLayer") || document.getElementById("FloatingLayerShoppingCart")) {
		if (document.getElementById("FloatingLayer")) var obj = document.getElementById("FloatingLayer");
		if (document.getElementById("FloatingLayerShoppingCart")) var obj = document.getElementById("FloatingLayerShoppingCart");
		//gather all input/select boxes:
		var inps = obj.getElementsByTagName("input");
		var sel = obj.getElementsByTagName("select");
		//prep post string:
		var updateStr = "";
		var selStr = "";
		var radStr = "";
		if (inps.length>0) {
			for(i=0; i<=inps.length-1;i++) {//alert(inps[i].name+": "+inps[i].value);
				if (inps[i].type == "text") {
					updateStr += inps[i].name+"="+encodeURIComponent(inps[i].value);
				}
				else if (inps[i].type == "radio") {
					if (inps[i].name == "shipping" && inps[i].checked==true) updateStr += inps[i].name+"="+encodeURIComponent(inps[i].value);
				}
				if (i<inps.length-1) updateStr += "&";
			}
			//select here
			if (sel.length>0) {
				for(i=0; i<=sel.length-1;i++) {
					selStr += sel[i].name+"="+encodeURIComponent(sel[i].value);
					if (i<sel.length-1) selStr += "&";
				}
			}
		}
		if (updateStr != "") {
			//do post here
			if (selStr != "") updateStr+="&"+selStr;
			//alert(updateStr);
			post_full_cart('update_full_cart.php', updateStr);
		}
	}
	else {
		alert("nothing to update");
	}
}
//var http_request_post_post = false;
//var http_request_post = false;
function post_full_cart(url, parameters) {
	http_request_post = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request_post = new XMLHttpRequest();
		if (http_request_post.overrideMimeType) {
			http_request_post.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
	 try {
		http_request_post = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request_post = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
	}
  if (!http_request_post) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  http_request_post.onreadystatechange = return_post;
  http_request_post.open('POST', url, true);
  http_request_post.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request_post.setRequestHeader("Content-length", parameters.length);
  http_request_post.setRequestHeader("Connection", "close");
  http_request_post.send(parameters);
}

function return_post() {
   //alert(http_request_post.status);
  if (http_request_post.readyState == 4) {
	 if (http_request_post.status == 200) {
		result = http_request_post.responseText;
		document.getElementById('mini_cart').innerHTML = result;
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}

function reveal_coupon() {
	if (document.getElementById("coupon_holder_div")) {
		if (document.getElementById("coupon_holder_div").style.display == "none") {
			document.getElementById("coupon_holder_div").style.display = "block";
		} else {
			document.getElementById("coupon_holder_div").style.display = "none";		
		}
	}
}

function reveal_shipping_options() {
	if (document.getElementById("shipping_hider")) {
		if (document.getElementById("shipping_hider").style.display == "none") {
			document.getElementById("shipping_hider").style.display = "block";
			if (document.getElementById("shipping_hider_label")) {
				document.getElementById("shipping_hider_label").innerHTML = "<a href='#' onclick='reveal_shipping_options(); return false;' class='subtle'>hide options</a>";
			}
		} else {
			document.getElementById("shipping_hider").style.display = "none";		
			if (document.getElementById("shipping_hider_label")) {
				document.getElementById("shipping_hider_label").innerHTML = "<a href='#' onclick='reveal_shipping_options(); return false;' class='subtle'>more options</a>";
			}			
		}
	}
}

function reveal_tax() {
	if (document.getElementById("tax_hider")) {
		if (document.getElementById("tax_hider").style.display == "none") {
			document.getElementById("tax_hider").style.display = "block";
			if (document.getElementById("tax_hider_label")) {
				document.getElementById("tax_hider_label").innerHTML = "<a href='#' onclick='reveal_tax(); return false;' class='subtle'>hide tax</a>";
			}
		} else {
			document.getElementById("tax_hider").style.display = "none";		
			if (document.getElementById("tax_hider_label")) {
				document.getElementById("tax_hider_label").innerHTML = "<a href='#' onclick='reveal_tax(); return false;' class='subtle'>Colorado residents calculate tax</a>";
			}			
		}
	}
}

//Shopping cart table
var shoppingCartTable;
var shoppingCartTableBody;
function init_shoppingcart_table() {
    shippingTable = document.getElementById("shopping_cart_table");
    shippingTableBody = shippingTable.tBodies[0];
}
function insertTableRow_shoppingcart(where,cell1,cell2,type) {
	//alert(where);
	var newRow = shoppingCartTableBody.insertRow(where);
	var newCell;
	newCell = newRow.insertCell(0);
	newCell.innerHTML = cell1;
	newCell.className = "checkoutCell";
	newCell.valign="middle";
	//alert(cell1);
	//add message place for member here
	var newCell;
	newCell = newRow.insertCell(1);
	newCell.innerHTML="&nbsp;";
	
	var newCell;
	newCell = newRow.insertCell(2);
	newCell.innerHTML=cell2;
	newCell.className = "checkoutCell";
	
	var newCell;
	newCell = newRow.insertCell(3);
	newCell.innerHTML="&nbsp;";
	
}
function setRow(){
 	var theRow = document.getElementById("coupon_reveal_span").parentNode;
	//alert(theRow.nodeName);
 	while(theRow && theRow.nodeName!="TR"){
		theRow = theRow.parentNode;
	}
	if(theRow.nodeName=="TR"){
		//theBtn.form.rowID.value = 
		//alert(theRow.rowIndex);
		reveal_coupon(theRow.rowIndex);
	}
}

//CUSTOM FUNC TO PAGE DROPDOWN
function changePage(newLoc) {
   nextPage = newLoc.options[newLoc.selectedIndex].value	
   		if (nextPage != "") {
      	document.location.href = nextPage}
}

//CUSTOM FUNC TO UPDATE PRODUCT ID
function update_current_id(sku_id,price_id) {
	
	if (document.getElementById(sku_id)) {
	
		current_id = document.getElementById(sku_id).value;
		var current_array = current_id.split(":");
		current_add_id = current_array[1];
		current_cat_id = current_array[0];
		
		//alert("current_add_id: "+current_add_id+" current cat id: "+current_cat_id);
		
		//GET PRICE IF NECESSARY
		if (document.getElementById("current_price")) {
			var url = "filebin/xml/current_price_xml.php?current_id="+current_add_id;
			var xml = new JKL.ParseXML(url);
			var data = xml.parse();
			var current_price = data.current_price;	
			if (current_price) {
				document.getElementById("current_price").innerHTML = "Price:&nbsp;$"+current_price;

				//TO CHECK FOR NOT ENOUGH SUPPORT DOLLARS
				//alert(current_points);
				if (document.getElementById(price_id)) {
					document.getElementById(price_id).value = current_points;				
				}
			} else {
				document.getElementById("current_price").innerHTML = "Price:&nbsp;select&nbsp;an&nbsp;option";
			}
		}

		//GET PRICE FOR SALES CONSULTANTS QUICK ORDER FORM
		if (document.getElementById("salesHead")) {
			var url = "filebin/xml/current_price_xml.php?current_id="+current_add_id;
			var xml = new JKL.ParseXML(url);
			var data = xml.parse();
			var current_price = data.current_price;	
			if (current_price) {
				//alert(current_price);
				document.getElementById(price_id).value = current_price;				
			}
		}

		
		//GET POINTS IF NECESSARY FOR SPAS QUICK ORDER FORM
		if (document.getElementById('pointsHead')) {
			var url = "filebin/xml/current_points_xml.php?current_id="+current_add_id;
			var xml = new JKL.ParseXML(url);
			var data = xml.parse();
			var current_points = data.current_points;	
			if (current_points!="") {
					//alert(current_points);
					document.getElementById(price_id).value = current_points;
			}
			//alert(current_points);
		}
		
		//UPDATE ALT IMAGES IF NECESSARY
		if (document.getElementById("alt_images") && current_add_id) {
			var image_id = current_add_id.substr(4);
			//alert(image_id);
			if (imagePaths[image_id]) {
				document.getElementById("full_image").src = imagePaths[image_id];		
			}
		}
	}
}

//FUNCTIONS FOR QUICK ORDER FORMS
function show_sub(section_id, type, modolo) {
	var sub_section = "sub_pages_"+section_id;
	var closer = "main_closer_"+section_id;
	var main_use = "main_page_"+section_id;	
	if (document.getElementById(sub_section)) {
		if (document.getElementById(sub_section).style.display == "none") {
			document.getElementById(sub_section).style.display = "block";
		if (document.getElementById(closer)) {
			document.getElementById(closer).src = "filebin/images/form_heads/close_"+modolo+".gif";
		}
		if (document.getElementById(main_use)) {
				if (document.getElementById(main_use).className == "main_page_TOP_"+modolo) {
					document.getElementById(main_use).className = "main_page_highlight_TOP_"+modolo;
				} else if (document.getElementById(main_use).className == "main_page_SECOND_"+modolo) {
					document.getElementById(main_use).className = "main_page_highlight_SECOND_"+modolo;				
				}
			}			
			//UPDATE DB
			var url = "filebin/ajax/php/update_form_display.php?id="+section_id+"&action=add&type="+type;
			var xml = new JKL.ParseXML(url);
			var data = xml.parse();
		} else {
			document.getElementById(sub_section).style.display = "none";		
			if (document.getElementById(closer)) {
				document.getElementById(closer).src = "filebin/images/form_heads/more_info_"+modolo+".gif";
			}
			if (document.getElementById(main_use)) {
				if (document.getElementById(main_use).className == "main_page_highlight_TOP_"+modolo) {
					document.getElementById(main_use).className = "main_page_TOP_"+modolo;
				} else if (document.getElementById(main_use).className == "main_page_highlight_SECOND_"+modolo) {
					document.getElementById(main_use).className = "main_page_SECOND_"+modolo;				
				}
			}
			//UPDATE DB
			var url = "filebin/ajax/php/update_form_display.php?id="+section_id+"&action=delete&type="+type;
			var xml = new JKL.ParseXML(url);
			var data = xml.parse();
		}
	}
}

//CUSTOM FUNC TO GET PRODUCTS IN SECTION FOR QUICK FORM
function show_products(id, type, modolo) {
	
	//FUNCTION TO PROVIDE FEEDBACK

	var product_fill = "products_fill_"+id;
	var closer = "main_closer_"+id;
	var plus = "plus_"+id;
	var main_use = "main_page_"+id;		
	var sub_level = "sub_level_form_"+id;	
	var product_action = "close";
	if (document.getElementById(product_fill).style.display == "none") {
		document.getElementById(product_fill).style.display = "block";		
		if (document.getElementById(product_fill)) {
			document.getElementById(product_fill).innerHTML = "<div class='loadingDiv'>loading products...</div>";
		}
		var product_action = "open";
	} else {
		if (document.getElementById(product_fill)) {
			document.getElementById(product_fill).style.display = "none";
		}
		//MAKE SECTION UNHIGHLIGHTED
		if (document.getElementById(closer)) {
			document.getElementById(closer).src = "filebin/images/form_heads/more_info_"+modolo+".gif";
		} else if (document.getElementById(plus)) {
			document.getElementById(plus).innerHTML = "&nbsp(+)";
			if (document.getElementById(sub_level)) {
				document.getElementById(sub_level).className = "sub_level_form_"+modolo;
			}			
		}		
		if (document.getElementById(main_use)) {
			if (document.getElementById(main_use).className == "main_page_highlight_TOP_"+modolo) {
				document.getElementById(main_use).className = "main_page_TOP_"+modolo;
			} else if (document.getElementById(main_use).className == "main_page_highlight_SECOND_"+modolo) {
				document.getElementById(main_use).className = "main_page_SECOND_"+modolo;				
			}
		}		
	}	setTimeout("show_products_action('"+id+"','"+type+"','"+modolo+"','"+product_action+"')",100);
}

function show_products_action(id, type, modolo, product_action) {

	try {

	var product_fill = "products_fill_"+id;
	var closer = "main_closer_"+id;
	var plus = "plus_"+id;
	var main_use = "main_page_"+id;		
	var sub_level = "sub_level_form_"+id;
	if (product_action == "open") {
		var url = "filebin/ajax/php/show_products.php?id="+id+"&type="+type;
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		if (data.result) {
			if (document.getElementById(product_fill)) {
				document.getElementById(product_fill).innerHTML = data.result;
			}
		}
		
		//MAKE SECTION HIGHLIGHTED
		if (document.getElementById(closer)) {
			document.getElementById(closer).src = "filebin/images/form_heads/close_"+modolo+".gif";
		} else if (document.getElementById(plus)) {
			document.getElementById(plus).innerHTML = "&nbsp(-)";
			if (document.getElementById(sub_level)) {
				document.getElementById(sub_level).className = "sub_level_form_highlight_"+modolo;
			}
		}
		if (document.getElementById(main_use)) {
			if (document.getElementById(main_use).className == "main_page_TOP_"+modolo) {
				document.getElementById(main_use).className = "main_page_highlight_TOP_"+modolo;
			} else if (document.getElementById(main_use).className == "main_page_SECOND_"+modolo) {
				document.getElementById(main_use).className = "main_page_highlight_SECOND_"+modolo;				
			}
		}			
		//UPDATE DB
		var url = "filebin/ajax/php/update_form_display.php?id="+id+"&action=add&type="+type;
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		
	} else {
		
		//UPDATE DB
		var url = "filebin/ajax/php/update_form_display.php?id="+id+"&action=delete&type="+type;
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		
	}
	
	} 
	
	catch(e) {
		//alert(e);
	}
	
}

//FUNCTION TO OPEN PREVIOUSLY OPENED SECTIONS
function open_form() {
	if (open_pages && type) {
		for(i=0; i<open_pages.length; i++) {			
			var product_fill = "products_fill_"+open_pages[i];
			var main_use = "main_page_"+open_pages[i];				
			
			//CHECK IF PAGE CONTAINS PRODUCTS
			if (document.getElementById(product_fill)) {

					var modoloClass = document.getElementById(product_fill).className;
					if (modoloClass == "products_fill_even") { 
						modolo = "even";
					} else {
						modolo = "odd";
					}
					show_products(open_pages[i],type, modolo);

			//IF NOT, CHECK IF PAGE CONTAINS SUBPAGES
			} else if (document.getElementById(main_use)) {
				var modoloClass = document.getElementById(main_use).className;
				if (modoloClass == "main_page_TOP_even") {
					modolo = "even";
				} else {
					modolo = "odd";
				}
				show_sub(open_pages[i],type, modolo);
			}
		}
	}
}

//FUNCTION TO CONFIRM CERTAIN PERCENTAGE OF POINTS ARE USED ON QUICK FORMS
function confirmPoints() {

	//alert('here');
	
	//GET TYPE
	if (document.getElementById('cart_type')) {
		var type = document.getElementById('cart_type').value;
	} else {
		var type = "spa";
	}
	if (type == "sales") {
		var label = "Support Dollars";
	} else {
		var label = "Partnership Points";		
	}

	//GET TOTAL IN CART AND AVAIL POINTS
	if ((document.getElementById('total_in_cart')) && (document.getElementById('avail_points'))) {
		if (type == "sales") {
			if ((document.getElementById('total_in_cart').value > 0) && (document.getElementById('avail_points').value >0)) {
				var total_in_cart = format_money(document.getElementById('total_in_cart').value);
				var avail_points = format_money(document.getElementById('avail_points').value);
			} else {
				var total_in_cart = 0;
				var avail_points = 0;
			}
		} else {
			if ((document.getElementById('total_in_cart').value > 0) && (document.getElementById('avail_points').value >0)) {
				var total_in_cart = parseFloat(document.getElementById('total_in_cart').value);
				var avail_points = parseFloat(document.getElementById('avail_points').value);		
			} else {
				var total_in_cart = 0;
				var avail_points = 0;			
			}
		}

		//alert(quantity+" * "+price+" = "+new_add_price);							
		//alert(total_in_cart+" <= "+avail_points);
		
		//FIRST ENSURE THEY DO NOT HAVE TOO MANY POINTS
		if (parseFloat(total_in_cart) <= parseFloat(avail_points) && (parseFloat(avail_points) > 0)) {

			//alert(parseFloat(total_in_cart)+" - "+avail_points);
		
			//COMPARE TOTAL IN CART WITH AVAIL POINTS - USE SET COEFFICIENT (80%)
			if (total_in_cart < (avail_points * .8)) { 
				var answer = confirm("You are only using "+total_in_cart+" of your "+avail_points+" available "+label+". Please note that the remainder will expire when you complete this order. Do you still want to proceed?");
				return answer;
			} else {
				return true;
			}
		} else {
			alert("You do not have enough "+label+" available to make this purchase. Please remove some items from your cart before proceeding.");
			return false;
		}
	}
}

//FUNCTION TO SWAP ALT PRODUCT IMAGES
function swapAltImage(id, full_path, cat_id, sku_id) {
	
	//UPDATE IMAGE
	document.getElementById("full_image").src = imagePaths[id];	

	//UPDATE DROPDOWN
	var target_id = "option_"+id+"_"+sku_id;
	if (document.getElementById(target_id)) {
		document.getElementById(target_id).selected = "true";
	}
	
	//UPDATE ID, SKU
	update_current_id(sku_id,id);	
}

//FUNCTION TO FORMAT NUMBERS
function format_money(input_num) {
	var d = 0;
	var c = 0;
	if (input_num.indexOf('.') > -1) {
		d = input_num.split('.')[0].toString();
		c = input_num.split('.')[1].toString();
	} else {
		d = input_num.toString();
		c = '0';
	}
	if (c.length == 1) {
		return d + '.' + c + '0';
	} else if (c.length == 2) {
		return d + '.' + c;
	} else if (c.length > 2) {
		return d + '.' + Math.round(parseFloat((c.substr(0,2) + '.' + c.substr(2))));
	} else {
		return d + '.' + '00';
	}
}

//FUNCTION TO ENSURE COOKIES ARE ENABLED
function checkIfCookie() {
   var tmpcookie = new Date();
   chkcookie = (tmpcookie.getTime() + '');
   document.cookie = "chkcookie=" + chkcookie + "; path=/";
   if (document.cookie.indexOf(chkcookie,0) < 0) {
       return false;
   }
   return true;
}