function showHelp(which)
{
	try {
		document.getElementById('help_target').innerHTML = document.getElementById('help_'+which).innerHTML;
	} catch(e) {}
}

function unCheckMaster(f,elemName)
{
	f.elements[elemName][0].checked=false;
}

function doCheckAll(f,elemName,checkState)
{
	try {
		for (var i=1; i<f.elements[elemName].length; i++)
			f.elements[elemName][i].checked=checkState;
	} catch(e) {alert(e.message);}
}

function setBSData(f, sel, title)
{
	try {
		if (!title) title = "";
		if (sel && clocs[sel])
		{
			f.elements['clnt_name'].value = (clocs[sel]['cloc_name'] ? clocs[sel]['cloc_name'] : title)
			f.elements['clnt_phone'].value = clocs[sel]['cloc_phone'];
			f.elements['clnt_fax'].value = clocs[sel]['cloc_fax'];
			f.elements['clnt_ship_address'].value = clocs[sel]['cloc_ship_address'];
			f.elements['clnt_bill_address'].value = clocs[sel]['cloc_bill_address'];
			f.elements['clnt_ship_city'].value = clocs[sel]['cloc_ship_city'];
			f.elements['clnt_bill_city'].value = clocs[sel]['cloc_bill_city'];
			f.elements['clnt_ship_zip'].value = clocs[sel]['cloc_ship_zip'];
			f.elements['clnt_bill_zip'].value = clocs[sel]['cloc_bill_zip'];
			for (i=0;i<f.elements['clnt_ship_state'].options.length;i++)
				if (f.elements['clnt_ship_state'].options[i].value == clocs[sel]['cloc_ship_state'])
				{
					f.elements['clnt_ship_state'].selectedIndex=i;
					break;
				}
			for (i=0;i<f.elements['clnt_bill_state'].options.length;i++)
				if (f.elements['clnt_bill_state'].options[i].value == clocs[sel]['cloc_bill_state'])
				{
					f.elements['clnt_bill_state'].selectedIndex=i;
					break;
				}
	}
	} catch(e) { alert(e.message); }
}

function FavoriteToggler(prod_id, crtStatus)
{
	// initialization
	var node = document.createElement('img');
	node.src = "/images/spacer.gif";
	node.className = "clickable product_favorite" + (crtStatus ? " product_is_favorite" : "");
	node.title = (crtStatus ? "This product is on your favorites list. Click to remove it." : "Click to add this product to your favorites list")

	// closures
	this.appendTo = function(elem)
	{
		elem.appendChild(node);
	}
	this.insertTo = function(elem)
	{
		elem.insertBefore(node, elem.firstChild);
	}

	// further initializations
	node.onclick = function() {
		x_NSF_SetFavorite(prod_id, crtStatus ? 0 : 1, function(newValue)
			{
				crtStatus = newValue;
				node.className = "clickable product_favorite" + (crtStatus ? " product_is_favorite" : "");
				node.title = (crtStatus ? "This product is on your favorites list. Click to remove it." : "Click to add this product to your favorites list")
			}
		);
	}
}


function ShowDiv( divId, relativeToElemId ) {
    divElem = document.getElementById( divId + '');
    relativeToElem = document.getElementById( relativeToElemId + '');

    if ( divElem && relativeToElem ) {
        divElem.style.display = 'block';
        divElem.style.top = parseInt(parseInt(relativeToElem.top) + 5) + 'px';
        divElem.style.left = relativeToElem.left;
    }
}

function HideDiv( divId ) {
    divElem = document.getElementById( divId + '');

    if ( divElem ) {
        divElem.style.display = 'none';
    }
}
