//array to hold all colors
var colors = new Array();
getColors();

//holds color
var qColor = "";
//see if there is a color in the querystring...
qColor = get_from_QueryString('attr_value2');

//get first color if color is NOT in QS
if(typeof qColor == "undefined" || !qColor) {
	if(colors[0])
		qColor = colors[0];
	else
		qColor ="";
}
//clean qColor
if(qColor!="")
	qColor = cleanColorName(qColor);

//array to hold all sizes having availability
var sizes = new Array();
getSizes();


function draw_leaf_tree(){

	var base_dept="3001";
	var passed_base=false;
	if ((typeof(leaf_tree)!="nothing")&&(leaf_tree.length>0)){
		for (i=leaf_tree.length-1;i>=0;i--){
			if (passed_base && leaf_tree[i].dept_name!="rti"){
				//seperator - getting here only after 2 levels deep to created bullet
				document.write("&nbsp;&gt;&nbsp;");
				//link and name
				document.write("<a href=\"" + leaf_tree[i].dept_link + "\" CLASS=\"leaftree\">" + leaf_tree[i].dept_name.toLowerCase() + "<\/a>");
			}else{
				if (leaf_tree[i].dept_id==base_dept && leaf_tree[i].dept_name=="rti"){
					passed_base=true;
					//HOME link and HOME name
					document.write("<a href=default.asp CLASS=\"leaftree\">home<\/a>");
				} //end if after else
			} //end else
		} // end for
	}// end if typeOf
	else
	{
		document.write("<img src='assets/images/spacer.gif' width='1' height='14'>");
	}
} // end function draw_leaf_tree

//this code is for an image swap
function draw_image_2(){

	if (typeof info_attributes!="undefined" && info_attributes != "" && info_attributes != "default")
	{
		document.write('<a href="javascript:void(0);" onClick="pop_alternates();return false;">');
	}
	document.write("<img name=\"mainimg\" id=\"mainimg\" ALIGN =\"" + product_image[1].align + "\" ");
	//if (product_image[1].width!=""){document.write("WIDTH =" + product_image[1].width + " ");}
	document.write("BORDER=0 ALT=\"" + product_image[1].alt_text + "\" ");
	if(qColor!="")
		document.write(" SRC=\"assets/product_images/" + pf_id + "-" + qColor +"-lg.jpg\"");
	else
		document.write(" SRC=\"assets/product_images/" + pf_id + "-lg.jpg\"");

	document.write(" onError=\"this.src='assets/product_images/Product.gif'\">");

	if (typeof info_attributes!="undefined" && info_attributes != "" && info_attributes != "default")
	{
		document.write('</a>');
	}

}

function getColors(){
	//get all colors

	//get colors from skus with availability
	for(pv in product_var) {
		if(product_var[pv].avail!='0'){
			//add color if color not already in array
			if(!contains(colors,product_var[pv].attr_value2.toLowerCase()))
				colors.push(product_var[pv].attr_value2.toLowerCase());
		}
	}

	//sort
	colors.sort(string_sort);
}

function getSizes(){
	//get all sizes

	//get sizes from skus with availability
	for(pv in product_var) {
		if(product_var[pv].avail!='0'){
			//add size if size not already in array
			if(!contains(sizes,product_var[pv].attr_value1.toLowerCase()))
				sizes.push(product_var[pv].attr_value1.toLowerCase());
		}
	}

	//sort
	sizes.sort(sizechart_sort);
}

var lastMainImg ="assets/product_images/" + pf_id + "-lg.jpg";
function imgOn(imgName) {
	lastMainImg = document.getElementById("mainimg").src;
	if(imgName!="")
		document.getElementById("mainimg").src="assets/product_images/" + pf_id + "-" + cleanColorName(imgName) + "-lg.jpg";
	else
		document.getElementById("mainimg").src="assets/product_images/" + pf_id + "-lg.jpg";
}
function imgOff(imgName) {
	/*if(qColor!="")
        document.getElementById("mainimg").src="assets/product_images/" + pf_id + "-" + qColor + "-lg.jpg";
	else
		document.getElementById("mainimg").src="assets/product_images/" + pf_id + "-" + qColor + "-lg.jpg";*/

	document.getElementById("mainimg").src = lastMainImg;
}


