// tablepage.js
var sAuthor = "";
if (document.location.href.indexOf("author") != -1) {
   sAuthor = "/author";
   } 

if (document.location.href.indexOf("TablePage=8654203") != -1) {
	if (document.cookie.indexOf("country=JPN") != -1) {
	document.location.replace(sAuthor + "/technical-service-home/product-catalog-jp.html");
	} else { document.location.replace(sAuthor + "/technical-service-home/product-catalog.html");
	}
   } else if (document.location.href.indexOf("TablePage=16270507") != -1) {
	if (document.cookie.indexOf("country=JPN") != -1) {
	document.location.replace(sAuthor + "/chemistry/chemical-synthesis/chemical-synthesis-catalog-jp.html");
	} else { document.location.replace(sAuthor + "/chemistry/chemical-synthesis/chemical-synthesis-catalog.html");
	}
   } else if (document.location.href.indexOf("TablePage=12693646") != -1) {
	if (document.cookie.indexOf("country=JPN") != -1) {
	document.location.replace(sAuthor + "/analytical-chromatography/analytical-chromatography-catalog-jp.html");
	} else { document.location.replace(sAuthor + "/analytical-chromatography/analytical-chromatography-catalog.html");
	}
   } else if (document.location.href.indexOf("TablePage=9568654") != -1) {
	if (document.cookie.indexOf("country=JPN") != -1) {
	document.location.replace(sAuthor + "/labware/labware-catalog-jp.html");
	} else {document.location.replace(sAuthor + "/labware/labware-catalog.html");
	}
}

function getElAbsX(elName)
{
  el = document.getElementById(elName);
  x = -10;
  while (el != document.body && el!=null)
  {
    x += el.offsetLeft;
    el = el.offsetParent;
  }
  return x;
}

function getElAbsY(elName)
{
  el = document.getElementById(elName);
  y = 0;
  while (el != document.body && el!=null)
  {
    y += el.offsetTop;
    el = el.offsetParent;
  }
  return y;
}

var baseName;
var x;
var y;

function isElScrollable()
{
  var contentHeight = document.getElementById(baseName + 'ItemContent').offsetHeight;
  var clipHeight = document.getElementById(baseName + 'ItemContainer').offsetHeight;
  return (contentHeight > clipHeight);
}

function setupEl(elBaseName)
{
  baseName = elBaseName;
  if (isElScrollable())
  {
    document.getElementById('ScrollUpContainer').style.width=document.getElementById(elBaseName + 'ItemContent').offsetWidth;
    document.getElementById('ScrollUpContainer').style.height='21px';
    document.getElementById('ScrollDownContainer').style.width=document.getElementById('ScrollUpContainer').style.width;
    document.getElementById('ScrollUpContainer').style.top=getElAbsY(elBaseName + 'Container')+'px';
    document.getElementById('ScrollUpContainer').style.left=getElAbsX(elBaseName + 'Container')+document.getElementById(elBaseName + 'Container').offsetWidth+'px';
    document.getElementById(elBaseName + 'ItemContainer').style.top=getElAbsY(elBaseName + 'Container')+document.getElementById('ScrollUpContainer').offsetHeight+'px';
    document.getElementById(elBaseName + 'ItemContainer').style.left=getElAbsX(elBaseName + 'Container')+document.getElementById(elBaseName + 'Container').offsetWidth+'px';
    document.getElementById('ScrollDownContainer').style.top=getElAbsY(elBaseName + 'ItemContainer')+document.getElementById(elBaseName + 'ItemContainer').offsetHeight+'px';
    document.getElementById('ScrollDownContainer').style.left=getElAbsX(elBaseName + 'Container')+document.getElementById(elBaseName + 'Container').offsetWidth+'px';
  }
  else
  {
    document.getElementById(elBaseName + 'ItemContainer').style.top=getElAbsY(elBaseName + 'Container')+'px';
    document.getElementById(elBaseName + 'ItemContainer').style.left=getElAbsX(elBaseName + 'Container')+document.getElementById(elBaseName + 'Container').offsetWidth+'px';
    document.getElementById(elBaseName + 'ItemContainer').style.height=document.getElementById(elBaseName + 'ItemContent').offsetHeight+'px';
  }
  y=0;
  document.getElementById(elBaseName + 'ItemContent').style.left="0px";
  document.getElementById(elBaseName + 'ItemContent').style.top="0px";
  showEl();
}

