add = function() {
	var inp=document.createElement('input');
	var br=document.createElement('br');
	inp.setAttribute('name','attach'+(parseInt($('num').value)));
	inp.setAttribute('type','file');
	inp.setAttribute('size',60);
	$('files').appendChild(inp);
	$('files').appendChild(br);
	$('num').value = parseInt($('num').value)+1;
}

showPicture = function(url) {
	var params = 'ajax=1';
	//var ajax = new Ajax.Request({success: container},url,{method: 'post', parameters: params, onFailure: reportError});
	
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: function(transport) {
		var r = transport.responseText.evalJSON();
		$('galleryDiv').innerHTML = '<img src="'+r.FileUrl+'" width="'+r.Width+'" height="'+r.Height+'" alt="'+r.Subject+'" id="'+r.id+'"><br>';
		$('galleryP').innerHTML = r.Subject;
	  },
	  onFailure: reportError,
	  parameters: params
	});	
}
function reportError(request) {
	$('galleryDiv') = "Error! Could not load the image!";
}
function openContent(newUrl){
	winobj=open(newUrl,"content","width=980,height=640,left=20,top=20,scrollbars=0,location=0,menubar=0,resizable=1");
	winobj.focus();
}
function openBuilder(newUrl){
	winobj=open(newUrl,"builder","width=980,height=640,left=20,top=20,scrollbars=1,location=0,menubar=0,resizable=1");
	winobj.focus();
}
function openCms(newUrl){
	winobj=open(newUrl,"cms","width=980,height=640,left=20,top=20,scrollbars=1,location=0,menubar=0,resizable=1");
	winobj.focus();
}
function openHelp(newUrl){
	winobj=open(newUrl,"help","width=980,height=640,left=60,top=60,scrollbars=1,location=0,menubar=0,resizable=1");
	winobj.focus();
}
function openDescr(newUrl){
	winobj=open(newUrl,"descr","width=450,height=350,left=20,top=20,scrollbars=1,location=0,menubar=0,resizable=1");
	winobj.focus();
}
function openPopup(newUrl){
	winobj=open(newUrl,"popup","width=400,height=150,left=250,top=250,scrollbars=1,location=0,menubar=0,resizable=1");
	winobj.focus();
   document.getElementById("winobj").style.background = "#ff0000";
}	
function UnHide( eThis ){    
  if( eThis.className == 'sc' ){
      eThis.className = 'sc_active'
      eThis.parentNode.parentNode.parentNode.className = '';
  }else{
      eThis.className = 'sc'
      eThis.parentNode.parentNode.parentNode.className = 'cl';
  }
  return false;
}
function folder( tmp ){    
  eThis = document.getElementById(tmp);
  if( eThis.className == 'sc' ){
      eThis.className = 'sc_active'
      eThis.parentNode.parentNode.parentNode.className = '';
  }else{
      eThis.className = 'sc'
      eThis.parentNode.parentNode.parentNode.className = 'cl';
  }
  return false;
}
function Unselect( eThis ){  
  tmp = document.getElementById('ddcontainer');  
  if( eThis.className == 'btn_select_close' ){
      tmp.className = 'ddopen'
      eThis.className = 'btn_select_open'
  }else{
      eThis.className = 'btn_select_close'
      tmp.className = 'ddclose'
  }
  return false;
}
function ddHide(t){  
  tmp_btn = document.getElementById('btn_select');  
  tmp_dd = document.getElementById('ddcontainer');  

  if( tmp_dd.className == 'ddopen' ){
      tmp_btn.className = 'btn_select_close';
      tmp_dd.className = 'ddclose';
      document.request.userMess.value = t.innerHTML; 
  }else{
      tmp_dd.className = 'ddopen';
      tmp_btn.className = 'btn_select_open';
  }
  return false;
}

var flash_version = 7;
function flashdetect(versionRequired)
{   
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;	
	if (isIE && isWin && !isOpera)    
	{     
		document.write('<SCRIPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('result=(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+versionRequired+'"))) \n'); 
		document.write('</SCR'+'IPT\> \n');
		if (result)
			return true;
		else 
			return false;
	}
	else
	{
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var versionMajor=parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
			if (versionRequired <= versionMajor)
				return true;
			else
				return false;
		}
		else 
			return false;
	}   
}
/* logo output */
function insLogo() {
   var isOpera7 = ((navigator.userAgent.indexOf("Opera") != 0) && (navigator.userAgent.indexOf("Opera") != -1) && (navigator.userAgent.indexOf("Opera") < 51)) ? true : false;	
   if ((f>=flash_version) && !isOpera7) {
      document.write('<object type="application/x-shockwave-flash" data="/i/logo.swf" width="290" height="210"><param name="movie" value="/i/logo.swf"></object>');
      }
   else {
      document.write('<img src="/i/logo.jpg" width="290" height="180" alt="Энергогарант" title="Энергогарант"><br>')
   }
}

