/* REGULAR EXPRESSIONS */
telRegExp = /([0-9-]+){11}|([0-9]+){10}/; 
timeRegExp = /^(\d{1,2}):(\d{2})$/;
emailRegExp = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.([a-zA-Z]){2,4})$/;
postcodeRegExp = /^([0-9]){4}([a-zA-Z]){2}$/;


function goTo(url) {
	window.location = url;
}

function confirm_goto(question, url) {
	var cbox = confirm(question);
	if(cbox == true) {
		window.location = url;
	}
}

function setImg(imgPath,imageId,extension) {
	document.getElementById(imageId).src = imgPath+'_active'+extension;
}

function resetImg(imgPath,imageId, extension) {
	document.getElementById(imageId).src = imgPath+extension;
}


function set_search_over_class() {		
	document.getElementById('search_submit').setAttribute('class', 'search_submit_over');	
}
		
function reset_search_over_class() {
	document.getElementById('search_submit').setAttribute('class', 'search_submit');
}
		
//fancy box	
$(document).ready(function() {	
	$("a.ajax_content").fancybox({
		'zoomOpacity': true,
		'hideOnContentClick': false
	});
});

var map;
var gdir;

function load_google_maps() {    
										
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		
		//add marker
		var latlng = new GLatLng(53.248988, 6.392788);
		map.addOverlay(new GMarker(latlng), "v.v. Zuidhorn");

		map.setCenter(new GLatLng(53.245187, 6.400137), 14);
		
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GLargeMapControl3D());
		
		gdir = new GDirections(map, document.getElementById("map_route"));
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
		GEvent.addListener(gdir, "error", handleErrors);
	
	}
	
	

}

function onGDirectionsLoad(){ 
		
}
	
function plan_route(){
	var from_adress = document.getElementById("route_address").value;	
	gdir.load("from: "+from_adress+", Nederland to: 53.248988, 6.392788");
}

function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS){
		alert("Het adres kan niet worden gevonden. Controleer of deze juist is ingevuld.");
	} else if (gdir.getStatus().code == G_GEO_BAD_KEY){
		alert("Fout met Google maps.");
	}
}

//cufon replace
Cufon.replace('h1', {hover:'true'});
Cufon.replace('h2');
Cufon.replace('h3');
//* AJAX FUNCTIONS *//

var xmlhttp;

/* LOGIN LOAD */


/* CALENDER LOAD */
function loadMonth(year, month) {
	
	
	xmlhttp=null;
	if (window.XMLHttpRequest){
	// code for Firefox, Mozilla, IE7, etc.
		xmlhttp=new XMLHttpRequest();
	} else if (window.ActiveXObject){
	 // code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){
	  xmlhttp.onreadystatechange = change_calendar;
	  xmlhttp.open("GET","/calendar.php?year="+year+"&month="+month+"&ajax=true",true);
	  xmlhttp.send(null);
	} else {
		alert("U browser ondersteund deze functie niet.");
	 }
}



function change_calendar() {

	//if(xmlhttp.readyState < 4) {
		//document.getElementById('calendar_div').innerHTML="<img src=\"/images/loader.gif\" width=\"16\" height=\"16\" alt=\"Bezig met controleren\"/>Bezig met controleren.";
	//}
	
	if (xmlhttp.readyState==4)  {
		// 4 = "loaded"
		
	  if (xmlhttp.status==200){
	  	// 200 = "OK"
	    
		document.getElementById('calendar_div').innerHTML=xmlhttp.responseText;
		//replace heads
		//alert("cufon now");
		Cufon.refresh('h1');
		//sIFR.replaceElement("h1", named({sFlashSrc: "flash/helvetica_bold.swf", sColor: "#FFFFFF", sWmode: "transparent", sCase: "upper"}));
	  } else {
	    alert("Er is een probleem met het ophalen van de data:" + xmlhttp.statusText);
	  }
	}
}

/* FORM CHECK FUNCTION */ 
//jQuery Functions

function pushvalueinform(value, formid){
	var temp_value = $("#"+formid).val();
	$("#"+formid).val(temp_value+value+";");	
}

