// JavaScript Document
function sh_div(what, what2) {
	 var i=1;
	 var coll = [];
	 var coll2 = [];
	 while (document.getElementById('d'+ i)) {
	  coll[i] = document.getElementById('d'+ i);
	  coll2[i] = document.getElementById('t'+ i);
		
		i++;
	 }
 obj = document.getElementById(what);
 obj2 = document.getElementById(what2);

 var i=1;
 if (obj.className == 'off') {
	 while (coll[i]) {
		coll[i].className = 'off';
		coll2[i].className = 'lang_tabs';
		
		i++;
		} 
	obj.className = 'on';
	obj2.className = 'lang_tabs_active';
 } 
}

function sh_hide_div(div_,what) {
	 var i=1;
	 while (document.getElementById(div_+i)) {
	 document.getElementById(div_+i).className="off";
		i++;
	 }
	 //alert(div_+what);
 if(what!=0) {
  document.getElementById(div_+what).className="on";
 }
}


function show_div(koi) {
 obj = document.getElementById(koi);
	obj.className = 'on';
	}

function hide_div(koi) {
 obj = document.getElementById(koi);
	obj.className = 'off';
	}

function menu_type_select(){
 var obj = document.getElementById('modul_type_id');
 var selected = obj.value;
 sh_hide_div('md',selected);
}

function xGetElementById(e) {
	if(typeof(e)!='string') return e;
	if(document.getElementById) e=document.getElementById(e);
	else if(document.all) e=document.all[e];
	else e=null;
	return e;
} 

function getNewCaptcha(n) {
	var _img = xGetElementById('captcha'+n);
	var _rnd = 12574*Math.random();
	_img.src = "/Scripts/myCaptcha.php?id="+_rnd;
}

function clear_search(text){
 var obj = document.getElementById('search_field');
 
 if(obj.value == text) {
	 obj.value="";
 }

}

function ajaxFunction(what) {
var xmlhttp;
var add_str="";

		add_str+='?menu_type_id='+document.getElementById('menu_type_id').value;
	

	if (window.XMLHttpRequest)	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }	else  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	
	var url="/admin/inc/ajax_menu.php"+add_str;
	
		xmlhttp.onreadystatechange=function()	{
			if(xmlhttp.readyState==4)  {
			  var div_text = "";
			  var otgovor = xmlhttp.responseText;
				div_text+='<option value="0|1">- Корена на сайта -</option>';
				if(otgovor!="") {
					masiv = otgovor.split('**');
					for(i=0;i<masiv.length; i++) {
						help = masiv[i].split('*');
						level = parseInt(help[2])+1;
					 div_text+='<option value="'+help[1]+'|'+level+'">'+help[0]+'</option>';
					}
				}
					 document.getElementById("parent_id").innerHTML=div_text;
			}
			  // alert();
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
}


// ============================= FORM VALIDATION EFECT ============================= //

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "/images/msg_arrow.gif"; 
}


// промо //

isNS = (navigator.appName == 'Netscape');
isIE = (navigator.appName.indexOf('Microsoft') != -1);
isOP = (navigator.appName == 'Opera');
ns4 = (document.layers);
ie4 = (document.all && !document.getElementById);
ie5 = (document.all && document.getElementById);
ns6 = (!document.all && document.getElementById);

function close_reklama() {
 var obj = document.getElementById('reklama');
 obj.className='off';
}

function pos(what) {
	var winW = 931, winH = 460; // for old browsers

	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
		winW = window.innerWidth;
		winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
	 }
	}


 var obj = document.getElementById(what); 
 var browser_width = winW; //screen.width;
 var browser_height = winH; //screen.height;
 // var top_ = browser_height/2-200;
 var top_ = 20;
 var left_ = browser_width/2-300;
 obj.style.left = left_+'px';
 obj.style.top = top_+'px';
 setInterval("close_reklama()",40000)
}
