submenu['comment_user_type'] = new Array();
submenu['comment_user_type'][0] = menuItem('<table cellspacing="0" border="0" style="margin-left: 4px;"><tr><td style="vertical-align: top;"><div style="width: 6px; height: 11px; background-image: url(\'http://www.apdrausk.lt/design/arrow.gif\'); background-repeat: no-repeat; margin-top: 6px;"></div></td><td width="128"><p class="comment">Jūs esate juridinis ar privatus klientas</p></td></tr></table>','0','');
submenu['comment_code'] = new Array();
submenu['comment_code'][0] = menuItem('<table cellspacing="0" border="0" style="margin-left: 4px;"><tr><td style="vertical-align: top;"><div style="width: 6px; height: 11px; background-image: url(\'http://www.apdrausk.lt/design/arrow.gif\'); background-repeat: no-repeat; margin-top: 6px;"></div></td><td width="128"><p class="comment">Įrašykite automobilio savininko 11 ženklu asmens kodą. Jūsų amžius bei rizikos grupė bus nustatyta remiantis įvestu asmens kodu.</p></td></tr></table>','0','');
submenu['comment_code2'] = new Array();
submenu['comment_code2'][0] = menuItem('<table cellspacing="0" border="0" style="margin-left: 4px;"><tr><td style="vertical-align: top;"><div style="width: 6px; height: 11px; background-image: url(\'http://www.apdrausk.lt/design/arrow.gif\'); background-repeat: no-repeat; margin-top: 6px;"></div></td><td width="128"><p class="comment">Įrašykite imonės, kuriai priklauso automobilis, 9 ženklų kodą.</p></td></tr></table>','0','');
submenu['comment_car_num'] = new Array();
submenu['comment_car_num'][0] = menuItem('<table cellspacing="0" border="0" style="margin-left: 4px;"><tr><td style="vertical-align: top;"><div style="width: 6px; height: 11px; background-image: url(\'http://www.apdrausk.lt/design/arrow.gif\'); background-repeat: no-repeat; margin-top: 6px;"></div></td><td width="128"><p class="comment">Įrašykite automobilio valstybinį numerį (be tarpų). Numeris turėtų būti egzistuojantis, nes pagal jį nustatoma automobilio galia ir variklio turis.</p></td></tr></table>','0','');
submenu['comment_email'] = new Array();
submenu['comment_email'][0] = menuItem('<table cellspacing="0" border="0" style="margin-left: 4px;"><tr><td style="vertical-align: top;"><div style="width: 6px; height: 11px; background-image: url(\'http://www.apdrausk.lt/design/arrow.gif\'); background-repeat: no-repeat; margin-top: 6px;"></div></td><td width="128"><p class="comment">Laukas yra neprivalomas, tačiau įrašę el. pašto adresą, po paskaičiavimo gausite laišką su papildomomis kainomis.</p></td></tr></table>','0','');

function disable_code2()
{
    document.getElementById('code2_field').style.display = 'none';
    document.getElementById('code_field').style.display = 'block';
    document.getElementById('myradio').checked = true; 
}

function enable_code2()
{
    document.getElementById('code2_field').style.display = 'block';
    document.getElementById('code_field').style.display = 'none';
    document.getElementById('myradio2').checked = true;
} 

function showload()
{
    document.getElementById('load').style.display = 'block';
    document.getElementById('login').style.display = 'none';
    document.getElementById('login_border_l').style.display = 'none';
    document.getElementById('login_border_r').style.display = 'none';
}
function hideload()
{
    document.getElementById('load').style.display = 'none';
}

function isEmailValid(email){ 
    var reg = /^(.+)@([^\(\);:,<>]+\.[a-zA-Z]{2,4})/;
    if(reg.test(email) == false) {
        return false;
    }                 
    return true;
}

function isCodeValid(code) {

    if (!code.match("^[0-9]{11}$"))
        return false;

    if (!code.match("^[34]"))
        return false;


    var menuo = code.substr(3,1) * 10 + parseInt(code.substr(4,1));
    var diena = code.substr(5,1) * 10 + parseInt(code.substr(6,1));

    if (menuo > 12 || diena > 31)
        return false;

    if ((menuo == 2) && (diena > 29))
        return false;


    var c  = parseInt(code.charAt(0)) + parseInt(code.charAt(1)) * 2 + parseInt(code.charAt(2)) * 3 + parseInt(code.charAt(3)) * 4 + parseInt(code.charAt(4)) * 5 + parseInt(code.charAt(5)) * 6 + parseInt(code.charAt(6)) * 7 + parseInt(code.charAt(7)) * 8 + parseInt(code.charAt(8)) * 9 + parseInt(code.charAt(9));
    c = c % 11;


    if (c == 10) {
        c = parseInt(code.charAt(0)) * 3 + parseInt(code.charAt(1)) * 4 + parseInt(code.charAt(2)) * 5 + parseInt(code.charAt(3)) * 6 + parseInt(code.charAt(4)) * 7 + parseInt(code.charAt(5)) * 8 + parseInt(code.charAt(6)) * 9 + parseInt(code.charAt(7)) + parseInt(code.charAt(8)) * 2 + parseInt(code.charAt(9)) * 3;
        c = c % 11;
    } 
    else if(c != code.charAt(10)){
        return false;
    }

    if (c == 10) c = 0;
    if (c != code.charAt(10))
        return false;
    return true;
}

