function IsNumber(Expression)
{
    Expression = Expression.toLowerCase();
    RefString = "0123456789";
    
    if (Expression.length < 1) 
        return (false);
    
    for (var i = 0; i < Expression.length; i++) 
    {
        var ch = Expression.substr(i, 1);
        var a = RefString.indexOf(ch, 0);
        if (a == -1)
            return (false);
    }
    return(true);
}

function agent(){
	var ievs = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
	if(ievs){
		var text = '<link rel="stylesheet" type="text/css" href="share/iefix.css">';
	}
	else{
		var text = '';
	}
	document.write(text);
	return true;
}

function clock() {
var x=new Date();
h=x.getHours();
m=x.getMinutes();
s=x.getSeconds();



if(s<=9) s="0"+s;
if(m<=9) m="0"+m;
if(h<=9) h="0"+h;
time="<h4>Su Aseryan sono le: "+h+":"+m+":"+s+"</h4>";
document.getElementById('orologio').innerHTML=time;
setTimeout("clock()",1000);
}

function timebusy(pausa,back) {
h=0;
m=0;
s=pausa;

while(s>=60){
m=m+1;
s=s-60;
}

while(m>=60){
h=h+1;
m=m-60;
}

if(s<=9) s="0"+s;
if(m<=9) m="0"+m;
if(h<=9) h="0"+h;

if (h>0) ora=h+":"+m+":"+s;
else ora=m+":"+s;
titolo=ora+" - Elentian Chronicles";
//time="<center><h5>Sei Impegnato</h5>Potrai compiere una nuova azione tra: "+ora+" </center></h4>";
time="<center>Potrai compiere una nuova azione tra: "+ora+" </center></h4>";
document.getElementById('luogo').innerHTML=time;
document.title=titolo;
if(pausa>0){
setTimeout("timebusy("+(pausa-1)+","+"'"+back+"'"+")",1000);
}
else{
//location.href = "ec.php?page="+back;
}

}

function avviso(msg) {
messaggio="<center><h5>Avviso</h5>"+msg+"</center>";
document.getElementById('advice').innerHTML=messaggio;
document.getElementById('advice').style.opacity=100;
setTimeout("avvisohide()",1000);

}


function avvisohide() {

alpha=document.getElementById('advice').style.opacity-10;
document.getElementById('advice').style.opacity=alpha*0.1;
document.getElementById('advice').style.filter = 'alpha(opacity=' + alpha + ')';
//document.getElementById('advice').destroy();
setTimeout("avvisohide()",2000);
}

function allmsg(tot){

var modulo = document.messaggi.elements;
    for (i=0; i<modulo.length; i++)
    {
        if(modulo[i].type == "checkbox")
        {
            modulo[i].checked = document.messaggi.all.checked;
        }
    }
}

function timer(pausa,back,dest) {
g=0;
h=0;
m=0;
s=pausa;

while(s>=60){
m=m+1;
s=s-60;
}

while(m>=60){
h=h+1;
m=m-60;
}

while(h>=24){
g=g+1;
h=h-24;
}

if(s<=9) s="0"+s;
if(m<=9) m="0"+m;
if(h<=9) h="0"+h;
if(g>1) g=g+" giorni e ";
if(g==1) g=g+" giorno e ";
if(g==0) g="";

ora=g+h+":"+m+":"+s;

time=ora;
//titolo=ora+" - Elentian Chronicles";
document.getElementById(dest).innerHTML=time;
//document.title=titolo;
if(pausa>0){
setTimeout("timer("+(pausa-1)+","+"'"+back+"'"+",'"+dest+"')",1000);
}
else{
location.href = "ec.php?page="+back;
}

}

function auction_timer(pausa,dest) {
g=0;
h=0;
m=0;
s=pausa;

while(s>=60){
m=m+1;
s=s-60;
}

while(m>=60){
h=h+1;
m=m-60;
}

while(h>=24){
g=g+1;
h=h-24;
}

if(s<=9) s="0"+s;
if(m<=9) m="0"+m;
if(h<=9) h="0"+h;
if(g>1) g=g+" giorni e ";
if(g==1) g=g+" giorno e ";
if(g==0) g="";

ora=g+h+":"+m+":"+s;
document.getElementById(dest).innerHTML=ora;

if(pausa>0){
setTimeout("auction_timer("+(pausa-1)+",'"+dest+"')",1000);
}
else{
location.href = "ec.php?page=Mercante9";
}

}






