// JavaScript Document
var holder_json = {"holder":{}};
var page_loaded = false;
	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") {
			//alert(divtag);
			document.getElementById(divtag).innerHTML = "<div style='padding: 10px;'>Loading...</div>";
			http.open("get", "mini_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();
				}
            }
        }
    }
	//cart functions:
	function update_product(mc_cart_product_id) {
	
		if (document.getElementById("qty_"+mc_cart_product_id).value) {
	
			var qty = document.getElementById("qty_"+mc_cart_product_id).value;
	
			//FIRST, GET MAX QUANTITY
			var url = "filebin/ajax/php/get_max_quantity.php?product_id="+mc_cart_product_id;
			var xml = new JKL.ParseXML(url);
			var data = xml.parse();
			var proceed = true;
			if (data.result) {
				var max = data.result.max;
				var existing = data.result.existing;
				
				//SKIP IF NO MAX OR NO EXISTING
				if (max != 0 && existing) {
				
					//DON'T PROCEED IF QTY IS BIGGER THAN MAX
					if (parseInt(qty) > parseInt(max)) {								
						proceed = false;
					}
				}				
			}
			
			if (proceed) {
		
				var more = "action=update&";
				more += "mc_cart_product_id="+document.getElementById("prod_"+mc_cart_product_id).value;
				more += "&qty="+document.getElementById("qty_"+mc_cart_product_id).value;
				setTimeout("sendRequest('"+more+"', 'mini_cart')",50);
				//sendRequest(more,'mini_cart');
				//sendRequest('action=display','cart_total');
			
			} else {
			
				alert("You cannot add "+qty+" product(s) to your cart.\nThere is a limit of "+max+". Please see the product page for more information on ordering larger quantities of this item.");
				
				//RESET QTY 
				document.getElementById("qty_"+mc_cart_product_id).value = existing;
				
			}
		}
	}
	function remove_product(mc_cart_product_id) {
		var more = "action=remove&";
		more += "mc_cart_product_id="+document.getElementById("prod_"+mc_cart_product_id).value;
		setTimeout("sendRequest('"+more+"', 'mini_cart')",50);
		//sendRequest(more,'mini_cart');
	}
	function validateInteger( strValue ) {
	  var objRegExp  = /(^-?\d\d*$)/;
	  return objRegExp.test(strValue);
	}
	function qty_call(product_id, event) {
		price_options(product_id);	
	}
	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")) {
					var form_obj = document.getElementById("form_product");
					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_"+product_ids[z])) qty_product = parseInt(document.getElementById("qty_"+product_ids[z]).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;
				alert(prod_res.product_id);
				for (f=0;f<prod_res.length;f++) {
					alert(prod_res[f]["product_id"]);
					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")) {
			var form_obj = document.getElementById("form_product");
			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_"+product_id)) qty_product = parseInt(document.getElementById("qty_"+product_id).value);
			if (document.getElementById("qty_"+product_id)) 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 product_get = data.instance;
                                 if (product_get) {
                                         var temp = product_get;
                                         holder_json["holder"]["product_"+product_id] = temp;
                                 }
                                 if (holder_json["holder"]["product_"+product_id]) {
		
                                       /*
                                       //CHANGE ID
                                       if (document.getElementById('hidden_id')) {
                                               document.getElementById('hidden_id').value = holder_json["holder"]["product_"+id]["id"];
                                       }
                                       */
                                       
                                       if (document.getElementById("dynamic_price_"+product_id)) {
                                          if (holder_json["holder"]["product_"+product_id]["total_price"]!="") {
                                                document.getElementById("dynamic_price_"+product_id).innerHTML = "<span class='price'>Product Total: $"+holder_json["holder"]["product_"+product_id]["total_price"]+"</span>";
                                          }
                                      }
                                      
                                      if (document.getElementById('qty_discount')) {
                                             document.getElementById('qty_discount').innerHTML = holder_json["holder"]["product_"+product_id]["qty_discount"];
                                     }
                                       
                                 }
                
				//var price_option_total = data.total_price;
                               // var qty_discount_full = data.qty_discount;
                                /*
				if (document.getElementById("dynamic_price_"+product_id)) {
				       if (price_option_total!="") {
                                          document.getElementById("dynamic_price_"+product_id).innerHTML = "<span class='price'>Product Total: $"+price_option_total+"</span>";
                                       }
				}
                                */
                                /*
                                //CHANGE QTY DISCOUNT INFO
                                 if (document.getElementById('qty_discount')) {
                                         document.getElementById('qty_discount').innerHTML = qty_discount_full;
                                 }
                                */
			}
		}
	}
	function price_options_text(product_id) {
		if (document.getElementById("form_product")) {
			//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");
			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_"+product_id)) more += "&qty="+document.getElementById("qty_"+product_id).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'>Price (USD): $"+price_option_total+"</span>";
			}
		}
	}
	var gr = 0;
	function apply_price_options() {
		if (window.product_ids_arr) {
			price_options(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(product_id,obj,max) {
	
		try {
	
		if (page_loaded) {
		
			if (validateInteger(document.getElementById("qty_"+product_id).value) && document.getElementById("qty_"+product_id).value>0) {
			
				current_qty = document.getElementById("qty_"+product_id).value;
			
				//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+". Please see the product page for more information on ordering larger quantities of this item.");
						
					} else {
					
						//RUN QUERY TO CHECK CART
						var url = "filebin/ajax/php/check_max_quantity.php?product_id="+product_id;
						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. Please see the product page for more information on ordering larger quantities of this item.");
								
							} else {
							
								//COMBINATION IS BELOW MAX
								var proceed = true;
						
							}

						} else {
							
							//DB ERROR - COULDN"T ACCESS CART
							var proceed = true;
						}
					}
				}
			
				if (proceed) {
				
					//var product_id = document.getElementById("product_id").value;
					var form_obj = document.getElementById("form_product");
					var var_line = "";
					var more = "action=add_product&product_id="+product_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 the Purchaser's 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 the Recipient's 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 the Recipient's 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_"+product_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_"+product_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) {
							document.getElementById("current_add_id").value = product_id;
							//alert(reqz);
							display_adding_div(obj,product_id);
							adding_id = product_id;
							more += "&url="+location.href;
							sendRequest(more, 'mini_cart');
							more = "";
						}
						if (reqz == 0) {
							alert("Please, select size...");
							more = "";
						}
					}
					else if (gc == 1) {
						//gift certificate
						if (gc_err == "") {
							document.getElementById("current_add_id").value = product_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 = "";
						}
					
					}
		
				}
			}
			else {
				//document.getElementById("qty").style.color = 'red';
			}
		}
		else {
			//document.getElementById("qty_"+product_id).style.color = 'red';
		}
	}
	
	}
	
	catch(e) {
		alert(e);
	}
	
}

	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 (document.getElementById("mini_cart").style.display == "none") document.getElementById("mini_cart").style.display='block';
		else document.getElementById("mini_cart").style.display='none';
		//update_view();
	}
	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) {
		var qty = document.getElementById("qty_"+prod_id).value;
		http.open("get", "filebin/ajax/php/add_product_info.php?product_id="+prod_id+"&qty="+qty);
		http.onreadystatechange = handleResponse2;
		http.send(null);
	}
	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 (document.getElementById("current_add_id") && document.getElementById("current_add_id").value != "") {
					var pr_add_id = document.getElementById("current_add_id").value;
					document.getElementById("current_add_id").value = "";
					if (document.getElementById("adding_layer")) add_info(pr_add_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(e, product_id, mc_account_id) {
	
		try {

		if (product_id == "") product_id = product_list_id;
		product_list_id = "";
		var more = "product_id="+product_id+"&mc_account_id="+mc_account_id;
		if (mc_account_id != "") {
			//get qty if not set to 1;
			var qty = 1;
			if (document.getElementById("qty_"+product_id)) qty = parseInt(document.getElementById("qty_"+product_id).value);
			//validateInteger(document.getElementById("qty_"+product_id).value)
			if (qty>0) {
					//For var and objects
					var form_obj = document.getElementById("form_product");
					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;
					more += "&url="+location.href;
					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")) {
							display_registry_contents(e, product_id, mc_account_id);
							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.");	
		}
		}
		catch(e) {
			alert(e);
		}
	}

function show_registry(e) {
	
	if (page_loaded && document.getElementById("registry_list").style.display != "block") {

		
		//GET MC_ACCOUNT_ID
		if (document.getElementById("hidden_account")) {
			var mc_account_id = document.getElementById("hidden_account").value;
		}
		
		//IF USER IS LOGGED IN, ADD PRODUCT TO WISHLIST
		if (mc_account_id && mc_account_id != "") {
	
				//GET PRODUCT ID
				if (document.getElementById("hidden_id")) {
					var product_id = document.getElementById("hidden_id").value;
				} 

				if (product_id && product_id != "") {			
					add_wishlist(e, product_id, mc_account_id);
				} else {
					
					//SHOW ERROR IF USER HAS NOT SELECTED A WISHLIST
					alert("Please first specify which product you would like to add to your saved cart.");
				}
		
		//ELSE, DISPLAY LOGIN PROMPT
		} else {
			display_registry_contents(e, product_id, mc_account_id);
		}
	}
  }

function display_registry_contents(e, mc_account_id) {

	if (page_loaded && document.getElementById("registry_list").style.display != "block") {
    	centerDiv('registry_list', 100, 400); 
	}		
}
 
 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";	

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

	//SHOW TARGET DIV
	document.getElementById(targetDiv).style.display = "block";

	//SHOW OVERLAY
	showOverlay();
 }
 
  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";
	sendRequest(more,'event_detail');
}
function moveObject1(e) {

   	centerDiv('event_detail', 100, 360); 	
	event_d();
	
  }
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 += "&message="+encodeURI(obj.message.value);
	more += "&page_url="+location.href;
	sendRequest(more,'event_detail');
 }
