//alert box spécial page subscribe
AG.prototype.alertScroll={
        lock:false,
        open:function(message){
            if(ag.alertScroll.lock == false){
                var targetWidth = (ag.browser.isIE())?(document.body.clientWidth):(window.innerWidth-18);
                var targetHeight = getHeight();
                if($('agTgtAlertLoadingScreen'))
                {
                    $('agTgtAlertLoadingScreen').style.top = 0;
                    $('agTgtAlertLoadingScreen').style.left = 0;
                    $('agTgtAlertLoadingScreen').style.width = targetWidth +'px';
                    $('agTgtAlertLoadingScreen').style.height = targetHeight+'px';
                    $('agTgtAlertLoadingScreen').style.display = 'block';
                    $('agTgtAlertLoadingScreen').style.zIndex = '300';
                }
                else
                {
                    var loadingScreen = ag.dom.createElement(
                    'div',
                    {
                        id:'agTgtAlertLoadingScreen',
                        className:'loading_screen'
                    },
                    {
                        top:0,
                        left:0,
                        width:targetWidth+'px',
                        height:targetHeight+'px',
                        display:'block',
                        zIndex:'300'
                    },
                    $T('BODY')[0]
                    );
                }
                //loadingScreen.style.display = 'block';
                //ag.loading.display();
                ag.alertScroll.lock = true;
                $('AgTgtAlertBox').style.filter = "Alpha(opacity=0)";
                $('AgTgtAlertBox').style.opacity = 0;
				$('AgTgtAlertBox').style.top=(getYScrolPos()+100)+'px';
                $('AgTgtAlertContent').innerHTML = message;
                $('AgTgtAlertContainer').style.display = 'block';
                animateCSS($('AgTgtAlertBox'),12,10,{
                    opacity:function(frame,time){
                        $('AgTgtAlertBox').style.filter = "Alpha(opacity="+(frame*8)+")";
                        return (frame*8)/100;
                    }
                },
                function(element){
                    $('AgTgtAlertBox').style.filter = '';
                    $('AgTgtAlertBox').style.opacity = '';
                    ag.alertScroll.lock=false;
                }
                );
            }
        },
        close:function(){
            $('agTgtAlertLoadingScreen').style.display = 'none';
            $('AgTgtAlertContainer').style.display = 'none';
            $('AgTgtAlertBox').style.opacity = 0;
            $('AgTgtAlertContent').innerHTML = '';
        }
    }
    
function getHeight() {
	if (document.documentElement.scrollHeight) {
		return document.documentElement.scrollHeight;
		}
	else if (document.body.scrollHeight) {
		return  document.body.scrollHeight;
		}
	}
function getYScrolPos() {
	if (document.documentElement.clientWidth) {
	 return document.documentElement.scrollTop;
	}
	//firefox
	else if (window.screenY) {
		return window.screenY
	}
}


function check_default_subscribe()
{
    if ( $('subscribe_table_info_2').style.display == 'none')
    {
        if (check_login_form() && check_password_form() && check_password2_form() && check_email_form())
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        if (check_login_form() && check_password_form() && check_password2_form() && check_email_form() && check_lastname_form() && check_firstname_form() && check_company_form() && check_phone_form() && check_address_form() && check_postal_form() && check_city_form() && check_country_form() && check_cgu())
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

function check_options_subscribe()
{
    if (check_lastname_form() && check_firstname_form() && check_company_form() && check_phone_form() && check_address_form() && check_postal_form() && check_city_form() && check_country_form())
    {
        return true;
    }
    else
    {
        return false;
    }
}

function check_login_form()
{
    var elem;
    elem = $('login');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_LOGIN'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_LOGIN'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 32 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_LOGIN'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_LOGIN'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.value.search("[^A-Za-z0-9]") >= 0 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_ALPHANUM_LOGIN'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_ALPHANUM_LOGIN'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_password_form()
{
    var elem;
    elem = $('password');
    if ( elem.value == "" || elem.value.length < 6 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_MINI_PASSWORD'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_MINI_PASSWORD'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 45 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_PASSWORD'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_PASSWORD'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.value.search("[^A-Za-z0-9]") >= 0 )
    {
        //ag.alertScroll.open(txt('subscribe|SUBSCRIBE_ERR_ALPHANUM_PASSWORD'));
        alert(txt('subscribe|SUBSCRIBE_ERR_ALPHANUM_PASSWORD'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_password2_form()
{
    var elem;
    elem = $('password2');
    if ( elem.value != $('password').value )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_DIFFERENT_PASSWORD'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_DIFFERENT_PASSWORD'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_email_form()
{
    var elem;
    elem = $('email');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_EMAIL'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_EMAIL'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_EMAIL'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_EMAIL'));
        elem.focus();
        elem.select();
        return false;
    }
    var re = /^\w+([\+\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
    if (re.test(elem.value) == false)
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_INVALID_EMAIL'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_INVALID_EMAIL'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_code_form()
{
    var elem;
    elem = $('code');
    if ( elem.value == '' )
    {
        return true;
    }
    if ( elem.length != 32 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_CODE'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_CODE'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_lastname_form()
{
    var elem;
    elem = $('lastname');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_LASTNAME'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_LASTNAME'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_LASTNAME'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_LASTNAME'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_firstname_form()
{
    var elem;
    elem = $('firstname');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_FIRSTNAME'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_FIRSTNAME'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_FIRSTNAME'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_FIRSTNAME'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_company_form()
{
    var elem;
    elem = $('company');
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_COMPANY'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_COMPANY'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_phone_form()
{
    var elem;
    elem = $('phone');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_PHONE'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_PHONE'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.value.search("[^0-9]") >= 0 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_PHONE'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_PHONE'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_PHONE'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_PHONE'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_address_form()
{
    var elem;
    elem = $('address');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_ADDRESS'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_ADDRESS'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_ADDRESS'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_ADDRESS'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_postal_form()
{
    var elem;
    elem = $('postal');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_POSTAL'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_POSTAL'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_POSTAL'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_POSTAL'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_city_form()
{
    var elem;
    elem = $('city');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_CITY'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_CITY'));
        elem.focus();
        elem.select();
        return false;
    }
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_CITY'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_CITY'));
        elem.focus();
        elem.select();
        return false;
    }
    return true;
}

function check_country_form()
{
    var elem;
    elem = $('country');
    if ( elem.value == "" )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_COUNTRY'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_EMPTY_COUNTRY'));
        elem.focus();
        return false;
    }
    if ( elem.length > 255 )
    {
        //ag.alertScroll.open(txt('default-subscribe|SUBSCRIBE_ERR_FULL_COUNTRY'));
        alert(txt('default-subscribe|SUBSCRIBE_ERR_FULL_COUNTRY'));
        elem.focus();
        return false;
    }
    return true;
}

function check_cgu()
{
    var elem;
    elem = $('accept_cgu');
    if ( elem.checked == false )
    {
        //ag.alertScroll.open(txt('default-signin|ERR_ACCEPT_CGU'));
        alert(txt('default-signin|ERR_ACCEPT_CGU'));
        elem.focus();
        return false;
    }

    return true;
}