
function imHi(imName){
 if (document.images) {
 document[imName].src = "images/" + imName + "H.gif";
 }
}
function imLo(imName){
 if (document.images) {
 document[imName].src = "images/" + imName + ".gif";
 }
}

// Tooltip code

var offsetxpoint=-60;
var offsetypoint=20;
var scrollbarWidth;
var ie=!!document.all && !window.opera;
var ns6=document.getElementById && !document.all;
var enabletip=false;
var tipobj;
var objBubble;
var objBubImg;
var oldOnload;
var imgProgress=new Image();
imgProgress.src="images/progressbar.gif";

function bubble_init(){
tipobj=document.getElementById("dhtmltooltip");
objBubble=document.getElementById("bubblebox");
objBubImg=document.getElementById("bubbleimg");
objBubImg.style.margin="170px";
objBubImg.src=imgProgress.src;
objBubImg.onload=bubbleLoaded;
document.onmousemove=positionAll;
scrollbarWidth=getScrollerWidth()+7;
}

addEvent(window, 'load', bubble_init);


function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function positionAll(e){
positiontip(e);
positionBubble(e);
}

/*var objBody = document.getElementsByTagName("body").item(0);
// objOverlay.onclick = function() { func1(); return false; }

var objBubble = document.createElement("div");
objBubble.setAttribute('id','bubblebox');
// objBubble.style.display = 'none';
objBody.appendChild(objBubble);

var objBubImg = document.createElement("img");
objBubImg.style.border=0;
objBubImg.src='prodim/100x100/earrings/E00001/E00001_5247.jpg';
objBubble.appendChild(objBubImg);
*/

var bAddX=30;
var bAddY=30;
var bubbleImLoaded=false;
var enableBubble=false;
var tBubble;

function bubbleLoaded() { 
bubbleImLoaded=true;
//alert(enableBubble && bubbleImLoaded);
//  return false; 
 }
//objBubImg.onload=function() { bubbleLoaded=true; return false; }

function openBubble(url){
 objBubImg.onload=bubbleLoaded;
 objBubImg.src=url;
 enableBubble=true;
 objBubImg.style.margin="0";
 tBubble=setTimeout("timerTicked()",500);
 return false;
}

function timerTicked(){
 if(enableBubble){
  switchSelects('hidden');
  objBubble.style.visibility='visible';
  enableBubble=false;
 }
}

function positionBubble(e){
// if(enableBubble && bubbleImLoaded){
 if(enableBubble){
 var wTop=ie? ietruebody().scrollTop : window.pageYOffset;
 var clientY=ie? event.clientY : e.clientY;
 var wLeft=ie? ietruebody().scrollLeft : window.pageXOffset;
 var clientX=ie? event.clientX : e.clientX;
  
 var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
 var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
 var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-bAddX : 
     window.innerWidth-e.clientX-bAddX-scrollbarWidth;
 var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-bAddY :
    window.innerHeight-e.clientY-bAddY-scrollbarWidth;
 var jX;
  if(rightedge<objBubble.offsetWidth)
   jX=wLeft + clientX-objBubble.offsetWidth-bAddX;
  else 
   jX=curX+bAddX;
  if(wLeft>jX)
   jX=wLeft+bAddX;
 objBubble.style.left=jX+"px";
 
 var jY;  
  if(bottomedge<objBubble.offsetHeight)
   jY=wTop+clientY-objBubble.offsetHeight-bAddY;
  else
   jY=curY+bAddY;
  if(wTop>jY)
   jY=wTop+bAddY;
 objBubble.style.top=jY+"px";
 
// if(bottomedge)
// alert(wTop + " ::: " + objBubble.style.top);
// objBubble.style.visibility="visible";
// enableBubble=false;
 }
}


function closeBubble(){
 enableBubble=false;
 bubbleImLoaded=false;
 objBubble.style.visibility='hidden';
 objBubble.style.left='-1000px';
 objBubImg.style.margin='170px';
 objBubImg.src=imgProgress.src; 
 switchSelects('visible');
}


var clickmsgtext;
function setClickMessage(elem, msg){
 elem.onclick=clicktip;
 clickmsgtext=msg;
}