function hideEl()
{
  document.getElementById('ScrollUpContainer').style.visibility='hidden';
  document.getElementById('ScrollDownContainer').style.visibility='hidden';
    
 if (baseName != undefined){
  	document.getElementById(baseName + 'ItemContainer').style.visibility='hidden';
  	document.getElementById(baseName + 'ItemContent').style.visibility='hidden';
  }
}

function showEl()
{
  if (isElScrollable())
  {
    document.getElementById('ScrollUpContainer').style.visibility='visible';
    document.getElementById('ScrollDownContainer').style.visibility='visible';
  }
  if (baseName != undefined)
  { 
  	document.getElementById(baseName + 'ItemContainer').style.visibility='visible';
  	document.getElementById(baseName + 'ItemContent').style.visibility='visible';
  }
}

var speed=50;
var loop, timer;

function moveEl(move)
{
  y = move;
  document.getElementById(baseName + 'ItemContent').style.top = y;
}

function scrollUp(yinc)
{
  if(y<0){
    moveEl(y-yinc);
    if(loop)
      timer = setTimeout("scrollUp("+yinc+")",speed);
  }
}

function scrollDown(yinc)
{
  if(y>-document.getElementById(baseName + 'ItemContent').offsetHeight+document.getElementById(baseName + 'ItemContainer').offsetHeight){
    moveEl(y-yinc);
    if(loop)
      timer = setTimeout("scrollDown("+yinc+")",speed);
  }
}

function performScroll(yinc)
{
  loop=true;
  if(yinc>0)
    scrollDown(yinc);
  else
    scrollUp(yinc);
}

function scrollStop()
{
  loop=false;
  if(timer) clearTimeout(timer);
}

/**************************************************************
tooltip.js
***************************************************************/
	document.write("<DIV ID=tooltip>");
	document.write("</DIV>");
	gPopupWin = 0;
	popupXoffset=-60;    // modify these values to ...
	popupYoffset= 20;    // change the popup position.
	
	var popupold,popupskn,popupiex=(document.all),yyy=-1000;
	
	var popupns4=document.layers
	var popupns6=document.getElementById&&!document.all
	var popupie4=document.all
	var tooltiptimer;
	
	if (popupns4)
	popupskn=document.tooltip
	else if (popupns6)
	popupskn=document.getElementById("tooltip").style
	else if (popupie4)
	popupskn=document.all.tooltip.style
	if(popupns4)document.captureEvents(Event.MOUSEMOVE);
	else{
	popupskn.visibility="visible"
	popupskn.display="none"
	}
	document.onmousemove=popupget_mouse;

function tooltip(msg,bak){
	var popupcontent="<TABLE class=normal style=\"font-size: 70%;\" WIDTH=200 BORDER=1 BORDERCOLOR=black CELLPADDING=3 CELLSPACING=0 "+
	"BGCOLOR=\""+bak+"\"><TD ALIGN=left>"+msg+"</TD></TABLE>";
	yyy=popupYoffset;
	tooltiptimer = setTimeout("tooltipdisplay('" + popupcontent + "')", 1000);
} 

