var ajaxInProcess=false;
var state=new Array();
state['txtName']=0;
state['txtSurname']=0;
state['selGender']=0;
state['date']=0;
state['txtZip']=0;
state['txtTown']=0;
state['selCountry']=0;
state['txtUsername']=0;
state['txtPassword']=0;
state['txtPasswordConf']=0;
state['txtEmail']=0;
state['txtCaptcha']=0;


function validate(field, value)
{
        if (value.trim()=='') return;
        var jSonRequest = new Request.JSON
        (
                {
                        url: 'index.php/ajax/ajaxcheck',
                        data: {'field': field, 'value': value},
                        method: 'post',
                        onComplete: function(json)
                        {
                                ajaxInProcess=false;
                                highlightError(json.status,json.field);
                        },
                        onRequest: function()
                        {
                                ajaxInProcess=true;
                        },
                        onError: function()
                        {
                                ajaxInProcess=true;
                                alert('Server Error!');
                        }
                }
        );

        jSonRequest.send();
}

function validateJS(field, value)
{
        if (value.trim()=='') return;
        switch (field)
        {
                case 'txtPassword':
                        var re=/^[A-z0-9a-z]{6,}$/;
                        if (re.test(value.trim())) highlightError(1,field);
                        else highlightError(0,field);
                        break;
                case 'txtPasswordConf':
                        if (value==$('txtPassword').value) highlightError(1,field);
                        else highlightError(0,field);
                        break;
                case 'txtName':case 'txtSurname':case 'txtTown':
                        var re=/^[a-zA-Z\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u03B2\s\.]+$/;
                        if (re.test(value.trim())) highlightError(1,field);
                        else highlightError(0,field);
                        break;
                case 'selCountry':
                                $('selCountrybund1').disabled=true;
                                $('selCountrybund2').disabled=true;
                                $('selCountrybund3').disabled=true;

                        if (value=='0')
                        {
                                $('txtCountry').disabled=true;
                                highlightError(0,field);

                        }
                        else if (value=='input')
                        {
                                state['selCountry']=0;
                                $('txtCountry').disabled=false;
                                $('txtCountry').focus();
                                $('txtCountry').select();
                                $('txtCountry').set('style','background: #FFFFFF');
                        }
                        else
                        {
                                highlightError(1,field);
                                $('txtCountry').disabled=true;
                                $('txtCountry').set('style','background-image: url(../../images/back.jpg); border: 0;');

                                if (value=='German')
                                {
                                $('selCountrybund1').disabled=false;
                                $('selCountrybund2').disabled=true;
                                $('selCountrybund3').disabled=true;
                                }
                                if (value=='Austria')
                                {
                                $('selCountrybund1').disabled=true;
                                $('selCountrybund2').disabled=false;
                                $('selCountrybund3').disabled=true;
                                }
                                if (value=='Switzerland')
                                {
                                $('selCountrybund1').disabled=true;
                                $('selCountrybund2').disabled=true;
                                $('selCountrybund3').disabled=false;
                                }
                        }
                        break;
                case 'txtCountry':
                        var re=/^[a-zA-Z\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u03B2\s\.]+$/;
                        if (re.test(value.trim())) highlightError(1,'selCountry');
                        else highlightError(0,'selCountry');
                        break;
                case 'selGender':
                        if (value=='0') highlightError(0,field);
                        else highlightError(1,field);
                        break;
                case 'selSearch':
                        if (value=='0') highlightError(0,field);
                        else highlightError(1,field);
                        break;
                case 'selKategorie':
                        if (value=='0') highlightError(0,field);
                        else highlightError(1,field);
                        break;
                case 'selCountrybundOg':
                        if (value=='0') highlightError(0,field);
                        else highlightError(1,field);
                        break;
                case 'txtZip':
                        var re=/^[0-9]{4,5}$/;
                        if (re.test(value.trim())) highlightError(1,field);
                        else highlightError(0,field);
                        break;
                default:
                        break;
        }
}

function validateADM(field, value)
{
        if (value.trim()=='') return;
        switch (field)
        {
                case 'txtPassword':
                        var re=/^[A-z0-9a-z]{6,}$/;
                        if (re.test(value.trim())) highlightErrorAdm(1,field);
                        else highlightError(0,field);
                        break;
                case 'txtPasswordConf':
                        if (value==$('txtPassword').value) highlightErrorAdm(1,field);
                        else highlightError(0,field);
                        break;
                case 'txtName':case 'txtSurname':case 'txtTown':
                        var re=/^[a-zA-Z\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u03B2\s\.]+$/;
                        if (re.test(value.trim())) highlightError(1,field);
                        else highlightErrorAdm(0,field);
                        break;

        }
}

