var isDOM = document.getElementById //DOM1 browser 
var isO   = isO5 = window.opera && isDOM; //Opera 5+
var isO6  = isO && window.print //Opera 6+
var isO7  = isO && document.readyState //Opera 7+
var isO8  = isO && document.createProcessingInstruction && (new XMLHttpRequest()).getAllResponseHeaders //Opera 8+
var isIE  = document.all && document.all.item && !isO //Microsoft Internet Explorer 4+
var isIE5 = isIE && isDOM //MSIE 5+
var isMZ  = isDOM && (navigator.appName=="Netscape")
var ua = navigator.userAgent.toLowerCase();
var isSafari = (ua.indexOf("safari") != -1);



function achange(obj)
{
	obj.style.border="solid 1px #f00";	

}

function code_copy(code){
  window.clipboardData.setData('text', code);
}



function input_copy(aname){
  window.clipboardData.setData('text', this.aname.value);
}



var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
var cf_modified = false;
var WIN_CLOSE_MSG = "\nВы не сохранили изменения. Действительно хотите уйти отсюда?\n";
var ADD_CLOSE_MSG = "\nВы создали документ, но не заполнили его содержимое!\n";

function set_modified(e){
  var el = window.event ? window.event.srcElement : e.currentTarget;
  el.className = "modified";
  cf_modified = true;
}

function ignore_modified(){
  if (typeof(root.onbeforeunload) != "undefined") root.onbeforeunload = null;
}

var creating_obj;

function check_cf(){

  if (creating_obj) return ADD_CLOSE_MSG;
  if (cf_modified) return WIN_CLOSE_MSG;

}

function init(){
  if (typeof(root.onbeforeunload) != "undefined") root.onbeforeunload = check_cf;
  else return;

  for (var i = 0; oCurrForm = document.forms[i]; i++){
    for (var j = 0; oCurrFormElem = oCurrForm.elements[j]; j++){
      if (oCurrFormElem.getAttribute("cf")){
        if (oCurrFormElem.addEventListener) oCurrFormElem.addEventListener("change", set_modified, false);
        else if (oCurrFormElem.attachEvent) oCurrFormElem.attachEvent("onchange", set_modified);
      }
    }
    if (oCurrForm.addEventListener) oCurrForm.addEventListener("submit", ignore_modified, false);
    else if (oCurrForm.attachEvent) oCurrForm.attachEvent("onsubmit", ignore_modified);
  }
}

if (root){
  if (root.addEventListener) root.addEventListener("load", init, false);
  else if (root.attachEvent) root.attachEvent("onload", init);
}



function sl(navRoot) {
      if (document.all&&document.getElementById) {
		if(navRoot=="")
            navRoot = document.getElementById("nav");
          
            
            for (i=0; i<navRoot.childNodes.length; i++) {
                  node = navRoot.childNodes[i];
                  
                  if (node.nodeName=="LI") {
                  
                        node.onmouseover=function() {
                              this.className+="over";
                        }
                        node.onmouseout=function() {
                              this.className=this.className.replace("over", "");
                        }
                  }
                 // else sl(node);
                 
            }
      }
}
function newValue(val,nval)
{
	re = /%<NEW_VALUE>%/g;
	return val.replace(re, nval);
}
function fromURL(URL)
{
	return window.showModalDialog(URL,'','dialogHeight : 420px; dialogWidth : 500px ; resizable:yes;');
}
function loadSourceFinish(id) {
	if (document.all) {
		document.all[id].innerHTML = parent.bufferFrame.document.body.innerHTML;
	} else if (document.getElementById) {
		document.getElementById(id).innerHTML = document.getElementById('bufferFrame').contentDocument.body.innerHTML;
	}

}
function loadSource(id,url) {
	if (document.layers) {
		var lyr = document.layers[id];
		lyr.load(url,lyr.clip.width);
	} else if (document.getElementById) {
		document.getElementById('bufferFrame').src = url;
	} else if (document.all) {
		parent.bufferFrame.document.location = url;
	}
}


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
function Hide(obj)
{
	obj.style.display="none";
}
function Show(obj)
{
	obj.style.display="block";
}
function Invert(obj)
{
	if(obj.style.display=="block")
	   obj.style.display="none";
	else
		obj.style.display="block";
}
var main_help="";
var din_help="";
var help_pref="http://wwware.magicssoft.ru/docs/";

	function keyhandler(e){
    var pressed=0;
    var we = null;
    if (window.event) we = window.event;
    else if (parent && parent.event) we = parent.event;
    if (we) {
      // IE & Opera
        (we.keyCode == 83 && we.ctrlKey);
       
    } else if (e) {
      // NN
      pressed = 
        (e.which==10 && e.modifiers==2) || // NN4
        (e.keyCode==0 && e.charCode==83 && e.ctrlKey) ||
        (e.keyCode==83 && e.ctrlKey) // Mozilla
        
    }
    if (pressed){if(axsubmit){axsubmit();return true;}}
   	else
   	{
   		pressed=0;
   	if(we) {
      // IE & Opera
      pressed = we.keyCode==112&&we.altKey;   

    } else if (e) {
    
      pressed = 
        (e.which==112) ||
        (e.keyCode==0 && e.charCode==112) ||
        (e.keyCode==112)
        
    }
    
     if (pressed)
     {
     	if(we)
     		we.keyCode=0;
     	else
     		e.keyCode=0;
     		
		if(din_help)
		{
			window.open(help_pref+din_help,"_blank");
		}
		else if(main_help)
		{
			window.open(help_pref+main_help,"_blank");
		}
     	else
     		window.alert("здесь помощь не доступна");
     	
     }
     return true;
   	}
   	return false;
    
    
  }
document.onkeydown = keyhandler;
document.onkeypress = keyhandler;
	
var req;
var domain;	

function loadXMLDoc(url,func) {
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        eval('req.onreadystatechange = '+func+' ;');
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
        	eval('req.onreadystatechange = '+func+' ;');
        	//req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function CodeUpload(url,input)
{
//alert(domain+url);
//return;
	eval( 'var  b  = document.all.flag_'+input+';');
	eval( 'var  ex  = document.all.data_'+input+';');
	if((b.className=='xclosed')&&(!ex.innerHTML))
	{
		loadXMLDoc(domain+url,'SendData');
	}
	else if((b.className!='xclosed'))
	{
		ex.className = "hidden";
		b.className="xclosed";
	}
	else
	{
		ex.className = "visible";
		b.className="xopen";
	}

}
function SendData() 
{
	
    // only if req shows "complete"
    if (req.readyState == 4) {
    	 
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
       
      response = req.responseXML.documentElement;
	  if(!response){return;}
      id = response.getElementsByTagName('id')[0].firstChild.data;

      result = response.getElementsByTagName('result')[0].firstChild.data;
      re = /&lt;/g;
	  result = result.replace(re,"<");
	  re = /&gt;/g;
	  result = result.replace(re,">");
	  eval( 'document.all.data_'+id+'.innerHTML=result');
	  eval( 'document.all.flag_'+id+'.className="xopen"');
      
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}