var actpage;
var nowpage=true;


function showPage(page, obj, title_)
{
	var content=document.getElementById('content');
	//alert(obj);
	if (title_!="") {
		var z=document.title;
		z=z.substr(0, z.indexOf(' :: ')+4);
		document.title=z+title_;
		if (!nowpage || (document.getElementById('actpage')!=null))
			{
			if (nowpage)
				{
				actpage=document.getElementById('actpage');
				nowpage=false;
				}
			actpage.className='nact_mm';
			}

		actpage=obj;
		obj.className='act_mm';
		nowpage=false;
		}
	
	content.innerHTML='<div class="loading">Пожалуйста подождите,<br> идёт загрузка страницы...</div>';
	ajaxRequest('GET', 'ajax.php'+page, 'content', test);
	return false;
}

function test()
{
var b=document.getElementById('bottom');
b.style.display='none';
b.style.display='block';
}

function login(id, obj, caption)
{
	var content=document.getElementById('content');
	var title=document.getElementById('title');
	var z=document.title;
	z=z.substr(0, z.indexOf(' :: ')+4);
	document.title=z+caption;	
	title.innerHTML=caption;
	
	if (nowpage)
		{
		actpage=document.getElementById('actpage');
		nowpage=false;
		}
	actpage.className='noact_button';
	actpage=obj;
	obj.className='act_button';
	content.innerHTML=document.getElementById(id).innerHTML;
	test();
	return false;
}

var ajaxRequest = new function() { 
    function handleReadyState(o, callback, id1) 
	{ 
        var poll = window.setInterval(function() { 
            if(o && o.readyState == 4) { 
			document.getElementById(id1).innerHTML=o.responseText;
                window.clearInterval(poll); 
                if ( callback ){ 
                    callback(o); 
                } 
            } 
        }, 
        50); 
    } 
    var http; 
    try { 
        http = new XMLHttpRequest(); 
    } 
    catch(e) { 
        var msxml = [ 
            'MSXML2.XMLHTTP.3.0',  
            'MSXML2.XMLHTTP',  
            'Microsoft.XMLHTTP' 
        ]; 
        for ( var i=0, len = msxml.length; i < len; ++i ) { 
            try { 
                http = new ActiveXObject(msxml[i]); 
                break; 
            } 
            catch(e) {} 
        } 
    } 
    return function(method, uri, id2, callback, postData) { 
        http.open(method, uri, true); 
        handleReadyState(http, callback, id2); 
        http.send(postData || null); 
        return http; 
    }; 
}();


// меню
var menu_width=200;		// шинина субменю
function showMenu(obj, id_obj, position)
{
var menu=document.getElementById(id_obj);

if (menu.innerHTML!="")
	{
	menu.style.display='block';
	if (obj!=null) {
		if (position=='b') {
			menu.style.top=(obj.offsetTop+obj.offsetHeight)+'px';
			menu.style.left=(obj.offsetLeft)+'px';
			}
		if (position=='r') {
			menu.style.top=(obj.offsetTop)+'px';
			menu.style.left=(obj.offsetLeft+menu_width)+'px';
			}			
		}
	}
}

function hideMenu(id_obj)
{
var menu=document.getElementById(id_obj);
menu.style.display='none';
}
//конец меню

function refreshCaptcha()
{
var c=document.getElementById('captcha');
c.src='captcha.php?'+Math.ceil(Math.random()*10000);
}

function changeMeta(obj)
{
if (obj.checked) {
	document.getElementById('meta').style.display="block";
	} else {
	document.getElementById('meta').style.display="none";
	}
}


// КомбоБокс
var cmb_value="";
var cmb_hidden="";
var cmb_checked=false;
function ShowComboBox(obj)
{
if ((cmb_checked) && (cmb_value!="")) {
	cmb_value.style.display='none';
	cmb_checked=false;
	stop;
	}
	else
	{
	var cmb=obj.parentNode;
	for (var i=0; i<cmb.childNodes.length; i++)
		{
		if (cmb.childNodes[i].className=='cmb_value') {
			cmb_value=cmb.childNodes[i];
			}
		if (cmb.childNodes[i].className=='cmb_hidden') {
			cmb_hidden=cmb.childNodes[i];
			}
		}
	
	cmb_list=obj.getAttribute("cmb_list");
	cmb_value.innerHTML=createComboBoxValues(cmb_list, cmb_hidden.value);
	cmb_value.style.left=(obj.offsetLeft+1)+'px';
	cmb_value.style.top=(obj.offsetTop+obj.clientHeight+2)+'px';
	cmb_value.style.display='block';
	cmb_checked=true;
	}
	
return false;
}

function setComboBoxValue(obj, caption, value)
{
if (cmb_checked)
	{
	while(obj.parentNode.className!='cmb_value')
		{
		obj=obj.parentNode;
		}
	obj=obj.parentNode;
	cmb=obj.parentNode;
	for (var i=0; i<cmb.childNodes.length; i++)
		{
		if (cmb.childNodes[i].className=='cmb_caption') {
			var cmb_caption=cmb.childNodes[i];
			cmb_caption.value=caption;
			}	
		if (cmb.childNodes[i].className=='cmb_hidden') {
			var cmb_hidden=cmb.childNodes[i];
			cmb_hidden.value=value;
			break;
			}
		}
	if (cmb_value!="")
		{
		cmb_value.style.display='none';
		cmb_checked=false;
		}
	}
}

function createComboBoxValues(cmb_list, active)
{
var ret="";
var cmb_list_sub="";
var cmb_list_next="";

if (cmb_list!="")
	{
	cmb_list=cmb_list.substr(3);
	
	var caption=cmb_list.substr(0, cmb_list.indexOf('|:|'));
	cmb_list=cmb_list.substr(cmb_list.indexOf('|:|')+3);
	var value=cmb_list.substr(0, cmb_list.indexOf('|:|'));
	cmb_list=cmb_list.substr(cmb_list.indexOf('|:|')+3);
	
	cmb_list_sub=cmb_list.substr(0, cmb_list.indexOf('{|'+value+'}'));	
	cmb_list_next=cmb_list.substr(cmb_list.indexOf('{|'+value+'}')+value.length+3);	
	
	if (active==value) {
		ret="<div class='actitem' onClick='setComboBoxValue(this, \""+caption+"\",\""+value+"\");'>"+caption+createComboBoxValues(cmb_list_sub, active)+"</div>"+createComboBoxValues(cmb_list_next, active);
		} else {
		ret="<div class='item' onClick='setComboBoxValue(this, \""+caption+"\",\""+value+"\");'>"+caption+createComboBoxValues(cmb_list_sub, active)+"</div>"+createComboBoxValues(cmb_list_next, active);
		}	
	}
return ret;
}
