

// checks the name of your browser

// isIE or isNN are boolean varibles identeficated this



isNN=navigator.appName.indexOf('Netscape')>=0;

isIE=navigator.appName.indexOf('Explorer')>=0;



var bV=parseInt(navigator.appVersion);

NS4=(document.layers) ? true : false;

IE4=((document.all)&&(bV>=4))?true:false;

ver4 = (NS4 || IE4) ? true : false;



// -------------------------------------------

// open extra window

// usage: openWindow("test.htm") or openWindow("test.jpg", 200, 120)

function resizeflash()
{
	var w=(document.body.clientWidth)-460;
	var h=Math.round(w/1.365625);
	document.getElementById('mainflash').style.width=w;
	document.getElementById('mainflash').style.height=h;
	if(isNN){
		document.getElementById('mainflash2').style.width=w;
		document.getElementById('mainflash2').style.height=h;
	}
}


function openWindow(filename, w, h, winname)

{

    var nWidth;

        var nHeigth;

				if(filename.match(/\?/)){
					         filename += '&'+Math.random();
				}else{
					         filename += '?'+Math.random();
				}

        if (h) nHeigth = h; else nHeigth = 500;

        if (w) nWidth = w; else nWidth = 700;

        if (!winname) winname = "_blank";
        var desktop = window.open(filename, winname,

    "width="+nWidth+",height="+nHeigth+",toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes");

};









//-------------------------------------------------

// go to URL.

function goToURL(url)

 {

  var sURL;

  if (url) sURL=url; else sURL="/";

  location.href=sURL;

 };



// --------------------------------------------------





// --- работа с картинками ---

function openImg(pic, title, wnd)

{

  var sTitle = title ? title : "Просмотр иллюстрации";

  var sWnd = wnd ? wnd : "_blank";



  if (pic)

  {



 var pWnd = window.open('',sWnd,'toolbar=no,location=no,status=no,menubar=no,scrollbars=no, fullscreen=no, resizable=yes, centered=yes');



 var wndCnt;



 wndCnt = "<html><head><title>"+ sTitle +"</title>"+

 "<SCRIPT>function resizer() {"+

 "if (document.images && (document.images['viewport'].readyState == 'complete')) {"+

 "window.blur();"+

 "var H0 = document.images['viewport'].height;"+

 "var W0 = document.images['viewport'].width;"+

 "var nH = (screen.availHeight < H0+30) ? screen.availHeight-30 : H0+30;"+

 "var nW = (screen.availWidth < W0+10) ? screen.availWidth-10 : W0+10;"+

 "var yRatio = nH / (document.images['viewport'].height+30);"+

 "var xRatio = nW / (document.images['viewport'].width+10);"+

 "var nRatio = (xRatio < yRatio) ? xRatio : yRatio;"+

 "document.images['viewport'].width = W0 * nRatio;"+

 "document.images['viewport'].height = H0 * nRatio;"+

 "window.resizeTo(document.images['viewport'].width+10, document.images['viewport'].height+10);"+

 "window.moveTo((screen.availWidth-document.images['viewport'].width)/2,(screen.availHeight-document.images['viewport'].height)/2);"+

 "window.focus();}"+

 "else setTimeout('resizer()', 200);}"+

 "</S"+"CRIPT>\n"+

 "</head><body topmargin=0 leftmargin=0>"+

 "<img src='"+pic+"' name='viewport'>"+

 "<script>resizer();</scr"+"ipt></body></html>";



 pWnd.document.open();

 pWnd.document.write(wndCnt);

 pWnd.document.close();

   }

 }



 function openImgTag(pic, title, wnd)

{

  var sTitle = title ? title : "Просмотр иллюстрации";

  var sWnd = wnd ? wnd : "_blank";



  if (pic)

  {



 var pWnd = window.open('',sWnd,'toolbar=no,location=no,status=no,menubar=no,scrollbars=no, fullscreen=no, resizable=yes, centered=yes');



 var wndCnt;



 wndCnt = "<html><head><title>"+ sTitle +"</title>"+

 "<SCRIPT>function resizer() {"+

 "if (document.images && (document.images[0].readyState == 'complete')) {"+

 "window.blur();"+

 "var H0 = document.images[0].height;"+

 "var W0 = document.images[0].width;"+

 "var nH = (screen.availHeight < H0+50) ? screen.availHeight-50 : H0+50;"+

 "var nW = (screen.availWidth < W0+30) ? screen.availWidth-30 : W0+30;"+

 "var yRatio = nH / (document.images[0].height+50);"+

 "var xRatio = nW / (document.images[0].width+30);"+

 "var nRatio = (xRatio < yRatio) ? xRatio : yRatio;"+

 "document.images[0].width = W0 * nRatio;"+

 "document.images[0].height = H0 * nRatio;"+

 "window.resizeTo(document.images[0].width+10, document.images[0].height+30);"+

 "window.moveTo((screen.availWidth-document.images[0].width)/2,(screen.availHeight-document.images[0].height)/2);"+

 "window.focus();}"+

 "else setTimeout('resizer()', 200);}"+

 "</S"+"CRIPT>\n"+

 "</head><body topmargin=0 leftmargin=0>"+pic+

 "<script>resizer();</scr"+"ipt></body></html>";



 pWnd.document.open();

 pWnd.document.write(wndCnt);

 pWnd.document.close();

   }

 }



