/*
 * Javascript observers
 */
var candidate;
var curriculum;
var search1;
var general;
var addthis_config = {ui_language: "nl"}
window.onload = function(){
    //document.observe('dom:loaded',  function(e){
    if($('player') != null){flowplayer("player", "/js/flowplayer-3.0.3.swf");}

    if($("candidate_login_form")!=null){
        $('candidate_login_form').observe('submit',  function(e){
            e.stop(); // To avoid submission process
            new Ajax.Updater($('user_login_block'), this.action, {
                method: 'post',
                parameters: this.serialize(),
                evalScripts: true,
                onLoading: function(){
                    $('candidate_login_submit').replace($('loading').innerHTML);
                },
                onFailure: function(request, exception){
                    $('user_login_block').update($('unexpected_error').innerHTML);
                }
            });
        });
    }
    /*
     * General Functions
     */
    general = {
        cleanUsser: function() {
            if( $F("username")=='Emailadres')
                $('username').value='';
        },
        cleanPass: function() {
            if( $F("password")=='1111')
                $('password').value='';
        }
    };
    /**
     * Search functions
     */
    search1 = {
        search_regio: function() {
            var regio_select=new Array();
            var i;
            i=0;
            //alert( $('Noord').checked);
            if($('Noord').checked==true) {
                regio_select[i]= $F('Noord');
                i++;
            }
            if($('Oost').checked==true) {
                regio_select[i]= $F('Oost');
                i++;
            }
            if($('West').checked==true) {
                regio_select[i]= $F('West');
                i++;
            }
            if($('Midden').checked==true) {
                regio_select[i]= $F('Midden');
                i++;
            }
            if($('Zuid').checked==true) {
                regio_select[i]= $F('Zuid');
                i++;
            }
            if(regio_select.length>0)
                $('regio').value=regio_select.join(',');
            else
                $('regio').value='';
            return true;
        }
    };
    /**
 * Candidate functions
 */
    candidate = {
        /**
     * Applies to a vacancy
     */
        apply: function(vacancy){
            //new Ajax.Updater($('apply_to_vacancy_dialogue'), '<?php //echo url_for('candidate/apply') ?>', {
//            new Ajax.Updater($('apply_to_vacancy_dialogue'), '/candidate/apply', {
	    new Ajax.Request('/candidate/apply', {
                method: 'get',
                parameters: {
                    vacancy: vacancy
                },
                evalScripts: true,
                onLoading: function(){
                    $('apply_to_vacancy_dialogue').update($('loading').innerHTML + ' Uw aanvraag wordt verwerkt...');
                },
                onFailure: function(request, exception){
                    $('apply_to_vacancy_dialogue').update($('unexpected_error').innerHTML);
                },
		onSuccess: function(transport){
			$('apply_to_vacancy_dialogue').update(transport.responseText)
		}
            });
        },
        index: function(vacancy){
            window.location.href='/contact/index/vacatures/'+vacancy;
        }
    }
    
curriculum = {
    limpiar: function(){
        var $j = jQuery.noConflict();

        $j('input[type=text][class="inputTextClassCvIn inputPartial"]').each(function(index) {
            $j(this).val('');
        });
        $j('textarea[class="inputTextAreaClassCvIn inputPartial"]').each(function(index) {
            $j(this).val('');
        });
        $j('textarea[class="inputTextAreaClassCv inputPartial"]').each(function(index) {
            $j(this).val('');
        });
        $j('select[class="inputPartial"]').each(function(index) {
            $j(this).val('');
        });
        $j('select[class="inputPartial1"]').each(function(index) {
            $j(this).val(2);
        });
    }
}
    /**
 * Looks for login event in order to perform actions
 */
    document.observe('user:signin',  function(e){
        /**
     * Check if the user tried to apply for a vacancy so we can display again
     * the apply link.
     */
        if($('login_to_apply'))
        {
            candidate.apply($('vacancy_to_apply').innerHTML);
            new Effect.Highlight('apply_to_vacancy_dialogue', {
                duration: 5
            });
        }
    });

    /**
 * updates news feed every 10 seconds
 */
    new PeriodicalExecuter(function(){
        //new Ajax.Request('<?php //echo url_for('news/feed') ?>',{
        new Ajax.Request('/news/feed',{
            method: 'get',
            onSuccess: function(transport){
                new Effect.Fade('news_feed', {
                    afterFinish: function()
                    {
                        $('news_feed').update(transport.responseText);
                        new Effect.Appear('news_feed');
                    }
                });
            }
        });
    }, 10);
//});
}

