//jas - this file contains code for the quickview functionality on department, deptsku, and search pages
//Note: the code has been modified from the default quickview code for specific Citysports customization

/**
 * This Quickview javascript references the following HTML which is placed on the page directly wherever this js is used. This is the 'shell' html of the quickview popup window
 * It must be on the page before quickview.js is included
 * Also note that extra code is needed to include the quickview icon on the page
 *
 * <!-- begin feature: quickview -->
 * <iframe id="qv_iframe" style="height:510px;width:400px;z-index:9999979;position:absolute;top:150px;left:200px;visibility:hidden;"></iframe>
 * <div id="qv_window" style="width:450px;height:525px;position:absolute;background:#FFFFFF;padding:8px;z-index:9999980;visibility:hidden;">
 * 	<a id="closebtn" href="javascript:void(0)" onclick="closeProd(this);" style="font-weight: bold; float: right;">close [x]</a>xxx
 * 	<br/>
 * 	<div id="qv_error" class="ErrorMsg"></div>
 * 	<div id="qv_action"></div>
 * </div>
  * <script type="text/javascript" language="javascript" src="assets/images/includes/quickview.js"></script>
 * <!-- end feature: quickview -->
 *
 *<!-- begin popup feature - this calls the quickview window to open up - put this div on each product that gets shown on the page-->
 *<!-- notice on the function calls we are sending it the pf_id of whatever product we are doing the quickview on -->
 *<div class="qv-wrapper"><img onmouseout="hideQVIcon('qvicon_PF_ID_HERE');" onclick="getProdInfo('PF_ID_HERE');" onmouseover="popQVIcon('qvicon_PF_ID_HERE');" id="qvicon_PF_ID_HERE" style="visibility: hidden;" class="qvicon" src="assets/images/qvicon.gif"/></div>
 *<!-- end popup feature -->
 * add to product thumbs
 * onmouseover="popQVIcon('qvicon_PF_ID_HERE');"
 * onmouseout="hideQVIcon('qvicon_PF_ID_HERE');"
*/

//jas - 11/11/07 modified layout for custom use on citysports
/* JAT 8/3/07 - this is a new version of quickview.js  */

var prodReq, prodObj;								// prodReq holds the request object and prodObj holds the returned json object
var isIE = ((navigator.appName) == "Microsoft Internet Explorer")? true : false;	// need this for determining popup positioning
var isIE6 = (window.ActiveXObject)? true : false;	// need this for ajax stuff and whether to display an iframe behind popup
var qvWin = document.getElementById('qv_window');
if(isIE6){var qvIFrame = document.getElementById('qv_iframe');}	// to prevent select dropdowns from bleeding through the div
var qvErr = document.getElementById('qv_error');				// holds message to user if they haven't chosen a sku from dropdown to add to basket
var qvAction = document.getElementById('qv_action');			// holds the product form and action buttons (add to cart, wish, view cart)
//var qvLoader = document.getElementById('qv_loader');			// (moosejaw specific) animated gif for loading
var winHeight = 0;

/**
 * Displays the quick view icon when user rolls over the product image
 * @param{string} pf_id is used to find the id of the quickview icon image on the page.
 **/
function popQVIcon(qv_id){
	var qvicon = document.getElementById(qv_id);
	qvicon.style.visibility = "visible";
	qvicon.style.cursor = "pointer";
	qvicon.parentNode.display = "block";
	//qvicon.parentNode.visibility = "visible";
}

/**
 * Hides the quick view icon when user rolls off the product image
 * @param{string} pf_id is used to find the id of the quickview icon image on the page.
 **/
function hideQVIcon(qv_id){
	document.getElementById(qv_id).style.visibility = "hidden";
}

/**
 * Populates and displays the quickview window for selected product
 **/
