
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({date:dataToSend}); 
     ajax.open("GET", "ajax.php");
     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/picgallery/"+pic+"' width='"+width+"' height='"+height+"'><br>");
  win.document.write("</body></html>");
} 

function drawOptions(arr,selected){
  selected = selected||"";
  arr['0'] = other;
  for(var i in arr){
     select = (i==selected)?"selected":'';
     document.write('<option value="'+i+'" '+select+'>'+arr[i]+'</option>');
   }
}

function switchPos(obj,selected){
  selected = selected||'';
  var ind = obj.options[obj.selectedIndex].value; 
  var selbox2 = document.getElementById('position');
  delOptions(selbox2);
  for(var i in indexes){
     for(j=0;j<indexes[i].length;j++)
      {
        if(ind==indexes[i][j])
         {
            createOption(selbox2,i,positions[i],selected);
            break;
         } 
      }  
   } 
 if(ind !="")  
  createOption(selbox2,'0',other,selected);
}

function switchCountry(obj,selected){
  selected = selected||'';
  var ind = obj.options[obj.selectedIndex].value; 
  var selbox2 = document.getElementById('city');
  delOptions(selbox2);
  for(var i in city){
    if(ind==city[i][0])
      createOption(selbox2,i,city[i][1],selected);
   } 
  if(ind !="")  
   createOption(selbox2,'0',other,selected); 
}

function createOption(parent,val,text,selected){
  var opt = document.createElement("option");
  opt.value = val;
  opt.innerHTML = text;
  if(val==selected)
	 opt.selected = true;
  parent.appendChild(opt);
}

function delOptions(obj){
  var count = obj.options.length-1; 
  for(i=count; i>0; i--)
	obj.removeChild(obj.options[i]);
}
