if(document.getElementById) document.write('<style type="text/css">TR.subdiv{display:none }</style>');
var is = new Is();
function Is(){
  this.agent=navigator.userAgent.toLowerCase();
  this.opera = (this.agent.indexOf('opera')!=-1) ? true:false;
  this.ie4 = ((this.agent.indexOf('msie')!=-1) && (this.agent.indexOf('opera')==-1)) ? true:false;
  this.ns6 = ((this.agent.indexOf('gecko')!=-1) && (this.agent.indexOf('opera')==-1)) ? true:false;
  this.ns4 = ((this.agent.indexOf('mozilla')!=-1) && (this.agent.indexOf('opera')==-1) && (this.agent.indexOf('msie')==-1) && (this.agent.indexOf('gecko')==-1)) ? true:false;
}

function SwapImage(id,mode,url){
  if (typeof id.src!="undefined"){
    var img = id;
  }else{
	  var img = document.getElementById(id);
  }
  if(!img){
	  img = document.images[id];
  }
  if (img){
	  if (typeof(url)=="undefined"){
		  if(mode==1) img.src=img.src.substr(0,img.src.length-4)+'_o.'+img.src.substr(img.src.length-3,img.src.length);
		  if(mode==0) img.src=img.src.substr(0,img.src.length-6)+'.'+img.src.substr(img.src.length-3,img.src.length);  
	  }else{
	  	  img.src=url;
	  }
  }
}

divover="#F0F6F0";
divcolor=["#F0F6F0","#F0F6F0","#F0F6F0"];

function hilitediv(myobj,mode,level){
  kids = myobj.childNodes;
  if(mode==0){
    color=divcolor[level];
    name="";
  }
  if(mode==1){
    name="template-menu"+(level+1)+"-o";
    try{ myobj.style.cursor="pointer"; } catch (a){}
    try{ myobj.style.cursor="hand"; } catch (a){}
  }
  if(mode==3){
    color="#F0F6F0";
    name="";
  }
  myobj.className=name;
}

/* What it is ? */
subdivcolor2="green";
subdivcolor4="yellow";
subdivcolor5="black";
subdivcolor6="cyan";

function hilitesubdiv(myobj,mode){
/*  kids = myobj.childNodes;
  if(mode==0){
    color1=subdivcolor1;
    color2=subdivcolor2;
  }
  if(mode==1){
    color1=subdivcolor3;
    color2=subdivcolor4;
    try{ myobj.style.cursor="pointer"; } catch (a){}
    try{ myobj.style.cursor="hand"; } catch (a){}
  }
  if(mode==3){
    color1=subdivcolor5;
    color2=subdivcolor6;
  }
  for(var i=0; i<kids.length; i++){
    if(kids[i].nodeName=='TD'){
      kids[i].style.backgroundColor=color1;
    }
  }*/
}

function opendiv(id){
	var display='none';
	with(document.getElementById("subdiv"+id)){
		if(innerHTML!='<TD></TD>' && (style.display=='none' || style.display=='')) 
			display=(is.ie4)?'block':'table-row';
		style.display=display;
	}
}

function OpenImg(src, width, height, target, scrollbars)
{
 win=window.open('',target.replace(/\./,"_"),'width='+width+',height='+height+',hotkeys=1,resizable=yes,scrollbars='+scrollbars);
 win.document.write('<html><head></head><body marginwidth=0 marginheight=0 style="margin:0 0 0 0; padding:0 0 0 0;">');
 win.document.write('<IMG src="'+src+'" alt="" width="'+width+'" height="'+height+'">');
 win.document.write("</body></html>");
 win.focus();
 win.document.close();
}

function OpenWin(src,target)
{
   win=window.open(src,target,'location=0,resizable=1,scrollbars=1');
   if(win) win.focus();
}
/* menu */
var t=null; 
var oni=""; 
var onj="";
var path2="";
var hiding=false;
var pad_v=5;
var pad_h=10;

function GetWindowWidth(){
	return((is.ie4)? document.body.clientWidth: window.innerWidth);
}

function SetTimer(){ 
	StopTimer();
	t = setTimeout('HideMenu()', 500);
}

function StopTimer(){
if(t!=null){ 
	clearTimeout(t);
	t=null;
}
return (true);
}

