/*********************************************************************************
*   Description: Async. javascript-xml library
*   Who/When: Maxim Kozhuh, 25 January 2005         Version: 1.0
*   Copyright: Copyright (c) 2005 Zublisher, Inc.
**********************************************************************************/

//debug output flags
var CFG_Error_block = false||window.CFG_Error_block;
var CFG_Reports_full = false||window.CFG_Reports_full;
var CFG_Error_Reporting = false;
window.ajax_call_counter=0;
document.write("<style>.progress_bar_opacity_div{ -moz-opacity: 0}</style>");
if (document.all) {
document.write("<style>.progress_bar_opacity_div{  filter: gray() alpha(opacity = 0);}</style>");
}
var ajax_progress_bar = null;

/*
*   Description: Ajax Progress Bar Class. Show or Hide ajax rogress bar during loading XML
*   Who/When:
*   Copyright: Copyright (c) 2006 Zublisher, Inc.
*/
function AjaxProgressBar(){
    if (window.ajax_div)            //if progress bar was created ->
        this.bar = window.ajax_div; //save 'Progress Bar' reference
    else                            //else ->
        this.init();                //create 'Progress Bar'
    this.counter = 0;               //ajax call counter
}

//initialize 'Progress Bar' object and append required HTML to body
AjaxProgressBar.prototype.init = function(){
    var bar = document.createElement("DIV");    //create main container DIV
    //set container class name, ID, stylesheets
    bar.className = 'ajax_progress_bar';
    bar.id = 'ajax_progress_bar';
    bar.align="center";
    var left = "350px";                                     //set left position
    var top  = "250px";                                     //set top position
    //create container HTML
    var html = '<div class="progress_bar_opacity_div" style="position:absolute;left:0px;top:0px;width:95%;background-color:transparent;height:500px;z-index:1000;"><div style="position:absolute;width:20px;height:20px;left:10px;top:10px;cursor:pointer;" onclick="showProgressBar(0)"></div></div><div id="ajax_progress_bar_container" style="position:absolute;background-color:white;z-index:1000;left:'+left+';top:'+top+';"><img id="ajax_progress_bar_image" src="/Library/libAjax/wait.gif"></div>';
    bar.innerHTML = html;           //set container HTML
    bar.style.display="none";       //hide 'Progress Bar'
    document.body.appendChild(bar); //append 'Progress Bar' to document
    this.bar = bar;                 //save reference
    window.ajax_div=bar;            //save reference
}

//show 'Progress Bar'
AjaxProgressBar.prototype.show = function(){
    if (this.counter <= 0)  //check current counter
        this.bar.style.display="";  //show
    this.counter++; //increment call counter
}

//hide 'Progress Bar'
AjaxProgressBar.prototype.hide = function(){
    this.counter--; //decrement call counter
    if (this.counter <= 0) {      //check current counter
        this.bar.style.display="none";  //hide
        this.counter = 0;
    }
}

AjaxProgressBar.prototype.setPos = function(x, y){
	var div = this.bar.getElementsByTagName('div')[2];
	div.style.left = x;
	div.style.top = y;
}

/*
 *   Description: Ajax Logger utility. Catch all errors and send to server
 *   Who/When:
 *   Copyright: Copyright (c) 2006 Zublisher, Inc.
 */
function AjaxErrorLogger(){
    this.ajax = new AjaxEngine();   //ajax engine
    this.logPath = '/Library/libAjax/log.php';  //php-logger file path
    return true;
}

AjaxErrorLogger.prototype.send = function(e, xml_obj){
    var location = window.location;                 //save current page
    var xml_path = xml_obj.loadParams['filePath'];  //save loaded XML path
    if (xml_obj.code)
        var params = xml_obj.code.join('&');        //save request parameters
    else
        var params = '';
    var text = xml_obj.xmlDoc.responseText;         //XML text
    //prepare new Ajax request
    this.ajax.addCode('location', location);
    this.ajax.addCode('xml_path', xml_path);
    this.ajax.addCode('params', params);
    this.ajax.addCode('text', text);
    this.ajax.addCode('exception', e.message+'::'+e.fileName+'::'+e.lineNumber+'::'+e.name);
    var f = function() {};
    if (CFG_Error_Reporting) {
        var rs = confirm('Error catched. '+e+' on line:'+e.lineNumber+'. Throw?');
        if (rs)
            throw e+'re-throw';
        }
    this.ajax.postXML(this.logPath, '', f); //send request
    try{
        this.reload(xml_obj);               //try to reload call_back function
    } catch(e){
    }
}