$(document).ready(function(){

	/*
		functions for become member form
	
	*/

	//auto fill bank with name from person
	/*$("#secondname").keyup(function(){
		$("#auth_name").val(this.value);
	});
	$("#zipcode").keyup(function(){
		$("#auth_zipcode").val(this.value);
	});
	$("#city").keyup(function(){
		$("#auth_city").val(this.value);
	});*/
	
	/*
		FUNCTIONS FOR DECLRATION FORM
	*/

	
	//
	$("#route_address").click(function(){
		if($(this).val() == "straat, plaats"){
			$(this).val("");
		}		
	});
	
	$(".image_enlarge").fancybox();
	
	//bank-giro
	$("#radio_giro").click(function(){
		$("label[for='bank_account']").text("ING rekeningnummer");
		$("#bank_account + label.error").text("Er is geen rekeningnummer ingevuld."); 		
		
	});
	$("#radio_bank").click(function(){
		$("label[for='bank_account']").text("Bankrekeningnummer");
		$("#bank_account + label.error").text("Er is geen bankrekeningnummer ingevuld.");		
	});
	
	var dec_rule_count = 1;
	
	$("td.dec_amount input").numeric(".");

	$("td.dec_amount input").keyup(function(){	
		//check regpexp
		calcTotalAmount();
	});
	
	$("#add_dec_rule").click(function(){
			
		//make a copy of the last rule 
		var rule = $("#dec_rules tr:last").html();
		
		//add rule to table
		$("#dec_rules").append("<tr>"+rule+"</tr>");
		
		//clear values and set new name to the form
		
		$("#dec_rules tr:last td.dec_options").html("<span class=\"icon cancel\"></span>");
		
		
		$("#dec_rules tr:last td.dec_date input").attr("name", "date["+dec_rule_count+"]");
		$("#dec_rules tr:last td.dec_amount input").attr("name", "amount["+dec_rule_count+"]");
		$("#dec_rules tr:last td.dec_details input").attr("name", "details["+dec_rule_count+"]");
		$("#dec_rules tr:last td.dec_depart input").attr("name", "depart["+dec_rule_count+"]");
		
		$("#dec_rules tr:last td.dec_amount input").numeric(".");
			
		$("#dec_rules tr:last td.dec_date input").mask("99-99-9999");
		
		$("#dec_rules tr:last td.dec_amount input").keyup(function(){
			calcTotalAmount();	
		});
	
		dec_rule_count++;
		
		//add a handler for removing
		$("#dec_rules tr:last td.dec_options span.cancel").click(function(){
			removeDecRule($(this).parent().parent());
		});
		//change number
		$("#dec_rules tr:last td.dec_nr").text(dec_rule_count);
		
		//clear the values
		
	});
	
	function calcTotalAmount(){
	
		var amount = 0;	
		//calc all the amounts 
		$("#dec_rules tr").each(function(){
			
			if($(this).find(".dec_nr").length >= 1){
				
				var temp_amount = $(this).find("td.dec_amount input").val().replace(",",".");
				amount = (amount+Number(temp_amount));
				
			}
		});
		//set the value and format as a good currency
		$("#totalamount").val(amount);
		$("#totalamount").formatCurrency();
		
		
	}
	
	function removeDecRule(object){
	
		//answer
		var answer = window.confirm("Weet u het zeker dat u deze declaratieregel wilt verwijderen?");
		
		if(answer) {
			$(object).remove();
			
			var current = 1;
			
			//update numbers
			$("#dec_rules tr").each(function(){
				
				if($(this).find(".dec_nr").length >= 1){
					
					//change the nr
					$(this).find(".dec_nr").text(current);
					
					//change the form names
					$(this).find("td.dec_date input").attr("name", "date["+(current-1)+"]");
					$(this).find("td.dec_amount input").attr("name", "amount["+(current-1)+"]");
					$(this).find("td.dec_details input").attr("name", "details["+(current-1)+"]");
					$(this).find("td.dec_depart input").attr("name", "depart["+(current-1)+"]");
					
					current++;
				}
				
			});
			
			dec_rule_count = current-1;
			calcTotalAmount();
		}
	}
	$("#dec_date").mask("99-99-9999");
	
	$("#date").mask("99-99-9999");

	$("td.dec_date input").mask("99-99-9999");
	//set mask for birthdate
	$("#birthdate").mask("99-99-9999");
	$("#date_mach").mask("99-99-9999");

	$(".table_normal tr.over").hover(function(){
			$(this).addClass("highlight");
		}, function() {
			$(this).removeClass("highlight");
		}
	);
			
			
	$("#content_slider").easySlider();
	
	
	$("#email_list_submit").click(function(){
		//validate the field
		if(validate_field("email_notlist")){
			call_email_list("submit");
		}
	});
	
	$("#email_list_unsubmit").click(function(){
		if(validate_field("email_notlist")){
			call_email_list("unsubmit");
		}	
	});
	
	function call_email_list(type){
		
		var email = $("#email_notlist").val();	
		
		//replace the form with a loader
		$("#afg_form").ajaxSend(function(){
			$(this).replaceWith("<span id='loader_afg'><img src='/images/ajax-loader.gif' width='16' height='16' /> bezig met verwerken</a></span>");
		});
			
		
		$.ajax({
			url: '/email_afgelastingen_action.php',
			data: "email="+email+"&type="+type,
			type: 'GET',
			dataType: 'html',
			success: function(succes) {
				
				$("#loader_afg").replaceWith(succes);
				
			}
		});
		
	}
	
	
	$('#news_ticker').vTicker({
		speed: 500,
		pause: 4000,
		showItems: 1,
		animation: 'fade',
		mousePause: false,
		height: 20,
		direction: 'up'
	});
	
	//sponsor
	$("#alphabetic_list > li").mouseover(function(){
		$(this).css("backgroundColor", "#E7E7E7");
	}).mouseout(function(){
		$(this).css("backgroundColor", "");
	});
	
	$("#alphabetic_list > li").click(function(){
		
		var scroll_to = this.id.replace("get", "list");
		
		$.scrollTo("#"+scroll_to, 200, {
			onAfter: function(){
					//fade slow in
					$("#"+scroll_to+" + ul").animate({"opacity": 1, "backgroundColor": '#E7E7E7'}, 1000, function(){ 
						$("#"+scroll_to+" + ul").animate({"opacity": 1, "backgroundColor": '#FFFFFF'}, 1000);
					});
				 }
			});
	});
	
	$(".open_sponsor").click(function(){
		
		var openli = this.id.replace("open", "sponsor");
		$("#"+this.id).toggleClass("title_bold");
		$("#"+this.id).toggleClass("sponsor_highlight");
		$("#"+this.id+" + li").toggleClass("sponsor_highlight");
		$("#"+openli).slideToggle();
		
	});
	
	$("#team_add_item").click(function(){
		
		//check if panel is open
		if($("#team_add_form").is(":visible")){
			
			//clear the form if there is input_tmb_id not is empty
			if(!$("#input_tmb_id").val()) {
				//toggle open
				$("#team_add_form").slideToggle();	
				//toggle icon class
				$(this).toggleClass("add_item");
				$(this).toggleClass("min_item");				
			} else {
							
				//clear form
				$("#team_add_form input").each(function(index) {
					
					if(index >= 1 && index <= 8){
						
						//get the type of this field [support for two types: checkbox, input]
						if($(this).attr("type") == "checkbox"){
							$(this).attr("checked", "");
						} else {
							$(this).val("");
						}
					}
				});
				
				//clear the select
				$("#team_add_form select").each(function(index) {
					$(this).val("0");
				});
				//disabled the remove btn
				$("#tmb_remove_btn").attr("disabled", "disabled");
				
			}
			
		} else {
					
			//toggle open
			$("#team_add_form").slideToggle();	
	
			//toggle icon class
			$(this).toggleClass("add_item");
			$(this).toggleClass("min_item");
		}

	});
	
	
	$(".change_player").click(function(){
		
		//
		//toggle open
		$("#team_add_form").slideDown();
		//toggle icon class
		$("#team_add_item").removeClass("add_item");
		$("#team_add_item").addClass("min_item");
		
		var playerid = this.id.replace("player_", "");
		var team = $("#team_add_teamid").val();
		//request ajax
		
		$.ajax({
			url: '/player_info.php',
			data: "id="+playerid+"&team="+team,
			type: 'GET',
			dataType: 'json',
			success: function(json) {
				
				$("#input_tmb_id").val(json[0].tmb_id);
				$("#remove_tmb_id").val(json[0].tmb_id);
				
				$("#input_tmt_id").val(json[0].tmt_id);
				$("#input_tmb_nr").val(json[0].tmb_nr);
				$("#input_tmb_name").val(json[0].tmb_name);
				$("#input_tmb_between").val(json[0].tmb_between);
				$("#input_tmb_family_name").val(json[0].tmb_family_name);
				$("#input_tmb_phone").val(json[0].tmb_phone);
				$("#input_tmr_id").val(json[0].tmr_id);
				
				//activate the tmb_remove_btn button
				$("#tmb_remove_btn").attr("disabled", "");
				
				if(json[0].tmb_captain == 1){
					//check captain	
					$("#input_tmb_captain").attr("checked", true);
				} else {
					//uncheck captain	
					$("#input_tmb_captain").attr("checked", false);
				}
				
				if(json[0].tmb_keeper == 1){
					//check captain	
					$("#input_tmb_keeper").attr("checked", true);
				} else {
					//uncheck captain
					$("#input_tmb_keeper").attr("checked", false);	
				}
				
			}
					
		});
		
	});
	
	
	var prevTeamSelect;
	
	if($("#select_team").val() == "all_teams"){
		prevTeamSelect = "all_teams";
		$("#team_options").hide();
		$("#wed_thuis").removeAttr("checked");
		$("#wed_uit").removeAttr("checked");
		$("#uitslagen").removeAttr("checked");
	}
	
	
	
	
	//team filter
	$("#select_team").change(function(){
		
		if(this.value == "all_teams"){
			//hide the options		
			$("#team_options").hide();
			//set checkboxes
			$("#wed_thuis").removeAttr("checked");
			$("#wed_uit").removeAttr("checked");
			$("#uitslagen").removeAttr("checked");		  
		} else {
			//show options
			$("#team_options").show();
			
			if(prevTeamSelect != "all_teams"){
				//get the settings		
			} else {
				$("#wed_thuis").attr("checked", "checked");
				$("#wed_uit").attr("checked", "checked");
				$("#uitslagen").attr("checked", "checked");
			}
		}
		
		prevTeamSelect = this.value;
	});
	
	$(".titles").click(function(){			
		//go tho url
		window.location = this.id;		
	});


  //toggle class for td mouseover
  
	$(".page_navigation div").hover(function(){
		
		$(this).addClass("td_highlight");
			}, function() {
		$(this).removeClass("td_highlight");
			
		}
	);
		
	$("#page_navigation div").click(function(){		
		
		var thisid = this.id;
		
		var id = thisid.replace("page_", "");

		window.location = "/new/nieuws/"+id+"";
		
	});
	
	$("#page_navigation_guestbook div").click(function(){		
		
		var thisid = this.id;
		
		var id = thisid.replace("page_", "");

		window.location = "/new/gastenboek/"+id+"";
		
	});	
	
	var item_count = 1;
	var textfieldclicked = false;
	
	$("#page_add_item").click(function(){

		// config.resize_maxWidth = 700;
		// config.resize_minHeight = 200;
		// config.resize_maxHeight = 500;

		//options for editor	
	 
		//add a item before this id
		$("#page_add_item_div").before("<form id='form_item_"+item_count+"' name='form' class='form_item_team'><div class='content_box_large'><div class='top_left'></div><div class='box_top'></div><div class='top_right'></div><div class='box_left'></div><div class='content'><div class='title'><div class='title_left'></div><div class='title_center'><input type='text' class='item_title' value='voer hier een titel in' name='item_title_"+item_count+"' id='item_title_"+item_count+"' /></div><div class='title_right'></div></div><div class='text'><textarea rows='5' cols='5' id='item_text_"+item_count+"'></textarea><input type='hidden' id='temp_images_"+item_count+"' name='temp_images_"+item_count+"' value='' /><input type='button' class='item_button' id='item_button_"+item_count+"' value='Opslaan' /></div></div><div class='box_right'></div><div class='bottom_left'></div><div class='box_bottom'></div><div class='bottom_right'></div></div></form>");
		
		$("textarea#item_text_"+item_count+"").ckeditor();

		//add event listener for title
		$(".item_title").click(function(){
			//remove content if it has a gray color
			$(this).val('');
			$(this).css('color', 'black');
			$(this).css('font-style', 'normal');			
		});
		
		//add ajax save function
		$("#item_button_"+item_count+"").bind('click', function() {
			
			
			//selector for form
			var save_form = this.id.replace("item_button_","form_item_");
			
			$("#"+save_form).ajaxSend(function(){
				$(this).replaceWith("<div class='content_box_large' id='loader_"+save_form+"'><div class='top_left'></div><div class='box_top'></div><div class='top_right'></div><div class='box_left'></div><div class='content'><div class='text_crumbpath'><img src='/images/ajax-loader.gif' width='16' height='16' /> bezig met opslaan.</div></div><div class='box_right'></div><div class='bottom_left'></div><div class='box_bottom'></div><div class='bottom_right'></div></div>");
			});

			//selector form text area
			var text_form = this.id.replace("button_","text_");
			var title_form = this.id.replace("button_","title_");
			var image_form = this.id.replace("item_button_","temp_images_");
			
			// Get the editor data. 
			var text_form_data = escape($("textarea#"+text_form+"").val()); 
			var page = $("#page_info").val();
			var team = $("#team").val();
			var title = $("#"+title_form).val();
			var images = $("#"+image_form).val();
			
			
			$.ajax({
					url: '/team_page_item_action.php',
					data: "title="+title+"&team="+team+"&page="+page+"&data="+text_form_data+"&images="+images,
					type: 'POST',
					dataType: 'json',
					error: function(x,e){
						if(e=='parsererror'){
							$("#loader_"+save_form).replaceWith("<div class='content_box_large' id='loader_"+save_form+"'><div class='top_left'></div><div class='box_top'></div><div class='top_right'></div><div class='box_left'></div><div class='content'><div class='text_crumbpath'>Kan de pagina niet automatisch updaten. <a href='javascript:window.location.reload()'>Herlaad</a> de pagina voor het resultaat.</div></div><div class='box_right'></div><div class='bottom_left'></div><div class='box_bottom'></div><div class='bottom_right'></div></div>");
						}
					},
					success: function(json) {
						
						$("#footer").append("json: "+json);
						
						if(!json){
							
						} else {
							
							$("#loader_"+save_form).replaceWith("<div class='content_box_large' id='page_item_"+json.page_id+"'><div class='top_left'></div><div class='box_top'></div><div class='top_right'></div><div class='box_left'></div><div class='content'><div class='title'><div class='title_left'></div><div class='title_center' id='title_"+json.page_id+"'><h1>"+json.title+"</h1><span class='icon_options_item' id='options_item_"+json.page_id+"'><span class='icon edit_item' id='page_item_edit_"+json.page_id+"' title='Item wijzigen'></span><span class='icon remove_item' id='page_item_remove_"+json.page_id+"' title='Item verwijderen'></span></span></div><div class='title_right'></div></div><div class='text' id='text_"+json.page_id+"'>"+json.text+"</div></div><div class='box_right'></div><div class='bottom_left'></div><div class='box_bottom'></div><div class='bottom_right'></div></div>");
							
							Cufon.replace('h1');
							
							$(".remove_item").unbind();
	
							$(".remove_item").bind('click', function(){
								removeItem(this.id);
							});
	
							$(".edit_item").unbind();
	
							$(".edit_item").bind('click', function(){
								editItem(this.id);
							});
							
							//remove the error msg
							$("#error_msg").slideUp("medium", function(){
								$(this).remove();
							});												
						}
					}
				});
			
		});	


		item_count++;
	});
	
	//edit function
	$(".edit_item").bind('click', function(){
		editItem(this.id);
	});

	function editItem(thisid){
		

		var cleanid = thisid.replace("page_item_edit_", "");
		
		$("#options_item_"+cleanid).hide();		

		$("#title_"+cleanid+" > h1").replaceWith("<form id='form_item_"+cleanid+"' name='form' class='form_item_team'><input type='text' class='item_title' value='"+$("#title_"+cleanid+"").text()+"' name='item_title_"+cleanid+"' id='item_title_"+cleanid+"' />");
		$("#item_title_"+cleanid+"").css('color', 'black');
		$("#item_title_"+cleanid+"").css('font-style', 'normal');
		//replace the text with ckeeditor
		var html = $("div#text_"+cleanid+"").html();
		//replace first with textarea
		$("div#text_"+cleanid+"").html("<textarea rows='5' cols='5' id='item_text_"+cleanid+"'>"+html+"</textarea>");	

		$("#item_text_"+cleanid+"").after("<input type='hidden' id='temp_images_"+cleanid+"' name='temp_images_"+cleanid+"' value='' /><input type='button' class='item_button' id='item_button_"+cleanid+"' value='Opslaan' /></form>");
		
		//call ckeditor for replace the textarea
		$("#item_text_"+cleanid).ckeditor();


		//add ajax save function
		$("#item_button_"+cleanid+"").bind('click', function() {
		
			//selector for form
			var save_form = this.id.replace("item_button_","page_item_");

			$("#"+save_form).ajaxSend(function(){
				$(this).replaceWith("<div class='content_box_large' id='loader_"+save_form+"'><div class='top_left'></div><div class='box_top'></div><div class='top_right'></div><div class='box_left'></div><div class='content'><div class='text_crumbpath'><img src='/images/ajax-loader.gif' width='16' height='16' /> bezig met opslaan</div></div><div class='box_right'></div><div class='bottom_left'></div><div class='box_bottom'></div><div class='bottom_right'></div></div>");
			});

			//selector form text area
			var text_form = this.id.replace("button_","text_");
			var title_form = this.id.replace("button_","title_");
			var image_form = this.id.replace("item_button_","temp_images_");
			
			// Get the editor data. 
			var text_form_data = escape($("textarea#"+text_form+"").val()); 
			var page = $("#page_info").val();
			var team = $("#team").val();
			var title = $("#"+title_form).val();
			var images = $("#"+image_form).val();
			
			//destroy the ckeditor for cleanup the page
			 $("textarea#"+text_form+"").ckeditor(function(){
				this.destroy();
			});

			//call the action page for saving and json callback
			$.ajax({
				url: '/team_page_item_action.php',
				data: "title="+title+"&team="+team+"&page="+page+"&data="+text_form_data+"&item="+cleanid+"&images="+images,
				type: 'POST',
				dataType: 'json',
				success: function(json) {
					
					if(!json){
						
						$("#loader_"+save_form).replaceWith("<div class='content_box_large' id='loader_"+save_form+"'><div class='top_left'></div><div class='box_top'></div><div class='top_right'></div><div class='box_left'></div><div class='content'><div class='text_crumbpath text_red'>Het opslaan is niet gelukt. Herlaad de pagina en probeer het nogmaals.</div></div><div class='box_right'></div><div class='bottom_left'></div><div class='box_bottom'></div><div class='bottom_right'></div></div>");
						
					} else {

						$("#loader_"+save_form).replaceWith("<div class='content_box_large' id='page_item_"+json.page_id+"'><div class='top_left'></div><div class='box_top'></div><div class='top_right'></div><div class='box_left'></div><div class='content'><div class='title'><div class='title_left'></div><div class='title_center' id='title_"+json.page_id+"'><h1>"+json.title+"</h1><span class='icon_options_item' id='options_item_"+json.page_id+"'><span class='icon edit_item' id='page_item_edit_"+json.page_id+"' title='Item wijzigen'></span><span class='icon remove_item' id='page_item_remove_"+json.page_id+"' title='Item verwijderen'></span></span></div><div class='title_right'></div></div><div class='text' id='text_"+json.page_id+"''>"+json.text+"</div></div><div class='box_right'></div><div class='bottom_left'></div><div class='box_bottom'></div><div class='bottom_right'></div></div>");
						

						$(".remove_item").unbind();

						$(".remove_item").bind('click', function(){
							removeItem(this.id);
						});

						$(".edit_item").unbind();

						$(".edit_item").bind('click', function(){
							editItem(this.id);
						});

						Cufon.replace('h1');
						
					}
				}
			});

		});
	}
	//});


	
	//remove function
	$(".remove_item").bind('click', function(){
		removeItem(this.id);
	});

	function removeItem(thisid){
	
		var ask = confirm("Weet je het zeker dat je dit item wilt verwijderen?");
		
		//page_item_remove_5
		var page = $("#page_info").val();

		if(ask){
			
			var id = thisid.replace("_remove", "");
			var cleanid = thisid.replace("page_item_remove_", "");

			$.ajax({
				url: '/team_page_item_remove.php',
				data: "page="+page+"&item="+cleanid,
				type: 'GET',
				success: function(msg) {
					if(!msg){
						alert('Het verwijderen is niet gelukt.');
					} else {
						
						$("#"+id).slideUp('medium', function(){
							//count content_box_large
							if($("div[id^='page_item']:visible").length == 0){
								//place item no content
								$("#page_add_item_div").before("<div class='content_box_large' id='error_msg' style='display:none;'><div class='top_left'></div><div class='box_top'></div><div class='top_right'></div><div class='box_left'></div><div class='content'><div class='text_crumbpath text_green'>Er zijn nog geen items op deze pagina.</div></div><div class='box_right'></div><div class='bottom_left'></div><div class='box_bottom'></div><div class='bottom_right'></div></div>");
								//hide directly and slide down after hide
								$("#error_msg").slideDown("medium");
							}
						});
						
						

					}
				}
			});
	
		}
	}
	



	$(".add_page").click(function(){		
		$("#add_page").slideToggle('medium');
	});

	$(".show_icons").mouseover(function(){		
		//select options
		if($("#"+this.id+" > span.icon_options").length){
			$("#"+this.id).addClass("hover");
			$("#"+this.id+" > span.icon_options").show();
		}

	}).mouseout(function(){
		//select options
		if($("#"+this.id+" > span.icon_options").length){
			$("#"+this.id).removeClass("hover");
			$("#"+this.id+" > span.icon_options").hide();
		}
	});

	$(".remove_page").click(function(){
		
		
		var id = this.id.replace("remove_","");
		var pageid = id.replace("item_", "");
		
		var url = "/team_page_remove.php?id="+pageid
		//confirm box
		
		confirm_goto("Weet u zeker dat u deze pagina wilt verwijderen? Alle onderliggende items worden ook verwijderd!", url);
		
	});
		
	
	$(".edit_page").click(function(){
		var id = this.id.replace("edit_","");
		var pageid = id.replace("item_", "");
		var text = $("#"+id+" > a").text();
		var link = $("#"+id+" > a").attr("href");
		//close previous item

		$("#"+id+" > a").replaceWith("<form class='team_page_edit' id='page_edit_form_"+id+"'><input type='hidden' name='page' value='"+pageid+"' /><input type='text' name='pagename' value='"+text+"' maxlength='35' /><span class='icon save' title='Opslaan' id='save_form_"+id+"'>&nbsp;</span> <span class='icon cancel' title='Annuleren' id='cancel_form_"+id+"'>&nbsp;</span> </form>");
		
		$("#save_form_"+id+"").bind('click', function() {
			var saveid = this.id.replace("save_form_","page_edit_form_");
			
			$("#"+saveid).ajaxSend(function(){
				$(this).replaceWith("<span id='loader_"+saveid+"'><img src='/images/ajax-loader.gif' width='16' height='16' /> bezig met opslaan</a></span>");
			});
	
			$.ajax({
				url: '/team_page_action.php',
				data: $("#"+saveid).serialize(),
				type: 'GET',
				dataType: 'json',
				success: function(json) {
					if(!json){
					} else {
						$("#loader_"+saveid).replaceWith("<a href='"+json.link+"'>"+json.name+"</a>");
					}
				}
			});

		});

		$("#cancel_form_"+id+"").bind('click', function() {
			var cancelid = this.id.replace("cancel_form_","page_edit_form_");
			$("#"+cancelid).replaceWith("<a href='"+link+"'>"+text+"</a>");
		});

		
	});

	
	
	//check for photo effect
	if($(".photoslideshow").length > 0) {
		$(".photoslideshow").cycle({
			fx: "fade"
		});	
		
	}
	
	//FORM CHECK FUNCTION	
	var default_message_empty = "Er is geen {value} ingevuld.";
	var default_message_plural_empty = "Er zijn geen {value} ingevuld.";	
	var default_message_notvalid = "Er is geen geldig {value} ingevuld.";
	var default_message_user_exists = "De gekozen {value} is al in gebruik.";

	
	$(".check").blur(function(){
		validate_field(this.id);	
	});
	
	
	$("#tmb_remove_btn").click(function(){
		
		var firstname = $("#input_tmb_name").val();
		var between = $("#input_tmb_between").val();
		var lastname = $("#input_tmb_family_name").val();
		
		var answer = confirm("Weet je zeker dat je '"+firstname+" "+between+" "+lastname+"' wilt verwijderen?");
		var form = $(this).parents("form").attr("id");
		
		if(answer){
			$("#"+form).submit();	
		}
		
	});
	
	
	$(".submit").click(function(){
		
		var form = $(this).parents("form").attr("id");

		//console.log(form+" - "+$("#"+form).attr("action"));
		
		var valid = false;		
		var return_form = true;
	
		//check form
		$("#"+form+" .check").each(function(){
			
			//check for each field in the form with the class check
			validate_field(this.id);
			
			valid = validate_field(this.id);
			
			if(!valid) {
				return_form = false;	
			}
			
		});
		
		//submit the form
		if(return_form) {
			$(".error_form").remove();
			$("#"+form).submit();
		} else {
			
			
			if($("#error_form_msg").length == 0) {
				$("#"+form).prepend("<p><label id=\"error_form_msg\" class=\"error_form\">Het formulier is niet verstuurd, controleer de gearceerde velden:</label></p>");	
			}
			
			//scroll to to top
			window.scrollTo(0,180);
			
		}

		
	});
	/*
	$(".submit_teamplayer").click(function(){
		
		var form_id = document.form.id;
		
		var valid;		
		var return_form = true;
		
		//check form
		$("#"+form_id+" + .check").each(function(){
			
			//check for each field in the form with the class check
			validate_field(this.id);
			
			valid = validate_field(this.id);
			
			if(!valid) {
				return_form = false;	
			}
			
		});
		
		//submit the form
		if(return_form) {
			document.form.submit();
		}
		
	});*/
	
	var form_valid = true;
	
	function validate_field(check_field){
		
		
		//REGEXP
		var email_regexp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		//var phone_regexp = /^(\d{10})$/;
		var phone_regexp = /(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)/;
		var zipcode_regexp = /^[1-9]{1}[0-9]{3}\s?[a-zA-Z]{2}$/;
		var url_regexp = /(((ht|f)tp(s?):\/\/)|(www\.[^ \[\]\(\)\n\r\t]+)|(([012]?[0-9]{1,2}\.){3}[012]?[0-9]{1,2})\/)([^ \[\]\(\),;&quot;'&lt;&gt;\n\r\t]+)([^\. \[\]\(\),;&quot;'&lt;&gt;\n\r\t])|(([012]?[0-9]{1,2}\.){3}[012]?[0-9]{1,2})/
		var bank_regexp = /^[0-9]{5,}$/;
		var field_value = document.getElementById(check_field).value;
		
		//generate the error message with the label
		var name = $("label[for='"+check_field+"']").text();
		var name_strip = name.replace(":", "");

	
		var message = default_message_empty.replace("{value}", name_strip.toLowerCase());
		var message_plural = default_message_plural_empty.replace("{value}", name_strip.toLowerCase());
		var message_notvalid = default_message_notvalid.replace("{value}", name_strip.toLowerCase());
		var message_userexists = default_message_user_exists.replace("{value}", name_strip.toLowerCase());
		
		var message_selector = "#"+check_field+" + .error";
	
		
		//default check
		if(!field_value) {			
			//check if message already is set
			if($(message_selector).length == 0) {
				//append the message for this id
				$("#"+check_field).addClass("error");
				
				if(check_field == "initials"){
					$("#"+check_field).after("<label class=\"error\">"+message_plural+"</label>");						
				} else {
					$("#"+check_field).after("<label class=\"error\">"+message+"</label>");	
				}

			}
			
			form_valid = false;
			
		} else {
			
			//remove the default message
			$("#"+check_field).removeClass("error");
			$(message_selector).remove();
			
			form_valid = true;

		}

		//check if there is a different field to check
		switch(check_field){
			case "zipcode":
				//check zipcode
				if(zipcode_regexp.test(field_value)){
					$("#"+check_field).removeClass("error");
					$(message_selector).remove();
					form_valid = true;
				} else {
					if($(message_selector).length == 0) {
						$("#"+check_field).addClass("error");
						$("#"+check_field).after("<label class=\"error\">"+message_notvalid+"</label>");
					}
					form_valid = false;
				}
				break;
			case "email":
				//check zipcode
				if(email_regexp.test(field_value)){
					$("#"+check_field).removeClass("error");
					$(message_selector).remove();
					form_valid = true;
				} else {
					if($(message_selector).length == 0) {
						$("#"+check_field).addClass("error");
						$("#"+check_field).after("<label class=\"error\">"+message_notvalid+"</label>");
					}
					form_valid = false;
				}
				break;
			case "email_notlist":
				//check zipcode
				if(email_regexp.test(field_value)){
					$("#"+check_field).removeClass("error");
					$(message_selector).remove();
					form_valid = true;
				} else {
					if($(message_selector).length == 0) {
						$("#"+check_field).addClass("error");
						$("#"+check_field).after("<label class=\"error\">"+message_notvalid+"</label>");
					}
					form_valid = false;
				}
				break;
			case "phone":
				//check phone
				if(phone_regexp.test(field_value)){
					$("#"+check_field).removeClass("error");
					$(message_selector).remove();
					form_valid = true;
				} else {
					if($(message_selector).length == 0) {
						$("#"+check_field).addClass("error");
						$("#"+check_field).after("<label class=\"error\">"+message_notvalid+"</label>");
					}
					form_valid = false;
				}
				break;
			case "cp_phone":
				//check phone
				if(phone_regexp.test(field_value)){
					$("#"+check_field).removeClass("error");
					$(message_selector).remove();
					form_valid = true;
				} else {
					if($(message_selector).length == 0) {
						$("#"+check_field).addClass("error");
						$("#"+check_field).after("<label class=\"error\">"+message_notvalid+"</label>");
					}
					form_valid = false;
				}
				break;
			case "da_phone":
				//check phone
				if(phone_regexp.test(field_value)){
					$("#"+check_field).removeClass("error");
					$(message_selector).remove();
					form_valid = true;
				} else {
					if($(message_selector).length == 0) {
						$("#"+check_field).addClass("error");
						$("#"+check_field).after("<label class=\"error\">"+message_notvalid+"</label>");
					}
					form_valid = false;
				}
				break;
			case "url":
				//check url
				if(url_regexp.test(field_value)){
					$("#"+check_field).removeClass("error");
					$(message_selector).remove();
					form_valid = true;
				} else {
					if($(message_selector).length == 0) {
						$("#"+check_field).addClass("error");
						$("#"+check_field).after("<label class=\"error\">"+message_notvalid+"</label>");
					}
					form_valid = false;
				}
				break;
			case "bank_account":
				//check url
				if(bank_regexp.test(field_value)){
					$("#"+check_field).removeClass("error");
					$(message_selector).remove();
					form_valid = true;
				} else {
					if($(message_selector).length == 0) {
						$("#"+check_field).addClass("error");
						$("#"+check_field).after("<label class=\"error\">"+message_notvalid+"</label>");
					}
					form_valid = false;
				}
				break;
				
		}
				
		return form_valid;
	}
	
	
});