function clicktip(e){
tipobj.innerHTML=clickmsgtext.replace(/\n/g, "<br>");
 var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
 var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
 var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : 
     window.innerWidth-e.clientX-offsetxpoint-scrollbarWidth;
 var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint :
    window.innerHeight-e.clientY-offsetypoint-scrollbarWidth;
 var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;
  if (rightedge<tipobj.offsetWidth)
   tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : 
    window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
  else if (curX<leftedge)
   tipobj.style.left="5px";
  else
   tipobj.style.left=curX+offsetxpoint+"px";
  if (bottomedge<tipobj.offsetHeight)
   tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" :  window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
  else
   tipobj.style.top=curY+offsetypoint+"px";
 tipobj.style.visibility="visible";
}

function openTip(thetext, thecolor, thewidth){
if (ns6||ie){
 if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"; else tipobj.style.width="200px";
 if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor; else tipobj.style.backgroundColor='#FFFFFF';
 tipobj.innerHTML=thetext.replace(/\n/g, "<br>");
 enabletip=true;
 return false;
 }
}

function positiontip(e){
 if (enabletip){
 var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
 var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
 var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : 
      window.innerWidth-e.clientX-offsetxpoint-scrollbarWidth;
 var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint :
    window.innerHeight-e.clientY-offsetypoint-scrollbarWidth;
 var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;
  if (rightedge<tipobj.offsetWidth)
   tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : 
    window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
  else if (curX<leftedge)
   tipobj.style.left="5px";
  else
   tipobj.style.left=curX+offsetxpoint+"px";
  if (bottomedge<tipobj.offsetHeight)
   tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" :  window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
  else
   tipobj.style.top=curY+offsetypoint+"px";
 tipobj.style.visibility="visible";
 }
}

function closeTip(){
 if (ns6||ie){
 enabletip=false;
 tipobj.style.visibility="hidden";
 tipobj.style.left="-1000px";
 //tipobj.style.backgroundColor='';
 //tipobj.style.width='';
 }
}

function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;

    // Remove the scrolling div from the doc
    document.body.removeChild(
        document.body.lastChild);

    // Pixel width of the scroller
    return (wNoScroll - wScroll);
}


var oneWindow;
function popup(url, thetitle, thewidth, theheight){
xposition=0; yposition=0; 
width=400; height=400; title='';
 if (typeof thewidth!="undefined") width = thewidth;
 if (typeof theheight!="undefined") height = theheight;
 if (typeof thetitle!="undefined") title = thetitle;
 
 if (parseInt(navigator.appVersion) >= 4 ){ 
 xposition = (screen.width - width) / 2; 
 yposition = (screen.height - height) / 2; 
 }

args = "width=" + width + ",height=" + height 
+ ",location=0,menubar=0,resizable=0,scrollbars=2,status=0,titlebar=0,toolbar=0,hotkeys=0"
+ ",screenx=" + xposition
+ ",screeny=" + yposition
+ ",left=" + xposition
+ ",top=" + yposition;
oneWindow = window.open(url,'onePopup',args);
oneWindow.focus();
return false;
}

 
 function addEvent(elem, type, handler){
  if (elem.addEventListener)
   elem.addEventListener(type, handler, false);
  else if (elem.attachEvent)
   elem.attachEvent("on" + type, handler);
 }


 function switchSelects(v){
// alert(ie);
 if(ie)
  for(var f=0; f<document.forms.length; f++)
   for(var e=0; e<document.forms[f].length; e++)
    if (document.forms[f].elements[e].options)
     document.forms[f].elements[e].style.visibility = v; 
 }




