function onbg(a){
	if(document.getElementById('bg'+a)){
		document.getElementById('bg'+a).className="bg1";
	}
}
function offbg(a){
	if(document.getElementById('bg'+a)){
		document.getElementById('bg'+a).className="bg2";
	}
}
function on(b){
	b.className="ItCatA";
}
function off(b){
	b.className="ItCat";
}
function onI(im){
	//obj = document.getElementById('im'+im);
	//obj.src = obj.name;
	document.getElementById('link'+im).className="linkCa";
}
function offI(im){
	//document.getElementById('im'+im).src="images/it1.jpg";
	document.getElementById('link'+im).className="linkC";
}

isOpera = 0;
isOpera6 = 0;
isOpera7 = 0;
isOpera8 = 0;
isOpera9 = 0;
isNetscape4 = 0;
isMozilla = 0;
isDOM=(document.getElementById)?1:0;//DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isOpera=isOpera5=(window.opera && isDOM)?1:0;//Opera 5+
isOpera6=(isOpera && window.print)?1:0; //Opera 6+
isOpera7=(isOpera && document.readyState)?1:0 ;//Opera 7+
isMSIE=(document.all && document.all.item && !isOpera)?1:0; //Microsoft Internet Explorer 4+
isMSIE5=(isDOM && isMSIE)?1:0; //MSIE 5+
isNetscape4=(document.layers)?1:0; //Netscape 4.*
isMozilla=(isDOM && navigator.appName=="Netscape")?1:0; //Mozilla eee Netscape 6.*

var oo=0;
nav=navigator.userAgent;k=nav.indexOf("Opera");if(k>1){oo=1}//Opera


function show(id, evt){
	var inf = document.getElementById(id);
	var innerHeight_ = window.innerHeight ? window.innerHeight : document.documentElement.offsetHeight;
	evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	inf.style.left = evt.clientX + 50 + 'px';
	inf.style.top = evt.clientY + document.documentElement.scrollTop + 'px';
	//alert(event.clientX+'|'+event.clientY);
	//inf.style.left = ( document.body.clientWidth / 2 - inf.clientWidth / 2 ) + 50 + 'px';
	//inf.style.top = ( document.documentElement.scrollTop + innerHeight_ / 2 - inf.clientHeight / 2 - 65) + 'px';
	inf.style.display = "block";

}
function hide(id){
	document.getElementById(id).style.display = "none";
}

function calcItem(im, priceCount) {
	document.getElementById('itemCount_'+im).value = document.getElementById('boxCount_'+im).value * document.getElementById('itemQuantity_'+im).value;
	calcPrize(im, priceCount);
}
function calcBox(im, priceCount) {
	document.getElementById('boxCount_'+im).value = document.getElementById('itemCount_'+im).value / document.getElementById('itemQuantity_'+im).value;
	calcPrize(im, priceCount);
}
function calcPrize(im, priceCount) {
	var sumRow;
	sumRow = document.getElementById('itemPrize_'+im).value * document.getElementById('boxCount_'+im).value / priceCount;
	document.getElementById('boxPrize_'+im).innerHTML = sumRow;
	calcAllPrize();
}
function calcAllPrize() {
	var mtable, mrow;
	var sumRow, sumAll = 0;
	mtable = document.getElementById('tablePrize');
	//alert(table.rows[0].cells);return;
	if (mtable) {
		for (i=0; i<mtable.rows.length; i++) {
			if (mtable.rows[i].id) {
				mrow = mtable.rows[i];
				//sumRow = document.getElementById('itemPrize_'+mrow.id).value * document.getElementById('itemCount_'+mrow.id).value / 1000;
				sumRow = parseInt(document.getElementById('boxPrize_'+mrow.id).innerHTML);
				if (sumRow) mrow.className = "contTRL";
				else mrow.className = "contTR";
				sumAll += sumRow;
			}
		}
	}
	document.getElementById('allPrize').innerHTML = sumAll;
}

function ADD() {
	//alert(document.body.clientHeight);
	document.getElementById('add').style.display = "block";
	document.getElementById('add').style.left = document.body.clientWidth/4 + "px";
	document.getElementById('add').style.top = document.body.clientHeight-(document.body.clientWidth/2) + "px";
}
function ADDoff() {
	document.getElementById('add').style.display = "none";
}

var req;
var reqTimeout;
 
function loadXMLDoc(url) {
    req = null;
    if (window.XMLHttpRequest) {
        try {
            req = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            req = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                req = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }
 
    if (req) {
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
        reqTimeout = setTimeout("req.abort();", 5000);
    } else {
        alert("Браузер не поддерживает AJAX");
    }
}
 
function processReqChange() {
	document.getElementById("addT1").innerHTML = stat(req.readyState);
    //document.form1.state.value = stat(req.readyState); 
 
 
    if (req.readyState == 4) {
        clearTimeout(reqTimeout);
 
        //document.form1.statusnum.value = req.status; 
        //document.form1.status.value = req.statusText; 
 
        // only if "OK"
        if (req.status == 200) {
        	document.getElementById("addT1").innerHTML = req.responseText;
            //document.form1.response.value=req.responseText;
        } else {
            alert("Не удалось получить данные:\n" + req.statusText);
        }
    }  
}
 
function stat(n)
{
  switch (n) {
    case 0:
      return "не инициализирован";
    break;
 
    case 1: 
      return "загрузка...";
    break;
 
    case 2: 
      return "загружено";
    break;
 
    case 3: 
      return "в процессе...";
    break;
 
    case 4: 
      return "готово";
    break;
 
    default:
      return "неизвестное состояние";  
  }  
}
 
function requestdata(params)
{
	var mtable, mrow;
	var sumRow, sumAll = 0;
	var request;
	mtable = document.getElementById('tablePrize');
	//alert(table.rows[0].cells);return;
	request = "?group="+params+"&act=add";
	for (i=0; i<mtable.rows.length; i++) {
		if (mtable.rows[i].id) {
			mrow = mtable.rows[i];
			sumRow = document.getElementById('itemPrize_'+mrow.id).value * document.getElementById('boxCount_'+mrow.id).value / 1000;
			if (sumRow > 0) request += "&item_count_"+mrow.id+"="+document.getElementById('itemCount_'+mrow.id).value;
			sumAll += sumRow;
		}
	}
	if (sumAll){
		ADD();
		loadXMLDoc(request);
	} else alert("Товар не выбран!");
  //alert(params);
}

function wo(link,ww,hh,title) {
	w=window.open(link,'',(ww ? 'width='+ww+',' : '')+(hh ? 'height='+hh+',' : '')+'toolbar=0,scrollbars=0,resizable');
	if (link.indexOf('.html')==-1) {
		if (document.layers) title='';
		w.document.open();
		w.document.write('<html><head><title>'+title+'</title><meta http-equiv=Content-Type content="text/html; charset=windows-1251"></head>');
		w.document.write('<body bgcolor=white marginwidth=0 marginheight=0 topmargin=0 leftmargin=0><table width=100% height=100% border=0 cellspacing=0 cellpadding=0><tr><td align=center><img src='+link+' width='+ww+' height='+hh+' border=0 alt=""></td></tr></table></body></html>');
		w.document.close();
	}
	w.focus();
}


