//-------POPUP PRIVACY
function WinOpenPrivacy() {
   msgWindow=window.open( 'privacy.asp','JavaScriptIt', 'toolbar= no,width=668,height=450,left=5,top=5,location= no,directories= no,status= no,menubar= yes,scrollbars= yes,resizable= no,copyhistory= no');
}
//-------POPUP HELP IP
function WinOpenHelpIP() {
   msgWindow=window.open( 'iphelp.asp','JavaScriptIt', 'toolbar= no,width=668,height=450,left=5,top=5,location= no,directories= no,status= no,menubar= yes,scrollbars= yes,resizable= no,copyhistory= no');
}
//POPUP AUTORI
function WinOpenFile(C) {
msg=open(C,'','toolbar= no,width=350,height=250,left=10,top=10,location= no,directories= no,status= no,menubar= no,scrollbars= yes,resizable= no,copyhistory= no');
}
//------------ CONVALIDA EMAIL
function isEmail(data)
{
				var thisChar;
				var OK1=0;
				var OK2=0;
				for (var i=1; i < (data.length-2); i++)
					{
					thisChar = data.substring(i, i+1);
					if (thisChar == "@") {
											OK1=1
											break;
										  }
					
					}
				if ((OK1==1) && (data.substring(i+1,i+2)!="."))
								{
								data = data.substring(i+2,data.length);
								 // alert(data);
								data = data.substring(data.length-4,data.length-2);
								// alert(data);
								for (var u=0; u < (data.length); u++)
										{
										thisChar = data.substring(u, u+1);
										// alert(thisChar);
										if (thisChar == ".") OK2=1;					
										}				
								if (OK2==1) return true;
								}
				return false
}


//-----CONVALIDA NUMERO - PIVA
function isNumber(data)
{
	var numStr="0123456789-+,";
	var thisChar;
	var counter = 0;
	for (var i=0; i < data.length; i++)
		{
		thisChar = data.substring(i, i+1);
		if (numStr.indexOf(thisChar) != -1) counter++;
		}
	if (counter != data.length) {return false;}
//	if (data.length < 11) {return false;}
	
	return true
}
//---------REGISTRA
function check_registra(objForm) {
with (objForm) {
		if (NOME.value.length < 1){
			alert("Attention, insert First Name");
			NOME.focus();
			return false
		}
		if (COGNOME.value.length < 1){
			alert("Attention, insert Last Nme");
			COGNOME.focus();
			return false
		}
		if (EMAIL.value.length < 1){
			alert("Attention, insert a valid Email");
			EMAIL.focus();
			return false
		}
		if (EMAIL.value.length > 0) {
				if (!isEmail(EMAIL.value)) {
					alert("Attention, insert a valid Email");
					EMAIL.focus();
					return false
					}
		}
		if (REMAIL.value.length < 1){
			alert("Attention, insert a valid Email");
			REMAIL.focus();
			return false
		}
		if (REMAIL.value.length > 0) {
				if (!isEmail(REMAIL.value)) {
					alert("Attention, insert a valid Email");
					REMAIL.focus();
					return false
					}
		}		
		if (TELEFONO.value.length > 0){
				if(!isNumber(TELEFONO.value)){
					alert("Attention, insert a Phone Number ");
					TELEFONO.focus();
					return false
				}
		}
		if (FAX.value.length > 0){
				if(!isNumber(FAX.value)){
					alert("Attention, insert a Fax Number ");
					FAX.focus();
					return false
				}
		}

	}
return true
}

//---------PROFILO
function check_profilo(objForm) {
with (objForm) {
		if (ENTE.value.length < 1){
			alert("Attention, insert institution");
			ENTE.focus();
			return false
		}
		if (NOME.value.length < 1){
			alert("Attention, insert First Name");
			NOME.focus();
			return false
		}
		if (EMAIL.value.length < 1){
			alert("Attention, insert a valid Email");
			EMAIL.focus();
			return false
		}
		if (EMAIL.value.length > 0) {
				if (!isEmail(EMAIL.value)) {
					alert("Attention, insert a valid Email");
					EMAIL.focus();
					return false
					}
		}
		if (TELEFONO.value.length > 0){
				if(!isNumber(TELEFONO.value)){
					alert("Attention, insert a Phone Number ");
					TELEFONO.focus();
					return false
				}
		}
		if (FAX.value.length > 0){
				if(!isNumber(FAX.value)){
					alert("Attention, insert a Fax Number ");
					FAX.focus();
					return false
				}
		}

	}
return true
}