function tooltip2(msg, bak){
	var popupcontent="<table id=\"popupTable\" class=\"\"  style=\"\" WIDTH=\"300\" BORDER=\"1\" BORDERCOLOR=\"black\" CELLPADDING=\"5\" CELLSPACING=\"0\" "+
	"BGCOLOR=\""+bak+"\"><tr><td align=left>"+msg+"</td></tr></table>";
	yyy=popupYoffset;
	
	//if(popupns4){popupskn.document.write(popupcontent);popupskn.document.close();popupskn.visibility="visible";}
	if(popupns6){
		//document.getElementById("tooltip").innerHTML = popupcontent;popupskn.display='';
	}
	//if(popupie4){document.all("tooltip").innerHTML=popupcontent;popupskn.display='';}
	
	//tableHeight = document.getElementById("tooltip").offsetHeight;
}

function tooltipdisplay(popupcontent){
	 if(popupns4){popupskn.document.write(popupcontent);popupskn.document.close();popupskn.visibility="visible"}
	 if(popupns6){document.getElementById("tooltip").innerHTML=popupcontent;popupskn.display=''}
	 if(popupie4){document.all("tooltip").innerHTML=popupcontent;popupskn.display=''}
}
 
function popupget_mouse(e){
	var x=(popupns4||popupns6)?e.pageX:event.x+document.body.scrollLeft;
	popupskn.left=x+popupXoffset;
	var y=(popupns4||popupns6)?e.pageY:event.y+document.body.scrollTop;
	popupskn.top=y+yyy;
}

function tooltipkill(){
	yyy=-1000;
	if(popupns4){popupskn.visibility="hidden";}
	else if (popupns6||popupie4)
	popupskn.display="none"
	if(tooltiptimer) clearTimeout(tooltiptimer);
}
 

function resetTable()
{  
	var url = location.href;
	window.location.href = url;
}

