var xmlhttp=false;
var iadm=0;

if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	return null;
}

function refG() {
        el = document.getElementById('gtvg');
	el.innerHTML = "...обновляем...";
	document.getElementById('real').style.display = 'none';
	document.getElementById('sub').style.display = '';
	if (xmlhttp) {
		var docname = "/live/gtv.php";
		docname += "?ie_cache=" + get_random(100000);
		xmlhttp.open("GET", docname, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
	//				alert(xmlhttp.responseText);
					var xmldata = xmlhttp.responseXML;
					var root = xmldata.getElementsByTagName('el')[0].firstChild.nodeValue;;
					el.innerHTML = root;
					document.getElementById('real').style.display = '';
					document.getElementById('sub').style.display = 'none';
			}
		}
		xmlhttp.send(null);
	} else {
		el.innerHTML = "AJAX недоступен :(";
	}

}
function adm() {
	//fr = document.getElementById('center');
	fr = frames['center'];
	if (iadm>0) {
		fr.document.getElementById('edit').style.display = '';
	}
}

function login(id) {
	if (readCookie('Frag') == null) {
		return null;
	}
	el = document.getElementById(id);
	el.innerHTML = "... производится вход ...";
	if (xmlhttp) {
		var docname = "/live/ajax-login.php";
		docname += "?ie_cache=" + get_random(100000);
		xmlhttp.open("GET", docname, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
	//				alert(docname);//xmlhttp.responseText);
					var xmldata = xmlhttp.responseXML;
					var root = xmldata.getElementsByTagName('user')[0];
					uid = root.getElementsByTagName("id")[0].firstChild.nodeValue;
					if (uid > 0) {
						el.innerHTML = "<b>" + root.getElementsByTagName("name")[0].firstChild.nodeValue + "</b> &mdash; <a href='../../logout_live.php'><u>выйти</u></a>";
						iadm = root.getElementsByTagName("adm")[0].firstChild.nodeValue;
					} else {
						el.innerHTML = "";
					}
			}
		}
		xmlhttp.send(null);
	} else {
		el.innerHTML = "AJAX недоступен :(";
	}
}
function get_random(maxNum) {
	if (Math.random && Math.floor)
	{
		var ranNum= Math.floor(Math.random()*(maxNum));
		return ranNum;
	}
}

function refreshcom () {
	parent.frames.comment.window.location.reload();
}

function popUpcom(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=250,left = 465,top = 209');");
}
