Tout='';

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";}
	}
	for(var i in document.getElementById('subm'))
		alert(i);
	if(Tout!="") clearTimeout(Tout); 
		document.getElementById('subm'+id+'').style.display="block";
}

function hide(id){
	if(Tout!="") clearTimeout(Tout); 
		Tout=setTimeout("document.getElementById('subm"+id+"').style.display='none'",500);
}
 
 

function lang_switch(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/gallery/"+pic+"' width='"+width+"' height='"+height+"'><br>");
  win.document.write("</body></html>");
  win.document.close();
} 











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

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);
   } 
}

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]);
}






function showElem(elmId){
	if(document.getElementById(elmId))
		document.getElementById(elmId).style.display="none";
	if(Tout!="") clearTimeout(Tout); 
		document.getElementById(elmId).style.display="block";
}

function hideElem(elmId){
	if(Tout!="") clearTimeout(Tout); 
		Tout=setTimeout("document.getElementById('"+elmId+"').style.display='none'",500);
}



//POPULI MENU
function populiTopMenu() {
}

populiTopMenu.prototype.drawMenu = function(elemID) {
	//window.status = sm_count;
	for (i=0;i<=sm_count;i++) {
		document.getElementById(i + '_sm').style.display = "none";
	}
	
	if(Tout!="") clearTimeout(Tout);
	if(document.getElementById(elemID + '_sm')) {
		document.getElementById(elemID + '_text').style.paddingLeft = this.X(elemID + '_tm') - 10;
		
		var tmDiv_obj = document.getElementById(elemID + '_sm');
		tmDiv_obj.style.display = "block";
		tmDiv_obj.style.left  = 10;
		
			if (document.all&&!window.opera) {
				var stepH  = 34;
				var stepH2 = 1;
			}
			else {
				var stepH  = 34;
				var stepH2 = 0;
			}
		//tmDiv_obj.style.top	  = this.Y(elemID + '_tm')+this.H(elemID + '_tm')+stepH;
		tmDiv_obj.style.top	  = this.Y(elemID + '_tm')+ stepH;
		//tmDiv_obj.style.top	  = 206+stepH2;//this.Y(elemID + '_tm')+18+stepH;
		tmDiv_obj.style.width = document.body.clientWidth-20;
	}
}

populiTopMenu.prototype.removeMenu = function(elemID) {
	var obj = document.getElementById(elemID + '_sm');
	if(document.getElementById(elemID + '_sm')) {
		if(Tout!="") clearTimeout(Tout);
		Tout=setTimeout (function () { obj.style.display = "none" } , 700);
	}
}



populiTopMenu.prototype.X = function(elemID) {
	var obj = document.getElementById(elemID);
	var x=0; 
	var elm = obj.parentNode.offsetParent;
	while(elm) {
		x  += elm.offsetLeft;
		elm = elm.offsetParent;
	}
	return x;
}

populiTopMenu.prototype.Y = function(elemID) {
	var obj = document.getElementById(elemID);
	var y=0; 
	var elm = obj.parentNode.offsetParent;
	while(elm) {
		y += elm.offsetTop;
		elm = elm.offsetParent;
	}
	return y;
}

populiTopMenu.prototype.H = function(elemID) {
	return  document.getElementById(elemID).offsetHeight;
}

populiTopMenu.prototype.W = function(elemID) {
	return  document.getElementById(elemID).offsetWidth;
}

populiTopMenu.prototype.createElement = function(ElemType,newID,parentID){
	var newElem = document.createElement(ElemType);
	newElem.setAttribute("id", newID); // || newElem.id = newID;
	newElem.setAttribute("style", "width:100%; height:200px; border:1px Solid red;");
	if (parentID != null)
		document.getElementById(parentID).appendChild(newElem);
	else
		document.body.appendChild(newElem);
	
}
populiTopMenu.prototype.removeElement = function(newID) {
	var elem = document.getElementById(newID);
	elem.parentNode.removeChild(elem);
}

function showVideo(name, width, height, autostart, showcontrols, showstatusbar, showdisplay, autorewind)//path,
{
	autostart = autostart ? autostart : 'True'; 
	showcontrols = showcontrols ? showcontrols : 'True';
	showstatusbar = showstatusbar ? showstatusbar : 'False';
	showdisplay = showdisplay ? showdisplay : 'False';						
	autorewind = autorewind ? autorewind : 'True';
	
	height = parseInt(height) + 50;
	
	var html = '';
	
    html += '<object width="' + width + '" height="' + height + '" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">\n';
    html += '<param name="Filename"      value="' + name + '">\n'; //+ path 
    html += '<param name="AutoStart"     value="' + autostart + '">\n';
    html += '<param name="ShowControls"  value="' + showcontrols + '">\n';
    html += '<param name="ShowStatusBar" value="' + showstatusbar + '">\n';
    html += '<param name="ShowDisplay"   value="' + showdisplay + '">\n';
    html += '<param name="AutoRewind"    value="' + autorewind + '">\n';

    html += '<embed type="application/x-mplayer2"\n'; 
    html += ' pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"'; 
    html += ' width="'         + width + '"\n'; 
    html += ' height="'        + height + '"\n'; 
    html += ' src="'           + name + '"\n';//path + 
    html += ' filename="'      + name + '"\n';
    html += ' autostart="'     + autostart + '"\n';
    html += ' showcontrols="'  + showcontrols + '"\n';
    html += ' showstatusbar="' + showstatusbar + '"\n'; 
    html += ' showdisplay="'   + showdisplay + '"\n';
    html += ' autorewind="'    + autorewind + '">\n';
    html += '</embed>'; 
    html += '</object>\n';

	sDesrc = "width=" + width + ", height=" + height + ", status=no, toolbar=no, menubar=no, scrollbars=no";
	win = window.open("Video", "", sDesrc);
	win.document.write("<html>\n<style>\nbody{padding:0px;margin:0px;}</style>\n<body>\n");
	win.document.write(html);
	win.document.write("</body>\n</html>\n");
	win.document.close();
}


function show_popupMap(dist_id) {
	sDesrc = "width=600, height=300, status=no, toolbar=no, menubar=no, scrollbars=yes, resizable=yes";
	win = window.open("/index_map.php?dist_id="+dist_id, "Map", sDesrc);
	win.document.close();
	win.focus();
}

function show_popupStructure(dist_id) {
	sDesrc = "width=600, height=500, status=no, toolbar=no, menubar=no, scrollbars=yes, resizable=yes";
	win = window.open("/index_structure.php?dist_id="+dist_id, "Map", sDesrc);
	win.document.close();
	win.focus();
}