
function checkEnterAndSubmit(e, formId){ 
    var characterCode;
    if(e && e.which){ //if which property of event object is supported (NN4)
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else{
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }
    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        document.getElementById(formId).submit(); //submit the form
        return false;
    }
    else{
        return true;
    }
}

function center(element, offsetX, offsetY){
    //set default values
    offsetX = offsetX || 0;
    offsetY = offsetY || 0;
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
        ( document.documentElement.clientWidth ||
            document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
        ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + offsetX + "px";
    element.style.top  = setY + offsetY + "px";
}

function updateClock ( )
{
    var currentTime = new Date ( );

    var currentYear = currentTime.getFullYear ( );
    var currentMonth = currentTime.getMonth ( ) + 1
    var currentDay = currentTime.getDate ( );
    var currentHours = currentTime.getHours ( );
    var currentMinutes = currentTime.getMinutes ( );
    var currentSeconds = currentTime.getSeconds ( );

    // Choose either "AM" or "PM" as appropriate
    var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

    // Pad the minutes and seconds with leading zeros, if required
    currentMonth = ( currentMonth < 10 ? "0" : "" ) + currentMonth;
    currentDay = ( currentDay < 10 ? "0" : "" ) + currentDay;
    currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours;
    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

    // Compose the string for display
    var currentTimeString = currentDay + "/" + currentMonth + "/" + currentYear + " " + currentHours + ":" + currentMinutes + ":" + currentSeconds;

// Update the time display
//document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}


function setCookie( name, value, expires, path, domain, secure ){
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
    if ( expires )
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );

}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function getCookie( check_name ) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split( '=' );


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if ( a_temp_cookie.length > 1 )
            {
                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if ( !b_cookie_found )
    {
        return null;
    }
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
    if ( getCookie( name ) ) document.cookie = name + "=" +
        ( ( path ) ? ";path=" + path : "") +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


$j(document).ready(function(){


    if ( getCookie( 'footerCollapsed' ) && getCookie( 'footerCollapsed' )=='yes' ) closeFooter();

    $$('a[rel="external"]').each(function(link) {
        if(link.readAttribute('href') != '' && link.readAttribute('href') != '#'){
            link.onclick = function(el) {
                window.open(link.href);
                return false;
            }
        }
    });

    //setInterval('updateClock()', 1000 );
    
    jQuery('#out').click(function(){
        jQuery('.logout_form').submit(); 
    });
    
    jQuery('#open_balance_det').click(function(){
        center('balance_det_popup');  
        jQuery('#balance_det_popup').show();
    });
                        
    var mouse_is_inside = false;
          
    jQuery('#myAccMenuHolder, #myAccMenu').hover(function(){ 
        mouse_is_inside=true; 
    }, function(){ 
        mouse_is_inside=false; 
    });

    jQuery("body").mouseup(function(){ 
        if(! mouse_is_inside) jQuery('#myAccMenuHolder').hide();
    });  
                    
    jQuery('#currentItem, #popOut').click(function(){
        jQuery('#myAccMenuHolder').toggle();
    });              

});



function closeFooter() {
    $j('#footer_collapse').slideUp();
    $j('#footer_bar_left_up').hide();
    $j('#footer_bar_left_down').show();
    setCookie( 'footerCollapsed', 'yes', '', '/', '', '' );
}
function openFooter() {
    $j('#footer_collapse').slideDown();
    $j('#footer_bar_left_up').show();
    $j('#footer_bar_left_down').hide();
    setCookie( 'footerCollapsed', 'no', '', '/', '', '' );
}

function getCurrentYPos() {
    if (document.body && document.body.scrollTop)
        return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
        return document.documentElement.scrollTop;
    if (window.pageYOffset)
        return window.pageYOffset;
    return 0;
}
function scroll_up_fix() {
    if (getCurrentYPos() > 768)
        window.scrollTo(0, document.getElementById('body_container').offsetTop);
}
function side_bar_fix() {
    return;
    var h = document.getElementById('body_content').clientHeight;
    document.getElementById('side_bar_foot_fill').style.height= h + 'px'
}

function closeFrame(){
    document.getElementById('popupHolder').style.display = "none";
    document.getElementById('overlayBody').style.display = "none";
    window.location.href = "http://www.netbetsport.it";
}

function calc_cf() {
    var name = document.getElementById('firstname').value;
    if(name=='') 
        document.getElementById('firstname').style.border = '1px solid #ff0000';
    else {
        document.getElementById('firstname').style.border = '1px #b2b2b2 solid';
        name = name.replace('\'','');
        name = name.replace('ò','o');
        name = name.replace('à','a');
        name = name.replace('è','e');
        name = name.replace('ì','i');
        name = name.replace('é','e');
        name = name.replace('ù','u');
    }
    
    var surname = document.getElementById('surname').value;
    if(surname=='') 
        document.getElementById('surname').style.border = '1px solid #ff0000';
    else {
        document.getElementById('surname').style.border = '1px #b2b2b2 solid';
        surname = surname.replace('\'','');
        surname = surname.replace('ò','o');
        surname = surname.replace('à','a');
        surname = surname.replace('è','e');
        surname = surname.replace('ì','i');
        surname = surname.replace('é','e');
        surname = surname.replace('ù','u');
    }
    
    var day = document.getElementById('dob_day').value;
    if(day=='0') 
        document.getElementById('dob_day').style.border = '1px solid #ff0000';
    else document.getElementById('dob_day').style.border = '1px #b2b2b2 solid';
    
    var month = document.getElementById('dob_month').value;
    if(month=='0') 
        document.getElementById('dob_month').style.border = '1px solid #ff0000';
    else document.getElementById('dob_month').style.border = '1px #b2b2b2 solid';
    
    var year = document.getElementById('dob_year').value;
    if(year=='0') 
        document.getElementById('dob_year').style.border = '1px solid #ff0000';
    else document.getElementById('dob_year').style.border = '1px #b2b2b2 solid';
    
    var country = document.getElementById('country_of_birth').value;
    if(country == "ITALIA")
        var town = document.getElementById('location_of_birth').value;
    else var town = country;
    
    var gender = (document.getElementById('sexm').checked)?0:1;
    
    if(name!='' && surname!='' && day!='0' && month!='0' && year!='0'){
        var $jqx = jQuery.noConflict();
        $jqx.post("/modules/calculate_cf/index.php", {
            nome: name, 
            cognome: surname, 
            giorno: day, 
            mese: month, 
            anno: year, 
            sesso: gender, 
            luogo: town
        }, function(data) {
            document.getElementById('fiscal_code').style.border = '1px #b2b2b2 solid';
            document.getElementById('fiscal_code').value = data;
            jQuery('#error_fiscal_code').hide();
            jQuery('#fiscal_code').parent().children('[id^="feedicon"]').attr('class','chk');
            jQuery('#fiscal_code').parent().children('[id^="feedicon"]').show();
        });
    } else {
        document.getElementById('fiscal_code').style.border = '1px solid #ff0000';
        document.getElementById('fiscal_code').value = '';
        jQuery('#fiscal_code').parent().children('[id^="feedicon"]').attr('class','crs');
        jQuery('#fiscal_code').parent().children('[id^="feedicon"]').show();
    }	
}

jQuery(document).ready(
    function(){
        jQuery('#top_menu_help').click(
            function(){
                return false;
            }
    
            );
    }
    );
