var currSobor=jsArgs.sobor;var ajaxLoadImg=new Image();ajaxLoadImg.src="/images/ajax-loader.gif";ajaxLoadImg.width=128;ajaxLoadImg.height=15;function a(obj){obj.setAttribute('is_active',(obj.className.match('active')?1:0));obj.style.textDecoration='none';return true;}
function u(obj){obj.style.textDecoration=obj.getAttribute('is_active')==1?'':'underline';return true;}
function sobor_switch(obj,s){obj.setAttribute('is_active',(obj.className.match('active')?1:0));if(obj.getAttribute('is_active')==1)return false;currSobor=!currSobor?(s?s:'sobor2009p'):((currSobor=='sobor2009a')?'sobor2009p':'sobor2009a');sobor_switch_all_inactive();obj.className='sw_menu_1_lnk active';obj.parentNode.className='sw_menu_1';obj.setAttribute('is_active',1);var page_header_H=document.getElementById("_h_");var page_header_txt='';if(page_header_H)page_header_txt=page_header_H.innerHTML;var div=document.getElementById('content_area');div.innerHTML='';div.appendChild(ajaxLoadImg);var additional_url_path="q_";if(jsArgs.rubric&&jsArgs.rubric.length>0)additional_url_path+="rubric"+jsArgs.rubric+"_";if(jsArgs.page&&jsArgs.page.length>0)additional_url_path+="page"+jsArgs.page+"_";if(jsArgs.cid&&jsArgs.cid.length>0)additional_url_path+="cid"+jsArgs.cid+"_";if(jsArgs.tag&&jsArgs.tag.length>0)additional_url_path+="tag"+jsArgs.tag+"_";additional_url_path+="q";server_call("",{},function(resp){var resp_objects=xml_getObjectList(resp);if(resp_objects&&resp_objects[0]){var content=resp_objects[0];div.removeChild(ajaxLoadImg);if(jsArgs.cid&&(jsArgs.cid=='News'||jsArgs.cid=='PhotoAlbum'||jsArgs.cid=='VideoDocument')){if(page_header_txt.match(/Поместный/)){page_header_txt=page_header_txt.replace(/Поместный/,'Архиерейский');page_header_txt=page_header_txt.replace(/\/sobor2009p\//,'/sobor2009a/');}else{page_header_txt=page_header_txt.replace(/Архиерейский/,'Поместный');page_header_txt=page_header_txt.replace(/\/sobor2009a\//,'/sobor2009p/');}}
div.innerHTML="<h1 id='_h_'>"+page_header_txt+"</h1>"+content["html"];}},("/rpc/"+currSobor+"/"+additional_url_path+"/content.xml"));return true;}
function sobor_switch_all_inactive(){var sCollection=document.getElementById('sobor_switch_table').getElementsByTagName('SPAN');for(var i=0,cLen=sCollection.length;i<cLen;i++){if(sCollection[i]){sCollection[i].className='sw_menu_2_lnk';sCollection[i].parentNode.className='sw_menu_2';sCollection[i].setAttribute('is_active',0);}}
return true;}
var rpc;RPC.READY_STATE_COMPLETE=4;function RPC(fe,skip_alerts){if(window.XMLHttpRequest){this.req=new XMLHttpRequest();}else if(window.ActiveXObject){this.req=new ActiveXObject("Microsoft.XMLHTTP");}else{alert("RPC not available");}
this.url=fe?fe:"rpc_save.html";var req=this.req;if(skip_alerts){this.skip_alerts=skip_alerts;req.skip_alerts=skip_alerts;}
var rpc=this;this.req.onreadystatechange=this.callback=function(){if(req.readyState==RPC.READY_STATE_COMPLETE){var httpStatus=req.status;if(httpStatus==200||httpStatus==0){var doc=req.responseXML;if(!doc){if(!this.skip_alerts)alert("Cannot parse server reply :\n"+req.responseText.substr(0,256));var cons=document.getElementById('__console');if(cons){cons.innerHTML+=req.responseText;}
return false;}
var response=doc.getElementsByTagName('response').item(0);if(!response){if(!this.skip_alerts)alert("Server reply has no response element "+"\n"+req.responseText);return false;}
var more=response.getAttribute('waitmore');var qid=response.getAttribute('qid');var qn=response.getAttribute('qn');var opts=response.getAttribute('opts');if(more){if(rpc.onStartWaiting){rpc.onStartWaiting();}
document.body.style.cursor="wait";setTimeout(function(){var newrpc=new RPC(fe);newrpc.onEndWaiting=rpc.onEndWaiting;newrpc.request('__wait',{q:qid,qn:qn,opts:opts},rpc.onOk);},parseInt(more));}else{var rc=response.getAttribute('rc');if(rc=='EXCEPTION'){var ex=xml_getObjectAttributes(response);var func_name='exception_'+ex.exceptionClass.replace(/::/g,'_');if(eval("window."+func_name)){eval(func_name+"(ex)");}else{alert(ex.text?ex.text:'произошла ошибка на сервере');}
if(rpc.onEndWaiting)rpc.onEndWaiting(req);document.body.style.cursor='default';return false;}
if(rc=='FAILED'){alert('произошла ошибка на сервере');if(rpc.onEndWaiting)rpc.onEndWaiting(req);document.body.style.cursor='default';return false;}
rpc.onOk(response,req);if(rpc.onEndWaiting)rpc.onEndWaiting(req);document.body.style.cursor='auto';}}else{rpc.onError(req);document.body.style.cursor='auto';}}};}
RPC.prototype.onError=function(req){if(!this.skip_alerts)
alert("error fetching data!"
+"\n\nreadyState:"+req.readyState
+"\nstatus: "+req.status
+"\nheaders: "+req.getAllResponseHeaders());}
RPC.prototype.onOk=function(){alert("Done");}
RPC.prototype.request=function(proc,args,onOk,sync,method){var qs='';if(proc!==null&&proc!==undefined&&proc.length>0)qs+='_proc='+proc;for(var arg in args){var val=args[arg];if(typeof(val)=='object'){for(k in val){if(val[k]&&val[k].constructor!=Function)
qs+='&'+encodeURIComponent(arg)+'='+encodeURIComponent(val[k]);}}
else{qs+='&'+encodeURIComponent(arg)+'='+encodeURIComponent(val);}}
var url=this.url;if(!method)method="POST";if(method=='GET')url+='?'+qs;this.req.open(method,url,!sync);this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');this.onOk=onOk;this.req.send(method=='GET'?null:qs);if(sync)this.callback();}
function server_call(proc,args,onOk,fe,sync,method,skip_alerts,onStartWaiting,onEndWaiting){rpc=new RPC(fe,skip_alerts);rpc.onStartWaiting=onStartWaiting;rpc.onEndWaiting=onEndWaiting;rpc.request(proc,args,onOk,sync,method);}
function xml_getObjectAttribute(node,attrName){for(var i=0;i<node.childNodes.length;i++){var nn=node.childNodes[i];if(nn.nodeType==1){if(nn.tagName==attrName){return nn.childNodes[0]?nn.childNodes[0].data:null;}}}
return'KO';}
function xml_getObjectAttributes(node){var o={};if(!node){alert("Empty node got");return o;}
for(var i=0;i<node.attributes.length;i++){o[node.attributes[i].nodeName]=node.attributes[i].nodeValue;}
for(var i=0;i<node.childNodes.length;i++){var nn=node.childNodes[i];if(nn.nodeType==1){if(nn.getAttribute('class')=='subobject'){o[nn.tagName]=null;for(var j=0;j<nn.childNodes.length;j++){var nnn=nn.childNodes[j];if(nnn.nodeType==1){o[nn.tagName]=xml_getObjectAttributes(nnn);}
break;}}else
if(nn.getAttribute('class')=='subobjects'){o[nn.tagName]=[];for(var j=0;j<nn.childNodes.length;j++){var nnn=nn.childNodes[j];if(nnn.nodeType==1){o[nn.tagName][o[nn.tagName].length]=xml_getObjectAttributes(nnn);}}}else
if(nn.childNodes[0]){o[nn.tagName]=nn.childNodes[0].data;}else{o[nn.tagName]=null;}}}
return o;}
function xml_getObjectList(node){var l=new Array;for(var i=0;i<node.childNodes.length;i++){var nn=node.childNodes[i];if(nn.nodeType==1){l[l.length]=xml_getObjectAttributes(nn);}}
return l;}
