function colorpicker(){
	$(".color-picker").miniColors();
}

function tooltip(){
	$(".tooltip").tipTip({delay:50,maxWidth:'300px'});
}

$(function(){
	$(".tooltip").tipTip({delay:50,maxWidth:'300px'});
});

function fade_out(veld) {
  	$(document.getElementById(veld)).fadeOut(2000, function() { });
}


function stop_fade(veld) {
  	$(document.getElementById(veld)).stop();
}

function checkedAll(waarde){
	var i='0';
	if(waarde==''){
		waarde = 'check';
	}
	var id= waarde + i;
	while(document.getElementById(id) != undefined)
	{
		var check = document.getElementById('checkall').checked;
		if(check == true){
			document.getElementById(id).checked=true;
		}else{
			document.getElementById(id).checked=false;
		}
		i=Number(i) + 1;
		id= waarde + i;
	}
}


function urlencode(str) {
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}


function ajaxFunction(){
	return  window.XMLHttpRequest  ?
	new window.XMLHttpRequest :
	new ActiveXObject("Microsoft.XMLHTTP");
}

function get_confirm(file,errorid){
	var where_to= confirm(errorid);
	if (where_to== true){
		window.location=file;
	}else{
		exit;
	}
}
function post_confirm(errorid){
	var where_to= confirm(errorid);
	if (where_to== true){
		return true;
	}else{
		return false;
	}
}

function getcheckedvalue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function save_new_account_family(locatie,type,inhoud){
	check_acces();	
	var velden=inhoud.split('{BF}');
	var waarde = '';
	var aantal=velden.length - 1;
	var par='';
	var na_naam ='';
	var na_voornaam ='';
	var nf_familienaam ='';

	for(var i=0;i<aantal;i++){
		var veld=velden[i].split('|');
		
		if(document.getElementById(veld[0])){
			if(veld[2]=='checkbox'){
				if(document.getElementById(veld[0]).checked==true){	par ='1';}
				else{	par ='0';}
			}else{
				par = document.getElementById(veld[0]).value;

			}
			if(type=='family' && veld[0]=='nf_familienaam'){
				nf_familienaam = par;
			}
			if(type=='account' && veld[0]=='na_naam'){
				na_naam = par;
			}
			if(type=='account' && veld[0]=='na_voornaam'){
				na_voornaam = par;
			}
			waarde = waarde + veld[0] + "=" + urlencode(par) + "&";
		}

	}
	waarde = addslashes(waarde);
	
	var httpObj = ajaxFunction();
	var query = "accountbeheerajax.php?qrnd=" + Math.random() + '&action=check_double' + '&type=' + type + '&na_naam=' + urlencode(na_naam) + '&na_voornaam=' + urlencode(na_voornaam) + '&nf_familienaam=' + urlencode(nf_familienaam);
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			var save='0';
			if(httpObj.responseText.replace(/^\s+|\s+$/g,"")==''){
				var save='1';
			}else if(confirm(httpObj.responseText)){
				var save='1';
			}
			if(save=='1'){
				save_new_account_family_add(type,waarde);
			}
		}
	}
}
function save_new_account_family_add(type,waarde){

	var httpObj = ajaxFunction();
	var url = "accountbeheerajax.php";
	var params = "qrnd=" + Math.random() + '&action=' + 'addnew' + '&type=' + type +'&'+ waarde ;

	httpObj.open("POST",url, true);
	httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=ISO-8859-1");
	httpObj.setRequestHeader("Content-length", params.length);
	httpObj.setRequestHeader("Connection", "close");	
	httpObj.send(params);
	httpObj.onreadystatechange = function() {

		if(httpObj.readyState == 4 && httpObj.status == 200) {

			closelightbox();
			if(locatie=='zoeken' && type =='account'){
				if(document.getElementById('zoeken_result_container')){
					zoeken_resulttabel_laden();
					fiches_laden('','','','','');
				}
			}
			if(locatie=='zoeken' && type =='family'){
					refresh_family_list();
			}
			if(locatie=='lonenbeheer'){
				location.reload(true);
			}
			if(locatie=='company'){
				contactszoeken('zoeknaam');
			}
		}
	}
}
function addslashes (ch) { 
return (ch+'').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}


