
function goToCheckout(zipIsSet, button)
{
	if(zipIsSet){
		goTo('https://www.buysodaonline.com/checkout.php');
	}else{
		alert("Please enter your zip code and update the cart before continuing");
		button.disabled = true;
	}
}


function disableShipping(disable)
{
	document.getElementById('shipping_name').disabled = disable;
	document.getElementById('shipping_address_1').disabled = disable;
	document.getElementById('shipping_address_2').disabled = disable;
	document.getElementById('shipping_city').disabled = disable;
	document.getElementById('shipping_state_id').disabled = disable;
	document.getElementById('shipping_zip').disabled = disable;
}


function hideOptionsLabel(frmName, map, id)
{
	var frm = document.forms[frmName];
	if(map[id] == true)
		frm['data[label]'].value = '';
	frm['data[label]'].disabled = map[id];
}


function validateDateField(fld)
{
	if(fld.value == 'mm-dd-yyyy'){
		fld.value == '';
		return false;
	}
	return true;
}


function confirmDelete(url)
{
	if( confirm('Are you sure you want to delete this record?') ){
		window.location.href = url;
		return true;
	}

	return false;
}


function goTo(url)
{
	window.location.href = url;
	return true;
}


function popupWindow(url, width, height, name)
{
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	if(name == null){
		day = new Date();
  		name = 'popup_' + day.getTime();
	}
	eval(name + " = window.open(url, '" + name + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + "');");
}

var expanded_sub = 0;

function expandSubCat( id )
{
	new Effect.toggle( $('product_subcat_' + id ), 'blind' );
}

function jumpCat( row )
{
	var id = row.value;
	
	new Effect.toggle( $('product_subcat_' + id ), 'blind' );
	$( id + '_header').scrollTo();
}

function quickJumpCat( id )
{
	new Effect.toggle( $('product_subcat_' + id ), 'blind' );
	$( id + '_header').scrollTo();
}

function toggleZip( which, state )
{
	if( state )
	{
		$('price_out_' + which ).innerHTML = '<div id="skewdiv"><a href="javascript:{}" onClick="toggleZip(' + which + ',0);" value="Hide Div">x</a>&nbsp;&nbsp;&nbsp;&nbsp;Zip <input type="text" name="textfield" size="10"><input type="image" name="Submit" value="go" src="images/zipbtngo.gif" width="17" height="13"></div>';
	}
	else
	{
		$('price_out_' + which ).innerHTML = ' <a id="' + which + '_link" class="price-it-out" href="javascript:void(0);" onclick="toggleZip( ' + which + ', 1 );">Price it out. <strong>Enter ZIP Code</strong></a>';
	}
}

function ajaxEnterProductZip( product_id )
{
	var params = "product_id=" + product_id;
	var url = "ajax/product_enter_zip.php";
	var div = "price_section";
	
	var ajax = new Ajax.Updater( 
		div,
		url,
		{
			parameters: params,
			evalScripts: true
		}
	)
}

function updateCartPrice( price, box )
{
	
	var new_total = parseFloat( total );
	var mod = parseFloat( price );
	
	if( box.checked == true )
	{
		new_total = new_total + mod;
		total = new_total;
	}
	else
	{
		new_total = new_total - mod;
		total = new_total;
	}
	
	$('order_total').innerHTML = "$" + number_format( new_total, 2, '.', ',' );
}

function number_format( number, decimals, dec_point, thousands_sep ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://crestidg.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57     
 
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "," : dec_point;
    var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}