//try to reload call_back function
AjaxErrorLogger.prototype.reload = function(xml_obj){
    //create empty XML
    var xmlString = '<data></data>';
    try     //Mozilla
    {
        var parser = new DOMParser();
        xml_obj.xmlDoc = parser.parseFromString(xmlString,"text/xml");
    }
    catch(e){   //IE
        xml_obj.xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xml_obj.xmlDoc.async=this.async
        xml_obj.xmlDoc.loadXML(xmlString);
    }
        xml_obj.onloadAction(xml_obj, xml_obj.onloadObj);   //reload call_back function
}



                //AJAX engine object
        function AjaxEngine(){
                this.code = new Array();    //array with request parameters
                return this;
        }


        //create activeX object
        AjaxEngine.prototype.initX=function(){
            //return if object already exists
//            if (this.xmlDoc) return;      //IE fix, cause IE XMLHTTP object can send request only once
            //for FF
            if(window.XMLHttpRequest)
                this.xmlDoc = new XMLHttpRequest(); //get httpRequest object
            else
                this.xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");        //create XMLDOM object
        }

        AjaxEngine.prototype.nullFunc=function(){}


        AjaxEngine.prototype.postXML=function(filePath,params,callFunc,isText){
				if (callFunc == null)
					callFunc = this.nullFunc;
				if (params == null)
					params = '';
                if (params && params.length > 1) {  //check parameters
                    params = params.split('&'); //parse parameters
                    for (var i=0; i<params.length; i++) {   //and save to array
                        var code = params[i].split('=');
                        if (code[0] != '' && code[1] != '')
                            this.code.push(code[0]+'='+code[1]);    //add parsed parameter to array
                    }
                }
                //store request parameters
                this.loadParams = new Array();
                this.loadParams['filePath'] = filePath;
                this.loadParams['callFunc'] = callFunc;
                this.loadParams['isText']   = isText;
                if (this.code.length > 0)   //check parameters
                    params = '&'+this.code.join('&');   //create string
                else
                    params = '';                        //create string
                if (!this.HideProgressBar) showProgressBar(true);  //show alert div
                this.onloadAction=callFunc; //save onload action
                //create activeX object
                this.initX();
                if (isText)
                    this.xmlDoc.onreadystatechange=new this.waitLoadTextFunction(this); //set onload event
                else
                    this.xmlDoc.onreadystatechange=new this.waitLoadFunction(this); //set onload event
                this.xmlDoc.open("POST",filePath,true); //configure async. xml request
				this.xmlDoc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
				if (this.OpenInWindow) window.open(filePath);
                this.xmlDoc.send(params);//send request
        }

        //load xml
        AjaxEngine.prototype.loadXML=function(filePath,callFunc,callObj,isText){
				if (callFunc == null) {
					callFunc = this.nullFunc;
				}
                if (filePath.indexOf('?') != -1) {  //check paramaters
                    var params = filePath.substr(filePath.indexOf('?')+1);
                    params = params.split('&'); //parse parameters
                    for (var i=0; i<params.length; i++) {   //and save to array
                        var code = params[i].split('=');
                        if (code[0] != '' && code[1] != '')
                            this.code.push(code[0]+'='+code[1]);    //add parsed parameter to array
                    }
	                filePath = filePath.substr(0, filePath.indexOf('?'));   //get request ajax file path without GET string
                }

                //save request parameters
                this.loadParams = new Array();
                this.loadParams['filePath'] = filePath;
                this.loadParams['callFunc'] = callFunc;
                this.loadParams['callObj']  = callObj;
                this.loadParams['isText']   = isText;
                if (this.code.length > 0) { //check parameters
                    var str = this.code.join('&');  //create perameters string
                    filePath += '?'+str;    //create request string
                }
                if (!this.HideProgressBar) showProgressBar(true);  //show alert div
                this.onloadAction=callFunc; //save onload action
                //create activeX object
                this.initX();
                if (isText)
                    this.xmlDoc.onreadystatechange=new this.waitLoadTextFunction(this); //set onload event
                else if (callObj) {
                    this.onloadObj=callObj; //save onload action
                    this.xmlDoc.onreadystatechange=new this.waitLoadFunction(this); //set onload event
                }
                else
                    this.xmlDoc.onreadystatechange=new this.waitLoadFunction(this); //set onload event

                this.xmlDoc.open("GET",filePath,true); //configure async. xml request
				if (this.OpenInWindow) window.open(filePath);
                this.xmlDoc.send(null);//send request
        }


        //inner onload handler
        AjaxEngine.prototype.waitLoadFunction=function(obj){
                this.check=function (){
                        if (!obj.xmlDoc.readyState)
                                {
                                 showProgressBar(false); //hide alert div
                                 window.ajax_call_counter++;
                                try {
                                    obj.onloadAction(obj,obj.onloadObj); //fire external onload handler for non IE browsers
                                    obj.code = new Array();
                                } catch(e) {
                                    var log = new AjaxErrorLogger();
                                    log.send(e, obj);
                                }
                                 }
                        else        {
                        if (obj.xmlDoc.readyState != 4) return false;         //skip incompletely loaded xml
                                else {
                                        try{showProgressBar(false);}catch(e){}   //hide alert div
										try{
	                                        if(obj.xmlDoc.status == "503") {
	                                            obj.resendXML(obj);
	                                            return;
	                                        }
										} catch(e){
										}
										try{
                                        if(CFG_Error_block) { obj.getErrorBlock(obj);                        //fire external onload handler for IE browser
                                                              showTab(aTopNode,"xml");
                                                            }
										}catch(e){}
                                        window.ajax_call_counter++;
                                        try {
                                            obj.onloadAction(obj, obj.onloadObj);   //call noload action
                                            obj.code = new Array(); //erase parameters array
                                        } catch(e) {    //on error
                                            var log = new AjaxErrorLogger();    //create new instance on Logger
                                            log.send(e, obj);   //send error to server
                                        }
                                }
                                    }
                };
                return this.check;        //return instance of function
        };

        AjaxEngine.prototype.waitLoadTextFunction=function(obj){
                this.check=function (){
                        if (!obj.xmlDoc.readyState)
                                {
                                 showProgressBar(false); //hide alert div
                                }
                        else    {
                        if (obj.xmlDoc.readyState != 4) return false;         //skip incompletely loaded xml
                                else {
                                if (obj.xmlDoc.status == "200") {
                                        // ...processing statements go here...
                                        window.file_name = obj.xmlDoc.responseText;
                                        //get_super_unit_data('All', '', varCoursware);
                                        showProgressBar(false);   //hide alert div
                                        try {
                                            obj.onloadAction(obj);  //call onload handler
                                            obj.code = new Array(); //erase parameters array
                                        } catch(e) {
                                            var log = new AjaxErrorLogger();    //create new instance on Logger
                                            log.send(e, obj);                   //send error to server
                                        }

                                } else if(obj.xmlDoc.status == "503"){  //is 'Server Busy'
                                    obj.resendXML(obj); //resend request
                                    showProgressBar(false);   //hide alert div
                                } else {
                                   showProgressBar(false);  //hide alert div
//                                   alert("There was a problem retrieving the XML data:\n" + obj.xmlDoc.statusText);
                                        }
                                                                       }
                                }
                };
                return this.check;        //return instance of function
        }

        AjaxEngine.prototype.suncRequest = function(filePath)
        {
            showProgressBar(true); //show alert div
            this.initX();
            this.xmlDoc.open("GET",filePath,false); //configure async. xml request
            this.xmlDoc.send(null);//send request
        }


        //resend request when 'Server Busy'
        AjaxEngine.prototype.resendXML=function(obj){
            if (obj.tryCount == null) {
                obj.tryCount = 5;   //attempt count
            }
            if (obj.tryCount < 0) { //if failed ->
                alert("Server busy. Try later.");   //show dialog box
            } else {
                obj.loadXML(obj.loadParams['filePath'], obj.loadParams['callFunc'], obj.loadParams['callObj'], obj.loadParams['isText']);   //send request
            }
            obj.tryCount--; //decrement counter
        }

        //add new request parameter
        AjaxEngine.prototype.addCode=function(code, value){
            this.code.push(encodeURIComponent(code)+'='+encodeURIComponent(value));
        };

        //return XML-node as text
        AjaxEngine.prototype.getNodeXML=function(node, num){
            if (num == null)    //check node num
                num = 0;    //set default value
            else
                num = parseInt(num);
            if (typeof(node) == 'object') { //check node type
            } else if (typeof(node) == 'string') {  //if node == nodeName
                node = this.xmlDoc.responseXML.getElementsByTagName(node);  //search node with givenname
                if (!node) return '';   //check
                if (!node[num]) return '';  //check
                node = node[num];   //get searched node
            }
            if (document.all) { //if IE
                return node.xml;    //return node text value
            } else {    //Gecko
                var xmlSerializer = new XMLSerializer();    //create serializer object
                return xmlSerializer.serializeToString(node);   //return node text value
            }
        }

        //return top node of xml
        AjaxEngine.prototype.getXMLTopNode=function(tagName){
                        //for Mozilla, search and return top node by name
                        if (this.xmlDoc.responseXML)  { var temp=this.xmlDoc.responseXML.getElementsByTagName(tagName); var z=temp[0];  }
                        else //for IE,  get top node from DOM
                                                {var z=this.xmlDoc.documentElement;}
                                                if (z) return z;        //return top node
//                        if(CFG_Reports_full) alert("Incorrect XML -> 'TopNode' not found"); alert("Incorrect XML");        //throw error if top node was not found
                        return document.createElement("DIV");        //return dummy node
        };

        AjaxEngine.prototype.getXMLNode=function(tagName)
                {
                        //search and return first node with name
                        if(this.xmlDoc.responseXML)
                        {
                                if(this.xmlDoc.responseXML.getElementsByTagName(tagName))
                                { var temp=this.xmlDoc.responseXML.getElementsByTagName(tagName);}
                                else {
//                                    (CFG_Reports_full?alert("Incorrect XML -> Tag '"+tagName+"' not found"):alert("Incorrect XML"));
                                    return;
                                }
                        }
                        else
                        {
                                if(this.xmlDoc.documentElement.getElementsByTagName(tagName))
                                { var temp=this.xmlDoc.documentElement.getElementsByTagName(tagName);}
                                else {
//                                    (CFG_Reports_full?alert("Incorrect XML -> Tag '"+tagName+"' not found"):alert("Incorrect XML"));
                                    return;
                                    }
                        }
                        var z=temp[0];
                        if (z) return z;       //return top node
//                        (CFG_Reports_full?alert("Incorrect XML -> Tag '"+tagName+"' not found"):alert("Incorrect XML"));//throw error if node was not found
                        return document.createElement("DIV");        //return dummy node
        };
        //return value of node in XML
        AjaxEngine.prototype.getNodeValue=function(data, nodename, style){
                                var top_node = data; //shortcut to data, backward compatibility only
                if(style == null) var top_node=data.getXMLNode("data");        //get top node
                for (var i=0; i<top_node.childNodes.length; i++)        //for all childs
                        if ((top_node.childNodes[i].nodeType==1)&&(top_node.childNodes[i].nodeName==nodename))        //check child node type and name
                                if (top_node.childNodes[i].childNodes.length)        //if text exists
                                        return top_node.childNodes[i].childNodes[0].data;        //return node value
                       return ""; //return empty string if node is empty
        }

        //convert XML to table
        AjaxEngine.prototype.formatAsATable=function(data,id,click_func,width, style) // data container, html container block, on click func, table width
                {
                //width parametr optional
                width=width||(new Array);
                style=style || (new Array);
                //set table header
                var html_table='<table border="0" cellpadding="0" cellspacing="0" id ='+id+'Table' +'>';
                var index=0; //row counter
                var top_node=data.getXMLNode("data"); //get top node
                        //alert(top_node.nodeName);
                                //var padd_text = "padding-left:3px";
                for (var i=0; i<top_node.childNodes.length; i++)        //for all childs
                        if ((top_node.childNodes[i].nodeType==1)&&(top_node.childNodes[i].nodeName=="row"))        //check child type and name
                        {
                                var row=top_node.childNodes[i];        //get row node
                                index++;                                                // increment row counter
                                //set row HTML representation
                                html_table+="<tr bgcolor='"+(index%2==1?"#FFFFFF":"#F7F7F8")+"' rowId='"+row.getAttribute("id")+"'>";
                                for (var j=0; j<row.childNodes.length; j++)                //for all row childs
                                        if ((row.childNodes[j].nodeType==1))                //check node type
                                        {
                                                var cell=row.childNodes[j];                                //get cell node
                                                if (style[j]) { var style_cur=style[j]; }
                                                else style_cur = '';
                                                //set cell HTML representation
                                                html_table+="<td><div style='"+style_cur+"'>"+(cell.childNodes.length?cell.childNodes[0].data:"&nbsp;")+"</div></td>";
                                        }
                                html_table+="</tr>";        //close row
                        }
                html_table+="</table>";                //close table

                // get layer
                var holder=document.getElementById(id);
                // writing the table into particular layer
                holder.innerHTML = html_table;

                //cet CSS class for table cells
                var rows=holder.childNodes[0].rows; //get table rows
                for (var i=0; i<rows.length; i++)        //for each row
                        {
                                rows[i].onclick=click_func;        //set row onclick handler
                                for (var j=0; j<rows[i].cells.length; j++)        //for each cell
                                        {
                                        if (rows[i].cells.length==1) rows[i].cells[j].className="AJfirstlastTD";        //one cell per row
                                        else if (j==0) rows[i].cells[j].className="AJfirstTD";                                                //first cell in row
                                        else if (rows[i].cells.length==j+1) rows[i].cells[j].className="AJlastTD";        //last cell in row
                                        else rows[i].cells[j].className="AJnormTD";                                                                //default cell CSS
                                        if (width[j]) rows[i].cells[j].width=width[j];
                                        }
                        }

                                holder.childNodes[0].className = "textOverflow HTMLTableHolder";
                if (document.all)        //for IE
                        //if scroll visible
                        if (holder.childNodes[0].clientHeight >  holder.clientHeight)
                                holder.childNodes[0].style.width = holder.clientWidth-1;        //correct table width
        }
        AjaxEngine.prototype.formatAsArray=function(data){
                var outArray = new Array();
                var index = 0;
                var top_node=data.getXMLNode("data"); //get top node
                for (var i=0; i<top_node.childNodes.length; i++)        //for all childs
                        if ((top_node.childNodes[i].nodeType==1)&&(top_node.childNodes[i].nodeName=="item"))        //check child type and name
                        {
                            var row=top_node.childNodes[i];        //get row node
                            outArray[index] = row.getAttribute("id")+"|"+(row.childNodes.length?row.childNodes[0].data:"");

                            index++;                                                // increment array counter
                        }
            return outArray;
        }


        AjaxEngine.prototype.formatAsObject=function(){
            var top_node=this.getXMLNode("data"); //get top node
            return this.xml2object(top_node);
        }
        AjaxEngine.prototype.xml2object=function(data){
            var obj = new Object;
            var len = data.childNodes.length;
            var summedText = '';
            if (data.childNodes[0] && !((len == 1 )&& (data.childNodes[0].nodeType != 1))) {
                for(var i=0; i<len; i++) {
                    var node = data.childNodes[i];
                    if (node.nodeType == 1) {
                        var nodeName = data.childNodes[i].nodeName;
                        if (obj[nodeName] == null)
                            obj[nodeName] = new Array();
                        var nodeObj = this.xml2object(node);
                        var attr = node.attributes;
                        var attr_len = attr.length;
                        for (var j=0; j<attr_len; j++) {
                            var attrName = attr[j].nodeName;
                            var attrVal  = attr[j].nodeValue;
                            nodeObj[attrName] = attrVal;
                        }
                        obj[nodeName].push(nodeObj);
                    }
                    else
                        summedText+= node.textContent;
                }
                if(summedText)
                {
                    obj = summedText;
                    summedText = '';
                }
            } else {
                obj = (data.childNodes[0]?data.childNodes[0].data:"");
            }
            return obj;
        }


                /**
                 *  What:                  dummy show of progress bar for 0.3 seconds
                 *  Who/When:         Denis, Zenkovich 25 October 2005, dzen@scand.com
                **/
                function dummyShowProgressBar(ind)
                {
                ind=ind||false;
                showProgressBar(!ind);
                        if(!ind) setTimeout("dummyShowProgressBar(true)", 300);
                }

            function showProgressBar(bool)
            {
                if (!ajax_progress_bar)        //if alert div not created
                    ajax_progress_bar = new AjaxProgressBar();
                if (bool=='forceHide') //if in force hide bar mode ->
                                         {
                                                 ajax_progress_bar.counter = 1; //set counter as for only one bar is shown
                                                ajax_progress_bar.hide(); //hide the bar
                                         }
                                         if (bool)
                    ajax_progress_bar.show();
                else
                    ajax_progress_bar.hide();
            }

            function getLoadingState()
            {
                if (!window.ajax_div)        //if alert div not created
                        return false;
                return  ((window.ajax_div.style.display == 'none')?false:true);
            }

            //TWL-style wrappers
            function open_connection_get(server_resource,action,show_progress)
            {
                var z=new AjaxEngine();
                if (!window.call_back) alert("function call_back not defined");
                else z.loadXML(server_resource+"&action="+action,call_back);
            }

            function open_connection_post(server_resource,arguments,show_progress)
            {
                var z=new AjaxEngine();
                if (!window.call_back) alert("function call_back not defined");
                else z.postXML(server_resource,arguments,call_back);
            }

            function open_connection(submit_type, server_resource,str, show_prog_bar)
            {
                if (submit_type == "POST") {
                        open_connection_post(server_resource, str, show_prog_bar);
                } else if (submit_type == "GET"){
                        open_connection_get(server_resource, str, show_prog_bar);
                }
            }
            //PWL-style wrappers
            function open_connection_get_text(server_resource,action,show_progress)
            {
                var z=new AjaxEngine();
                if (!window.call_back) alert("function call_back not defined");
                else z.loadXML(AppPath+server_resource+"&action="+action,call_back,null,true);
            }


            function open_connection_post_text(server_resource,arguments,action,show_progress)
            {
                var z=new AjaxEngine();
                if (!window.call_back) alert("function call_back not defined");
                else z.postXML(AppPath+server_resource,arguments+"&action="+action,call_back,true);
            }