function submitRefinement(command, refinementNumber) 
{   
	if (command =='Refine'){   
			var url = location.href;
			var iof = url.indexOf("?");
			if (iof > 0)
			{
				url = url.substring(0,iof);
			}

			var intIndexOfMatch = refinementNumber.indexOf(" "); 
			// Loop over the string value replacing all space with $
			 while (intIndexOfMatch != -1){			  
				 refinementNumber = refinementNumber.replace(/ /,"$"); 	 
				 intIndexOfMatch = refinementNumber.indexOf(" ");
			 }
			 
			qs = window.location.search.substring(1);
			qsList = qs.split("&");
			for (i=0;i<qsList.length;i++)
			{
				if (qsList[i].indexOf("refinementValue") < 0 )
				{
					if (i==0)
					{
						url = url + '?' + qsList[i];
					}
					else
					{
						url = url +  '&' + qsList[i];
					}
				}else{
				
					if (i==0)
					{ 
						url = url + '?refinementValue=' + refinementNumber;
					}
					else
					{
						url = url + '&refinementValue=' + refinementNumber;
					}
				}
			} 
			 
			if(url.indexOf("refinementValue")<0){
				if(url.indexOf("?")<0){
					url = url + '?refinementValue=' + refinementNumber;
				}else{
					url = url + '&refinementValue=' + refinementNumber;
				}
			}
			
			location.href=url;
			return;
	} 
}
 
	function submitAddToCartProduct(brandkey, materialNumber)
	{ 
		var Qty = 1;
		document.ProductAddToCart.Brand.value = brandkey;
		document.ProductAddToCart.ProdNo_0.value = materialNumber;
		document.ProductAddToCart.MatNo_0.value = "";
		document.ProductAddToCart.Qty_0.value = Qty;	 
		document.ProductAddToCart.URL.value = location.href;	 
		document.ProductAddToCart.submit();
		// remember the screen position
		//document.cookie = "screenPosition=" + document.body.scrollTop + ";";
	}
	 
	function zoomImage(caption, imageURL)
	{
		
		if (caption != "")
		{
		caption = "    <" + "B" + ">Caption<" + "/B><" + "BR>\n" + caption;
		}
		var popupHtml = "<" + "HTML" + ">\n" +
	    				"<STYLE type=text/css> .printIcon {display: inline;cursor: pointer;background-image: url(\"/etc/medialib/sigma-aldrich/headers/endeca-search-and/print_icon.Par.0001.Image.gif\");width: 14px;height: 15px;}</STYLE>"+
	                    "<" + "BODY" + ">\n" + 
	                    "  <" + "STYLE type=text/css" + "><" + "!--\n" +
	                    "      .one { FONT: 11px/13px Arial, Helvetica, sans-serif }\n" +
	                    "      .normal { FONT: 13px/15px Arial, Helvetica, sans-serif }\n" +
	                    "  --" + ">" + "<" + "/STYLE" + ">\n" +
	                    "  <" + "DIV class=\"normal\"" + ">\n" + 
	                    "    <" + "SPAN style=\"color: red; font-weight: 900; font-size: 2em; line-height: 1.2em;\"" + ">" + "<" + "SPAN style=\"font-size: .8em; \"" + ">" + "<" + "SUP" + ">" + "&copy;" + "<" + "/SUP" + ">" + "<" + "/SPAN" + ">" + "www.sigma-aldrich.com" + "<" + "HR style=\"color: red; height: 4px;\"" + ">" + "<" + "/SPAN" + ">\n" + 
	                    "    <" + "BR" + ">\n" + 
	                    "    <" + "P align=center" + ">" + "<" + "IMG src=\"" + imageURL + "\"" + ">" + "<" + "/P" + ">\n" + 
	                    "<SPAN style=\"line-height: 1.4em;\">\n" + 
	                    "<DIV style=\"line-height: 1.6em;\">"+caption + "</DIV>"+
	                    "</SPAN>\n"+
	                    "<BR><BR><a href='#' onclick='window.print();'><DIV class=\"printIcon\"><!-- --></DIV><SPAN style=\"font-size: 11px;\">&nbsp;Print</SCAN></a>\n"+
	                    "  <" + "/DIV" + ">\n" + 
	                    "<" + "/BODY" + ">\n" + 
	                    "<" + "/HTML" + ">\n";
	    viewPopupPage('',650,680,'yes');
	    gPopupWin.document.open();
	    gPopupWin.document.write(popupHtml);
	    gPopupWin.document.close();
	}
	function dropDownHandler(myform)
	{
		if ( document.searchForm.searchprop.options[document.searchForm.searchprop.selectedIndex].value == 'RNAI' )
		{
	  		window.location.href ="/insite_mission_target_search";
		}
		else if ( document.searchForm.searchprop.options[document.searchForm.searchprop.selectedIndex].value == 'SIRNA' )
		{
    	   window.location.href ="/insite_your_favorite_gene_search";
		}		
    }    

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13)
	{
		document.searchForm.refinementValue.value = 'ENTER';
    	document.searchForm.btnSearchFromCornerBox.click();
		return false;
	}
	else
	return true;
}
function printPreview()
{
    var loc = location.search;
    if (loc == "")
        loc += "?";
    else
        loc += "&";
    loc += "PrtPrv=20388431";
    if (typeof(imageLen) != "undefined" && imageLen != 0)
        loc += "&Img=" + imageNum;
      window.open(loc);
}

function redirectURL(url){
	document.cookie = "screenPosition=" + document.body.scrollTop + ";";
	window.location.href = url;
}

function checkAndSubmitAddToCartProduct(isCartShown, brandkey, materialNumber)
{ 
	if(isCartShown.toLowerCase() == 'false'){
	   window.location.href = '/webapp/wcs/stores/servlet/LogonForm?storeId=11001&langId=-1'; 
	}else{
	   submitAddToCartProduct(brandkey, materialNumber);
	}
}

