/********** GENERIC FUNCTIONS **********/

	function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
	{
		 var arVersion = navigator.appVersion.split("MSIE")
		 var version = parseFloat(arVersion[1])
		 if ((version >= 5.5) && (document.body.filters)) 
		 {
				for(var i=0; i<document.images.length; i++)
				{
					 var img = document.images[i]
					 var imgName = img.src.toUpperCase()
					 if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
					 {
							var imgID = (img.id) ? "id='" + img.id + "' " : ""
							var imgClass = (img.className) ? "class='" + img.className + "' " : ""
							var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
							var imgStyle = "display:inline-block;" + img.style.cssText 
							if (img.align == "left") imgStyle = "float:left;" + imgStyle
							if (img.align == "right") imgStyle = "float:right;" + imgStyle
							if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
							var strNewHTML = "<span " + imgID + imgClass + imgTitle
							+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
							+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
							+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
							img.outerHTML = strNewHTML
							i = i-1
					 }
				}
		 }    
	}

	function setPid(pid){
		document.editor.pid.value = pid;
	}

	function switchBG(pid){
		elem = $(pid);
		color = elem.getStyle('backgroundColor');
		if(color == '' || color == 'transparent'){
			elem.setStyle({backgroundColor:'#FFCDCA'});
		}else{
			elem.setStyle({backgroundColor:'transparent'});
		}		
	}


	function filterLastName(LTR){
		var url = '_ajax/filterLastName.php';
		var vestiging = $('vestiging');
		var vestiging = vestiging.options[vestiging.selectedIndex].value;
		var params = 'suggest=' + LTR  + '&vestiging=' + vestiging;
		var ajax = new Ajax.Updater(
						{success: 'people_result'},
						 url,
						{method: 'get', parameters: params, onLoading: showProgress, onFailure: reportError});		
	}
	
	function filterPartners(){
		var url = '_ajax/filterPartners.php';
		var ajax = new Ajax.Updater(
						{success: 'people_result'},
						 url,
						{method: 'get', onLoading: showProgress, onFailure: reportError});		
	}
	
	function filterName(){
		var url = '_ajax/filter_people.php';
		var suggest = $F('suggest');
		var vestiging = $('vestiging');
		var vestiging = vestiging.options[vestiging.selectedIndex].value;
		var params = 'suggest=' + suggest + '&vestiging=' + vestiging;
		var ajax = new Ajax.Updater(
						{success: 'people_result'},
						 url,
						{method: 'get', parameters: params, onLoading: showProgress, onFailure: reportError});
	}


// Autofilter met AJAX in CMS
	function searchSuggest(){
		var url = '_modules/filter_people.php';
		var suggest = $F('suggest');
		var params = 'suggest=' + suggest;
		var ajax = new Ajax.Updater(
						{success: 'searchresults'},
						 url,
						{method: 'get', parameters: params, onLoading: showProgress, onFailure: reportError});
	}
		
		function reportError(request) {
			 $F('searchresults') = "An error occurred";
		}
		
		function showProgress(request){
			$F('searchresults') = "Updating People list";
		}


function fconfirmation(link, msg) {
  if( confirm(msg) ) {
    this.document.location.href=link;
  } else {
    return false;
  }
}

function fconfirmsubmit( formid, msg, cancelurl ) {
  if( confirm(msg) ) {
  	$( formid ).submit();
  } else {
		sURL = unescape( window.location.pathname );
		document.location.href=sURL;
  }
}

function fpopup( mypage, myname, w, h ) {
  var winl = ( screen.width - w ) / 2;
  var wint = ( screen.height - h ) / 2;

  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=yes,directories=no,status=no,menubar=no,scrollbars=yes, resizable=yes';
  win = window.open( mypage, 'popup', winprops );
  if( parseInt( navigator.appVersion ) >= 4 ) {
    win.window.focus();
  }

  return win;
}

function fpopup2(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function fswitch() {
  for ( var i=0; i < arguments.length; i++ ) {
    $( arguments[i] ).style.display = ( $( arguments[i] ).style.display != 'none' ? 'none' : '' );
  }
}

function fswapbool() {
  for ( var i=0; i < arguments.length; i++ ) {
    $( arguments[i] ).value = ( $( arguments[i] ).value == '0' ? '1' : '0' );
  }
}

function fswapimg( elemid, first, second ) {
  var img = $( elemid );
  img.src = ( img.src.indexOf( first ) >= 0 ? second : first );
}

function fcheckvalue( elemid, condition ) {
  if( $( elemid ).value == condition ) {
    return true;
  } else {
    return false;
  }
}

function fswitchoff( elemid ) {
  $( elemid ).style.display = 'none';
}

function fswitchon( elemid ) {
  $( elemid ).style.display = '';
}

function fvalue( elemid, value ) {
  $( elemid ).value = value;
}

function fsubmit( formid ) {
  $( formid ).submit();
}

function fpost( formid, elemid, value ) {
  fvalue( elemid, value );
  fsubmit( formid );
}

function fgetcookie( name ) {
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;

  if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
    return null;

  if ( start == -1 )
    return null;

  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 )
    end = document.cookie.length;

  return unescape( document.cookie.substring( len, end ) );
}

function fsetcookie( name, value, expires, path, domain, secure )
{
  var today = new Date();
  today.setTime( today.getTime() );

  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }

  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie = name+"="+escape( value ) +
    ( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function fdeletecookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}