function cleanBlogString(string) {

      var cleaned = string.replace(/[<>]/gi, '').replace(/&lt;/gi, '').replace(/&gt;/gi, '').replace(/alert\(/gi, '').replace(/alert \(/gi, '').replace(/#/gi, '');
      //cleaned = escape(cleaned);

      return cleaned;
}

  function prepareBlogSearch() {

      var string = document.getElementById('id_bstring').value;


      if(string != "Search Blog" && string.length > 1) {

      document.getElementById('id_bstring').value = cleanString(string);

      document.bSearch.submit();
      return true;
      } else {
          
          if(string == "Search Blog") {
          
          alert('Missing search string.');
          return false;
          
          } else if(string.length < 2) {
          
           alert('Minimum search string length is two characters.');
           return false;         
          }
      }
      
		  return false;
     
}

  function ForumRequiredFieldCheck(validate) {

    var rfstring = document.getElementById('id_setRequiredFields').value;
  
    if(rfstring.length > 0) {
   
    var rfstring = rfstring.split("+");
   
    var checkedpart = '';
   
    for(f=0;f < rfstring.length;f++) {

    checkedpart = document.getElementById(rfstring[f]).value;

       if(checkedpart.length == 0) {
    
		  alert('Please, fill all required fields!');
		  return false;
      }



        if(validate == '1') {

        if(rfstring[f].indexOf('mail') != -1) {

         if(!EmailValidator(rfstring[f])) return false;
       }
       
         document.getElementById(rfstring[f]).value = cleanBlogString(checkedpart);

        }
      
      }

    }
      
      return true;
}  
   
  

function EmailValidator(param){

  if(document.getElementById(param)) {

	var email=document.getElementById(param);
	
	if ((email.value==null)||(email.value=="")){
		alert("Must contain an e-mail address!");
		return false;
	}
	if (check(email.value)==false){
		return false;
	}
	}
	return true;
 }
 
   
 
 function countChar(what) {

  var doalert = '450';
  var gameover = '500';
  var str = new String(what.value);
  var len = str.length;
  
  var splited = str.split("\n");
  
  if(splited.length > 1) {
  var enters = splited.length -1;
  len = len + enters*40;  
  }


  if(len >= doalert && len < gameover) {
  document.getElementById('id_countinfo').style.display = 'block';
  document.getElementById('id_countinfo').style.fontWeight= 'bold';
  document.getElementById('id_countinfo').style.color= 'black';
  document.getElementById('id_countinfo').innerHTML = 'Maximum comment length will soon be reached.';
  }

  if(len >= gameover) {
  document.getElementById('id_countinfo').style.display = 'block';
  document.getElementById('id_countinfo').style.fontWeight= 'bold';
  document.getElementById('id_countinfo').style.color= '#cc0000';
  document.getElementById('id_countinfo').innerHTML = 'Maximum comment length exceeded!';
  }
    
  if(len < doalert) {
  document.getElementById('id_countinfo').style.display = 'none';

  }

  
}

  function showPageImg(id,job){
  //alert();
  (job == '1') ? document.getElementById(id).style.visibility="visible" : document.getElementById(id).style.visibility="hidden"
  
  }