/*
Ceres Control Panel

This is a control pannel program for Athena and Freya
Copyright (C) 2005 by Beowulf and Nightroad

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

To contact any of the authors about special permissions send
an e-mail to cerescp@gmail.com
*/

function LINK_ajax(http,div_name){var LINK_xmlhttp=false;try{LINK_xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{LINK_xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){try{LINK_xmlhttp=new XMLHttpRequest();}
catch(e){LINK_xmlhttp=false;}}}
if(!LINK_xmlhttp)return null;document.getElementById('load_div').style.visibility="visible";LINK_xmlhttp.open("GET",http,true);LINK_xmlhttp.onreadystatechange=function(){if(LINK_xmlhttp.readyState==4){document.getElementById('load_div').style.visibility="hidden";if(LINK_xmlhttp.responseText.indexOf("<script type=\"text/javascript\">")>-1){var x=LINK_xmlhttp.responseText.indexOf("<script type=\"text/javascript\">")+"<script type=\"text/javascript\">".length;var y=LINK_xmlhttp.responseText.indexOf("</script>")-x;eval(LINK_xmlhttp.responseText.substr(x,y));}
if(LINK_xmlhttp.responseText.indexOf('ALERT|')>-1){var x=LINK_xmlhttp.responseText.indexOf('ALERT|')+"ALERT|".length;var y=LINK_xmlhttp.responseText.indexOf('|ENDALERT')-x;window.alert(LINK_xmlhttp.responseText.substr(x,y));}else
document.getElementById(div_name).innerHTML=LINK_xmlhttp.responseText+' ';}}
LINK_xmlhttp.send(null);return false;}
function POST_ajax(http,div_name,frm_name){var POST_xmlhttp=false;var frm=false
var url="";try{POST_xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{POST_xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){try{POST_xmlhttp=new XMLHttpRequest();}
catch(e){POST_xmlhttp=false;}}}
if(!POST_xmlhttp)return null;frm=document.getElementById(frm_name);document.getElementById('load_div').style.visibility="visible";url="frm_name="+frm_name;for(i=0;i<frm.elements.length;i++){frm.elements[i].disabled=true;if(frm.elements[i].type=="checkbox"){if(frm.elements[i].checked)
frm.elements[i].value=1;else
frm.elements[i].value=0;}
url=url+"&"+frm.elements[i].name+"="+escape(frm.elements[i].value);}
POST_xmlhttp.open("POST",http,true);POST_xmlhttp.onreadystatechange=function(){if(POST_xmlhttp.readyState==4){document.getElementById('load_div').style.visibility="hidden";for(i=0;i<frm.elements.length;i++){if(frm.elements[i].type=="checkbox")
frm.elements[i].checked=false;if(frm.elements[i].type=="password")
frm.elements[i].value="";frm.elements[i].disabled=false;}
if(POST_xmlhttp.responseText.indexOf("<script type=\"text/javascript\">")>-1){var x=POST_xmlhttp.responseText.indexOf("<script type=\"text/javascript\">")+"<script type=\"text/javascript\">".length;var y=POST_xmlhttp.responseText.indexOf("</script>")-x;eval(POST_xmlhttp.responseText.substr(x,y));}
if(POST_xmlhttp.responseText.indexOf('ALERT|')>-1){var x=POST_xmlhttp.responseText.indexOf('ALERT|')+"ALERT|".length;var y=POST_xmlhttp.responseText.indexOf('|ENDALERT')-x;window.alert(POST_xmlhttp.responseText.substr(x,y));}else
document.getElementById(div_name).innerHTML=POST_xmlhttp.responseText+' ';}}
POST_xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");POST_xmlhttp.setRequestHeader("Content-length",url.length);POST_xmlhttp.setRequestHeader("Connection","close");POST_xmlhttp.send(url);return false;}
function GET_ajax(http,div_name,frm_name){var GET_xmlhttp=false;var frm=false
var url="";try{GET_xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{GET_xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){try{GET_xmlhttp=new XMLHttpRequest();}
catch(e){GET_xmlhttp=false;}}}
if(!GET_xmlhttp)return null;frm=document.getElementById(frm_name);document.getElementById('load_div').style.visibility="visible";url=http+"?frm_name="+frm_name;for(i=0;i<frm.elements.length;i++){frm.elements[i].disabled=true;if(frm.elements[i].type=="checkbox"){if(frm.elements[i].checked)
frm.elements[i].value=1;else
frm.elements[i].value=0;}
url=url+"&"+frm.elements[i].name+"="+escape(frm.elements[i].value);}
GET_xmlhttp.open("GET",url,true);GET_xmlhttp.onreadystatechange=function(){if(GET_xmlhttp.readyState==4){document.getElementById('load_div').style.visibility="hidden";for(i=0;i<frm.elements.length;i++){if(frm.elements[i].type=="checkbox")
frm.elements[i].checked=false;if(frm.elements[i].type=="password")
frm.elements[i].value="";frm.elements[i].disabled=false;}
if(GET_xmlhttp.responseText.indexOf("<script type=\"text/javascript\">")>-1){var x=GET_xmlhttp.responseText.indexOf("<script type=\"text/javascript\">")+"<script type=\"text/javascript\">".length;var y=GET_xmlhttp.responseText.indexOf("</script>")-x;eval(GET_xmlhttp.responseText.substr(x,y));}
if(GET_xmlhttp.responseText.indexOf('ALERT|')>-1){var x=GET_xmlhttp.responseText.indexOf('ALERT|')+"ALERT|".length;var y=GET_xmlhttp.responseText.indexOf('|ENDALERT')-x;window.alert(GET_xmlhttp.responseText.substr(x,y));}else
document.getElementById(div_name).innerHTML=GET_xmlhttp.responseText+' ';}}
GET_xmlhttp.send(null);return false;}
function server_status(){LINK_ajax('server_status.php','status_div');setTimeout("server_status()",120000);}
function login_status(){LINK_ajax('login.php','login_div');setTimeout("login_status()",60000);}
function chat_win(){LINK_ajax('chat.php','main_div'); chattimer = setTimeout("chat_win()",5000);}
function chat_bar(){LINK_ajax('bar_chat.php','menu_load');}
function chat_bar_close(){ LINK_ajax('empty.php','menu_load');}
function login_hide(x_y){if(x_y==1)
document.getElementById('new_div').style.visibility="visible";else if(x_y==0)
document.getElementById('new_div').style.visibility="hidden";else if(x_y==2)
LINK_ajax('middle.php','new_div');}
function load_menu(){var script=document.getElementById('menu_script');if(script){script.parentNode.removeChild(script);}
script=document.createElement('script');script.id="menu_script";script.type="text/javascript"
script.src="menu.php?rand="+Math.random();var head=document.getElementsByTagName('HEAD')[0];head.appendChild(script);}
function force(item_name,frm_name,e){var keynum;if(window.event)
keynum=e.keyCode;else if(e.which)
keynum=e.which;if(keynum==13){var frm=false;var i=0;var j=0;frm=document.getElementById(frm_name);for(i=0;i<frm.elements.length;i++){if(item_name==frm.elements[i].name){if(frm.elements[i+1].type=="submit"){for(j=0;j<frm.elements.length;j++){if(frm.elements[j].type=="checkbox")
continue;if(frm.elements[j].value==''){frm.elements[j].focus();return false;}}}
while(frm.elements[i+1]){if(frm.elements[i+1].type!="hidden"){frm.elements[i+1].focus();return false;}
i++;}}}}
return true;}
function  hide_language(x_y){if(x_y==1)
document.getElementById('sel_language').style.visibility="visible";else if(x_y==0)
document.getElementById('sel_language').style.visibility="hidden";else if(x_y==2)
LINK_ajax('selectlang.php','sel_language');}

function countit(what,num,idvalore){
id = idvalore;
formcontent=what.form.contbox.value;
what.form.displaycount.value=(num-formcontent.length);
}

function showitem(title){
	if(document.getElementById(title).style.display == "none")
		document.getElementById(title).style.display = "inline";
	else
		document.getElementById(title).style.display = "none";
}

function calcola_euro(euro,idcheckbox){
		var calc_euro = document.getElementById("campoeuro").value;
		var euro;
	
		calc_euro = parseFloat(calc_euro);
		euro = parseFloat(euro);		
	
		if(document.getElementById(idcheckbox).checked==true){
		
			calculate = calc_euro+(euro/100);
			searchlength = String(calculate);

			if(searchlength.length > 5)
				calculate = parseInt(calculate)+1;
		
			document.getElementById("campoeuro").value = calculate;
			if(document.getElementById("campoeuro").value > 100)
				alert('Non esagerare con le donazioni!');
		} else {
			calculate = calc_euro-(euro/100);
			searchlength = String(calculate);

			if(searchlength.length > 5)
				calculate = parseInt(calculate)-1;
			document.getElementById("campoeuro").value = calculate;
		}
		
		if(document.getElementById("campoeuro").value < 1)
		{
			document.getElementById("campoeuro").value = 0;
			document.getElementById("donate_push").style.visibility = "hidden";
		} else {
			document.getElementById("donate_push").style.visibility = "visible";
		}

		
}

	/* Serve per sottolineare le parole */
	var testval;
	function tellword(){
		if(document.getElementById("inputs").value){
			testval = document.getElementById("inputs").value;
			for(var i=0; i<document.getElementById("counter").value; i++)
				document.getElementById(i).innerHTML=document.getElementById(i).innerHTML.replace( document.getElementById("inputs").value, "<span style='background: yellow;'>"+document.getElementById("inputs").value+"</span>");
		}
	}
	
	function tellword2(){
		if(testval){
			for(var i=0; i<document.getElementById("counter").value; i++)	
				document.getElementById(i).innerHTML=document.getElementById(i).innerHTML.replace( "<span style=\"background: yellow;\">"+testval+"</span>", testval);
			testval = "";
		}
	}
	
	/* Sottolinea gli id */
	function makeword(){
		var base;
		var str;
		var s=0;

		
		if(document.getElementById("inputs").value){
			for(var i=0; i<document.getElementById("counter").value; i++){

				base = document.getElementById(i).innerHTML;
				base = base.toUpperCase();
				inputs = document.getElementById("inputs").value;
				str = base.search(inputs.toUpperCase());
				if(str!=-1){
					s++;
					document.getElementById(i).style.backgroundColor = "#686464";
					document.getElementById("signcount").innerHTML = "Found "+s;
				}
			}
		}
	}
	
	function makeword2(){
			for(var i=0; i<document.getElementById("counter").value; i++)	
				document.getElementById(i).style.backgroundColor = "Transparent";
				
			document.getElementById("signcount").innerHTML = "";
	}
	
function hideItem(idItem){
if(document.getElementById(idItem).style.display != 'none') document.getElementById(idItem).style.display = 'none'; else document.getElementById(idItem).style.display = 'inherit';
return;
}

function TimeCalcBack(houri,mini,seci,idname){
var type;
var dayi;
var hour;
type = document.getElementById(idname);

		dayi = houri / 24;

		hour = houri;
		while(hour > 24){
			hour -= 24;
		}
			
		seci = seci - 1;
		if(seci < 0){
			seci = 59;
			mini = mini - 1;
		}
		
		if(mini < 0){
			mini = 59;
			hour = hour - 1;
			houri = houri - 1;
		}
		
		if(hour < 0){
			hour = 23;
			dayi = dayi - 1;
		}
		
		
		if(houri < 0)
			return type.innerHTML="Finish!";
				
		if (seci < 10)
			sec0 = "0";
		else
			sec0 = "";
		if (mini < 10)
			min0 = "0";
		else
			min0 = "";
						
				DinaHeure = "Day [" + parseInt(dayi,10) + "] " + hour + ":" + min0 + mini + ":" + sec0 + seci;
		which = DinaHeure
		if (type){
			type.innerHTML=which;
		}
	setTimeout("TimeCalcBack("+houri+","+mini+","+seci+",'"+idname+"')",1000);
}
