/* PRODUCT PAGE */
function showDetail(What, CheckURL) 
{
	var a, i;
	if (CheckURL) {
		i = document.URL.indexOf("#");
		if(i != -1) {
			showDetail(document.URL.substring(i+1,document.URL.length));
			//alert(document.URL.substring(i+1,document.URL.length));
			return;
		}
	}
	if (!document.getElementsByTagName) 
		return;
	a = document.body.getElementsByTagName("div");
	if (a.length == 0) 
		return;
	if (typeof a[0].style != 'object') 
		return;
	if (typeof a[0].style.display == 'undefined') 
		return;
	for (i = 0; i < a.length; i++) {
		if (a[i].className != "section") 
			continue;
		if (a[i].id != What) 
			a[i].style.display = "none";
		else 
			a[i].style.display = "block";
	}
	return true;
}

activePages = new Array();
function doOnLoad() {
	showDetail(0);
	activePages.pop(); 
	activePages.push('topPictureNav');
	imageReset('topSpec'); 
	imageReset('topAbout'); 	
	highlightActivePages(activePages);	
}

function draw_product_properties(){	

	//build list of properties to show
	var specsArray = new Array();
	var output = "";
	var shownProperties = "";	
	
	//if there are Single Valued Attributes to show 
	if(attrs>0)
	{		
		//loop
		for(pa=0; pa<attrs; pa++){
			if(shownProperties.indexOf(","+product_attrbute [pa].attname+":"+product_attrbute [pa].attvalue+",")==-1)
			{
				//add to array
				specsArray.push(new aSpec(product_attrbute[pa].attname,product_attrbute[pa].attvalue));				
				shownProperties += ","+product_attrbute [pa].attname+":"+product_attrbute [pa].attvalue+",";
			}
		}
	}
	
	shownProperties = "";//reset shownProperties
	
	//if there are searchable attributes to show
	if(sa_array.length>0) {		
		//loop
		for(pa=0; pa<sa_array.length; pa++){
			if(shownProperties.indexOf(","+sa_array[pa].name+":"+sa_array[pa].value+",")==-1)
			{
				//add to array
				specsArray.push(new aSpec(sa_array[pa].name,sa_array[pa].value));				
				shownProperties += ","+sa_array[pa].name+":"+sa_array[pa].value+",";
			}
		}
	}
	
	//first attribute
	var label=attr_label[0];
	if(attr_label[0] == "Attribute") label="Color";
	if(product_var[0].attr_value1!="") specsArray.push(new aSpec(label,product_var[0].attr_value1));	
	
	//second attribute
	label=attr_label[1];
	if(attr_label[1] == "Attribute") label="Color";
	if(label!="" && product_var[0].attr_value2!="")	specsArray.push(new aSpec(label,product_var[0].attr_value2));
	
	//sort list
	specsArray.sort(specchart_sort);
	
	//build list output
	for(sa=0; sa<specsArray.length; sa++){
		output +='<li><span class="ProductPropertyLabel">'+specsArray[sa].name+': </span> <span class="ProductProperty">'+specsArray[sa].value+'</span></li>';
	}
	
	//show list
	if(output !=""){
		output = '<UL id="lstProperties">' + output + '</UL>';		
		document.write(output);
	}else{
		document.write("No specs available");
	}
}

function aSpec(name,value){
	this.name = name;
	this.value = value;
}
//sort order
var sortSpecs = ",Designer,Primary Metal,Additional Metal,Material,Material 1,Material 2,Stone 1,Stone 2,Stone 3,Stone 4,Stone 5,Size,Color,Message,";
function specchart_sort(r,s){if (parseInt(specSort(r.name))>=parseInt(specSort(s.name))){return 1;}else{return -1;}}
function specSort(x){return sortSpecs.indexOf("," + String(x) + ",");}

