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){
  if (theURL.href) {
    return MM_openBrWindow(theURL.href,'help_page','menubar=yes,scrollbars=yes,resizable=yes,width=640,height=475');
  } else {
    if (theURL == 'http://www.pictureframes.com/html/galleryWrap2.html') {
      //alert("We offer Gallery Wrapped Canvas");
      return MM_openBrWindow(theURL,'help','menubar=yes,scrollbars=yes,resizable=yes,width=790,height=650');
    } else {
      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 matColorPopup(theURL){
  return MM_openBrWindow(theURL,'matColors', 'menubar=yes,scrollbars=yes,resizable=yes, width=450,height=600,screenX=400,left=400');
}*/

function PF_returnToBrWindow(theUrl) {
 if (self.opener) {
  eval("self.opener.location='" + theUrl + "'");
  self.close();
 }
 else eval("blank.location='" + theUrl +"'");
 return false;

}
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 MM_jumpMenu(targ,selObj,restore){ //v3.0
	if (selObj.options[selObj.selectedIndex].value == ""){
	return;
	}
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function setByString(jStr) { //v2.0
  self.opener.setValueByString(jStr);
  self.close();
}
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 setValueOf(inchPop,fracPop,newVal){
	newVal=Math.max(newVal,0);
	inchPop.selectedIndex=Math.floor(newVal/8);
	fracPop.selectedIndex=newVal%8;
}
function hasChanged(aPopup){return !aPopup.options[aPopup.selectedIndex].defaultSelected;}
function validateAndClose(ref) {
	//window.opener.document.pfsMainForm.submit();
	window.opener.location.href = ref;
	window.close();
	return false;
}

/*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) sku = f.bottommatcolor.options[f.bottommatcolor.selectedIndex].value;
			else if (type && type == 2) sku = f.topmatcolor.options[f.topmatcolor.selectedIndex].value;
		}
		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;
		}
		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 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)) {
			// change mat sku in image url
			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);
			}
			// add mat borders to image url
			if (src.indexOf("&t=")==-1 && src.indexOf("&l=")==-1 && src.indexOf("&r=")==-1 && src.indexOf("&b=")==-1) {
				f.submit();
			}
			// set border to 0 if no mat is selected
			if (type && type == 1 && f.bottommatcolor.selectedIndex == 0) {
				setValueOf( f.matTopI, f.matTopF, 0 );setValueOf( f.matBotI,f.matBotF, 0 );
				setValueOf( f.matLeftI,f.matLeftF, 0 );setValueOf( f.matRightI,f.matRightF, 0 );
				f.topmatcolor.selectedIndex = 0
				setValueOf( f.matOffI, f.matOffF, 0 );
				f.submit();
			} else if (type && type == 2 && f.topmatcolor.selectedIndex == 0) {
				setValueOf( f.matOffI, f.matOffF, 0 );f.submit();
			}
			f.imgSrc.src = src;
		} else {
			if (type == 1) {
				setValueOf( f.matTopI, f.matTopF, 16 );setValueOf( f.matBotI,f.matBotF, 16 );
				setValueOf( f.matLeftI,f.matLeftF, 16 );setValueOf( f.matRightI,f.matRightF, 16 );
			} else if (type ==2) {
				setValueOf( f.matOffI, f.matOffF, 4 );
			}
			f.submit();
		}
		
	}
	changeHtmlString("mat"+type, name);
}

//check to see if cookies are enabled
function checkCookie(){
document.cookie="cookieTest="+"Cookies Enabled"
cookieEnabled=(document.cookie.indexOf("cookieTest")!=-1)? true : false;
if (!cookieEnabled) //if cookies are disabled on client's browser
	alert("Your computer or browser appears to be set not to accept cookies. For the best pictureframes.com shopping experience, please set your browser to accept cookies or add pictureframes.com to your list of trusted websites.");
}

function checkpbase(obj) {
      if (getCookie("pbflag")) {
	if (getCookie("pbflag").length > 0  && obj.src.indexOf("/pbaseupload/images/top.jpg")==-1) {
		if (document.getElementById('pbaseuploadCheck')) { document.location = "http://www.pbase.com/image/" + getCookie("pbflag"); }
		obj.src = "/pbaseupload/images/top.jpg";
		obj.useMap = '#PbaseMap';
		document.getElementById('Layer1').style.display= "none";
		document.getElementById('pbwelcomeLayer').style.display= "block";
		if (document.getElementById('backtopbase')) {
			 document.getElementById('backtopbase').href = "http://www.pbase.com/image/" + getCookie("pbflag");
		} 
		if (document.layers) document.layers['sideNav'].visibility="hide";
		if (document.layers) document.layers['searchTable'].visibility="hide";
		if (document.getElementById('sideNav')) { document.getElementById('sideNav').style.display= "none"; }
		if (document.getElementById('searchTable')) { document.getElementById('searchTable').style.display= "none"; }
		setCookie("wosidg", getCookie("wosid"), 1, "/", "", "");
		setCookie("instg", getCookie("woinst"), 1, "/", "", "");
	}
      }
      return;
}
function setCookie( name, value, expires, path, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ) {
     expires = expires * 1000 * 60 * 60 ;
  }

  var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
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;
}

function validate_required(elem,name)
{
  if(elem.value.length == 0)
  {
    alert(name+" is a required field.");
    return false;
  }
  return true;
}