//---------LOGIN
function check_login(objForm) {
with (objForm) {
		if (cUsername.value.length < 1){
			alert("Attention, to insert the username");
			cUsername.focus();
			return false
		}
		if (cPassword.value.length < 1){
			alert("Attention, to insert the password");
			cPassword.focus();
			return false
		}
	}
return true
}
//---------SEARCH
function check_search(objForm) {
with (objForm) {
		if (cSearch.value.length < 1){
			alert("Please, insert text");
			cSearch.focus();
			return false
		}
	}
return true
}

//----- EMAIL
function check_email(objForm) {
with (objForm) {
		if (EMAIL.value.length < 7) {
									alert("Insert a valid Email");
									EMAIL.focus();
									return false;
									} else {
										if (!isEmail(EMAIL.value)) {
														alert("Insert a valid Email");
														EMAIL.focus();
														return false
														}
											}		
	}
return true
}
//-------------- ADMIN
function check_admin(objForm) {
with (objForm) {
		if (ACCESS_MODE.value.length < 1){
			alert("Attenzione, inserire il tipo di accesso");
			ACCESS_MODE.focus();
			return false
		}
		if (NOME.value.length < 1){
			alert("Attenzione, inserire il nome");
			NOME.focus();
			return false
		}
		if (USR.value.length < 1){
			alert("Attenzione, inserire la username");
			USR.focus();
			return false
		}
		if (PWD.value.length < 1){
			alert("Attenzione, inserire la password");
			PWD.focus();
			return false
		}
	}
return true
}
//-------------- USERS
function check_users(objForm) {
with (objForm) {
		if (NOME.value.length < 1){
			alert("Attenzione, inserire il nome");
			NOME.focus();
			return false
		}
		if (USR.value.length < 1){
			alert("Attenzione, inserire la username");
			USR.focus();
			return false
		}
		if (PWD.value.length < 1){
			alert("Attenzione, inserire la password");
			PWD.focus();
			return false
		}
		if (EMAIL.value.length > 0) {
				if (!isEmail(EMAIL.value)) {
					alert("Attenzione inserire correttamente il campo EMAIL");
					EMAIL.focus();
					return false
					}
		}		
		if (TELEFONO.value.length > 0){
				if(!isNumber(TELEFONO.value)){
					alert("Attenzione, inserire solo numeri nel campo TELEFONO ");
					TELEFONO.focus();
					return false
				}
		}

	}
return true
}
//---------ARTICOLI
function check_articles(objForm) {
with (objForm) {
		if (TITLE.value.length < 1){
			alert("Attenzione, inserire il titolo ");
			TITLE.focus();
			return false
		}
		if (ABSTRACT.value.length < 1){
			alert("Attenzione, inserire abstract ");
			ABSTRACT.focus();
			return false
		}
		if (KEYWORDS.value.length < 1){
			alert("Attenzione, inserire le keywords ");
			KEYWORDS.focus();
			return false
		}
		if (NPAGE.value.length < 1){
			alert("Attenzione, inserire le pagine ");
			NPAGE.focus();
			return false
		}
	}
return true
}

//-------------- VOLUMI
function check_books(objForm) {
with (objForm) {
		if (VOLUME.value.length < 1){
			alert("Attenzione, inserire il volume");
			VOLUME.focus();
			return false
		}
		if (AUTHORS.value.length < 1){
			alert("Attenzione, inserire gli autori");
			AUTHORS.focus();
			return false
		}
		if (TITLE.value.length < 1){
			alert("Attenzione, inserire il titolo");
			TITLE.focus();
			return false
		}
		//if (PREZZO.value.length < 1){
		//	alert("Attenzione, inserire il prezzo");
		//	PREZZO.focus();
		//	return false
		//}
		//if (PREZZO.value.length > 0){
		//		if(!isNumber(PREZZO.value)){
		//			alert("Attenzione, PREZZO è un numero");
		//			PREZZO.focus();
		//			return false
		//		}
		//}
	
	}
return true
}