function showProd(department_id){
	
	// set "global vars" from product.js onto the json object instead
	prodObj.num_avail = false;	// make a num_avail in place of missing one

	// check if object has product info before going through all the display stuff
	if(!prodObj.pf_id){
		// in the rare case there is no product info returned - display a message to user & clear out quickview popup
		qvWin.style.height = "300px";
		if(isIE6){qvIFrame.style.height = "300px";}
		qvErr.innerHTML = "Sorry, product information is unavailable at this time.";
		return;
	}else if(prodObj.Items.length <= 0){	// if product comes back with no items
		qvWin.style.height = "300px";
		if(isIE6){qvIFrame.style.height = "300px";}
		qvErr.innerHTML = "So sorry but this product is sold out. It will be removed from the site as soon as possible. ";
		return;
	}	
	
	
	//holds the product display to be written to action div
	var actionMarkup = "";
	
	// begin form that will add product to basket
	actionMarkup += "<FORM METHOD=POST NAME=\"form2\" ACTION=\"" + i_jscript_uu_rootURL + "shopper_lookup.asp\" onsubmit=\"return checkSku();\">";
	actionMarkup += "<input type=hidden name=target id=target value=\"xt_orderform_additem.asp\">";
	actionMarkup += "<INPUT TYPE=HIDDEN NAME=\"auto_reg\" VALUE=\"1\">";
	actionMarkup += "<INPUT TYPE=HIDDEN NAME=s_id VALUE=" + i_jscript_uu_sid + " >";	
	actionMarkup += "<input type=hidden name=qty value=1>";
	if (user_guid !=' '){
		actionMarkup += "<INPUT TYPE=HIDDEN NAME=mscssid VALUE=" + user_guid + " >";
	}

	actionMarkup += "<INPUT TYPE=HIDDEN NAME=wish_id VALUE=" + GetParamterValueQv("wish_id") + " >";
	actionMarkup += "<INPUT TYPE=HIDDEN NAME=order_sid VALUE=" + GetParamterValueQv("order_sid") + " >";
	actionMarkup += "<INPUT TYPE=HIDDEN NAME=so_number VALUE=" + GetParamterValueQv("so_number") + " >";
	actionMarkup += "<INPUT TYPE=HIDDEN NAME=pf_id VALUE=" + prodObj.pf_id + " >";
	
	//if(dept_id){actionMarkup += "<INPUT TYPE=HIDDEN NAME=dept_id VALUE=" + dept_id + " >";}
	
	//actionMarkup += "<INPUT TYPE=HIDDEN Name=returnpath Value=\""+document.location.pathname+document.location.search+"&addfrom=qv\" >";
	
	actionMarkup += '<table width="380" border="0" cellspacing="0" cellpadding="0">';
		//product name
		actionMarkup += '<tr><td valign="top"><FONT class="ProductName">'+prodObj.name+'</FONT></td>';
		//display price
		// check onsale flag to see if sale price should be displayed.		
		actionMarkup += '<td valign="top" align="right">';
		
		//actionMarkup += ( prodObj.on_sale == "true") ? "<font class='ListPricewoSale'>Regular Price&nbsp;"+prodObj.list_price_str+"</font><br><font class='SalePrice'>Sale&nbsp;"+prodObj.sale_price_str+"</font>" : "<font class='ListPricewoSale'>Price&nbsp;"+prodObj.list_price_str+"</font>";		
		actionMarkup += '</td></tr>';
		
		actionMarkup += '<tr><td colspan="2" class="product_top_spacer">&nbsp;</td></tr>';		
		//display sku and qty dropdowns		 
		actionMarkup += '<tr><td>'+draw_sku_option_qv()+'</td><td align="right">';
	
		// add to cart button
		if (prodObj.enable_basket==1 && prodObj.num_avail){
			//actionMarkup += '<INPUT TYPE=Image NAME="pbasket" SRC="assets/images/btnaddtocart.gif" BORDER=0 ALT="Add to your shopping cart">';
			actionMarkup += ( prodObj.on_sale == "true") ? "<font class='ListPricewoSale'>Regular Price&nbsp;"+prodObj.list_price_str+"</font><br><font class='SalePrice'>Sale&nbsp;"+prodObj.sale_price_str+"</font>" : "<font class='ListPricewoSale'>Price&nbsp;"+prodObj.list_price_str+"</font>";
		}
		actionMarkup += '</td></tr>';
		
		actionMarkup += '<tr><td colspan="2" align="center">';
		//display image with link to product
		// create main image
		//jas - added code to display department_id and dl_id in the querystring
		if(department_id)
		{
			if(ptargetc){
				if(ptargetc.indexOf("dl_id")!=-1)
				{
					var the_dl_id = ptargetc.substr(ptargetc.indexOf("dl_id"));
					actionMarkup += "<br><a href=\"product.asp?pf_id=" + prodObj.pf_id + "&dept_id="+department_id + "&"+the_dl_id+ "\" onclick=\"return(visitargs('product.asp','pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&"+the_dl_id+"','URL'));\">";
					actionMarkup += "<img id='prod_img' BORDER=0  VSPACE=0  HSPACE=0 ALT=\"" + prodObj.name + "\" title=\"" + prodObj.name + "\" src=\"assets/product_images/" + prodObj.image_2_file+"\" onError=\"this.src='assets/images/coming_soon.jpg';\"></a><br><br>";	
					actionMarkup += '</td></tr>';
					actionMarkup += '<tr><td colspan="2" align="center">';
					actionMarkup += "<a href=\"product.asp?pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&"+the_dl_id+"\" onclick=\"return(visitargs('product.asp','pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&"+the_dl_id+"','URL'));\"><img src=\"assets/images/btndetails.gif\" alt=\"Product Details\" title=\"Product Details\" border=\"0\"></a>";	
				}
				else
				{
					actionMarkup += "<br><a href=\"product.asp?pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&\" onclick=\"return(visitargs('product.asp','pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&','URL'));\">";
					actionMarkup += "<img id='prod_img' BORDER=0  VSPACE=0  HSPACE=0 ALT=\"" + prodObj.name + "\" title=\"" + prodObj.name + "\" src=\"assets/product_images/" + prodObj.image_2_file+"\" onError=\"this.src='assets/images/coming_soon.jpg';\"></a><br><br>";	
					actionMarkup += '</td></tr>';
					actionMarkup += '<tr><td colspan="2" align="center">';
					actionMarkup += "<a href=\"product.asp?pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&\" onclick=\"return(visitargs('product.asp','pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&','URL'));\"><img src=\"assets/images/btndetails.gif\" alt=\"Product Details\" title=\"Product Details\" border=\"0\"></a>";	
				}
			}else{
				actionMarkup += "<br><a href=\"product.asp?pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&\" onclick=\"return(visitargs('product.asp','pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&','URL'));\">";
				actionMarkup += "<img id='prod_img' BORDER=0  VSPACE=0  HSPACE=0 ALT=\"" + prodObj.name + "\" title=\"" + prodObj.name + "\" src=\"assets/product_images/" + prodObj.image_2_file+"\" onError=\"this.src='assets/images/coming_soon.jpg';\"></a><br><br>";	
				actionMarkup += '</td></tr>';
				actionMarkup += '<tr><td colspan="2" align="center">';
				actionMarkup += "<a href=\"product.asp?pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&\" onclick=\"return(visitargs('product.asp','pf_id=" + prodObj.pf_id + "&dept_id="+department_id+"&','URL'));\"><img src=\"assets/images/btndetails.gif\" alt=\"Product Details\" title=\"Product Details\" border=\"0\"></a>";	
			}
		}
		else
		{
			actionMarkup += "<br><a href=\"product.asp?pf_id=" + prodObj.pf_id + "&\" onclick=\"return(visitargs('product.asp','pf_id=" + prodObj.pf_id + "&','URL'));\">";
			actionMarkup += "<img id='prod_img' BORDER=0  VSPACE=0  HSPACE=0 ALT=\"" + prodObj.name + "\" title=\"" + prodObj.name + "\" src=\"assets/product_images/" + prodObj.image_2_file+"\" onError=\"this.src='assets/images/coming_soon.jpg';\"></a><br><br>";	
			actionMarkup += '</td></tr>';
			actionMarkup += '<tr><td colspan="2" align="center">';
			actionMarkup += "<a href=\"product.asp?pf_id=" + prodObj.pf_id +"&\" onclick=\"return(visitargs('product.asp','pf_id=" + prodObj.pf_id +"&','URL'));\"><img src=\"assets/images/btndetails.gif\" alt=\"Product Details\" title=\"Product Details\" border=\"0\"></a>";	
		}
		
		//buttons
		if (prodObj.enable_wish==1 && prodObj.num_avail){		// add to wish basket button
			 actionMarkup += '<INPUT TYPE=Image  NAME="wbasket" SRC="assets/images/btnaddwish2.gif" BORDER=0 ALT="Add to your wish cart" onclick="addto=4;">';
		}
		if (prodObj.enable_basket==1 && prodObj.num_avail){		// add to cart button
			actionMarkup += '<INPUT TYPE=Image  NAME="pbasket" SRC="assets/images/btnaddtocart.gif" BORDER=0 ALT="Add to your shopping cart">';
		}
		//actionMarkup += "<a href=\"javascript:shareproduct('share_new.asp','none','SURL','"+prodObj.pf_id+"','"+prodObj.image_file+"','"+escape(prodObj.name)+"');\"><img src=\"assets/images/btnemlfriend.jpg\" alt=\"Email This to a Friend\" border=\"0\"></a>";
		actionMarkup += '</td></tr>';				
		
		actionMarkup += '</table>';
	
	actionMarkup += "</FORM><br class='clear'>";// end the form

	qvAction.innerHTML = actionMarkup;	// put form, add to cart, add to wish basket, view cart buttons inside div
	
	winHeight = 600;
	//make height 215 + height of image
	if(document.getElementById("prod_img"))
	{
		var img = document.getElementById("prod_img");
		winHeight = img.height + 215;
	}
	
	// re-set the popup's height
	//winHeight = (prodObj.name.length > 60)? 580 : 560;	// change height of main popup window if product title goes to a second line
	//winHeight += ((qvPrice.innerHTML).indexOf('-') > -1)? 15 : 0;	// add 10 px if price is too long for one line
	qvWin.style.height = winHeight + "px";
	qvWin.style.height = "auto";
	if(isIE6){	// make iframe visible if IE
		//qvIFrame.style.height = winHeight + "px";
		qvIFrame.style.height = (winHeight-50) +"px";
		//qvIFrame.style.left = ((document.body.clientWidth / 2) - 235) + "px";
		//qvIFrame.style.top = (document.documentElement.scrollTop + 50) + "px";
		qvIFrame.style.display = "block";
		qvIFrame.style.visibility = "visible";
		qvIFrame.style.zIndex = "9999979";
	}

	//qvLoader.style.display = "none";	// hide loader animation	
	qvWin.style.visibility = "visible";	// finally display the product quickview popup on the page
}


