/*
ALGEMENE JAVASCRIPT FUNCTIES DIE NODIG ZIJN OP DE SITE
*/

function window_popup(url,naam,width,height) {

	var scr_w = get_browser_width();
	var scr_h = get_browser_height();
	var scr_top = 0;
	var scr_left = 0;
	
	var top = scr_top + ((scr_h - height) / 2);
	var left = scr_left + ((scr_w - width) / 2);
	
	var status = 'no';
	var scrollbars = 'no';
	var toolbar = 'no';
	
	var new_window = window.open(url, naam, 'width='+width+',height='+height+',status='+status+',scrollbars='+scrollbars+',toolbar='+toolbar+',top='+top+',left='+left);
	new_window.focus();
	return new_window;
}

function window_popup_scroll(url,naam,width,height) {
	var scr_w = get_browser_width();
	var scr_h = get_browser_height();
	var scr_top = 0;
	var scr_left = 0;
	
	var top = scr_top + ((scr_h - height) / 2);
	var left = scr_left + ((scr_w - width) / 2);
	
	var status = 'no';
	var scrollbars = 'yes';
	var toolbar = 'no';
	
	var new_window = window.open(url, naam, 'width='+width+',height='+height+',status='+status+',scrollbars='+scrollbars+',toolbar='+toolbar+',top='+top+',left='+left);
	new_window.focus();
	return new_window;
}

function check_email(email_val) {
	var result = false;
	if(email_val.indexOf('@',0) == -1 || email_val.indexOf('.',0)==-1) {
		result = false;
	}
	else {
		result = true;
	}
	return result;
}

function check_empty_text(text_val) {
	var result = false;
	if(text_val == null || text_val == "" || text_val == " ") {
		result = false;
	}
	else {
		result = true;
	}
	return result;
}

function get_browser_width() {
	var width=0;
	/*
	if (navigator.userAgent.indexOf("MSIE") > 0)
		{
			width = document.body.clientWidth;
        }
	else
		{
			width =  window.outerWidth;
		}
		*/
		width = window.screen.width;
	return width;
}

function get_browser_height() {
	var height=0;
	/*if (navigator.userAgent.indexOf("MSIE") > 0)
		{
			height=document.body.clientHeight;
		} 
	else
		{
			height=window.outerHeight;
		}*/
		height = window.screen.height;
	return height;
}

function str_replace(oldText,newText,inString) {
	return (inString.split(oldText).join(newText));
}

function ltrim(str)
{
	var charlist = "";
	if(arguments.length == 1) {
		charlist = "";
	}
	else {
		charlist = arguments[1];
	   
	}
   var whitespace = new String(" \t\n\r"+charlist);

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

function rtrim(str)
{
	var charlist = "";
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
  if(arguments.length == 1) {
		charlist = "";
	}
	else {
		charlist = arguments[1];
	}
   var whitespace = new String(" \t\n\r"+charlist);
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

function trim(str)
{
	var result = "";
	if(arguments.length == 1) {
		 result = rtrim(ltrim(str));
	}
	else {
		var charlist = arguments[1];
		result = rtrim(ltrim(str,charlist),charlist);   
	}
  return result;
}

function tel_aantal_karakters (f_form, f_element, tel_veld, maximum) {
	var tel_element = f_form.elements[tel_veld];
	if(f_element.value.length > maximum) {
		 f_element.value =f_element.value.substring(0, maximum);
	}
	else {
		tel_element.value = maximum - f_element.value.length;
	}
}
