
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;
i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { 

  v=args[i+2];
    if (obj.style) {
	obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
    }
    obj.visibility=v; 
  }
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM
_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
 x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_
p[j++].src=a[i];}}
}
function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features); 
  return false;
}
function popupHelp(theURL){
 return MM_openBrWindow(theURL,'help','menubar=yes,scrollbars=yes,resizable=yes,width=640,height=475');
}
function matColorPopup(theURL){
 if (document.all)
        var xMax = screen.width;
 else
        if (document.layers)
            var xMax = window.outerWidth;
	else
            var xMax = 1000;

 var xOffset = xMax - 500; 
 return MM_openBrWindow(theURL,'matColors', 'menubar=yes,scrollbars=yes,resizable=yes, width=450,height=600, screenX='+xOffset+',left='+xOffset+''); 
}

function setValueByString(jsStr) { //v2.0
for (var i = 0;  i < document.orderform.fancycut.length; i++){
	var current = document.orderform.fancycut.options[i].value;
	if (current == jsStr){ document.orderform.fancycut.selectedIndex = i;
	break;
	}
}
}

function setByString(jStr) { //v2.0
  self.opener.setValueByString(jStr);
  self.close();
}
function updateImageSrc(type, f, sku, name) {
	if (!f) f = document.forms[0];
	if (f.imgSrc) {
		var src = f.imgSrc.src;
		if (!sku) {
			if (type && type == 1 && f.bottommatcolor.selectedIndex != 0)
				sku = f.bottommatcolor.options[f.bottommatcolor.selectedIndex].value;
			else if (type && type == 2 && f.topmatcolor.selectedIndex != 0) 
				sku = f.topmatcolor.options[f.topmatcolor.selectedIndex].value;
			else sku = "";
		}
		if (!name)  {
			if (type && type == 1 && f.bottommatcolor.selectedIndex != 0) name = f.bottommatcolor.options[f.bottommatcolor.selectedIndex].text;
			else if (type && type == 2 && f.topmatcolor.selectedIndex != 0) name = f.topmatcolor.options[f.topmatcolor.selectedIndex].text;
			else name = " ";
		}
		if (hasBorders(type, f)) {
			if (src.indexOf("&mat"+type) == -1) src += ("&mat"+type+"="+sku);
			else {
				src = src.substring(0, src.indexOf("&mat"+type)+6) + sku + "&" + src.substring(src.indexOf("&mat"+type)+6);
			}
		}
		f.imgSrc.src = src;
	}
	changeHtmlString("mat"+type, name);
}
function hasBorders(type, f) {
	if (type == 1) 
		return valueOf(f.matTopI,f.matTopF) > 0 && valueOf(f.matBotI,f.matBotF) > 0 && valueOf(f.matLeftI,f.matLeftF) > 0 && valueOf(f.matRightI,f.matRightF) > 0
	else if (type == 2)  return valueOf( f.matOffI, f.matOffF ) > 0;
	else return false;
}
function valueOf(inchPop,fracPop){return inchPop.selectedIndex*8+fracPop.selectedIndex;}
function validateAndClose(ref) {
	//window.opener.document.pfsMainForm.submit();
	window.opener.location.href = ref;
	window.close();
	return false;
}
function changeHtmlString(name, value) {
    var obj = MM_findObj(name);
	if (!obj && self.opener) {
		obj = self.opener.MM_findObj(name);
	}
    if (obj && obj.innerHTML && value) obj.innerHTML = value;
}

