function set_delivery_method_options(current_obj)
{
	var question_prefix_array = ['question_3', 'question_4', 'question_5'];
	
	var current_prefix = current_obj.id;
	for(i=0; i<question_prefix_array.length; i++)
	{
		current_prefix = current_prefix.replace(question_prefix_array[i], '');
	}
	
	if(current_obj.type.toLowerCase() == 'radio' || current_obj.type.toLowerCase() == 'checkbox')
	{
		for(i=0; i<question_prefix_array.length; i++)
		{	
			if($(question_prefix_array[i]+current_prefix)!=null)
				$(question_prefix_array[i]+current_prefix).checked = current_obj.checked;
		}
	}
	else
	{
		for(i=0; i<question_prefix_array.length; i++)
		{
			if($(question_prefix_array[i]+current_prefix)!=null)
			{
				var current_value = current_obj.value;
				
				if(parseInt($(question_prefix_array[i]+current_prefix).alt) < parseInt(current_obj.value))
				{
					current_value = $(question_prefix_array[i]+current_prefix).alt;
				}
				
				$(question_prefix_array[i]+current_prefix).value = current_value;
			}
		}
	}
}

function show_boltdown_method_options(current_obj)
{
	var question_prefix_array = ['boltdown_3', 'boltdown_4', 'boltdown_5'];
	
	var current_prefix = current_obj.id;
	for(i=0; i<question_prefix_array.length; i++)
	{
		current_prefix = current_prefix.replace(question_prefix_array[i], '');
	}
	
	if(current_obj.type.toLowerCase() == 'radio' || current_obj.type.toLowerCase() == 'checkbox')
	{
		for(i=0; i<question_prefix_array.length; i++)
		{	
			if($(question_prefix_array[i]+current_prefix)!=null)
				$(question_prefix_array[i]+current_prefix).checked = current_obj.checked;
		}
	}
	else
	{
		for(i=0; i<question_prefix_array.length; i++)
		{
			alert(question_prefix_array[i]+current_prefix);
			
			if($(question_prefix_array[i]+current_prefix)!=null)
				$(question_prefix_array[i]+current_prefix).value = current_obj.value;
		}
	}
	
	display_option = 'none';
	if(current_obj.checked)
		display_option = 'block';
	
	for(i=0; i<question_prefix_array.length; i++)
	{
		if($(question_prefix_array[i]+current_prefix+'_price')!=null)
		{
			$(question_prefix_array[i]+current_prefix+'_price').style.display = display_option;
		}
	}
	
}


function load_template_zip_box()
{
	var smartBoxZip = new SmartHoverBox({ 	
											boxTimer        : 2000, // how many milliseconds before the box hides after mouseleave
											yOffset         : 0, // up and down offset in px - accepts negative ints		
											xOffset         : 0, // left and right offset in px - accepts negative ints
											smartBoxSuffix  : '_zipsmarthbox', //suffix that creates a hover box
											lockY   		: 'bottom', // 'top', 'bottom'
											lockX    		: 'right' // 'left', 'right'
										  });

	return smartBoxZip;

}

function load_template_learnmore() {
	
	var topbarlearnmore = new SmartHoverBox({ 	
												boxTimer        : 20, // how many milliseconds before the box hides after mouseleave
												yOffset         : 0, // up and down offset in px - accepts negative ints		
												xOffset         : 0, // left and right offset in px - accepts negative ints
												smartBoxSuffix  : '_learnsmarthbox', //suffix that creates a hover box
												lockY   		: 'bottom', // 'top', 'bottom'
												lockX    		: 'left', // 'left', 'right'
												fadeIn			: true,
												fadeOut			: true
											  });
}


function set_delivery_multibox(class_name)
{
	var deliveryMultiBox = new multiBox({
											mbClass: '.'+class_name,
											container: $(document.body),
											showControls: false,
											useOverlay: true
										});

}


