function PopUpSized(url, wname, width, height, xpos, ypos)
{
	var newWind = window.open(url, wname, "menubar=0,location=1,status=1,resizable=1,scrollbars=1,width=" + width + ",height=" + height +",left=" + xpos + ",top=" + ypos)
	if (newWind.opener == null) {
		newWind.opener = self
	}
}


// OpenWindow() - Generic open window function ...

function OpenWindow(winName, urlLoc, w, h, showStatus, isViewer, needsNav) {
	l = (screen.availWidth - w)/2;
	t = (screen.availHeight - h)/2;
	features  = "toolbar=" + (needsNav?"yes":"no");   // yes|no 
	features += ",location=no";    // yes|no 
	features += ",directories=no"; // yes|no 
	features += ",status=" + (showStatus?"yes":"no");  // yes|no 
	features += ",menubar=no";     // yes|no 
	features += ",scrollbars=" + (isViewer?"yes":"no");   // auto|yes|no 
	features += ",resizable=" + (isViewer?"yes":"no");   // yes|no 
	features += ",dependent";      // close the parent, close the popup, omit if you want otherwise 
	features += ",height=" + h;
	features += ",width=" + w;
	features += ",left=" + l;
	features += ",top=" + t;
	winName = winName.replace(/[^a-z]/gi,"_");
	window.open(urlLoc,winName,features);
	return;
} 

// Go() - Allows a link to be used as a form button ...

function Go(action) {
	document.forms.frmMain.Action.value = action
	document.forms.frmMain.submit();	
}

// GoForm() - Like Go() but allows specification of the form name ...

function GoForm(form, action) {
	eval("document.forms." + form + ".Action.value = action")
	eval("document.forms." + form + ".submit()")
}

// GoFormTxt() - Like Go() but allows specification of the form name ...