function printpage() {
	window.print();  
}
function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" ) {
	window.addEventListener( "load", fnc, false );
  }
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}
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) {
			//alert(curleft+" + "+obj.offsetLeft);
			//special case ieght6
			if (obj.offsetLeft>=0)	curleft += obj.offsetLeft;
			else curleft += 200;
			//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
    	centerDiv('adding_layer', 100, 400); 
		
	}
	
}
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() {
	//alert(document.getElementById("coupon_holder_div").style.display);
	if (document.getElementById("coupon_holder_div2")) {
		document.getElementById("coupon_holder_div1").style.display = "block";
		document.getElementById("coupon_holder_div2").style.display = "block";
		//hide click here:
		document.getElementById("coupon_reveal_span").style.display = "none";
	}
}

//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);
	}
}
function image_swap(id) {
	var image_to_swap = "alt_image_replacement_"+id;
	if (document.getElementById('image_display') &&  document.getElementById(image_to_swap)) {
		document.getElementById('image_display').innerHTML = document.getElementById(image_to_swap).innerHTML;
	}
}
function image_swap_out() {
	if (document.getElementById('image_display') &&  document.getElementById('image_original')) {
		document.getElementById('image_display').innerHTML = document.getElementById('image_original').innerHTML;
	}
}

function cat_replace_drop() {
	if (document.getElementById('category_select')) {
		var id = document.getElementById('category_select').value;
		cat_replace(id);
	}
}
function change_wallaroo(cat_id,sel_name,sel_id) {
   var prod_id='';
   var add_price='0';
   if (document.getElementById('wallaroo_unit_color')) {
      if (sel_name == 'wallaroo_unit_color') var uc_id = sel_id;
      else var uc_id = document.getElementById('wallaroo_unit_color').value;
   } else {
      var uc_id = "";
   }
   if (document.getElementById('wallaroo_end_color')) {
      if (sel_name == 'wallaroo_end_color') var ec_id = sel_id;
      else var ec_id = document.getElementById('wallaroo_end_color').value;
   } else {
      var ec_id = "";
   }
   if (document.getElementById('wallaroo_trim_color')) {
      if (sel_name == 'wallaroo_trim_color') var tc_id = sel_id;
      else var tc_id = document.getElementById('wallaroo_trim_color').value;
   } else {
      var tc_id = "";
   }
   if (document.getElementById('wallaroo_closing_style')) {
      var cs_id = document.getElementById('wallaroo_closing_style').value;
   } else {
       var cs_id = "";
   }
   if (document.getElementById('wallaroo_keyless_lock')) {
      var kl_id = document.getElementById('wallaroo_keyless_lock').value;
   } else {
      var kl_id = "";
   }
   if (document.getElementById('wallaroo_electronic_lock')) {
      var el_id = document.getElementById('wallaroo_electronic_lock').value;
   } else {
      var el_id = "";
   }
   if (document.getElementById('wallaroo_handle_style')) {
      var hs_id = document.getElementById('wallaroo_handle_style').value;
   } else {
      var hs_id = "";
   }
   
   // End Cap Color
      // ec_id  color swatch id
      // vo_ec_id  vo option id for that color
   if (ec_id == '6') vo_ec_id = '15'; //Almond
   else if (ec_id == '2') vo_ec_id = '16'; //Gray
   else if (ec_id == '17') vo_ec_id = '17'; //Light Oak
   else if (ec_id == '18') vo_ec_id = '18'; //Medium Oak
   else if (ec_id == '19') vo_ec_id = '19'; //Cherry
   else if (ec_id == '20') vo_ec_id = '38'; //Light Cherry
   else vo_ec_id = "";
   
   
   // Trim Strip Color
   if (tc_id == '1') vo_tc_id = '20'; //Adobe
   else if (tc_id == '2') vo_tc_id = '15'; //Almond
   else if (tc_id == '3') vo_tc_id = '21'; //Black
   else if (tc_id == '4') vo_tc_id = '22'; //Burgundy
   else if (tc_id == '5') vo_tc_id = '23'; //Charcoal Gray
   else if (tc_id == '6') vo_tc_id = '16'; //Gray
   else if (tc_id == '7') vo_tc_id = '24'; //Harvest
   else if (tc_id == '8') vo_tc_id = '25'; //Light Blue
   else if (tc_id == '9') vo_tc_id = '26'; //Hunter Green
   else if (tc_id == '10') vo_tc_id = '27'; //Mauve
   else if (tc_id == '11') vo_tc_id = '28'; //Mulberry
   else if (tc_id == '12') vo_tc_id = '29'; //Navy Blue
   else if (tc_id == '13') vo_tc_id = '30'; //Olive
   else if (tc_id == '14') vo_tc_id = '31'; //Seaform Green
   else if (tc_id == '15') vo_tc_id = '32'; //Taupe
   else if (tc_id == '16') vo_tc_id = '33'; //Teal
   else if (tc_id == '17') vo_tc_id = '17'; //Light Oak
   else if (tc_id == '18') vo_tc_id = '18'; //Medium Oak
   else if (tc_id == '19') vo_tc_id = '19'; //Cherry
   else vo_tc_id = "";
   
   if (vo_ec_id != "" && vo_tc_id != "") var wall_vo = '5:'+vo_ec_id+',6:'+vo_tc_id;
   else var wall_vo = "";
   
   
   if (cat_id == '172') { // WALLaroo 2000 XW
      if (uc_id=='6' && cs_id=='Automatic' && kl_id=='Yes') prod_id = '1635';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1638';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1639';
      else if (uc_id=='2' && cs_id=='Automatic' && kl_id=='No') prod_id = '1628';
      else if (uc_id=='6' && cs_id=='Automatic' && kl_id=='No') prod_id = '1632';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1636';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1637';
      else prod_id = '1634';
      if (sel_id=='17' || vo_ec_id=='18' || sel_id=='19' || sel_id=='20') {
         add_price='75.00';
      }
   } else if (cat_id == '173') { // WALLaroo 2000 XXT
      if (uc_id=='6' && cs_id=='Automatic' && kl_id=='Yes') prod_id = '1675';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1678';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1679';
      else if (uc_id=='2' && cs_id=='Automatic' && kl_id=='No') prod_id = '1672';
      else if (uc_id=='6' && cs_id=='Automatic' && kl_id=='No') prod_id = '1673';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1676';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1677';
      else prod_id = '1674';
   } else if (cat_id == '216') { // WALLaroo 2000 XXTD
      if (uc_id=='6' && cs_id=='Automatic') prod_id = '2928';
      else if (uc_id=='2' && cs_id=='Hand Assisted') prod_id = '2925';
      else if (uc_id=='6' && cs_id=='Hand Assisted') prod_id = '2927';
      else prod_id = '2926';
   } else if (cat_id == '174') { // WALLaroo 2000 XT
      if (uc_id=='6' && cs_id=='Automatic' && el_id=='No') prod_id = '1643'; // Gray / Auto / No
      else if (uc_id=='2' && cs_id=='Hand Assisted' && el_id=='No') prod_id = '1644'; // Almond / Manual / No
      else if (uc_id=='6' && cs_id=='Hand Assisted' && el_id=='No') prod_id = '1645'; // Gray / Manual / No
      else if (uc_id=='6' && cs_id=='Automatic' && el_id=='Yes') prod_id = '2909'; // Gray / Auto / Yes
      else if (uc_id=='2' && cs_id=='Hand Assisted' && el_id=='Yes') prod_id = '2907'; // Almond / Manual / Yes
      else if (uc_id=='6' && cs_id=='Hand Assisted' && el_id=='Yes') prod_id = '2908'; // Gray / Manual / Yes
      else if (uc_id=='2' && cs_id=='Automatic' && el_id=='Yes') prod_id = '2906'; // Almond / Auto / Yes 
      else prod_id = '1640'; // Almond / Auto / No
   } else if (cat_id == '175') { // WALLaroo 2000
      if (uc_id=='6' && cs_id=='Automatic' && kl_id=='Yes') prod_id = '1658';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1653';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1654';
      else if (uc_id=='2' && cs_id=='Automatic' && kl_id=='No') prod_id = '1655';
      else if (uc_id=='6' && cs_id=='Automatic' && kl_id=='No') prod_id = '1656';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1646';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1651';
      else prod_id = '1657';
      if (sel_id=='17' || vo_ec_id=='18' || sel_id=='19' || sel_id=='20') {
         add_price='75.00';
      }
   } else if (cat_id == '176') { // WALLaroo 2000 XD
      if (uc_id=='6' && cs_id=='Automatic' && kl_id=='Yes') prod_id = '1683';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1685';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1687';
      else if (uc_id=='2' && cs_id=='Automatic' && kl_id=='No') prod_id = '1680';
      else if (uc_id=='6' && cs_id=='Automatic' && kl_id=='No') prod_id = '1682';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1684';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1686';
      else prod_id = '1681';
   } else if (cat_id == '177') { // HALF-A-ROO 2000
      if (uc_id=='6' && cs_id=='Automatic' && kl_id=='Yes') prod_id = '1671';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1668';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='Yes') prod_id = '1669';
      else if (uc_id=='2' && cs_id=='Automatic' && kl_id=='No') prod_id = '1666';
      else if (uc_id=='6' && cs_id=='Automatic' && kl_id=='No') prod_id = '1667';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1662';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && kl_id=='No') prod_id = '1664';
      else prod_id = '1670';
      if (sel_id=='17' || vo_ec_id=='18' || sel_id=='19' || sel_id=='20') {
         add_price='75.00';
      }
   } else if (cat_id == '178') { // Original WALLaroo
      if (uc_id=='6' && cs_id=='Automatic' && hs_id=='Recessed') prod_id = '1463';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && hs_id=='Recessed') prod_id = '1464';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && hs_id=='Recessed') prod_id = '1465';
      else if (uc_id=='2' && cs_id=='Automatic' && hs_id=='Extruded') prod_id = '1460';
      else if (uc_id=='6' && cs_id=='Automatic' && hs_id=='Extruded') prod_id = '1461';
      else if (uc_id=='2' && cs_id=='Hand Assisted' && hs_id=='Extruded') prod_id = '1453';
      else if (uc_id=='6' && cs_id=='Hand Assisted' && hs_id=='Extruded') prod_id = '1455';
      else prod_id = '1462';
   } else if (cat_id == '179') { // Original HALF-A-ROO
      if (uc_id=='6' && cs_id=='Automatic') prod_id = '1471';
      else if (uc_id=='2' && cs_id=='Hand Assisted') prod_id = '1466';
      else if (uc_id=='6' && cs_id=='Hand Assisted') prod_id = '1468';
      else prod_id = '1470';
   } else if (cat_id == '182') { // ECONOROO
      if (uc_id=='6') prod_id = '1661';
      else prod_id = '1660';
   }
   else if (cat_id == '185') { // WALLaroo Jr.
      if (uc_id=='6') prod_id = '1459';
      else prod_id = '1457';
   }
   
   cat_wallaroo_replace(prod_id,cat_id,uc_id,ec_id,tc_id,cs_id,kl_id,el_id,hs_id,wall_vo,add_price);
}

