window.onload = initialization; 
window.onresize = setScreenClass;

function initialization() {
	tabActive = getElement('tab1');
	displayed = getElement('video_block');
	setScreenClass();
}

function setScreenClass(){
	var fmt = document.documentElement.clientWidth;
	var cls = (fmt<1200) ? 'screen_hi' : 'screen_wide';
	document.body.className=cls;
};

function getElement(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}
	else if (document.all) {
		return document.all(id);
	}
}

function showInfo(sourceTab, infoContainer) {
	if (sourceTab != tabActive) {
		changingCurrent = getElement(infoContainer);
		tabActive.className = tabActive.className.replace(/block2/g, 'head10');
		sourceTab.className = 'block2';		
		tabActive = sourceTab;
		changingCurrent.style.display = 'block';
		displayed.style.display = 'none';
		displayed = changingCurrent;
	}
}

  function image_reload()
  {
   document.images['captcha'].src='/captcha.php?rnd='+Math.round(Math.random(0)*1000);
  }
  
	/**
	* @desc Install main variables
	*/
	var new_window;
	var allow_flash = false;
	
	function submitform(url)
	{
	   document.form_with_navigation.action = url;
	   document.form_with_navigation.submit();
	}	
	
	
	// Clear func
	function onclearform(frm) {
		for (var i = 0; i < frm.length; i++)
		if (/^(text|pass)/.test(frm.elements[i].type))
		frm.elements[i].value = '';
		else if (/^(radio|checkbox)/.test(frm.elements[i].type))
		frm.elements[i].checked = false;
		else if (/^select/.test(frm.elements[i].type))
		frm.elements[i].options.selectedIndex = (/one$/.test(frm.elements[i].type) ? 0 : -1);
	}
	
	//  Vote func
	function write_quest(str) {
		for (var i = 0; i < str.length; i++)
		if (!isNaN(parseInt(str.elements[i].value)))
		if (str.elements[i].checked) {
			str.submit();
			return;
		}
		alert('Пожалуйста, выбирите один из предложенных вариантов дл\я голосовани\я!');
	}
	
	function onindicatetext(str) {
		str.value = str.value.replace(/^(\s+)/gi, '');
		str.value = str.value.replace(/(\s+)$/gi, '');
		if (str.value.length > 0)
		return true;
	
		//if(str==null) return;
		str.select();
		str.focus();
		return false;
	}
	
	function onindicateexists(str, tmp) {
		for (var i = 0; i < tmp.length; i++)
		if (str == tmp[i])
		return true;
		return false;
	}
	
	function onindicatemail(str) {
		var tmp  = '';
		var lg   = true;
		var arr0 = new Array(45, 46, 95);
	
		var arr1 = str.value.match(/\b(\w((\w|\.|-)*\w)?@\w((\w|\.|-)*\w)?(\.[a-z]{2,3}))\b/gi);
		if (arr1 != null)
		for (var i = 0; (i < arr1.length && lg); i++) {
			tmp+= (tmp.length > 0 ? String.fromCharCode(59, 32) : '') + arr1[i];
			for (var j = 0; j < arr0.length; j++)
			if (arr1[i].indexOf(String.fromCharCode(arr0[j], arr0[j])) > -1) {
				lg = false; break; }
		}
	
	
		if (!lg || (str.value.length > 0 && tmp.length == 0))
		return false;
	
		str.value = tmp;
		return true;
	}
	
	function onindicatehref(str)
	{
		var tmp_href=str.value;
	
		var arr1 = tmp_href.match(/^(http:\/\/)([_a-z\d\-]+(\.[_a-z\d\-]+)+)((\/[ _a-z\d\-\\\.]+)+)*/gi);
		if(arr1!=null) return true
		else return false
	}
	
	function onformsform(frm,page) {
		var page_mas=eval(page+"_arr");
		for (var i = 0; i < frm.length; i++)
		{
			if (/^text/i.test(frm.elements[i].type))
			{
				if (!onindicatetext(frm.elements[i]))
				{
					if (onindicateexists(frm.elements[i].name, page_mas)) {
						onformsmess(frm.elements[i].name);
						return;
					}
				}
				else if (/mail$/.test(frm.elements[i].name))
				{
					if (!onindicatemail(frm.elements[i])) {
						onformsmess(frm.elements[i].name);
						return;
					}
				}
				else if(/href$/.test(frm.elements[i].name))
				{
					if (!onindicatehref(frm.elements[i])) {
						onformsmess(frm.elements[i].name);
						return;
					}
				}
			}
			else if(/sel_1$/.test(frm.elements[i].name))
			{
				if(frm.elements[i].options[frm.elements[i].selectedIndex].value==0)
				{
					onformsmess(frm.elements[i].name);
					return;
				}
			}
		}
	
		frm.submit();
	}
	
	function onformsmess(str) {
		var tmp = eval(str);
		alert(tmp.length > 0 ? tmp : mess);
	}
	
	function openWindow(url, w, h) {
		var options = "width=" + w + ",height=" + h + ",";
		options += "scrollbars=yes,status=no,";
		options += "menubar=no,toolbar=no,position=center,location=no,directories=no";
		var newWindow = window.open(url, 'newWind', options);
		newWindow.focus();
	}
	
	
	
	
	
	
	function window_available()
	{
		if (!new_window) return false
		else if (new_window.closed) return false
		else return true
	}
	
	function resize_image(path)
	{
		var img_loaded=new Image();
		img_loaded.src=path;
		new_window.window.resizeTo(img_loaded.width,img_loaded.height);
	}
	
	function display_image(path,title)
	{
		var img=new Image();
		img.src=path;
		img_width=img.width;
		img_height=img.height;
	
		add_param="menubar=no,toolbar=no,location=no,directories=no,width="+img_width+",height="+img_height;
	
		(window_available())? new_window.close(): new_window=false;
	
		new_window = window.open("","",add_param);
		new_window.document.writeln('<html>');
		new_window.document.writeln('<head>');
		new_window.document.writeln('<title>'+title);
		new_window.document.writeln('<\/title>');
		new_window.document.writeln('<\/head>');
		new_window.document.writeln('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
		new_window.document.writeln("<img src='"+img.src+"'>");
		new_window.document.writeln('<\/body>');
		new_window.document.writeln('<\/html>');
		var img_loaded=new Image();
		img_loaded.src=path;
		new_window.window.resizeTo(img_loaded.width,img_loaded.height);
		new_window.document.close();
	}
	
	function write_image(i, t)
	{
		var par='location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width='+Math.floor(screen.width/2)+',height='+Math.floor(screen.height/2);
		 var wind = window.open(SITE_URL + 'image.php?act='+i+'&title='+t,'OrattaImage',par);
		wind.focus();
	}
	
	function write_vote(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=350,height=250';
		var wind=window.open(SITE_URL+LANG_URL+'vote/other/'+i,'Blank',par);
		wind.focus();
	}
	
	function message(i, id)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=600,height=570';
		var wind=window.open(SITE_URL+LANG_URL+'message/'+i+'/'+id,'Blank',par);
		wind.focus();
	}
	
	function write_confreport(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=500,height=300';
		var wind=window.open(SITE_URL+LANG_URL+'conference/report/'+i,'Blank',par);
		wind.focus();
	}	
	
	function write_progreport(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=700,height=500';
		var wind=window.open(SITE_URL+LANG_URL+'programm/report/'+i,'Blank',par);
		wind.focus();
	}		
	
	function write_product(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=350,height=250';
		var wind=window.open(SITE_URL+LANG_URL+'product/detail/'+i,'Blank',par);
		wind.focus();
	}
	
	function order_action(i)
	{
		var par='location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes';
		var wind=window.open(SITE_URL+LANG_URL+'action/order/'+i,'Blank',par);
		wind.focus();
	}	
	
	function open_service(i)
	{
		var par='location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=700,height=700';
		var wind=window.open(SITE_URL+LANG_URL+'service/info/'+i,'Blank',par);
		wind.focus();
	}	
	
	function publish_vote(i)
	{
		var par='location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=700,height=700';
		var wind=window.open(SITE_URL+LANG_URL+'vote/publish/'+i,'Blank',par);
		wind.focus();
	}	
	
	function servicecomplex(complex,service)
	{
		var par='location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=700,height=700';
		var wind=window.open(SITE_URL+LANG_URL+'service/complex/'+complex+'/'+service,'Blank',par);
		wind.focus();
	}	
	
	function show_map(i)
	{
		var par='location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=810,height=600';
		var wind=window.open('http://training.com.ua/map.php?address=' + i,'Blank',par);
		wind.focus();
	}	
	
	function write_form(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=780,height=550';
		var wind=window.open(SITE_URL+LANG_URL+'forms/'+i,'Blank',par);
		wind.focus();
	}
	
	function write_table(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=700,height=400';
		var wind=window.open(SITE_URL+LANG_URL+'table/'+i,'Blank',par);
		wind.focus();
	}
	
	/**
	 * Check allow flash
	 */
	var plugVersion = 6;
	var n = navigator; 
	
	if (n.plugins && n.plugins.length > 0)
	{
		var np = n.plugins;
		for (i in np)
		if (np[i].description && np[i].description.match(/Shockwave[\s]+Flash[\s]+([0-9\.]+)/ig))
		{
			if (parseInt(RegExp.$1) > plugVersion)
			{
				allow_flash = true;
				break;
			}
		}
	}
	else if (n.userAgent && /MSIE/ig.test(n.userAgent) && /Win/ig.test(n.appVersion))
	{
		document.write('<SCRIPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('allow_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & plugVersion)))\n');
		document.write('</SCRIPT\> \n');
	}
	
	/**
	 * Check allow flash
	 * 
	 * @author X-MAN <Admin@relax-info.com>
	 * @return bool
	 */
	function check_allow_flash()
	{	
		return (allow_flash)? 1 : 0;
	}
	
    function updatelist(event)
    { 
		alert(event.charCode);
    }	
    
    
	function _(e) {
	    return document.getElementById(e) ? document.getElementById(e) : false;
	}
    
	fsize.counter = 0;
	fsize.classNames = new Array('16', '18');
	
	function fsize($)
	{
		 _('content').style.fontSize = (function(){
			return function ()
			{
				if ($ == "+")
				{
					fsize.counter++
					if ( fsize.counter < fsize.classNames.length)
					{
						_("plus").src = "http://training/images/font_up_off.gif";
						_("minus").src = "http://training/images/font_down.gif";
						return fsize.classNames[fsize.counter]
					}
					else
					{
						fsize.counter = fsize.classNames.length - 1;
						return fsize.classNames[fsize.counter]
					}
				}
				
				if ($ == "-")
				{
					fsize.counter--
					if ( fsize.counter > 0 )
					{
						return fsize.classNames[fsize.counter]
					}
					else
					{
						_("plus").src = "http://training/images/font_up.gif";
						_("minus").src = "http://training/images/font_down_off.gif";
						fsize.counter = 0;
						return fsize.classNames[fsize.counter]
					}
				}
			}();
		})() + "px";
	}    
	
	function toggle(id)
	{
		var display = _(id).style.display ? '' : 'none';
		_(id).style.display = display;
	}
	
	function serv(id)
	{
		var arr = id.split('_');
		_('group'+arr[0]).className='head3over';
		_('s'+arr[1]).className='supover';
	}	
	
	function unserv(id)
	{
		var arr = id.split('_');
		_('group'+arr[0]).className='head3';
		_('s'+arr[1]).className='sup';
	}	