function display_thumbnails()
{
	var array_largeimage;

	//if there are colors to show
	if (colors.length>=2)
	{
		//the number below changes the number of columns for the swatches
		var columns=3;
		var atn;
		atn=0;
		var myImage;
		var counter=1;
		document.write("<div id=\"colors_label\">Roll Over to View Colors</div>");
		document.write("<table border=0 cellpadding=0 cellspacing=0><tr>");

		for (atn=0; atn<colors.length; atn++)
		{
			document.write("<td align=center class=\"swatch\"><A HREF=\"javascript:void(0);\" onClick=\"return false\" onmouseover=\"imgOn('"+colors[atn]+"');\" onmouseout=\"imgOff();\";><img NAME=\""+colors[atn]+"\" id=\""+colors[atn]+"\" src=\"assets/product_images/sw/" + pf_id + "-" + cleanColorName(colors[atn]) + "-sw.jpg\" onerror=\"this.src='assets/images/spacer.gif'\" border=0></a>");
			document.write("<br>"+colors[atn]+"</td>");
			if (counter==columns){document.write("</tr><tr>");counter=0}

			counter = counter+1;
		}
		document.write("</tr></table>");
	}
} //end display_thumbnails





function draw_sku_option()
{
	//if there are attr_values...
	if(typeof attr_values != "undefined") {
		var dropdownattr1 = "";
		var attrname = "";
		var dropdown_label="";

		if(porder_code !="GIFTCARD"){ //gift cards have different dropdowns...
			for (outer=0;outer<attr_values.length;outer++)
			{
				attrname = "attr" + (outer+1);

				document.write("<TR VALIGN=TOP ><TD>");

				if (attr_label[outer].toLowerCase()=="attribute")
				{
					//change colors in array to only available colors
					attr_values[outer] = colors;
					dropdown_label="Then Color...";
				}else if(attr_label[outer].toLowerCase()=="size"){
					//change sizes in array to only available sizes
					attr_values[outer] = sizes;
					dropdown_label="First, Select Size...";
				}else{
					dropdown_label=attr_label[outer];
				}


				document.write("<select name="+attrname+" id="+attrname+" onchange=\"get_values("+(outer+1)+");findprice();\" class=\"qjump\">");

				document.write('<option value="" selected>'+dropdown_label+"</option>");

				//only draw the options for size initially...
				if(attr_label[outer].toLowerCase()=="size"){
					for(innerarr=0;innerarr<attr_values[outer].length;innerarr++)
					{
					  dropdownattr1=attr_values[outer][innerarr];
					  document.write('<option value=\''+dropdownattr1.toUpperCase()+'\'>'+dropdownattr1.toUpperCase()+'</option>');
					}
				}
				document.write("</select>");

				document.write("<span id=single_option"+(outer+1)+"></span>");

				document.write("</TD></TR>");
				document.write("<INPUT TYPE=HIDDEN  NAME=sku id=sku VALUE=''>");
			}//end for
		} else {
			//if gift card, show the amount to select only
			document.write("<TR VALIGN=TOP ><TD>");

			dropdown_label="Select Amount";


			document.write("<select name='sku' id='sku'  onchange=\"getQuantity(this.options[this.selectedIndex].value);\"  class=\"qjump\">");

			document.write('<option value="" selected>'+dropdown_label+"</option>");

			product_var.sort(UUSort);

			for (atn=0;atn< product_var.length ;atn++){
				if(product_var[atn].avail!="0")
					writeoption(product_var[atn].sku,"$"+product_var[atn].attr_value1,sel_values[0]);
			}

			document.write("</select>");

			document.write("</TD></TR>");
		}
		document.write('<tr><td><select id="qty" name="qty" class="qjump" onChange="display_avail();"><option value="0">Select Quantity</option></select></TD></TR>');
	}//end if attr_values
	else {
		document.write("<INPUT TYPE=HIDDEN ID=sku  NAME=sku VALUE='"+product_var[0].sku+"'>");
	}

} //end draw_sku_option