//reskin - update OPC page to match the style of PDP and SRP
 //Tool-Tip
   function toolTipToggler(ths){  
       // jQuery(".opcContainer .tool-tip").not(jQuery(ths).parent("p").siblings(".opcContainer .tool-tip")).hide(); 
        if(jQuery(ths).parent("p").siblings(".tool-tip").is(":hidden")){    		
    		jQuery(ths).closest(".opcContainer").find(".tool-tip").hide(); 
	       jQuery(ths).parent("p").siblings(".tool-tip").fadeIn().parent("div").css("position","relative");
	       
        }else{
            jQuery(ths).closest(".opcContainer").find(".tool-tip").hide();
   	        jQuery(ths).parent("p").siblings(".tool-tip").css({"display":"none"}).parent("div").css("position","relative");  
        }           
     };
     
  	function toolTipClose(ths){
    	jQuery(ths).closest(".tool-tip").css("display","none");
	}
	  
	function addAllToCart(ths){
	   
	    var itemArray = new Array(); 
	    var i = 0;
	
	    var input = jQuery(ths).closest(".bulk-cart").prev("table").find(".quantity-input");
    	input.each(function(index) {

	        var quantity = jQuery(this).val();
	        var sku = jQuery(this).siblings(".sku").val();
	        var brand = jQuery(this).siblings(".brand").val(); 
	        if (Math.floor(quantity).toString() == quantity.toString() && quantity > 0) { 
	            itemArray[i] = new Array(); 
	             itemArray[i]["sku"] = sku;
	            itemArray[i]['quantity'] = quantity;
	            itemArray[i]["brand"] = brand;
	            i++;
	        } else { 
	            //the user either did not enter a quantity for a particular product            
	        }
	    });
	
	    if(itemArray.length > 0){
	        submitAddToCartProductRS_jquery(itemArray);
	    }else{
	        //the user did not enter a quantity for a particular product
	       // alert("please enter quantity");
	        jQuery(ths).find(".addToCartErrorText").show();
	        input.each(function(index) {
	          jQuery(this).css("border","1px solid #E86F6B");
	        });
	    }
	}
    
//this func over-write the same one on DAY. once we more to DAY, the old one can be removed
//by default, the quantity of each material used to be blank, now '0', so add new logic to take care of quantity=0 
function submitAddToShelfProduct(brandkey, productNumber, materialNumber)
{
	var Qty = document.getElementById(materialNumber).value;
	if (Qty == "" || Qty == "0")
	{
		Qty=1;
	}

	var descriptionField = "Desc"+materialNumber;
	var description = document.getElementById(descriptionField).value;	

	var ProductAddToShelf = document.getElementById('ProductAddToShelfForm');
	ProductAddToShelf.Desc.value = description;
	ProductAddToShelf.Brand.value = brandkey;
	ProductAddToShelf.ProdNo_0.value = materialNumber;
	ProductAddToShelf.chkAdd0.value = materialNumber;
	ProductAddToShelf.MatNo_0.value = "";
	ProductAddToShelf.Qty_0.value = Qty;
	var iof = location.href.indexOf("?");
	if (iof == -1)
		ProductAddToShelf.URL.value =  location.href + "?AddToFav=Search";
	else
		ProductAddToShelf.URL.value =  location.href + "&AddToFav=Search";

	counter++;
	if(counter > 1) 
	{ 
		return false; 
	} 
	ProductAddToShelf.submit();
}

//failure function for both PDP and SRP pages
function failurePriceFunctionRS(o)
{ 	 
	jQuery("#priceErrorMsg a").attr("href","/technical-service-home.html?cm_sp=DiscontinuedProduct-_-TService-_-"+ cmProductNumber); 
	document.getElementById(o.argument).innerHTML = document.getElementById("priceErrorMsg").innerHTML;
}

//success function for product details page	
function successPriceFunctionRS_PDP(o)
{ 
	    try
		{
			var xmlDoc = "";
			if(o.responseXML != null){
				var xmlDoc = o.responseXML.documentElement;
			}						 
			xmlDoc=o.responseText;
			
			//Coremetrics tags for Discontinued Product debug - Product Detial
			if (window.location.href.indexOf('ProductDetail.do') >=0 && xmlDoc.indexOf('cm_sp=DiscontinuedProduct-_-TService') >=0) {
				cmCreatePageviewTag('PRODUCT: '+ cmBrandKey +' (' + cmProductNumber +')', 'PD_DEBUG');
			}
			//End CM Tags
			
			document.getElementById(o.argument).innerHTML = xmlDoc;		
		}
		catch(err)
		{
				failurePriceFunctionRS(o);
		} 
}