function get_required_fields_array()
{

	var registrationRequired = [		"ship_name_first","First Name (Shipping Address)","",
										"ship_name_last","Last Name (Shipping Address)","",
										"ship_address_street","Address (Shipping Address)","",
										"ship_address_city","City (Shipping Address)",""];
	
	if($('ship_address_country_id').value == 223) //USA									
		registrationRequired = registrationRequired.concat(["ship_address_state_vl","State (Shipping Address)",""]);
	else
		registrationRequired = registrationRequired.concat(["ship_address_state_txt","State (Shipping Address)",""]);
	
	registrationRequired = registrationRequired.concat([	"ship_address_zip","Zip (Shipping Address)","",
															"phone_main","Phone","phone"]);
	
	
	registrationRequired = registrationRequired.concat([	"email","Email","email",
															"email_verify","Verify Email","email"]);
	
	
	if(!$('sameaddress_flag').checked)
	{
		registrationRequired = registrationRequired.concat([	"name_first","First Name (Billing Address)","",
																"name_last","Last Name (Billing Address)","",
																"address_street","Address (Billing Address)","",
																"address_city","City (Billing Address)",""]);
		
		if($('address_country_id').value == 223) //USA									
			registrationRequired = registrationRequired.concat(["address_state_vl","State (Billing Address)",""]);
		else
			registrationRequired = registrationRequired.concat(["address_state_txt","State (Billing Address)",""]);
		
		registrationRequired = registrationRequired.concat(["address_zip","Zip (Billing Address)",""]);	
	}
	
	
	if($('payment_type_id_0') == null || $('payment_type_id_0').checked)
	{
		registrationRequired = registrationRequired.concat([	"c_holder","Name on Credit Card","",
																"c_number","Credit Card",""]);
	}
	
	return registrationRequired;
	
}

function set_state_field()
{
	
	if($('ship_address_country_id').value == 223) //USA
	{
		document.getElementById('ship_address_state_txt').style.display='none';
		document.getElementById('ship_address_state_txt').disabled='disabled';
		document.getElementById('ship_address_state_vl').style.display='block';
		document.getElementById('ship_address_state_vl').disabled='';
	}
	else
	{
		document.getElementById('ship_address_state_vl').style.display='none';
		document.getElementById('ship_address_state_vl').disabled='disabled';
		document.getElementById('ship_address_state_txt').style.display='block';
		document.getElementById('ship_address_state_txt').disabled='';
	}
	
	
	if($('sameaddress_flag') == null || !$('sameaddress_flag').checked)
	{
		if($('address_country_id').value == 223) //USA
		{
			document.getElementById('address_state_txt').style.display='none';
			document.getElementById('address_state_txt').disabled='disabled';
			document.getElementById('address_state_vl').style.display='block';
			document.getElementById('address_state_vl').disabled='';
		}
		else
		{
			document.getElementById('address_state_vl').style.display='none';
			document.getElementById('address_state_vl').disabled='disabled';
			document.getElementById('address_state_txt').style.display='block';
			document.getElementById('address_state_txt').disabled='';
		}
	}
	
}
	
function verify_matching_fields()
{
	var errors = '';
	var backgroundColorFail = "#FFCC66";
	var backgroundColorVaild = "#FFFFFF";
	
	if(document.getElementById('email').value != document.getElementById('email_verify').value)
	{
		errors += "- The email you entered does not match the email verify.\n";
		
		document.getElementById('email').style.background = backgroundColorFail;
		document.getElementById('email_verify').style.background = backgroundColorFail;
	}
	else
	{
		document.getElementById('email').style.background = backgroundColorVaild;
		document.getElementById('email_verify').style.background = backgroundColorVaild;
	}
	
	if(errors)
	{
		alert("The following errors occured:\n"+errors);
		return false;
	}
	
	return true;
}

function close_all_delivery(current_open_id, class_name)
{
	var deliveryoptions = $$('.'+class_name);
	deliveryoptions.each(
		function(el) {
			if(el.id != current_open_id)
				slide_out_section(el.id);
		}
	);
	
	if(current_open_id != '')
		slide_in_section(current_open_id);

}

function submit_delivery_method()
{
	
	var delivery = $('delivery_method');
	
	var req = new Request({
            url: 'build_delivery_inc.php',
            onRequest: function(){
            	delivery.empty().addClass('ajax-loading');
            },
            onComplete: function(response) {
                delivery.removeClass('ajax-loading');
				delivery.set('html', response);
            }
        }).post($('delivery_form'));
}

function submit_delivery_method_gm()
{
	
	var delivery = $('delivery_method');
	
	var req = new Request({
			url: 'build_delivery_inc_gm.php',
			onRequest: function(){
				delivery.empty().addClass('ajax-loading');
			},
			onComplete: function(response) {
				$('initial_load').value = 0; //this is so we know the page has loaded once already
				delivery.removeClass('ajax-loading');
				delivery.set('html', response);
			}
		}).post($('delivery_form'));
}