/**
 * Calls the ajax request for product data
 * @param{string} pf_id is sent in the POST to specify which product's data we're requesting
 **/
function getProdInfo(pf_id,department_id){
	if(qvWin.style.visibility == "visible"){closeProd(qvWin.firstChild);}
	// set the popup positioning
	if(isIE6){		// ie6
		qvIFrame.style.left = ((document.body.clientWidth / 2) - 235) + "px";
		qvIFrame.style.top = (document.documentElement.scrollTop + 50) + "px";
		qvWin.style.left = qvIFrame.style.left;
		qvWin.style.top = qvIFrame.style.top;
	}else if(isIE){	// ie7
		qvWin.style.left = ((document.body.clientWidth / 2) - 235) + "px";
		qvWin.style.top = (document.body.scrollTop + 50) + "px";
	}else{			// ff + others
		qvWin.style.left = ((document.body.scrollWidth / 2) - 235) + "px";
		qvWin.style.top = (window.pageYOffset + 50) + "px";
	}

	// display the popup window with a 'loading' message to user until the product info has been loaded
	//qvLoader.style.display = "block";
	qvWin.style.visibility = "visible";
	if(isIE6){qvIFrame.style.display = "block";}

	if (!isIE6) { // iIE7, Mozilla, Safari, ...
		prodReq = new XMLHttpRequest();
		isIE6 = false;
	} else{ // IE6, below
		prodReq = new ActiveXObject("Microsoft.XMLHTTP");
		isIE6 = true;
	}

	/* determine page protocol */  
	var myTemp = window.location.href;  
	var tempSplit = myTemp.split(":");  
	var pageProt = tempSplit[0];  
	  
	/* determine correct path to use based on protocol (http vs https)  */  
	switch (pageProt)  {  
	  case "http":  
	    prodReq.open('GET', i_jscript_uu_rootURL+'product_json.asp?pf_id='+pf_id, true);
	    break;  
	  case "https":  
	    prodReq.open('GET', i_jscript_uu_rootSURL+'product_json.asp?pf_id='+pf_id, true);
	    break;  
	}

	prodReq.setRequestHeader('Content-type', 'application/xml');
	prodReq.onreadystatechange = function(){productCallback(department_id);}	// specify our callback function
	prodReq.send(null);
}