function GoFormTxt(form, action) {
	eval("document.forms." + form + ".txtAction.value = action")
	eval("document.forms." + form + ".submit()")
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

//--------------------------------------------------//
//		CHOOSERS									//
//--------------------------------------------------//

function setField(strFieldID,strValue) {
	for (var i=0;i<document.getElementById(strFieldID).options.length;i++) {
		if (document.getElementById(strFieldID).options[i].value == strValue) {
			document.getElementById(strFieldID).selectedIndex = i;
		}
	}
/*	document.getElementById("ChooserPopup").style.display = "none";
	document.getElementById("ChooserPopupShadow").style.display = "none";
	document.getElementById("Chooserie6Fix").style.display = "none";*/
	tb_remove();
	/*document.getElementById("mokumePopupTop").style.display = "none";
	document.getElementById("mokumePopupBottom").style.display = "none";*/
}
function closeOptions() {
	document.getElementById("ChooserPopup").style.display = "none";
	document.getElementById("ChooserPopupShadow").style.display = "none";
	document.getElementById("Chooserie6Fix").style.display = "none";
}
function MokumeChooser(strDropDown) {
	var strMokumeChooserHTML = "<p>Options</p><p class=\"CloseButton\"><a href=\"javascript:closeOptions()\"><img src=\"images/popup-choice-close-btn.gif\" alt=\"Close\" width=\"14\" height=\"22\" border=\"0\" /></a></p>";
	for (var i=1;i<document.getElementById(strDropDown).options.length;i++) {
/*		strMokumeChooserHTML += "";
		strMokumeChooserHTML += "  <div class=\"mokumeRow\">\n";
		strMokumeChooserHTML += "    <div class=\"mokumeImage\"><a href=\"javascript:setField('" + strDropDown + "','" + document.getElementById(strDropDown).options[i].value + "')\"><img src=\"/images/mokumeChooser/" + document.getElementById(strDropDown).options[i].title + "\" width=\"30\" height=\"30\" alt=\"\"></a></div>\n";
		strMokumeChooserHTML += "    <div class=\"mokumeDescription\"><a href=\"javascript:setField('" + strDropDown + "','" + document.getElementById(strDropDown).options[i].value + "')\">" + document.getElementById(strDropDown).options[i].text + "</a></div>\n";
		strMokumeChooserHTML += "  </div>\n";*/
		strMokumeChooserHTML += "<div class=\"Choice\">\n";
		strMokumeChooserHTML += "<a class=\"ChoiceImage\" href=\"javascript:setField('" + strDropDown + "','" + document.getElementById(strDropDown).options[i].value + "')\"><img src=\"/images/mokumeChooser/" + document.getElementById(strDropDown).options[i].title + "\" alt=\"\"></a>\n";
		strMokumeChooserHTML += "<a class=\"ChoiceText\" href=\"javascript:setField('" + strDropDown + "','" + document.getElementById(strDropDown).options[i].value + "')\">" + document.getElementById(strDropDown).options[i].text + "</a></div>\n";
	}
	var arrPos = findPos(document.getElementById(strDropDown));
	document.getElementById("ChooserPopup").innerHTML = strMokumeChooserHTML;
	var arrDivs = document.getElementById("ChooserPopup").getElementsByTagName("div");
	for (var j=0;j<arrDivs.length;j++) {
		arrDivs[j].onmouseover = function() {
			this.style.backgroundPosition = "0px -48px";
		}
		arrDivs[j].onmouseout = function() {
			this.style.backgroundPosition = "0px 0px";
		}
	}
	//document.getElementById("mokumePopupTopContent").innerHTML = strMokumeChooserHTML;
	/*document.getElementById("mokumePopupTop").style.left = (arrPos[0]+220) + "px";
	document.getElementById("mokumePopupTop").style.top = "60px";
	document.getElementById("mokumePopupBottom").style.left = (arrPos[0]+225) + "px";
	document.getElementById("mokumePopupBottom").style.top = "65px";
	document.getElementById("mokumePopupTop").style.display = "block";
	document.getElementById("mokumePopupBottom").style.height = (document.getElementById("mokumePopupTop").offsetHeight-2) + "px";
	document.getElementById("mokumePopupBottom").style.display = "block";*/
	document.getElementById("ChooserPopup").style.left = (arrPos[0]+100) + "px";
	document.getElementById("ChooserPopup").style.top = "60px";
	
	document.getElementById("ChooserPopupShadow").style.top = "65px";
	document.getElementById("ChooserPopup").style.display = "block";
	document.getElementById("ChooserPopupShadow").style.left = (arrPos[0]+105) + "px";
	document.getElementById("ChooserPopupShadow").style.height = (document.getElementById("ChooserPopup").offsetHeight-14) + "px";
	document.getElementById("ChooserPopupShadow").style.display = "block";
	
	document.getElementById("Chooserie6Fix").style.left = (arrPos[0]+110) + "px";
	document.getElementById("Chooserie6Fix").style.top = "70px";
	document.getElementById("Chooserie6Fix").style.height = (document.getElementById("ChooserPopup").offsetHeight-0) + "px";
	document.getElementById("Chooserie6Fix").style.display = "block";
}


function MokumeChooserRing(strDropDown) {
	var strMokumeChooserHTML = "<div class=\"title-controls\"><p>Options</p><p class=\"CloseButton\"><a href=\"javascript:closeOptions()\"><img src=\"images/popup-choice-close-btn.gif\" alt=\"Close\" width=\"14\" height=\"22\" border=\"0\" /></a></p></div>\n";
	strMokumeChooserHTML += "<div class=\"column-titles\">\n";
	strMokumeChooserHTML += "  <div class=\"title\">Gray</div>\n";
	strMokumeChooserHTML += "  <div class=\"title\">Red</div>\n";
	strMokumeChooserHTML += "  <div class=\"title\">Yellow</div>\n";
	strMokumeChooserHTML += "</div>";
	strMokumeChooserHTML += "<div class=\"options-list\">";
	strMokumeChooserHTML += "<div class=\"content\">";
	var arrOptionValues = new Array();
	for (var i=1;i<document.getElementById(strDropDown).options.length;i++) {
		var intTemp = arrOptionValues.length;
		arrOptionValues[intTemp] = [document.getElementById(strDropDown).options[i].text,document.getElementById(strDropDown).options[i].value,document.getElementById(strDropDown).options[i].title];
	}
	arrOptionValues = arrOptionValues.sort();
	var strCurAlpha = arrOptionValues[0][0].split(" - ")[0];
	var strTempAlpha = strCurAlpha;
	strMokumeChooserHTML += "<div class=\"option-row\">\n";
	strMokumeChooserHTML += "<div class=\"option-row-title\">" + strTempAlpha + "</div>\n";
	for (var i=0;i<arrOptionValues.length;i++) {
		strTempAlpha = arrOptionValues[i][0].split(" - ")[0];
		if (strTempAlpha != strCurAlpha) {
			strMokumeChooserHTML += "</div>\n";
			strMokumeChooserHTML += "<div class=\"option-row\">\n";
			strMokumeChooserHTML += "<div class=\"option-row-title\">" + strTempAlpha + "</div>\n";
			strCurAlpha = strTempAlpha;
		}
		strMokumeChooserHTML += "<div class=\"option-item\">";
		strMokumeChooserHTML += "<a href=\"javascript:setField('" + strDropDown + "','" + arrOptionValues[i][1] + "')\"><img src=\"/images/mokumeChooser/" + arrOptionValues[i][2] + "\" alt=\"\"></a>";
		strMokumeChooserHTML += "</div>\n";
	}
	strMokumeChooserHTML += "</div>";
	strMokumeChooserHTML += "</div>";
	strMokumeChooserHTML += "</div>";
	var arrPos = findPos(document.getElementById(strDropDown));
	document.getElementById("ChooserPopup").innerHTML = strMokumeChooserHTML;
	var arrDivs = document.getElementById("ChooserPopup").getElementsByTagName("div");
	for (var j=0;j<arrDivs.length;j++) {
		arrDivs[j].onmouseover = function() {
			this.style.backgroundPosition = "0px -48px";
		}
		arrDivs[j].onmouseout = function() {
			this.style.backgroundPosition = "0px 0px";
		}
	}
	document.getElementById("ChooserPopup").style.left = (arrPos[0]+100) + "px";
	document.getElementById("ChooserPopup").style.top = "60px";
	document.getElementById("ChooserPopupShadow").style.top = "65px";
	document.getElementById("ChooserPopup").style.display = "block";
	document.getElementById("ChooserPopupShadow").style.left = (arrPos[0]+105) + "px";
	document.getElementById("ChooserPopupShadow").style.height = "400px";
	document.getElementById("ChooserPopupShadow").style.display = "block";
	document.getElementById("Chooserie6Fix").style.left = (arrPos[0]+110) + "px";
	document.getElementById("Chooserie6Fix").style.top = "70px";
	document.getElementById("Chooserie6Fix").style.height = "400px";
	document.getElementById("Chooserie6Fix").style.display = "block";
}

function DisplayHelp(linkClicked) {
	var arrPos = findPos(document.getElementById(linkClicked));
	var h, w;
	h = 300;	//offset height
	w = 200;	//offset width
	
	var framewidth, frameHeight;
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	
	var t = frameHeight/2 - h;
	var l = frameWidth/2 - w;
	
	var mcy = arrPos[1];			//if mouse click pos much farther down (below fold)
	if ((mcy - t) > h*2) t += h;	//move window down a bit
	
	document.getElementById("helpPopupTop").style.left = (l) + "px";
	document.getElementById("helpPopupTop").style.top = (t) + "px";
	document.getElementById("helpPopupBottom").style.left = (l+5) + "px";
	document.getElementById("helpPopupBottom").style.top = (t+5) + "px";
	
	document.getElementById("helpPopupTop").style.display = "block";
	document.getElementById("helpPopupBottom").style.height = (document.getElementById("helpPopupTop").offsetHeight-2) + "px";
	document.getElementById("helpPopupBottom").style.display = "block";
}
function closeHelp() {
	document.getElementById("helpPopupTop").style.display = "none";
	document.getElementById("helpPopupBottom").style.display = "none";
}
function populateChooser(strFieldID, strWindowID, strMode) {
	var arrOptionValues = new Array();
	for (var i=1;i<document.getElementById(strFieldID).options.length;i++) {
		var intTemp = arrOptionValues.length;
		var arrTemp = document.getElementById(strFieldID).options[i].text.split(" - ");
		var strTempAlpha = arrTemp[0];
		var strTempContent = arrTemp[arrTemp.length - 1];
		arrOptionValues[intTemp] = [strTempAlpha,document.getElementById(strFieldID).options[i].text,document.getElementById(strFieldID).options[i].value,document.getElementById(strFieldID).options[i].title,strTempContent];
	}
	arrOptionValues = arrOptionValues.sort();
	var strCurAlpha = arrOptionValues[0][0];
	var strTempAlpha = strCurAlpha;
	var strWindowContent = "<table id=\"mokumeTable\" border=\"0\" cellspacing=\"1\">";
	if (strMode == "roundedge") {
		strWindowContent += "<tr><th>Mokume Style</th><th>Grey Gold</th><th>Red Gold</th><th>Yellow Gold</th></tr>";
	} else {
		strWindowContent += "<tr><th>Mokume Style</th><th>&nbsp;</th></tr>";
	}
	strWindowContent += "<tr>";
	strWindowContent += "<td align=\"center\" bgcolor=\"#FFFFFF\"><strong>" + strTempAlpha + "</strong> - " + arrOptionValues[0][4] + "</td>";
	for (var i=0; i<arrOptionValues.length; i++) {
		if (strTempAlpha != arrOptionValues[i][0]) {
			strTempAlpha = arrOptionValues[i][0];
			strWindowContent += "</tr>";
			strWindowContent += "<tr>";
			if (strTempAlpha == "Z") {
				strWindowContent += "<td align=\"center\" bgcolor=\"#FFFFFF\"><strong>Solid</strong></td>";
			} else {
				strWindowContent += "<td align=\"center\" bgcolor=\"#FFFFFF\"><strong>" + strTempAlpha + "</strong> - " + arrOptionValues[i][4] + "</td>";
			}
		}
		strWindowContent += "<td align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"javascript:setField('" + strFieldID + "','" + arrOptionValues[i][2] + "')\"><img src=\"images/mokumeChooser/" + arrOptionValues[i][3] + "\" border=\"0\"></a></td>";
	}
	strWindowContent += "</tr>";
	strWindowContent += "</table>";
	document.getElementById(strWindowID).innerHTML = strWindowContent;
}
