
var thetimer=new Array(),theDiv=new Array();

function hideStatusDiv(n) {
 if(thetimer[n]) clearTimeout(thetimer[n]);
 if(theDiv[n]) document.body.removeChild(theDiv[n]);
 theDiv[n]=false;
 }

function showStatusDiv(txt,status) {
 for(var i=0;i<=theDiv.length;i++) {
  if(!theDiv[i])
   break;
  else if(theDiv[i].innerHTML==txt)
   return;
  }
 if(theDiv) hideStatusDiv(i);
 theDiv[i]=document.createElement('div');
 theDiv[i].style.width='300px';
 theDiv[i].style.height='18px';
 theDiv[i].style.overflow='hidden';
 theDiv[i].align='center';
 theDiv[i].valign='top';
 theDiv[i].style.color='#000000';
 if(status) {
  theDiv[i].style.background='#FFDC79';
  theDiv[i].style.border='1px solid #EC8800';
  }
 else {
  theDiv[i].style.background='#E38758';
  theDiv[i].style.border='1px solid #C93900';
  }
 theDiv[i].style.position='absolute';
 var scroll=self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
 var height=document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
 theDiv[i].style.left=(document.body.clientWidth-400)+'px';
 theDiv[i].style.top=(height+scroll-24*(i+2))+'px';
 theDiv[i].onclick=new Function("hideStatusDiv("+i+");");
 theDiv[i].innerHTML=txt;
 document.body.appendChild(theDiv[i]);
 if(thetimer[i]) clearTimeout(thetimer[i]);
 thetimer[i]=setTimeout('hideStatusDiv('+i+')',2500);
 }

function submitForm(form,skip_show_status,callback) {
 if(!skip_show_status) {
  var status=document.getElementById('page_status');
  if(status) {
   document.getElementById('page_status').innerHTML=document.getElementById('page_status_saving').value;
   document.getElementById('page_status').className='status_save';
   }
  }
 do {
  if(form.tagName=="SPAN") {
   var container=findContainer(form);
   var res="container="+container;
   res=recurseForm(form,res);
   var locs=document.location.toString();
   if(locs.indexOf('?')>0) locs+='&';
   else locs+='?';
   locs+=res;
   var pos=locs.indexOf('?');
   var parts=new Array(2);
   parts[0]=locs.substr(0,pos);
   parts[1]=locs.substr(pos+1);
   var xln=new XML_Load(parts[0],"POST",parts[1],"TEXT",null);
   if(xln.IsReady()) {
    xln.OnReady=function(status,list,ldata) {
     if(ldata=="no_refresh") return;
     if(ldata.substring(0,7)=='status:') {
      var st=ldata.substring(8,ldata.indexOf(';'));
      if(st=="error") {
       document.getElementById('page_status').innerHTML=ldata.substring(ldata.indexOf('message:')+8);
       document.getElementById('page_status').className='status_process';
       showStatusDiv(ldata.substring(ldata.indexOf('message:')+8),false);
       return;
       }
      }
     if(!skip_show_status) {
      var status=document.getElementById('page_status');
      if(status) {
       document.getElementById('page_status').innerHTML=document.getElementById('page_status_complete').value;
       document.getElementById('page_status').className='status_saved';
       showStatusDiv(document.getElementById('page_status_complete').value,true);
       }
      }
     container=document.getElementById(container);
     while(container.hasChildNodes()) container.removeChild(container.lastChild);
     container.innerHTML=ldata;
     var arr=ldata.match(/<script.*?>((?:.|[\r\n])*?)<\/script>/ig);
     if(arr) {
      for(var a=0;a<arr.length;a++) {
       arr[a].match(/<script.*?>((?:.|[\r\n])*?)<\/script>/ig);
       var script=RegExp.$1;
       if((script.indexOf('\{!')>-1)||(script.indexOf('\{?')>-1)) continue;
       if(window.execScript) window.execScript(script);
       else window.eval(script);
       }
      }
     if(typeof(callback)=='function') callback();
     }
    xln.Load();
    }
   }
  form=form.parentNode;
  } while(form);
 }