//success function for search results page
function successPriceFunctionRS_SRP(o)
{ 
	    var divID =	o.argument;	 
	    try{
			var xmlDoc = o.responseText;	
			if(xmlDoc == null || xmlDoc.length == 0){
			   failurePriceFunctionRS(o);
			}else{			
				//Coremetrics tags for Discontinued Product debug - Search Results Page
				if (window.location.href.indexOf('Lookup.do') >=0 && xmlDoc.indexOf('cm_sp=DiscontinuedProduct-_-TService') >=0) {
					cmCreatePageviewTag('PRODUCT: '+ cmBrandKey +' (' + cmProductNumber +')', 'SR_DEBUG');
				}	
				//End CM Tags								
				document.getElementById(divID).innerHTML = xmlDoc;				 
			}
		}
		catch(err)
		{		
		    failurePriceFunctionRS(o);;
		} 
}
	
function setupPendingRS(divId){ 
		if(document.getElementById(divId))
			document.getElementById(divId).innerHTML = '<div class="priceAvailLoading"><img src="' + getRedCubeImg() + '" >&nbsp;Loading Price & Availability Information</img></div>';
}


//P&A on PDP
function loadPA_RS(productNumber, brandKey, divID){ 
	var loadFor ='PRD_RS';  

//Set Coremetrics global debug variables for Detail Pages
	cmBrandKey = brandKey;
	cmProductNumber = productNumber;
	var catalog =  getContextPath();
	var pricingUrl = catalog + '/PricingAvailability.do?productNumber='+productNumber+'&brandKey='+brandKey+'&divId='+divID;		
	var postData = 'loadFor=' +loadFor;				
	setupPendingRS(divID); 
	
	jQuery.ajax({
		url: pricingUrl,
		data: postData,
		dataType: "html",
		error: function(jqXHR, textStatus, errorThrown) {
			var o = new Object();
			o.argument = divID;
			failurePriceFunctionRS(o);
		},	
		success: function(data, textStatus, jqXHR){
			var o = new Object();
			o.responseText = data;
			o.argument = divID;
			successPriceFunctionRS_PDP(o);
		},
		timeout: 50000,
		type: "POST"
	});
	
}
  
//run this when arrow next to pricing link is clicked
function clickPricingArrow(ths){
	 var priceLink = jQuery(ths).closest(".row").find("li.priceValue div a.text");               
             priceLink.trigger('click');
             return false; 
}

//run this when SRP pricing button is clicked
function openPAOnSR_RS(productNumber, brandKey, divID, pricingButtonId, page){ 
 	//flip arrow image next to pricing link
    jQuery("#"+pricingButtonId).closest(".row").find("li.expandArrow a").css("background-position","-92px -10px");   	
     
 	//show p&a clip div
	jQuery("#"+divID).css("display","block"); 
	          
	var button = document.getElementById(pricingButtonId); 	        
	var closeButtonText  = "close"; 
	try{
		closeButtonText  = document.getElementById("closeButton").value; 
	}
	catch(ignore){}
 
	if(page!=null){
		button.innerHTML ="<a class='text' onclick=\"javascript:closePAOnSR_RS(\'" + productNumber + "\', \'" + brandKey + "\',\'" + divID + "\',\'" + pricingButtonId + "\',\'"+page+"\');cmTagAndLink('Close Pricing', '"+page+"',null,null,null);\">"+closeButtonText+"</a>";
	}
	else{
		button.innerHTML ="<a class='text' onclick=\"javascript:closePAOnSR_RS(\'" + productNumber + "\', \'" + brandKey + "\',\'" + divID + "\',\'" + pricingButtonId + "\',\'"+page+"\');cmTagAndLink('Close Pricing','Search Result Page Details',null,null,null);\">"+closeButtonText+"</a>";
	}
	loadPAOnSR_RS(productNumber, brandKey, divID);
}
	
