function padleft(str,count,char){
	if (str.toString().length < count){
		var len = count - str.toString().length;
		var addstr = "";
		for(i=0;i<len;i++) addstr += char;
		return addstr+str;
	} else {
		return str;
	}
}

function setCurrentDate(){
	var tm = new Date();
	$("#contact_date").html(padleft(tm.getDay(),2,"0")+"."+padleft(tm.getMonth(),2,"0")+"."+tm.getFullYear());
	$("#contact_time").html(padleft(tm.getHours(),2,"0")+":"+padleft(tm.getMinutes(),2,"0")+":"+padleft(tm.getSeconds(),2,"0"));
	setTimeout(setCurrentDate,1000);
}

function add2wishlist(obj){
	var reg = /select_(\d+)/i;
	var arr = reg.exec(obj.id);
	if (arr == null) return;
	$.getJSON("/add2wishlist.php",{pid:arr[1]},function(json){
		$("#selected_products").html(json.count.toString());
		$("#product_"+json.pid).addClass("selected_bg");
		$("#select_"+json.pid).hide();
		$("#unselect_"+json.pid).show();
	});
}

function rem2wishlist(obj){
	var reg = /select_(\d+)/i;
	var arr = reg.exec(obj.id);
	if (arr == null) return;
	$.getJSON("/rem2wishlist.php",{pid:arr[1]},function(json){
		$("#selected_products").html(json.count.toString());
		$("#product_"+json.pid).removeClass("selected_bg");
		$("#select_"+json.pid).show();
		$("#unselect_"+json.pid).hide();
	});
}

	function shiftby(delta){
		var obj = document.getElementById("inner");
		var div = document.getElementById("box");
		
		if (obj.style.left == "") obj.style.left = "-250px";
		var x = parseInt(obj.style.left)+delta;
		if (x >= 0) return;
		if (Math.abs(x) >= (obj.clientWidth-div.clientWidth)) return;
		obj.style.left = x+"px";
	}
	function shiftto(delta){
		var obj = document.getElementById("inner");
		var div = document.getElementById("box");
		var x = -delta;
		if (x > 0) x = 0;
		var a = obj.clientWidth;
		if (Math.abs(x) > (a-div.clientWidth)) x = -(a-div.clientWidth);
		obj.style.left = x+"px";
	}
	var timer;
	function move2right(){
		clearTimeout(timer);
		timer = setTimeout(move2right,10);
		shiftby(-10);
	}
	function move2left(){
		clearTimeout(timer);
		timer = setTimeout(move2left,10);
		shiftby(10);
	}		
	function stop(){
		clearTimeout(timer);
	}
	
	var productimageid = 0;
	var imagegroupid = 0;
	function showImage(group,url,pid,cid){
		if (productimageid == 0) productimageid = pid;
		if (imagegroupid == 0) imagegroupid = cid;
		$("#caption").html(group);
		$("#bigimage").attr({src:url});
		
		$(".active_menu_item").removeClass("active_menu_item");
		//$("#group_"+imagegroupid).removeClass("active_menu_item");
		imagegroupid = cid;
		$("#group_"+imagegroupid).addClass("active_menu_item");
		
		$("#image_"+productimageid).removeClass("sel_view");
		productimageid = pid;
		$("#image_"+productimageid).addClass("sel_view");
	
		var obj = document.getElementById("img_"+pid);
		var box = document.getElementById("box");
		if (obj == null) return;
		if (box == null) return;

		var l = 0;
		try{
			l = obj.offsetLeft+obj.offsetParent.offsetLeft+obj.offsetParent.offsetParent.offsetLeft;
		} catch(e) {
			l = obj.offsetLeft;
		}
		var w = obj.offsetWidth;
		var ao = l-Math.ceil(box.offsetWidth/2)+Math.ceil(w/2);
		shiftto(ao);
		window.location.hash = "#"+pid;
	}
	
	function showblock(id){
		var obj = document.getElementById("block_"+id);
		var box = document.getElementById("box");
		if (obj == null) return;
		if (box == null) return;
		try{
			shiftto(obj.offsetLeft+Math.ceil(obj.offsetWidth/2)-Math.ceil(box.offsetWidth/2));
		}catch(e){
			shiftto(obj.offsetLeft);
		}
		
		$("#group_"+imagegroupid).removeClass("active_menu_item");
		imagegroupid = id;
		$("#group_"+imagegroupid).addClass("active_menu_item");
	}
	
	var slideindex;
	var slidetimer;
	
	function slide(){
		eval(slideimages[slideindex]);
		slideindex++;
		if (slideindex >= slideimages.length) clearTimeout(slidetimer); else slidetimer = setTimeout("slide()",3500);
	}
	
	function slideshow(){
		slideindex = 0;
		
		eval(slideimages[slideindex]);
		slideindex++;
		if (slideindex < slideimages.length) slidetimer = setTimeout("slide()",3500);
	}
	
	function disableselect(e){
	  return false
	}
	function reEnable(){
	  return true
	}
	
	
	function noCopy(){
	  $(".no-copy").each(function(i){
	    this.onselectstart=new Function ("return false")
	    if (window.sidebar){
	    this.onmousedown=disableselect
	    this.onclick=reEnable
	    }
	  })
	}

