document.observe("dom:loaded", function() {
	$$("span#zoekformulierpgp > select").each( function(select){
		Event.observe(select, "change", function(e){
			var name = this.readAttribute("name");
			if(name=="partner"){
				alert("TODO");
			} else if (name=="groep"){
				alert("TODO");
			} else if (name=="project"){
				alert("TODO");
			}
		});
	});
});

function refresh_menu(menu) {
	window.location.href=window.location.href;
}

var deleted = new Array;

function submit_menu_changes(parent_id, type) {
	var list = $(type + '_menu_list_edit');
	var list_postvars = serialize_menu_list(list);
	
//	alert(list_postvars);
	Droppables.remove(type + '_menu_ajax_recycle_bin');
	
	new Ajax.Request('index.php?m=Menu.edit', {
		method: 'post',
		evalScripts: true,
		parameters: '&type=' + type + '&parent_id=' + parent_id + '&action=save&' + list_postvars,
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function serialize_menu_list(list) {
	var result = "";
	
	var elements = list.immediateDescendants();
	for (i=0; i<elements.size(); i++) {
		if (elements[i].id.substring(0,3) == 'new') {
			result += "item_order[" + i + "]=-1&";
			result += "item_name[-1]=" + $F('new_item_name') + "&";			
		} else if (elements[i].id.substring(0,4) == 'menu'){
			id = elements[i].id.substring(10);
			result += "item_order[" + i + "]=" + id + "&";
			result += "item_name[" + id + "]=" + $F('item_name_' + id) + "&";
		}
	}	
	
	//JPW: TODO
	for (i=0; i < deleted.length; i++) {
		result += "deleted[]=" + deleted[i] + "&";
	}
	
	return result;
}

function infi_submit_content(id) {
	
	new Ajax.Request('index.php?m=Content.edit', {
		method: 'post',
		evalScripts: true,
		parameters: '&id=' + id + '&action=save&content_text=' + escape($F('content_text')) + '&content_subtitle=' + $F('content_subtitle'), 
		onComplete: function(transport) {
			window.location.href=window.location.href;
		}
	});
	return false;
}

function press_enter(username,password) {
	
	if (window.event.keyCode == 13)
		{
		infi_logon(username,password)
		}
}

function infi_logon(username,password) {
	
	new Ajax.Request('index.php?m=login', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=login&login=' + username + '&pass=' + password,
		
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function osage_reactie(news_id_r, naam_r, reactie_r) {
new Ajax.Request('index.php?m=reactie', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=reactie&news_id_r='+ news_id_r +'&naam_r=' + escape(naam_r) + '&reactie_r=' + escape(reactie_r),
		onComplete: function(transport) {
	
			ajaxRequest3('index.php?m=News.reacties&news_id='+news_id_r+'&tellen=1','','reacties_result')
			//window.location.href=window.location.href;
		}
	});
}


function osage_check_doc(doc_id) {
	
	if($('homepage'+doc_id).checked == true){
	doc_homepage = 1;

	new Ajax.Request('index.php?m=Documenten', {
				
			method: 'post',
			evalScripts: true,
			parameters: '&action=update&doc_id='+ doc_id + '&doc_homepage=' + doc_homepage,
			onComplete: function(transport) {
		
			ajaxRequest3('index.php?m=Documenten.list&nav_id='+ nav_id +'','','reloaden1')
			//window.location.href=window.location.href;
	
			}
		});
	} else if($('homepage'+doc_id).checked == false){
		
	doc_homepage = 0;

	new Ajax.Request('index.php?m=Documenten', {
				
			method: 'post',
			evalScripts: true,
			parameters: '&action=update&doc_id='+ doc_id + '&doc_homepage=' + doc_homepage,
			onComplete: function(transport) {
		
			ajaxRequest3('index.php?m=Documenten.list&nav_id='+ nav_id +'','','reloaden1')
			//window.location.href=window.location.href;
	
			}
		});	
		
	}
}

function osage_del_doc(doc_id, nav_id, doc_naam) {

new Ajax.Request('index.php?m=Documenten', {
			
		method: 'post',
		evalScripts: true,
		parameters: '&action=delete&doc_id='+ doc_id,
		onComplete: function(transport) {
	
		ajaxRequest3('index.php?m=Documenten.list&nav_id='+ nav_id +'','','reloaden')
		//window.location.href=window.location.href;

		}
	});

}
function osage_reactie_delete(reactie_id, news_id_r) {
	
new Ajax.Request('index.php?m=reactie', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=delete&reactie_id='+ reactie_id,
		onComplete: function(transport) {
		
			ajaxRequest3('index.php?m=News.reacties&news_id='+news_id_r+'&tellen=1','','reacties_result')
			//window.location.href=window.location.href;

		}
	});
}


function ov2(maand,leef,jaar) {
	window.location.href="/ontslagvergoeding?p=ontslagvergoeding&m=ontslagvergoeding.result&action=bereken&maand="+maand+"&leef="+leef+"&jaar="+jaar+"&#uitkomst";
}

function osage_ontslagvergoeding(maand,leef,jaar) {
//window.location.href="/ontslagvergoeding?p=ontslagvergoeding&m=ontslagvergoeding.result&action=bereken&maand="+maand+"&leef="+leef+"&jaar="+jaar+"&#uitkomst";
new Ajax.Request('/?m=ontslagvergoeding.result', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=bereken&maand='+ maand +'&leef=' + leef + '&jaar=' + jaar,
		onComplete: function(transport) {
		
		ajaxRequest3('/?m=Ontslagvergoeding.result','&action=bereken&maand='+ maand +'&leef=' + leef + '&jaar=' + jaar+ '','ontslagvergoeding')
	
		/*	$('ontslagvergoeding').update();
			$('ontslagvergoeding').update(transport.responseText);
		*/
		}
	});
}

function osage_wwuitkering(v1,v2,v3,v4,v5,v6) {

//window.location.href="/wwuitkering?p=wwuitkering&m=wwuitkering.result&action=bereken&v1="+v1+"&v2="+v2+"&v3="+v3+"&v4="+v4+"&v5="+v5+"&v6="+v6+"&#uitkomst";
new Ajax.Request('/?m=wwuitkering.result', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=bereken&v1='+ v1 +'&v2=' + v2 + '&v3=' + v3 + '&v4=' + v4 + '&v5=' + v5 + '&v6=' + v6,
		onComplete: function(transport) {
	
		ajaxRequest3('/?m=Wwuitkering.result','&action=bereken&v1='+ v1 +'&v2=' + v2 + '&v3=' + v3 + '&v4=' + v4 + '&v5=' + v5 + '&v6=' + v6+ '','wwuitkering')
	
	/*	$('wwuitkering').update();
			$('wwuitkering').update(transport.responseText);
	*/
		}
	});
}

function osage_zoek(zoekwoord) {

new Ajax.Request('index.php?m=content.zoek', {
		method: 'post',
		evalScripts: true,
		parameters: '&zoekwoord='+ zoekwoord,
		onComplete: 
		
		function(transport) {
			$('zoek_resultaat').update();
			$('zoek_resultaat').update(transport.responseText);
		}


});
}
function osage_email(email,doelgroep) {

	new Ajax.Request('index.php?m=email', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=email&email=' + escape(email) + '&doelgroep=' + doelgroep,
		onComplete: function(transport) {
			
	 	ajaxRequest3('/?m=Content.emaillijst','','lijstddd')
		$('nieuwsbrief').update();
		$('nieuwsbrief').update(transport.responseText);
		}	
	});
}


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

