//window.myTimeOut;
var old = "";
var isactive;

function hideTimer(nm) {
     window.myTimeOut = setTimeout("hideLyr('"+nm+"')",500);
     isactive = "";
}
function hideLyr(nm) {
	if(nm != isactive){
		var lyr = document.getElementById(nm);
	    if(!lyr) {return;}
	    lyr.style.visibility = 'hidden';
    }
	manipulateSelects('visible');
}
function cTI(nm){
	isactive = nm;
	if(old!=null && old == nm) { 
		clearTimeout(window.myTimeOut);
	}
}

function manipulateSelects(show) {
	for (var i = 0; i<document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].type == 'select-one') {
			document.forms[0].elements[i].style.visibility = show;
		}
	}
}

function showMenu(id, lnk, w, xOffset, yOffset) {
	var lyr = document.getElementById(id);
	var t = document.getElementById(lnk.name);
/*
	var offsTop = 0;
	var offsLeft = 0;
	lyr.style.top = (getAnchorPosition(lnk.name)).y + lnk.offsetHeight + yOffset + 1+"px";
	lyr.style.left = xOffset + ((getAnchorPosition(lnk.name)).x - 10)+"px";
*/
	if(!lyr) {
		return;
	}
	lyr.style.visibility = 'visible';
	if(id!=old && old!="") {	
		var t = document.getElementById(old);
		if(t!=null) { t.style.visibility = 'hidden'; }
	}
	old = id;
	manipulateSelects('hidden');
}

/*
2) Your anchor tag MUST contain both NAME and ID attributes which are the 
   same. For example:
   <A NAME="test" ID="test"> </A>

*/ 
// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		//fix for netscape 7 works fine in ver 6 too
		//		x=o.offsetLeft;
		//		y=o.offsetTop;
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOinsertBeforeffsetTop(el)-document.body.scrollTop;
	}

function $id(id) {
	return document.getElementById(id);
}
function updateInnerHTML(obj, id, str) {
	$id(id).innerHTML = str;
}
function addClassName(obj, id, strClassName){
	var strCurrentClass = $id(id).className;
	if(!new RegExp(strClassName, "i").test(strCurrentClass)){
		$id(id).className = strCurrentClass + ((strCurrentClass.length > 0)? " " : "") + strClassName;
	}
}
function removeClassName(obj, id, strClassName){
	var oClassToRemove = new RegExp((strClassName + "\s?"), "i");
	$id(id).className = $id(id).className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, "");
}