//get_values receives the attr number of the dropdown that has changed.
//
function get_values(ddnum)
{
  var thisattr,nextdd,tempattr,tempdd;
  var ctr = 0;
  var optstr = "";
  var tempopt;
  var attr_flag = true;
  var selection = "";
  var sel_flag = false;


  switch(attr_values.length)
  {
    case 5:
      var dd5 = document.getElementById('attr5');
    case 4:
      var dd4 = document.getElementById('attr4');
    case 3:
      var dd3 = document.getElementById('attr3');
    case 2:
      var dd2 = document.getElementById('attr2');
      var dd1 = document.getElementById('attr1');

	  for (i=ddnum+1;i<=attr_values.length;i++)
	  {
		//clear out the next dropdown
		nextdd = eval("dd"+i);
		//store the selected value so that it will remain selected if available
		selection = nextdd.value;

		//cear dropdown
		for (j=nextdd.options.length-1;j>=1;j--)
		{
		  nextdd.options[j] = null;
		}



		/*
		** if the current dropdown's selection is the label option (value = blank),
		** then do not add new options, keep drop clear
		*/
		//get current selection
		var currentDropSelection = eval("dd"+ddnum).value;
		//if current selection is not blank
		if(currentDropSelection != "")
		{
			//create new options
			var sortarray= new Array();

			//loop thru product array
			for (atn=0;atn< product_var.length;atn++)
			{
			  attr_flag = true;

			  for (k=1;k<=i-1;k++)
			  {
				//check each dropdown up to one before nextdd
				tempattr = eval("product_var[atn].attr_value"+k);
				tempdd = eval("dd"+k).value;

				if (tempattr != tempdd && tempdd!="")
				{
				  //this product doesn't match our selected values
				  attr_flag = false;
				}
			  }//end for k


			  if (attr_flag == true)
			  {
				  //store the attr if it is new AND if available
				  thisattr = eval("product_var[atn].attr_value"+i);
				  if (optstr.indexOf(";" + thisattr + ";") == -1 && parseInt(product_var[atn].avail)>0) //keep 0 avail out
				  {
					optstr += ";" + thisattr + ";";
					//add option to array
					sortarray[ctr]=thisattr;
					ctr++;
				  }
			  }
			}//end for atn

			//sort array and add options to select
			sortarray.sort(smart_sort);
			if (sortarray.length==0)
			{
				nextdd.style.display = "none";

			} else
			{
				nextdd.style.display = "block";
				document.getElementById("single_option"+i).innerHTML="";
			}

			//write options
			for (s=0;s<sortarray.length;s++){
				if (sortarray[s] == selection) { sel_flag = true; }else{ sel_flag = false; }
				tempopt = new Option(sortarray[s],sortarray[s],sel_flag);
				nextdd.options[s+1] = tempopt;
			}
		}//end if current selection

		optstr = "";
		ctr = 0;
		selection = "";
	  }//end for
      break;
    case 1: //1 dropdown - do nothing here
    case 0: //no dropdowns - do nothing here
    default:

      break;
  }
}

function getWishListLink() {
    findsku();
    document.getElementById('wish_list_link').href = "shopper_lookup.asp?target=xt_orderform_additem.asp&addto=4&pf_id="+pf_id+"&sku=" + document.getElementById("sku").value;
    visitargs('shopper_lookup.asp', 'target=xt_orderform_additem.asp&addto=4&pf_id='+pf_id+'&sku=' + document.getElementById("sku").value, 'SURL');
}


