//----------------------------------------------     Browser & Div      -------------------------------------------
function checkBrowser()
{
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}

bw=new checkBrowser()

function ShowOrHide(div,nest)
{
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	
	if (obj.display=='inline')
	{
		 obj.display='none';
	}
	else 
	{
		obj.display='inline';
	}	
}

function Show(div,nest)
{
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.display='inline'
}

function Hide(div,nest)
{
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.display='none'
}

//----------------------------------------------     Windows Open     -------------------------------------------
function WWopen(what,wx,wy)
{
	window.open(what,'windows','width='+wx+',height='+wy+',status=no,scrollbars=yes,location=no,toolbar=no,resizable=no');
}
function Copen()
{
	window.open('chat/chatroom.asp','Chat','width=600,height=470,status=no,scrollbars=no,location=no,toolbar=no,resizable=no');
}
function sendfriend(id)
{
	WWopen("send_invite.asp?id="+id,510,280);
}
function sendstaff(id)
{
	WWopen("send_abuse.asp?id="+id,510,320);
	
}
function WopenFix(what)
{
	WWopen("_showimg.asp?img=" + what ,680,690);
	
}

//----------------------------------------------     Varie     -------------------------------------------
function PutValue(v)
{
	if(v==1 && document.data.luia.selectedIndex==63){document.data.luia.selectedIndex=document.data.luida.selectedIndex}	
	if(v==2 && document.data.leia.selectedIndex==63){document.data.leia.selectedIndex=document.data.leida.selectedIndex}
}

function go() 
{
	Hide("Upload");
	Show("Wait");
	setTimeout("document.formdata.submit();", 500);
}

function checklenSubmit(data,max)
{
	var	dax=data.value.substring(0,max-1);
	if (data.value.length>max) 
	{
		data.value=dax
		alert('Raggiunto numero massimo di caratteri');
	}
	else
	{
		document.form1.submit();
	}
}

function checklen(data,max)
{
	var	dax=data.value.substring(0,max-1);
	if (data.value.length>max) 
	{
		data.value=dax
		alert('Raggiunto numero massimo di caratteri');
	}
}


//----------------------------------------------     Controllo Input      -------------------------------------------
function check (field, kind)
{
	var e = 0,i,schar,found,Rchars,a='',appfield;
	switch (kind){
		case 0:Rchars = "abcdefghilmnopqrstuvzwxykj.@_-1234567890";break;//email
   		case 1:Rchars = "abcdefghilmnopqrstuvzwxykj ";break; // string
   		case 2:Rchars = "1234567890";break;//number
   		case 3:Rchars = "abcdefghilmnopqrstuvzwxykj1234567890,. ";break;//address
   		case 4:Rchars = "abcdefghilmnopqrstuvzwxykj1234567890";break;//Utente
		default: break;}
		appfield=field.value.toLowerCase();
		for (i=0;i<field.value.length;i++)	{
			schar =appfield.charAt(i);
			found=Rchars.indexOf(schar);
			if (found==-1){e=1;}else{a += schar;}
		}
		if (e==1){
			field.value=a;field.focus();
			return(false);
		}
	return(true);
}

function checkemail (field)
{
	var e=false,apos,dotpos,lastpos;
	e=check(field, 0);
	if (field.value!="" || e==true){
		apos=field.value.indexOf("@");
		dotpos=field.value.lastIndexOf(".");
		lastpos=field.value.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) e=false;
	}
	if (e==false && field.value!=""){
		alert ('indirizzo email inserito non valido');
        field.focus();
	}
	return(e)
}


function checkit(n)
{
	if (n==1) globalcheck1();
	if (n==2) globalcheck2();
	if (n==3) globalcheck3();
	if (n==4) globalcheck4();
	if (n==5) globalcheck5();
}

//----------------------------------------------     Ajax      -------------------------------------------

function sendCMD(scrtp,data)
{	
	var myAjax = new Ajax.Request(scrtp,{method: 'post',parameters: data,onComplete: sResponse});
}

function sResponse(ajobj) 
{

	  if (ajobj.readyState == 4) 
	  {
			
			if(ajobj.status == 200)
			{
				 ElabResults(ajobj.responseText);
			} 
			else 
			{
				ShowMessage("ERROR:" + ajobj.status);
			}
	  }
	  
}

function GetMouse(e)
{
	//posx=0;posy=0;
	var ev=(!e)?window.event:e;//IE:Moz

	if (ev.pageX)
	{//Moz
		mousex=ev.pageX;//+window.pageXOffset;
		mousey=ev.pageY;//+window.pageYOffset;
	}
	else if(ev.clientX){//IE
		mousex=ev.clientX+document.body.scrollLeft;
		mousey=ev.clientY+document.body.scrollTop;
	}
	else{return false}//old browsers

	return(mousey);
	//document.getElementById('msg').innerHTML='X='+mousex+' Y='+mousey;
}

function ShowMessage(msg,yy)
{
		//if (yy==null){document.getElementById('msg').style.height='100px';} else {document.getElementById('msg').style.height=yy+'px';}
		document.getElementById('msgbody').innerHTML="<BR><B>"+msg+"</B>";
		//document.getElementById('msg').style.top=GetMouse-100;	
		Show("msg");
		//document.getElementById('msg').style.top=100;
	
}

function ShowMessageLang(idmsg,yy)
{
		var mms;
		mms=MessageLang(idmsg);
		
		if (yy==null){document.getElementById('msg').style.height='100px';} else {document.getElementById('msg').style.height=yy+'px';}
		document.getElementById('msg').innerHTML="<BR><div align=center>"+mms+"<BR><input class='bottone' type='button' name='Ok' value='Ok' onclick=Hide('msg'); ></div>"
		Show("msg");
	
}

function Jrun(ContDiv,cmd,cmdata,postAct,param1,param2,param3)
{
	var bckDiv='';
	var datafrom='';
	if (cmdata){datafrom=Form.serialize(cmdata)}
	
 	if (document.getElementById(ContDiv))
	 {
	  bckDiv=document.getElementById(ContDiv).innerHTML;
	  document.getElementById(ContDiv).innerHTML='<img src="../img/load.gif" alt="Loading.." align="absmiddle"/>';
	 }
	
	if (cmd)
	{
		new Ajax.Request(cmd,
		{
			method: 'post',parameters: datafrom,onSuccess: function(results)
			{
				switch (postAct)
				{
					case 0: 
						document.getElementById(ContDiv).innerHTML='<img src="'+param1+'" align="absmiddle" />';
						break;
					case 1://swap div
						Hide(ContDiv);
						Show(param1); 	 
						break;
					case 2://Ri visualizza bottone e lo disabilita
						//alert(results.responseText);
						document.getElementById(ContDiv).innerHTML=bckDiv;
						document.getElementById(param1).disabled=true;
						break;
					case 4://Sostituisce con param1
						//alert("pausa");
						document.getElementById(ContDiv).innerHTML=param1;
						break;
					case 5://Sostituisce con responseText
						//alert("pausa");
						document.getElementById(ContDiv).innerHTML=results.responseText;
						break;
					case 6://carica pagina al posto di div da response text
						//alert("pausa");
						window.location.href = results.responseText;
						break;
				}	
			}
		,onFailure: ShowMessage
		});
	}
}
