function get_Obj(ElmID)
{
	if(document.getElementById)
   	{
    	if(document.getElementById(ElmID))
    	{
        	return document.getElementById(ElmID);
        }
   	}

    return false;
}

function show_FullPhoto(ID, width, height, alt)
{
      var scroll = "no";
      var top=0, left=0;
      if(width > screen.width-10 || height > screen.height-28) scroll = "yes";
      if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14);
      if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5);
      width = Math.min(width, screen.width-10);
      height = Math.min(height, screen.height-28);
      var wnd = window.open("","","scrollbars="+scroll+",resizable=yes,width="+width+",height="+height+",left="+left+",top="+top);
      wnd.document.write("<html><head>\n");
      wnd.document.write("<"+"script language='JavaScript'>\n");
      wnd.document.write("<!--\n");
      wnd.document.write("function KeyPress()\n");
      wnd.document.write("{\n");
      wnd.document.write("if(window.event.keyCode == 27)\n");
      wnd.document.write("window.close();\n");
      wnd.document.write("}\n");
      wnd.document.write("//-->\n");
      wnd.document.write("</"+"script>\n");
      wnd.document.write("<title>\""+alt+"\"</title></head>\n");
      wnd.document.write("<body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onKeyPress=\"KeyPress()\">\n");
      wnd.document.write("<a href=\"#\" title=\"Закрыть\" onclick=\"window.close()\"><img src=\""+ID+"\" border=\"0\" alt=\"Закрыть\"></a>");
      wnd.document.write("</body>");
      wnd.document.write("</html>");
      wnd.document.close();
}

function show_FormError(elem, iError)
{
	var arError = new Array();

	arError[0] = 'Пожалуйста, заполните все обязательные поля';
	arError[1] = 'Пожалуйста, правильно укажите E-mail';
	arError[2] = 'Пожалуйста, правильно укажите URL сайта';
    arError[3] = 'Поле должно содержать только числовое значение';

    elem.focus();
    alert(arError[iError]);

	return false;
}

function do_FormValid(sFormName)
{
    var form = document.forms[sFormName];

	for(var i=0; i<form.elements.length; i++)
	{
		elem = form.elements[i];

	    if(elem.type == 'hidden') continue;

	    if(elem.getAttribute('set') != null)
	    {
	    	if(elem.getAttribute('set').indexOf('*') != -1)
	        {
	        	if(elem.value == '')
	            {
                    return show_FormError(elem, 0);
	            }
	        }

	        if(elem.getAttribute('set').indexOf('mail') != -1 && elem.value != '')
	        {
	        	var reg = /^[A-Za-z0-9_\-\.=+~]+@[A-Za-z0-9_\-\.]+\.[A-Za-z]{2,4}\s*$/;

	            if (elem.value.match(reg) == null)
	            {
                    return show_FormError(elem, 1);
	            }
	        }

	        if(elem.getAttribute('set').indexOf('url') != -1 && (elem.value != ''))
	        {
	        	var reg = /^\s*(http[s]?:\/\/)?[A-Za-z0-9_\-\.]+\.[A-Za-z]{2,4}\s*$/;

	            if (elem.value.match(reg) == null)
	            {
                    return show_FormError(elem, 2);
	            }
	        }

            if(elem.getAttribute('set').indexOf('int') != -1 && (elem.value != ''))
	        {
	        	var reg = /^[0-9]+\s*$/;

	            if (elem.value.match(reg) == null)
	            {
                    return show_FormError(elem, 3);
	            }
	        }
	    }
	}
	return true;
}

//set Cookie
function set_Cookie(sName, sValue)
{
    var obDate = new Date();
    obDate.setTime(obDate.getTime()+1000*3600*24);
	document.cookie = sName+'='+sValue+';expires='+obDate+';path=/;';
}

// get Content Cookie
function get_Cookie(name)
{
	var cookie = ' ' + document.cookie;
	var search = ' ' + name + '=';
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0)
	{
    	offset = cookie.indexOf(search);
        if (offset != -1)
        {
        	offset += search.length;
            end = cookie.indexOf(';', offset)
            if (end == -1)
            {
            	end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
	return(setStr);
}

function do_ShowFlash()
{
    var iValue = 0;
    var sName = 'bSwitchShowFlash';

    if(!get_Cookie(sName) || get_Cookie(sName)<1) iValue = 1;

    set_Cookie(sName, iValue);

    return false;
}


/*function do_ShowMenuItem(ID, bSwitch)
{
    var obj = null;

    if(obj = document.getElementById('item_' + ID))
    {
        if(bSwitch) obj.style.backgroundImage = 'url(images/btn_' + ID + 'a.jpg)';
        else obj.style.backgroundImage = 'url(images/btn_' + ID + '.jpg)';
    }
}*/

function do_ShowMenuItem(MaketID, MenuItemID, bSwitch, sSuffix, sPostfix)
{
    var obj = null;

    if(obj = document.getElementById('item_' + MenuItemID))
    {
        if(bSwitch) obj.src = '/img/newmaket/btn_' + MaketID + MenuItemID + sPostfix + '.jpg';
        else obj.src = '/img/newmaket/btn_' + MaketID + MenuItemID + sSuffix + '.jpg';
    }
}

function ImgShw2(ID, width, height, alt)
{
	var scroll = "no";
	var top=0, left=0;
	if(width > screen.width-10 || height > screen.height-28) scroll = "yes";
	if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14);
	if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5);
	width = Math.min(width, screen.width-10);
	height = Math.min(height, screen.height-28);
	var wnd = window.open("","","scrollbars="+scroll+",resizable=yes,width="+width+",height="+height+",left="+left+",top="+top);
	wnd.document.write(
		"<html><head>"+
		"<"+"script type=\"text/javascript\">"+
		"function KeyPress()"+
		"{"+
		"	if(window.event.keyCode == 27) "+
		"		window.close();"+
		"}"+
		"</"+"script>"+
		"<title>"+(alt == ""? "Картинка":alt)+"</title></head>"+
		"<body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onKeyPress=\"KeyPress()\">"+
		"<img src=\""+ID+"\" border=\"0\" alt=\""+alt+"\" />"+
		"</body></html>"
	);
	wnd.document.close();
}
			
function doCalc(){
	window.open('/ru/packet_size.php',"tools_window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizeable=no,height=370,width=683,top=30,left=30");
}