 ns4 = (document.layers) ? 1:0;  
 ie4 = (document.all)    ? 1:0;
 
//alert(ns4 + "-" + ie4 );
//----------------------------------------------     Layer     -------------------------------------------
function Show(layer)
{
	if (ns4) { document.layers[layer].display="inline"; }
    if (ie4) { document.all[layer].style.display="inline"; }
}

function Hide(layer)
{
	if (ns4) { document.layers[layer].display="none"; }
    if (ie4) { document.all[layer].style.display="none"; }
} 

//----------------------------------------------     Windows Open     -------------------------------------------
function WWopen(what,wx,wy)
{
	window.open(what,'windows','width='+wx+',height='+wy+',status=no,scrollbars=no,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 WopenFix(what)
{
	WWopen("_showauto.asp?img=" + what ,306,607);
	
}

//----------------------------------------------     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 checklen(data,max)
{
	var	dax=data.value.substring(0,max-1);
	if (data.value.length>max-1) 
	{
		data.value=dax
		alert('Raggiunto numero massimo di caratteri');
	}
}
		 
function msgassembler(layer)
{
	var msg='';	
	for(i=0;i<document.data.elements.length-1;i++)
	{
		msg= msg + document.data.elements[i].name + ":  " + document.data.elements[i].value + '<BR>';
	}
	
	document.data.msg.value=msg;
	document.data.submit();
}

//----------------------------------------------     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)
}