function slide_in_section(section_id)
{
	if($(section_id).style.display=='none')
	{
		hideSection(section_id);
		$(section_id).style.display='block';
	}
	var myVerticalSlide = new Fx.Slide(section_id);
	myVerticalSlide.slideIn();
}

function slide_out_section(section_id)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	myVerticalSlide.slideOut();
}

function load_new_colors_html(obj, pg_id)
{
	
	var url_path = 'safe_page_colors.php?pg_id='+pg_id+'&safe_view='+($('safe_view').value)+'&color_view='+($('color_view').value)+'&page_view='+($('page_view').value);
	
	$('safe_display_left').set('html', '<div align="center" style="padding-top:50px;padding-bottom:50px;"><img src="includes/styles/mb_Components/loader.gif" alt="colors" width="31" height="31" align="middle" /></div>');
	
	var modelsizebutton = $$(".buttonBselected");
	modelsizebutton.each(
		function(el) {
			el.className = 'buttonB';
		}
	);
	
	obj.className = "buttonBselected";
	
	var reqcolors = new Request.HTML({
		url:url_path, 
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('safeColorsArea').set('text', '');
			//Inject the new DOM elements into the results div.
			method:'get',
			$('safeColorsArea').adopt(html);
			colors_load();
			set_delivery_multibox('deliveryMultiBox-mb');
			run_colors_box('safeimage-mb');
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('safeColorsArea').set('text', 'An error occured. The colors were unable to load.');
		}
	});

	reqcolors.send();

}

function colors_load()
{
	var smartBox = new SmartHoverBox({ 
		boxTimer        : 20, // how many milliseconds before the box hides after mouseleave
		yOffset         : -100, // up and down offset in px - accepts negative ints		
		xOffset         : 0, // left and right offset in px - accepts negative ints
		smartBoxSuffix  : '_colorssmarthbox', //suffix that creates a hover box
		smartBoxClose  	: 'colorssmarthbox_close', //this class will add "close" click event to element
		trigger			: 'click',
		lockY   		: 'none', // 'top', 'bottom'
		lockX    		: 'none' // 'left', 'right'
	  });
}


/**
* create a tab structure -
*/
function setTabs() {
  var tabs = $$("*[tab]");    // get all the tab links
  var selected_tab = null;    // the currently selected tab

  var selected_tabs = new Hash();

  // go through all the found tabs
  if(tabs.length > 0) {
    tabs.each(
      function(el) {
        if(!el.getProperty("default_tab")) {
          $(el.getProperty("tab")).setStyle("display","none");    // if not hide the contents (though they should be hidden using css already)
        } else {
          selected_tabs.set(el.get("tab_group"),el);
          $(el.getProperty("tab")).setStyle("display","block");
          el.addClass("tab_selected");
        }

        el.set(
          {
            "events" : {
              "mouseover" : function() {   // on mouseover set the pointer and give it some style
                      this.setStyle("cursor","pointer");
                      if(selected_tabs.get(this.getProperty("tab_group")) != this)
                      {
                      	this.addClass("tab_hover");
                      }
                    },
              "mouseout" : function() {    // on mouseout set the cursor to normal and return the style (if it is not selected)
                      this.setStyle("cursor","auto");
                      if(selected_tabs.get(this.getProperty("tab_group")) != this) this.removeClass("tab_hover");

                    },
              "click" : function() {     // on click hide the current, show the chosen and add some style
                      if(selected_tabs.get(this.getProperty("tab_group")) != this) {
                        $(this.getProperty("tab")).setStyle("display","block");
                        if(selected_tabs.get(this.getProperty("tab_group"))) {
                          $(selected_tabs.get(this.getProperty("tab_group")).getProperty("tab")).setStyle("display","none");
                          selected_tabs.get(this.getProperty("tab_group")).removeClass("tab_selected");
                          selected_tabs.get(this.getProperty("tab_group")).removeClass("tab_hover");
                        }
                        selected_tabs.set(this.getProperty("tab_group"),this);
                      }
                      
                      this.addClass("tab_selected");
                      
                    }
            }
          }
        );
      }
    );
    
    
    //This is if you want to control the tabs from another element beside the tab itself (tab_manually="tab_id_name_here")
    var tabs_manually = $$("*[tabs_manually]");    // get all the manual tab links
  
	  // go through all the found tabs
	  if(tabs_manually.length > 0) {
		tabs_manually.each(
		  function(el) {
	
			el.set(
			  {
				"events" : {
				  
				  "click" : function() {     // on click hide the current, show the chosen and add some style
						  
							var to_obj = $(el.getProperty("tabs_manually"));
	
							// on click hide the current, show the chosen and add some style
							if(selected_tabs.get(to_obj.getProperty("tab_group")) != this) {
							$(to_obj.getProperty("tab")).setStyle("display","block");
							if(selected_tabs.get(to_obj.getProperty("tab_group"))) {
							$(selected_tabs.get(to_obj.getProperty("tab_group")).getProperty("tab")).setStyle("display","none");
							selected_tabs.get(to_obj.getProperty("tab_group")).removeClass("tab_selected");
							selected_tabs.get(to_obj.getProperty("tab_group")).removeClass("tab_hover");
							}
							selected_tabs.set(to_obj.getProperty("tab_group"),to_obj);
							}
							
							to_obj.addClass("tab_selected");		  
						  
					}
				}
			  }
			);
		  }
		);
	  
		
	  }
      
  }
  
}