/////////////////////////////////////////////////////
//
//        DEBUG Ajax CLASS
//
/////////////////////////////////////////////////////

                /**
                 *  What:                  method - gets error messages from XML and saves them for DebugWindow
                 *  Who/When:         Denis, Zenkovich 25 October 2005, dzen@scand.com
                **/
                AjaxEngine.prototype.getErrorBlock = function(data)
                {
                        aTopNode = data.getXMLNode('data');
                        var error_block = data.getXMLNode("errorBlock");
                        var error_string;
                        if ((error_block.nodeType==1)&&(error_block.nodeName=="errorBlock")) //check node type and name
                        {
                                var error_html = "";
                                var error_num;
                                var error_text;
                                var warning_html = "";
                                var warning_num;
                                var warning_text;
                                var errors_length = error_block.childNodes.length;
                                var e_c = error_block.attributes[0].value-1;
                                var w_c = error_block.attributes[1].value-1;
                                aErrors = Array();
                                aWarnings = Array();

                                for(var j=0; j<errors_length; j++)
                                {
                                        if(error_block.childNodes[j].nodeType==1 && error_block.childNodes[j].nodeName == "error")
                                        {
                                                aErrors.push(error_block.childNodes[j]);
                                        }
                                        if(error_block.childNodes[j].nodeType==1 && error_block.childNodes[j].nodeName == "warning")
                                        {
                                                aWarnings.push(error_block.childNodes[j]);
                                        }
                                }
                                var result = document.getElementById("resultBox");
                                if(result){        }
                                else {createErrorContainer(error_html);}

                                var stat = document.getElementById("stat_"); //save XML load status
                                //alert(data.xmlDoc.readyState);
                                stat.innerHTML = ' '+data.xmlDoc.status;  //save XML load status

                                var docSize = "";
                                if(!d.all) docSize = data.xmlDoc.responseText.length;
                                if(d.all)  docSize = data.xmlDoc.documentElement.xml.length;
                                //alert(data.xmlDoc.implementation);

                                lnkz=document.getElementById('linkz');
                                lnk_text=' <a href="#" onclick=showTab(aTopNode,"xml")>XML ('+docSize+')</a> / '
                                lnk_text+='<a href="#" onclick=showTab("XMLDebugWindow_","errors")>Errors ('+e_c+')</a> / '
                                lnk_text+='<a href="#" onclick=showTab("XMLDebugWindow_","warnings")>Warnings ('+w_c+')</a>'
                                lnkz.innerHTML=lnk_text;
                                return;
                        }
                }


