
var g_VisibleMenu;

var d=document;
var agt=navigator.userAgent.toLowerCase();
var major = parseInt(navigator.appVersion);
var dom=(d.getElementById)?1:0;
var ns=(d.layers);
var ns4up=(this.ns && this.major >=4);
var ns6=(this.dom&&navigator.appName=="Netscape");
var op=(window.opera? 1:0);
var ie=(d.all);
var ie4=(d.all&&!this.dom)?1:0;
var ie4up=(this.ie && this.major >= 4);
var ie5=(d.all&&this.dom);
var win=((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1));
var mac=(this.agt.indexOf("mac")!=-1);

function openStars(){
	win = window.open("index.cfm?fuseaction=forums.stars","Stars","height=300,width=320");
}

function printableHelp(){
	win = window.open("index.cfm?fuseaction=order.printable","PrintableHelp","height=400,width=500,resizable=yes,scrollbars=yes");
}

function doNothing(){
}

function checkAll(theCheckAll, theCheckboxes){
	if (theCheckboxes){
		if (theCheckboxes.length){
			for (i=0; i<=theCheckboxes.length-1; i++){
				theCheckboxes[i].checked = theCheckAll.checked;
			}
		} else {
			theCheckboxes.checked = theCheckAll.checked;
		}
	}
}

function getY(obj){
	var y=0;
	if (ns){
		y=obj.pageY;
	} else {
		o=obj;
		while(eval(o)) { y+=o.offsetTop; o=o.offsetParent; }
	}
	
	return y;
}

function getX(obj){
	var x=0;
	if (ns){
		x=obj.pageX;
	} else {
		o=obj;
		while(eval(o)) { x+=o.offsetLeft; o=o.offsetParent; }
	}
	
	return x;
}

function Document_Click(){
	HideMenu();
}

function HideMenu(){
	
	if (g_VisibleMenu){
		g_VisibleMenu.style.visibility="hidden";
	}
}

function ShowMenu(theMenu, x, y){
	g_VisibleMenu = document.getElementById(theMenu);
	if (g_VisibleMenu){
		g_VisibleMenu.style.top=y;
		g_VisibleMenu.style.left=x;
		g_VisibleMenu.style.visibility="visible";
		
	} 
	else {
		return false;
	}
}

function hideItem(theObj){
	var hiddenClass="hiddenItem";
	if (theObj.nodeName == "TR")
	{
		hiddenClass="hiddenRow";
	}

	if (theObj.length){
		for (i=0; i<theObj.length; i++){
			theObj[i].className=hiddenClass;
		}
	} else {
		theObj.className=hiddenClass;
	}
}
function showItem(theObj){
	var visibleClass="visibleItem";
	if (theObj.nodeName == "TR")
	{
		visibleClass="visibleRow";
	}
	
	if (theObj.length){
		for (i=0; i<theObj.length; i++){
			theObj[i].className=visibleClass;
		}
	} else {
		theObj.className=visibleClass;
	}
}
function showBlock(theObj){
	var visibleClass="visibleBlock";
	if (theObj.nodeName == "TR")
	{
		visibleClass="visibleRow";
	}
	
	if (theObj.length){
		for (i=0; i<theObj.length; i++){
			theObj[i].className=visibleClass;
		}
	} else {
		theObj.className=visibleClass;
	}
}

function hideRow(theObj){
	if (theObj.length){
		for (i=0; i<theObj.length; i++){
			//theObj[i].style.top=0;
			//theObj[i].style.position="absolute";
			//theObj[i].style.visibility="hidden";
			theObj[i].className="hiddenRow";
		}
	} else {
		//theObj.style.top=0;
		//theObj.style.position="absolute";
		//theObj.style.visibility="hidden";
		//theObj.style.display="none";
		theObj.className="hiddenRow";
	}
}
function showRow(theObj){
	if (theObj.length){
		for (i=0; i<theObj.length; i++){
			//theObj[i].style.top=0;
			//theObj[i].style.position="relative";
			//theObj[i].style.visibility="visible";
			theObj[i].className="visibleRow";
		}
	} else {
		//theObj.style.top=0;
		//theObj.style.position="relative";
		//theObj.style.visibility="visible";
		//theObj.style.display="table-row";
		theObj.className="visibleRow";
	}
}

function swapImage(theImage, changeTo){
	document.getElementById(theImage).src=changeTo;
}
function openItemImageWindow(ItemID){
	var dlg = window.open("index.cfm?fuseaction=store.itemImages&item_id="+ItemID, "ItemImageWindow", "toolbar=no,menubar=no,personalbar=no,width=600,height=600,scrollbars=yes,resizable=no");
}
//document.onclick=Document_Click;

function checkItemOptions(theForm,theErrorMessage)
{
	if (theForm.Item_Type_List)
	{
		if (theForm.Item_Type_Group_List.length)
		{
			for (i=0; i<theForm.Item_Type_List.length; i++)
			{
				if (theForm.Item_Type_List[i].selectedIndex==0)
				{
					showItem(document.getElementById(theErrorMessage));
					return false;
				}
			}
		}
		else
		{
			if (theForm.Item_Type_List.selectedIndex==0)
			{
				showItem(document.getElementById(theErrorMessage));
				return false;
			}
		}
	}
	return true;
}

