var lingua = linguadetect();

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('_' + lingua + "."));
	urlext = which.src.substring(which.src.lastIndexOf('_' + lingua + "."),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.citta.value)) { msg += 'Inserire la città.\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 checkmanifesto(){
	msg = '';
    if (!validateNotEmpty(document.manifestoform.nome.value)) { msg += 'Inserire il nome.\n'}
	if (!validateNotEmpty(document.manifestoform.citta.value)) { msg += 'Inserire la città.\n'}
    if (!validateEmail(document.manifestoform.email.value)) { msg += 'Inserire un indirizzo email valido.\n'}
	if (cod != document.manifestoform.codicedigitato.value) {msg += 'Inserire il codice corretto.\n'}
    if (msg.length > 0) {alert(msg)}
		else { document.manifestoform.submit();}
    }
	

function checkmailing(){
	msg = '';
    if (!validateEmail(document.mailinglist.memail.value)) { msg += 'Inserire un indirizzo email valido.\n'}
    if (msg.length > 0) {alert(msg)}
		else { document.mailinglist.submit();}
	return false;
    }
	
function checkcommentoeng(){
	msg = '';
    if (!validateNotEmpty(document.modulo.nome.value)) { msg += 'Please type your name.\n'}
    if (!validateEmail(document.modulo.email.value)) { msg += 'Please type your email address.\n'}
    if (!validateNotEmpty(document.modulo.commento.value)) { msg += 'Please type your comment.\n'}
	if (cod != document.modulo.codicedigitato.value) {msg += 'Please type the right code.\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 checkcontattoeng(){
	msg = '';
    if (!validateNotEmpty(document.modulo.nome.value)) { msg += 'Please type a name.\n'}
    if (!validateEmail(document.modulo.email.value)) { msg += 'Please type an email address.\n'}
	if (cod != document.modulo.codicedigitato.value) {msg += 'Please type the right code.\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;
}

function leggitutto(boxname) {
	var box = $(boxname);
	var box_open = $(boxname + "_open");
	var box_close = $(boxname + "_close");
	
	Element.show(box); 
	Element.hide(box_open);
	Element.show(box_close);
	
}

function chiudi(boxname) {
	var box = $(boxname);
	var box_open = $(boxname + "_open");
	var box_close = $(boxname + "_close");
	
	Element.hide(box); 
	Element.show(box_open);
	Element.hide(box_close);
}

function leggitutto2(boxname) {
	var box = document.getElementById(boxname);
	var box_open = document.getElementById(boxname + "_open");
	var box_close = document.getElementById(boxname + "_close");
	
	box.style.display = "inherit"; 
	box_open.style.display = "none"; 
	box_close.style.display = "inherit"; 
}

function chiudi2(boxname) {
	var box = document.getElementById(boxname);
	var box_open = document.getElementById(boxname + "_open");
	var box_close = document.getElementById(boxname + "_close");
	
	box.style.display = "none"; 
	box_open.style.display = "inherit"; 
	box_close.style.display = "none"; 
}

function tuttiicommentiGo() {
	var ppcom = document.getElementById("pulsantetuttiicommenti");
	var bbcom = document.getElementById("elencotuttiicommenti");
	ppcom.style.display = "none"; 
	bbcom.style.display = "block"; 
}