function get_large_swatch_image(obj, image_base_text)
{
	
	var img_obj = $(obj.id+'_img');
	
	if(img_obj.src.search(image_base_text) != -1)
	{
		//the image has already been loaded.
	}
	else
	{
		var newsrc = 'images/swatches/swatch_lg_'+image_base_text+'.jpg';
		images = [newsrc];
		
		var myImages = new Asset.images(images, {
		onComplete: function(){
				images.each(function(im) {
					img_obj.src = im;
					img_obj.width = 300;
					img_obj.height = 225;
				});
			}
		});
	}
	/*
	return;
	
	
	
	var img_obj = $('swatch_display');
	
	if(img_obj.src.search(image_base_text) != -1)
	{
		//the image has already been loaded.
	}
	else
	{
		var newsrc = 'images/swatches/swatch_lg_'+image_base_text+'.jpg';
		images = [newsrc];
		
		//img_obj.fade(0);
		
		var displayimage = new Fx.Morph(img_obj);
				
		displayimage.start({
			opacity: 0
		});
		
		
		displayimage.addEvent('complete', function() {
			
			img_obj.style.display = '';
		
			var myImages = new Asset.images(images, {
			onComplete: function(){
					images.each(function(im) {
						img_obj.src = im;
						img_obj.fade(1);
					});
				}
			});
		
		});
		
		
	}
	
	*/
}

function numbersOnly(obj)
{
	var filter  = /[^\d]+/g;
	var str = obj.value;
	str = str.replace(filter, '');
	obj.value = str;
}

function change_cart_qty(qtynum, qtyclass)
{
	var original_qty = 1;
	var quantityfields = $$("."+qtyclass);

	if(quantityfields.length > 0)
	{
		if(confirm('Would you like to update the quantity for the accessories added to this safe?'))
		{	
			quantityfields.each(
				function(el) {
					//original_qty = $('original'+el.id).value;
					//el.value = original_qty * qtynum;
					el.value = qtynum;
				}
			);
		}
	}	
}

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function controlSectionArea(section_id, control_status)
{
	var status = $(section_id).title;
	if(status == 'default')
	{
		if(control_status == 'closed')
		{
			$(section_id).title = 'closed';
			toggleSectionSimple(section_id);
		}
		else
		{
			$(section_id).title = 'open';
		}
	}
	else if(status == 'closed' && control_status == 'open')
	{
		$(section_id).title = 'open';
		toggleSectionSimple(section_id);
	}
	else if(status == 'open' && control_status == 'closed')
	{
		$(section_id).title = 'closed';
		toggleSectionSimple(section_id);
	}
	
}

function toggleSectionSimple(section_id)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	myVerticalSlide.toggle();
}

function showSection(section_id)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	myVerticalSlide.show();
}