/*
* for look 2
*/
function prepareMenu(){
  if(document.getElementById && document.getElementsByTagName){
    if(document.getElementById('tabmenu') ){
      var gallery = document.getElementById( 'tabmenu' );
      var links = gallery.getElementsByTagName( 'a' );
      for( var i=0; i < links.length; i++ ){
      	var found = false;
      	if(links[i].parentNode.attributes['class']) {
		    found = links[i].parentNode.attributes['class'].value=='active';
      	} else {
  	     	found = links[i].parentNode.getAttribute('class')=='active';
      	}
      	if(found) {
 			var id = links[i].id.substring(4,5);
 			var m = document.getElementById('sub'+id);
 			if(m) {
 				m.style.visibility = 'visible';
 			}
 			var ls = m.getElementsByTagName( 'a' );
		    for( var t = 0; t < ls.length; t++ ){
      			var fnd = false;
				fnd = (ls[t].search == window.location.search);
				if(fnd) {
					ls[t].setAttribute('id', 'active');
					return;
      			}
			} 			
      	}
      }
    }
  }
}
function addEvent2(obj, evType, fn, useCapture, params){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
  	obj.myparams = params;
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    r.myparams = params;
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

function addEvent(obj,type, fn, p ){
	obj["e"+type+fn] = fn;
	if (obj.addEventListener){
		eval( 'obj.addEventListener( type, function(event){	obj["e"+type+fn](event, ' + p + ')}, false );' 
		);
	} else if (obj.attachEvent){
		obj[type+fn] = function() { 
			eval ( 'obj["e"+type+fn](window.event, ' + p + ');' ); 
		}
		obj.attachEvent("on"+type, obj[type+fn]);
	}
}



addEvent(window, 'load', prepareMenu);
UIMessage = new Object();
/**
* private methods
**/
UIMessage._dn = function(uid, msg, cls) {
	addEvent(window, 'load', this._cn, "'"+uid+"', '"+msg+"', '"+cls+"'");
}
UIMessage._cn = function(obj, uid, msg, cls) {
	var doc = $id('messages');
	var newNode = document.createElement('DIV');
	var mess = '<div class="head"><h5>'+msg+'</h5></div>';
	newNode.className = "itembox centerbox "+cls;
	newNode.innerHTML = mess;
	doc.insertBefore(newNode,doc.firstChild);
	
	var r = $id(uid);
	if(r) {
		r = r.parentNode;
		var n = document.createElement('span');
		n.style.color='#f00';
		n.innerHTML=' (!)';
		r.appendChild(n);
	}
}
/**
* public methods
**/

//display node
UIMessage.dn = UIMessage._dn;





function DL_GetElementLeft(eElement) {
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE
                                     
   var nLeftPos = eElement.offsetLeft;       // initialize var to store calculations 
   var eParElement = eElement.offsetParent;  // identify first offset parent element                            

   while (eParElement != null)                 
   {                                         // move up through element hierarchy
      if(DL_bIE)
      {
         if(eParElement.tagName == "TD")     // if parent a table cell, then...
         {
            nLeftPos += eParElement.clientLeft; // append cell border width to calcs
         }
      }

      nLeftPos += eParElement.offsetLeft;    // append left offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nLeftPos;                          // return the number calculated
}
    
function DL_GetElementTop(eElement) {
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE
                                     
   var nTopPos = eElement.offsetTop;       // initialize var to store calculations 
   var eParElement = eElement.offsetParent;  // identify first offset parent element                            

   while (eParElement != null)                 
   {                                         // move up through element hierarchy
      if(DL_bIE)
      {
         if(eParElement.tagName == "TD")     // if parent a table cell, then...
         {
            nTopPos += eParElement.clientTop; // append cell border width to calcs
         }
      }

      nTopPos += eParElement.offsetTop;    // append top offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nTopPos;                          // return the number calculated
}
function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

var myImageTimer;
function etim() {
	window.clearTimeout(myImageTimer);
	var doc = $1('imgLyr');
	if(doc) {
		doc.style.display='none';
	}
}
function stim(str,e,id) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	var x = DL_GetElementLeft(targ) + 400;
	var y = DL_GetElementTop(targ) + 25;
	var scrollPosY = getScrollXY()[1] + getSize()[1];
	var height = document.documentElement.scrollHeight;
	if((scrollPosY-225) < y || (height-250) < y) {
		y = y - 250;
	}
	myImageTimer = setTimeout('lim(\''+str+'\',\''+id+'\','+x+','+y+')', 250);
}
function stimCVC(str,e,id) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	var x = DL_GetElementLeft(targ) + 100;
	var y = DL_GetElementTop(targ) - 100;
	//var scrollPosY = getScrollXY()[1] + getSize()[1];
	//var height = document.documentElement.scrollHeight;
	//if((scrollPosY-225) < y || (height-250) < y) {
	//	y = y - 250;
	//}
	myImageTimer = setTimeout('lim(\''+str+'\',\''+id+'\','+x+','+y+')', 250);
}
function lim(s,id,x,y) {
	var doc = $1('imgLyr');
	if(!doc) {
		doc = document.createElement('div');
		doc.id = 'imgLyr';
		$1('body').appendChild(doc);
		doc.style.zIndex=100;
		doc.style.position='absolute';
		doc.style.border='1px solid #000';
		doc.style.backgroundColor='#fff';
	}
	doc.style.left=x+'px';
	doc.style.top=y+'px';
	doc.innerHTML = '<img src="'+s+'" alt="" />';
	doc.style.display='block';
}

function fullsize(uri, label, width, height) {
	if (!width) {
		width = 450;
	}
	if (!height) {
		height = 350;
	}
	var params = 'directories=no,width=' + width + ' ,height=' + height + ',location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes';
	var win = window.open(uri, label, params);
	win.focus();
	win.onclick=win.close;
}

	function getData(url, caller, async) {
		var req = createRequest();
		
		if (!req) {
			alert('Your browser does not support XMLHTTP.');
			return;
		}

		url += (url.indexOf('?') == -1) ? '?' : '&amp;';
		url += 'rnd=' + new Date();

		if (async) {
			req.onreadystatechange = function () {
				if (req.readyState != 4) {
					return;
				}
				if (req.status != 200 && req.status != 304) {
					return;
				}
				caller.requestCallback(req);
			}
		}
		req.open('GET', url, async);
		req.send(null);
		
		if (!async) {
			if (req.status == 200) {
				caller.requestCallback(req);
			} else {
				return;
			}
		}
	}

	function createRequest() {
		if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			return new ActiveXObject('Microsoft.XMLHTTP');
		}
		return null;
	}
	
	function updateCompareProducts(imgObj) {
		var compAction = parseInt(imgObj.getAttribute('compAction'));
		if (compAction == 0 && cmpFull) {
			alert(cmpFullMsg);
			return;
		}
		var url = cmpURL;
		url += '?id=';
		url += imgObj.getAttribute('prodid');
		url += '&add=';
		url += compAction == 0 ? 'true' : 'false'
		
		imgObj.requestCallback = function(req) {
			var responseNode = req.responseXML.documentElement;
			if (responseNode.getAttribute('ok') == 'true') {
				var compAction = parseInt(this.getAttribute('compAction'));
				
				if (compAction == 0) {
					var label = getSubNodeValue(responseNode, 'label');
					var prodLink = getSubNodeValue(responseNode, 'prodLink');
					var imgURI = getSubNodeValue(responseNode, 'imgURI');
					var price = getSubNodeValue(responseNode, 'price');

					var cmpContainer = document.getElementById('cmpcont');
					var lastDiv = null;
					for (var i = 0; i < cmpContainer.childNodes.length; i++) {
						if (cmpContainer.childNodes[i].nodeName.toLowerCase() == 'div') {
							lastDiv = cmpContainer.childNodes[i];
						}
					}

					var divNode = document.createElement('div');
					divNode.id = 'prodcmp' + this.getAttribute('prodid');
					divNode.className = 'items';

					var divNode2 = document.createElement('div');
					divNode2.className = 'wrapper';
					
					var aNode = document.createElement('a');
					aNode.href = prodLink;
					divNode2.appendChild(aNode);
					
					var imgNode = document.createElement('img');
					imgNode.src = imgURI;
					aNode.appendChild(imgNode);

					divNode.appendChild(divNode2);
					
					divNode2 = document.createElement('div');
					
					aNode = document.createElement('a');
					aNode.href = prodLink;
					aNode.innerHTML = label;
					divNode2.appendChild(aNode);
					
					divNode.appendChild(divNode2);
					
					divNode2 = document.createElement('div');
					divNode2.className = 'removebutton';

					imgNode = document.createElement('img');
					imgNode.src = delImg;
					imgNode.title = delImgHover;
					imgNode.alt = delImgHover;
					imgNode.setAttribute('prodid', this.getAttribute('prodid'));
					imgNode.onclick = function() {
						removeCompareProduct(this);
					};
					divNode2.appendChild(imgNode);

					divNode.appendChild(divNode2);
					
					emNode = document.createElement('em');
					emNode.className = 'price';
					emNode.innerHTML = price;
					
					divNode.appendChild(emNode);
					
					divNode2 = document.createElement('div');
					divNode2.className = 'itembar';
					
					divNode.appendChild(divNode2);

					if (!lastDiv) {
						cmpContainer.insertBefore(divNode, cmpContainer.firstChild);
					} else {
						cmpContainer.insertBefore(divNode, lastDiv.nextSibling);
					}
					
					if (!lastDiv) {
						var cmpBox = document.getElementById('cmpbox');
						cmpBox.style.display = 'block';
					}
					cmpFull = 'true' == responseNode.getAttribute('full');
				} else if (compAction == 1) {
					var cmpContainer = document.getElementById('cmpcont');
					var cmps = cmpContainer.getElementsByTagName('div');
					for (var i = 0; i < cmps.length; i++) {
						if (cmps[i].id == 'prodcmp' + this.getAttribute('prodid')) {
							cmpContainer.removeChild(cmps[i]);
						}
					}
					cmps = cmpContainer.getElementsByTagName('div');
					if (cmps.length == 0) {
						var cmpBox = document.getElementById('cmpbox');
						cmpBox.style.display = 'none';
					}
					cmpFull = false;
				}
				
				compAction = compAction == 0 ? 1 : 0;
				this.setAttribute('compAction', compAction);
				if (this.nodeName.toLowerCase() == 'img') {
					this.src = cmpImgs[compAction];
					this.title = cmpTitles[compAction];
				} else if (this.nodeName.toLowerCase() == 'a') {
					this.innerHTML = cmpProdLinks[compAction];
				}
			}		
		}
		
		getData(url, imgObj, true);
	}
	
	function getSubNodeValue(parent, childName) {
		var child = parent.getElementsByTagName(childName)[0];
		if (child.textContent) {
			return child.textContent;
		} else if (child.text){
			return child.text;
		}
		return '';	
	}

	function removeCompareProduct(imgObj) {
		var url = cmpURL;
		url += '?id=';
		url += imgObj.getAttribute('prodid');
		url += '&add=false';
		
		imgObj.requestCallback = function(req) {
			var responseNode = req.responseXML.documentElement;
			if (responseNode.getAttribute('ok') == 'true') {
				var cmpContainer = document.getElementById('cmpcont');
				var cmps = cmpContainer.childNodes;
				for (var i = 0; i < cmps.length; i++) {
					if (cmps[i].id == 'prodcmp' + this.getAttribute('prodid')) {
						cmpContainer.removeChild(cmps[i]);
					}
				}
				cmps = cmpContainer.getElementsByTagName('div');
				if (cmps.length == 0) {
					var cmpBox = document.getElementById('cmpbox');
					cmpBox.style.display = 'none';
				}
				
				var listImg = document.getElementById('listcmp' + this.getAttribute('prodid'));
				if (listImg) {
					listImg.setAttribute('compAction', 0);
					listImg.src = cmpImgs[0];
					listImg.title = cmpTitles[0];
				}
				
				var prodLink = document.getElementById('prodcmp');
				if (prodLink && prodLink.getAttribute('prodid') == this.getAttribute('prodid')) {
					prodLink.setAttribute('compAction', 0);
					prodLink.innerHTML = cmpProdLinks[0];
				}
				
				if (window.location.href.search('seid=etailer-productcomparison') > -1) {
					window.location.href = window.location.href;
				}
				
				cmpFull = false;
			}		
		}
		
		getData(url, imgObj, true);
	}
	
	function removeAllComparedProducts() {
		var url = cmpURL;
		url += '?removeAll=true';
		
		this.requestCallback = function(req) {
			var cmpBox = document.getElementById('cmpbox');
			cmpBox.style.display = 'none';
		
			var cmpContainer = document.getElementById('cmpcont');
			var child = cmpContainer.firstChild;
			while (child) {
				var sibling = child.nextSibling;
				if (child.id && child.id.search('prodcmp') == 0) {
					var prodid = child.id.substring(7);
				
					var listImg = document.getElementById('listcmp' + prodid);
					if (listImg) {
						listImg.setAttribute('compAction', 0);
						listImg.src = cmpImgs[0];
						listImg.title = cmpTitles[0];
					}

					var prodLink = document.getElementById('prodcmp');
					if (prodLink && prodLink.getAttribute('prodid') == prodid) {
						prodLink.setAttribute('compAction', 0);
						prodLink.innerHTML = cmpProdLinks[0];
					}
				
					cmpContainer.removeChild(child);
				}
				child = sibling;
			}
			
			if (window.location.href.search('seid=etailer-productcomparison') > -1) {
				window.location.href = window.location.href;
			}
			
			cmpFull = false;
		}
		
		getData(url, this, true);
	}
	
	var fadeHash = new Hash();

function mov(id, xOff, yOff, width, caller, url) {
	
	var imageElem = document.getElementById(id);
	var messageElem = document.getElementById(id + '_msg');
	
	if(imageElem && messageElem) {
		var fadeEffect = fadeHash.get(id);
		if (fadeEffect){
			fadeEffect.cancel();
		}
		
		messageElem.style.display='block';
		
		Effect.Fade(messageElem, { duration: 0.5, to: 1 })
		
		if (xOff){
				
			messageElem.style.position='absolute';
			messageElem.style.left = xOff +'px';
			messageElem.style.top = yOff +'px';
			messageElem.style.width = width + 'px';
			messageElem.style.zIndex = '99';
		
			messageElem.onmouseout = function() {
				mou(id);
			}
			messageElem.onmouseover = function() {
				mov(id);
			}
		}
		
	
	}
}

function mou(id) {
	var messageElem = document.getElementById(id + '_msg');
	
	if (messageElem){
		fadeHash.set(id, Effect.Fade(messageElem, { duration: 2.0, from: 1, to: 0 }));			
	}
}