/**
 * Callback function called in getProdInfo, catches errors or bad statuses that may be returned
 **/
function productCallback(department_id){
	try{
		if(prodReq.readyState == 4){	// 4 = complete
			prodObj = eval('(' + prodReq.responseText + ')');	// parse returned json object for our javascript to read
			showProd(department_id);	// call functino to display product /quickview window
			if (prodReq.status !=200) {
				alert('status != 200');
				return;
			}
		}
		else {
			// So IE won't throw an error
			return;
		}
	}catch(e){
		// improperly formed json
	}

}

/**
 * Closes and clears out the product quickview window
 **/
function closeProd(win){
	// clear out divs
	qvErr.style.visibility = "hidden";	
	qvAction.innerHTML = "";	
	win.parentNode.style.visibility = "hidden";		// hide quickview popup
	if(qvIFrame){qvIFrame.style.display = "none";}	// hide iframe
}

/**
 * make sure a product sku has been selected from dropdown before adding to basket
 * @param{boolean} onchange is a flag that is set to true if being called from the sku dropdown onchange event
 */
function checkSku(onchangeFlag){
	var skuSelect;
	if(document.getElementById('sku')){skuSelect = document.getElementById('sku');}	// only grab the sku select dropdown if it exists on the page

	if(onchangeFlag){	// only do this stuff if being called from the select box onchange
		if(skuSelect.value != ""){
			qvErr.style.display = "none";
		}
		return;
	}else{
		if(skuSelect){
			if(skuSelect.value == ""){	// only do this stuff if being called from the form2 onsubmit
				qvErr.style.display = "block";
				//qvWin.style.height = (winHeight + 40) + "px";
				return false;
			}else{
				//jas - added code to redirect through shopper lookup when adding to wishlist
				if (addto==4){go_thru_shopper_lookup(skuSelect.value);return false;}
				else
				{
					qvErr.style.display = "none";
					return true;
				}
			}
		}else{
			// if there is no sku select
			qvErr.style.display = "none";
			return false;
		}
	}
}


