var Tout;

function $(o){
  return document.getElementById(o);
}

function Toggle(id1,id2,obj,color){

  setTimeout(function(){ChangeColor(obj,color);},0);
  document.getElementById(id1).style.display ="none";
  document.getElementById(id2).style.display ="block";  
}

function ChangeColor(obj,color){
 obj.style.backgroundColor ="#"+color;
}


function linkMouseOver(obj){
 obj.style.backgroundColor ="#A33905";
 obj.style.color  = "#fff";

}


function linkMouseOut(obj){
 obj.style.backgroundColor="#fff";
 obj.style.color="#000";

}


function show(id,num){
 for(i=0;i<num;i++){
   if(document.getElementById('subm'+i)){
     document.getElementById('subm'+i).style.display="none";}
 }

 if(Tout!="") clearTimeout(Tout); 
   document.getElementById('subm'+id+'').style.display="block";
}



function hide(id){
 if(Tout!="") clearTimeout(Tout); 
   Tout=window.setTimeout("document.getElementById('subm"+id+"').style.display='none'",500);
}
 
 
function expand(id){
   submenu = document.getElementById(id);
   submenu.style.display = submenu.style.display == 'block' ? 'none' : 'block';	
}
 


function showActiveMenu(id){
  id = 'submenu' + id;	
  if(document.getElementById(id))
    document.getElementById(id).style.display="block"; 
}



function lang(lang)
{
 var current=window.location.href;
 var new_loc;
 if(/lang=/.test(current))
   new_loc=current.replace(/lang=\w*/,"lang="+lang);
 else if(/\?/.test(current))
   new_loc=current+"&lang="+lang;
 else 
   new_loc=current+"?lang="+lang;  
 window.location.replace(new_loc);
}

var send = function(link){
 var dataToSend =document.getElementById('calendar_y').value+"."+document.getElementById('calendar_m').value;
 var ajax = new httpAjaxRequest(); 
 if(ajax)
  {  
     ajax.prepareHash({}); 
     ajax.open("GET", link.replace('index','ajax')+dataToSend);
     ajax.send();
     ajax.getData();
     ajax.onreadystatechange = function()
       { 
           data =ajax.getResult();
           document.getElementById("calendar_div").innerHTML =data.calendar; 
       }  
  }
 else window.location = link + document.getElementById('calendar_y').value+"."+document.getElementById('calendar_m').value; 
}
 
function showPic(pic,width,height)
{ 
  sDesrc = "width=" + width + ", height=" + height +
  		", status=no, toolbar=no, menubar=no, scrollbars=no";
  win=window.open("Gallery", "", sDesrc);
  win.document.write("<html><style>body{padding:0px;margin:0px;}</style><body>");
  win.document.write("<img src='uploads_script/"+pic+"' width='"+width+"' height='"+height+"'><br>");
  win.document.write("</body></html>");
  win.document.close();
} 



function ajaxUpdate(container,query,alternative){
   var url = './ajax.php?'+query; 
   showLoader();
   
   var ajax = new Ajax.Updater(container,url, {
          method:  'get',
          evalScripts:  true,
          onException: function(){
             if(alternative){
                window.setTimeout(function(){window.location.href=alternative},0); 
             }
             else{
                alert('Failed to perform request. Check if ajax is supported');
                hideLoader(); 
             }  
          },
          onSuccess: function() {
             hideLoader();
          }
          
      }); 
}


function hideLoader(){
  document.getElementById('loader').style.display = 'none';
}

function showLoader(){
  document.getElementById('loader').style.display = 'block';
}


function CheckIsIE() {
  return (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER');
}


function print_innerHTML(parseFrom,iframeTo,css_src) {
 var iDoc = get_DOC($(iframeTo));
 iDoc.getElementById('print_body').innerHTML = document.getElementById(parseFrom).innerHTML;
 if(CheckIsIE()==true) {
   iframe = eval ('document.'+iframeTo);
   iframe.close();
   importCSS(iDoc,css_src);
   iframe.focus();
   iframe.print();
 }
 else{
   importCSS(iDoc,css_src);
   $(iframeTo).contentWindow.print();
 }
}

function importCSS(doc, css) {
 var css_ary = css.replace(/\s+/, '').split(',');
 var csslen, elm, headArr, x, css_file;

 for (x = 0, csslen = css_ary.length; x<csslen; x++) {
 css_file = css_ary[x];

 if (css_file != null && css_file != 'null' && css_file.length > 0) {
 // Is relative, make absolute
 if (css_file.indexOf('://') == -1 && css_file.charAt(0) != '/')
 css_file = this.documentBasePath + "/" + css_file;

 if (typeof(doc.createStyleSheet) == "undefined") {
 elm = doc.createElement("link");

 elm.rel = "stylesheet";
 elm.href = css_file;

 if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)
 headArr[0].appendChild(elm);
 } else
 doc.createStyleSheet(css_file);
 }
 }
}

function get_DOC(iframe) {
 if(iframe.contentWindow)
 return iframe.contentWindow.document;
 else if (iframe.contentDocument)
 return iframe.contentDocument;
 else
 return iframe.document;
}


