function switch_room(target,section,sec_det)
  { 
  	var trgt = document.getElementById(target);
    var xmlhttp = null;
	var cont = null;
	if(sec_det != ''){sec_det = '&sec_det='+sec_det;}
	var url = 'sections.php?sec_id='+section+sec_det;
	//document.getElementById(room).style.borderStyle = 'inset';
	//document.getElementById('blinker').innerHTML = loading_text;
	
	//alert(url);
	//alert(target);
    // Mozilla
    if (window.XMLHttpRequest && !window.ActiveXObject) {
        xmlhttp = new XMLHttpRequest();
        //alert("FF "+navigator.appName+" "+navigator.appVersion);
    }
    // IE
    else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        //alert("IE");
    }
   
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange = function() {
         if(xmlhttp.readyState == 4 && xmlhttp.status >= 400) {
            cont = on_error_text;
			active_room_sel(section);
			trgt.innerHTML = cont;

			//sec_id = section;
        }
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {

        	var cont = xmlhttp.responseText;
			//active_room_sel(section);
			trgt.innerHTML = cont;
			
			document.distr_url = document.distr_srv+'?sec_id='+section;
			if(sec_det != '&sec_det=undefined')
			{
				document.distr_url +=sec_det;			
			}
			
			document.distr_url += '&sync=1';
			//document.getElementById('blinker').innerHTML = '&nbsp;';
			//roudIt();
        }
    };
    xmlhttp.send(null);
}

function active_room_sel(section)
{
	//alert(section);
	var items = menu.length - 1;
	var menu_item;
	var i;
		
	for (i = 0; i <= items; i++)
	{
		menu_item = document.getElementById(menu[i]);
		//alert(menu_item);
		if (menu_item.id == section)
		{
			menu_item.className = 'menu_selected';
		}
		else
		{
			menu_item.className = 'menu_class';
		}
		
	}
}


function photo(name, header, width, height) {
  var w = width*7;
  var h = height*7;
  myWin= open(name, "displayWindow", 
    "width="+w+",height="+h+"status=no,toolbar=no,menubar=no,scrollbars=1,resizable=1");
  myWin.focus();
  
}

function music(name) {
  var w = 200;
  var h = 100;
  myWin= open(name, "displayWindow", 
    "width="+w+",height="+h+"status=no,toolbar=no,menubar=no,scrollbars=0,resizable=0");
  myWin.focus();
  
}

function cliLoad(sec_id)
{
	 myWin= open('cliLoad.php?sec_id='+sec_id, "displayWindow", 
    "width=300,height=200,status=no,toolbar=no,menubar=no,scrollbars=1,resizable=1,top=350,left=500");
  myWin.focus();
}

function markArt(sec_id,sub_id,back,mark)
{
	callback = 'document.getElementById(\''+back+'\').innerHTML = cont';
	
	//callback = 'alert(cont)';
	
	url = 'action.php?action=mark_art';
	params = '&sec_id='+sec_id+'&det_id='+sub_id+'&mark='+mark;
	alert_mes = '\u0412аш голос принят!';
	method = 'GET';
	
	
	CliReq_callback(url,params,alert_mes,method,callback);
	
}

function CliReq_callback(url,params,alert_mes,method,callback)
  { 
  	var xmlhttp = null;
	var cont = null;
	if (method !== 'POST' && method !== 'GET')
	{method = 'GET';}

	//alert(url);
    // Mozilla
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
   
   	if(method == 'GET')
	{
		xmlhttp.open(method, url+'&'+params, true);
		xmlhttp.send(null);
	}
	else if (method == 'POST')
	{
		xmlhttp.open(method, url, true);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		//alert(params);
		xmlhttp.send(params);
	}
    
    xmlhttp.onreadystatechange = function() {
         if(xmlhttp.readyState == 4 && xmlhttp.status >= 400) {
           // cont = "Возникла проблема при передаче запроса. Проверьте подключение к Интернет.";
			alert("\u0412озникла проблема при передаче запроса. Проверьте подключение к Интернет.\n Детали:\n"+xmlhttp.responseText);
			
        }
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//alert(xmlhttp.responseText);           
			cont = xmlhttp.responseText;
				if(alert_mes !== '')
				{
					alert(alert_mes);
				}
				if(callback)
				{
					eval(callback);
				}
			}
        }
    }
    
    function panCollapse(id)
    {
		
		if(!document.getElementById(id).oldStyle)
		{
			document.getElementById(id).oldStyle = new Object;
		}
		
    	if(document.getElementById(id).style.display !== 'none')
    	{
			document.getElementById(id).oldStyle = document.getElementById(id).style;
    		document.getElementById(id).style.display = 'none';
    	}
    	else
    	{
    		document.getElementById(id).style.display = 'block';
			document.getElementById(id).style.backgroundColor = document.getElementById(id).oldStyle.backgroundColor;
    	}
    	
    }

function checkField(f,t)
{
	var callback = "validResult(cont,'"+f.id+"')";
	CliReq_callback('/sections.php?module=reg_mod','test=1&'+t+'='+f.value,'','GET',callback)
}
function validResult(r,id)
{
	if(r == "0")
	{
		document.getElementById(id).style.borderColor = 'green';
	}
	else if(r == "1")
	{
		document.getElementById(id).style.borderColor = 'red';
	}
	else
	{
		alert("\u041eшибка асинхронной проверки данных!\nИспользуйте тоько буквы и цифры.");
	}
}
function checkPass()
{
	var p = document.getElementById("pass_inp");
	var p_c = document.getElementById("pass_check");
	
	if(p.value == p_c.value)
	{
		checkField(p,'pass');
		validResult(0,"pass_check");
	}
	else
	{
		validResult(1,"pass_inp");
		validResult(1,"pass_check");
	}
	
}
function checkName(f)
{
	if(f.value == '')
	{
		validResult(1,"name_check");
	}
	else
	{
		validResult(0,"name_check");
	}
}
function checkDate(f)
{
	if(f.value == '')
	{
		validResult(1,f.id);
	}
	else
	{
		validResult(0,f.id);
	}
}

//|||||||||||||||||||||||||||||||||||||||||||||COOKIES||||||||||||||||||||||||||||||||||||||||||||||||

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
// don't use this, it's weak and does not handle some cases
// correctly, this is just to maintain legacy information
function Get_Cookie( name ) {

var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


//END||||||||||||||||||||||||||||||||||||||||||COOKIES||||||||||||||||||||||||||||||||||||||||||||||||