var d = document; //document shortcut

var iDIv=null;

var aErrors=Array()
var aWarnings=Array()
var aTopNode=null;
var iStatus

var mObj
var mFlag
var mX
var mY
var mX1
var mY1
var mCount=0

var class_obj = null;

//var http_request = false;
//var sURL=''

        /**
         *  What:      Creates Error-reporting div
         *  Who/When:  Denis, Zenkovich XX October 2005, dzen@scand.com
         *                           Vitaliy Bondaruk XX December 2005, vbond@scand.com
        **/
        function createErrorContainer()
        {
                class_obj = new XMLDebugWindow('XMLDebugWindow_');
                class_obj.show();
        }
        /**
         *  What:      puts an error message
         *  Who/When:  Denis, Zenkovich 12 January 2006, dzen@scand.com
        **/
        function PutInError(err_text)
        {

        }
/**
 *  What:      XML Debug Window object
 *        Who/When:  Vitaliy Bondaruk XX December 2005, vbond@scand.com
**/
function XMLDebugWindow(idn)
{
        if(idn!='')this.obj = d.getElementById(idn);
        if(this.obj==null){
                this.obj = d.createElement('div');
                this.obj.className = "XMLDebugWindow";
                this.obj.id = (idn!='')?idn:'XMLDebugWindow_';
                d.body.appendChild(this.obj);
        }
        var head = d.getElementsByTagName("head")[0];
        var lnk = d.createElement("LINK");
        lnk.href = "../../StyleSheet/Common/DebugWindow.css";
        lnk.rel = "Stylesheet";
        if(d.all)  head.appendChild(lnk); //add XMLDebugWindow css for IE
        if(!d.all) head.innerHTML+="<link rel='Stylesheet' href='../../StyleSheet/Common/DebugWindow.css'/>"; //add XMLDebugWindow css for Gecko
        return this;
}

