//Prevent spambots from harvesting email addresses
function TL_writeEmail(theUser,theDomain,theName) {
	if(theName!=''){ 
		document.write('<a class="black" href=\"mailto:'+theUser+'@'+theDomain+'\">'+theName+'</a>');
	} else {
		document.write('<a class="black" href=\"mailto:'+theUser+'@'+theDomain+'\">'+theUser+'@'+theDomain+'</a>');
	}
}

function evaluateForm () {

	var html_replacement = '';

	//radio buttons
	if (document.frm.cat_id[3].checked) {
		html_replacement = '<ol class="subsublist">';
		html_replacement += '	<li>lid 2, geboren (ddmmjj): <input size="2" maxlength="2" type="text" name="dagA" value="" /><input size="2" maxlength="2" type="text" name="maandA" value="" /><input size="4" maxlength="4" type="text" name="jaarA" value="" /> Naam: <input type="text" name="NaamA" value="" /></li>';
		html_replacement += '	<li>lid 3, geboren (ddmmjj): <input size="2" maxlength="2" type="text" name="dagB" value="" /><input size="2" maxlength="2" type="text" name="maandB" value="" /><input size="4" maxlength="4" type="text" name="jaarB" value="" /> Naam: <input type="text" name="NaamB" value="" /></li>';
		html_replacement += '	<li>lid 4, geboren (ddmmjj): <input size="2" maxlength="2" type="text" name="dagC" value="" /><input size="2" maxlength="2" type="text" name="maandC" value="" /><input size="4" maxlength="4" type="text" name="jaarC" value="" /> Naam: <input type="text" name="NaamC" value="" /></li>';
		html_replacement += '</ol>';
		html_replacement += '<p class="cursief">Een gezinslidmaatschap bestaat uit maximaal 2 volwassenen en 2 kinderen t/m 15 jaar, woonachtig op zelfde adres als inschrijver. Voor leef tijdsafhankelijke indeling in een categorie geldt als datum de leeftijd op 1 juli van het lopende jaar.</p>';
	}
	
	var element = document.getElementById("gezinslidmaatschap"); 
    element.innerHTML = html_replacement;
}

var SITE = {};

SITE.functionality = {

	ajaxURL: '/wp-content/themes/vriendenkring/scripts/ajax/',
	animationSpeed: 1000,
	tellafriendOn: false,
	debug: true,
	
	init: function() {
	
		Cufon.replace('h1 span');
		Cufon.replace('h4 span');  	
	
		this.emphasizeNav();
		
		this._moveSocialBookmarks();
		
		this.goForms();
		
		if($("#mail_ico")) {
			$("#mail_ico").bind("click",SITE.functionality.tellafriend);
		}
		
		if( $("#TweetSpot")) {
			 $("#TweetSpot").jTweetr('VKfctwente', { Title: '', SearchType: TweetTypes.From });
		}
		
	},
	
	_moveSocialBookmarks: function() {
		if($('.social_bookmark')) {
			var socialBookmarks = $('.social_bookmark').html();
			$('#clickbox').append(socialBookmarks);
			$('.social_bookmark').remove();
		}
	},	
	
	goForms: function () {
		if($("#inschrijfForm")) {
			$("#inschrijfForm").validate();
		}
		if($("#inlogForm")) {
			$("#inlogForm").validate();
		}
		if($("#pwdForm")) {
			$("#pwdForm").validate();
		}				
		if($("#vraagstellenForm")) {
			$("#vraagstellenForm").validate();
		}
		if($("#koppelForm")) {
			$("#koppelForm").validate();
		}
		if($("#gegevensForm")) {
			$("#gegevensForm").validate();
		}		
		if($("#registratieForm")) {
			$("#registratieForm").validate({
				rules: {
					username: {
						required: true,
						remote: SITE.functionality.ajaxURL + "unique_field.php"
					}, 
					password: {
						required: true
					},				
					email: {
						required: true,
						email: true,
						remote: SITE.functionality.ajaxURL + "unique_field.php"
					}
				},
        messages: {
					username: {
						remote: "Deze naam is al in gebruik."
					},
					email: {
						remote: "Dit e-mailadres is al in gebruik."
					}				
				}
			});
		}		
	},
	
	switchElement: function( pElement, pClickedElement ) {
		if(pClickedElement.checked == true) {
			$("#" + pElement).show(this.animationSpeed);
		} else {
			$("#" + pElement).hide(this.animationSpeed);
		}
	},
	
	toggleElement: function( pElement ) {
		var isHidden = $("#" + pElement).is(':hidden');
		
		if(isHidden) {
			$("#" + pElement).show(this.animationSpeed);
		} else {
			$("#" + pElement).hide(this.animationSpeed);
		}
		
	},
	
	tellafriend: function (oE) {
		if(SITE.functionality.tellafriendOn) {
			$('#tellafriendform').hide(SITE.functionality.animationSpeed);
			SITE.functionality.tellafriendOn = false;
		} else {
			$('#tellafriendform').show(SITE.functionality.animationSpeed);
			SITE.functionality.tellafriendOn = true;
		}
		return false;
	},	
	

	emphasizeNav: function() {
		if($('#sitenavigation')) {
			$('#sitenavigation').find('a').wrap('<em></em>');
		}
	},
	
	setParentPageToCurrent: function ( pID ) {
		var menuItem = $('#sitenavigation').find('.page-item-' + pID );
		if (!menuItem.hasClass('current_page_item')) {
			menuItem.toggleClass('current_page_item');		
		}
	},
	
	trace: function (trace) {
		if (SITE.functionality.debug) {
			if(typeof console =='object') {
				if(typeof trace =='string' || typeof console.dir !='function'){
					console.info("Trace: "+trace);
				}else{
					console.dir(trace);
				}
			}
		}
	}
}	