/* Nieuwsbrief */
var nbscriptlocation = "/includes/nieuwsbrief.php";

function postNB() {

    var email = jQuery("#nb_form_home [name='email']").val();

    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (email.length<2 || email=="e-mailadres" || !filter.test(email) ) {
        alert("Geef een geldig e-mailadres op!");
        return;
    }

    jQuery.ajax({
        type: "POST",
        url: nbscriptlocation,
        dataType: "json",
        data: {'function':"add_NB", 'listname':"TMF Nieuwsbrief", 'email':email },
        success: function(result){
            if (result[0]==1) {
                // OK!
                jQuery("#nb_form_home").hide().html(result[1]).slideDown('slow');
                //jQuery("#nb_form_home").hide();
            }
        }
    });

    return false;
}

/* Musicpanel */
function postMP() {

    var email = jQuery("#mp_form_home [name='emailmp']").val();

    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (email.length<2 || email=="e-mailadres" || !filter.test(email) ) {
        alert("Geef een geldig e-mailadres op!");
        return;
    }

    jQuery.ajax({
        type: "POST",
        url: nbscriptlocation,
        dataType: "json",
        data: {'function':"add_NB", 'listname':"TMF Musicpanel", 'email':email },
        success: function(result){
            if (result[0]==1) {
                // OK!
                jQuery("#mp_form_home").hide().html(result[1]).slideDown('slow');
                //jQuery("#nb_form_home").hide();
            }
        }
    });

    return false;
}


/* Frequentie zoeker */
function findValue(li) {
	if( li == null ) return alert("Geen match!");

	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;

	alert("Jouw frequentie is: " + sValue);
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0];
}

function lookupAjax(){
	var oSuggest = $("#frequentie_lookup")[0].autocompleter;

	oSuggest.findValue();

	return false;
}

$(document).ready(function() {
	$("#frequentie_lookup").autocomplete(
		"includes/_autocomp_frequentie.php",
		{
			delay:10,
			minChars:2,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			maxItemsToShow:8,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:true
		}
	);
	
	$("a.fancybox").fancybox();
	
	$('a.iframe').each(function(){  
		var dWidth = parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));  
		var dHeight =  parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));  
		$(this).fancybox({  
			'width' : dWidth,  
			'height' : dHeight,  
			'autoScale' :  true,  
		    'type' : 'iframe'  
		});  
	});

});

/* hotornot vote */
// Stem voor een hotornot, en ververs deze, via een Ajax updater.
function hotornotvote(uid) {
	var votevalue=value='';

	// get form
	jQuery("#hotornotform input[type=radio]").each(
		function() {
			if (this.checked) {
				votevalue = this.value;
			}
		}
	)

	if(votevalue=='') {
		alert('Je moet natuurlijk wel een keuze maken.');
		return false;
	} else {
		jQuery("#hotornot"+uid).load('/includes/_ajax_hotornot.php?uid='+escape(uid)+'&vote='+escape(votevalue));
	}

}

// Toon een hotornot, via een dynamische Ajax updater.
function hotornotview(uid) {
	jQuery("#hotornot"+uid).load('/includes/_ajax_hotornot.php?uid='+escape(uid));
}
/* end hotornot vote */

/* poll vote */
// Stem voor een poll, en ververs deze, via een Ajax updater.
function pollvote(uid) {
	var votevalue=value='';

	// get form
	jQuery("#pollform input[type=radio]").each(
		function() {
			if (this.checked) {
				votevalue = this.value;
			}
		}
	)

	if(votevalue=='') {
		alert('Je moet natuurlijk wel een keuze maken.');
		return false;
	} else {
		jQuery("#poll"+uid).load('/includes/_ajax_poll.php?uid='+escape(uid)+'&vote='+escape(votevalue));
	}

}

// Toon een poll, via een dynamische Ajax updater.
function pollview(uid) {
	jQuery("#poll"+uid).load('/includes/_ajax_poll.php?uid='+escape(uid));
}
/* end poll vote */

/* fiveatfive vote */
//  Stem voor een track en ververs deze via een Ajax updater.
function fiveatfive(){                                             
    
    var track = jQuery("#fiveatfiveform [name='track']").val();    
    
    jQuery("#fiveatfive").load('/includes/_ajax_fiveatfive.php?track='+escape(track));    
}

//Popup voor games 
function popUp(page) {
    newWindow = window.open(page,'newWindow','width=700,height=500,scrollbars=no,status=no,toolbar=no,resizable=no,location=no,menubar=no,directories=no' );
    newWindow.focus();
}