/* draws the sku dropdown */
/**
 * Returns true if 'e' is contained in the array 'a'
 * @author Johan Känngård, http://dev.kanngard.net
 */
function contains(a, e) {
	if(a!=null)
		for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}

function draw_sku_option_qv()
{	
	// set differences in vars		
	var product_var = prodObj.Items;
	
	var attr_label = new Array();
	attr_label[0] = prodObj.attr_label1;
	attr_label[1] = prodObj.attr_label2;	
	
	var skuMarkup = "";
	var num_avail = 0;
	var dropdownattr1 = "";
	var attrname = "";
	var dropdown_label="";	
	if (product_var.length >= 1 ){
		prodObj.num_avail = true;
		if(product_var.length==1){
			skuMarkup += "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>";
			skuMarkup += "<TR VALIGN=middle ><TD class=ProductAttrlabel >" + attr_label[0] + " </TD><TD>";
			if (product_var[0].avail != "0") {
				num_avail=1;
				skuMarkup += "&nbsp;" + product_var[0].attr_value1;
			} else 
			{
				skuMarkup += "<BR>So sorry but this product is not available.";
			
			}
			skuMarkup += "<INPUT TYPE=HIDDEN  NAME=sku ID=sku VALUE=\"" + product_var[0].sku + "\" >";
			skuMarkup += "</td></TR></TABLE>";
		}
		else
		{	
			skuMarkup += "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>";
	
			i=attr_label.length-1;
			labelstr="";
			while (attr_label[i]!= "" && i >=0 ) {
			labelstr=labelstr + attr_label[i] + " ";
			i=i-1;
			}
			product_var.sort(UUSort);
			//writeoption_qv("",labelstr ,sel_values[0]);
			for (atn=0;atn< product_var.length ;atn++){
				if (product_var[atn].avail != "0") {
				  if (num_avail == 0){
				    skuMarkup += "<TR VALIGN=middle><TD class=ProductAttrlabel>Size&nbsp;</TD><TD>";
				    skuMarkup += "<div id=ddDiv><SELECT class=ProductAttr NAME='sku' id='sku' >";
				  }
				  if (prodObj.useVariantPrice=="True"){
				    if (prodObj.on_sale=="True"){
				      skuMarkup +=writeoption_qv(product_var[atn].sku,(product_var[atn].attr_value2 + " - " + product_var[atn].attr_value1 + " $"+ OKStrOfPenny(product_var[atn].price_sale)+"&nbsp;") ,'');
				    } else {
				      skuMarkup +=writeoption_qv(product_var[atn].sku,(product_var[atn].attr_value2 + " - " + product_var[atn].attr_value1 + " $"+ OKStrOfPenny(product_var[atn].price_list)+"&nbsp;") ,'');
				    }
				  } else {
				    skuMarkup +=writeoption_qv(product_var[atn].sku,(product_var[atn].attr_value2 + " - " + product_var[atn].attr_value1+"&nbsp;") ,'');
				  }
				  num_avail++;
				}
			}//end for
			if (num_avail > 0){
			  skuMarkup += "</SELECT></div></TD><td class=ProductAttrlabel>&nbsp;Qty&nbsp;</td><td><div id=ddDiv><SELECT class=ProductAttr NAME='qty' id='qty'>";
			for(na=1;na<=5;na++){skuMarkup += "<option value=\""+na+"\">"+na+"&nbsp;</option>";}
			  skuMarkup += "</select></div></td>";
			}else{
			  skuMarkup += "<TR VALIGN=TOP><TD class=ProductAttrlabel><BR>So sorry but this product is not available.</td>";
			}
			skuMarkup += "</TR></TABLE>";
		}
	}
	
	return skuMarkup;
	
} //end draw_sku_option

