function registrationSubmit( registrationType ) {
  //Get object for current registration type
  var registrationTypeObj   = document.getElementById( 'registrationType' );
  var cellNumberObj   = document.getElementById( 'cellNumberZero9_' + registrationType );
  var idCarrierObj    = document.getElementById( 'idCarrierZero9_' + registrationType );
  var acceptZero9Obj  = document.getElementById( 'acceptZero9_' + registrationType );
  
  //Set registration type
  if( registrationTypeObj != null )
    registrationTypeObj.value = registrationType;
  
  //alert(registrationTypeObj.value);
  //alert('check js disabled!');
  //return true;
  
  //Check data
  if( cellNumberObj != null ) {
    if( cellNumberObj.value.length != cellNumberLength ) {
      alert(messages['error.invalidnumber']);
      cellNumberObj.focus();
      return false;
    }
    if( !isNumeric(cellNumberObj.value) ) {
      alert(messages['error.onlynumber']);
      cellNumberObj.focus();
      return false;
    }
  }
  if( idCarrierObj != null ) {
    if( idCarrierObj.selectedIndex <= 0 ) {
      alert(messages['error.registration.selectcarrier']);
      idCarrierObj.focus();
      return false;
    }
  }
  if( acceptZero9Obj != null ) {
    if( acceptZero9Obj.checked == false ) {
      alert(messages['error.acceptcondition']);
      idCarrierObj.focus();
      return false;
    }
  }
  return true;
}

function passwordSubmit() {
  var acceptZero9Obj  = document.getElementById( 'acceptZero9_zero9web' );
  var passwordObj = document.getElementById( 'password_zero9web' );
  if( acceptZero9Obj != null ) {
    if( acceptZero9Obj.checked == false ) {
      alert(messages['error.acceptcondition']);
      passwordObj.focus();
      return false;
    }
  }
  return true;
}

function getContentSubmit(checkAcceptCondition) {
  var acceptCondition  = document.getElementById( 'acceptCondition' );
  var checkCompatibility  = document.getElementById( 'checkCompatibility' );
  if( acceptCondition != null && checkAcceptCondition == 1 ) {    
    if( acceptCondition.checked == false ) {
      alert(messages['error.acceptcondition']);
      acceptCondition.focus();
      return false;
    }
  }
  if( checkCompatibility != null ) {
    if( checkCompatibility.checked == false) {
      alert(messages['error.checkcompatibility']);
      checkCompatibility.focus();
      return false;
    }
  }
  return true;
}

function setAuthorStartWithAndSubmit( letter ) {
  authorStartWith = document.getElementById('authorStartWith');
  if( authorStartWith != null )
    authorStartWith.value = letter;
  //Clear text box
  text = document.getElementById('searchText');
  if( text != null )
    text.value = '';
  document.searchFormBean.submit();
}

function validateTellAFriend() {
  var msg = '';
  formObj = document.tellAFriendFormBean;
  var recipientEmail1 = formObj.recipientEmail1;
  
  if ((recipientEmail1.value=='')||(! isEmail(recipientEmail1.value))) {
    msg = msg + 'Indirizzo E-MAIL non valido\n\n';
  }
  
  if (msg != '') {
    alert(msg);
    return false;
  } 
  else { 	
    return true;
  }   
}    

function submitTellAFriend() {   
  if(validateTellAFriend())
    document.tellAFriendFormBean.submit(); 
}

function isEmail(str) {
  // Verifico che le siano supportate le regualar exp?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function isNumeric(str) {
  var validChars = "0123456789";
  var isNumber=true;
  var char;
  for (i = 0; i < str.length && isNumber == true; i++) { 
    char = str.charAt(i); 
    if (validChars.indexOf(char) == -1) 
      isNumber = false;
  }
  return isNumber;
}

function loginSubmit() {
  var cellNumberObj = document.getElementById( 'username');
  var passwordObj = document.getElementById( 'password');
  if( cellNumberObj != null ) {
    if( cellNumberObj.value.length != cellNumberLength ) {
      alert(messages['error.invalidnumber']);
      cellNumberObj.focus();
      return false;
    }
    if( !isNumeric(cellNumberObj.value) ) {
      alert(messages['error.onlynumber']);
      cellNumberObj.focus();
      return false;
    }
  }
  if( passwordObj != null ) {
    if( passwordObj.value.length != 4 && passwordObj.value.length != 5) {
      alert(messages['error.invalidpassword']);
      passwordObj.focus();
      return false;
    }
    return true;
  }
}