function load_autocompletenewaccount()
{
    $('#copyfromaccount').simpleAutoComplete('autocomplete.php',{
	autoCompleteClassName: 'autocomplete',
	selectedClassName: 'sel',
	attrCallBack: 'rel',
	identifier: 'accountid'
    },copyfromaccountcallback);
    
    $('#copyfromfamily').simpleAutoComplete('autocomplete.php',{
	autoCompleteClassName: 'autocomplete',
	selectedClassName: 'sel',
	attrCallBack: 'rel',
	identifier: 'familieid'
    },copyfromfamilycallback);
}
function copyfromaccountcallback( par )
{
    new_account('',par[0],'');
}
function copyfromfamilycallback( par )
{
    new_account('','',par[0]);
}

function load_autocompletenewfamily()
{
    $('#copyfamilyfromaccount').simpleAutoComplete('autocomplete.php',{
	autoCompleteClassName: 'autocomplete',
	selectedClassName: 'sel',
	attrCallBack: 'rel',
	identifier: 'accountid'
    },copyfamilyfromaccountcallback);
   
}
function copyfamilyfromaccountcallback( par )
{
    new_family('',par[0],'');
}


function new_account(locatie,accountid,familieid,subscriptionid)
{
	if(subscriptionid==undefined){
		subscriptionid = '';
	}
	check_acces();
	openlightbox();
	
	var httpObj = ajaxFunction();
	var query = "accountbeheerajax.php?qrnd=" + Math.random() + '&action=newaccount' + '&locatie=' + locatie + '&accountid=' + accountid + '&familieid=' + familieid + '&subscriptionid=' + subscriptionid;
	
	httpObj.open("GET",query, true);
	httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=latin1");
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById('blackbox').innerHTML = httpObj.responseText;	
			calendar();
			load_autocompletenewaccount();
		}
	}
}
function new_family(locatie,accountid,familieid,subscriptionid)
{
	check_acces();
	openlightbox();
	
	var httpObj = ajaxFunction();
	var query = "accountbeheerajax.php?qrnd=" + Math.random() + '&action=newfamily' + '&locatie=' + locatie + '&accountid=' + accountid + '&familieid=' + familieid + '&subscriptionid=' + subscriptionid;
	httpObj.open("GET",query, true);
	httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=latin1");
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById('blackbox').innerHTML = httpObj.responseText;	
			load_autocompletenewfamily();
		}
	}
}
function selecteer_rij(id,maxaantal,classwel,classniet)
{
	var i = 0;
	for(i=0;i < maxaantal;i++)
	{
		var veld= 'row' + i;
	
		if(document.getElementById(veld))
		{
			document.getElementById(veld).className=classniet;
		}
	}
	
	document.getElementById(id).className='view_id_selected';
}


function single_select(id,query,uitvoer,functie,action)
{
	
	var veld = id + '_view'; 
	var waarde = document.getElementById(veld).value;
	var httpObj = ajaxFunction();
	var query = "single_multi_selectajax.php?qrnd=" + Math.random() + '&type=' + 'single' + '&query=' + query + '&uitvoer=' + uitvoer + '&functie=' + functie + '&action=' + action + '&waarde=' + waarde + '&id=' + id;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			
			var veld = id + '_select'; 
			document.getElementById(veld).innerHTML = httpObj.responseText;
			document.getElementById(veld).style.display = '';
		}
	}
}

function login_opvragen(action,accountid)
{
	openlightbox();
	alert('geopend');
	var httpObj = ajaxFunction();
	var query = "getloginajax.php?qrnd=" + Math.random() + '&action=' + 'action' + '&accountid=' + 'accountid';
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById(blackbox).innerHTML = httpObj.responseText;
		}
	}
}

 function openaccountbox()
 {
	$("#accountbox").dialog({minHeight:400 ,width:330,resizable:false});
	document.getElementById('accountbox').innerHTML='<img style="margin-top:10px;" src="images/loading.gif">';
	$( "#accountbox" ).dialog({
	   close: function(event, ui) { 
	   	document.getElementById('accountbox').innerHTML='';
	   }
	});
	
 }
 function closeaccountbox(){
	document.getElementById('accountbox').innerHTML='';
	$("#accountbox").dialog("close");	
 }


 function openlightbox()
 {
 	
	$("#blackbox").dialog({minHeight:400 ,width:800,modal:true});
	document.getElementById('blackbox').innerHTML='<img style="margin-top:10px;" src="images/loading.gif">';
	$( "#blackbox" ).dialog({
	   close: function(event, ui) { 
	   	document.getElementById('blackbox').innerHTML='';
	   }
	});
 }
 function closelightbox(){
	document.getElementById('blackbox').innerHTML='';
	$("#blackbox").dialog("close");	
 }
 
 
function NewWindow(mypage,myname,w,h,pos,infocus){
	if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";win=window.open(mypage,myname,settings);
	win.focus();
}

	
