
var adminUrl = "adminchat/admin_write.php";
var chatdiv = document.getElementById('admin_chat');
var newdiv = document.getElementById('new_chat');

var t;
var t2;

function PopMoreSmiles2(form,name) {
         newWin2=window.open('index.php?page=moresmiles&form='+form+'&text='+name,'moresmile','height=500,width=450,resizable=yes,scrollbars=yes');
         if (window.focus) {newWin2.focus()}
}

function swap_chat() {
	var disp = document.getElementById("a_chat_content");
	if (disp.style.display == 'none') {
		Effect.toggle('a_chat_content', 'slide');
		newdiv.innerHTML = '';
		setCookie('chat_mode','block','0x7fffffff');
		chatdiv.innerHTML='<div style="width:100%; text-align:center;"><img src="http://avatar-bg.org/images/loading2.gif" ></div>' + chatdiv.innerHTML;
		makeRequestAdminChat('new');
		clearTimeout(t2);
	} else {
		Effect.toggle('a_chat_content', 'slide');
		clearTimeout(t);
		setCookie('chat_mode','none','0x7fffffff');
		newAdminChat();
	}
}

var AdminhandleSuccess = function(o){
	if(o.responseText !== undefined){
		chatdiv.innerHTML = o.responseText;
		clearTimeout(t);
		t=setTimeout('makeRequestAdminChat(\'refresh\');',15000);
//makeRequestAdminChatR();
	}
}

var AdminhandleFailure = function(o){
	if(o.responseText !== undefined){
	}
}

function makeRequestAdminChat(p){
	var request = YAHOO.util.Connect.asyncRequest('GET', adminUrl+'?'+p,
            {
                success: AdminhandleSuccess,
                failure: AdminhandleFailure,
		  cache:false 
            }
        );
}

var newSuccess = function(o){
	if(o.responseText !== undefined){
		newdiv.innerHTML = o.responseText;
		clearTimeout(t2);
		t2=setTimeout('newAdminChat();',30000);
	}
}

var newFailure = function(o){
	if(o.responseText !== undefined){
	}
}

function newAdminChat(){
	var request = YAHOO.util.Connect.asyncRequest('GET', adminUrl+'?only_new',
            {
                success: newSuccess,
                failure: newFailure,
		  cache:false 
            }
        );
}

function sendCommenta() {
    ChatText = encodeURIComponent(document.forms['admin_chat_form'].elements['chatbarTexta'].value);
    if (ChatText != '') {
        adminName = encodeURIComponent(document.forms['admin_chat_form'].elements['namea'].value);
        adminUid = document.forms['admin_chat_form'].elements['uida'].value;
        adminPrefix = encodeURIComponent(document.forms['admin_chat_form'].elements['prefixa'].value);
        adminSuffix = encodeURIComponent(document.forms['admin_chat_form'].elements['suffixa'].value);
        var p = 'an='+ adminName+'&ac='+ ChatText+'&au='+ adminUid+'&ap='+ adminPrefix+'&as='+ adminSuffix; 
	makeRequestAdminChat(p);
    document.forms['admin_chat_form'].elements['chatbarTexta'].value = '';
    }
//alert (ChatText + '    ' + p);
}

function del_a_comment(id) {
	var t='delete='+id;
	makeRequestAdminChat(t);

}

 function admin_history() {
var ur='adminchat/admin_write.php?all';

try {
	var w=Windows.getWindow('ADMIN_HISTORY').getId();
}
 catch(err) {
		win = new Window({id:'ADMIN_HISTORY',
			className: 'alphacube', title: 'ИСТОРИЯ НА ЧАТА НА ЕКИПА', width:350,height: 450,
			minimizable:false, maximizable: false, destroyOnClose: true,
			url: ur
		});
		win.showCenter();

	}
}

var cook=getCookie('chat_mode');
if (cook=='block')
	makeRequestAdminChat('new');
else
	newAdminChat();