// shows the image with scaling if it is bigger



function scaleImg(pic, limit)

{

  var nLimit = limit ? limit : 400;



  if (pic)

  {

  if (document.images && (pic.readyState == 'complete'))

  {



    var H0 = pic.height;

         var W0 = pic.width;

        var nH = (nLimit < H0) ? nLimit : H0;

        var nW = (nLimit < W0) ? nLimit : W0;

        var yRatio = nH / pic.height;

        var xRatio = nW / pic.width;

        var nRatio = (xRatio < yRatio) ? xRatio : yRatio;

        pic.width = W0 * nRatio;

        pic.height = H0 * nRatio;



   }

   else setTimeout('scaleImg('+pic+','+limit+')', 200);



  }

}


function vrfyMail(email)
{
 if ((email.value == "ваш@e-mail") || (email.value == ""))
 {
  alert("Не заполнено поле c адресом электронной почты");
  email.focus();
  return false;
 }

 if (email.value.indexOf("@") != "-1" &&
     email.value.indexOf(".") != "-1")
   return true;
  else
  {
  alert("Неверно заполнено поле c адресом электронной почты");
  email.focus();
  return false;
   }
}




// открытите/закрытие секций в админе



function sectionExp(item)

{

if (document.all)

 {

 var pSection=document.all[item];

  if (pSection)

   pSection.style.display = (pSection.style.display=="none" ? "block" : "none");

 }

}

function flag_on()
{
   for(j=1;j<icheck;j++)
    document.getElementById('t'+j).checked=true;
}

function flag_off()
{
   for(j=1;j<icheck;j++)
    document.getElementById('t'+j).checked=false;
}

function mousePageXY(e)
{
    if (!e) e = window.event;
    if (e.pageX || e.pageY)
    {
      mouse_x = e.pageX;
      mouse_y = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
      mouse_x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
      mouse_y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
    }

}
document.onmousemove = function(e){var mCur =mousePageXY(e);}

function go_login(){
	var login=document.getElementById('login').value;
	var password=document.getElementById('password').value;
	openWindow('/login?login='+login+'&password='+password, 300, 300);
}

function message_to_reg(mes){
	if(mes==1) mes="Данный раздел доступен только зарегистрированным пользователям, являющимися покупателями. Хотите начать процесс регистрации?";
	if(mes==2) mes="Данный раздел доступен только зарегистрированным пользователям, являющимися поставщиками. Хотите начать процесс регистрации?";
	if(mes==3) mes="Данный раздел доступен только зарегистрированным пользователям? Хотите начать процесс регистрации?";
	if(confirm(mes)){
		window.location='/work/register';
	}
}


var rownumber=1;

function addrow(){
    var d = document;
    // Считываем значения с формы
    //name = d.getElementById('name').value;
    //initials = d.getElementById('initials').value;
    //posada = d.getElementById('posada').value;

		var header=d.getElementById('header').value;
		var tech=d.getElementById('tech').value;
		var zavod=d.getElementById('zavod').value;
		var cena_zavod=d.getElementById('cena_zavod').value;
		var cena_sklad=d.getElementById('cena_sklad').value;
    // Находим нужную таблицу
    if(!header || !tech || !zavod || !cena_zavod || !cena_sklad) {alert ('необходимо заполнить все поля!'); exit}
    var tbody = d.getElementById('tab1').getElementsByTagName('TBODY')[0];

    // Создаем строку таблицы и добавляем ее
    var row = d.createElement("TR");
    tbody.appendChild(row);
    row.id='tr'+rownumber;

    // Создаем ячейки в вышесозданной строке
    // и добавляем тх
    var td1 = d.createElement("TD");
    var td2 = d.createElement("TD");
    var td3 = d.createElement("TD");
    var td4 = d.createElement("TD");
    var td5 = d.createElement("TD");
    var td6 = d.createElement("TD");

    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row.appendChild(td4);
    row.appendChild(td5);
    row.appendChild(td6);

    // Наполняем ячейки
    td1.innerHTML = header+'<input type="hidden" name="header" value="'+header+'">';
    td2.innerHTML = tech+'<input type="hidden" name="tech" value="'+tech+'">';;
    td3.innerHTML = zavod+'<input type="hidden" name="zavod" value="'+zavod+'">';;
    td4.innerHTML = cena_zavod+'<input type="hidden" name="cena_zavod" value="'+cena_zavod+'">';;
    td5.innerHTML = cena_sklad+'<input type="hidden" name="cena_sklad" value="'+cena_sklad+'">';;
    td6.innerHTML = '<a href="javascript: delrow('+rownumber+')"><small>удалить</small></a>';
    rownumber++
}

function delrow(num_id)
{
    var d = document;

    //var len = arr_del_me.length;
    var tbody = d.getElementById('tr'+num_id).parentNode;
    tbody.removeChild(d.getElementById("tr"+num_id));
}