function isValidEmail(value)
{
	var x = value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function isValidPhoneNumber(s)
{
	// Check for correct phone number
	rePhoneNumber = new RegExp(/\d{3}\-\d{3}\-\d{4}/);
	
	if (!rePhoneNumber.test(s))
		return false;
	
	return true;
}

function isValidSerialNumber(s)
{
	serial_number = s.toUpperCase();
	
	var filter1  = /^(L\d{6})+$/;
	var filter2  = /^(L\d{9})+$/;
	var filter3  = /^(LIT\d{8})+$/;
	var filter4  = /^(F\d{6})+$/;
	
	if(filter1.test(serial_number) || filter2.test(serial_number) || filter3.test(serial_number) || filter4.test(serial_number))
		return true;
	else
		return false;
}

function formValidate(formobj){
	// Enter name of mandatory fields
	//var fieldRequired = Array("FirstName","First Name","email","LastName","Last Name","ssn");
	//You can have as many required arrays as desired i.e. formValidate(formobj, Array1, Array2,...)
	
	var backgroundColorFail = "#FF9999";
	var backgroundColorVaild = "#FFFFFF";
	
	// dialog message
	var alertMsg = "Please complete the following:\n";
	
	var l_Msg = alertMsg.length;
	
	args=formValidate.arguments;
	
	for (var k = 1; k < args.length; k++)
	{	
		var fieldRequired = args[k];
		for (var i = 0; i < fieldRequired.length; i++)
		{
			var obj = formobj.elements[fieldRequired[i]];
			if (obj){
				switch(obj.type){
				case "select-one":
					if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
						alertMsg += " - " + fieldRequired[i+1] + "\n";
						obj.style.background = backgroundColorFail;
					}
					else
						obj.style.background = backgroundColorVaild;
					break;
				case "select-multiple":
					if (obj.selectedIndex == -1){
						alertMsg += " - " + fieldRequired[i+1] + "\n";
						obj.style.background = backgroundColorFail;
					}
					else
						obj.style.background = backgroundColorVaild;
					break;
				case "text":
				case "textarea":
				case "password":
				case "hidden":
					if (obj.value == "" || obj.value == null)
					{
						alertMsg += " - " + fieldRequired[i+1] + "\n";
						obj.style.background = backgroundColorFail;
					}
					else if(fieldRequired[i+2] == 'email')
					{
						if(!isValidEmail(obj.value))
						{
							alertMsg += " - " + fieldRequired[i+1] + " must be an email address\n";
							obj.style.background = backgroundColorFail;	
						}
						else
							obj.style.background = backgroundColorVaild;
					}
					else if(fieldRequired[i+2] == 'phone')
					{
						if(!isValidPhoneNumber(obj.value))
						{
							alertMsg += " - " + fieldRequired[i+1] + " must be entered as: xxx-xxx-xxxx\n";
							obj.style.background = backgroundColorFail;	
						}
						else
							obj.style.background = backgroundColorVaild;
					}
					else if(fieldRequired[i+2] == 'date')
					{
						if(!validateDate(obj.value,'U','A'))
						{
							alertMsg += " - " + fieldRequired[i+1] + " must be a date formatted mm-dd-yyyy\n";
							obj.style.background = backgroundColorFail;	
						}
						else
							obj.style.background = backgroundColorVaild;
					}
					else if(fieldRequired[i+2] == 'serial')
					{
						if(!isValidSerialNumber(obj.value))
						{
							alertMsg += " - " + fieldRequired[i+1] + " is an invalid Serial Number\n";
							obj.style.background = backgroundColorFail;	
						}
						else
							obj.style.background = backgroundColorVaild;
					}
					else
						obj.style.background = backgroundColorVaild;
					break;
				default:
				}
				if (obj.type == undefined){
					var blnchecked = false;
					for (var j = 0; j < obj.length; j++){
						if (obj[j].checked){
							blnchecked = true;
						}
					}
					if (!blnchecked)
					{
						alertMsg += " - " + fieldRequired[i+1] + "\n";
					}
				}
			}
			
			i=i+2;
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		if(alertMsg.length > 100)
			alertMsg = '(Press "ENTER" on your keybord to continue.)\n'+alertMsg;
		alert(alertMsg);
		return false;
	}
}

function verifyPassword(form_element)
{
	var errors = '';
	
	if(form_element.password.value.length < 4)
  		errors += '- Your password needs to be at least four characters.\n';
  
 	if(form_element.password.value != form_element.password_confirm.value)
  		errors += '- Your password does not match the password confirm.\n';
	
	if(form_element.terms.value != null && !form_element.terms.checked)
  		errors += '- You must agree to the terms of use.\n';
	
	if(errors)
	{
		alert('The following error(s) occurred:\n'+errors);
		return false;
	}
	else
		return true;
	
}

function safe_swap_image(imgsrc, prod_id, hardware_lock_id, color_exterior_id, color_interior_id, show_interior)
{
	if(show_interior)
		var newsrc = 'images/products/prod'+prod_id+'_hardware'+hardware_lock_id+'_exterior'+color_exterior_id+'.jpg';
	else
		var newsrc = 'images/products/prod'+prod_id+'_hardware'+hardware_lock_id+'_exterior'+color_exterior_id+'_interior'+color_interior_id+'.jpg';

	swap_images(imgsrc, newsrc);
}

function swap_image_view(imgsrc, display, obj, exterior_exists, interior_exists)
{
	$(imgsrc).title = display;
	var paramsList = '';
	
	var navigation = $$(".buttonAselected");
	navigation.each(
		function(el) {
			el.className = 'buttonA';
		}
	);
	
	obj.className = 'buttonAselected';
	$('safe_view').value = display;
	
	var radioButtons = $$(".colorRadio");
	radioButtons.each(
		function(el) {
			if(el.checked)
			{
				paramsList = el.value;
			}
		}
	);

	//alert(paramsList);
	
	swap_images(imgsrc, paramsList, exterior_exists, interior_exists);
	
}

function swap_image_view_multiple(imgsrc, display, obj, exterior_exists, interior_exists, pg_id)
{
//alert(imgsrc);
	$(imgsrc).title = display;
	var paramsList = '';
	
	$("safe_view_exterior_"+pg_id).className = 'buttonA';
	$("safe_view_interior_"+pg_id).className = 'buttonA';
	
	obj.className = 'buttonAselected';
	$('safe_view_'+pg_id).value = display;

//alert(".colorRadio_"+pg_id);
	
	var radioButtons = $$(".colorRadio_"+pg_id);
	radioButtons.each(
		function(el) {
			if(el.checked)
			{
				paramsList = el.value;
			}
		}
	);

//alert(paramsList);
	
	swap_images_multiple(imgsrc, paramsList, exterior_exists, interior_exists);
	
}

function swap_image_viewcart(imgsrc, display, obj, paramsList, display_area, imgid)
{
	$(imgsrc).title = display;
	
	var navigation = $$(".buttonAselected");
	navigation.each(
		function(el) {
			el.className = 'buttonA';
		}
	);
	
	obj.className = 'buttonAselected';
	
	swap_images(imgsrc, paramsList, display_area, imgid);
	
}

function swap_images(imgsrc, paramsList, display_area, imgid)
{
	if(paramsList == '')
	{
		alert('Please select a color');
		return;
	}
	
	if($('color_view')!=null)
		$('color_view').value = paramsList;
	
	newsrc = '';
	
	paramList_array = paramsList.split('+');
	
	var s = paramList_array[1];
	var g = paramList_array[2];
	var gp = paramList_array[3];
	var ch = paramList_array[4];
	var ce = paramList_array[5];
	var ci = paramList_array[6];
	
	//alert(imgsrc);
	
	if($(imgsrc).title == 'interior')
	{
		var sendurl = 'build_image_display.php?s='+s+'&g='+g+'&gp='+gp+'&ch='+ch+'&ce='+ce+'&ci='+ci+'&imgid='+imgid;
	}
	else
	{
		var sendurl = 'build_image_display.php?s='+s+'&g='+g+'&gp='+gp+'&ch='+ch+'&ce='+ce+'&imgid='+imgid;
	}
//alert(sendurl);
	
	var req = new Request({

		url:sendurl,
		
		onSuccess: function(html){
			
			if($(display_area).innerHTML.search(html) < 0)
			{
				var displayimage = new Fx.Morph(display_area);
				
				displayimage.start({
					opacity: 0
				});
				
				displayimage.addEvent('complete', function() {
				
//alert(html);					
					$(display_area).innerHTML = html;
					
					$(display_area).fade(0); //just give it a second to load
					$(display_area).fade(1);
					
					run_colors_box('safeimage-mb');
					
				});
			
			}
			
		},

		onFailure: function(){
			//failed
		}

	});
	
	
	req.send();
	
}

function swap_images_multiple(imgsrc, paramsList, display_area, imgid)
{
	if(paramsList == '')
	{
		alert('Please select a color');
		return;
	}
	
	if($('color_view')!=null)
		$('color_view').value = paramsList;
	
	newsrc = '';
	
	paramList_array = paramsList.split('+');
	
	var s = paramList_array[1];
	var g = paramList_array[2];
	var gp = paramList_array[3];
	var ch = paramList_array[4];
	var ce = paramList_array[5];
	var ci = paramList_array[6];
	
	//alert(imgsrc);
	
	if($(imgsrc).title == 'interior')
	{
		var sendurl = 'build_image_display.php?s='+s+'&g='+g+'&gp='+gp+'&ch='+ch+'&ce='+ce+'&ci='+ci+'&imgpg='+g;
	}
	else
	{
		var sendurl = 'build_image_display.php?s='+s+'&g='+g+'&gp='+gp+'&ch='+ch+'&ce='+ce+'&imgpg='+g;
	}
//alert(sendurl);
	
	var req = new Request({

		url:sendurl,
		
		onSuccess: function(html){
			
			if($(display_area).innerHTML.search(html) < 0)
			{
				var displayimage = new Fx.Morph(display_area);
				
				displayimage.start({
					opacity: 0
				});
				
				displayimage.addEvent('complete', function() {
				
//alert(html);					
					$(display_area).innerHTML = html;
					
					$(display_area).fade(0); //just give it a second to load
					$(display_area).fade(1);
					
					run_colors_box('safeimage-'+g+'-mb');
					
				});
			
			}
			
		},

		onFailure: function(){
			//failed
		}

	});
	
	
	req.send();
	
}

function run_colors_box(class_name)
{
	var safeImageDisplayMultiBox = new multiBox({
										mbClass: '.'+class_name,
										container: $(document.body),
										showControls: false,
										useOverlay: true
									});

}

function toggleSection(section_id)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	myVerticalSlide.toggle();
	
	myVerticalSlide.addEvent('complete', function() {
		
		if(myVerticalSlide.open)
		{
			//this simply fixes a bug
			$(section_id).parentNode.style.height = null;
		}
		
	});
}