function openFormulaWindow() {
	var t=window.open('index.cfm?fuseaction=shippingtable.formulahelp','FormulaHelp','width=400,height=350');
}

function openItemNotifyWindow(item_id){
	var t=window.open('index.cfm?fuseaction=order.notify&item_id='+item_id,'ItemNotify','width=450,height=250');
}

function openWindow(url,windowName,options){
	var t=window.open(url,windowName,options);
}

function validUploadType(theField, UploadList)
{
	fileName = theField.value;
	
	if (fileName != "")
	{
		extension = fileName.substr(fileName.lastIndexOf(".") +1).toLowerCase();
		
		for (i=0; i < UploadList.length; i++ )
		{
			if (extension == UploadList[i])
			{
				return true;
			}
		}
		
		alert('The file you are uploading must be of the following types: ' + UploadList);
		return false;
	}
	return true;
}

function deleteLinkPrompt(theMessage, theLink)
{
	ans = confirm(theMessage);
	if(ans)
	{
		location.href=theLink;
	}
}

function checkAll(theToggle, theCheckBoxes)
{
	if (theCheckBoxes.length)
	{
		for (i=0; i<=theCheckBoxes.length-1; i++){
			theCheckBoxes[i].checked = theToggle.checked;
		}
	}
	else
	{
		theCheckBoxes.checked = theToggle.checked;
	}
}

function getElement(name)
{
	var element = "";
	if (document.getElementById)
	{
		element = document.getElementById(name);
	}
	else if (document.all)
	{
		element = document.all[name];
	}
	return element;
}

//taken from DWUtil
function isArray(data)
{
    return (data && data.join) ? true : false;
}

//optional arguments 3 and 4 are named keys for the data array
function addOptionsWithBlank(theCombo, dataArray)
{
	var o = new Option("", "");
	theCombo[theCombo.length] = o;
	if (arguments.length == 4)
		addOptions(theCombo, dataArray, arguments[2], arguments[3]);
	else if (arguments.length == 3)
		addOptions(theCombo, dataArray, arguments[2]);
	else
		addOptions(theCombo, dataArray);
	
}
//taken from DWUtil
//optional arguments 3 and 4 are named keys for the data array
function addOptions(theCombo, dataArray)
{
	var val = 0;
	var text = 0;
	var oVal = "";
	var oText = "";
	
	if (arguments.length >= 3)
	{
		//"key" value
		val = arguments[2];
		text = arguments[2];
	}
	if (arguments.length >= 4)
	{
		text = arguments[3];
	}
	
	if (isArray(dataArray))
	{
		for (var i = 0; i < dataArray.length; i++)
		{
			oText = dataArray[i][text];
			oVal = dataArray[i][val];
			
			var opt = new Option(oText, oVal);
			theCombo.options[theCombo.options.length] = opt;
		}
	}
	else
	{
		for (var prop in dataArray)
		{
			if (val != 0)
			{
				oText = prop;
				oVal = dataArray[prop];
			}
			else
			{
				oText = dataArray[prop];
				oVal = prop;
			}
			
			var opt = new Option(oText, oVal);
			theCombo.options[theCombo.options.length] = opt;
		}
	}
}

function loadChildLocFromParent(theParent, theChild, elementToHide)
{
	theChild.options.length = 0;
	if (theParent[theParent.selectedIndex].value != "")
	{
		if (_ParentLocations[theParent[theParent.selectedIndex].value].length)
		{
			addOptionsWithBlank(theChild, _ParentLocations[theParent[theParent.selectedIndex].value], "KEY", "VALUE");
			showItem(document.getElementById(elementToHide));
		}
	}
	if (theChild.options.length == 0)
	{
		hideItem(document.getElementById(elementToHide));
	}
}

function loadChildSelect(theParent, theChild, valuesArray, blankMessage, elementToHide)
{
	theChild.options.length = 0;
	if (theParent[theParent.selectedIndex].value != "")
	{
		if (valuesArray[theParent[theParent.selectedIndex].value].length)
		{
			addOptionsWithBlank(theChild, valuesArray[theParent[theParent.selectedIndex].value], "KEY", "VALUE");
			if (elementToHide)
				showItem(document.getElementById(elementToHide));
		}
	}
	if (theChild.options.length == 0)
	{
		theChild[0] = new Option(blankMessage, "");
		if (elementToHide)
			hideItem(document.getElementById(elementToHide));
	}
}

function preloadImages(imageArray)
{
	var images = new Array();
	for(i=0; i<imageArray.length; i++)
	{
		images[i] = new Image(); 
		images[i].src = imageArray[i];
	}
}

/******/
function doCharCount(textArea, textBlock, maxChars)
{
	document.getElementById(textBlock).innerHTML=maxChars - textArea.value.length; 
	if (textArea.value.length > maxChars) 
	{ 
		textArea.value = textArea.value.substring(0,maxChars);
		document.getElementById(textBlock).innerHTML=0;
		return false;
	}
}


function openPersonPhotoWindow(PersonID,PersonPhotoID){
	var dlg = window.open("index.cfm?fuseaction=photos.popupList&person_id="+PersonID+"&person_photo_id="+PersonPhotoID, "PersonPhotoWindow", "toolbar=no,menubar=no,personalbar=no,width=#Evaluate(maxImageWidth+50)#,height=#Evaluate(maxImageHeight+100)#,scrollbars=yes,resizable=yes");
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