//P&A for SRP exact match		
function loadPAOnSR_RS(productNumber, brandKey, divID){  
    var loadFor ='SR_RS';   
//Set Coremetrics global debug variables for Detail Pages
	cmBrandKey = brandKey;
	cmProductNumber = productNumber;
	var catalog =  getContextPath();
	var pricingUrl = catalog + '/PricingAvailability.do?productNumber='+productNumber+'&brandKey='+brandKey+'&divId='+divID;		
	var postData = 'loadFor=' +loadFor;				
	setupPendingRS(divID); 
	
	jQuery.ajax({
		url: pricingUrl,
		data: postData,
		dataType: "html",
		error: function(jqXHR, textStatus, errorThrown) {
			var o = new Object();
			o.argument = divID;
			failurePriceFunctionRS(o);
		},	
		success: function(data, textStatus, jqXHR){
			var o = new Object();
			o.responseText = data;
			o.argument = divID;
			successPriceFunctionRS_SRP(o);					
		},
		timeout: 50000,
		type: "POST"
	});
	
}

//run this when SRP close button is clicked
function closePAOnSR_RS(productNumber, brandKey, divID, pricingButtonId, page){ 
 	//flip arrow image next to pricing link
	jQuery("#"+pricingButtonId).closest(".row").find("li.expandArrow a").css("background-position","-73px -10px");              
       
	jQuery("#"+divID).css("display","none");
	 var button = document.getElementById(pricingButtonId);			 
	 var pricingButtonText  = "pricing";
	 try{			  
	   pricingButtonText  = document.getElementById("pricingButton").value;
	 }catch(ignore){}
		 if (page!=null){
	 		 button.innerHTML ="<a class='text' onclick=\"javascript:openPAOnSR_RS(\'" + productNumber + "\', \'" + brandKey + "\',\'" + divID + "\',\'" + pricingButtonId + "\',\'"+page+"\');cmTagAndLink('Open Pricing','"+page+"',null,null,null);\">"+pricingButtonText+"</a>";
		 }else{		     
	 		 button.innerHTML ="<a class='text' onclick=\"javascript:openPAOnSR_RS(\'" + productNumber + "\', \'" + brandKey + "\',\'" + divID + "\',\'" + pricingButtonId + "\',\'"+page+"\');cmTagAndLink('Open Pricing','Search Result Page Details',null,null,null);\">"+pricingButtonText+"</a>";
		 }
		 var priceDiv = document.getElementById(divID);
		 priceDiv.innerHTML ="";		 		 
		
} 

//P&A on tool tip
function loadPAForMat_RS(matNo, productNumber, brandKey, quantityinputbox, availabilitymessagediv){ 	
		  
	var Qty =1; 
	try{
		 Qty = document.getElementById(quantityinputbox).value;	 
		 if (Qty == "")			  
		 	Qty=1;	 
	 }catch(ignore){ 
	 }  
	 
	var catalog = getContextPath(); 
	var catalogUrl = catalog + '/PricingAvailability.do?productNumber='+productNumber+'&brandKey='+brandKey;	 
	var postData='MatNo' + matNo +'=' + Qty+ '&loadFor=MAT_LD';	 
	var matRow = document.getElementById(availabilitymessagediv);  
	matRow.innerHTML = '<img src="' + getRedCubeImg() + '">&nbsp;Checking availability</img>'; 
	
	jQuery.ajax({
		url: catalogUrl,
		data: postData,
		dataType: "html",
		error: function(jqXHR, textStatus, errorThrown) {
			var o = new Object();
			o.argument = availabilitymessagediv;
			failurePriceRowLDFunction(o);
		},	
		success: function(data, textStatus, jqXHR){
			var o = new Object();
			o.responseText = data;
			o.argument = availabilitymessagediv;
			successPriceRowLDFunction(o);
		},
		timeout: 50000,
		type: "POST"
	}); 
}

