// JavaScript Document
function cleanString(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 prepareSearch() {

      var string = document.getElementById('searchField').value;

      if(string != "Full Site Search" && string.length > 1) {

      document.getElementById('searchField').value = cleanString(string);
      //alert(cleaned);
      //window.location.href='System/Search.php?Search='+cleaned;
      document.SearchHeader.submit();
      return true;
      } else {
          
          if(string == "Full Site Search") {
          
          alert('Missing search string.');
          return false;
          
          } else if(string.length < 2) {
          
           alert('Minimum search string length is two characters.');
           return false;         
          }
      }
		  return false;
     
}

function popitup(url)
{
	newwindow=window.open(url,'name','height=650,width=650');
	if (window.focus) {newwindow.focus()}
	return false;
}

function open_url(urltoopen,menubar,scrollbars,resizable,width,height)
{
window.open(urltoopen,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=" + menubar + ", scrollbars="+ scrollbars + ", resizable=" + resizable + ", copyhistory=no, innerWidth=0, innerHeight=0, width=" + width + ", height=" + height);
}


// FORM VALIDATOR START
function check(adr) {
  		var esc = adr.toLowerCase();
  		var kw = 0;
		for (var i=0; i < esc.length; i++) {
    		var ch = esc.charAt(i);
    		if (ch == '@')
      		kw += 1;
  		}
		if (kw!=1){
			alert("Error type: missing or multiple instances of @ in email address!");
			return(false);
		}
		var filter=/^.+@.+\..{2,3}$/
		if (!filter.test(esc)){
			alert("Error type: missing or wrong character in email address!");
			return(false);
		}
		txt=esc.split("@");
 		if (txt[1].indexOf("..")>1) {
    		alert("Error type: multiple use of dot!");
    		return(false);
 		}
		if (esc.indexOf(" ")>0){
  			alert("Error type: a space between letters!");
			return(false);
		}
		adr.value=esc;
		return(true);
	}
	
function FormValidator(){

	var email=document.ContactForm.emailto;
	var yname=document.ContactForm.name;
	var ymail=document.ContactForm.mailfrom;
	var message=document.ContactForm.message.value;
	
	
	if ((email.value==null)||(email.value=="") || (yname.value=="") || (ymail.value=="") || (ymail.value==null)){
		alert("Please, fill the required fields.");
		ymail.focus()
		return false
	}
	
	if (check(email.value)==false){
		email.value=""
		email.focus()
		return false
	} 
  
  if(check(ymail.value)==false){
		ymail.value=""
		ymail.focus()
		return false
	}

	if(message.length > 500) {
		alert("Sorry, to many characters in the message. Only five full lines allowed.");
		ymail.focus()
		return false
	
	}
	
	if(message.length > 0)  document.ContactForm.message.value = cleanString(message); 
		                      document.ContactForm.name.value = cleanString(yname.value);
		

	return true
 }

function CheckRequired(param) {

      
    var comment = document.getElementById('comment').value;
    var name = document.getElementById('name').value;
   

   
    if(param.length > 0) {
		if(comment=='' || name=='') {
			window.alert ("Please, fill the required fields.");
			return false

	   }
	   }
			
	  Validator();

	 if(name.length > 0) document.getElementById('name').value = cleanString(name); 
	 if(comment.length > 0) document.getElementById('comment').value = cleanString(comment); 

    return true;
	
}

function Validator(){

  if(document.getElementById('xmail')) {

	var xmail=document.ContactForm.xmail;
	
	if ((xmail.value==null)||(xmail.value=="")){
		alert("Must contain an e-mail address!");
		xmail.focus()
		return false
	}
	if (check(xmail.value)==false){
		xmail.value=""
		xmail.focus()
		return false
	}
	
	return true
	
 } else {
 
	return true
 }
}
// FORM VALIDATOR END