function HideMenu(){
if(t!=null) StopTimer();
if(oni!=""){
	if (is.ie4){
		var select = document.getElementsByName("neighbours")[0];
		if (select){
			select.style.visibility='visible';
		}
	}
	if(onj!="")DeSelect(oni,onj);
	if (path2!=""){
		arr1=path2.split("_");
		var tohide=arr1[0];
		for (k=1;k<arr1.length;k++){
			tohide=tohide+"_"+arr1[k];
			HideNext(tohide);
		}
		document.getElementById("s"+arr1[0]).style.visibility='hidden';
		//document.getElementById("m"+arr1[0]).firstChild.style.color='black';
		path2="";
	}else{
		document.getElementById("s"+oni).style.visibility='hidden';
		//document.getElementById("m"+oni).firstChild.style.color='black';
	}
	oni="";
}
}

function ShowNext(elid){
	var arr=elid.split("_");
	arr.length=arr.length-1;
	//var temp=arr.pop();
	s_obj=document.getElementById("s"+arr.join("_"));
	var t1=s_obj.offsetTop+document.getElementById("t"+elid).offsetTop;
	if (t1-1<parseInt(s_obj.style.top))
		t1=t1+1;
	var l1=s_obj.offsetLeft+s_obj.offsetWidth-1;
	var winwid=GetWindowWidth();

	with(document.getElementById("s"+elid).style){
		visibility="visible";
		display='block';
	}
	var subwid=document.getElementById("t"+elid).offsetWidth;
	var s_wid=document.getElementById("s"+elid).offsetWidth;
	with(document.getElementById("s"+elid).style){
		visibility="hidden";
		display='none';
	}

	if (l1+subwid>winwid){
		l1=l1-s_wid-subwid+2+pad_h*2;
		//t1+=document.getElementById("t"+elid).offsetHeight;
	}
	with(document.getElementById("s"+elid).style){
		top=t1-1+pad_v;
		left= l1-pad_h;
		visibility="visible";
		display='block';
		path2=elid;
		//borderTop='1px solid #B0B0B0';
		//backgroundColor='#EAEAEA !important';
		//backgroundColor='#F4F4F4 !important';
	}
}

function HideNext(id){
	if ((obj=document.getElementById("s"+id)) && !hiding){
		hiding=true;
		obj.style.visibility='hidden';
		if (path2.search("_")){
			arr=path2.split("_");
			//arr.pop();
			arr.length=arr.length-1;
			path2=arr.join("_")
		}
		hiding=false;
	}
}

function ShowMenu(id){
StopTimer();
if(oni!=id) {
	HideMenu();
	if (is.ie4){
		var select = document.getElementsByName("neighbours")[0];
		if (select)
			select.style.visibility='hidden';
	}
	var winwid=GetWindowWidth();
	with(document.getElementById("s"+id).style){
		visibility="visible";
		display=is.ie4?'block':'table-cell';
	}
	var subwid=document.getElementById("t"+id).offsetWidth;
	with(document.getElementById("s"+id).style){
		visibility="hidden";
		display='none';
		//backgroundColor='#F4F4F4';
	}
	var menu_height=document.getElementById("tsub").offsetHeight;
	var height2menu=241;
	with (document.getElementById("m"+id)){
	    try{ style.cursor="pointer"; } catch (a){}
	    try{ style.cursor="hand"; } catch (a){}
		//firstChild.style.color="#FF5C00";
		//var l = offsetLeft-1;
		//var l = offsetLeft+document.getElementById("tsub").offsetLeft-1;
		//var l = winwid+227-1+offsetLeft;
		var temp_r=getAbsolutePos(document.getElementById(id));
		//var l = offsetLeft+document.getElementById("tsub").offsetLeft-1+278+(is.ie4?-1:0);
		var l =temp_r.x+1; 
		//var t = height2menu+menu_height;
		var t = temp_r.y+37;
		var w=offsetWidth;
		if (l+subwid>winwid-(is.ns6?10:0)){
			//l=winwid-subwid-5;
			l=winwid-subwid-(is.ns6?0:0);
		}
		if (l<0)
			l=0;

	}
	//if (id==1)
		//l=l-document.getElementById("t"+id).offsetWidth+document.getElementById("m"+id).offsetWidth+1;
	with(document.getElementById("t"+id)){
		//width=w+12;
		//width=w+23;
	}
	with(document.getElementById("s"+id).style){
		top=t-1;
		left= l-1;
		visibility="visible";
		display=is.ie4?'block':'table-cell';
	}
	oni=id; 
	onj="";
}
}	

function DeSelect(i,j){
with(document.getElementById("t"+i+"_"+j).style){
	//backgroundColor="#EAE9E9";
	//color='#000066';
}
//onj=0;
}

