var pos=0;
var to=0;
var cur=0;
var maxi=0;
var can1=1;
var can2=0;
function move1()
{
	cur=cur-10;
	if (cur<to)
	cur=to;
	document.getElementById('tbl').style.left=cur;
	step=10;
	if ((cur-100)<=to)
	step=40;
	if (cur > to) {
		timer = setTimeout(move1, step);
	}
}
function move2()
{
	cur=cur+10;
	if (cur>to)
	cur=to;
	document.getElementById('tbl').style.left=cur;
	step=10;
	if ((cur+100)>=to)
	step=40;
	if (cur < to) {
		timer = setTimeout(move2, step);
	} 
}
function scrollleft(width)
{
	//alert(width);
	if (can1==1)
	{
		can2=1;
	maxi=width;
	cur=pos;
	pos=pos-130*4;
	if (Math.abs(pos)>=(width-520))
	{
		pos=-width+520;
		//document.getElementById('right').style.color="#585858";
		//document.getElementById('img_r').src="/i/portfolio-strelka-next1.jpg";
		can1=0;
	}
	to=pos;
	move1();
	//document.getElementById('tbl').style.left=pos;
	//document.getElementById('left').style.color="#385F9E";
	//document.getElementById('img_l').src="/i/portfolio-strelka-back1.jpg";
	}
}
function scrollright(width)
{
	//alert(width);
	if (can2==1)
	{
		can1=1;
	maxi=width;
	cur=pos;
	pos=pos+130*4;
	if (pos>=0)
	{
		pos=0;
		//document.getElementById('left').style.color="#585858";
		//document.getElementById('img_l').src="/i/portfolio-strelka-back.jpg";
		can2=0;
	}
	to=pos;
	move2();
	//move2(document.getElementById('tbl').style.left);
	//document.getElementById('tbl').style.left=pos;
	//document.getElementById('right').style.color="#385F9E";
	//document.getElementById('img_r').src="/i/portfolio-strelka-next.jpg";
	}
}


		function set1()
        {
                var img = document.getElementById("sub");
                img.style.color = "#FF0000";
        }
        function set2()
        {
                var img = document.getElementById("sub");
                img.style.color = "#3879D6";
        }

    function del(id) {
        var req = new Subsys_JsHttpRequest_Js();
        req.caching = false;
        req.onreadystatechange = '';
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                if (req.responseJS) {
                                        var img = document.getElementById('item'+id);
                                        img.style.display = "none";
                                        if (req.responseJS.num ==0)
                                        {
                                        document.getElementById('table').style.display = "none";
                                        //document.getElementById('count').innerHTML = 'нет';
                                        document.getElementById('empty').style.display = "block";
                                        document.getElementById('frm').style.display = "none";
                                        }
                }
            }
        }
        req.open('POST', '/delete.php?id='+id, true);
        req.send('id='+id);
    }
	
	
	var curid = '1';
	var t;
 function show_menu (id)
 {
 	//alert(id);
 	document.getElementById("sub"+curid).style.display="none";
 	
	curid = id;
 	document.getElementById("sub"+id).style.display="block";
 	clearTimeout(t);
 } 
 function show_menu1 (id)
 {
 	document.getElementById("sub"+id).style.display="block";
 }
 
 
 
 
 function hide_menu (id)
 {
	
 	t=setTimeout('hide('+id+')',300);
 }

 
 function hide (id)
 {
 		
	//alert(id);
	idd=id;
 	//window.setTimeout('document.getElementById("sub"+idd).style.display="none";',1000);
 	//setTimeout(1000);
 	document.getElementById("sub"+id).style.display="none";
 	//clearTimeout(timer);
 	op=95;
 	//fadeOut();
 	//op=0;
 	
 }

 
     function checksub() {
            _qfMsg='';
                if (document.getElementById('name').value == '') {
                        _qfMsg = _qfMsg + 'Не указано имя\n';
                }
                value = document.getElementById('email').value;
                var regex = /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/;
                if (value != '' && !regex.test(value)) {
                        _qfMsg = _qfMsg + 'Неправильно указан E-mail\n';
                }
                if (value == '') {
                        _qfMsg = _qfMsg + 'Не указан E-mail\n';
                }
                if (document.getElementById('phone').value == '') {
                        _qfMsg = _qfMsg + 'Не указан телефон\n';
                }
                if (document.getElementById('text').innerHTML == '') {
                        _qfMsg = _qfMsg + 'Заполните зявку\n';
                }
                if (_qfMsg!='')
                {
                        alert (_qfMsg);
                        return false;
                }
                return true;
    }
 
	
	
	
    function checksub() {
            _qfMsg='';
                if (document.getElementById('name').value == '') {
                        _qfMsg = _qfMsg + 'Не указано имя\n';
                }
                if (document.getElementById('phone').value == '') {
                        _qfMsg = _qfMsg + 'Не указан телефон\n';
                }
                value = document.getElementById('company').value;
                if (value == '') {
                        _qfMsg = _qfMsg + 'Не указана компания';
                }
                if (_qfMsg!='')
                {
                        alert (_qfMsg);
                        return false;
                }
    }
    function PopUp(PopUpUrl){
    var ScreenWidth=window.screen.width;
    var ScreenHeight=window.screen.height;
    var movefromedge=0;
    placementx=(ScreenWidth/2)-((360)/2);
    placementy=(ScreenHeight/2)-((380)/2);
    WinPop=window.open(PopUpUrl,"","width=360,height=290,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
   }
    function popupBig(PopUpUrl,name){
    var ScreenWidth=window.screen.width;
    var ScreenHeight=window.screen.height;
    var movefromedge=0;
    placementx=(ScreenWidth/2)-((600)/2);
    placementy=(ScreenHeight/2)-((413)/2);
    WinPop=window.open("/show.php?url="+PopUpUrl+"&name="+name,"","width=600,height=413,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
   }
    function popup_(PopUpUrl){
    var ScreenWidth=window.screen.width;
    var ScreenHeight=window.screen.height;
    var movefromedge=0;
    placementx=(ScreenWidth/2)-((600)/2);
    placementy=(ScreenHeight/2)-((600)/2);
    WinPop=window.open(PopUpUrl,"","width=600,height=413,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
   }
    function addcart(id) {
        // Получаем текст запроса из <input>-поля.
        if (isNaN(document.getElementById('num'+id).value))
        {
                alert('Необходимо ввести число.');
                return false;
        }
        
        var price = document.getElementById('price'+id).value;
        var napol = document.getElementById('napol'+id).value;
        if (napol==0)
        {
                alert('Выберите наполнитель');
                return false;
        }
	    var num = document.getElementById('num'+id).value;
        if (num<=0)
        {
                alert('Необходимо ввести число.');
                return false;
        }
            var name = document.getElementById('name'+id).value;
        // Создаем новый объект JSHttpRequest.
        var req = new Subsys_JsHttpRequest_Js();
        req.onreadystatechange = '';
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                if (req.responseJS) {
                    alert('Товар '+name+' добавлен в корзину ('+num+' шт.)');
                    //alert(req.responseJS.napol);
                }
            }
        }
        req.caching = false;
        // Подготваливаем объект.
        //alert('/addcart.php?id='+id+'&name='+name+'&price='+price+'&num='+num+'&type='+type);
        req.open('POST', '/addcart.php', true);
        // Посылаем данные запроса (задаются в виде хэша).
        req.send('id='+id+'&name='+name+'&price='+price+'&num='+num+'&napol='+napol);

    }





ToolTip.offsetX=20; //смещения подсказки от курсора
ToolTip.offsetY=10; //
function ToolTip(obj, text) {
  if(!obj||obj.nodeType!=1) throw "Illigal argument exception"; //обьект к кому привязываем подсказку
  //-- Разметка подсказки ---
  var tip=document.createElement("DIV");
  tip.className="tool_tip";
  tip.innerHTML=text;
  document.body.appendChild(tip);
  //-- события --
  obj.onmouseout=function (ev) {
      tip.style.visibility="hidden";
  };
  obj.onmousemove=function(ev) { //если не нужно что бы подскасзка бегала, то onmouseover
      tip.style.visibility="visible";
      if(window.event) ev=window.event;
      tip.style.left=ev.clientX + document.body.scrollLeft + ToolTip.offsetX;
      tip.style.top=ev.clientY + document.body.scrollTop + ToolTip.offsetY;
  };
}
//переберем заданные элементы, дадим подказку тем у кого есть аттрибут tooltip
//В аргументах передаем имена рассматриваемых тегов, * все теги
function initToolTips() {
//   return;
    var tags, tooltext;
    for(var i=0; i<arguments.length; i++) {
       tags=document.body.getElementsByTagName(arguments[i]);
       for(var j=0; j<tags.length; j++)
            if((tooltext=tags[j].getAttribute("tooltip"))) ToolTip(tags[j], tooltext);
   }
}
old='';
done=0;
function resize (obj)
{
	if (old!=='')
	{
		var img = document.getElementById('choose'+old);
		img.style.display = "none";
		check_old();
	}
	
var img = document.getElementById('choose'+obj);
img.style.display = "block";
	new Rico.Effect.Size( 'choose'+obj, 
						230, // width = 450px
						 
						150, // don't change the height
						 
						300, // 500ms (1/2 second)
						 
						10, // 10 steps
						 
						{complete:function() {done=1;}}  );
old=obj;
}

function mkch (main,ob)
{
		var img = document.getElementById('link'+main);
		img.innerHTML = document.getElementById('napnam'+ob).value;
		var img = document.getElementById('napol'+main);
		img.value = ob;
		var img = document.getElementById('choose'+main);
		img.style.display = "none";
		img.style.width=50;
		img.style.height=10;
		old='';
		done=0;
}

function check_old()
{
	if (old!='') if (done==1)
	{
		var img = document.getElementById('choose'+old);
		img.style.display = "none";
		img.style.width=50;
		img.style.height=10;
		old='';
		done=0;
		return false;
	}
	
}

function Start(url,name,wid,hei)
 {
 OpenWin = this.open("/show.php?url="+url+"&amp;name="+name+"&amp;width="+wid,"_blank","toolbar=No,menubar=No,location=No,scrollbars=No,resizable=Yes,status=No,width="+wid+",height="+hei+"");
 
 }
