var prevMenu = null;
var currMenu = null;
var im=new Image();

var win= null;
function OpenNewWindow(mypage,w,h,myname){
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no'
win=window.open(mypage,myname,settings)
if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function isNetscape(){
  if (navigator.appName == "Netscape") {
    return true
  }else{
    return false
  }
}

function menuMouseOver(obj)
{
	prevMenu = currMenu;
	currMenu = obj;
	if (prevMenu)
	{
		HideChild(prevMenu);
	}
	ShowChild(currMenu);
}
function menuMouseOut(menuObj)
{
	var obj = document.getElementById('submenu_'+menuObj.getAttribute('menuId'));
	if(obj){
		if (!isNetscape()) {
			if(event.toElement!=obj && !obj.contains(event.toElement)){
				var x1 = getOffsetLeft(menuObj);
				var x2 = x1 + menuObj.offsetWidth;
				if(!(event.offsetX<=x2 && event.offsetX>=x1 && event.offsetY>getOffsetTop(menuObj))){
					HideChild(menuObj);
				}
			}
		} else {
			var x1 = getOffsetLeft(menuObj);
			var x2 = x1 + menuObj.offsetWidth;
			if(!(MouseEvent.clientX<=x2 && MouseEvent.clientX>=x1 && MouseEvent.clientY>getOffsetTop(menuObj))){
				HideChild(menuObj);
			}		
		}
	}
}
function HideChild(menuObj)
{
	var obj = document.getElementById('submenu_'+menuObj.getAttribute('menuId'));
	if (obj)
	{
		if (!isNetscape()) {
			obj.style.display = 'none';
		}
		obj.style.zIndex = '0';
		obj.style.visibility='hidden';
	}
}
function getOffsetLeft(obj)
{
  var tmp = 0;
  if (obj != document.body) {
	tmp = getOffsetLeft(obj.offsetParent) + obj.offsetLeft;
  } else {
    tmp = obj.offsetLeft;
  }
  return tmp;
}
function getOffsetTop(obj)
{
  var tmp = 0;
  if (obj != document.body) {
	tmp = getOffsetTop(obj.offsetParent) + obj.offsetTop;
  } else {
    tmp = obj.offsetTop;
  }
  return tmp;
}
function ShowChild(menuObj)
{
	var obj = document.getElementById('submenu_'+menuObj.getAttribute('menuId'));
	if (obj)
	{
		obj.style.zIndex = '100';
		obj.style.top = getOffsetTop(menuObj)+menuObj.offsetHeight+0;
		obj.style.left = getOffsetLeft(menuObj)+0;
		obj.style.display = '';
		obj.style.visibility='visible';
	}
}
function submenuMouseOut(obj)
{
	if (!isNetscape()) {
		if(event.toElement!=currMenu && !obj.contains(event.toElement)){
			prevMenu = null;
			currMenu = null;
			obj.style.display = 'none';
			obj.style.visibility='hidden';
			obj.style.zIndex = '0';
		}
	} else {
			prevMenu = null;
			currMenu = null;
			obj.style.visibility='hidden';
			obj.style.zIndex = '0';
	}
}

function submenuMouseOver(obj)
{
	if (!isNetscape()) {
		if(event.toElement!=currMenu && !obj.contains(event.toElement)){
			prevMenu = null;
			currMenu = null;
			obj.style.display = 'block';
			obj.style.visibility='visible';
			obj.style.zIndex = '100';
		}
	} else {
			prevMenu = null;
			currMenu = null;
			obj.style.visibility='visible';
			obj.style.zIndex = '100';
	}
}

function rot13(str) {
    var l = str.length;
    var s = '';
    var c = 0;

    for(i = 0; i < l; i++) {
        c = str.charCodeAt(i);
        if((c >= 97 && c <= 109) || (c >= 65 && c <= 77)) {
            c += 13;
        } else if((c >= 110 && c <= 122) || (c >= 78 && c <= 90)) {
            c -= 13;
        }
        s += String.fromCharCode(c);
    }
    return(s);
}

function order(id, s) {
	if (id!="") im.src="options.php?tov="+id+"&s="+s+"&act=add";
	alert("Препарат добавлен в Корзину. Оформить заказ вы можете в разделе 'Ваш заказ'.");
}

function delit(id, s) {
	if (id!="") {
		if (confirm("Позиция будет удалена из заказа. Продолжить?")) {
			im.src="options.php?tov="+id+"&act=del";
			document.forms[0].submit();
		}
	} else alert("Ошибка передачи данных");
}

function recalculation() {
	alert("Итоговая сумма пересчитана!");
	document.forms[0].act1.value="recalc";
	document.forms[0].submit();
}

function complete_order(){
	document.forms[0].act1.value="complete";
	document.forms[0].submit();	
}

function sendorder() {
	if (document.forms[0].family.value=="") {
		alert("Ваша фамилия...");
	} else if (document.forms[0].nm.value=="") {
		alert("Ваше имя...");
	} else if (document.forms[0].surname.value=="") {
		alert("Ваше отчество...");
	} else if (document.forms[0].zipcode.value=="") {
		alert("Почтовый индекс...");
	} else if (document.forms[0].address.value=="") {
		alert("Адрес...");
	} else {
		document.forms[0].act1.value="sendorder";
		document.forms[0].submit();	
	}
}

function go2main() {
	document.forms[0].target="top";
	document.forms[0].action="index.php";
	document.forms[0].act1.value="";
	document.forms[0].submit();	
}

function go2price() {
	document.forms[0].target="top";
	document.forms[0].action="index.php?page=9";
	document.forms[0].act1.value="";
	document.forms[0].submit();	
}

function searchprep() {
	if (document.forms[0].nozolog.value!=0) {
		document.forms[0].act1.value="search";
		document.forms[0].submit();
	}
}

function check_(str) {
	
	var t=parseInt(str);
	if (isNaN(t)) {
		return false;
	}
	str_t=new String(t);
	if (str_t.length < str.length) {
		return false;
	}
	return true;

}

function get_s(str, nm) {
	var t=0;
	var s1=new Number(0);
	var flag=0;
	var n=parseInt(nm);

	if (check_(str)) {

		t=parseInt(str);
		var d=eval("var g=document.forms[0].price"+n+".value;");
		s1=parseFloat(g)*t;
		s1=Math.round(s1*100)/100;

		var b=eval("document.forms[0].sum"+n+".value=new String(s1);");

	} else {
		var b=eval("document.forms[0].sum"+n+".value=new String(0);");
	} 
	var b=eval("document.forms[0].kol"+n+".focus();");	
}
