// 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);
	}
}