// JavaScript Document
function CellHover(cell,onflag)
{
	cell.style.backgroundColor = (onflag ? "#FFFFFF" : "#AACCFF");
	cell.style.border = (onflag ? "1 solid #AACCFF" : "none");
	cell.style.cursor = "hand";
	//cell.style.color = (onflag ? "#AACCFF" : "#000000");
	var lnk = document.getElementById("nl_"+cell.id);
	//if (lnk != null) lnk.style.color = (onflag ? "#AACCFF" : "#000000");
}

function OpenPopup(url, width, height, name, otherattribs)
{
	window.open(url, name, "width="+width+",height="+height+","+otherattribs);
}

function PreviewImage(imgpath)
{
	OpenPopup("file://" + imgpath, 350, 350, "", "");
}

function ConfirmJobLoad(categoryName)
{
	var msg = "This will replace the currently loaded "+categoryName+" job with the selected one.\n"
			+ "All art items for the current "+categoryName+" job will be cleared out.\n"
			+ "Your current category selection will also be set to "+categoryName+".\n\n"
			+ "Are you sure you wish to continue?";
	return (window.confirm(msg));
}

function tsmsg()
{
	location.href = "mailto:webadmin@avioart.com";
}

function ToggleSelection(chkName, chkVal)
{
    var frmctls = document.forms[0].elements;

    for (var i=0; i < frmctls.length; i++)
    {
			if (frmctls[i].type == "checkbox")
			{
				if (frmctls[i].name.indexOf(chkName) > -1) frmctls[i].checked = chkVal;
			}
    }
}

function ParseFileName(srcFile)
{
	// parse on backslashes to find everything after the last backslash (i.e. the file name)
	var tokens = srcFile.split("\\");
	var imgName = tokens[tokens.length-1];
	
	// set the file name without the .XXX extension
	document.f_art.Image_Name.value = imgName.substring(0, imgName.length-4);
	
	// empty out all the controls
	ClearControlArray(GetControlArray())
}

function ParseImageName(imgName)
{
	// don't bother if the value is empty
	if (imgName == "") return;
	
	// array of fields for the page
	var ctls = GetControlArray()
	
	// empty out all the controls
	ClearControlArray(ctls)
	
	// split an array from the image name, based on underscores
	var flds = imgName.split("_");
	
	// loop through the array created here
	for (var i=0; i < flds.length; i++)
	{
		if (i < ctls.length)
		{
			switch (ctls[i]) 
			{
				case "Retail_Price_Art" :
					var re = /d/gi;
					var price = flds[i].toLowerCase().replace(re, "");
					if (price.indexOf("p") > -1) {
						var p = price.split("p");
						document.f_art.Retail_Price_Art.value = p[0] + "." + p[1];
					} else {
						document.f_art.Retail_Price_Art.value = price + ".00";
					}
					break;
				case "Active_Flag" :
					if (flds[i].toLowerCase() == "y") document.f_art.Active_Flag[0].checked = true;
					if (flds[i].toLowerCase() == "n") document.f_art.Active_Flag[1].checked = true;
					break;
				case "Category_Id" :
					switch (flds[i].toLowerCase())
					{
						case "t" :
							document.f_art.Category_Id_Traditional.checked = true;
							break;
						case "b" :
							document.f_art.Category_Id_Contemporary.checked = true;
							document.f_art.Category_Id_Traditional.checked = true;
							break;
						default :
							document.f_art.Category_Id_Contemporary.checked = true;
					}
					break;
				case "Image_Height_Width" :
					var txt = flds[i].toLowerCase()
					if (txt.indexOf("x") > -1)
					{
						var dimms = txt.split("x");
						for (var j=0; j < dimms.length; j++)
						{
							var dimm;
							if (dimms[j].indexOf("p") > -1) {
								var p = dimms[j].split("p");
								dimm = p[0] + "." + p[1];
							} else {
								dimm = dimms[j];
							}
							if (j == 0)
								document.f_art.Image_Height.value = dimm;
							else 
								document.f_art.Image_Width.value = dimm;
						}
					}
					break;
				default :
					document.f_art.elements[ctls[i]].value = flds[i];
			} 
		}
	}
}

function GetControlArray()
{
	// array of fields for the page
	return (new Array("Artist_Last_Name", "Artist_First_Name", "Art_Title", "Image_Source_Cd", 
		"Source_Order_Num", "Image_Height_Width", "Category_Id", "Active_Flag", "Retail_Price_Art"));	
}

function ClearControlArray(ctlArray)
{
	// empty out all the controls
	for (var i=0; i < ctlArray.length; i++)
	{
		switch (ctlArray[i]) 
		{
			case "Active_Flag" :
				document.f_art.Active_Flag[0].checked = false;
				document.f_art.Active_Flag[1].checked = false;
				break;
			case "Category_Id" :
				document.f_art.Category_Id_Contemporary.checked = false;
				document.f_art.Category_Id_Traditional.checked = false;
				break;
			case "Image_Height_Width" :
				document.f_art.Image_Height.value = "";
				document.f_art.Image_Width.value = "";
				break;
			default :
				document.f_art.elements[ctlArray[i]].value = "";
		} 
	}
}