function findsku()
{
	if (typeof attr_values!="undefined"){
		if(porder_code !="GIFTCARD"){ //gift cards have different dropdowns...
			if(product_var.length>1){
				//var sku_flds = document.getElementsByName("sku");
				//var qty_flds = document.getElementsByName("qty");
				var matchsku=false;
				var eachsku=0;
				var selectedsku;
				while (matchsku==false && eachsku<product_var.length)
				{
					var matching=true;
					for (drop=1;drop<=attr_values.length ;drop++)
					{
						//document.getElementById('this').value=document.getElementById('dropsku'+drop).options[document.getElementById('dropsku'+drop).selectedIndex].value;
						if (eval("product_var["+eachsku+"].attr_value"+drop).toUpperCase()!=document.getElementById('attr'+drop).options[document.getElementById('attr'+drop).selectedIndex].value.toUpperCase()){matching=false;}
					}
					if (matching==true){selectedsku=eval("product_var["+eachsku+"].sku");matchsku=true;
					//sku_flds.value="selectedsku";
					//qty_flds.value="1";
					//alert(selectedsku);
					//document.form1.sku.value=selectedsku;
					document.getElementById("sku").value = selectedsku;

                                   //if (( button == "wishlist" ) && ( user_email.indexOf("@") == -1 )) {
                                      //document.getElementById('returnpath').value="shopper_lookup.asp?target=xt_orderform_additem.asp&sku="+selectedsku+"&qty=1";
                                     // window.location.replace("shopper_lookup.asp?target=xt_orderform_additem.asp&sku="+selectedsku);
                                  // } else {

					fill_returnpath(selectedsku);
                                   //}

					//document.form1.submit();
					return true;

					}
					eachsku=eachsku+1;
				}//end while
			}//end if
			else if(product_var.length==1){
				//document.form1.sku.value=product_var[0].sku;
				document.getElementById("sku").value = product_var[0].sku;

                           // if (( button == "wishlist" ) && ( user_email.indexOf("@") == -1 )) {
                                      //document.getElementById('returnpath').value="shopper_lookup.asp?target=xt_orderform_additem.asp&sku="+selectedsku+"&qty=1";
                                      //window.location.replace("shopper_lookup.asp?target=xt_orderform_additem.asp&sku="+selectedsku);
                           // } else {

				fill_returnpath(product_var[0].sku);
                            //}

				return true;
			}
		} else { //end porder code check
			fill_returnpath(document.getElementById("sku").options[document.getElementById("sku").selectedIndex].value);
			return true;
		}
	}//end if
}

function findprice(){
	if (typeof attr_values!="undefined"){
		//var sku_flds = document.getElementsByName("sku");
		//var qty_flds = document.getElementsByName("qty");
		var matchsku=false;
		var eachsku=0;
		var selectedskuprice;
		var listprice;
		var avail_message;
		var selectedQuantity = 0;
		while (matchsku==false && eachsku<product_var.length)
		{
			var matching=true;
			for (drop=1;drop<=attr_values.length ;drop++)
			{
				if (eval("product_var["+eachsku+"].attr_value"+drop)!=document.getElementById('attr'+drop).options[document.getElementById('attr'+drop).selectedIndex].value){matching=false;}
			}
			if (matching==true){
				avail_message = eval("product_var["+eachsku+"].avail_msg");
				selectedQuantity = eval("product_var["+eachsku+"].avail");
				if (eval("product_var["+eachsku+"].price_sale")!="" && eval("product_var["+eachsku+"].price_sale")!="0" && eval("product_var["+eachsku+"].price_sale")<eval("product_var["+eachsku+"].price_list")){

					listprice=eval("OKStrOfPenny(product_var["+eachsku+"].price_list)");matchsku=true;
					selectedskuprice=eval("OKStrOfPenny(product_var["+eachsku+"].price_sale)");matchsku=true;
					//document.getElementById("prod_price").innerHTML = "<font class='ListPricewSale'><br>Regular Price:&nbsp;$"+listprice+"</font><font class='SalePrice'><br>ON SALE!&nbsp;$"+selectedskuprice+"</font><br>"+avail_message;
				}else{
					selectedskuprice=eval("OKStrOfPenny(product_var["+eachsku+"].price_list)");matchsku=true;
					//document.getElementById("prod_price").innerHTML = "<font class='ListPricewoSaleP'><br>Selected Item Price&nbsp;$"+selectedskuprice+"</font><br><br>"+avail_message;
				}

				set_avail_message(avail_message);
				//display_avail(avail_message);

				if(selectedQuantity!=0)
				{
					updateQuantity(selectedQuantity);
				}

				//sku_flds.value="selectedsku";
				//qty_flds.value="1";
				//document.form1.sku.value=selectedsku;
				//document.form1.submit();
				return true;

			} //end if matching
			eachsku=eachsku+1;
		}//end while

		//if matching still is false at this point...
		if(!matching) {
			//update qty drop with no options
			updateQuantity(0);
		}//end if not matching
	}//end if
}


var availability_message = "";
function set_avail_message(avail_message)
{
	//if the availability message is not empty...
	if(avail_message!="" && avail_message!="&nbsp;")
		availability_message = avail_message;
	else
		availability_message = "&nbsp;";
}

function display_avail()
{
	document.getElementById("availability_message").innerHTML = availability_message;
}