function hideSection(section_id)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	myVerticalSlide.hide();
}

function toggle_leftnav(section_id)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	
	if($(section_id).style.display = 'none')
		$(section_id).style.display = '';
	
	myVerticalSlide.toggle();
	
	myVerticalSlide.addEvent('complete', function() {
		
		if(myVerticalSlide.open)
		{
			$(section_id+'-img').setProperty('src', 'images/sort_open.png');
			$(section_id).parentNode.style.height = null; //this simply fixes a bug
		}
		else
		{
			$(section_id+'-img').setProperty('src', 'images/sort_closed.png');
		}
		
	});
	
}

function toggle_viewcart(section_id)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	
	if($(section_id).style.display = 'none')
		$(section_id).style.display = '';
	
	myVerticalSlide.toggle();
	
	myVerticalSlide.addEvent('complete', function() {
		
		if(myVerticalSlide.open)
		{
			$(section_id+'-img').setProperty('src', 'images/arrow_a_opened.png');
			$(section_id).parentNode.style.height = null; //this simply fixes a bug
			
			if($(section_id+'_buttons_closed') != null)
				$(section_id+'_buttons_closed').style.display = 'none';
				
			if($(section_id+'_buttons_opened') != null)
				$(section_id+'_buttons_opened').style.display = 'block';
		}
		else
		{
			$(section_id+'-img').setProperty('src', 'images/arrow_a_closed.png');
			
			if($(section_id+'_buttons_closed') != null)
				$(section_id+'_buttons_closed').style.display = 'block';
				
			if($(section_id+'_buttons_opened') != null)
				$(section_id+'_buttons_opened').style.display = 'none';
		}
		
	});
	
}