function validateDate()
{
        var f=document.frmRegister;
        var d=f.selDay.value;
        var m=f.selMonth.value;
        var y=f.selYear.value;

        if (d*m*y!=0)
        {
                m--;
                var date=new Date();
    date.setFullYear(y,m,d);
                 if (date.getMonth() == m) highlightError(1,'date');
                 else highlightError(0,'date');
        }
}

function highlightError(status,field)
{
        var statusBar=$(field+'Status');
        if (status!='ERROR')
        {
                if (status=='1')
                {
                        statusBar.getParent().set('style','background: #fff;');
                        statusBar.set('text','OK');
                        statusBar.fade(0);
                }
                else
                {
                        statusBar.setStyles
                        (
                                {
                                        display:'inline',
                                        opacity: 0
                                }
                        );
                        statusBar.set('text','Error');
                        statusBar.fade(1);
                        statusBar.getParent().set('style','background: #C91A21');
                }
                state[field]=status;
        }
}
function highlightErrorAdm(status,field)
{
        var statusBar=$(field+'Status');
        if (status!='ERROR')
        {
                if (status=='1')
                {
                        statusBar.getParent().set('style','background:#F1F1ED;');
                        statusBar.set('text','OK');
                        statusBar.fade(0);
                }
                else
                {
                        statusBar.setStyles
                        (
                                {
                                        display:'inline',
                                        opacity: 0
                                }
                        );
                        statusBar.set('text','Error');
                        statusBar.fade(1);
                        statusBar.getParent().set('style','background: #C91A21');
                }
                state[field]=status;
        }
}
function submitOgo()
{
        var flag=true;
        for (key in state)
        if (state[key]==0)
        {
                flag=false;
                break;
        }
        if ($('selKategorie').value=='0')
        {
                $('selKategorieStatus').set('text',_lang_register_must_select);
                $('selKategorieStatus').getParent().set('style','background: #ff7777');
                flag=false;
        }
        else
        {
                $('selKategorieStatus').empty();
                $('selKategorieStatus').getParent().set('style','background: #fff');
        }
        if ($('selCountrybundOg') && $('selCountrybundOg').value=='0')
        {
                $('selCountrybundOgStatus').set('text',_lang_register_must_select);
                $('selCountrybundOrtOgStatus').set('text',_lang_register_must_select);
                $('selCountrybundOgStatus').getParent().set('style','background: #ff7777');
                $('selCountrybundOrtOgStatus').getParent().set('style','background: #ff7777');
                flag=false;
        }
        else
        {
                $('selCountrybundOgStatus').empty();
                $('selCountrybundOgStatus').getParent().set('style','background: #fff');
        }
        if ($('selCountrybundOrtOg') && $('selCountrybundOrtOg').value=='0')
        {
                $('selCountrybundOrtOgStatus').set('text',_lang_register_must_select);
                $('selCountrybundOrtOgStatus').getParent().set('style','background: #ff7777');
                flag=false;
        }
        else
        {
                $('selCountrybundOrtOgStatus').empty();
                $('selCountrybundOrtOgStatus').getParent().set('style','background: #fff');
        }
        if (flag && !ajaxInProcess)
        {
                f.submit();
        }
        else
        {
                for (key in state)
                {
                        if (state[key]==0)
                        {
                                highlightError(0,key);
                        }
                }
        }
}

function submitForm()
{
        var f=document.frmRegister;
        var flag=true;
        for (key in state)
        if (state[key]==0)
        {
                flag=false;
                break;
        }
        if (!f.chkAgb.checked)
        {
                $('chkAgbStatus').set('text',_lang_register_must_click);
                $('chkAgbStatus').getParent().set('style','background: #ff7777');
                flag=false;
        }
        else
        {
                $('chkAgbStatus').empty();
                $('chkAgbStatus').getParent().set('style','background: #fff');
        }

        if (flag && !ajaxInProcess)
        {
                f.submit();
        }
        else
        {
                for (key in state)
                {
                        if (state[key]==0)
                        {
                                highlightError(0,key);
                        }
                }
        }
}