/* used by gift card dropdown to get quantity to fill qty select */
function getQuantity(thesku){
	var qty = 0;
	//get avail based on passed in sku
	for(pv=0;pv<product_var.length;pv++){
		if (product_var[pv].sku==thesku) {
			qty = product_var[pv].avail;
			set_avail_message(product_var[pv].avail_msg);
		}
	}
	//update qty
	updateQuantity(qty)
}

//updates the quantity dropdown based on quantity sent in
function updateQuantity(qty)
{
	//change options in qty dropdown so that only UP TO AND INCLUDING passed in number is displayed as options
	var qtyDrop = document.getElementById('qty');

	//clear qty drop - but leave first option (start at 1)
	for (op=qtyDrop.options.length-1;op>=1;op--)
    {
		qtyDrop.remove(op);
	}

	var topqty = 0;
	(qty>5 ? topqty = 5 : topqty = qty);

	//add options up to passed in quantity
	for(num=1; num<=topqty; num++)
	{
		qtyDrop.options[num] = new Option(num,num,false);
	}
}

var currentlyShownImg = 0;
/* alternate image popup */
function display_alternates(){
	if (typeof info_attributes!="undefined" && info_attributes != "" && info_attributes != "default")
	{
		//prepare alternate images so that we know which images to show in popup and have number links to display
		prepare_alternates();

		document.write('<img src="Assets/images/btnEnlargeImage.gif" border="0" style="margin:1px 0px 0px 0px;"><div id="alternate_btn_text"><a href="javascript:void(0);" onClick="show_next_alt();return false;" title="Click to View Alternate Images">Alternate Views</a>&nbsp;&nbsp;');
		for(var i=0; i<alt_nums.length; i++)
		{
			if(i!=0) document.write(' | ');
			
			document.write('<a href="javascript:void(0);" id="alt_'+i+'" onClick="show_alternate('+i+');return false;" class="number">'+(i+1)+'</a>');
		}
		document.write('</div><div id="alternate_btn_enlarge"><a href="javascript:void(0);" onClick="pop_alternates();return false;" title="Click to Enlarge Alternate Images">Enlarge</a></div>');
		
		//set currently shown image class to on
		document.getElementById('alt_0').className='on';
	}
}

/* Variables used to hold alternate images */
var alternates = info_attributes.split(",");
var currColorAlts = new Array();
var otherColorAlts = new Array();
var main_alt_img ="";
var alt_thumbs = "";
var alt_nums = new Array();


//function used to get all of the alternates images
function prepare_alternates()
{
	//loop through all alternates and separate out current color from other colors
	for(alt in alternates)
	{
		//if img is for current color...
		var compColor = cleanColorName(alternates[alt]).toUpperCase();
		if(compColor.search('-')!=-1){
			compColor = compColor.substring(0,compColor.indexOf('-'));
		}
		//if(cleanColorName(alternates[alt]).toUpperCase().search(cleanColorName(qColor).toUpperCase())!=-1) {
		if(compColor == cleanColorName(qColor).toUpperCase()) {
			currColorAlts.push(cleanColorName(alternates[alt]));

		} else {
			//see if color is available
			for(color in colors)
			{
				if(cleanColorName(alternates[alt]).indexOf(cleanColorName(colors[color]))!=-1){
					otherColorAlts.push(cleanColorName(alternates[alt]));
					break;
				}
			}

		}
	}

	//get first img of current color to display as main img
	if(currColorAlts[0])
		main_alt_img = "<img src=\"assets/product_images/xlg/"+pf_id+"-"+currColorAlts[0]+"-xlg.jpg\" id=\"main_alt_img\">";
	
	
	//loop through all current colors
	for(curAlt in currColorAlts)
	{
		alt_thumbs += "<img src=\"assets/product_images/"+pf_id+"-"+currColorAlts[curAlt]+"-xsm.jpg\" id=\"alt_thumb\" onClick=\"change_alt('assets/product_images/xlg/"+pf_id+"-"+currColorAlts[curAlt]+"-xlg.jpg');\">";
		alt_nums.push(currColorAlts[curAlt]);
	}

	//loop through all other colors and take the first of each color (go by the number of curColorsAlts)
	if(currColorAlts.length > 0) {
		for(otherAlt=0; otherAlt<otherColorAlts.length; otherAlt=otherAlt+currColorAlts.length)
		{
			alt_thumbs += "<img src=\"assets/product_images/"+pf_id+"-"+otherColorAlts[otherAlt]+"-xsm.jpg\" id=\"alt_thumb\" onClick=\"change_alt('assets/product_images/xlg/"+pf_id+"-"+otherColorAlts[otherAlt]+"-xlg.jpg');\">";
			alt_nums.push(otherColorAlts[otherAlt]);
		}
	} else {
		//to avoid infinite loop, use regular incrementor if there are no currColorAlts
		for(otherAlt=0; otherAlt<otherColorAlts.length; otherAlt++)
		{
			alt_thumbs += "<img src=\"assets/product_images/"+pf_id+"-"+otherColorAlts[otherAlt]+"-xsm.jpg\" id=\"alt_thumb\" onClick=\"change_alt('assets/product_images/xlg/"+pf_id+"-"+otherColorAlts[otherAlt]+"-xlg.jpg');\">";
			alt_nums.push(otherColorAlts[otherAlt]);
		}
	}

	//if there is no main image
	if(main_alt_img =="" && typeof otherColorAlts[0] != "undefined"){
		//use the first image of otherColorAlts array
	   main_alt_img = "<img src=\"assets/product_images/xlg/"+pf_id+"-"+otherColorAlts[0]+"-xlg.jpg\" id=\"main_alt_img\">";
	}
	
	/* function (change_alt) used to change main alternate image with the selected image
	is inside the popup window function (pop_alternates) */
}

