var xmlHttp = false;

var server = 'http://www.energylife.kiev.ua';//+location.hostname;
var branch = 'info';
var branch2 = 'info'
var branch3 = 'info';

// ################### AJAX INITIALIZATION  START #################3
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/
/////////////////////

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
   if (xmlHttp.overrideMimeType) {
                        xmlHttp.overrideMimeType('text/xml');
                    }

} 

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
   if (xmlHttp.overrideMimeType) {
                        xmlHttp.overrideMimeType('text/xml');
                    }
} 
// ################### AJAX INITIALIZATION  END #################3
function goURL(url)
{
/*	if (cancelled) return;

	if (url.substr(0, 4) == "/?a=" || url.substr(0, 3) == "?a=")
		document.location = url + "&back=" + escape(document.location); 
	else*/
		document.location = url; 
}

function submitForm(form)
{
	window.open('about:blank', 'submit', 'width=320,height=180');
	form.target = 'submit';
	form.method = 'post';
	form.submit();
}


function removeObject(delid) { 
        parentObj = document.getElementById(delid).parentNode; 
        childObj = document.getElementById(delid);  
        parentObj.removeChild(childObj); 
    			     }
function create( name, attributes ) {
  var el = document.createElement( name );
  if ( typeof attributes == 'object' ) {
    for ( var i in attributes ) {
      el.setAttribute( i, attributes[i] );

      if ( i.toLowerCase() == 'class' ) {
        el.className = attributes[i];  // for IE compatibility

      } else if ( i.toLowerCase() == 'style' ) {
        el.style.cssText = attributes[i]; // for IE compatibility
      }
    }
  }
  for ( var i = 2; i<arguments.length; i++ ) {
    var val = arguments[i];
    if ( typeof val == 'string' ) { val = document.createTextNode( val ) };
    el.appendChild( val );
  }
  return el;
}
function brNew()
{
document.getElementById('uinf').innerHTML = xmlHttp.responseText;
document.getElementById('info').style.display = 'none';
document.getElementById('uinf').style.display = 'block';
}

function brINF(pid)
{
	var url = server + "/?a=suinfo&n=" + pid;
document.getElementById('info').style.display = "block";
xmlHttp.open("GET", url, true); 
xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState==4)
           if (xmlHttp.status==200)
                brNew();
};
xmlHttp.send(null);  
}

function bRU(opa){
document.getElementById('d'+opa).innerHTML = xmlHttp.responseText;
brINF(opa);
}
function bR3(gid) {
	var url = server + "/?a=sutree&third=1&gid=" + gid;
xmlHttp.open("GET", url, true);
document.getElementById(branch3).style.display = 'none';
branch3 = 'd'+gid+'';
document.getElementById(branch3).style.display = 'block';
xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState==4)
            if (xmlHttp.status==200)
                bRU(gid);
    };
	xmlHttp.send(null);
}

function bR2(gid) {
	var url = server + "/?a=sutree&second=1&gid=" + gid;
xmlHttp.open("GET", url, true);
document.getElementById(branch2).style.display = 'none';
branch2 = 'd'+gid+'';
document.getElementById(branch2).style.display = 'block';
xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState==4)
            if (xmlHttp.status==200)
                bRU(gid);
    };
	xmlHttp.send(null);
}
function bR1(gid) {
	var url = server + "/?a=sutree&gid=" + gid;
xmlHttp.open("GET", url, true);
document.getElementById(branch).style.display = 'none';
branch = 'd'+gid+'';
document.getElementById(branch).style.display = 'block';
xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState==4)
            if (xmlHttp.status==200)
                bRU(gid);
    };
	xmlHttp.send(null);
}





//////////////////


function uP(){
 if (xmlHttp.readyState == 4) 
  {
document.getElementById('quick').innerHTML = xmlHttp.responseText;
document.getElementById('info').style.display = 'none';
document.getElementById('bask').style.display = 'block';
 
}}

function uNew(fred, color2){
var div = create("div", {id: fred}, "");
document.getElementById("infotree").appendChild(div);
document.getElementById(fred).innerHTML = xmlHttp.responseText;
document.getElementById('info2').style.display = 'none';
document.getElementById('bask2').style.display = 'block';
document.getElementById('t'+fred).style.borderColor = color2;
document.getElementById('t'+fred).style.backgroundColor = color2;
document.getElementById('d'+refid).style.backgroundColor = color2;

}
function adINF(gid, color){
	var url = server + "/?a=uinfo&n=" + gid;
document.getElementById('info2').style.display = "block";
xmlHttp.open("GET", url, true); 
xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState==4)
            if (xmlHttp.status==200)
                uNew(gid, color);
    };
xmlHttp.send(null);
}                                          
function uINF(gid) {
	var url = server + "/?a=uinfo&n=" + gid;
	document.getElementById('info').style.display = "block";
	xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = uP;
	xmlHttp.send(null);
}

function gMot(){
document.getElementById("getbon").innerHTML = xmlHttp.responseText;
}
function gMos(){
	var url = server + "/?a=getbon&n=67";
xmlHttp.open("GET", url, true); 
xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState==4)
            //if (xmlHttp.status==200)
                gMot();
    };
}

function cS(gid) {
	var url = server + "/?a=ajax&n=" + gid;
document.getElementById('info').style.display = "block";
xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = uP;
	xmlHttp.send(null);
}
function dEL(gid) {
	var url = "/?a=ajax&com=del&n=" + gid;
	$("#info").show();
//document.getElementById('info').style.display = "block";
$("#bask").load(url,function(){
	
	$("#info").hide();
});

}
function SearchUp() {

document.getElementById("found").innerHTML = xmlHttp.responseText;
}
function Ajax(action, where,p1,p2,p3,p4) 
{
	var url = server + "/cgi-bin/ajax.pl?a=" + action + "&p1="+p1 + "&p2="+p2+ "&p3="+p4+ "&p2="+p3;
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function() 
	{ 
		if (xmlHttp.readyState==4)
        	if (xmlHttp.status==200) document.getElementById(where).innerHTML = xmlHttp.responseText;
	}
}

 function Search(what) {
if (document.getElementById("sop1").checked) how = "usr"
else how = "log"; 
        var url = server + "/?a=search&what=" + what + "&how=" + how;
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function() { 
if (xmlHttp.readyState==4)
            if (xmlHttp.status==200)
                SearchUp();	
}
xmlHttp.send(null);
}

function Calculate() {
var price = 0.00 + parseFloat(document.getElementById('price').value);
var skidka = 100;

if (document.getElementById('percent').checked) {
	 
	document.getElementById('skidkafix').disabled = 1;
	document.getElementById('skidkapr').disabled = 0;
	skidka = parseFloat(document.getElementById('skidkapr').value);
	document.getElementById('total').value = price - (price*skidka*0.01);
	if (skidka<10) document.getElementById('total').value = '������ ������� ����!';}
	
if (document.getElementById('fixed').checked) {
	document.getElementById('skidkafix').disabled = 0;
	document.getElementById('skidkapr').disabled = 1;
	skidka = parseFloat(document.getElementById('skidkafix').value);
	document.getElementById('total').value = price - skidka;
        if (skidka<500) document.getElementById('total').value = '������ ������� ����!';}
if (price == 0.00) document.getElementById('total').value = '������� ����!';
	

}
