function wishlistAdd() {
 var url = 'http://wishlist.myknobs.com/cgi-bin/wishlist.pl?action=add';
 if (check_options(document.product)) {
 document.product.action = url;
  gaTrackEvent('wishlist','add',document.location.pathname);
  document.product.submit();
 }
}

function goYahoo(dropdown) {
    var id = dropdown.options[dropdown.selectedIndex].value;
    if (id) {
    	var loc = document.location + '';
        var page = loc.indexOf('edit.store') > 0 ?
        		   '' : 'http://www.myknobs.com/';
        document.location.href = page + id + '.html';
    }
}

function MM_openBrWindow(theURL,winName,features) {
    smallWin=window.open(theURL,winName,features);
    gaTrackEvent('popup-window',winName,theURL);
}

function PrintPage()
	{
	window.name = "main";
	var page = "printable.html";
	windowprops = "height=450,width=610,left=10,top=110,"+ "scrollbars=no,menubars=no,toolbars=no,resizable=yes";
	window.open(page, "print", windowprops);
	gaTrackEvent('social','print',document.location.pathname);
	}

function tellAFriend () {
 var href=document.location.href;  
 if (href.indexOf('/g?')>-1) {
    baseRef = href.substr(href.indexOf('/g?')+3);
 } else {
   baseRef = document.location.href.substring(document.location.href.lastIndexOf("/") + 1,location.href.length);
    baseRef = baseRef.substring(0,baseRef.lastIndexOf("."));
}   
 var URL = "http://tellafriend.myknobs.com/cgi-bin/tellafriend.pl?id=" + baseRef;
    MM_openBrWindow(URL,'tellAFriend','scrollbars=no,resizable=yes,width=453,height=447,left=200,top=50');
}

function ZoomPopUp(theURL,imgHeight,imgWidth) {
if ((navigator.appVersion.indexOf("AOL") >0)) {
  var features = "scrollbars=no,resizable=no,width=" + imgWidth + ",height=" + imgHeight + ",left=200,top=30"
  MM_openBrWindow(theURL,"ZoomPopUp",features);
} else if (navigator.appVersion.indexOf("Mac") != -1) {
  var features = "scrollbars=no,resizable=no,width=" + imgWidth + ",height=" + imgHeight + ",left=200,top=30"
  MM_openBrWindow(theURL,"ZoomPopUp",features);
} else {
PopUp=window.open("","ZoomPopUp",'scrollbars=no,resizable=yes,width=600,height=600,left=200,top=30');
	PopUp.document.write ("<HTML><HEAD><TITLE>");
	PopUp.document.write ("Image Zoom");
	PopUp.document.write ("</TITLE></HEAD>");
	PopUp.document.write ("<body border=0 TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 BGCOLOR=#FFFFFF TEXT=#000000 LINK=#336699 VLINK=#336699>");
	PopUp.document.write ("<table cellpadding=0 cellspacing=0 bgcolor=#FFFFFF border=0 width=100%><tr><td background=/lib/myknobs/white.gif><img src=/lib/myknobs/white.gif width=1 height=5></td></tr></table>");
	PopUp.document.write ("<CENTER><hr width=375 size=1 color=#666666 noshade>");
	PopUp.document.write ("<A HREF='JavaScript:this.close()'><img src=/lib/myknobs/close.gif width=109 height=19 border=0 align=absmiddle></a></CENTER>");
	PopUp.document.write ("<table cellpadding=0 cellspacing=0 bgcolor=#FFFFFF border=0 width=100%><tr><td height=375>");
	PopUp.document.write ("<P ALIGN=CENTER>");
	PopUp.document.write ("<A HREF='JavaScript:this.close()'><IMG BORDER=0 HSPACE=0 VSPACE=0 SRC='");
	PopUp.document.write (theURL);
	PopUp.document.write ("'></a>");
	PopUp.document.write ("</P>");
	PopUp.document.write ("</td></tr><tr><td bgcolor=#ffffff class=tan>");
	PopUp.document.write ("<CENTER><hr width=375 size=1 color=#666666 noshade></CENTER>");
	PopUp.document.write ("</td></tr></table>");
        PopUp.document.write ("</BODY></HTML>");

	}
}

function check_options(frm) {
	 for (var x = 0; x < frm.elements.length; x++) {
		if (frm.elements[x].selectedIndex == 0) {
		  // check to see if it's a selected option
		  if(x > 0)
		  {
                        var y = frm.elements[x].name;
			y = y.replace(/^vwattr/i,"");
			y = y.replace(/_.+/,"");
		    	if(document.getElementById('fp_ma_qty_'+y))
		    	{ 
		    		if(document.getElementById('fp_ma_qty_'+y).style.display!='none')
		    		{ 
		  			alert('You must choose an option to continue');
		  			return false;				
				}
			}
		  	else
		  	{
		  		alert('You must choose an option to continue');
		  		return false;
		  	}	
		  }
		  else
		  { 
		  	alert('You must choose an option to continue');
		  	return false;
		  }
		}
	  }
  return true;

 }

function popupPage() {
	window.name = "main";
	var page = "free-shipping.html";
	windowprops = "height=470,width=450,left=200,top=30,"
	+ "scrollbars=no,menubars=no,toolbars=no,resizable=yes";

	window.open(page, "Popup", windowprops);
	gaTrackEvent('popup-window','Popup',page);
}


