<!--

function launch(newURL, newName, newFeatures, orgName) {
  var remote = open(newURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
  return remote;
  }

function launchLegal() {
  myRemote = launch("http://www.oliopepesale.com/risorse/legalstuff.htm", "myRemote", "height=600, width=600, screenX=50, left=50, screenY=50, top=50, channelmode=0, dependent=1, directories=0, fullscreen=0, location=0, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=0", "myWindow");
  }

//master form check function
function checkForm(theForm) {
    var why = "";
	why += checkUsername(theForm.reviewer.value);
	why += checkEmail(theForm.email.value);
	why += checkReview(theForm.description.value);
	why += checkBestItems(theForm.best_items.value);
	// why += checkGuess(theForm.myguess.value);
	if (why != "") {
       alert(why);
       return false;
       }
    return true;
    }

// username - min-max chars, allowed chars
function checkUsername (strng) {
var error = "";
if  (strng == "") {
    error = "- un nome и richiesto ... anche se non и quello vero!\n";
    }
else {
    var illegalChars = /[^A-Za-z0-9_-абвийклИмноптуфхцщъыьяз ]/; // allowed chars
    if ((strng.length < 1) || (strng.length > 50)) {
       error = "- il nome deve avere un massimo di 50 caratteri\n";
       }
    else if (illegalChars.test(strng)) {
       error = "- il nome contiene caratteri non consentiti\n";
       }
    }
return error;
}

// email
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "- inserisci il tuo indirizzo e-mail (o lascia anonimo@oliopepesale.com)\n";
}
else { 
    //test email for correct morphology
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "- l'indirizzo e-mail non sembra valido\n";
    }
    else {
    //test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
       if (strng.match(illegalChars)) {
          error = "- l'indirizzo e-mail contiene caratteri non consentiti\n";
       }
    }
	} 
return error;    
}

// non-empty 
function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "- scrivi qualche parola ...\n"
  }
return error;	  
}

// review must exist and contain no illegal chars
function checkReview (strng) {
var error = "";
    var illegalChars = /[^A-Za-z0-9_-абвийклИмноптуфхцщъыьяз!?,;:'" ]/; // allowed chars
    if ((strng.length == 0)) {
       error = "- scrivi qualche parola di commento ...\n";
       }
    else if (illegalChars.test(strng)) {
       error = "- il tuo commento contiene caratteri non consentiti: \n puoi usare lettere, numeri e punteggiatura (tranne il punto); non puoi usare HTML\n";
       }
return error;
}

// dishes, allowed chars + max width
function checkBestItems (strng) {
var error = "";
    var illegalChars = /[^A-Za-z0-9_-абвийклИмноптуфхцщъыьяз,;:'"!? ]/; // allowed chars
    if ((strng.length > 50)) {
       error = "- la descrizione di quanto ti и piaciuto deve avere un massimo di 50 caratteri\n";
       }
    else if (illegalChars.test(strng)) {
       error = "- la descrizione di quanto ti и piaciuto contiene caratteri non consentiti\n";
       }
return error;
}

function checkForm2(theForm) {
    var why = "";
	why += checkGuess(theForm.myguess.value);
	if (why != "") {
       alert(why);
       return false;
       }
    return true;
    }
	// guess - not empty, allowed chars
	function checkGuess (strng) {
	var error = "";
	if (strng == "") {
		error = "- devi inserire la parola antispam\n";
	}
	else {
    	var illegalChars = /[^A-Za-z0-9_-абвийклИмноптуфхцщъыьяз]/; // allow letters, numbers, and underscores
    	if (illegalChars.test(strng)) {
       	error = "- la parola antispam contiene caratteri non consentiti\n";
    	}
		}
	return error;
	}

// toggle show/hide comments form
function toggle() {
	var ele = document.getElementById("toggleText");
	var text = document.getElementById("displayText");
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		text.innerHTML = "mostra il modulo per lasciare il tuo commento";
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = "nascondi il modulo";
	}
} 

// -->