//add to cart from P&A clip: add multiple materials at one time
function submitAddToCartProductRS_jquery(array){
	if(array!=null && array.length>0){
		var brand ="";
		for(var i=0; i<array.length; i++){
			var item = array[i];
			var matNo=item["sku"];
		    brandkey= item["brand"];
			var qty = item["quantity"];
			jQuery('#ProductAddToCartForm_all').append("<input type='hidden' name='ProdNo_"+i+"' value='"+ matNo+"'>");
					jQuery('#ProductAddToCartForm_all').append("<input type='hidden' name='chkAdd"+i+"' value='"+ matNo+"'>");					
					jQuery('#ProductAddToCartForm_all').append("<input type='hidden' name='MatNo_"+i+"' value='"+ "'>");
					jQuery('#ProductAddToCartForm_all').append("<input type='hidden' name='Qty_"+i+"' value='"+ qty+"'>");	
		}
		jQuery('#rs_brand').val(brandkey);			
	    jQuery('#rs_url').val(location.href);
	    jQuery('#ProductAddToCartForm_all').submit();
	}
}
 
 //add to cart from tool tip: add only single material
function submitAddToCartProductQuantity_RS(brandkey, materialNumber, quantityinputbox)	{ 
	var Qty =1;
		try{
			 Qty = document.getElementById(quantityinputbox).value;			
			 if (Qty == "")			  
			 	Qty=1;		 
		 }catch(ignore){} 
		 
	var ProductAddToCart = 	document.getElementById('ProductAddToCartForm_single');	
	ProductAddToCart.Brand.value = brandkey;
	ProductAddToCart.ProdNo_0.value = materialNumber;
	ProductAddToCart.chkAdd0.value = materialNumber;
	ProductAddToCart.MatNo_0.value = "";
	ProductAddToCart.Qty_0.value = Qty;	 
	ProductAddToCart.URL.value = location.href;	 
	counter++;
	if(counter > 1) 
	{ 
		return false; 
	}
	ProductAddToCart.submit();
} 

//sort opc table and flip up/down arrow	
  function sortReskinTableOPCWithPricing(ths, id,col,rev,table) { 
	if(jQuery(ths).hasClass('active')){
		jQuery(ths).find('p.arrowContainer').toggleClass('sortArrowDown sortArrowUp');
	}else{
		var activeCol = jQuery(ths).closest('tr').children('.active');
		activeCol.removeClass('active');
		activeCol.find('p.arrowContainer').removeClass('sortArrowDown sortArrowUp'); 

		jQuery(ths).addClass('active');
		jQuery(ths).find('p.arrowContainer').addClass('sortArrowDown'); 
	}
	 
	 //call old sort func
 	sortTableOPCWithPricing(id,col,rev,table); 	
  }
    
	//View tool-tip	for OPC refinements   
    function  toggleOPCRefinements(e, ths){ 
    	  if (!e) var e = window.event;
				e.cancelBubble = true;				 
			if (e.stopPropagation) 
				e.stopPropagation();
				 
	       // jQuery(".opcContainer .ref-tool-tip").not(jQuery(ths).siblings(".opcContainer .ref-tool-tip")).hide();  	   
	        if(jQuery(ths).siblings(".ref-tool-tip").is(":hidden")){
	            jQuery(ths).closest(".opcContainer").find(".ref-tool-tip").hide();
    			jQuery(ths).siblings(".ref-tool-tip").fadeIn().parent("div").css("position","relative");
				jQuery(ths).css("background-position","-54px -10px");
	        }else{      
	            jQuery(ths).closest(".opcContainer").find(".ref-tool-tip").hide();	        
       			jQuery(ths).siblings(".ref-tool-tip").css({"display":"none"}).parent("div").css("position","relative"); 
	            jQuery(ths).css("background-position","-34px -10px"); 
	        }  
	       	        
            return false;         
	}
//end of reskin
 