function cat_wallaroo_replace(id,cat_id,uc_id,ec_id,tc_id,cs_id,kl_id,el_id,hs_id,wall_vo,add_price) {
	//CHECK FOR CATEGORY
	//alert('category: '+all_products.category.id);

	//alert(id);

	//if (!holder_json["holder"]["product_"+id]) {

		//PRODUCT INFO NOT IN ARRAY, GET IT
		var url = "filebin/ajax/php/getWallarooData.php?id="+id+"&uc_id="+uc_id+"&ec_id="+ec_id+"&tc_id="+tc_id+"&cs_id="+cs_id+"&kl_id="+kl_id+"&el_id="+el_id+"&wall_vo="+wall_vo+"&hs_id="+hs_id+"&cat_id="+cat_id+"&add_price="+add_price;
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		var product_get = data.instance;
		if (product_get) {
			var temp = product_get;
			holder_json["holder"]["product_"+id] = temp;
		}
	//}

	//alert(holder_json["holder"]["product_"+id]["id"]);


	// GET PRODUCT DATA
	if (holder_json["holder"]["product_"+id]) {
		
		//CHANGE ID
		if (document.getElementById('hidden_id')) {
			document.getElementById('hidden_id').value = holder_json["holder"]["product_"+id]["id"];
		}
                
                //CHANGE PURCHASING INFO
		if (document.getElementById('product_purchasing')) {
			document.getElementById('product_purchasing').innerHTML = holder_json["holder"]["product_"+id]["purchasing"];
		}
                
                //CHANGE ORIGINAL IMAGE
		if (document.getElementById('image_original')) {
			document.getElementById('image_original').innerHTML = holder_json["holder"]["product_"+id]["image"];
		}

		//CHANGE DISPLAY IMAGE
		if (document.getElementById('image_display')) {
			document.getElementById('image_display').innerHTML = holder_json["holder"]["product_"+id]["image"];
		}
                
                //CHANGE HTML DATA
		if (document.getElementById('product_html')) {
			document.getElementById('product_html').innerHTML = holder_json["holder"]["product_"+id]["product_data"];
		}		
   
                //CHANGE QTY DISCOUNT INFO
		if (document.getElementById('qty_discount')) {
			document.getElementById('qty_discount').innerHTML = holder_json["holder"]["product_"+id]["qty_discount"];
		}
                //CHANGE DETAILS INFO
		if (document.getElementById('details_data')) {
			document.getElementById('details_data').innerHTML = holder_json["holder"]["product_"+id]["details"];
		}
                
                //CHANGE CAPACITY INFO
		if (document.getElementById('capacity_data')) {
			document.getElementById('capacity_data').innerHTML = holder_json["holder"]["product_"+id]["capacity"];
		}
                
                //CHANGE DIMENSIONS INFO
		if (document.getElementById('dimensions_data')) {
			document.getElementById('dimensions_data').innerHTML = holder_json["holder"]["product_"+id]["dimensions"];
		}

		//CHANGE COMPANION IMAGES
		if (document.getElementById('product_companions')) {
			document.getElementById('product_companions').innerHTML = holder_json["holder"]["product_"+id]["companion"];
		}
		
		//SET DROPDOWN TO MATCH SELECTED PICK
		if (document.getElementById('category_select')) {
			document.getElementById('category_select').value = id;
		}	
	}
}

