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

// 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 openWindow(filename, w, h)

{

    var nWidth;

	var nHeigth;

	

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

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

	

	var desktop = window.open(filename, "_blank", 

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

};



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

// inserts flash move into the document body


function formReset(elementid)
{
 if(elementid){
	if(document.getElementById(elementid)){sel = document.getElementById(elementid).options[0].selected = true;}
}
else {
 if(document.getElementById('inter')){  sel = document.getElementById('inter').options[0].selected = true;}
// if(document.getElementById('part')){  sel = document.getElementById('part').options[0].selected = true;}
 if(document.getElementById('countr')){ sel = document.getElementById('countr').options[0].selected = true;}
 if(document.getElementById('region')){ sel = document.getElementById('region').options[0].selected = true;}
 if(document.getElementById('contin')){	sel = document.getElementById('contin').options[0].selected = true;}
 if(document.getElementById('month')){	 document.getElementById('month').options[0].selected = true;}
 if(document.getElementById('timenow')){	document.getElementById('timenow').value = "";}
	}
}

//function chkString(sid, max)
//{
//    if(document.getElementById(sid))
//    {
//        var len, str;
//        str = document.getElementById(sid).value;
        //str = str.replace(/\s/gm, "");
        //str = str.replace(/\ /gm, "");
        //str = str.replace(/<.+?>/gm, "");
        //str = str.replace(/&nbsp;/gm, "");
        //str = str.replace(/&lt;/gm, "");
        //str = str.replace(/&gt;/gm, "");
//        len = str.length;
//        if(len > max)
//        {
                //max = /^(.{0,max})\w+/;
//                str = str.replace( /^(.{0,80})\w+/, "$1");
//                document.getElementById(sid).value = str;
//                alert('Название не может привышать '+max+' символов');
//        }
        
//    }
//}
 
 
//function chkPort(sid, max)
//{
//    if(document.getElementById(sid))
//    {
//        var len, str;
//        str = document.getElementById(sid).value;
//        str = str.replace(/\s/gm, "");
        //str = str.replace(/\ /gm, "");
        //str = str.replace(/<.+?>/gm, "");
        //str = str.replace(/&nbsp;/gm, "");
        //str = str.replace(/&lt;/gm, "");
        //str = str.replace(/&gt;/gm, "");
//        len = str.length;
//        if(len > max)
//        {
                //max = /^(.{0,max})\w+/;
//                str = str.replace( /^(.{0,120})\w+/, "$1");
//                document.getElementById(sid).value = str;
//                alert('Название не может привышать '+max+' символов');
//        }
        
//    }
//}

function viewPic(pic)
{
    	if(document.getElementById(pic)){
            if(document.getElementById(pic).style.display == "block"){
	        document.getElementById(pic).style.display = "none";
            }else{
                document.getElementById(pic).style.display = "block";
            }
	}
}

function showGallery(ng, isframe, extraHeight)
{
        var H1;
        if(window.parent.document.getElementById('contentID'))
        {
                H1 = (parseInt(window.parent.document.getElementById('contentID').offsetHeight));
        }
        else
        {
		if(window.parent.document.getElementById('ContentBlock')){
	                H1 = (parseInt(window.parent.document.getElementById('ContentBlock').offsetHeight));}
		else {
	                H1 = (parseInt(window.parent.document.getElementById('contentpage').offsetHeight));}
        }
	if(extraHeight && isIE){H1 = H1 + extraHeight;}
	if(window.parent.document.getElementById(ng))
	{
             window.parent.document.getElementById(ng).style.height = H1+"px";
             //document.getElementById('innerFrame').style.height = H1+"px";
            if(window.parent.document.getElementById(ng).style.display == "block")
	    {
	        window.parent.document.getElementById(ng).style.display = "none";
            }
	    else
	    {
                window.parent.document.getElementById(ng).style.display = "block";
            }
	}
}

function onloadGallery(ng, page)
{

        var stmp;
        var Cl = fotos.collection.length;
     
        stmp = document.getElementById('bigPic').name;
//        if(!stmp)
        {
		if(document.getElementById('sPic'+window.fotos.collection[0].id))
			{
                document.getElementById('sPic'+window.fotos.collection[0].id).style.color = "#fa6525"; 
                document.getElementById('smallPic'+window.fotos.collection[0].id).style.border = "2px solid #fa6c00";
			}
                document.getElementById('bigPic').name = fotos.collection[0].id;
                document.getElementById('bigPic').style.backgroundImage = "url("+fotos.collection[0].big+")";
        }
        for (var i=0; i<Cl; i++)
        {
                document.getElementById('smallPic'+fotos.collection[i].id).src = fotos.collection[i].src;
        }
	pic_id = document.getElementById('bigPic').name = fotos.collection[0].id;
}

function showPicGrey(spic, sid)
{        
        var stmp;
        stmp = document.getElementById('bigPic').name;
        if(stmp)
        {
		if(document.getElementById('sPic'+stmp)){
	                document.getElementById('smallPic'+stmp).style.border = "2px solid #999999";
	                document.getElementById('sPic'+stmp).style.color = "#333333"; 
			}
        }
	if(document.getElementById('sPic'+sid)){
       		document.getElementById('sPic'+sid).style.color = "#fa6525"; 
        	document.getElementById('smallPic'+sid).style.border = "2px solid #fa6c00";
		}
        document.getElementById('bigPic').name = sid;
	document.getElementById('bigPic').style.backgroundImage = "url("+spic+")";
}

function showPic(spic, sid)
{        
        var stmp;
        stmp = document.getElementById('bigPic').name;
        if(stmp)
        {
		if(document.getElementById('sPic'+stmp)){
                	document.getElementById('smallPic'+stmp).style.border = "2px solid #999999";
	                document.getElementById('sPic'+stmp).style.color = "#ffffff"; 
			}
        }
	if(document.getElementById('sPic'+sid)){
        	document.getElementById('sPic'+sid).style.color = "#fa6525"; 
	        document.getElementById('smallPic'+sid).style.border = "2px solid #fa6c00";
		}
        document.getElementById('bigPic').name = sid;
	document.getElementById('bigPic').style.backgroundImage = "url("+spic+")";
}

function updateTags(oid, tags)
{
        if(window.opener.document.getElementById(oid))
        {
		window.opener.document.getElementById(oid).value = tags;
        }
}

function alertTags(max,th)
{
        alert("Общая длина тегов привышает допустимую норму " + max + " символов.\nОбщая длина имеющихся и выбраных выми тегов равняется " + th + " символам.");
}

function insertFlash(filename, w, h)

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

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



 	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"');

	document.write(' ID=24 WIDTH='+ nWidth + 'HEIGHT=' + nHeigth + '>');

 	document.write('<PARAM NAME=movie VALUE="33.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#003399>');

	document.write('<EMBED src=' + filename + ' quality=high bgcolor=#003399  WIDTH='+ nWidth + 'HEIGHT=' + nHeigth + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');

	document.write('</EMBED></OBJECT>');

};



function showGM(title, lat, lng)
{
var popup=window.open('http://www.nilsen.ru/gis/cgi-bin/google_map.cgi?title='+title+'&lat='+lat+'&lng='+lng, '', 'toolbar=0,menubar=0,location=0,status=0,directories=0,height=600,width=985,left=0,top=0'); 
popup.focus();
}
    
//--------------------------------------------

// timeout close the window. You can change the action

// to use it U have to place in your HTML timer initiation

// nTimer = setTimeout("leave();", nTimerExpired);



var nTimer;

var nTimerExpired = 15000; // U have to change this time

// window.focus();

function leave()

{

 if (nTimer) clearTimeout(nTimer);

 window.close();

};



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

// go to URL. 

function goToURL(url)

 {

  var sURL;

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

  location.href=sURL;

 };



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


function openWindowFixed(filename, w, h)

{

    var nWidth;

	var nHeigth;

	

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

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

	

	var desktop = window.open(filename, "_blank", 

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

};


function PutToCart(num, id)

{

	var nCell = "amount"+num;

	

	if (!num && !id)

	{

		window.open('/cgi-bin/korzina.pl', "Korzina","width=600,height=550,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes");

	this.blur();



	} else

	{

	window.open('/cgi-bin/korzina.pl?amount='+ document.forms["shop"].elements[nCell].value+'&zakaz_id='+ id, "Korzina","width=600,height=550,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes");

	

 

	if (document.forms["iscart"].opd.value=="yes") 

	{

	  this.focus();

	  alert("Товар помещен в корзину. Для просмотра используйте ссылку Ваша корзина");

	}

		else 

		{ 

		 document.forms["iscart"].opd.value="yes";

		 this.focus();

	  	 alert("Товар помещен в корзину. Для просмотра используйте ссылку Ваша корзина");

		}

	}

 };



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



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 accEdit(acc)
{
    if(document.getElementById(acc))
    {
        document.getElementById(acc).value = 'edit';
    }
}


function getPageOffsetLeft(el) {

  var x;

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}





var timeout;
var activeMenu = null;
var off=1;

function ShowHideSendEmail(id)
{
 if (activeMenu)
        {
                activeMenu.style.visibility = "hidden";
 //               activeMenu.style.display = "none";
        }
 var subMenu = document.getElementById("sendemail");


 var menuItem = document.getElementById(id);

 if(menuItem)
        {
           var x = getPageOffsetLeft(menuItem); 
           var y = getPageOffsetTop(menuItem);
	if(id == 'dopfunctions')
		{
		x=x+330;
		y=y-150;
		}
	else
		{
		x=x;
		y=y+60;
		}
	}
//alert('x:'+x+' y:'+y);
 if (subMenu)
    {
      if (off)
        {
             subMenu.style.left = x + "px";
             subMenu.style.top  = y + "px";

             subMenu.style.visibility = "visible";
//             subMenu.style.display = "block";
             activeMenu = subMenu;
		off=0;
        }
      else
        {
             subMenu.style.visibility = "hidden";
//             subMenu.style.display = "none";
             activeMenu = null;
		off=1;
        }
    }

}