function writeoption_qv(option,display,select){
	var optMarkup = "";
	if (select==option){selected=" SELECTED";}else{selected="";}
	option=String(option);
	option=option.replace(/'/g,"&#39;");
	optMarkup += "<OPTION Value='"+option+"'"+ selected +">"+ display + "</option>";
	return optMarkup;
}

function GetParamterValueQv(ParameterName)
{
var EQUAL = "=";
var AMP = "&";
var QUE = "?";
var EMPTY = "";
var url = window.document.URL.toString();
if (url.indexOf(QUE) > 0 ) {
var Parameters = url.split(QUE)[1].split(AMP);

	for (i = 0; i < Parameters.length; i++ ){
		if (Parameters[i].indexOf(EQUAL) > 0 ){
		var ParameterValue = Parameters[i].split(EQUAL);

		if (ParameterValue[0]== ParameterName ) {
		return ParameterValue[1];
		}
		}
	}
}
return EMPTY;
}

/* draws quick view icon on search thumbnail
*/
function draw_search_qv(product_pfid)
{
	document.write("<div class=\"qv-wrapper\">");
	document.write("<img src=\"assets/images/qvicon.gif\" class=\"qvicon\" style=\"visibility:hidden;\" ");
	if(window.XMLHttpRequest){document.write("style=\"left:0px;\" ");}	// add in an ie7 hack
	document.write("id=\"qvicon_" + product_pfid  + "\" ");
	document.write("onmouseover=\"popQVIcon('qvicon_" + product_pfid  + "');\" ");
	document.write("onclick=\"getProdInfo('" +  product_pfid + "');\" ");
	document.write("onmouseout=\"hideQVIcon('qvicon_" + product_pfid  + "');\" /></div>");
}

/* draws quick view icon on dept thumbnail
jas - added product_identifier (of dept_id) for multiple instances of the same product (attached to different depts) appearing on deptksu page
*/
function draw_dept_qv(product_pfid,product_identifier)
{
	document.write("<div class=\"qv-wrapper\">");
	document.write("<img src=\"assets/images/qvicon.gif\" class=\"qvicon\" style=\"visibility:hidden;\" ");
	if(window.XMLHttpRequest){document.write("style=\"left:0px;\" ");}	// add in an ie7 hack
	document.write("id=\"qvicon_" + product_pfid  + "_"+product_identifier +"\" ");
	document.write("onmouseover=\"popQVIcon('qvicon_" + product_pfid  + "_"+product_identifier + "','"+product_identifier+"');\" ");
	document.write("onclick=\"getProdInfo('" +  product_pfid + "','"+product_identifier+"');\" ");
	document.write("onmouseout=\"hideQVIcon('qvicon_" + product_pfid  +  "_"+product_identifier + "');\" /></div>");
}



/* function called to share product with a friend*/
function shareproduct(PageURL,args,SURL,apf_id,aimage,aproduct_name)
{
	if(typeof apf_id == "undefined") apf_id = pf_id;
	if(typeof aimage == "undefined" && product_image[0].image) aimage = product_image[0].image;
	if(typeof aproduct_name == "undefined") aproduct_name = product_name;
	
	var plink;
	var emailbody;
	var url;
	if (args.indexOf("=")<0 ||args.indexOf("&")<0 ){
		args="";
	}
	if (user_guid !=' ')
	{		
		PageURL =PageURL + '?mscssid='+ user_guid+ '&pf_id='+apf_id+ '&'+ args ;
	}else{
		PageURL =PageURL + '?pf_id='+apf_id+ '&'+ args ;
	}
	
	plink=i_jscript_uu_rootURL+"product.asp?pf_id="+ apf_id +"&" ;
	emailbody="Dear #RecipientName#,<BR> #Text_field_3# <BR><BR>";
	if (aimage!=""){
		emailbody = emailbody + "<A HREF=\"#URL#\" ><img src=\""+i_jscript_uu_rootURL+"assets/product_images/"+aimage+"\" border=0 alt=\""+ aproduct_name+"\" ></a>" ;
	}
	emailbody = emailbody + "<A HREF=\"#URL#\" >"+ aproduct_name + "</a><BR>" ;
	emailbody = emailbody + "from #FromName# at <A href=\"mailto:#FromEmail#\">#FromEmail# <BR>" ;
	window.location=PageURL +"referer="+escape(plink)+"&email_body="+escape(emailbody)+"&target="+ escape(window.location.href)+"&";
	//Note: This return is required as well
	// false tells the browser to ignore the default action entirely
	//usage Click Here II
	return(false);
} //end shareproduct

//jas - added sorting code from uu_sort.js
//begin sorting functions
var sizelist = ",1,2,3,4,4 1/8,4 1/4,4 3/8,4 1/2,4 5/8,5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,14,15,16,30,32,34,35,36,38,40,xxxs,xxs,xs,s,m,l,xl,xxl,xxxl,XXS,XS,XS/S,SMALL,S/M,MEDIUM,M/L,LARGE,L/XL,XL,XL/XXL,XXL,XXXL,";

function sizechart(x){return sizelist.indexOf("," + String(x) + ",");}

function numsubstr(fs){
	var not_done = true;
	var i=1;
	var t=fs.charAt(0);
	while ((not_done) && (fs.length >= i)){
		if (isNaN(t+fs.charAt(i))){not_done = false;}else{t=t+fs.charAt(i);}
		i++;
	}
	if (isNaN(t)){t=0;}  //if, for some reason, there is no integer at all, make it a zero.
	return t;
}

function smart_sort(a,b){
	var inda=sizelist.indexOf(a);
	var indb=sizelist.indexOf(b);
	if ((inda >= 0) || (indb >= 0)){
		if((inda >= 0) && (indb >= 0)){
			if (sizechart(a)>=sizechart(b)){return 1;}else{return -1;}
		}else{
			if(inda >= 0){
				if(isNaN(b)){return -1;}else{return 1;}
			}else{
				if(isNaN(a)){return 1;}else{return -1;}
			}
		}
	}else{
		if (isNaN(a) || isNaN(b)){
			if (a>=b){return 1;}else{return -1;}
		}else{
			if (parseInt(a)>=parseInt(b)){return 1;}else{return -1;}
		}
	}
}

function sizechart_sort(r,s){if (parseInt(sizechart(r))>=parseInt(sizechart(s))){return 1;}else{return -1;}}

function float_sort(p,q){
	var flt1, flt2;
	if (isNaN(p)){flt1=numsubstr(p);}else{flt1=p;}
	if (isNaN(q)){flt2=numsubstr(q);}else{flt2=q;}
	if (parseFloat(flt1)>=parseFloat(flt2)){return 1;}else{return -1;}
}

function integer_sort(m,n){
	var int1, int2;
	if (isNaN(m)){int1=numsubstr(m);}else{int1=m;}
	if (isNaN(n)){int2=numsubstr(n);}else{int2=n;}
	if (parseInt(int1)>=parseInt(int2)){return 1;}else{return -1;}
}

function string_sort(j,k){if (j>=k){return 1;}else{return -1;}}

function double_sort(a1,b1,a2,b2){
	var intval = 1; //intval is the value to be returned.  It starts at 1 and is only changed if a is NOT greater than b.
	//If a1 equals b1 then look at a2 & b2.  Otherwise look at a1&b1.
	if(a1==b1){
		//a1=b1, so look at a2<>b2
		
		//SECOND TERM SORT:
		intval = smart_sort(a2,b2);
	}else{
		//a1&b1 are different, if b1>a1 then make intval=-1.
		
		//FIRST TERM SORT:3

		intval = smart_sort(a1,b1);
	}
	return intval;
}

function UUSort(a,b){return double_sort(a.attr_value1,b.attr_value1,a.attr_value2,b.attr_value2);}

//end sorting functions

//jas - redirects wish basket to shopper lookup first (to make user log in or create account before adding to wishlist)
function go_thru_shopper_lookup(selectedsku)
{
	visitargs('shopper_lookup.asp','target=xt_orderform_additem.asp&addto=4&pf_id='+prodObj.pf_id+'&sku='+selectedsku+'&attr_value1='+prodObj.attr_label1+'&attr_value2='+prodObj.attr_label2+'&attr_value3='+prodObj.attr_label3+'&attr_value4='+prodObj.attr_label4+'&attr_value5='+prodObj.attr_label5+'&','');
}