function getById(idElement) {
    return document.getElementById(idElement);
}


function manageKeyEnter(evt, idElement) {
    evt = (evt) ? evt : event;    
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    
    if (charCode == 13 || charCode == 3) {
        eval(getById(idElement).onclick());
        return false;
    }  
    return true;
}


/* My Light */

	function myLight(){

	css = document.getElementById('skin');

	if ( css.href == '../css/skin.css' )
 		{
 			css.href= '../css/skin_light.css';
		
 		}
 		else if (( css.href= '../css/skin_light.css' ))
 		{
 			css.href= '../css/skin.css';
 			
 		}
 		else
 		{
 			css.href= '../css/skin_light.css';
			
 		}
}

/* CHANGE RESOLUTION */

function changeResolution(){
	
	css = document.getElementById('layout');

	if ( css.href == '../css/layout_800x600.css' )
 		{
 			css.href= '../css/layout_1024x768.css';
		
 		}
 		else if (( css.href= '../css/layout_1024x768.css' ))
 		{
 			css.href= '../css/layout_800x600.css';
 			
 		}
 		else
 		{
 			css.href= '../css/layout_800x600.css';
			
 		}
}
/* CONTROL SEARCH */

function fnCtr(f) 
{    
  
    var radio  = f.radioSelected; // gruppo di radio button   
    var valore = getById('textToSearch').value;

    if (radio[0].checked) {
        if (radio[0].value == "0") 
            valore = "site:www.mymy.it" + " " + valore;   
    }
   
    f.text.value = valore;
    f.submit();    
}

/* FORM CONTROLS */


function privacyValidator(idPush)
	{
	accept = document.getElementById('accept').checked
		if (accept == true)
		{
		document.getElementById(idPush).disabled = false;
		
		}
	
		if (accept == false)
		{
		document.getElementById(idPush).disabled = true;
		
		}
	
	}


function isNotValidEmail(elem) {
	var str = elem.value;
	var re  = /\b[a-z0-9._%-]+@[a-z0-9._%-]+\.[a-z0-9._%-]{2,4}\b/;
	if (!str.match(re))
		return false;
	else
		return true;
}



function formValidator(theForm)
{

  if (theForm.dato_nome.value == "")
  {
    alert('Il nome è obbligatorio');
    theForm.dato_nome.focus();
    return (false);
  }

  if (theForm.dato_cognome.value == "")
  {
    alert('Il cognome è obbligatorio');
    theForm.dato_cognome.focus();
    return (false);
  }  

  if (theForm.dato_email.value == "")
  {
    alert('La mail è obbligatoria');
    theForm.dato_email.focus();
    return (false);
  }
	
	if (!isNotValidEmail(document.forms['formContacts'].elements['dato_email']))
	{
		alert("il formato dell'email non è corretto");
		return false;
	}
	

  if (theForm.dato_note.value == ""  || theForm.dato_note.value == " " )
  {
    alert('Inserire una richiesta informativa');
    theForm.dato_note.focus();
    return (false);
  }
  return (true);
}

function nlValidator(theForm)
{

  

  if (theForm.dato_email.value == "")
  {
    alert('La mail è obbligatoria');
    theForm.dato_email.focus();
    return (false);
  }
	
	if (!isNotValidEmail(document.forms['formNewsletter'].elements['dato_email']))
	{
		alert("il formato dell'email non è corretto");
		return false;
	}
	
  return (true);
}