function show_next_alt()
{ 
	//set last currently shown image class to number
	document.getElementById('alt_'+currentlyShownImg).className='number';
	
	currentlyShownImg++;
	//if next is not valid, make it 0
	if(currentlyShownImg<0 || currentlyShownImg>alt_nums.length-1)
	{
		currentlyShownImg = 0;
	}
	show_alternate(currentlyShownImg);
}

function show_alternate(imgIDToShow)
{
	//set last currently shown image class to number
	document.getElementById('alt_'+currentlyShownImg).className='number';
	
	//set currently shown image
	currentlyShownImg = imgIDToShow;
	
	//change main image to selected
	imgOn(alt_nums[currentlyShownImg]);
	
	//set currently shown image class to on
	document.getElementById('alt_'+currentlyShownImg).className='on';	
}



var winPhoto2;
function pop_alternates(defaultImageToShow)
{
	//if there is a default Image to show...
	if(!defaultImageToShow) defaultImageToShow = "assets/product_images/xlg/"+pf_id+"-"+alt_nums[currentlyShownImg]+"-xlg.jpg";

	//get images to display from info_attributes
	winPhoto2 = window.open("","AltView","height=650,width=550,status=0,scrollbars=1,location=0,resizable=1");
	if (winPhoto2)
	{
		winPhoto2.document.open();

		var output = '<html>';
		output +='    <head>';
		output +='        <title>NM Other View |  Click on Small Image to See Larger</title>';
		output +='        <link rel="stylesheet" type="text/css" href="Assets/images/includes/lingerie.css">';
		output +='        <scri'+'pt language="javascript">function change_alt(newImage){document.getElementById(\'main_alt_img\').src = newImage;}</scr'+'ipt>';
		output +='    </head>';

		output +='    <body><div id="alt_container">';
		output +='    <img src="assets/images/logo.gif" alt="Nancy Meyer" longdesc="http://nancymeyer.com" vspace="5">';
		output +='	  <table border="0" cellspacing="0" cellpadding="0" align="center">';
		output +='	    <tr>';
		output +='		  <td class="alternate_thumbs" valign="top" align="center">'+alt_thumbs+'</td>';
		output +='		  <td class="alternate_main" valign="top" align="center">'+main_alt_img+'</td>';
		output +='	    </tr>';
		output +='	    <tr>';
		output +='		  <td >&nbsp;</td>';
		output +='		  <td class="alt_instruction_text" align="center">(Click on Small Images for Larger View)</td>';
		output +='	    </tr>';
		output +='	  </table>';
		output +='	  <a href="javascript:window.close();" class="alt_link"><img src="assets/images/close-window.gif" border="0"></a>';
		output +='	  <scri'+'pt language="javascript"> var defaultImageToShow = "'+defaultImageToShow+'"; if(defaultImageToShow !="") change_alt(defaultImageToShow);</scr'+'ipt>';
		output +='    </div></body>';
		output +='</html>';

		winPhoto2.document.write(output);

		winPhoto2.document.close();
		winPhoto2.focus();
	}else{
		alert("Your browser is blocking popups for our web site. In order to view this content, please allow popus for our site.");
	}
	return false;
}