function refreshCaptcha()
{
        area=$('captchaArea');
        area.empty();
        var jSonRequest = new Request.JSON
        (
                {
                        url: 'index.php/ajax/refresh_captcha',
                        data: {'act': 'refresh'},
                        method: 'post',
                        onComplete: function(json)
                        {
                                area.empty();
                                area.set('html',json.image);
                        },
                        onRequest: function()
                        {
                                area.set('text','Loading....');
                        },
                        onError: function()
                        {
                                area.set('text','Error! Try Letter!');
                        }
                }
        );

        jSonRequest.send();
}
function selectLands(field, value)
{
        switch (field)
        {
        			 case 'selCountry':
                                $('selCountrybund1').disabled=true;
                                $('selCountrybund2').disabled=true;



                                if (value=='German')
                                {
                                $('selCountrybund1').disabled=false;
                                //$('selCountrybund2').dispose();
                                $('selCountrybund2').disabled=true;

                                }
                                if (value=='Austria')
                                {
                                $('selCountrybund1').disabled=true;
                                $('selCountrybund2').disabled=false;

                                }


                        break;


                default:
                        break;
        }
}


function mustRegister()
{
        alert ('You must register to continue!!!');
        return;
}

function selectLand(value,ort,lang)
{

       var jSonRequest = new Request.JSON
        (
                {
                        url: _config_live_site+'index.php/ajax/get_lands',
                        data: { 'value':value, 'lang':lang },
                        method: 'post',
                        onComplete: function(json)
                        {

                                if (json.status=='OK')
                                {


                                 text=json.message;

                                 $('bundesland').set('html',text)
                                 $('bundeslandOrt').set('html',ort)



                                }
                                else
                                {


                                }
                        },
                        onRequest: function()
                        {
                        },
                        onError: function()
                        {
                                alert('Error! Try Letter!');
                        }
                }
        );

        jSonRequest.send();
}
function selectOrt(value,lang)
{

       var jSonRequest = new Request.JSON
        (
                {
                        url: _config_live_site+'index.php/ajax/get_ort',
                        data: { 'value':value, 'lang':lang  },
                        method: 'post',
                        onComplete: function(json)
                        {

                                if (json.status=='OK')
                                {

                                 text=json.message;
                                 $('bundeslandOrt').set('html',text)


                                }
                                else
                                {


                                }
                        },
                        onRequest: function()
                        {
                        },
                        onError: function()
                        {
                                alert('Error! Try Letter!');
                        }
                }
        );

        jSonRequest.send();
}
function selectLandReg(value)
{

       var jSonRequest = new Request.JSON
        (
                {
                        url: _config_live_site+'index.php/ajax/get_lands_reg',
                        data: { 'value':value },
                        method: 'post',
                        onComplete: function(json)
                        {

                                if (json.status=='OK')
                                {

                                 text=json.message;

                                 $('bundeslandReg').set('html',text)

                                }
                                else
                                {


                                }
                        },
                        onRequest: function()
                        {
                        },
                        onError: function()
                        {
                                alert('Error! Try Letter!');
                        }
                }
        );

        jSonRequest.send();
}

function selectZugang(value)
{
                                if (value=='1')
                                {
                                $('selBezahlung').disabled=true;
                                }
                                if (value=='2')
                                {
                                $('selBezahlung').disabled=false;
                                }
}

function selectLandOg(value,ort,lang)
{

       var jSonRequest = new Request.JSON
        (
                {
                        url: _config_live_site+'index.php/ajax/get_lands_og',
                        data: { 'value':value, 'lang':lang },
                        method: 'post',
                        onComplete: function(json)
                        {

                                if (json.status=='OK')
                                {


                                 text=json.message;

                                 $('bundeslandOg').set('html',text)
                                 $('bundeslandOrtOg').set('html',ort)



                                }
                                else
                                {


                                }
                        },
                        onRequest: function()
                        {
                        },
                        onError: function()
                        {
                                alert('Error! Try Letter!');
                        }
                }
        );

        jSonRequest.send();
}
function selectOrtOg(value,lang)
{

       var jSonRequest = new Request.JSON
        (
                {
                        url: _config_live_site+'index.php/ajax/get_ort_og',
                        data: { 'value':value, 'lang':lang },
                        method: 'post',
                        onComplete: function(json)
                        {

                                if (json.status=='OK')
                                {


                                 text=json.message;
                                 $('bundeslandOrtOg').set('html',text)


                                }
                                else
                                {


                                }
                        },
                        onRequest: function()
                        {
                        },
                        onError: function()
                        {
                                alert('Error! Try Letter!');
                        }
                }
        );

        jSonRequest.send();
}
function myPopup2(st) {
window.open( st, "myWindow", "status = 1, height = 750, width = 750, resizable = 1, scrollbars=yes"  )
}
