function SfindObj(n, d) 
{	//v4.01
	var p, i, x;
	if (!d) 
		d = document; 
	if ((p = n.indexOf("?") ) > 0 && parent.frames.length) 
	{
		d = parent.frames [n.substring(p + 1)].document; 
		n = n.substring(0, p);
	}
	if (!(x = d [n]) && d.all) 
		x = d.all [n]; 
	for (i = 0; !x && i < d.forms.length; i ++) 
		x = d.forms [i] [n];
	for (i = 0; !x && d.layers && i < d.layers.length; i ++)
		x = SfindObj(n, d.layers [i].document);
	if(!x && d.getElementById) 
		x = d.getElementById(n);
	return x;
}
function srch()
{
	if((obj=SfindObj('srch')) && (v=obj.value))
		window.document.location.href='/search/'+encodeURI(v);
}

function ShowProd (wwidth,wheight,isrc,modelid) {
	if(isrc=='/') return;
	
	obj1=SfindObj('preview');
	obj2=SfindObj('previewimg');
	obj3=SfindObj('previewtbl');
	obj4=SfindObj('loading');
	
	if (modelid >=0 ) {
		objLoad=SfindObj("loaddata");
		objLoad.innerHTML='';
		objLoad.style.display='none';
	}
	
	obj2.src='/i/dot.gif';
	wheight = wheight*1+20;
	obj1.style.width=wwidth+'px';
	obj1.style.height=wheight+'px';
	
	obj3.style.width=wwidth+'px';
	obj3.style.height=wheight+'px';
	
	obj4.style.width=wwidth+'px';
	obj4.style.height=wheight+'px';

	CenterLayer('preview',wwidth,wheight,window.document);
	obj1.style.visibility='visible';

	obj2.src=isrc;
}

function HideProd () {
	obj1=SfindObj('preview');
	obj2=SfindObj('previewimg');
	objLoad=SfindObj("loaddata");
	objLoad.innerHTML='';
	objLoad.style.display='none';
	obj2.src='/i/dot.gif';
	obj1.style.visibility='hidden';
}

function CenterLayer (layer,width,height,target,xoffset,yoffset) {
	if (!target)
		target=window.document;
	
	if (!xoffset)
		xoffset = 0;
		
	if (!yoffset)
		yoffset = 0;

	leftLayer = ((target.body.clientWidth - width)/2);
	topLayerABS = (target.body.clientHeight - height)/2;

	topLayer=target.body.scrollTop;
	
	newTop = topLayer + topLayerABS;
	if (newTop < 0)
		newTop=0;
		
	nTop = topLayer + topLayerABS + yoffset;
	nLeft = leftLayer + xoffset;
	
	if (nTop < target.body.scrollTop)
		nTop = target.body.scrollTop + 5;
	
	target.getElementById(layer).style.left = nLeft + 'px';
	target.getElementById(layer).style.top= nTop + 'px';
}

function active_menu(menu)
{
	menu = SfindObj('menu_'+menu);
	if(menu)
		menu.className = 'activemenu';
}

function SetCookie(name, value) {
   var argv    = SetCookie.arguments;
   var argc    = SetCookie.arguments.length;
   var expires = (argc > 3) ? new Date(argv[3]) : null;
   //var path    = (argc > 4) ? argv[4] : null;
	var path    = '/';
   var domain  = (argc > 5) ? argv[5] : null;
   var secure  = (argc > 6) ? argv[6] : false;
   expires = 'Friday, 01-Jan-2399 00:00:00 GMT';

   document.cookie = name + "=" + escape(value)
      + ((expires == null) ? "" : ("; expires=" + expires))
      + ((path == null) ? "" : ("; path=" + path))
      + ((domain == null) ? "" : ("; domain=" + domain))
      + ((secure == true) ? "; secure" : "");
} 

function GetCookie(name) {
   var arg  = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i    = 0;

   while(i < clen) {
      var offset = i + alen;

      if(document.cookie.substring(i, offset) == arg) {
         var iEnd  = document.cookie.indexOf(";", offset);

         if(iEnd == -1) {
            iEnd = document.cookie.length;
         }

         return unescape(document.cookie.substring(offset, iEnd));
      }

      i = document.cookie.indexOf(" ", i) + 1;

      if(i == 0) {
         break;
      }
   }

   return null;
}

function addcart(id,title)
{
	prods =	GetCookie('prods');
	a = 1;

	if (prods) 
	{
		aprods = prods.split(';');
		prods = '';
		for (i = 0; i < aprods.length; i++) 
		{
			if (aprods[i] == id) 
			{
				a = 0;
				break;
			}
			prods += aprods[i] + ';'
		}
	}
	
	if(a)
	{
		prods += id + ';';
		SetCookie('prods',prods);
		alert('Product '+title+' added to cart');
	}
	else
		alert('Product '+title+' already in Your cart');
}

function remcart(id,title)
{
	prods =	GetCookie('prods');
	
	if (!prods) return;

	aprods = prods.split(';');
	prods = '';
	for (i = 0; i < aprods.length; i++) 
	{
		if (aprods[i] != id) 
		{
			p = parseInt(aprods[i]);
			if(p > 0) prods += aprods[i] + ';'
		}
	}
	SetCookie('prods',prods);
	alert('Product '+title+' removed from cart');
}

function showwnd(tag,txt)
{
	if (!(obj = SfindObj(tag)))
	{
		try 
		{
			obj = window.document.createElement("<div class=wnd id=" + tag + "><!-- --></div>");
		} 
		catch (e) 
		{
			obj = window.document.createElement("div");
			obj.setAttribute("id", tag);
			obj.setAttribute("class", "wnd");
		}
		if(txt && (txt1=SfindObj(txt))) obj.innerHTML = txt1.innerHTML;
		window.document.body.appendChild(obj);
	}
	
	if (!obj) return;
	if (obj.style.visibility == 'visible') 
		obj.style.visibility = 'hidden';
	else 
	{
		CenterLayer(tag,obj.offsetWidth, obj.offsetHeight);
		obj.style.visibility = 'visible';
	}
}