/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

(function(){CKEDITOR.config.jqueryOverrideVal=typeof CKEDITOR.config.jqueryOverrideVal=='undefined'?true:CKEDITOR.config.jqueryOverrideVal;var a=window.jQuery;if(typeof a=='undefined')return;a.extend(a.fn,{ckeditorGet:function(){var b=this.eq(0).data('ckeditorInstance');if(!b)throw 'CKEditor not yet initialized, use ckeditor() with callback.';return b;},ckeditor:function(b,c){if(!a.isFunction(b)){var d=c;c=b;b=d;}c=c||{};this.filter('textarea, div, p').each(function(){var e=a(this),f=e.data('ckeditorInstance'),g=e.data('_ckeditorInstanceLock'),h=this;if(f&&!g){if(b)b.apply(f,[this]);}else if(!g){if(c.autoUpdateElement||typeof c.autoUpdateElement=='undefined'&&CKEDITOR.config.autoUpdateElement)c.autoUpdateElementJquery=true;c.autoUpdateElement=false;e.data('_ckeditorInstanceLock',true);f=CKEDITOR.replace(h,c);e.data('ckeditorInstance',f);f.on('instanceReady',function(i){var j=i.editor;setTimeout(function(){if(!j.element){setTimeout(arguments.callee,100);return;}i.removeListener('instanceReady',this.callee);j.on('dataReady',function(){e.trigger('setData.ckeditor',[j]);});j.on('getData',function(l){e.trigger('getData.ckeditor',[j,l.data]);},999);j.on('destroy',function(){e.trigger('destroy.ckeditor',[j]);});if(j.config.autoUpdateElementJquery&&e.is('textarea')&&e.parents('form').length){var k=function(){e.ckeditor(function(){j.updateElement();});};e.parents('form').submit(k);e.parents('form').bind('form-pre-serialize',k);e.bind('destroy.ckeditor',function(){e.parents('form').unbind('submit',k);e.parents('form').unbind('form-pre-serialize',k);});}j.on('destroy',function(){e.data('ckeditorInstance',null);});e.data('_ckeditorInstanceLock',null);e.trigger('instanceReady.ckeditor',[j]);if(b)b.apply(j,[h]);},0);},null,null,9999);}else CKEDITOR.on('instanceReady',function(i){var j=i.editor;setTimeout(function(){if(!j.element){setTimeout(arguments.callee,100);return;}if(j.element.$==h)if(b)b.apply(j,[h]);},0);},null,null,9999);});return this;}});if(CKEDITOR.config.jqueryOverrideVal)a.fn.val=CKEDITOR.tools.override(a.fn.val,function(b){return function(c,d){var e=typeof c!='undefined',f;this.each(function(){var g=a(this),h=g.data('ckeditorInstance');if(!d&&g.is('textarea')&&h){if(e)h.setData(c);else{f=h.getData();return null;}}else if(e)b.call(g,c);else{f=b.call(g);return null;}return true;});return e?this:f;};});})();