function setDefaultBorder(item)
{
    item.style.borderTopColor = "#404040";
    item.style.borderLeftColor = "#404040";
    item.style.borderBottomColor = "#d4d0c8";
    item.style.borderRightColor = "#d4d0c8";
}

function check()
{
    var error = false;
    var code = document.getElementById('code');
    var code2 = document.getElementById('code2');
    var car_num = document.getElementById('car_num');
    var radio_button = document.getElementById('myradio');
    //var email = document.getElementById('email');
    var car_num = document.getElementById('car_num');

    if (radio_button.checked){
        if (code.value == ''){
            error = true; 
            code.style.borderColor = "rgb(255, 100, 100)";
            document.getElementById('error_code_empty').style.display = "block";
        }
        else{
            document.getElementById('error_code_empty').style.display = "none";
            if (isCodeValid(code.value)){
                setDefaultBorder(code);
                document.getElementById('error_code_invalid').style.display = "none";
            }
            else{
                error = true; 
                code.style.borderColor = "rgb(255, 100, 100)";
                document.getElementById('error_code_invalid').style.display = "block";
            }
        }
        document.getElementById('error_code2_empty').style.display = "none";
    }
    else{
        if (code2.value == ''){
            error = true; 
            code2.style.borderColor = "rgb(255, 100, 100)";
            document.getElementById('error_code2_empty').style.display = "block";
        }
        else{
            setDefaultBorder(code2);
            document.getElementById('error_code2_empty').style.display = "none";
        }
        document.getElementById('error_code_invalid').style.display = "none";
        document.getElementById('error_code_empty').style.display = "none";
    }
    if (car_num.value == ''){
        error = true; 
        car_num.style.borderColor = "rgb(255, 100, 100)";
        document.getElementById('error_car_num_empty').style.display = "block";
    }
    else{
        document.getElementById('error_car_num_empty').style.display = "none";
        if (car_num.value.length != 6){
            error = true; 
            car_num.style.borderColor = "rgb(255, 100, 100)";
            document.getElementById('error_car_num_short').style.display = "block";
        }
        else{
            setDefaultBorder(car_num);
            document.getElementById('error_car_num_short').style.display = "none";
        }
    }


    /*if (email.value.length > 1){
        if (isEmailValid(email.value)){
            setDefaultBorder(email);
            document.getElementById('error_email').style.display = "none";
        }
        else{
            error = true;
            email.style.borderColor = "rgb(255, 100, 100)";
            document.getElementById('error_email').style.display = "block"; 
        }
    } */ 


    return error;
}

function getinfo(url){       
    if (check()){
        return;
    }
    showload();
    var xmlHttp;
    try
    {
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
            }
            catch (e)
            {
                alert("Jūsų naršyklė nepalaiko būtino komponento(AJAX) portalo veikimui, atsinaujinkite naršyklę arba naudokite kitą naršyklę.");
                document.getElementById('next_step').value = '0';
                document.step0.submit();      
            }
        }
    }  

    xmlHttp.onreadystatechange=function(){  
        if(xmlHttp.readyState==4){
            if (xmlHttp.status == 200){
                if (xmlHttp.responseText == "invalid_user" || xmlHttp.responseText == "invalid_user \n"){
                    document.getElementById('form1').style.display = 'none';
                    document.getElementById('invalid_user_message').style.display = 'block';
                    document.getElementById('load').style.display = 'none'; 
                }
                else{ 
                    document.getElementById('next_step').value = '1';
                    document.step0.submit();
                }
            }
        }
    }
    var code_url = document.getElementById("code").value;
    var number_url = document.getElementById("car_num").value;
    var radio_button = document.getElementById('myradio');
    var code2 = document.getElementById('code2').value;
    //var email = document.getElementById('email').value; 
    var guid = document.getElementById('guid').value; 
    var group = 1;
    if (!radio_button.checked){
        group = 0;
    }

    //var url="http://www.apdrausk.lt/testap/dynamic_modules/getinfo.php";
    url=url+"?code="+code_url;
    url=url+"&car_num="+number_url;
    url=url+"&group="+group;
    url=url+"&code2="+code2;
    //url=url+"&email="+email;
    url=url+"&guid="+guid;
    xmlHttp.open("GET", url, true);    
    xmlHttp.send(null);
}