function osage_achtergrond(achtergrond) {
	
	new Ajax.Request('index.php?m=achtergrond', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=achtergrond&achtergrond=' + achtergrond,
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function infi_logout() {
	new Ajax.Request('index.php?m=logout', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=logout',
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function mm_showhidelayers() { //v6.0
  var i,p,v,obj,args=mm_showhidelayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}





function echeck(str) {
		
		var kleurfout = "#f09999"
		var kleurgoed = "#00FF33"
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		document.form.email.style.background = kleurfout
			document.form.action.disabled = true
		//   alert("Invalid E-mail IDsdfsdfsdfdfdhfhghghsss")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		 	document.form.email.style.background = kleurfout
			document.form.action.disabled = true
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			document.form.email.style.background = kleurfout
			document.form.action.disabled = true
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			document.form.email.style.background =  kleurfout
			document.form.action.disabled = true
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    document.form.email.style.background =  kleurfout
			document.form.action.disabled = true
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			document.form.email.style.background =  kleurfout
			document.form.action.disabled = true
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		 	document.form.email.style.background =  kleurfout
			document.form.action.disabled = true
		    return false
		 }
		document.form.email.style.background = kleurgoed
		document.form.action.disabled = false
 		 return true					
	}

function ValidateForm(){
	var emailID=document.from.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		document.form.email.style.background = kleurfout
		document.form.action.disabled = true
	//	emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		//emailID.value=""
		emailID.focus()
		return false
	}
	return true
	document.form.email.style.background = kleurgoed
	document.form.action.disabled = false
 }

function searchfor(elm) {
	var lang = window.location.toString().match(/http:\/\/[^\/]+\/../gi)[0].match(/..$/gi)[0];
	
	//console.log('/'+lang+'/portal/overig/index.php?p=detail&cat='+elm.name+'&id='+elm.value);
	
	window.location = '/'+lang+'/portal/overig/index.php?p=detail&cat='+elm.name+'&id='+elm.value;
}

function doDelete(id, vraag) {
	var vr = 'Weet u zeker dat u dit item wilt verwijderen?';
	
	if(vraag)
		vr = vraag;
	
	var conf = confirm(vr);
	
	if(conf)
		$(id).value = 1;
	
	return conf;
}
