function checkmandat(frm) {
  if (frm.adiname) {
    if (frm.adiname.value=="") {
      alert("It is necessary to fill in the title!");
      frm.adiname.focus();
      return false;
    }
  }
  
  if (frm.adititle) {
    if (frm.adititle.value=="") {
      alert("It is necessary to fill in the Meta Title!");
      frm.adititle.focus();
      return false;
    }
  }  

  if (frm.aditext) {
    if (frm.aditext.value=="") {
      alert("The description is necessary to be filled in!");
      frm.aditext.focus();
      return false;
    }
  }  

  if (frm.adidescription) {
    if (frm.adidescription.value=="") {
      alert("The Meta Description is necessary to be filled in!");
      frm.adidescription.focus();
      return false;
    }
  }
  
  if (frm.adiurl) {
    if (frm.adiurl.value=="" || frm.adiurl.value=="http://") {
      alert("The URL is necessary to be filled in!");
      frm.adiurl.focus();
      return false;
    }
  }  
  
  if (frm.adiurlrecip) {
    if (frm.adiurlrecip.value=="" || frm.adiurlrecip.value=="http://") {
      alert("The Recip URL is necessary to be filled in!");
      frm.adiurlrecip.focus();
      return false;
    }
  }  

  if (frm.adiemail) {
    if (frm.adiemail.value=="") {
      alert("The Email is necessary to be filled in!");
      frm.adiemail.focus();
      return false;
    }
  }  

  return true;
}

var str;
var maxChars_aditext = 250;
var maxChars_adidescription = 150;
var maxWidth;

function counted(str) {
  var orginal = str.length;
  return  orginal;
}

function countChars250(){
   var theForm = document.getElementById('part1');
   
   theForm.counter_aditext.value = counted(theForm.aditext.value);
   progresbar (theForm.aditext.value, 250, 'aditext');

   if ( theForm.counter_aditext.value > 250 ) {
     alert('Maximum 250 characters');
     theForm.aditext.value=theForm.aditext.value.substr(0,250);
     progresbar(theForm.aditext.value, 250, 'aditext');
     theForm.counter_aditext.value = 250;
   } else if (theForm.counter_aditext.value > 250) {
      theForm.counter_aditext.style.color = '#cc0000';
   } else if (theForm.counter_aditext.value > 200) {
      theForm.counter_aditext.style.color = '#FF8000';
   } else if (theForm.counter_aditext.value > 120) {
      theForm.counter_aditext.style.color = '#000';
   } else if (theForm.counter_aditext.value > 50) {
      theForm.counter_aditext.style.color = '#808080';
   } else if (theForm.counter_aditext.value > 20) {
      theForm.counter_aditext.style.color = '#c0c0c0';
   } else {
      theForm.counter_aditext.style.color = '#c0c0c0';
   }
}

function countChars150(){
   var theForm = document.getElementById('part1');
   
   theForm.counter_adidescription.value = counted(theForm.adidescription.value);
   progresbar (theForm.adidescription.value, 150, 'adidescription');

   if ( theForm.counter_adidescription.value > 150 ) {
     alert('Maximum 150 characters');
     theForm.adidescription.value=theForm.adidescription.value.substr(0,150);
     progresbar(theForm.adidescription.value, 150, 'adidescription');
     theForm.counter_adidescription.value = 150;
   } else if (theForm.counter_adidescription.value > 150) {
      theForm.counter_adidescription.style.color = '#cc0000';
   } else if (theForm.counter_adidescription.value > 100) {
      theForm.counter_adidescription.style.color = '#FF8000';
   } else if (theForm.counter_adidescription.value > 50) {
      theForm.counter_adidescription.style.color = '#808080';
   } else {
      theForm.counter_adidescription.style.color = '#c0c0c0';
   }
}

function progresbar (str, maxChars, id) {
  var len = str.length;
  maxWidth = parseInt(document.getElementById('progres_main_' + id).clientWidth, 10);
  var pBar = document.getElementById('progres_bar_' + id);
  var newWidth = maxWidth/maxChars*len;
  if (newWidth > maxWidth) newWidth = maxWidth;
  var procento = Math.round((len/maxChars*100)-0.4)+'%';
  pBar.style.width = newWidth+'px';
  document.getElementById('progres_val_' + id).innerHTML=procento;
}