function draw_sku_option()
{
	if (product_var.length >= 1 ){
		if(product_var.length==1){			
			//document.write('<TR><td class="ProductPropertyLabel" align="left" valign="top">' + attr_label[0] + ':</TD>');
			//document.write('<td class="ProductProperty" align="left" valign="top">' + product_var[0].attr_value1 + '</TD></TR>');
			//if(attr_label[1]!=""){
			//	document.write('<TR><td class="ProductPropertyLabel" align="left" valign="top">' + attr_label[1] + ':</TD>');
			//	document.write('<td class="ProductProperty" align="left" valign="top">' + product_var[0].attr_value2 + '</TD></TR>');
			//}
			//document.write("<TR><TD colspan=2>" + product_var[0].avail_msg);
			document.write("<INPUT TYPE=HIDDEN id=\"sku\" NAME=sku VALUE=\"" + product_var[0].sku + "\" >");
			//document.write("</TD></tr>");
		}else{	

			document.write("<tr>");
			document.write('<td class="ProductPropertyLabel" align="left" valign="top"></td>');
			document.write('<td class="ProductProperty" align="left" valign="top">');
									
			document.write("<SELECT class=\"SkuSelect\" NAME=sku id=\"sku\" onChange=\"updatelblSKU();\">");
			i=0;
			labelstr= "Select Color/Size";/*"-- select ";
			while (attr_label[i]!= "" && i < attr_values.length ) {
				labelstr=labelstr + attr_label[i] + " ";
				i++;
			}
			labelstr+="--";*/
			writeoption("",labelstr ,sel_values[0]);
			
			var separator=" - ";
			
			for (atn=0;atn< product_var.length ;atn++){
				//empty separator if secdond attr is empty
				if(product_var[atn].attr_value2=="") separator="";
				
				//draw options
				if (useVariantPrice=="True"){
					if(product_var[atn].avail!=0){
						if (on_sale=="True"){
							writeoption(product_var[atn].sku,(product_var[atn].attr_value1 + separator + product_var[atn].attr_value2 + " - $"+ OKStrOfPenny(product_var[atn].price_sale)) + "" ,sel_values[0]);
						}else{
							writeoption(product_var[atn].sku,(product_var[atn].attr_value1 + separator + product_var[atn].attr_value2 + " - $"+ OKStrOfPenny(product_var[atn].price_list)) + "" ,sel_values[0]);
						}
					}
					
				}else{
					if(product_var[atn].avail!=0){
						if (product_var[atn].avail_msg==""){
							product_var[atn].avail_msg="on back order";
						}
						writeoption(product_var[atn].sku,(product_var[atn].attr_value1 + separator + product_var[atn].attr_value2) + "",sel_values[0]);
					}
				}
			}//end for
			document.write("</SELECT></TD>");	
			document.write("</TR>");
		}//end else
	}//end if
} //end draw_sku_option


function updatelblSKU(){
	if(document.getElementById("lblSKU"))
	{
		document.getElementById("lblSKU").innerHTML = document.getElementById("sku").value;
		//also update size and color in properties 
			
		for (atn2=0;atn2< product_var.length ;atn2++){
			if(document.getElementById("sku").value == product_var[atn2].sku) {
				if(document.getElementById("product_property_size"))
					document.getElementById("product_property_size").innerHTML = product_var[atn2].attr_value1;
				if(document.getElementById("product_property_color"))
					document.getElementById("product_property_color").innerHTML = product_var[atn2].attr_value2;
			}
		}
	}
}


function check_add_basket()
{

	var query = window.location.search.substring(1);	
					 
	if(query.indexOf('addto=4') != -1)
	{
	  //redirect to wish_basket
	  parent.location.replace("wish_basket.asp?s_id="+s_id);
	}
	
	if(query.indexOf('addto=2') != -1)
	{
	  //redirect to basket_compare
	  parent.location.replace("compare_basket.asp?s_id="+s_id);
	}
	
	
	if((query.indexOf('&addfrom=product&msg=added&')>0)&&(query.indexOf('addto=1')!= -1)&&(query.indexOf('&error=')<=0) && (shopping_basket.no_items > 0))
	{
		parent.location.replace("basket.asp?s_id="+s_id);
	}

} //end check_add_basket


