var Url = window.location.href.split("/");
var subscribe_url_nl = "http://www.denhaagstudentenstad.nl/nl/bedankt-voor-je-inschrijving";
var subscribe_url_gb = "http://www.denhaagstudentenstad.nl/gb/thanks-for-your-subscription";

var fnames = new Array();var ftypes = new Array();fnames[1]='FNAME';ftypes[1]='text';fnames[0]='EMAIL';ftypes[0]='email';var err_style = '';
try{
    err_style = mc_custom_error_style;
} catch(e){
    err_style = 'margin: 1em 0 0 0; padding: 1em 0.5em 0.5em 0.5em; background: ERROR_BGCOLOR none repeat scroll 0% 0%; font-weight: bold; float: left; z-index: 1; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: ERROR_COLOR;';
}
//var mce_jQuery = jQuery.noConflict();
$(document).ready( function($) {

	if($(".autoform").size()>0){
		$(".autoform").validate();
	}
	if($('.datepickers').size()){
		$('.datepickers').datepicker();
	}
	
	if($("#serachvalue").length>0){
	  $("li div").highlight($("#serachvalue").html());
	}

	$("#footer>a").bind("click",function(){
		$("html, body").animate({scrollTop:"0px"}, "slow");
		return false;
	});
	$("#search_input, #mce-FNAME, #mce-EMAIL").bind("focus blur",function(event){
		if(event.type=="focus"){
			$(this).removeClass("inactive");
			if($(this).val()==$(this).attr("title")){
				$(this).val("");
			}
		}else if(event.type=="blur"&&$(this).val()==""){
			$(this).val($(this).attr("title")).addClass("inactive");
		}
	});


  var options = { errorClass: 'mce_inline_error', errorElement: 'div', errorStyle: err_style, onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
  var mce_validator = $("#mc-embedded-subscribe-form").validate(options);
  var ajax_url = Url[3]=="gb"?"http://stichtingstudentensteden.us1.list-manage.com/subscribe/post-json?u=5b64558daca5ae63ede2575f9&id=245a57518a&c=?":'http://stichtingstudentensteden.us1.list-manage1.com/subscribe/post-json?u=5b64558daca5ae63ede2575f9&id=8a56b9d226&c=?'
  options = { url: ajax_url, type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",
                beforeSubmit: function(){
                    $('#mce_tmp_error_msg').remove();
                    $('.datefield','#mc_embed_signup').each(
                        function(){
                            var txt = 'filled';
                            var fields = new Array();
                            var i = 0;
                            $(':text', this).each(
                                function(){
                                    fields[i] = this;
                                    i++;
                                });
                            $(':hidden', this).each(
                                function(){
                                	if ( fields[0].value=='MM' && fields[1].value=='DD' && fields[2].value=='YYYY' ){
                                		this.value = '';
									} else if ( fields[0].value=='' && fields[1].value=='' && fields[2].value=='' ){
                                		this.value = '';
									} else {
	                                    this.value = fields[0].value+'/'+fields[1].value+'/'+fields[2].value;
	                                }
                                });
                        });
                    return mce_validator.form();
                },
                success: mce_success_cb
            };
  $('#mc-embedded-subscribe-form').ajaxForm(options);

});
function mce_success_cb(resp){
    $('#mce-success-response').hide();
    $('#mce-error-response').hide();
    if (resp.result=="success"){
	window.location.href = eval((Url[3]=="gb"?"subscribe_url_gb":"subscribe_url_nl"));
        $('#mc-embedded-subscribe-form').each(function(){
            this.reset();
    	});
    } else {
        var index = -1;
        var msg;
        try {
            var parts = resp.msg.split(' - ',2);
            if (parts[1]==undefined){
                msg = resp.msg;
            } else {
                i = parseInt(parts[0]);
                if (i.toString() == parts[0]){
                    index = parts[0];
                    msg = parts[1];
                } else {
                    index = -1;
                    msg = resp.msg;
                }
            }
        } catch(e){
            index = -1;
            msg = resp.msg;
        }
        try{
            if (index== -1){
                $('#mce-'+resp.result+'-response').show();
                $('#mce-'+resp.result+'-response').html(msg);
            } else {
                err_id = 'mce_tmp_error_msg';
                html = '<div id="'+err_id+'" style="'+err_style+'"> '+msg+'</div>';

                var input_id = '#mc_embed_signup';
                var f = $(input_id);
                if (ftypes[index]=='address'){
                    input_id = '#mce-'+fnames[index]+'-addr1';
                    f = $(input_id).parent().parent().get(0);
                } else if (ftypes[index]=='date'){
                    input_id = '#mce-'+fnames[index]+'-month';
                    f = $(input_id).parent().parent().get(0);
                } else {
                    input_id = '#mce-'+fnames[index];
                    f = $().parent(input_id).get(0);
                }
                if (f){
                    $(f).append(html);
                    $(input_id).focus();
                } else {
                    $('#mce-'+resp.result+'-response').show();
                    $('#mce-'+resp.result+'-response').html(msg);
                }
            }
        } catch(e){
            $('#mce-'+resp.result+'-response').show();
            $('#mce-'+resp.result+'-response').html(msg);
        }
    }
}

var mc_custom_error_style = '';
//--sIfr
 var cochin = {
      src: '/scripts/sifr.swf'
      ,ratios: [7, 1.32, 11, 1.31, 13, 1.24, 14, 1.25, 19, 1.23, 27, 1.2, 34, 1.19, 42, 1.18, 47, 1.17, 48, 1.18, 69, 1.17, 74, 1.16, 75, 1.17, 1.16]
    };
    // You probably want to switch this on, but read <http://wiki.novemberborn.net/sifr3/DetectingCSSLoad> first.
    sIFR.useStyleCheck = true;
    sIFR.activate(cochin);

    sIFR.replace(cochin, {selector: 'h1',wmode: 'transparent',css: [ '.sIFR-root {text-decoration:none;}' ]});