function magicboxactive(count, maxbet){
bet=document.getElementsByName("bet")[0].value;

if((IsNumber(bet)==false)||(bet<1)){
alert("La puntata deve essere un numero");
return false;
}

if(bet>maxbet){
alert("Non disponi di fondi sufficienti");
return false;
}

if(bet<=0){
alert("Devi puntare una somma valida");
return false;
}

document.getElementsByName("bet")[0].disabled=true;;
text="<img id=box1 src=img/azzardo/scatola.png onclick='magicboxopen(box1,"+count+")'>";
text=text+"<img id=box2 src=img/azzardo/scatola.png onclick='magicboxopen(box2,"+count+")'>";
text=text+"<img id=box3 src=img/azzardo/scatola.png onclick='magicboxopen(box3,"+count+")'>";
text=text+"<img id=box4 src=img/azzardo/scatola.png onclick='magicboxopen(box4,"+count+")'>";
text=text+"<img id=box5 src=img/azzardo/scatola.png onclick='magicboxopen(box5,"+count+")'>";
text=text+"<form name=magicbox action='ec.php?page=esitomagicbox' method='post'><input type=hidden name=bet value="+bet+"><input type=hidden name=box value=''>";

document.getElementById('magicboxcontainer').innerHTML=text;



}

function magicboxopen(ids,count){
/*
if((count%300==0)&&(count>0)){
	mod="jack";
}
else{
	num=Math.random()*100;
	if(num>=80){
		mod="piena";
	}
	if((num<80)&&(num>=60)){
		mod="mezza";
	}
	if(num<60){
		mod="vuota";
	}
}

text="<img id=box1 src=img/azzardo/scatola.png>";
text=text+"<img id=box2 src=img/azzardo/scatola.png>";
text=text+"<img id=box3 src=img/azzardo/scatola.png>";
text=text+"<img id=box4 src=img/azzardo/scatola.png>";
text=text+"<img id=box5 src=img/azzardo/scatola.png>";
text=text+"<form name=magicbox action='ec.php?page=esitomagicbox' method='post'><input type=hidden name=bet value="+bet+"><input type=hidden name=box value=''>";

document.getElementById('magicboxcontainer').innerHTML=text;
document.getElementById(ids.id).src="img/azzardo/scatola"+mod+".png";
document.getElementsByName("box")[0].value=mod;
setTimeout("magicbox.submit()",1000);
*/
setTimeout("magicbox.submit()",1000);
}

function diceactive(count, maxbet){
bet=document.getElementsByName("bet")[0].value;

if((IsNumber(bet)==false)||(bet<1)){
alert("La puntata deve essere un numero");
return false;
}

if(bet>maxbet){
alert("Non disponi di fondi sufficienti");
return false;
}

if(bet<=0){
alert("Devi puntare una somma valida");
return false;
}

document.getElementsByName("bet")[0].disabled=true;;
text="<img id=dice1 src=img/azzardo/dado1.png onclick='diceselect(1,"+count+")'>";
text=text+"<img id=dice2 src=img/azzardo/dado2.png onclick='diceselect(2,"+count+")'>";
text=text+"<img id=dice3 src=img/azzardo/dado3.png onclick='diceselect(3,"+count+")'><br>";
text=text+"<img id=dice4 src=img/azzardo/dado4.png onclick='diceselect(4,"+count+")'>";
text=text+"<img id=dice5 src=img/azzardo/dado5.png onclick='diceselect(5,"+count+")'>";
text=text+"<img id=dice6 src=img/azzardo/dado6.png onclick='diceselect(6,"+count+")'><br>";
text=text+"<img id=dicep src=img/azzardo/dadop.png onclick='diceselect("+'"p"'+","+count+")'>";
text=text+"<img id=diced src=img/azzardo/dadod.png onclick='diceselect("+'"d"'+","+count+")'>";
text=text+"<form name=diceform action='ec.php?page=esitodice1' method='post'><input type=hidden name=bet value="+bet+"><input type=hidden name=dice value=''>";

document.getElementById('dicecontainer').innerHTML=text;
}

function diceselect(ids,count){
document.getElementsByName("dice")[0].value=ids;
setTimeout("diceform.submit()",10);
}

function prezzo_tot(id, monete, action, max_monete, max_q){
	var q=document.getElementById("q"+action+"_"+id);
	var p=document.getElementById("p"+action+"_"+id);
	var bottone=document.getElementById("ok"+action+"_"+id);
	//alert(bottone.id);
	if((IsNumber(q.value))||(q.value=='')){
		p.innerHTML=q.value*monete;
		
		if((q.value>max_q)||((q.value*monete)>max_monete)){
			bottone.disabled=true;
		}
		else{
			bottone.disabled=false;
		}
		
	}
	else{
		alert("Il valore inserito non è valido");
		q.value=1;
		p.innerHTML=monete;
		bottone.disabled=false;
	}
	
}