function display_color_swatches(swatchClassName)
{
	
	//using tool tips to display a larger image

	$$(swatchClassName).each(function(element) {
		var content = element.get('rel');
		element.store('tip:title', '');
		element.store('tip:text', '<img src="'+content+'">');
	});

	var customTips = $$(swatchClassName);
	
	var toolTips = new Tips(customTips, {
		showDelay: 10,
		hideDelay: 100,
		className: 'custom_tip',
		
		//this sets the x and y offets
		offsets: {
			'x': 5,       //default is 16
			'y': 5        //default is 16
		},
		
		//this determines whether the tooltip
		//remains staitionary or follows your cursor
		//true makes it stationary
		fixed: false,      //default is false
		onShow: function(toolTipElement){
			toolTipElement.fade(1);
		},
		onHide: function(toolTipElement){
			toolTipElement.fade(0);
		}
	});

}

function display_fixed_tooltips(tipClassName, cssClassName)
{

	$$(tipClassName).each(function(element) {
		var content = element.get('rel');
		element.store('tip:title', '');
		element.store('tip:text', $(content).innerHTML);
	});
	
	var customTips = $$(tipClassName);
	
	var toolTips = new Tips(customTips, {
		showDelay: 10,
		hideDelay: 100,
		className: cssClassName,
		
		
		//this sets the x and y offets
		offsets: {
			'x': 0,       //default is 16
			'y': 22        //default is 16
		},
		
		//this determines whether the tooltip
		//remains staitionary or follows your cursor
		//true makes it stationary
		fixed: true,      //default is false
		onShow: function(toolTipElement){
			toolTipElement.fade(1);
		},
		onHide: function(toolTipElement){
			toolTipElement.fade(0);
		}
	});

}