XMLDebugWindow.prototype.show = function(){
        var obj = this.obj;
        var html = '<div class="DW_mover" href="#">--------- move ---------</div>';
        html+= '<div class=tabs>Views:<span id=linkz></span></div>';
        html+='<div class=status>Status:<span id=stat_></span></div>';
        html+='<div class=result id=resultBox></div>';
        obj.innerHTML=html;

        //obj.childNodes[0].className;
        class_ = this;

        obj.firstChild.onmousedown=function(e){win_move(e,class_);}
        d.onmouseup=function(e){win_move(e,class_);}
        obj.style.top = "60px";
        obj.style.right = "20px";
}

function showTab(obj,c){
        if(obj){
                result=d.getElementById('resultBox');
                var all='';
                switch(c){
                        case 'xml':
                                all=xml2html_parser(obj,'');
                                break;
                        case 'errors':
                                for(i=0;i<aErrors.length;i++){
                                        attrs=aErrors[i].attributes;
                                        all+='<div class="error"> code(<b>'+attrs[0].value+'</b>): '+aErrors[i].firstChild.nodeValue+'</div>';
                                }
                                //result.style.border='none';
                                break;
                        case 'warnings':
                                for(i=0;i<aWarnings.length;i++){
                                        var attrs=aWarnings[i].attributes;
                                        var value = aWarnings[i].childNodes[0].data;
                                        all+='<div class=warning><b>'+attrs[0].value+'</b>: '+value+'</div>';
                                        //result.style.border='none';
                                }
                                break;
                }

                result.innerHTML=all;
                result.style.display='block';

                if(aErrors.length==0&&c=='errors') result.style.display='none';
                if(aWarnings.length==0&&c=='warnings') result.style.display='none';
                if(result.scrollHeight > 400) {result.style.height = "392px"; result.style.overflow = "auto";}
                else {result.style.height = ""; result.style.overflow = "";}
                if(result.scrollWidth > 300) {result.style.width = "292px"; result.style.overflow = "auto";}
                else {result.style.width = ""; result.style.overflow = "";}
        }
//        else if(CFG_Error_block) alert('div not exist');
}