function showHomePageBox(boxId, idHomePageBox) {
  if (boxId == ('divTopdownloads'+idHomePageBox)) {
    document.getElementById('divTopdownloads'+idHomePageBox).style.display='block';
    document.getElementById('pTopdownloads'+idHomePageBox).className='current';
    document.getElementById('divLatest'+idHomePageBox).style.display='none';
    document.getElementById('pLatest'+idHomePageBox).className='';
    document.getElementById('divRecommend'+idHomePageBox).style.display='none';
    document.getElementById('pRecommend'+idHomePageBox).className='';
  }
  else {
    if (boxId == ('divLatest'+idHomePageBox)) {
      document.getElementById('divTopdownloads'+idHomePageBox).style.display='none';
      document.getElementById('pTopdownloads'+idHomePageBox).className='';
      document.getElementById('divLatest'+idHomePageBox).style.display='block';
      document.getElementById('pLatest'+idHomePageBox).className='current';
      document.getElementById('divRecommend'+idHomePageBox).style.display='none';
      document.getElementById('pRecommend'+idHomePageBox).className='';
    }
    else {
      if (boxId == ('divRecommend'+idHomePageBox)) {
        document.getElementById('divTopdownloads'+idHomePageBox).style.display='none';
        document.getElementById('pTopdownloads'+idHomePageBox).className='';                                
        document.getElementById('divLatest'+idHomePageBox).style.display='none';
        document.getElementById('pLatest'+idHomePageBox).className='';
        document.getElementById('divRecommend'+idHomePageBox).style.display='block';
        document.getElementById('pRecommend'+idHomePageBox).className='current';
      }
    }
  }
}

function playAudio(id,basePath) {
    if( id > 0 ) {
        var stra=basePath+'audiopreviewfilescreate?id='+id+'&page='+getIdPage();
        ver = parseInt(navigator.appVersion);
        enablePlay = (ver>3 && navigator.appName=='Microsoft Internet Explorer') ? 1 : 0;
        if(enablePlay) {
            // Attention!! <bgsound id="soundpreview" > is into header.jsp
            //document.getElementById('soundpreview').src = stra;
            document.getElementById('imgprova').src=stra;    
            playaudio(id);
        }
        else{            
            document.getElementById('imgprova').src=stra;    
            playaudio (id);
        }
    }
    return;
}


function smsSubmit() {
  var cellNumberObj = document.getElementById( 'recipient');
  
  if( cellNumberObj != null ) {
    if( cellNumberObj.value.length != cellNumberLength ) {
      alert(messages['error.invalidnumber']);
      cellNumberObj.focus();
      return false;
    }
    if( !isNumeric(cellNumberObj.value) ) {
      alert(messages['error.onlynumber']);
      cellNumberObj.focus();
      return false;
    }
  }
  return true;
}

function countChars(messageCharsNumber)
{
  var form = document.smsFormBean;
  if (form.smsText.value.length > messageCharsNumber)
  {
    oldString = form.smsText.value.substring(0, messageCharsNumber);
    form.smsText.value = oldString;
  }
  else 
  {
    form.availableChars.value = messageCharsNumber - form.smsText.value.length;
  }
}

function submitSearch( seoSearch, contentTypeGroupNameSeo, isSearchBar )
{
  var href = seoSearch + '/';
  if( contentTypeGroupNameSeo.length > 0 )
    href = href + contentTypeGroupNameSeo + '/';  
  var text='';
  if( isSearchBar==true )
  {
    var coll = document.getElementsByName('searchBy');
    for(var i=0; i < coll.length; i++)
    {
      if( coll[i].checked == true && coll[i].value == 'author')
        href = href + 'autore' + '/';
      else if( coll[i].checked == true && coll[i].value == 'title')
        href = href + 'titolo' + '/';
    }
    if(document.getElementById('searchText')!=null){
    	text = document.getElementById('searchText').value;
    	} else {
    		text = document.getElementById('searchTextHeader').value;
    	}
  } else if(isSearchBar==false){
  	text = document.getElementById('searchTextHeader').value;
  } else {
  
  	href = href + 'autore' + '/';
    text = isSearchBar;
  }
  
  href = href + text;
  document.location.href = href;
  return false;
}

function manageKeyEnter(evt, actionToEval){
  var evt = (evt) ? evt : event;    
  var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
  if (charCode==13||charCode==3)
  {
  	actionToEval=actionToEval.replace('false', 'true');
    eval(actionToEval);
    return false;
  }  
  return true;
}
function switchFromRAtoMobileSubscription(elem){
    var queryString = unescape(location.search);
    if(queryString==''|| queryString==null)
        elem.href=document.URL+'?hidera=true';
    else
        elem.href=document.URL+'&hidera=true';
}
function popUpRegolamento(){                               
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('http://www.zero9.it/regolamento.html', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=350, left = 290,top = 150');");
}