var timeId;
var isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
var isOpera=isOpera5=window.opera && isDOM //Opera 5+
var isOpera6=isOpera && window.print //Opera 6+
var isOpera7=isOpera && document.readyState //Opera 7+
var isMSIE=document.all && document.all.item && !isOpera //Microsoft Internet Explorer 4+
var isMSIE5=isDOM && isMSIE //MSIE 5+
var isNetscape4=document.layers //Netscape 4.*
var isMozilla=isDOM && navigator.appName=="Netscape" //Mozilla или Netscape 6.*}
/* popup */
function openDescriptionWindow( url, width, height, event ) {
	//printProperties(e);
	//return false;
    var frameS = '<iframe src="' + url + '" width="' + width + '" height="' + height + '" name="DescriptionIframe" id="DescriptionIframe" frameborder="0" marginheight="0" marginwidth="0"></iframe>';
    document.all['DescriptionContainer'].innerHTML = frameS;
    // move to position relative to click
    document.all['DescriptionContainer'].style.left = '' + getX( width, event ) + 'px';
    document.all['DescriptionContainer'].style.top = '' + getY( height, event ) + 'px';    
    // make it visible
    document.all['DescriptionContainer'].style.visibility = 'visible';
    return false;
}

function getX( width, event ) {
	var x = 2;
	var windowWidth = window.document.body.clientWidth;
	var columnWidth = Math.round( windowWidth/3 );
	var columnNumber = 1;
	for( var i=0; i<3; i++ ) {
		if ( event.clientX < columnWidth ) {
			columnNumber = i+1;
			break;
		}
		columnWidth += columnWidth;
	}
	switch (columnNumber) {
		case 1:
         if (isMSIE5) { x = event.clientX+document.body.scrollLeft; } else { x = event.pageX; } 			
			break;
		case 2:
         if (isMSIE5) { x = event.clientX+document.body.scrollLeft - Math.round(width/2); } else { x = event.pageX - Math.round(width/2); } 			
			if ( x<2 ) x=2;
			break;		
		case 3:
         if (isMSIE5) { x = event.clientX+document.body.scrollLeft - width; } else { x = event.pageX - width; }			
			if ( x<2 ) x=2;
			break;
		default:
         if (isMSIE5) { x = event.clientX+document.body.scrollLeft; } else { x = event.pageX; }			
	}
	return x;
}

function getY( height, event ) {
	var y = 2;
	var windowHeight = window.document.body.clientHeight;
	var rowHeight = Math.round( windowHeight/2 );
	if( event.clientY > rowHeight ) {
      if (isMSIE5) { y = event.clientY + document.body.scrollTop - height; } else { y = event.pageY - height; } 		
		var clientY = event.clientY - height;
		if( clientY < 2 ) {
			var shiftY = 2 - clientY;
			y += shiftY;
		}
	} else {
      if (isMSIE5) { y = event.clientY+document.body.scrollTop; } else { y = event.pageY; } 			
		var clientY = event.clientY;
		var downY = event.clientY + height + 2;
		if( downY > windowHeight ) {
			var shiftY = downY - windowHeight + 4;
			y -= shiftY;
			clientY -= shiftY;
		}
		if( clientY < 2 ) {
			shiftY = 2 - clientY;
			y += shiftY;
		}
	}
	return y;
}

function closeDescriptionWindow() {
    document.all['DescriptionContainer'].style.visibility = 'hidden';    
}

function reloadParentWindow() {
    closeDescriptionWindow();
    window.location.reload();
}

function printProperties( obj ) {
	var s = '';
	for( var i in obj ) {
		s += i + '=' + obj[i] + '<br>\n';
	}
	var w = window.open();
	w.document.open();
	w.document.write(s);
	w.document.close();
}

function closeFrame(){
	if ( ( window.parent ) && (window.parent.closeDescriptionWindow) ) {
		window.parent.closeDescriptionWindow();
	}	
}

function reloadParent(){
	if ( ( window.parent ) && (window.parent.reloadParentWindow) ) {
		window.parent.reloadParentWindow();
	}	
}

