nn4 = (document.layers)? true : false;
ie4 = (document.all)? true : false;
nn6 = (document.getElementById && !ie4)? true : false;
function popupWin(cardName, winW, winH, winTitle) {
//if (nn4 || ie4 || nn6) {
posX = Math.round((screen.width - winW) / 2);
posY = Math.round((screen.height - winH) / 2);
posCode = /*(nn4 || nn6)? 'screenX='+posX+',screenY='+posY :*/ 'left='+posX+',top='+posY;
cardWindow = window.open('','_blank','menubar=no,toolbar=no,scrollbars=no,status=no,width='+winW+',height='+winH+','+posCode);
cardWindow.document.open();
cardWindow.document.write('<html><head><title>'+winTitle+'<\/title><\/head>');
cardWindow.document.write('<body marginwidth=0 marginheight=0 topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0>');
cardWindow.document.write('<center><img src="'+cardName+'" width="'+winW+'" height="'+winH+'" align="center" /></center><\/body><\/html>');
cardWindow.document.close();
cardWindow.focus();
}

function LoadBrands(catalogue_id) {
if (catalogue_id > 0) {
    DisableElement('search_button');
    DisableElement('good_id');
    DisableElement('brand_id');
	JsHttpRequest.query(
		'/index_ajax.php',
        {
			'action':'brands_load',
			'catalogue_id':catalogue_id
        },
        function(result, errors) {
            if (result) {
				if (result["res"] == 'failed')
				{
				 alert(result["errors"]);
				}
				else
				{
				 document.getElementById('msel02').innerHTML = result["res"];
				}
            }
        },
    false
    );
}
}

function LoadGoods(brand_id) {
if (brand_id > 0) {
    DisableElement('search_button');
    DisableElement('good_id');
	JsHttpRequest.query(
		'/index_ajax.php',
        {
			'action':'goods_load',
			'brand_id':brand_id
        },
        function(result, errors) {
            if (result) {
				if (result["res"] == 'failed')
				{
				 alert(result["error"]);
				}
				else
				{
				 document.getElementById('msel03').innerHTML = result["res"];
				 EnableElement('search_button');
				}
            }
        },
    false
    );
}
}

function ChooseGood(good_id)
{
 //if (good_id > 0)
  EnableElement('search_button');
// else
  //DisableElement('search_button');
}

function Search()
{
 DisableElement('search_button');
 good_id = document.getElementById('good_id').value;
 brand_id = document.getElementById('brand_id').value;
 if (good_id <= 0 && brand_id <= 0)
 {
  alert('Выберите что-то из списков для поиска файлов!');
  EnableElement('search_button');
  return;
 }
 
 if (good_id > 0)
 JsHttpRequest.query(
		'/index_ajax.php',
        {
			'action':'goodfiles_load',
			'good_id':good_id
        },
        function(result, errors) {
            if (result) {
				if (result["res"] == 'failed')
				{
				 alert(result["error"]);
				}
				else
				{
				 EnableElement('search_button');
				 document.getElementById('msections').innerHTML = result["res"];
				}
            }
        },
    false
    );
 else
 if (brand_id > 0)
 JsHttpRequest.query(
		'/index_ajax.php',
        {
			'action':'brandfiles_load',
			'brand_id':brand_id
        },
        function(result, errors) {
            if (result) {
				if (result["res"] == 'failed')
				{
				 alert(result["error"]);
				}
				else
				{
				 EnableElement('search_button');
				 document.getElementById('msections').innerHTML = result["res"];
				}
            }
        },
    false
    );
}

function EnableElement(id) {
 document.getElementById(id).disabled=false;
}

function DisableElement(id) {
 document.getElementById(id).disabled=true;
}

function CompareM(good_id,add) {
 if (add == true)
  action = 'compare_add';
 else
  action = 'compare_delete';
 JsHttpRequest.query(
		'/index_ajax.php',
        {
			'action':action,
			'good_id':good_id
        },
        function(result, errors) {
            if (result) {
				if (result["res"] == 'failed')
				 alert(result["error"]);
				//else
				// alert(result["res"]);
            }
        },
    false
    );
}
