	function  getEl(id){
		return document.getElementById(id);
	}
	var req;
	var el="";
	var ajaxfile='includes/ajax.php';
	function showBusyLayer() {
		var busyLayer = document.getElementById("busy_layer")
		if (busyLayer != null) {
			busyLayer.style.visibility = "visible";
			busyLayer.style.height = "2500px";
		}
		document.getElementById('loading-layer').style.display='block';
	}

	function hideBusyLayer() {
		var busyLayer = document.getElementById("busy_layer")
		if (busyLayer != null) {
			busyLayer.style.visibility = "hidden";
			busyLayer.style.height = "0px";
		}
		document.getElementById('loading-layer').style.display='none';
	}

	function loadXMLDoc(url) {
	    if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	        req.onreadystatechange = processReqChange;
	        req.open("GET", url, true);
	        req.send(null);
	    } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	        if (req) {
	            req.onreadystatechange = processReqChange;
	            req.open("GET", url, true);
	            req.send();
	        }
	    }
	}
	function processReqChange() {   
        showBusyLayer();
	    ab = window.setTimeout("req.abort()", 8000);
	    if (req.readyState == 4) {
	        clearTimeout(ab);

	        if (req.status == 200){
	        	if(el !=""){
	          		document.getElementById(el).innerHTML=req.responseText;
        			hideBusyLayer();
        		}
        		else{
        			hideBusyLayer();
        			alert(req.responseText);
        		}	        

	        }
	        else 
	            alert("Error! Please try again.");   
	    }  
       	hideBusyLayer();
	}
	function DisplayAjaxErrors(element_errors){
			element_errors="AJAX_ERRORS";
			if(!getEl(element_errors))
				window.setTimeout("DisplayAjaxErrors()", 1000);
			else{
				alert(getEl(element_errors).innerHTML);
			 getEl(element_errors).id='tmp';
		}

	}
	function sel_game(id,div,tr_race,tr_class,tr_other_games,div_class,race){
//alert('PPPPPPPPP');return false;
		if(id==0 && getEl(tr_race) && getEl(tr_class)) {
			 getEl(tr_race).style.display="none"; getEl(tr_class).style.display="none"; return false;}
		if(id==23 && getEl(tr_class) && getEl(tr_race)) {
			 getEl(tr_class).style.display="none"; getEl(tr_race).style.display="none";  getEl(tr_other_games).style.display=""; return false;}
		else if(id==0){
			getEl(div).innerHTML="<select name=\"race\"><option value=\"0\" selected>Любая</option></select>";
//			getEl(div).style.display="none";
			return false;
		}
		  getEl(tr_other_games).style.display="none";
		  getEl(tr_class).style.display="none";
		  getEl(tr_race).style.display="none";
		  
		getEl(div).style.display="";		

		el=div;	
		if(getEl(tr_race))
			getEl(tr_race).style.display="";
		get="?id="+id+"&race="+race+"&id_class="+div_class+"&tr_class="+tr_class+"&SELECT_RACE=1";		
		url=ajaxfile+get;
		loadXMLDoc(url);
	}
	function sel_class(id,div,tr_class,class_){
//		alert(id+'+'+div+'+'+tr_class);
		if(id==0 && getEl(tr_class)){ getEl(tr_class).style.display="none"; return false;}
		else if(id==0){
			getEl(div).innerHTML="<select name=\"class\"><option value=\"0\" selected>Любой</option></select>";
//			getEl(div).style.display="none";
			return false;
		}
		getEl(div).style.display="";		


		el=div;	
		if(getEl(tr_class))
			getEl(tr_class).style.display="";
		get="?id="+id+"&class="+class_+"&SELECT_CLASS=1";		
		url=ajaxfile+get;
		loadXMLDoc(url);
	}
	function addfavorite(id,fl){
		get="?id="+id+"&fl="+fl+"&ADD_FAVORITE=1";		
		url=ajaxfile+get;
		loadXMLDoc(url);
	
	}
	var iframe,id;	
	function sort(form1,i,ifr,url){
//		 alert(document.forms[form1]['gt'].value); return false;
		 form=document.forms[form1];
		 iframe=ifr;
		 g=document.forms[form1]['gt'].value;
		 get="?"+g+"&SORT=1";
	    		  form.setAttribute('action', url+get);
  	    showBusyLayer();
	    form.submit();
	    window.setTimeout("testiframefile()", 1000);
	   return false;
	}
	function testiframefile(){
		var cnt2=frames[iframe].document.getElementById('test_iframe');
	    if(!cnt2)  	 window.setTimeout("testiframefile()", 1000);
	    else {
			var doc=iframe.contentDocument;
			if (!doc && iframe.contentWindow) doc=iframe.contentWindow.document;
			if (!doc) doc=window.frames[iframe].document;
			if (!doc) return null;
			if (doc.location=="about:blank") return null;
			if (doc.XMLDocument) doc=doc.XMLDocument;
			var  div=doc.getElementById('cont');
			document.getElementById('content_appl').innerHTML=div.innerHTML;
//		    alert(div.innerHTML);
	 			  	 		frames[iframe].location='1.html';
		    hideBusyLayer();
		    return;
	    }
	}
	function add_comment(form1,i,ifr,url){
 //alert(document.forms[0].submit()); return false;
		 form=document.forms[form1];		 
		 iframe=ifr;
		 get="?ADD_COMMENT=1";
	    		  form.setAttribute('action', url+get);
  	    showBusyLayer();
	    form.submit();
	    window.setTimeout("testiframecom()", 1000);
	   return false;
	}
	function testiframecom(){
		var cnt2=frames[iframe].document.getElementById('test_iframe');
	    if(!cnt2)  	 window.setTimeout("testiframecom()", 1000);
	    else {
			var doc=iframe.contentDocument;
			if (!doc && iframe.contentWindow) doc=iframe.contentWindow.document;
			if (!doc) doc=window.frames[iframe].document;
			if (!doc) return null;
			if (doc.location=="about:blank") return null;
			if (doc.XMLDocument) doc=doc.XMLDocument;
			var  div=doc.getElementById('cont');
			var  error=doc.getElementById('error').innerHTML;
			if(error !=''){
				alert(error);
			    hideBusyLayer();
	 			  	 		frames[iframe].location='1.phtml';

				return false;
			}
			document.getElementById('all_content').innerHTML=div.innerHTML;
//	 			  	 		frames[iframe].location='1.phtml';
		    hideBusyLayer();
			alert("Ваш комментарий добавлен");
		    return;
	    }
	}
	function del_comm(div,id){
		el=div;	
		get="?id="+id+"&DELETE_COMMENT=1";		
		url=ajaxfile+get;
		loadXMLDoc(url);
		DisplayAjaxErrors(); // "AJAX_ERRORS" - ид элемента с ошибками!
	}

	