function parseAttributes(obj)
{
        var code = "";
        if(obj.attributes && obj.attributes.length>0)
        {
                for(j=0;j<obj.attributes.length;j++)
                {
                        code+=' '+obj.attributes[j].nodeName+'="';
                        code+=obj.attributes[j].value+'"';
                }
        }
        return code;
}

function xml2html_parser(obj)
{
        var str = "";
        str+='<div class=xml>&lt;'+obj.nodeName+parseAttributes(obj)+'&gt;';
        if(obj.nodeValue) str+='<div class=xmlD>'+obj.nodeValue+'</div>';
        if(obj.hasChildNodes&&obj.nodeType==1)
        {
                for(var i=0; i<obj.childNodes.length; i++) //for all childNodes
                {
                        //alert(obj.nodeName+"_"+obj.childNodes[i].nodeName);
                        if(obj.childNodes[i].nodeName!='error'&&obj.childNodes[i].nodeName!='warning')
                        {
                                //if(obj.childNodes[i].nodeValue) str+='<div class=xmlD>'+obj.childNodes[i].nodeValue+'</div>';
                                if(obj.childNodes[i].hasChildNodes && obj.childNodes[i].childNodes.length>1) str+=xml2html_parser(obj.childNodes[i]);
                                else
                                {
                                        str+='<div class=xml>&lt;'+obj.childNodes[i].nodeName+parseAttributes(obj.childNodes[i])+'&gt;';
                                        if(obj.childNodes[i].firstChild)
                                                str+='<div class=xmlD>'+obj.childNodes[i].firstChild.nodeValue+'</div>';
                                        if(obj.childNodes[i].nodeValue) str+='<div class=xmlD>'+obj.childNodes[i].nodeValue+'</div>';
                                                str+='&lt;/'+obj.childNodes[i].nodeName+'&gt;</div>';
                                        //alert(obj.nodeValue);
                                }
                        }
                }
        }
        str+='&lt;/'+obj.nodeName+'&gt;</div>';

        return str;
}