function get_from_QueryString(item){
	var theQueryString = window.location.search.substring(1);
	var theQueryStringArray = theQueryString.split('&');

	for (theItem in theQueryStringArray) {
		//find
		if(String(theQueryStringArray[theItem]).indexOf(item+"=",0)!= -1){
			return theQueryStringArray[theItem].substring(theQueryStringArray[theItem].indexOf("=")+1);
			//return value if found
		}
	} //end for
	return false //if not found
}


function writeStyle() {
	var styleOut = porder_code;
	styleOut += "-"+ qColor;
	document.write(styleOut);
}

//redirect to the appropriate page based on action performed
function check_add_basket()
{

	var query = window.location.search.substring(1);

	if((query.indexOf('&addfrom=product&msg=added&')>0)&&(query.indexOf('addto=4') != -1) &&(query.indexOf('&error=')<=0))
	{
	  //redirect to wish_basket
	  //window.location.replace("wish_basket.asp?s_id="+s_id);
	  //get sku and qty from url
		var sk = get_from_QueryString("sku");
		var qt = get_from_QueryString("qty");

		//redirect to gentle reminder for wish list
		window.location.replace("product.asp?pf_id="+pf_id+"&px_id=71&attr_value2="+qColor+"&addedsku="+sk+"&addedqty="+qt);
	} else if((query.indexOf('addto=2') != -1) &&(query.indexOf('&error=')<=0))	{
	  //redirect to basket_compare
	  window.location.replace("compare_basket.asp?s_id="+s_id);
	} else if((query.indexOf('&addfrom=product&msg=added&')>0)&&(query.indexOf('addto=1')!= -1)&&(query.indexOf('&error=')<=0) && (shopping_basket.no_items > 0))	{
		//get sku and qty from url
		var sk = get_from_QueryString("sku");
		var qt = get_from_QueryString("qty");

		//redirect to gentle reminder
		window.location.replace("product.asp?pf_id="+pf_id+"&px_id=61&attr_value2="+qColor+"&addedsku="+sk+"&addedqty="+qt);
	}
}

/**
 * Returns true if 'e' is contained in the array 'a'
 * @author Johan Känngård, http://dev.kanngard.net
 */
function contains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}

function fill_returnpath(selSku){
	/* If there is no sku selected... */
	if (typeof selSku == "undefined" || selSku == "" ) {
		document.getElementById("returnpath").value = 'product.asp?dept_id=' + dept_id + '&pf_id='+ pf_id +'&attr_value2='+qColor+'&addfrom=product&error=unavailable&';
	} else { /* Sku was selected... */
		var selQty = document.getElementById('qty').options[document.getElementById('qty').selectedIndex].value
		if(selQty==""||selQty=="0") selQty="1";
		var selColor = findSelectedColor(selSku);

		document.getElementById("returnpath").value = 'product.asp?dept_id=' + dept_id + '&pf_id='+ pf_id + '&sku=' + selSku +'&qty=' + selQty + '&attr_value2='+cleanColorName(selColor)+'&addfrom=product';
	}
}

function findSelectedColor(selSku) {
	//find the color of the selected sku
	for(pv=0; pv<product_var.length; pv++) {
		if(product_var[pv].sku == selSku)
			return product_var[pv].attr_value2;
	}
	return "";
}

function draw_designerLinks()
{
	var designer = "";

	//find Designer searchable attribute
	for(sa in sa_array)	{
		if(sa_array[sa].name.toLowerCase() == "designer")
		{
			designer = sa_array[sa].value;
			break;
		}
	}

	//see if vendor code is in bio list
	var desBio = false;

	if( designerBioList.indexOf("," + pvendor_code + ",") != -1 )
	{
		desBio = true;
	}

	var designerOutput = "";
	
	if(designer != "") {
		designerOutput += "<a href=\"search2.asp?search_freetext="+designer+"\" onClick=\"return(visitargs('search2.asp','search_freetext="+designer+"','URL'));\">View all items by this designer</a>";
	}
	if(desBio) {
		designerOutput += "<a href=\"#\" onclick=\"openWindow('"+pvendor_code+"_bio.html'); return false;\">Designer Biography</a>";
	}
	if( laPerlaBioList.indexOf("," + pvendor_code + ",") != -1 ){
		designerOutput += "<a href=\"#\" onclick=\"openWindow('"+pvendor_code+"2_bio.html'); return false;\">About "+designer+"</a>";
	}
	
	document.write(designerOutput);
}


