function showmenu(elmnt1,elmnt2) {
	document.getElementById(elmnt1).style.visibility="visible";
	//document.getElementById(elmnt2).style.background="#EFEDE6";
	//document.getElementById(elmnt3).style.visibility="visible";
}

function hidemenu(elmnt1,elmnt2) {
	document.getElementById(elmnt1).style.visibility="hidden"
	//document.getElementById(elmnt2).style.background="#EFEDE6";
	//document.getElementById(elmnt3).style.visibility="hidden";
}

function jsSwapImage()
{
	if (document.images){
		for (var i=0; i < jsSwapImage.arguments.length; i=i+2){
			document.images[jsSwapImage.arguments[i]].src = jsSwapImage.arguments[i+1];
		}
	}
}

var images = new Array();
function jsLoadImages()
{
	if (document.images)
	{
		for (var i=0; i < jsLoadImages.arguments.length; i++){
			images[i] = new Image();
			images[i].src = jsLoadImages.arguments[i];
		}
	}
}


function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
    return null;
  }
  if ( start == -1 ) return null;
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}


function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function ChangeinnerHTML(layerid, htmlcode, format_type) {
    var statement = '';
	//var newhtmlcode = insertCommas(htmlcode);
	var newhtmlcode;
	if (format_type=="NUMBER") {
		nf = new NumberFormat(htmlcode);
		nf.setSeparators(true, nf.COMMA, nf.PERIOD);
		nf.setNegativeFormat(nf.PARENTHESIS);
		nf.setPlaces(0);
		newhtmlcode = nf.toFormatted()
	}
	else if (format_type=="FLOAT") {
		nf = new NumberFormat(htmlcode);
		nf.setSeparators(true, nf.COMMA, nf.PERIOD);
		nf.setNegativeFormat(nf.PARENTHESIS);
		nf.setPlaces(2);
		newhtmlcode = nf.toFormatted()
	}
	else if (format_type=="CURRENCY") {
		nf = new NumberFormat(htmlcode);
		nf.setSeparators(true, nf.COMMA, nf.PERIOD);
		nf.setNegativeFormat(nf.PARENTHESIS);
		nf.setCurrency(true);
		nf.setCurrencyPosition(nf.LEFT_INSIDE)
		nf.setPlaces(0);
		newhtmlcode = nf.toFormatted()
	}
	else if (format_type=="PERCENT") {
		nf = new NumberFormat(htmlcode);
		nf.setSeparators(true, nf.COMMA, nf.PERIOD);
		nf.setNegativeFormat(nf.PARENTHESIS);
		nf.setPlaces(0);
		newhtmlcode = nf.toPercentage();
	}
	else if (format_type=="TEXT") {
		newhtmlcode = htmlcode;
	}
	else {
		nf = new NumberFormat(htmlcode);
		newhtmlcode = nf.toFormatted()
	}


    // insert commas into calculations
	//alert(htmlcode)
    if (document.all) 
	  statement += "document.all['" + layerid + "'].innerHTML = '" + newhtmlcode + "';";	     
    else if (document.getElementById)           
	  statement += "document.getElementById('" + layerid + "').innerHTML = '" + newhtmlcode + "';"; 
    
    eval(statement);    
}
function GetinnerHTML(layerid) {
    var statement = '';

    if (document.all) 
	  statement += "document.all['" + layerid + "'].innerHTML;";	     
    else if (document.getElementById)           
	  statement += "document.getElementById('" + layerid + "').innerHTML;"; 
    
    return eval(statement);    
}
function removeChar(s)
{
	var ch = (removeChar.arguments.length > 1) ? removeChar.arguments[1]: ','; // default = comma
	var astrVals = s.split(',');
	s = astrVals.join('');
	return s;
}

function addtocart(item_id) {

	
	var quantity = eval('document.forms[0].quantity_'+item_id+'.value');
	var quantity_type =  eval('document.forms[0].quantity_type_'+item_id+'.value');
	
	
	//cart_contents = item_id+'|'+num_bottles+'|'+num_cases+"~";
	//Set_Cookie('mycart', cart_contents, '', '/', '', '' );
	
	if(Get_Cookie('item_exists'+item_id)=="true") {
		// This item has already been added
		//add number of bottles and cases
		if(quantity_type=="bottle"){
			num_bottles = parseInt(quantity) + parseInt(Get_Cookie('bottle'+item_id));
			num_cases = Get_Cookie('case'+item_id);
		} else if (quantity_type=="case") {
			num_cases = parseInt(quantity) + parseInt(Get_Cookie('case'+item_id));
			num_bottles = Get_Cookie('bottle'+item_id);
		}
		//alert(num_bottles);
		Set_Cookie('bottle'+item_id, num_bottles, '', '/', '', '' );
		Set_Cookie('case'+item_id, num_cases, '', '/', '', '' );

	} else {
		// add item id
		existing_ids_incart = Get_Cookie('itemids_in_cart');
		existing_ids_incart = existing_ids_incart+item_id+',';
		//alert(existing_ids_incart);
		Set_Cookie( 'itemids_in_cart', existing_ids_incart, '', '/', '', '' );
		
		//add number of bottles and cases
		if(quantity_type=="bottle"){
			num_bottles = quantity;
			num_cases = 0;
		} else if (quantity_type=="case") {
			num_cases = quantity;
			num_bottles = 0;
		}
		Set_Cookie('bottle'+item_id, num_bottles, '', '/', '', '' );
		Set_Cookie('case'+item_id, num_cases, '', '/', '', '' );
		
		//mark id as exists
		Set_Cookie( 'item_exists'+item_id, 'true', '', '/', '', '' );
		
		//Set_Cookie( 'item'+num_items, item_id, '', '/', '', '' );
		//Set_Cookie( 'quantity'+item_id, quantity, '', '/', '', '' );
		//Set_Cookie( 'quantity_type'+item_id, quantity_type, '', '/', '', '' );
	}
	//alert(document.cookie.split(';').join('\n'));
	num_items = parseInt(num_items) +parseInt(num_bottles) + parseInt(num_cases);
	ChangeinnerHTML("html_num_items",num_items,"NUMBER");
	Set_Cookie( 'items_in_cart', num_items, '', '/', '', '' );
	window.location.href="viewcart.php";
}

function removefromcart(item_id,quantity,quantity_type) {
	

}