function toggleSectionMain(section_id, section_element)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	if($(section_id).style.display = 'none')
		$(section_id).style.display = '';
	
	myVerticalSlide.toggle();
	
	myVerticalSlide.addEvent('complete', function() {
		
		if(myVerticalSlide.open)
		{
			section_element.className = 'sectionbuttonOpen';
			$(section_id).parentNode.style.height = null;//this simply fixes a bug
		}
		else
		{
			section_element.className = 'sectionbuttonClose';
		}
		
	});
}

var PropelDropdown = new Class({
	
	initialize: function(closeAreaList, menuBarList, popupList){
		this.closeAreaList = closeAreaList; //these are the areas you would like to close the bar
		this.menuBarList = menuBarList; //These will open the bar
		this.popupList = popupList; //These are the popups that will open
		window.addEvent('domready',this.domReady.bind(this));	
	},
	
	domReady:function(){		
		
		var currentParentObj;
		var currentBarObj;
		var lastPopup = null;
		var instanceObj = this;
		
		//if you mouse over this area, close everything
		$$(this.closeAreaList).each(function(button) {
			
			button.addEvent('mouseenter',function() {
				instanceObj.hideCurrentBar(currentParentObj, currentBarObj);
				if(lastPopup != null) lastPopup.fade(0);  //clear the last popup
				currentBarObj = null;
				currentParentObj = null;
			});
			
		});
		
		
		$$(this.menuBarList).each(function(button) {
			
			button.addEvent('mouseenter',function() {
				
				if(lastPopup != null) lastPopup.fade(0); //clear the last popup
				
				if(currentBarObj != null && currentBarObj != $(button.get('id') + '-content-display'))
				{
					instanceObj.hideCurrentBar(currentParentObj, currentBarObj);
					currentBarObj = null;
					currentParentObj = null;
				}
				
				if(currentBarObj == null || currentBarObj != $(button.get('id') + '-content-display'))
				{
					currentParentObj = button;
					currentParentObj.addClass('topnav_menu_selected');
					currentBarObj = $(button.get('id') + '-content-display');
					currentBarObj.setStyles({opacity:0,display:'block'});
					currentBarObj.fade(1);
				}
			});
			
		});
		
		
		$$(this.popupList).each(function(button) {
			
			if($(button.get('id') + '-content-display') != null)
			{
				button.addEvent('mouseenter',function() {
					if(lastPopup != null && lastPopup.id != button.get('id') + '-content-display') lastPopup.fade(0);  //clear the last popup
					$(button.get('id') + '-content-display').setStyles({opacity:0,display:'block'});
					$(button.get('id') + '-content-display').fade(1);
					lastPopup = $(button.get('id') + '-content-display');
				});
				
				
				$(button.get('id') + '-content-display').addEvent('mouseleave',function() {
					$(button.get('id') + '-content-display').fade(0);
				});
			}
			
			
		});
			
	},
	
	hideCurrentBar:function(currentParentObj, currentBarObj){
		if(currentBarObj != null)
		{
			currentBarObj.fade(0);
			if(currentParentObj != null)
			{
				currentParentObj.removeClass('topnav_menu_selected');
			}
		}
	}
	
});

function toggle_edit_delivery_info(section_id, section_edit_id)
{
	var myVerticalSlide = new Fx.Slide(section_id);
	
	if($(section_id).style.display = 'none')
		$(section_id).style.display = '';
	
	myVerticalSlide.toggle();
	
	myVerticalSlide.addEvent('complete', function() {
		
		if(myVerticalSlide.open)
		{
			$(section_id+'-img').setProperty('src', '../images/button_edit_active.png');
			$(section_id).parentNode.style.height = null; //this simply fixes a bug
		}
		else
		{
			$(section_id+'-img').setProperty('src', '../images/button_edit_selected.png');
		}
		
	});
	
	
	var myVerticalSlideEdit = new Fx.Slide(section_edit_id);

	$(section_edit_id).style.display = 'block';
	
	myVerticalSlideEdit.toggle();
	
	myVerticalSlideEdit.addEvent('complete', function() {
		
		if(myVerticalSlideEdit.open)
		{
			//this simply fixes a bug
			$(section_edit_id).parentNode.style.height = null;
		}
		else
		{
			$(section_edit_id).style.display = 'none';
		}
		
	});
	
	
}
