function swap(which){
	menuarray = which.split("_");
	
	if (menuarray.length == 2) {
		menuname = menuarray[0];
		menustatus = menuarray[1];
		document.getElementById(menuname).src = menu[which];
	}
}

function swapimg(which){
	urlname = which.src.substring(0,which.src.lastIndexOf("."));
	urlext = which.src.substring(which.src.lastIndexOf("."),which.src.length);
	//alert(urlname.substring(urlname.length-1,urlname.length));
	if (urlname.substring(urlname.length-1,urlname.length) == '1') {which.src = urlname.substring(0,urlname.length -1) + urlext}
	else {which.src = urlname + '1' + urlext;}
	return false;
}

function startpage(){
	/*
	c = new Effect.Appear('menu', { duration: 0.6 , delay: 0.0}); 	
	b = new Effect.Appear('logo', { duration: 0.7, delay: 0.3});
	a = new Effect.Appear('titolo', { duration: 0.5, delay: 0.4});
	d = new Effect.Appear('content', { duration: 0.7 , delay: 0.5});
	*/
}


function checkcommento(){
	msg = '';
    if (!validateNotEmpty(document.modulo.nome.value)) { msg += 'Inserire il nome.\n'}
    if (!validateEmail(document.modulo.email.value)) { msg += 'Inserire un indirizzo email valido.\n'}
    if (!validateNotEmpty(document.modulo.commento.value)) { msg += 'Inserire il commento.\n'}
    if (msg.length > 0) {alert(msg)}
		else { document.modulo.submit();}
    }
    
function checkemail(){
	if (!validateEmail(document.modulo.email.value)) {alert('Inserire un indirizzo email valido.')}
    	else {document.modulo.submit()}
}

function validateEmail(strValue) {
if (!strValue.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/)){return false;
}
else {return true}
}
function validateNotEmpty( strValue ) {
/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
var strTemp = strValue;
strTemp = trimAll(strTemp);
if(strTemp.length > 0){return true;}
	return false;
}

function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}
