var lastBoxId = null;

function toggleBox(boxId, state)
{
    var obj = document.layers ? document.layers[boxId] : document.getElementById ? document.getElementById(boxId).style : document.all[boxId].style;
    obj.visibility = document.layers ? (state ? "show" : "hide") : (state ? "visible" : "hidden");
    return false;
}

function show(boxId)
{
    if (lastBoxId != null) { toggleBox(lastBoxId, false); }
    lastBoxId = boxId;
    return toggleBox(boxId, true);
}

function inc(name)
{
    var qty = parseInt(document.product[name].value, 10);
    if (isNaN(qty)) { qty = 1; }
    else { qty++; }
    if (qty < 1) { qty = 1; }
    //if (qty > 11) { qty = 10; }
    document.product[name].value = qty;
    return false;
}

function dec(name)
{
    var qty = parseInt(document.product[name].value, 10);
    if (!isNaN(qty) && qty > 1) { qty--; } else { qty = ""; }
    if (qty < 1) { qty = ""; }
    //if (qty > 10) { qty = 10; }
    document.product[name].value = qty;
    return false;
}

var PopUpWindow;

function openPopUpWindow(Url, Width, Height, Scrollbars)
{
    var DefaultHeight = 670;
    var DefaultWidth = 600;
    var DefaultScrollbars = "yes";
    
    if (Height == null) { Height = DefaultHeight; }
    if (Width == null) { Width = DefaultWidth; }
    if (Scrollbars == null) { Scrollbars = DefaultScrollbars; }
    
    if (PopUpWindow && !PopUpWindow.closed) { PopUpWindow.document.location.href = Url; }
    else
    {
        PopUpWindow = window.open(Url, "PopUpWindow", "scrollbars=" + Scrollbars + ",status=no,resizable=no,left=100,top=100,width=" + Width + ",height=" + Height);
    }
    return false;
}

function openBanner(Url, Width, Height, Scrollbars)
{
    if (readCookie("banner") != "no")
    {
        createCookie("banner", "no")
        return openPopUpWindow(Url, Width, Height, Scrollbars);
    }
}

function checkDelivery(frm)
{
    var user_input;
    for (i = 0; i < frm.delivery.length; i++)
    {
    	if (frm.delivery[i].checked)
    	{
    		user_input = frm.delivery[i].value;
    	}
    }
    //if (user_input == 7)
    //{
        return openPopUpWindow("/lawfirm.html", 400, 300, "no");
    //}
}

function createCookie(name,value,days)
{
	document.cookie = name+"="+value+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

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 Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

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";
}