function addCounters(){
var html = "<div style=\"float:right\"><!--/Start Trafic.ro/--><script type=\"text/javascript\">t_rid=\"rentalmd\";</script><script type=\"text/javascript\" src=\"http://storage.trafic.ro/js/trafic.js\"></script><noscript><a href=\"http://www.trafic.ro/top/?rid=rentalmd\"  target=\"_blank\"><img border=\"0\" alt=\"trafic ranking\" src=\"http://log.trafic.ro/cgi-bin/pl.dll?rid=rentalmd\"/></a></noscript><!--/End Trafic.ro/--><!-- Start | SUPER.MD v2 | ID#8636 --><SCRIPT language=JavaScript><!--// st=\"<A HREF='http://super.md/' TARGET='_top'><img src='http://v1.super.md/?col=99000000;b=a;id=8636;v=2;je=\";st+=((navigator.javaEnabled()==true)?\"y\":\"n\");st+=\";pp=\"+escape(document.referrer)+\";cp=\"+escape(window.location.href);st+=\";sh=\"+screen.height+\";sw=\"+screen.width+\";sc=\"+screen.colorDepth;st+=\"' border='0' alt='super.md'></A>\"; document.write(st); //--></SCRIPT><NOSCRIPT><A HREF=\"http://super.md/\" TARGET=\"_top\"><IMG SRC=\"http://v1.super.md/?col=99000000;b=a;id=8636;v=2;je=0\" alt=\"super.md\"></A></NOSCRIPT><!-- End | SUPER.MD v2 | ID# --><!--TOP20.MD--><script language='javascript' type='text/javascript'><!-- top20_id='rentalmd';//--></script><script src='http://www.top20.md/client/scripts/stats.js' language='javascript' type='text/javascript'></script><noscript><a href='http://www.top20.md/?site=rentalmd' target='_blank'><img border='0' alt='Top20.md - Web Statistics!' src='http://www.top20.md/client/?id=rentalmd&ref='/></a></noscript><!--TOP20.MD--><!--LiveInternet counter--><script type=\"text/javascript\"><!-- document.write(\"<a href='http://www.liveinternet.ru/click' \"+\"target=_blank><img src='http://counter.yadro.ru/hit?t18.5;r\"+escape(document.referrer)+((typeof(screen)==\"undefined\")?\"\":\";s\"+screen.width+\"*\"+screen.height+\"*\"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+\";u\"+escape(document.URL)+\";\"+Math.random()+\"' alt='' title='LiveInternet: �������� ����� ���������� �� 24\"+\" ����, ����������� �� 24 ���� � �� �������' \"+\"border=0 width=88 height=31><\/a>\")//--></script><!--/LiveInternet--></div>";
document.write(html);
}