function shareproduct(PageURL,args,SURL) 
{ 

	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 ;
	}
	
	//plink must be the dept page with page= and pf_id=
	plink=parent.location + "&pf_id="+ pf_id ;
	
	//email body
	
	emailbody ='<html><custom name="opencounter" type="tracking"><head><title>Zinnia</title>'+
	'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />'+
	'<style>/* ---------------------------- general element classes ---------------------------*/'+
	'body {font: 10px arial, helvetica, sans-serif; color: black; margin: 0px; padding: 0px; text-align: center;}'+
	'a:link, a:active {color: #AB6666; text-decoration: none;}'+
	'a:visited { color: #B3B3B3;	text-decoration: none;}'+
	'a:hover { color: #710101; text-decoration: none;}'+
	'a:focus { outline: none;}'+
	'/* ---------------------------- general page classes ---------------------------*/'+
	'.seperator { border-bottom: 3px solid #fff; font: 1px arial; clear: both;}'+
	'.smallSeperator { border-bottom: 1px solid #fff; font: 1px arial; clear: both;}'+
	'.clear { clear: both; font: 1px sans-serif;}'+
	'.bodyCopy { text-align: left; padding-top: 10px; padding-bottom: 10px; padding-right: 25px;}'+
	'/* ---------------------------- page regions ---------------------------*/'+
	'#wrapper {width: 537px; margin-left: auto; margin-right: auto; text-align: center; background-color: #fff;}'+
	'#contentContainer { text-align: left; padding-top: 10px; padding-left: 10px; padding-bottom: 10px; padding-right: 25px;}'+
	'#footer { border-top: 1px solid #000;}'+
	'#copyright { font: 10px verdana, arial, sans-serif; color: #696a60; text-align: right;}'+
	'.blackBar {	height: 16px; font: bold 10px verdana, arial, sans-serif; color: white; background-color: #4b3900; background-repeat:no-repeat; text-align: left; margin-bottom:5px;}'+
	'</style></head><body>'+
	'<div id="wrapper"><div style="float: left; width: 268px;"><a href="'+i_jscript_uu_rootURL+'"><img src="'+i_jscript_uu_rootURL+'assets/images/zinnia/zinnia_logo_clear.gif" align="left" border="0" alt="Zinnia"/></a></div><div style="float: left; width: 269px;"></div><div class="smallSeperator"></div><div class="blackBar">&nbsp;</div><div class="seperator"><br/></div><div id="contentContainer"><br/>';	
	emailbody += "A friend thought you might find this page interesting <A HREF=\""+plink +"\">"+ product_name + "</a>" ;	
	emailbody += '<br/><br/>Comment:<br>#Text_field_3#</div><div id="seperator"><br/></div><div class="blackBar"></div><div class="seperator"><br/></div><div id="footer"><span id="copyright">&copy; Copyright 2007 Zinnia, Inc. All rights reserved</span></div><div class="seperator"><br/></div></div></body></html>';
	
	var emailmsg = "A friend thought you might find this page interesting <A HREF=\""+plink +"\">"+ product_name + "</a><br/><br/>Comment:<br>#Text_field_3#" ;	
	
	//open in a new window	
	//window.open(PageURL +"referer="+escape(plink)+"&email_body="+escape(emailbody)+"&target="+escape(PageURL+"&submitted=yes"), 'newWindow1334970309', 'menubar=0,toolbar=0,resizable=1,height=385,innerHeight=385,width=375,innerWidth=375');
	window.open(PageURL +"referer="+escape(plink)+"&email_message="+escape(emailmsg)+"&target="+escape(PageURL+"&submitted=yes"), 'newWindow1334970309', 'menubar=0,toolbar=0,resizable=1,height=385,innerHeight=385,width=375,innerWidth=375');
	
	//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