/***************** Product description page */
addEvent(window, 'load', prod_init);
 
 var gObj, gImg, pWnd, fObj, cBtn, exIMG;
 var topSpace=0;
 var imgMargin=20;
 var gObjClosed=true;
 
 function prod_init(){
 gObj=document.getElementById("giantimage");
 gImg=document.getElementById("giantImg");
 fObj=document.getElementById("faded");
 cBtn=document.getElementById("giantCloseBtn");
 pWnd=document.getElementById("progressWnd");
 pWnd.style.position="absolute";
 }
 
 function styleOpac(obj, p){
  s=obj.style;
  s.opacity=(p/100); 
  s.MozOpacity=(p/100); 
  s.KhtmlOpacity=(p/100); 
  s.filter="alpha(opacity="+p+")"; 
 }

 function openGiant(url){

 gObj.style.left=ie? ietruebody().scrollLeft : window.pageXOffset;
 gObj.style.top=ie? ietruebody().scrollTop : window.pageYOffset;
 gObj.style.width=document.body.clientWidth ? (ie?document.body.clientWidth:document.body.clientWidth-7) : window.innerWidth-25;
 gObj.style.height=document.body.clientHeight ? (ie?document.body.clientHeight:document.body.clientHeight-7) : window.innerHeight-25;
 fObj.style.left=gObj.style.left;
 fObj.style.top=gObj.style.top;
 fObj.style.width=gObj.style.width;
 fObj.style.height=gObj.style.height;
 pWnd.style.left=parseInt((parseInt(gObj.style.width)-parseInt(pWnd.style.width))/2);
 pWnd.style.top=parseInt((parseInt(gObj.style.height)-parseInt(pWnd.style.height))/2) + topSpace;
 pWnd.style.visibility="visible";
 gImg.style.visibility="hidden";
 gObj.style.visibility="visible";
 fObj.style.visibility="visible";
 styleOpac(fObj, 60);
 exIMG = new Image();
 exIMG.onload=giantLoaded;
 gObjClosed=false;
 exIMG.src=url;
 }
 
 
 function giantLoaded(){
 if(gObjClosed) return;
 pWnd.style.visibility="hidden";
 k=(parseInt(exIMG.width) + imgMargin*2)/(parseInt(exIMG.height) + imgMargin*2);
 dH=parseInt(gObj.style.height) - topSpace;
 dW=parseInt(gObj.style.width);
  if(k < dW/dH){
   gImg.height=dH - imgMargin*2;
   gImg.width=parseInt((dH - imgMargin*2)*k);
  }else{
   gImg.width=dW - imgMargin*2;
   gImg.height=parseInt((dW - imgMargin*2)/k);
  }
 l=parseInt((dW-gImg.width)/2);
 gImg.style.left=l;
 gImg.style.top=parseInt((dH-gImg.height)/2) + topSpace;
 gImg.src=exIMG.src;
 cBtn.style.top=parseInt(gImg.style.top)+4;
 cBtn.style.left=parseInt(gImg.style.left)+parseInt(gImg.width)-parseInt(cBtn.width)-3;
 gImg.style.visibility="visible";
 gObj.style.visibility="visible";
 fObj.style.visibility="visible";
 cBtn.style.visibility="visible";
 }
 
 function closeGiant(){
 gObjClosed=true;
 fObj.style.visibility="hidden";
 cBtn.style.visibility="hidden";
 gObj.style.visibility="hidden";
 gImg.style.visibility="hidden";
 pWnd.style.visibility="hidden";
 gObj.style.left="-1000px";
 }
 
 var oldThumb=false;
 var giantUrl='';
 function openg(){
  openGiant(giantUrl);
 }
 
 var clickMsg="Sorry, no full screen image is available";
 function selMainView(thumbim, imsrc, gUrl){
 glnk=document.getElementById("openGlink");
 g=document.images['mainView'];
  if(gUrl.length==0){
  setClickMessage(g,clickMsg);
  g.onmouseout=closeTip;
   if(glnk){
   setClickMessage(glnk,clickMsg);
   glnk.onmouseout=closeTip;
   glnk.style.visibility='hidden';
   }
  }else{
  giantUrl=gUrl;
  g.onclick=openg;
   if(glnk){
   glnk.onclick=openg;
   glnk.style.visibility='visible';
   }
  }

 document.images['mainView'].src=imsrc;
 thumbim.className='p_thumbHi';
  if(oldThumb && oldThumb!=thumbim)
   oldThumb.className='p_thumb';
 oldThumb=thumbim;
 }
 
 function optionGoTo(elm,s){
 sel=document.getElementById(elm);
 window.location=s+sel.options[sel.selectedIndex].value;
 }


 /***************** Product description page ------------- end */


 /***************** Product search */

 function c_toggleSelectors(elm){
  s=document.getElementById('selectorsExtra');
  l=document.getElementById('selectorsShowLink');
  if(s && l)
   if(s.style.display==''){
    s.style.display = 'none';
    l.innerHTML='more&nbsp;options&nbsp;&gt;&gt;';
    }else{
    s.style.display = '';
    l.innerHTML='less&nbsp;options&nbsp;&lt;&lt;';
   }
 }

 /***************** Product search ------------- end */
 
 
 
 document.getElementsByClassName = function(cl) {
  var retnode = [];
  var myclass = new RegExp('\\b'+cl+'\\b');
  var elem = this.getElementsByTagName('*');
   for (var i = 0; i < elem.length; i++) {
   var classes = elem[i].className;
    if (myclass.test(classes)) retnode.push(elem[i]);
   }
  return retnode;
 };
