var navigateTo = 'http://www.gmxmarket.com/gmx';

function pageTracker(){
    try {
        var pageTracker = _gat._getTracker("UA-5600256-24");
        pageTracker._trackPageview();
    } catch(err) {}
}

/*This method opens the privacy policy jsf*/
function openwindow()
{
    window.open("/privacy-policy","mywindow","location=1,status=1,scrollbars=1,menubar=1,resizable=1,width=1000,height=480");
}

/*This function authenticates the beta user*/
function navigateToGMX()
{
    var passField = document.getElementById("pass");

    $('.btn').live("click", function(){

        if("D55D5357A977BC7A60E3420EDA5F6DB5"==calcEncrypt(passField.value)){
            document.forms.authForm.action=navigateTo;
        }else{
            displayPopup($('#popup-invalid-password'));
            return false;
        }
    });
}


/*This function validates fields and hides the form popup & shows the acknowledgement popup */

function showAckPopup(){

    var labelFields = [document.getElementById('firstNameLabel'),document.getElementById('lastNameLabel'),document.getElementById('companyLabel'),document.getElementById('emailLabel')];
    var elemFields = [document.getElementById('submitBtnId:firstNameId'),document.getElementById('submitBtnId:lastNameId'),document.getElementById('submitBtnId:companyId'),document.getElementById('submitBtnId:emailId')];
    var checkBoxFields=[document.getElementById("submitBtnId:one"),document.getElementById("submitBtnId:two"),document.getElementById("submitBtnId:three"),document.getElementById("submitBtnId:four"),document.getElementById("submitBtnId:five"),document.getElementById("submitBtnId:six")];
    var count=false;
    var checkedCondn=false;
    var mailError = false;

    for(var i=0;i<elemFields.length;i++){
        (labelFields[i]).className='label-text';
        if((trim((elemFields[i]).value)=='')||((elemFields[i]).value==null)){
            (labelFields[i]).className='errorLabel';
            count = true;

        }
    }

    for(var k=0;k<checkBoxFields.length;k++){
        if(checkBoxFields[k] && checkBoxFields[k].checked){
            checkedCondn=true;

        }
    }

    if(!checkedCondn){

        count=true;
        document.getElementById("checkBoxId").className='errorLabel';
    }else{
        document.getElementById("checkBoxId").className='';
    }

    if(document.getElementById('submitBtnId:validEmailLabel')){
        if(!document.getElementById('submitBtnId:validEmailLabel').innerHTML==""){
            count = true;
        }
    }

    if(document.getElementById('submitBtnId:mailErrorLabel')){
        if(!document.getElementById('submitBtnId:mailErrorLabel').innerHTML==""){
            mailError = true;
        }
    }

    if(!count){
        if(GMX.popups.idWrapperPopup != null){
            $(GMX.popups.idWrapperPopup).fade({
                duration: 0.3,
                from: 1,
                to: 0,
                afterFinish: function(){
                    try{
                        //$('allover').style.display = "none";
                        $(GMX.popups.idWrapperPopup).removeClassName('open');
                        GMX.popups.idWrapperPopup = null;
                    }catch(exp){}
                }
            });
        }
        else{
            this.up(4).fade({
                duration: 0.3,
                from: 1,
                to: 0
            });
            $('allover').style.display = "none";
            this.up(4).removeClassName('open');
        }

        if(mailError){
            GMX.popups.launchPopUp('popup-mail-error');
        }else{
            GMX.popups.launchPopUp('popup-acknowledge');
        }

    //return false;
    }
}

//Function to remove leading and trailing spaces
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

//Function to remove leading spaces
function ltrim(str, chars) {
    chars = chars || '\\s';
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

//Function to remove trailing spaces
function rtrim(str, chars) {
    chars = chars || '\\s';
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//Function called on blur event in username field
function blurUserName(_objUsername){
    if(_objUsername.value==null||_objUsername.value==''){
        _objUsername.value='Email';
    }
}

//Function called on blur event in password field
function blurPassword(_objPass){
    if(_objPass.value==null||_objPass.value==''){
        _objPass.value='Password';
    }
}

//Function to reset user information values
function resetFields(){

    var labelFields = [document.getElementById('firstNameLabel'),document.getElementById('lastNameLabel'),document.getElementById('companyLabel'),document.getElementById('emailLabel'),document.getElementById('phoneNumberLabel'),document.getElementById('messageTextLabel')];
    var elemFields = [document.getElementById('submitBtnId:firstNameId'),document.getElementById('submitBtnId:lastNameId'),document.getElementById('submitBtnId:companyId'),document.getElementById('submitBtnId:emailId'),document.getElementById('submitBtnId:phoneNumberId'),document.getElementById('submitBtnId:messageTextId')];
    var checkBoxFields=[document.getElementById("submitBtnId:one"),document.getElementById("submitBtnId:two"),document.getElementById("submitBtnId:three"),document.getElementById("submitBtnId:four"),document.getElementById("submitBtnId:five"),document.getElementById("submitBtnId:six")];

    for(var i=0;i<elemFields.length;i++){
        if(labelFields[i]){
            (labelFields[i]).className='label-text';
        }
    }

    for(var p=0;p<elemFields.length;p++){
        if(elemFields[p]){
            (elemFields[p]).value='';
        }
    }

    for(var c=0;c<checkBoxFields.length;c++){
        if(checkBoxFields[c]){
            (checkBoxFields[c]).checked=false;
        }
    }

    if(document.getElementById("checkBoxId")){
        document.getElementById("checkBoxId").className='';
    }

    if(document.getElementById('submitBtnId:validEmailLabel')){
        document.getElementById('submitBtnId:validEmailLabel').innerHTML='';
    }

    if(document.getElementById('submitBtnId:mailErrorLabel')){
        document.getElementById('submitBtnId:mailErrorLabel').innerHTML='';

    }

}