function toggle() {
var x = document.getElementById("xdiv");
x.style.display = ("block" != x.style.display) ? "block" : "none";
}

function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function checkEmail(obj){
    var str=obj.value;
    if(str=='') return true;
    if (/^([\w-~_]+\.)*[\w-~_]+@([\w-_]+\.){1,3}\w{2,4}$/.test(str))	return true;

alert("Неправильный e-mail адрес");
obj.focus();
return false;
}

function SearchForm( theform,fieldName )
{
	var MissingFields = false;
	var strFields = "";

 	if( theform.searchstring.value == '')
    {
		 MissingFields = true;
	  }

  if( MissingFields )
    {
    //alert("Введите модель для поиска");
    return false;
  	}

 return true;
}

function badImg(img){
	//alert('badImg');
	try{
		img.src='/cat/blank.gif';
		img.width=100;
		img.height=100;
	}
	catch(e){}
}

function fixImgs(whichId, size_x, size_y) {
try{var pix=document.getElementById(whichId).getElementsByTagName('img');
  for (i=0; i<pix.length; i++) {
  if(pix[i].id=='res'){pix[i].style.display = "block";
   var orginal_width  = pix[i].width;
   var orginal_height = pix[i].height;
   var x  = parseInt(size_x);
   var y  = parseInt(size_y);

     x = Math.floor(y * orginal_width / orginal_height);
     y = Math.floor(x * orginal_height / orginal_width);

     if (orginal_width > parseInt(size_x) || orginal_height > parseInt(size_y))
      {
		  if ( (orginal_height/y) > (orginal_width/x) )
       {
			 x=Math.ceil((orginal_width/orginal_height)* y);
		   }
      else
       {
			 y=Math.ceil(x/(orginal_width/orginal_height));
		   }
       pix[i].width=x;
       pix[i].height=y;
      }
    }
   }
  } catch(e){}
}


function redir(path) {document.location.href = path;}
