// threadsafe asynchronous XMLHTTPRequest code
function ajaxSend(url, callback, errorcallback, noCache,err, show){
if(!show){ show=false;}
err="s_"+err;
// we use a javascript feature here called "inner functions"
// using these means the local variables retain their values after the outer function
// has returned. this is useful for thread safety, so 
// reassigning the onreadystatechange function doesn't stomp over earlier requests.

    function error(errorText) {
        if (ajaxErrorCallback){
            ajaxErrorCallback(errorText);
        } else {
            alert(errorText);
        }
    }


    function ajaxBindCallback(){
        if (ajaxRequest.readyState == 4) {
            if (ajaxRequest.status == 200) {
                if (ajaxCallback){
                    if (ajaxRequest.responseXML.documentElement) {
                        ajaxCallback(ajaxRequest.responseXML);
                    } else {
                       error("Error parsing: " + ajaxRequest.responseText);
                    }
                } else {
                    error('no callback defined');
                }
            } else {
               // error("There was a problem retrieving the xml data:\n" + ajaxRequest.status + ":\t" + ajaxRequest.statusText + "\n" + ajaxRequest.responseText);
            }
        }
		if (ajaxRequest.readyState == 1) {
    		if(show)document.getElementById(err).innerHTML = "<img src='/Files/counter.gif' border=0>Çàãðóæàåòñÿ.... ";
			// error("-");
		}
		if (ajaxRequest.readyState == 2) {
			if(show)document.getElementById(err).innerHTML = "<img src='/Files/counter.gif'  border=0>Çàãðóæåíî.... ";
			//  error("-");
		}
		if (ajaxRequest.readyState == 3) {
			if(show)document.getElementById(err).innerHTML = "<img src='/Files/counter.gif' border=0>Èíèöèàëèçàöèÿ.... ";
			//  error("-");
		}
    }

    if( noCache ) { url += ( ( url.indexOf('?') + 1 ) ? '&' : '?' ) + ( new Date() ).getTime(); } //prevent cache


// use a local variable to hold our request and callback until the inner function is called...
    var ajaxRequest = null;
    var ajaxCallback = callback;
    var ajaxErrorCallback = errorcallback;


// bind our callback then hit the server...
    try {
        if (window.XMLHttpRequest) {
            // moz et al
            ajaxRequest = new XMLHttpRequest();
            ajaxRequest.onreadystatechange = ajaxBindCallback;
            ajaxRequest.open("GET", url, true);
            ajaxRequest.send(null);
        } else if (window.ActiveXObject) {
            // ie
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            if (ajaxRequest) {
                ajaxRequest.onreadystatechange = ajaxBindCallback;
                ajaxRequest.open("GET", url, true);
                ajaxRequest.send();
            }
        }
    } catch (err) {
       error(err.description);
    }
}

//======================================
function processXMLResponse(XML) {  
	var elip,title,elts;
	if (XML.documentElement) {
		var sname =decodeURI(XML.documentElement.getElementsByTagName("sname")[0].firstChild.nodeValue);
		//alert(sname)
//if ( sname == "content" ){
//			var description = XML.documentElement.getElementsByTagName("description")[0].firstChild.nodeValue;
			//var PID = XML.documentElement.getElementsByTagName("PID")[0].firstChild.nodeValue;
			tarrr="s_content";
			document.getElementById(tarrr).innerHTML = decodeURI(XML.documentElement.getElementsByTagName("description")[0].firstChild.nodeValue);
		 // }
		/*var targetspan = null;
		if (elts != null){ 
		  targetspan = elts.firstChild.nodeValue;
		}
		if (elip != null) {
			if(sname !=null){
			
			}else{
				tarrr="s_doc";
				document.getElementById(tarrr).innerHTML = decodeURI(elip.firstChild.nodeValue);		
			}
		}
		var content = "";
		if (elct != null){
			content = elct.firstChild.nodeValue;
			
			if (elts != null) {
			  if ((targetspan == "content") && (elip != null)){
				 document.getElementById(targetspan).innerHTML = content;
			 } else {
				if (document.getElementById(targetspan))
				  document.getElementById(targetspan).innerHTML = content;
			  }   
			} else {

			 }
		}*/
	} else {
		errorXMLResponse("Error parsing XML");
	}
}
        
function errorXMLResponse(errorText) {
 alert(errorText);
}

function show_content(iId){
  var url = "/_new/ajax.php?sname=content&path=" + iId;
  ajaxSend(url, processXMLResponse, errorXMLResponse, true, "content", false);
}
function show_content2(iId, id2){
//alert(iId+"========"+ id2)
  var url = "/_new/ajax.php?sname=content2&id="+id2+"&path=" + iId;
  ajaxSend(url, processXMLResponse, errorXMLResponse, true, "content2", false);
}


