// Opens the coupon window

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Marty's cpshop javascript library
var popUpWin = false;
var browsertype=false;
if((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)>=3)) browsertype=true;
if((navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>=4)) browsertype=true;

function e (z, h, w, b, g) {
	document.write('<div style="width:'+w+';height:'+h+';background:white url(http://zoom.cafepress.com/'+(z%10)+'/'+z+'_zoom.jpg) no-repeat center center;"><img border="'+b+'" class="imageborder" src="/content/marketplace/img/'+(g?'zoom':'spacer')+'.gif" width="'+w+'" height="'+h+'"></div>')
}

function objectdata(hsize,vsize,hilite,original,messge)
{if(browsertype)
{       this.messge=messge;
        this.simg=new Image(hsize,vsize);
        this.simg.src=hilite;
        this.rimg=new Image(hsize,vsize);
        this.rimg.src=original;
}}

/**
 ** changeDropDownValueSelected - finds a match to newIndexValue among the option values and sets the
 **									matching value to be the selected option
 ** Params:
 ** dropDownId - id of select drop down
 ** newSelectValue - new selected option value
**/
function changeDropDownValueSelected(dropDownId, newSelectValue) {
	var selectDropDown = document.getElementById(dropDownId);
	for(i=0; i < selectDropDown.options.length; i++) {
		var optionVal = selectDropDown.options[i].value;
		if (optionVal == newSelectValue) {
			selectDropDown.options[i].selected = true;
			return;
		}
	}
}
/**
 ** sets a global variable 'thumbnailPerspective' if it exists on the page
 **/
function setThumbnailPerspective(perspectiveValue) {
	if (thumbnailPerspective != undefined) {
		thumbnailPerspective = perspectiveValue;
	}
}

/**
 ** getColorAndViewLarger - used in prod_detail pages to get the current
 ** chosen color value in the dropDown and pass this to launchHelp so that the proper
 ** colored product will be shown
 ** Params:
 ** dropDownId - id of select drop down
 ** theUrl - see launchHelp
 ** newFeatuers - see launchHelp
**/
function getColorAndViewLarger(dropDownId, theUrl, newFeatures) {
	//get value of color drop down
	var dropDown = document.getElementById(dropDownId);
	if (dropDown != undefined) {
		var colorNo = dropDown.options[dropDown.options.selectedIndex].value;
		theUrl = theUrl + '&colorNo=' + colorNo;
	}
	var appendStr = '&pr=F';
	if (thumbnailPerspective != undefined && thumbnailPerspective.toLowerCase() == 'back') {
		appendStr = '&pr=B';
	}
	theUrl = theUrl + appendStr;
	launchHelp(theUrl, newFeatures);
}
/**
 ** swapImgWithUrl() -- replaces target image src with given src string
 ** Params:
 **   ToImg - pass in the name of the target iamge
 **   NewImgUrl - pass in the new src URL to replace target image
 **/
 function swapImgWithUrl(ToImg, NewImgUrl)
 {
	if (document.images[ToImg] != undefined) {
		document.images[ToImg].src = NewImgUrl
	}
 }

/**
 ** swapImgsWithUrls() -- calls swapImgWithUrl for every element in the array
 ** Params:
 ** ToImgArray - array of target image names
 ** NewImgUrlArray - array of new src URL strings
 **/
 function swapImgsWithUrls(ToImgArray, NewImgUrlArray)
 {
	for(i=0; i < ToImgArray.length; i++) {
		swapImgWithUrl(ToImgArray[i], NewImgUrlArray[i])
	}
}
/**
 ** swapImg() -- swaps two images
 ** Params:
 **   ToImg - pass in the name of the target image
 **  FromImg - pass in the name of the original image
 **/
function swapimg(ToImg, FromImg)
{
	document.images[ToImg].src=document.images[FromImg].src
}

/**
** simulateClickSwatch -- used in prod_detail pages to simulate onclick of swatch images
** with id=imageIdPrepend_<<chosenVal in dropdown>>
** Params:
**	imageIdPrepend -- the string to prepend to the id string e.g. imageColor_
**  dropDownId -- id of the select dropDown element
**/
function simulateClickSwatch(imageIdPrepend, dropDownId) {
	var dropDown = document.getElementById(dropDownId)
	//get the value selected
	var chosenVal = dropDown.options[dropDown.options.selectedIndex].value
	var imgId = imageIdPrepend + chosenVal;
	document.getElementById(imgId).onclick();
}

function swapimg(ToImg, FromImg)
  {
    document.images[ToImg].src=document.images[FromImg].src
  }

function hilite(name)
{if(browsertype)
{//window.status=object[name].messge;
document[name].src=object[name].simg.src;}}

function original(name)
{if(browsertype)
{//window.status="";
document[name].src=object[name].rimg.src;}}

function launchHelp(newURL, newFeatures)
{
  if ((navigator.appName=='Microsoft Internet Explorer') && (window.HelpWindow)) HelpWindow.close();
  HelpWindow = open(newURL, "HelpWindow", newFeatures + ",screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,status=0,toolbar=0,scroll=1");
  if (HelpWindow.opener == null) HelpWindow.opener = window;
  HelpWindow.focus();
}

function CheckPopup() {
    if (popUpWin) {
        popUpWin.close();
    };
};


