function checkfile(v)
{
 arrayOfStrings = v.split(".");len=arrayOfStrings.length;
 s='';
 if(len!=0) {
  s=arrayOfStrings[len-1];
  s=s.toUpperCase();
  }
 if(s=='JPG' || s=='JPEG')
   {; }
 else {alert('Выберите пожалуйста файл JPEG');return false;}

return true;
}


function buy(i)
{
 n=1;
 sendRPC('vtorbu.php?id='+i+'&n='+n+'&rnd='+Math.random());
}

function buy0(i,n,r)
{
 sendRPC('vtorbu.php?id='+i+'&n='+n+'&r='+r+'&rnd='+Math.random());
}

function strtolower( str ) {    // Make a string lowercase
return str.toLowerCase();
}

function sendRPC(url)
{
//alert(url);
var newScript=document.createElement('script');
newScript.src=url;
newScript.type="text/javascript";
document.body.appendChild(newScript);
}

function setinner(id,t)
{
 z=document.getElementById(id);
 if(z) z.innerHTML=t;
}

function tobask(n,sum)
{
 nn=n;
 ss=sum;
 setinner('shtukas',nn);
 setinner('sumsum',ss);
}


function opendit(cod){
		var win=window.open(cod,'newwin'+Math.round(Math.random()*10000+1),'height=600,width=750,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		/*win.blur();
		window.focus();*/
}

function chknums(cod){
  for(i=1;i<=ttlns;i++)
     {
	  aaa='item'+cod+'_'+i;
      if(!document.getElementById(aaa)) continue;
      val=document.getElementById(aaa).value;
	  //alert(aaa+'val='+val);
      for(j=0;j<val.length;j++)
          {c=val.charAt(j);
           if (c<'0' || c>'9')
              {
               alert('введите пожалуйста целое число.');
               document.getElementById(aaa).focus();
               return false;
              }}
	 }
    sum=0; 
    for(i=1;i<=ttlns;i++)
     {
	  aaa='item'+cod+'_'+i;
      if(!document.getElementById(aaa)) continue;
      val=document.getElementById(aaa).value;
      //if(val>0) return true;
      sum+=val;
	 }
   if(sum<1) {alert('введите пожалуйста количество товара.'); return false;}
   return true;
}

var timerID = null;
var timerRunning = false;
var num=1;

var timerID1 = null;
var timerRunning1 = false;
var num1=-1;

var pic=new Array();
var pica=new Array();
var zag=new Array();
var picts=0;

function pic_preload()
{
for(i=1;i<7;i++) {
 pic[i] = new Image();
 pic[i].src="images/v"+i+".jpg";
}
}

function stopclock(){
   if(timerRunning)
      clearInterval(timerID);
   timerRunning = false;
   if(timerRunning1)
      clearInterval(timerID1);
   timerRunning1 = false;
}

function startclock(){
   // Make sure the clock is stopped
   stopclock();
   timerID = setInterval("showtime()",2000);
   timerRunning = true;
   timerID1 = setInterval("showtime1()",3000);
   timerRunning1 = true;
   pic_preload();
}

function startclock_new(){
   // Make sure the clock is stopped
   stopclock();
   timerID = setInterval("showtime_new()",2000);
   timerRunning = true;
   timerID1 = setInterval("showtime1()",3000);
   timerRunning1 = true;
}

function showtime_new(){
   //alert(picts);
   num++;
   //var num=Math.round(Math.random()*6+1);
   if(num>picts) num=1;
   //alert(num%3+1);
   if(document.getElementById("videopic")) 
   document.getElementById("videopic").innerHTML='<a href="'+pica[num]+'" class="ntextlink"><img id="picc"  border="0" title="посмотреть видеоролик"></a>';
   if(document.getElementById("picc")) {
   //alert(pic[num].src);
   document.getElementById("picc").src=pic[num].src;
   z='посмотреть видеоролик';
   if(zag[num]!='') z=z+' '+zag[num];
   document.getElementById("picc").title=z;
   }
   if(document.getElementById("vid_adr")) {
   document.getElementById("vid_adr").innerHTML='<a href="'+pica[num]+'" class="ntextlink"><b>ПОСМОТРЕТЬ ВИДЕОРОЛИК</b></a>';
   }
}

function showtime(){
   num++;
   //var num=Math.round(Math.random()*6+1);
   if(num>6) num=1;
   //alert(num%3+1);
   if(document.getElementById("video")) 
   //document.getElementById("video").innerHTML='<a href="index.php?page=video&v='+Math.round(num/2)+'" class="ntextlink"><img id="picc"  border="0" title="посмотреть видеоролик"><br><center><b>ПОСМОТРЕТЬ ВИДЕОРОЛИК</b></center></a>';
   document.getElementById("video").innerHTML='<a href="video/&v='+Math.round(num/2)+'" class="ntextlink"><img id="picc"  border="0" title="посмотреть видеоролик"><br><center><b>ПОСМОТРЕТЬ ВИДЕОРОЛИК</b></center></a>';
   if(document.getElementById("picc"))
   document.getElementById("picc").src=pic[num].src;
}

function showtime1(){
   n1=parseInt(document.getElementById('shwd_n').innerHTML);
   idstyle('nws'+n1,'none');
   ttl=parseInt(document.getElementById('ttl_n').innerHTML);
   zz=parseInt(Math.random()*1000)+5;
   for(i=0;i<zz;i++) m=Math.random();
   var num1=parseInt(Math.random()*ttl)+1;
   document.getElementById('shwd_n').innerHTML=num1;
   idstyle('nws'+num1,'block');
}

function sh_hide(i)
{
if(document.getElementById(i))
  {
  v=document.getElementById(i).style.display;
  if(v=="block") n="none";
  else n="block";
  document.getElementById(i).style.display=n;
  }
}

function idstyle(id,s)
{
 document.getElementById(id).style.display=s;
}

function getstyle(id)
{
 return document.getElementById(id).style.display;
}

function getval(id)
{
 z=document.getElementById(id);
 if(z) return z.value;
 return '';
}

  function setval(id,v)
{
 z=document.getElementById(id);
 if(z) document.getElementById(id).value=v;
}

function click_it(id)
{
 //alert('click_it('+id+')');
 if(document.getElementById(id))
 document.getElementById(id).click();
}

function ischecked(a)
{
aa=a.split('|');
total=aa.length;

for(i=0;i<total;i++) if(ischk(aa[i])) return 1;
return 0;
}

function ischk(a)
{
 d=document.getElementById(a);
 if(!d.disabled) d=d.checked; else d=0;
 return d;
}
