function isEmpty(str) {
	for (var j=0; j<str.length; j++) {
		if (" " != str.charAt(j)) return false;
	}
	return true;
}

function checkForm(f)
{
	for (var i=0; i<f.elements.length; i++) {
		if (null!=f.elements[i].getAttribute("forcheck")) {
		if (isEmpty(f.elements[i].value) || f.elements[i].value == f.elements[i].getAttribute("forcheck")) {
				alert('Вы не написали ' + f.elements[i].getAttribute("forcheck") + '!');
				f.elements[i].focus();
				return false;
		}
		}
	}
	f.go.disabled = true;
	return true;
}

function checkSearch(f)
{
	if (f.text.value.length < 3) {
		alert('Вы ввели слишком маленький запрос! Минимальное количество символов - 3.');
		f.text.focus();
		return false;
	}
	return true;
}

function insFl(v) {

	var flashinstalled = 0;
	var flashversion = 0;
	MSDetect = "false";

	if (navigator.plugins && navigator.plugins.length)
	{
	    x = navigator.plugins["Shockwave Flash"];
	    if (x)
	    {
		flashinstalled = 2;
		if (x.description)
		{
		    y = x.description;
		    flashversion = y.charAt(y.indexOf('.')-1);
		}
	    }
	    else
		flashinstalled = 1;
	    if (navigator.plugins["Shockwave <span class='searchlite'>Flash</span> 2.0"])
	    {
		flashinstalled = 2;
		flashversion = 2;
	    }
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{
	    x = navigator.mimeTypes['application/x-shockwave-flash'];
	    if (x && x.enabledPlugin)
		flashinstalled = 2;
	    else
		flashinstalled = 1;
	}
	else
	    MSDetect = "true";


	if (MSDetect == "true") {
		for (var i=3;i<10;i++) {
			if (eval('new ActiveXObject("ShockwaveFlash.ShockwaveFlash.'+i+'")')) {
				flashversion = i;
				flashinstalled = 2;
			} else {
				flashinstalled = 0;
			}
		}
	}

	if (flashinstalled == 2 && flashversion >= v)
	{
		return true;
	} else {
		return false;
	}

}

function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
	
    if (element.tagName=='IMG') //Если текущий элемент картинка (тэг IMG)
    {
      if (/\.png$/.test(element.src)) //Если файл картинки имеет расширение PNG
      {
        src = element.src;
        element.src = "/i/s.gif";
      }
    }
    else
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        element.runtimeStyle.backgroundImage="none";
      }
    }
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}


function tfocus(el)
{
	if (el.value == el.getAttribute("forcheck")) {
		el.value = '';
	}
}

function tblur(el)
{
	if (isEmpty(el.value)) {
		el.value = el.getAttribute("forcheck");
	}
}

function checkMail(mt)
{
	var reg = new RegExp("^[A-Za-z0-9_-]{1,20}@(([A-Za-z0-9-]+\\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})$");
	if(!reg.test(mt)) {
		return false;
	} else {
		return true;
	}
}

function replaceDivs(div1, div2)
{
	document.getElementById(div1).style.display = 'block';
	document.getElementById(div2).style.display = 'none';
}

function MM_preloadImages() {
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() {
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) {
	var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src;
	x.src=a[i+2];}
}

function getCookiesCat()
{
	var outArr = new Array();
	var aCookie = document.cookie.split("; ");

	for (var i=0; i < aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split("=");
		if (aCrumb[0].indexOf('o.')!=-1) {
			folder = aCrumb[0].replace(/o\./, "");
			outArr.push(folder);
		}
	}


	return outArr;
}


function wopen(name,width,height,top,left,scroll)
{
	top = (top) ? top : (screen.height/2)-(height/2)-30;
	left = (left) ? left : (screen.width/2)-(width/2);
	scroll = (scroll || scroll == 0) ? scroll : 1;
	today = new Date();
	open(name,parseInt(today.getSeconds()),"location=0,directories=0,status=0,menubar=0,scrollbars="+scroll+",resizable=1,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left);
}

function cmp()
{
	allChecks = document.getElementsByName("cmp");
	ids = "";	

	for (i=0; i<allChecks.length; i++) {
		if (allChecks[i] == undefined) continue;
		if (allChecks[i].checked) {
			ids += allChecks[i].value + ",";
		}
	}
	
	if (ids == "") {
		alert('Вы не выбрали ни одного товара для сравнения!');
	} else {
		wopen('/catalog/cmp.html?ids='+ids.substr(0, ids.length-1), 900, 600);
	}
}

function cmp_clear()
{
	allChecks = document.getElementsByName("cmp");

	for (i=0; i<allChecks.length; i++) {
		if (allChecks[i] == undefined) continue;
		if (allChecks[i].checked) {
			allChecks[i].checked = false;
		}
	}
}


child = false;
cm = null;
hide_delay = 300;
tstat = 0;

function switchDiv(objElement, bolVisible){
	if(!bolVisible) {
		objElement.style.visibility = "hidden";
	} else {
		objElement.style.visibility = "visible";
	}
	return 1;
}

function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp];
		el = el.offsetParent;
	}
	return iPos;
}

function showI(mob, xpos, ypos) {
	if (cm!=null) {
		switchDiv(cm,false);
	}
	el = document.getElementById('t_'+mob);
	if (mob!=null) {
		mb=document.getElementById(mob);
		mb.style.left = getPos(el,"Left")+xpos;
		mb.style.top = getPos(el,"Top")+ypos;
		switchDiv(mb,true);
		cm=mb;
	}

}

function showDiv(mob, xpos, ypos) {
	cancelhide();
	timer2=setTimeout("showI('"+mob+"', "+xpos+", "+ypos+")",hide_delay);
	return 1;
}

function hideDiv() {
	clearTimeout(timer2);
	timer1=setTimeout("showI(null)",hide_delay);
	tstat=1;
	return 1;
}

function cancelhide() {
	if (tstat==1) {
		clearTimeout(timer1);
		tstat = 0;
	}
	return 1;
}

function checkSearch(f)
{
	if (f.text.value.length < 3) {
		alert('Вы ввели слишком маленький запрос! Минимальное количество символов - 3.');
		f.text.focus();
		return false;
	}
	return true;
}