/*
* vertical news ticker
* Tadas Juozapaitis ( kasp3rito@gmail.com )
* http://plugins.jquery.com/project/vTicker
*/
(function(a){a.fn.vTicker=function(b){var c={speed:700,pause:4000,showItems:3,animation:"",mousePause:true,isPaused:false,direction:"up",height:0};var b=a.extend(c,b);moveUp=function(g,d,e){if(e.isPaused){return}var f=g.children("ul");var h=f.children("li:first").clone(true);if(e.height>0){d=f.children("li:first").height()}f.animate({top:"-="+d+"px"},e.speed,function(){a(this).children("li:first").remove();a(this).css("top","0px")});if(e.animation=="fade"){f.children("li:first").fadeOut(e.speed);if(e.height==0){f.children("li:eq("+e.showItems+")").hide().fadeIn(e.speed)}}h.appendTo(f)};moveDown=function(g,d,e){if(e.isPaused){return}var f=g.children("ul");var h=f.children("li:last").clone(true);if(e.height>0){d=f.children("li:first").height()}f.css("top","-"+d+"px").prepend(h);f.animate({top:0},e.speed,function(){a(this).children("li:last").remove()});if(e.animation=="fade"){if(e.height==0){f.children("li:eq("+e.showItems+")").fadeOut(e.speed)}f.children("li:first").hide().fadeIn(e.speed)}};return this.each(function(){var f=a(this);var e=0;f.css({overflow:"hidden",position:"relative"}).children("ul").css({position:"absolute",margin:0,padding:0}).children("li").css({margin:0,padding:0});if(b.height==0){f.children("ul").children("li").each(function(){if(a(this).height()>e){e=a(this).height()}});f.children("ul").children("li").each(function(){a(this).height(e)});f.height(e*b.showItems)}else{f.height(b.height)}var d=setInterval(function(){if(b.direction=="up"){moveUp(f,e,b)}else{moveDown(f,e,b)}},b.pause);if(b.mousePause){f.bind("mouseenter",function(){b.isPaused=true}).bind("mouseleave",function(){b.isPaused=false})}})}})(jQuery);