//debug window move functions
function win_move(e,class_){
        obj=document.getElementById('XMLDebugWindow_');

        if (obj){
                if(e){
                        x=e.pageX?e.pageX:e.clientX?e.clientX:0;
                        y=e.pageY?e.pageY:e.clientY?e.clientY:0;

                }else if(event) {
                        e = event
                        x=e.clientX;
                        y=e.clientY;
                }
                objl = obj.style.left.slice(0,-2);
                objt = obj.style.top.slice(0,-2);
                x1=x-(objl!=''?objl:obj.offsetLeft*1);
                y1=y-(objt!=''?objt:obj.offsetTop*1);

                mFlag=(e.type=='mousedown'?1:0);
                mX1=x1
                mY1=y1
                document.onmousemove=function(e){thism(e,class_);}
        }
}

function thism(e,class_){
x=mX;
y=mY;
x1=mX1;
y1=mY1;
num=mFlag;
obj = document.getElementById('XMLDebugWindow_');
        if(e){
                x=e.pageX?e.pageX:e.clientX?e.clientX:0;
                y=e.pageY?e.pageY:e.clientY?e.clientY:0;

        }else if(event) {
                x=event.clientX;
                y=event.clientY;
        }
        else {
                x=0; y=0;x1=0;y1=0;
        }
        if(num==1){
                if(x-x1>0) obj.style.left=x-x1+'px';
                if(y-y1>0) obj.style.top=y-y1+'px';
        }else mCount++;
        mX=x;
        mY=y;
}