/** feature begin:share product, status:altered, editor:JMS, date:08.13.07
* descr: changed format to display non-standard product images **/


function shareproduct(PageURL,args,SURL)
{
	/** to change the code of the offer edit the text in between the quotes **/
	var plink = "";
	var emailbody = "";
	var url = "";
	if (args.indexOf("=")<0 ||args.indexOf("&")<0 )
	{
		args="";
	}
	if (user_guid !=' ')
	{
		PageURL =PageURL + '?mscssid='+ user_guid+ '&dept_id='+dept_id+ '&pf_id='+pf_id+ '&'+ args ;
	}else{
		PageURL =PageURL + '?dept_id='+dept_id+ '&pf_id='+pf_id+ '&'+ args ;
	}
	if(sharepage="none" || sharepage==""){
		referer= i_jscript_uu_rootURL + "product.asp";
	}
	else {
		referer= i_jscript_uu_rootURL + sharepage ;
	}

	plink=i_jscript_uu_rootURL+"product.asp?dept_id=" + dept_id + "&pf_id="+ pf_id +"&" ;

	emailbody ="<style>BODY{ FONT-SIZE: 12px; background-image:url("+i_jscript_uu_rootURL+"assets/images/lingerie_bg.gif); background-repeat: repeat-x; background-color: #e3deda; COLOR: #363636; FONT-FAMILY: Arial, Helvetica, sans-serif; }</style>";
	emailbody +="<TABLE cellspacing=5 cellpadding=5 width=\"90%\">";
	emailbody +="<TR><TD><a href=\""+i_jscript_uu_rootURL+"\"><img src=\""+i_jscript_uu_rootURL+"assets/images/logo.gif\" border=0 alt=\"Nancy Meyer\" ></a></TD>";
	emailbody +="</TR><TR><td >";
	emailbody +="Dear #RecipientName#,<br>";
	emailbody +="<br> #Text_field_3# </td></tr><tr><td >";
	/** table with product image **/
	emailbody +="<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"100%\">";
	emailbody +="<tr valign=top><td >";

	emailbody +=" <A HREF=\"" + referer + "?dept_id=" + dept_id + "&pf_id=" + pf_id + "&\"><IMG SRC=\""+ i_jscript_uu_rootURL + "assets/product_images/"+ pf_id + "-" + qColor + "-sm.jpg\" border=0 alt=\"" + product_name + "\">";
	emailbody +="<div style=\"display: block; text-align: center;\"><img src=\""+i_jscript_uu_rootURL+"assets/images/btnbuynow.gif\" border=\"0\"></A></td><td valign=top>";
	emailbody +="<A HREF=\"" + referer + "?dept_id=" + dept_id + "&pf_id=" + pf_id + "&\">" + product_name + "</A><br><br>";
	emailbody +="<font >";

    emailbody += product_description;

	emailbody +="</font>";
	emailbody +="<br><A HREF=\"" + referer + "?dept_id=" + dept_id + "&pf_id=" + pf_id + "&\">See this product at NancyMeyer.com</A><br><br>From <a href=\"mailto:#FromEmail#\">#FromName#</a>";
	emailbody +="</TD></TR></TABLE>";
	emailbody +="</td></tr></table>";


	//set the inputs
	document.getElementById("share_new_referer").value = plink;
	document.getElementById("share_new_target").value = "text_3.asp";
	document.getElementById("share_new_email_body").value = emailbody;

	/*
	Not changing the location any longer...submitting form instead to get around IE querystring character limit
	window.location=PageURL +"referer="+escape(plink)+"&email_body="+escape(emailbody)+"&target="+ escape(window.location.href)+"&";
	*/

	var w = window.open(document.share_new.action, "share_window","scrollbars=1,menubar=0,toolbar=0,resizable=1,height=550,width=550");
	w.focus();

	//submit form
	document.share_new.submit();

	//return(false);
}//end shareproduct