/*
 * jQuery UI Effects 1.8.2
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Effects/
 */
jQuery.effects||function(f){function k(c){var a;if(c&&c.constructor==Array&&c.length==3)return c;if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))return[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10)];if(a=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))return[parseFloat(a[1])*2.55,parseFloat(a[2])*2.55,parseFloat(a[3])*2.55];if(a=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))return[parseInt(a[1],
16),parseInt(a[2],16),parseInt(a[3],16)];if(a=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)];if(/rgba\(0, 0, 0, 0\)/.exec(c))return l.transparent;return l[f.trim(c).toLowerCase()]}function q(c,a){var b;do{b=f.curCSS(c,a);if(b!=""&&b!="transparent"||f.nodeName(c,"body"))break;a="backgroundColor"}while(c=c.parentNode);return k(b)}function m(){var c=document.defaultView?document.defaultView.getComputedStyle(this,null):this.currentStyle,
a={},b,d;if(c&&c.length&&c[0]&&c[c[0]])for(var e=c.length;e--;){b=c[e];if(typeof c[b]=="string"){d=b.replace(/\-(\w)/g,function(g,h){return h.toUpperCase()});a[d]=c[b]}}else for(b in c)if(typeof c[b]==="string")a[b]=c[b];return a}function n(c){var a,b;for(a in c){b=c[a];if(b==null||f.isFunction(b)||a in r||/scrollbar/.test(a)||!/color/i.test(a)&&isNaN(parseFloat(b)))delete c[a]}return c}function s(c,a){var b={_:0},d;for(d in a)if(c[d]!=a[d])b[d]=a[d];return b}function j(c,a,b,d){if(typeof c=="object"){d=
a;b=null;a=c;c=a.effect}if(f.isFunction(a)){d=a;b=null;a={}}if(f.isFunction(b)){d=b;b=null}if(typeof a=="number"||f.fx.speeds[a]){d=b;b=a;a={}}a=a||{};b=b||a.duration;b=f.fx.off?0:typeof b=="number"?b:f.fx.speeds[b]||f.fx.speeds._default;d=d||a.complete;return[c,a,b,d]}f.effects={};f.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(c,a){f.fx.step[a]=function(b){if(!b.colorInit){b.start=q(b.elem,a);b.end=k(b.end);b.colorInit=
true}b.elem.style[a]="rgb("+Math.max(Math.min(parseInt(b.pos*(b.end[0]-b.start[0])+b.start[0],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[1]-b.start[1])+b.start[1],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[2]-b.start[2])+b.start[2],10),255),0)+")"}});var l={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,
183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,
165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0],transparent:[255,255,255]},o=["add","remove","toggle"],r={border:1,borderBottom:1,borderColor:1,borderLeft:1,borderRight:1,borderTop:1,borderWidth:1,margin:1,padding:1};f.effects.animateClass=function(c,a,b,d){if(f.isFunction(b)){d=b;b=null}return this.each(function(){var e=f(this),g=e.attr("style")||" ",h=n(m.call(this)),p,t=e.attr("className");f.each(o,function(u,
i){c[i]&&e[i+"Class"](c[i])});p=n(m.call(this));e.attr("className",t);e.animate(s(h,p),a,b,function(){f.each(o,function(u,i){c[i]&&e[i+"Class"](c[i])});if(typeof e.attr("style")=="object"){e.attr("style").cssText="";e.attr("style").cssText=g}else e.attr("style",g);d&&d.apply(this,arguments)})})};f.fn.extend({_addClass:f.fn.addClass,addClass:function(c,a,b,d){return a?f.effects.animateClass.apply(this,[{add:c},a,b,d]):this._addClass(c)},_removeClass:f.fn.removeClass,removeClass:function(c,a,b,d){return a?
f.effects.animateClass.apply(this,[{remove:c},a,b,d]):this._removeClass(c)},_toggleClass:f.fn.toggleClass,toggleClass:function(c,a,b,d,e){return typeof a=="boolean"||a===undefined?b?f.effects.animateClass.apply(this,[a?{add:c}:{remove:c},b,d,e]):this._toggleClass(c,a):f.effects.animateClass.apply(this,[{toggle:c},a,b,d])},switchClass:function(c,a,b,d,e){return f.effects.animateClass.apply(this,[{add:a,remove:c},b,d,e])}});f.extend(f.effects,{version:"1.8.2",save:function(c,a){for(var b=0;b<a.length;b++)a[b]!==
null&&c.data("ec.storage."+a[b],c[0].style[a[b]])},restore:function(c,a){for(var b=0;b<a.length;b++)a[b]!==null&&c.css(a[b],c.data("ec.storage."+a[b]))},setMode:function(c,a){if(a=="toggle")a=c.is(":hidden")?"show":"hide";return a},getBaseline:function(c,a){var b;switch(c[0]){case "top":b=0;break;case "middle":b=0.5;break;case "bottom":b=1;break;default:b=c[0]/a.height}switch(c[1]){case "left":c=0;break;case "center":c=0.5;break;case "right":c=1;break;default:c=c[1]/a.width}return{x:c,y:b}},createWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent();
var a={width:c.outerWidth(true),height:c.outerHeight(true),"float":c.css("float")},b=f("<div></div>").addClass("ui-effects-wrapper").css({fontSize:"100%",background:"transparent",border:"none",margin:0,padding:0});c.wrap(b);b=c.parent();if(c.css("position")=="static"){b.css({position:"relative"});c.css({position:"relative"})}else{f.extend(a,{position:c.css("position"),zIndex:c.css("z-index")});f.each(["top","left","bottom","right"],function(d,e){a[e]=c.css(e);if(isNaN(parseInt(a[e],10)))a[e]="auto"});
c.css({position:"relative",top:0,left:0})}return b.css(a).show()},removeWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent().replaceWith(c);return c},setTransition:function(c,a,b,d){d=d||{};f.each(a,function(e,g){unit=c.cssUnit(g);if(unit[0]>0)d[g]=unit[0]*b+unit[1]});return d}});f.fn.extend({effect:function(c){var a=j.apply(this,arguments);a={options:a[1],duration:a[2],callback:a[3]};var b=f.effects[c];return b&&!f.fx.off?b.call(this,a):this},_show:f.fn.show,show:function(c){if(!c||
typeof c=="number"||f.fx.speeds[c])return this._show.apply(this,arguments);else{var a=j.apply(this,arguments);a[1].mode="show";return this.effect.apply(this,a)}},_hide:f.fn.hide,hide:function(c){if(!c||typeof c=="number"||f.fx.speeds[c])return this._hide.apply(this,arguments);else{var a=j.apply(this,arguments);a[1].mode="hide";return this.effect.apply(this,a)}},__toggle:f.fn.toggle,toggle:function(c){if(!c||typeof c=="number"||f.fx.speeds[c]||typeof c=="boolean"||f.isFunction(c))return this.__toggle.apply(this,
arguments);else{var a=j.apply(this,arguments);a[1].mode="toggle";return this.effect.apply(this,a)}},cssUnit:function(c){var a=this.css(c),b=[];f.each(["em","px","%","pt"],function(d,e){if(a.indexOf(e)>0)b=[parseFloat(a),e]});return b}});f.easing.jswing=f.easing.swing;f.extend(f.easing,{def:"easeOutQuad",swing:function(c,a,b,d,e){return f.easing[f.easing.def](c,a,b,d,e)},easeInQuad:function(c,a,b,d,e){return d*(a/=e)*a+b},easeOutQuad:function(c,a,b,d,e){return-d*(a/=e)*(a-2)+b},easeInOutQuad:function(c,
a,b,d,e){if((a/=e/2)<1)return d/2*a*a+b;return-d/2*(--a*(a-2)-1)+b},easeInCubic:function(c,a,b,d,e){return d*(a/=e)*a*a+b},easeOutCubic:function(c,a,b,d,e){return d*((a=a/e-1)*a*a+1)+b},easeInOutCubic:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a+b;return d/2*((a-=2)*a*a+2)+b},easeInQuart:function(c,a,b,d,e){return d*(a/=e)*a*a*a+b},easeOutQuart:function(c,a,b,d,e){return-d*((a=a/e-1)*a*a*a-1)+b},easeInOutQuart:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a+b;return-d/2*((a-=2)*a*a*a-2)+
b},easeInQuint:function(c,a,b,d,e){return d*(a/=e)*a*a*a*a+b},easeOutQuint:function(c,a,b,d,e){return d*((a=a/e-1)*a*a*a*a+1)+b},easeInOutQuint:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a*a+b;return d/2*((a-=2)*a*a*a*a+2)+b},easeInSine:function(c,a,b,d,e){return-d*Math.cos(a/e*(Math.PI/2))+d+b},easeOutSine:function(c,a,b,d,e){return d*Math.sin(a/e*(Math.PI/2))+b},easeInOutSine:function(c,a,b,d,e){return-d/2*(Math.cos(Math.PI*a/e)-1)+b},easeInExpo:function(c,a,b,d,e){return a==0?b:d*Math.pow(2,
10*(a/e-1))+b},easeOutExpo:function(c,a,b,d,e){return a==e?b+d:d*(-Math.pow(2,-10*a/e)+1)+b},easeInOutExpo:function(c,a,b,d,e){if(a==0)return b;if(a==e)return b+d;if((a/=e/2)<1)return d/2*Math.pow(2,10*(a-1))+b;return d/2*(-Math.pow(2,-10*--a)+2)+b},easeInCirc:function(c,a,b,d,e){return-d*(Math.sqrt(1-(a/=e)*a)-1)+b},easeOutCirc:function(c,a,b,d,e){return d*Math.sqrt(1-(a=a/e-1)*a)+b},easeInOutCirc:function(c,a,b,d,e){if((a/=e/2)<1)return-d/2*(Math.sqrt(1-a*a)-1)+b;return d/2*(Math.sqrt(1-(a-=2)*
a)+1)+b},easeInElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return-(h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g))+b},easeOutElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return h*Math.pow(2,-10*a)*Math.sin((a*e-c)*2*Math.PI/g)+d+b},easeInOutElastic:function(c,
a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e/2)==2)return b+d;g||(g=e*0.3*1.5);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);if(a<1)return-0.5*h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)+b;return h*Math.pow(2,-10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)*0.5+d+b},easeInBack:function(c,a,b,d,e,g){if(g==undefined)g=1.70158;return d*(a/=e)*a*((g+1)*a-g)+b},easeOutBack:function(c,a,b,d,e,g){if(g==undefined)g=1.70158;return d*((a=a/e-1)*a*((g+1)*a+g)+1)+b},easeInOutBack:function(c,
a,b,d,e,g){if(g==undefined)g=1.70158;if((a/=e/2)<1)return d/2*a*a*(((g*=1.525)+1)*a-g)+b;return d/2*((a-=2)*a*(((g*=1.525)+1)*a+g)+2)+b},easeInBounce:function(c,a,b,d,e){return d-f.easing.easeOutBounce(c,e-a,0,d,e)+b},easeOutBounce:function(c,a,b,d,e){return(a/=e)<1/2.75?d*7.5625*a*a+b:a<2/2.75?d*(7.5625*(a-=1.5/2.75)*a+0.75)+b:a<2.5/2.75?d*(7.5625*(a-=2.25/2.75)*a+0.9375)+b:d*(7.5625*(a-=2.625/2.75)*a+0.984375)+b},easeInOutBounce:function(c,a,b,d,e){if(a<e/2)return f.easing.easeInBounce(c,a*2,0,
d,e)*0.5+b;return f.easing.easeOutBounce(c,a*2-e,0,d,e)*0.5+d*0.5+b}})}(jQuery);
;/*
 * jQuery UI Effects Highlight 1.8.2
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Effects/Highlight
 *
 * Depends:
 *	jquery.effects.core.js
 */
