function sc_add_item(id, sc, item_name)
{
	sc_object.item_name = item_name;
	qty = new Number(GID('item_' + id).value);
	request = {
	"handler":"/resources/engines/shopcart/ajax/sc_add_item.php?sc=" + sc,
	"item":id,
	"qty":qty,
	"show_request":false
	}
	
	ajax(request, sc_update_cart);
}

function sc_update_cart(result)
{
	GID('shopcart_itemcount').innerHTML = result;
	
	if (sc_object.notify)
	{
		sc_notify();
	}
}

function sc_store_checkout()
{
	config = {
	"url":"/resources/engines/shopcart/ajax/sc_store_checkout.php",
	"post":true
	}
	
	data = new Object();
	
	if (document.shopcart.delivery_date)
	{
		data.delivery_date = document.shopcart.delivery_date.value;
	}
	
	if (document.shopcart.shipping)
	{
		data.shipping = document.shopcart.shipping.value;
	}
	
	if (document.shopcart.customer_notes)
	{
		data.notes = document.shopcart.customer_notes.value;
	}
	
	request = {
	"config":config,
	"data":data
	}
	
	ajax(request, sc_tmp);
}

function sc_tmp(result)
{
	alert(result);
}

function sc_notify()
{    
	item_name = sc_object.item_name;
    login = sc_object.login;
    register = sc_object.register;
    background_color  = sc_object.background_color;
 
    darkenScreen(80);
    boxWidth = 300;
    boxHeight = 130;
    screenWidth = GXY('x');
    screenHeight = GXY('y');

    div = document.createElement('div');
    div.style.position = 'absolute';
    div.style.fontSize = '12pt';
    div.style.padding = '10px';
    div.style.textAlign = 'center';
    div.style.backgroundColor = background_color;
    div.style.zIndex = 10;
    div.className = 'contenttd';
    div.id = 'notifyCartBox';
    div.innerHTML = '<b>' + item_name + '</b><br>has been added to your cart<br><br>';
    div.innerHTML += '<div style="width:' + boxWidth + 'px">';
    div.innerHTML += '<div><a href="javascript:continue_shopping()">' +
                        'Continue Shopping</a></div>';  
    div.innerHTML += '<div><a href="?sc=checkout">' +
                        'Checkout</a></div>';  
                        
    if (!readCookie('USERNAME'))
    {
        if (login)
        {
            div.innerHTML += '<div><a href="' + login + '">' +
                                'Login</a></div>';            
            boxHeight += 20;  
        }
        
        if (register)
        {
            div.innerHTML += '<div><a href="' + register + '">' +
                                'Register</a></div>';     
            boxHeight += 20;       
        }
             
    }
     
    div.innerHTML += '</div>';
    div.style.width = boxWidth + 'px';
    div.style.height = boxHeight + 'px';
    div.style.top = (f_scrollTop() + (((screenHeight + boxHeight)/2) - boxHeight - 50)) + 'px';
    div.style.left = (screenWidth/2) - (boxWidth/2) + 'px';                          
    document.body.appendChild(div);
    
    //alert(readCookie('USERNAME'));
    //darkenScreen(0)
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function sc_update_total(c)
{
	url = ''	
	check = ["shipping", "tax"];
	
	for (i = 0; i < check.length; i ++)
	{
		id = check[i] + '[' + c + ']';
		obj = document.forms['shopcart[' + c + ']'].elements[id];		
		if (obj)
		{
			if (obj.value)
			{
				url += '&' + check[i] + '[' + c + ']=' + obj.value;
			}
		}
	}
	
	if (url.length)
	{
		location = '?sc=checkout' + url;
	}
}

function sc_send_order(c)
{
	valid = true;
	f = document.forms['shopcart[' + c + ']'];
	
	check = ["shipping", "tax"];
	
	for (i = 0; i < check.length; i ++)
	{
		obj = f.elements[check[i] + '[' + c + ']'];
		if (obj)
		{
			warning = GID(check[i] + '_warning[' + c + ']');
			warning.style.display = 'none';
			if (!obj.value)
			{
				valid = false;
				warning.style.display = 'inline';
			}
		}
	}
		
	if (valid)
	{
		f.submit();
	}	
}

function send_order(c)
{
	alert(c);
}

function continue_shopping()
{
    darkenScreen(0);
    document.body.removeChild(GID('notifyCartBox'));
}