$(document).ready(function(){
    $.ajaxSetup({
    	cache: false
    });
    /** Double load check **/
    if($('body').attr('authCheck') == true)return;
    $('body').attr('authCheck',true);

    /*
     * Checking for logged in user for logonComponent
     */
    // retrieving cookie
    var cookie = $.cookie("jcmUserCookie");
    if (cookie != null && cookie != '' && cookie != 'undefined') {
         $("#ghost").load("/dyncomponent/template/loggedLogonComponent.html");
    } else {
    
   
    	/** Check page autorizations **/
    	
    	var keywds = $('meta[name=keywords]').attr('content');
    	
   	if(keywds.indexOf("%%LOGGED%%") != -1){
   		url = $('meta[name=description]').attr('content');
   		if(url.indexOf('url(') == -1){
   			window.location = "/index-registration.html";
   			return;
   		} else {
   			url = url.substring(url.indexOf('url(')+4);
   			url = url.substring(0,url.indexOf(')'));
   			if (url == "/index-registration.html") {
				url = "/richieste/richiesta-registrazione.html"
			}
   			window.location = url;
   			return;
   		}
   	}
    
    
    
        $("#ghost").load("/dyncomponent/template/logonComponent.html");
    }

});