(function(b){b.effects.highlight=function(c){return this.queue(function(){var a=b(this),e=["backgroundImage","backgroundColor","opacity"],d=b.effects.setMode(a,c.options.mode||"show"),f={backgroundColor:a.css("backgroundColor")};if(d=="hide")f.opacity=0;b.effects.save(a,e);a.show().css({backgroundImage:"none",backgroundColor:c.options.color||"#ffff99"}).animate(f,{queue:false,duration:c.duration,easing:c.options.easing,complete:function(){d=="hide"&&a.hide();b.effects.restore(a,e);d=="show"&&!b.support.opacity&&
this.style.removeAttribute("filter");c.callback&&c.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
;

/*
	Masked Input plugin for jQuery
	Copyright (c) 2007-2009 Josh Bush (digitalbush.com)
	Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) 
	Version: 1.2.2 (03/09/2009 22:39:06)
*/
(function(a){var c=(a.browser.msie?"paste":"input")+".mask";var b=(window.orientation!=undefined);a.mask={definitions:{"9":"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"}};a.fn.extend({caret:function(e,f){if(this.length==0){return}if(typeof e=="number"){f=(typeof f=="number")?f:e;return this.each(function(){if(this.setSelectionRange){this.focus();this.setSelectionRange(e,f)}else{if(this.createTextRange){var g=this.createTextRange();g.collapse(true);g.moveEnd("character",f);g.moveStart("character",e);g.select()}}})}else{if(this[0].setSelectionRange){e=this[0].selectionStart;f=this[0].selectionEnd}else{if(document.selection&&document.selection.createRange){var d=document.selection.createRange();e=0-d.duplicate().moveStart("character",-100000);f=e+d.text.length}}return{begin:e,end:f}}},unmask:function(){return this.trigger("unmask")},mask:function(j,d){if(!j&&this.length>0){var f=a(this[0]);var g=f.data("tests");return a.map(f.data("buffer"),function(l,m){return g[m]?l:null}).join("")}d=a.extend({placeholder:"_",completed:null},d);var k=a.mask.definitions;var g=[];var e=j.length;var i=null;var h=j.length;a.each(j.split(""),function(m,l){if(l=="?"){h--;e=m}else{if(k[l]){g.push(new RegExp(k[l]));if(i==null){i=g.length-1}}else{g.push(null)}}});return this.each(function(){var r=a(this);var m=a.map(j.split(""),function(x,y){if(x!="?"){return k[x]?d.placeholder:x}});var n=false;var q=r.val();r.data("buffer",m).data("tests",g);function v(x){while(++x<=h&&!g[x]){}return x}function t(x){while(!g[x]&&--x>=0){}for(var y=x;y<h;y++){if(g[y]){m[y]=d.placeholder;var z=v(y);if(z<h&&g[y].test(m[z])){m[y]=m[z]}else{break}}}s();r.caret(Math.max(i,x))}function u(y){for(var A=y,z=d.placeholder;A<h;A++){if(g[A]){var B=v(A);var x=m[A];m[A]=z;if(B<h&&g[B].test(x)){z=x}else{break}}}}function l(y){var x=a(this).caret();var z=y.keyCode;n=(z<16||(z>16&&z<32)||(z>32&&z<41));if((x.begin-x.end)!=0&&(!n||z==8||z==46)){w(x.begin,x.end)}if(z==8||z==46||(b&&z==127)){t(x.begin+(z==46?0:-1));return false}else{if(z==27){r.val(q);r.caret(0,p());return false}}}function o(B){if(n){n=false;return(B.keyCode==8)?false:null}B=B||window.event;var C=B.charCode||B.keyCode||B.which;var z=a(this).caret();if(B.ctrlKey||B.altKey||B.metaKey){return true}else{if((C>=32&&C<=125)||C>186){var x=v(z.begin-1);if(x<h){var A=String.fromCharCode(C);if(g[x].test(A)){u(x);m[x]=A;s();var y=v(x);a(this).caret(y);if(d.completed&&y==h){d.completed.call(r)}}}}}return false}function w(x,y){for(var z=x;z<y&&z<h;z++){if(g[z]){m[z]=d.placeholder}}}function s(){return r.val(m.join("")).val()}function p(y){var z=r.val();var C=-1;for(var B=0,x=0;B<h;B++){if(g[B]){m[B]=d.placeholder;while(x++<z.length){var A=z.charAt(x-1);if(g[B].test(A)){m[B]=A;C=B;break}}if(x>z.length){break}}else{if(m[B]==z[x]&&B!=e){x++;C=B}}}if(!y&&C+1<e){r.val("");w(0,h)}else{if(y||C+1>=e){s();if(!y){r.val(r.val().substring(0,C+1))}}}return(e?B:i)}if(!r.attr("readonly")){r.one("unmask",function(){r.unbind(".mask").removeData("buffer").removeData("tests")}).bind("focus.mask",function(){q=r.val();var x=p();s();setTimeout(function(){if(x==j.length){r.caret(0,x)}else{r.caret(x)}},0)}).bind("blur.mask",function(){p();if(r.val()!=q){r.change()}}).bind("keydown.mask",l).bind("keypress.mask",o).bind(c,function(){setTimeout(function(){r.caret(p(true))},0)})}p()})}})})(jQuery);



(function($) {
	
	$.fn.formatCurrency = function(settings) {
		settings = jQuery.extend({
		    name: "formatCurrency",
		    useHtml: false,
		    symbol: '€',
		    global: true
		}, settings);
		
		return this.each(function() {
		    var num = "0";
		    num = $(this)[settings.useHtml ? 'html' : 'val']();
		    num = num.replace(/\$|\,/g, '');
		    if (isNaN(num))
		        num = "0";
		    sign = (num == (num = Math.abs(num)));
		    num = Math.floor(num * 100 + 0.50000000001);
		    cents = num % 100;
		    num = Math.floor(num / 100).toString();
		    if (cents < 10)
		        cents = "0" + cents;
		    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		        num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
		
		    $(this)[settings.useHtml ? 'html' : 'val'](((sign) ? '' : '-') + settings.symbol + num + '.' + cents);
		});
	};

  // Remove all non numbers from text
  $.fn.toNumber = function(settings) {
		settings = jQuery.extend({
		    name: "toNumber",
		    useHtml: false,
		    global: true
		}, settings);  

    return this.each(function() {
      var method = settings.useHtml ? 'html' : 'val';   
      $(this)[method]($(this)[method]().replace(/[^\d\.]/g, ''));
    });
  };


})(jQuery);

/*
 *
 * Copyright (c) 2006-2010 Sam Collett (http://www.texotela.co.uk)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * Version 1.2
 * Demo: http://www.texotela.co.uk/code/jquery/numeric/
 *
 */
(function($) {
/*
 * Allows only valid characters to be entered into input boxes.
 * Note: does not validate that the final text is a valid number
 * (that could be done by another script, or server-side)
 *
 * @name     numeric
 * @param    decimal      Decimal separator (e.g. '.' or ',' - default is '.'). Pass false for integers
 * @param    callback     A function that runs if the number is not valid (fires onblur)
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $(".numeric").numeric();
 * @example  $(".numeric").numeric(",");
 * @example  $(".numeric").numeric(null, callback);
 *
 */
$.fn.numeric = function(decimal, callback)
{
	decimal = (decimal === false) ? "" : decimal || ".";
	callback = typeof callback == "function" ? callback : function(){};
	return this.data("numeric.decimal", decimal).data("numeric.callback", callback).keypress($.fn.numeric.keypress).blur($.fn.numeric.blur);
}

$.fn.numeric.keypress = function(e)
{
	var decimal = $.data(this, "numeric.decimal");
	var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
	// allow enter/return key (only when in an input box)
	if(key == 13 && this.nodeName.toLowerCase() == "input")
	{
		return true;
	}
	else if(key == 13)
	{
		return false;
	}
	var allow = false;
	// allow Ctrl+A
	if((e.ctrlKey && key == 97 /* firefox */) || (e.ctrlKey && key == 65) /* opera */) return true;
	// allow Ctrl+X (cut)
	if((e.ctrlKey && key == 120 /* firefox */) || (e.ctrlKey && key == 88) /* opera */) return true;
	// allow Ctrl+C (copy)
	if((e.ctrlKey && key == 99 /* firefox */) || (e.ctrlKey && key == 67) /* opera */) return true;
	// allow Ctrl+Z (undo)
	if((e.ctrlKey && key == 122 /* firefox */) || (e.ctrlKey && key == 90) /* opera */) return true;
	// allow or deny Ctrl+V (paste), Shift+Ins
	if((e.ctrlKey && key == 118 /* firefox */) || (e.ctrlKey && key == 86) /* opera */
	|| (e.shiftKey && key == 45)) return true;
	// if a number was not pressed
	if(key < 48 || key > 57)
	{
		/* '-' only allowed at start */
		if(key == 45 && this.value.length == 0) return true;
		/* only one decimal separator allowed */
		if(decimal && key == decimal.charCodeAt(0) && this.value.indexOf(decimal) != -1)
		{
			allow = false;
		}
		// check for other keys that have special purposes
		if(
			key != 8 /* backspace */ &&
			key != 9 /* tab */ &&
			key != 13 /* enter */ &&
			key != 35 /* end */ &&
			key != 36 /* home */ &&
			key != 37 /* left */ &&
			key != 39 /* right */ &&
			key != 46 /* del */
		)
		{
			allow = false;
		}
		else
		{
			// for detecting special keys (listed above)
			// IE does not support 'charCode' and ignores them in keypress anyway
			if(typeof e.charCode != "undefined")
			{
				// special keys have 'keyCode' and 'which' the same (e.g. backspace)
				if(e.keyCode == e.which && e.which != 0)
				{
					allow = true;
					// . and delete share the same code, don't allow . (will be set to true later if it is the decimal point)
					if(e.which == 46) allow = false;
				}
				// or keyCode != 0 and 'charCode'/'which' = 0
				else if(e.keyCode != 0 && e.charCode == 0 && e.which == 0)
				{
					allow = true;
				}
			}
		}
		// if key pressed is the decimal and it is not already in the field
		if(decimal && key == decimal.charCodeAt(0))
		{
			if(this.value.indexOf(decimal) == -1)
			{
				allow = true;
			}
			else
			{
				allow = false;
			}
		}
	}
	else
	{
		allow = true;
	}
	return allow;
}

$.fn.numeric.blur = function()
{
	var decimal = $.data(this, "numeric.decimal");
	var callback = $.data(this, "numeric.callback");
	var val = $(this).val();
	if(val != "")
	{
		var re = new RegExp("^\\d+$|\\d*" + decimal + "\\d+");
		if(!re.exec(val))
		{
			callback.apply(this);
		}
	}
}

$.fn.removeNumeric = function()
{
	return this.data("numeric.decimal", null).data("numeric.callback", null).unbind("keypress", $.fn.numeric.keypress).unbind("blur", $.fn.numeric.blur);
}

})(jQuery);