function cat_replace(id) {
                                        
	//CHECK FOR CATEGORY
	//alert('category: '+all_products.category.id);
        
        
         var form_obj = document.getElementById("form_product");
         var var_line = "";
         if (form_obj) { 
                  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);
                  }
         }
        
	if (!holder_json["holder"]["product_"+id]) {
		//PRODUCT INFO NOT IN ARRAY, GET IT
		var url = "filebin/ajax/php/getProductData.php?id="+id+"&product_vo="+var_line;
		var xml = new JKL.ParseXML(url);
		var data = xml.parse();
		var product_get = data.instance;
		if (product_get) {
			var temp = product_get;
			holder_json["holder"]["product_"+id] = temp;
		}
	}

	//alert(holder_json["holder"]["product_"+id]["id"]);


	// GET PRODUCT DATA
	if (holder_json["holder"]["product_"+id]) {	
		
		//CHANGE NAME
		if (document.getElementById('product_name')) {
			document.getElementById('product_name').innerHTML = "<h1>"+holder_json["holder"]["product_"+id]["name"]+"</h1>";
		}
		
		//CHANGE ORIGINAL IMAGE
		if (document.getElementById('image_original')) {
			document.getElementById('image_original').innerHTML = holder_json["holder"]["product_"+id]["image"];
		}

		//CHANGE DISPLAY IMAGE
		if (document.getElementById('image_display')) {
			document.getElementById('image_display').innerHTML = holder_json["holder"]["product_"+id]["image"];
		}
		
		//CHANGE DISPLAY IMAGE
		if (document.getElementById('product_alt_images')) {
			document.getElementById('product_alt_images').innerHTML = holder_json["holder"]["product_"+id]["alts"];
		}		
		
		//CHANGE HTML DATA
		if (document.getElementById('product_html')) {
			document.getElementById('product_html').innerHTML = holder_json["holder"]["product_"+id]["product_data"];
		}		
		
		//CHANGE PRODUCT DESCRIPTION
		//if (document.getElementById('product_description') && holder_json["holder"]["product_"+id]["product_description"]) {
		//	document.getElementById('product_description').innerHTML = holder_json["holder"]["product_"+id]["product_description"];
		//}	
		
		//CHANGE PURCHASING INFO
		if (document.getElementById('product_purchasing')) {
			document.getElementById('product_purchasing').innerHTML = holder_json["holder"]["product_"+id]["purchasing"];
		}
                //CHANGE QTY DISCOUNT INFO
		if (document.getElementById('qty_discount')) {
			document.getElementById('qty_discount').innerHTML = holder_json["holder"]["product_"+id]["qty_discount"];
		}
                //CHANGE DETAILS INFO
		if (document.getElementById('details_data')) {
			document.getElementById('details_data').innerHTML = holder_json["holder"]["product_"+id]["details"];
		}
                
                //CHANGE CAPACITY INFO
		if (document.getElementById('capacity_data')) {
			document.getElementById('capacity_data').innerHTML = holder_json["holder"]["product_"+id]["capacity"];
		}
                
                //CHANGE DIMENSIONS INFO
		if (document.getElementById('dimensions_data')) {
			document.getElementById('dimensions_data').innerHTML = holder_json["holder"]["product_"+id]["dimensions"];
		}

		//CHANGE COMPANION IMAGES
		if (document.getElementById('product_companions')) {
			document.getElementById('product_companions').innerHTML = holder_json["holder"]["product_"+id]["companion"];
		}
		
		//SET DROPDOWN TO MATCH SELECTED PICK
		if (document.getElementById('category_select')) {
			document.getElementById('category_select').value = id;
		}	
	}
}

function page_onload() {
	page_loaded = true;	
}
addOnloadEvent(page_onload);
