var SITE_URL='/';
Opera5 = window.opera && DOM;
IE = document.all && !Opera5;

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function big_pic_show(link,w,h){
 bodya=truebody();
 elem=document.getElementById('big_foto');
 mewimage=document.getElementById('big_img');
 mewimage.src=link;
 if(w>bodya.clientWidth){
  ww=bodya.clientWidth*0.9;
  h=Math.round(h*ww/w); w=ww;
 }
 mewimage.width=w;
 mewimage.height=h;
 ll=Math.round(bodya.clientWidth/2-elem.clientWidth/2+bodya.scrollLeft);
 tt=Math.round(bodya.clientHeight/2-elem.clientHeight/2+bodya.scrollTop);
 elem.style.left=ll+(IE ? '' : 'px;');
 elem.style.top=tt+(IE ? '' : 'px;');
 elem.style.visibility="visible";
}

function change_checkbox(checkid){
  checkbox=document.getElementById(checkid);
	if(checkbox.checked) checkbox.checked=false;
	else checkbox.checked=true;
}
function filter_submit(){	cat=document.getElementById('category_id').value;
	brand=document.getElementById('brand_id').value;
	from=document.getElementById('price_from').value;
	till=document.getElementById('price_till').value;
	if(cat=='') cat=0;
	if(brand=='') brand=0;
	if(from=='' || !parseInt(from)) from=0;
	if(till=='' || !parseInt(till)) till=0;
	location.href=SITE_URL+'products/'+cat+"/0/"+brand+"/"+from+"/"+till+"/";
	return false;
}
if(!getCookie('newWinCounter')) createCookie('newWinCounter','0',1);
function open_window(link,w,h){
  var newWinCounter=getCookie('newWinCounter');
  var top = (screen.height - h) / 2;
  var left = (screen.width - w) / 2;
  var win = "width="+(w+20)+",height="+(h+20)+",top="+top+",left="+left+",menubar=no,location=no,resizable=yes,scrollbars=yes";
  newWin = window.open(link,'newWin'+newWinCounter,win);
  newWinCounter
  newWin.focus();
  createCookie('newWinCounter',newWinCounter+1,1);
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
String.prototype.trim=function() { return this.replace(/^\s+|\s+$/g, ''); }
function addHandler(object, event, handler){
  if(!IE) object.addEventListener(event, handler, false);
  else object.attachEvent('on' + event, handler);
}
function removeHandler(object, event, handler){
  if(!IE) object.removeEventListener(event, handler, false);
  else object.detachEvent('on' + event, handler);
}
function input_focus(inp_id,text){
  var inp=document.getElementById(inp_id);
  if(inp.value=='') inp.value=text;
  function inp_focus(e){
    if(this.value.trim()==text) this.value='';
  }
  function inp_blur(e){
    if(this.value.trim()=='') this.value=text;
  }
  addHandler(inp,'focus',inp_focus);
  addHandler(inp,'blur',inp_blur);
}
function input_check_numeric(elemID,after_dot){
  if(!after_dot) after_dot=0;
  elem=document.getElementById(elemID);
  var temp_str='';
  elem.value=elem.value.replace(',','.');
  for(i=0; i<elem.value.length; i++){
    ch=elem.value.substr(i,1);
    if((ch.charCodeAt(0)>=48 && ch.charCodeAt(0)<=57) || (after_dot>0 && ch=='.' && temp_str.indexOf('.')==-1)) temp_str+=ch;
  }
  if((pos=temp_str.indexOf('.'))!=-1) temp_str=temp_str.substr(0,pos+after_dot+1);
  elem.value=temp_str;
}
