//var lingua = linguadetect();
var lingua = "";

function menu_attivo() {
	var anchors = document.getElementsByTagName('a');
	
	for (var i=0; i<anchors.length; i++){
		
		var ancora = anchors[i];
		if (ancora.href == nomepagina()){
			ancora.style.color = "#83d5ff";
			//ancora.setAttribute("rel","portfolio_vuota");
		}
	}
}

function nomepagina() {
	var x = location.href.split("?");
	y = x[0];
	y = y.replace(/_dettaglio/,"");
	return y;
}

function linguadetect(){
	indirizzo = document.location + "";
	if (indirizzo.lastIndexOf("_eng") > 0) {
		return  "eng"
	}
	else {
		return  "ita"
	}
	
	return (indirizzo.substring(str_start,str_end));
}

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

function sezione(){
	indirizzo = document.location + "";
	indirizzo = indirizzo.replace("http://www.albertonconsulting.it/","");
	str_end = indirizzo.indexOf("/");
	indirizzo = indirizzo.substring(0,str_end);
	indirizzo = indirizzo.replace("_","");
	//alert("sezione=" + indirizzo);
	return (indirizzo);
	
}

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 (cod != document.modulo.codicedigitato.value) {msg += 'Inserire il codice corretto.\n'}
    if (msg.length > 0) {alert(msg)}
		else { document.modulo.submit();}
    }
	
function checkcontatto(){
	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 (cod != document.modulo.codicedigitato.value) {msg += 'Inserire il codice corretto.\n'}
    if (msg.length > 0) {alert(msg)}
		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;
}