function recurseForm(form,res) {
 if(form.firstChild) {
  var o=form.firstChild;
  do { 
   if((o.tagName!='undefined')&&(o.tagName!=undefined)) {
    var value;
    if(o.value) {
     value=o.value.toString().replace(/\+/g,'&#43;');
     value=value.replace(/&/g,'#AMP#');
     }
    else value='';
    if(((o.tagName=='INPUT')&&(o.type!='checkbox')&&(o.type!='radio'))||(o.tagName=='HIDDEN')||(o.tagName=='TEXTAREA')) { if((o.name!='undefined')&&(o.name)) { if((o.name.indexOf('_new_')<=0)||(o.value)) res+="&"+o.name+"="+value; } }
    else if((o.type=='checkbox')&&(o.checked)) res+="&"+o.name+"=on";
    else if((o.type=='radio')&&(o.checked)) { res+="&"+o.name+"="+value; }
    else if((o.tagName=='RADIO')&&(o.selected)) res+="&"+o.name+"="+value;
    else if(o.tagName!='undefined') res=recurseForm(o,res);
    }
   if(o.nextSibling) o=o.nextSibling;
   else break;
   } while(o);
  }
 return res;
 }

function findContainer(o) {
 do {
  if(o.className=="container") return o.id;
  o=o.parentNode;
  } while(o);
 return "";
 }

function reloadFragments(fragments,params,func) {
 var status=document.getElementById('page_status');
 if(status) {
  document.getElementById('page_status').innerHTML=document.getElementById('page_status_saving').value;
  document.getElementById('page_status').className='status_save';
  }
 var locs=window.location.protocol+"//"+window.location.host+window.location.pathname+"?"+window.location.search.substr(1);
 var i=locs.indexOf( "#" );
 if(i>=0)
  locs=locs.substring(0,i);
 locs+='&fragments='+(typeof fragments != 'undefined' ? fragments : window.fragments) ;
 show_status=1;
 if(params){
	 if(params.search(/nostatus=1/)>=0)show_status=0;
	 locs+="&"+params;
 }
 var pos=locs.indexOf('?');
 var parts=new Array(2);
 parts[0]=locs.substr(0,pos);
 parts[1]=locs.substr(pos+1);
 var xln=new XML_Load(parts[0],"POST",parts[1],"TEXT",null);
 if(xln.IsReady()) {
  xln.OnReady=function(status,list,ldata) {
   if(ldata=="no_refresh") return;
   var status=document.getElementById('page_status');
   if(status) {
    if(ldata.substring(0,7)=='status:') {
     var st=ldata.substring(8,ldata.indexOf(';'));
     if(st=="error") {
      document.getElementById('page_status').innerHTML=ldata.substring(ldata.indexOf('message:')+8);
      document.getElementById('page_status').className='status_process';
      showStatusDiv(ldata.substring(ldata.indexOf('message:')+8),false);
      return;
      }
     }
    if(show_status){
      document.getElementById('page_status').innerHTML=document.getElementById('page_status_complete').value;
      document.getElementById('page_status').className='status_saved';
      showStatusDiv(document.getElementById('page_status_complete').value,true);
    }
    }
   var data=ldata.split("---- boundary ----\n");
   for(d in data) {
    if(!data[d]) continue;
    fragment=data[d].substring(2,data[d].indexOf("}"));
    var rdata=data[d].substring(data[d].indexOf("}")+1);
    var container=document.getElementById(fragment);
    if(container) {
     while(container.hasChildNodes())
      container.removeChild(container.lastChild);
     container.innerHTML=rdata;
     var arr=rdata.match(/<script.*?>((?:.|[\r\n])*?)<\/script>/ig);
     if(arr) {
      for(var a=0;a<arr.length;a++) {
       arr[a].match(/<script.*?>((?:.|[\r\n])*?)<\/script>/ig);
       var script=RegExp.$1;
       if((script.indexOf('\{!')>-1)||(script.indexOf('\{?')>-1)) continue;
       if(window.execScript) window.execScript(script);
       else window.eval(script);
       }
      }
     }
    }

   if ( func ) func();
   }
  xln.Load();
  }
 }

var right_fragments={},opened={};

function openRightFragment(name,formname) {
 if(document.getElementById('row_'+name).style.display!='none') {
  document.getElementById('row_'+name).style.display='none';
  document.getElementById('table_'+name).className='title_hide';
  document.getElementById('opened_'+name).value=0;
  }
 else {
  document.getElementById('row_'+name).style.display='';
  document.getElementById('table_'+name).className='title_scroll';
  document.getElementById('opened_'+name).value=1;
  }
 document.getElementById('save_state_'+name).value=1;
 submitForm(document.getElementById(formname),true);
 document.getElementById('save_state_'+name).value=0;
 }

   function XML_FindSubRootSection(XML_RootO,sec_TagName) {
    if (!XML_RootO) return null;
    var xml_co=XML_RootO.firstChild;
    while (xml_co) {
     if (xml_co.tagName==sec_TagName) return xml_co;
     xml_co=xml_co.nextSibling;
    }
    return null;
   }