function HideSequence(first,last){
	rest=last.substr(first.length+1);
	var ar=rest.split("_");
	for(var k=0;k<ar.length;k++){
		first=first+"_"+ar[k];
		HideNext(first);
	}
}
function Select(i,j){
if ((oni!="") && (onj!="")) DeSelect(oni,onj);
with(document.getElementById("t"+i+"_"+j).style){
    try{ cursor="pointer"; } catch (a){}
    try{ cursor="hand"; } catch (a){}
	//backgroundColor="#FFFFFF";
	//color="#4C4CB2";
}
if (i==oni && j==onj)
	return "";
/*if (onj==j && i!=oni+"_"+onj){
	HideNext(path2);
}else if (onj!=j && oni+"_"+j!=path2){
	HideNext(oni+"_"+onj);
}*/
oni=oni.toString();
ar1=oni.split("_");
ar2=i.split("_");
if (ar1.length-ar2.length>0){
	//ar1.pop();
	HideSequence(i,path2);
}else if (oni==i && path2!=oni && i+"_"+j!=path2){
	HideNext(path2);
}
onj=j;
oni=i;
}

function GoTo(url,target){
	if (url!=''){
		if (target!='')
			window.open(url);
		else
			window.location=url;
	}
}

function getAbsolutePos (obj) {
	
	var SL = 0, ST = 0;
	var  r = {x: obj.offsetLeft-SL, y: obj.offsetTop-ST};

	if (obj.offsetParent) {
		var pos=getAbsolutePos(obj.offsetParent);
		r.x += pos.x;
		r.y += pos.y;
		return r;
	}
	return r;
};

function open_popup(src, width, height, target, scrollbars){
	var win=window.open(src,target,'screenX='+Math.floor((screen.availWidth-width)/2)+', screenY='+Math.floor((screen.availHeight-height)/2)+', left='+Math.floor((screen.availWidth-width)/2)+', top='+Math.floor((screen.availHeight-height)/2)+', height='+height+',width='+width+', resizable=no, scrollbars=auto');
	win.focus();
	return win;
}

var add_to_cart_obj=null;
function add_to_cart(obj,price){
	if (typeof relative_path=="undefined")
		relative_path="";
	if (add_to_cart_obj){
		add_to_cart_obj.offsetParent.removeChild(add_to_cart_obj);
	}
	abs_pos=getAbsolutePos(obj);
	X=abs_pos.x;
	Y=abs_pos.y;
	if (is.ie4){
		Y=Y-55;
	}
	var div = document.createElement('DIV');
	div.id="add-to-cart";
	div.style.position='absolute';
	div.style.left=X+5;
	div.style.top=Y+5;
	div.innerHTML='<form name="frm"><table cellpadding="0" cellspacing="0" border="0" class="round round2">\
<tr><td>\
	<table cellpadding="0" cellspacing="0" border="0" width="100%">\
	<td class="top-left">&nbsp;</td><td class="top-bg">&nbsp;</td><td class="top-right">&nbsp;</td>\
	</table>\
</td></tr>\
<tr><td class="middle">\
<table cellpadding="0" cellspacing="0" border="0" class="cart">\
<tr>\
	<td class="first"><input name="amount" value="1" class="border" size="4"></td>\
	<td class="last"><input type="button" value="OK" onClick="window.location=\''+obj.href+'\'+\'&amount=\'+document.forms.frm[\'amount\'].value;"></td>\
</tr>\
</table>\
</td></tr>\
<tr>\
	<td>\
<table cellpadding="0" cellspacing="0" border="0" width="100%">\
<tr><td class="bottom-left">&nbsp;</td><td class="bottom-bg">&nbsp;</td><td class="bottom-right">&nbsp;</td></tr>\
</table></td></tr></table></form>';
	//obj.offsetParent.appendChild(div);
	document.body.appendChild(div);

	var btn = document.createElement("img");
	btn.src=relative_path+"pics/btn-close.gif";
	btn.width=12;
	btn.height=11;
	if (document.all){
		btn["onclick"]=new Function ("add_to_cart_obj.offsetParent.removeChild(add_to_cart_obj);add_to_cart_obj=null;");
		btn["onmousedown"]=new Function ("this.style.borderColor=\'ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow\';this.style.borderRight=\'none\';window.event.cancelBubble=true;");
	}else{
		btn.setAttribute("onClick","add_to_cart_obj.offsetParent.removeChild(add_to_cart_obj);add_to_cart_obj=null;");
		btn.setAttribute("onMouseDown","this.style.borderColor=\'ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow\';this.style.borderRight='none';event.cancelBubble=true;");
	}
	div.appendChild(btn);
	
	add_to_cart_obj=div;
	return false;
}