function draw_related(type,display,message){
	var prodlink="";
	var typematch=0;
	//page_option_4: 0=horizontal 1=vertical
	if(typeof type=="undefined"){
	type="0";
	}
	if (typeof display=="undefined"){
	display=page_option_4;
	}
	if (typeof message=="undefined"){
	message="";
	}
	if (nRelated>0){
		for (atn=0;atn< nRelated ;atn++){
			if (Related_prod[atn].crosstype==type){
				typematch=1;
			}
		}
	}
	if (typematch==1) {
	document.write(message);
	}
	
	if (nRelated>0){
		//document.write('<table id="RelatedItems1_pnlMain" border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>');
		//document.write('<div class="RelatedItemsBlock"> <div class="RelatedItemsBlockContent">');
		
		document.write("<div class=\"relProductlabel\">You might also like...</div>");
		
		//open table
		document.write('<table width="222" border="0" cellspacing="0" cellpadding="0"><tr>');
		
		for (atn=0;atn< nRelated ;atn++){
			if (Related_prod[atn].crosstype==type){
				document.write('<td width="110" height="108"><div class="SingleRelatedContainer">');
					
				prodlink="<A target='_parent' HREF=\"product.asp?pf_id=" + Related_prod[atn].pf_id + "&s_id="+s_id+"\">";			
				
				//product image & link
				if ((Related_prod[atn].image!="")&&(rel_image_enable!="NONE")){
					
					document.write('<div class="SingleRelatedDisplayImage">'+prodlink);
					document.write("<img BORDER=0  VSPACE=0  HSPACE=0  ALT=\"" + Related_prod[atn].pf_id + " - " + Related_prod[atn].name + "\" SRC=\"assets/product_images/" + Related_prod[atn].pf_id + "t.jpg\"</\a></\div>");
				}//end if image			
		
				//product price (if enabled)
				if ((page_option_5==1)&&(Related_prod[atn].list_price!="")){
					document.write('<div class="SingleRelatedDisplayPrice">'+prodlink);
					if (Related_prod[atn].on_sale!="False" && Related_prod[atn].sale_price!="" && Related_prod[atn].sale_price!="$0.00" && Related_prod[atn].sale_price!=Related_prod[atn].list_price){
						if(Related_prod[atn].list_price != ""){document.write(Related_prod[atn].list_price);}
						document.write("<font class=SalePriceR>" + rel_sale_pricelab + Related_prod[atn].sale_price + "<\/font>");
					}else{
						if(Related_prod[atn].list_price != ""){document.write(Related_prod[atn].list_price);}
					}
					document.write('</a></div>');
				}//end if page_option_5
				document.write("<\/div>");
				
				document.write("</div></td>");
				
				if(nRelated == 1) document.write('<td width="110" height="108"><div class="SingleRelatedContainer"></div></td>');
				
				if(atn%2==1) document.write('</tr><tr>');
				if(atn%2!=1 && atn==nRelated) document.write('</tr>');
			}//end if crosstype match	
		}//end for
		//document.write("<\/div><\/div><\/td><\/tr><\/Table>");
		document.write("</table>");
	}
}//end function draw_related


//this function needs to be called on the wish button on the softcode of the product page, like this: onclick=\"return(go_thru_shopper_lookup())\"
function go_thru_shopper_lookup()
{
	var selectedsku = document.getElementById('sku').value;
	if (selectedsku=="")
	{
		alert("Please select from the dropdown and try again.");
		return false;
	}
	else
	{
		if (product_var)
		{
			for (j=0;j< product_var.length ;j++)
			{
				if(product_var[j].sku==document.getElementById("sku").value)
				{
					//if logged in go directly to add to wish basket...
					if(user_email.indexOf("@") !=-1)
					{
						parent.location.replace('xt_orderform_additem.asp?addto=4&dept_id='+dept_id+'&pf_id='+pf_id+'&sku='+product_var[j].sku+'&attr_value1='+escape(product_var[j].attr_value1)+'&attr_value2='+escape(product_var[j].attr_value2)+'&attr_value3='+escape(product_var[j].attr_value3)+'&attr_value4='+escape(product_var[j].attr_value4)+'&attr_value5='+escape(product_var[j].attr_value5)+'&s_id='+s_id+'&mscssid='+user_guid+'&');
					}
					else //if not logged in go through shopper_lookup
					{
						parent.location.replace('shopper_lookup.asp?target=xt_orderform_additem.asp&addto=4&dept_id='+dept_id+'&pf_id='+pf_id+'&sku='+product_var[j].sku+'&attr_value1='+escape(product_var[j].attr_value1)+'&attr_value2='+escape(product_var[j].attr_value2)+'&attr_value3='+escape(product_var[j].attr_value3)+'&attr_value4='+escape(product_var[j].attr_value4)+'&attr_value5='+escape(product_var[j].attr_value5)+'&s_id='+s_id+'&mscssid='+user_guid+'&');
					}					
				}
			}
		}
	}
}
