function form_cheking(id,reg)
{
	if(reg.test(document.getElementById(id+'_f').value)==true)
	{
		document.getElementById('i_'+id).src='resource/images/true.png';
		document.getElementById('i_'+id).title='OK';
	}
	else
	{
		document.getElementById('i_'+id).src='resource/images/false.png';
		document.getElementById('i_'+id).title='Error';
	}
}

function remActive(id,ev)
{
	d = document.getElementById(id);
    tleft = ev.clientX;
    ttop = ev.clientY;
    d.style.pixelLeft = tleft+10;
    d.style.pixelTop = ttop+20;
    d.style.display = 'block';
}

function checkABA(s) {
    var i, n, t;
    // First, remove any non-numeric characters.
    t = "";
    for (i = 0; i < s.length; i++)
	{
      	c = parseInt(s.charAt(i), 10);
      	if (c >= 0 && c <= 9)t = t + c;
    }

    // Check the length, it should be nine digits.
    if (t.length != 9)return false;

    // Now run through each digit and calculate the total.
    n = 0;
    for (i = 0; i < t.length; i += 3)
	{
      	n += parseInt(t.charAt(i),     10) * 3
          +  parseInt(t.charAt(i + 1), 10) * 7
          +  parseInt(t.charAt(i + 2), 10);
    }

    // If the resulting sum is an even multiple of ten (but not zero),
    // the aba routing number is good.
    if(n != 0 && n % 10 == 0)return true;
    else return false;
}

function aba_cheking(id)
{
	if(checkABA(document.getElementById(id+'_f').value)==true)
	{
		document.getElementById('i_'+id).src='resource/images/true.png';
		document.getElementById('i_'+id).title='OK';
	}
	else
	{
		document.getElementById('i_'+id).src='resource/images/false.png';
		document.getElementById('i_'+id).title='Error';
	}
}

var vyearid=['34','33','32','31','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30'];
var vyearyear=['2008','2007','2006','2005','2004','2003','2002','2001','2000','1999','1998','1997','1996','1995','1994','1993','1992','1991','1990','1989','1988','1987','1986','1985','1984','1983','1982','1981','1980','1979','1978','1977','1976','1975'];
var vmakeid=[];var vmakemake=[];var vmodelid=[];var vmodelmodel=[];var vsubmodelid=[];var vsubmodelsubmodel=[];
function returnYear(year){for(var i=0;i<vyearyear.length;i++){if(vyearyear[i]==year)return vyearid[i];}}
function returnMake(make){for(var i=0;i<vmakemake.length;i++){if(vmakemake[i]==make)return vmakeid[i];}}
function returnModel(model){for(var i=0;i<vmodelmodel.length;i++){if(vmodelmodel[i]==model)return vmodelid[i];}}
function returnSubmodel(submodel){for(var i=0;i<vsubmodelsubmodel.length;i++){if(vsubmodelsubmodel[i]==submodel)return vsubmodelid[i];}}

var now_year;
var now_make;
var now_model;

function AJAXGetMakes(year)
{
    now_year = year;
    var CarMake=document.getElementById("vmake");
    CarMake.innerHTML = "Load...";
    var CarModel=document.getElementById("vmodel");
    CarModel.innerHTML = "<input style='width:200px;' disabled>";
    
    xmlhttp = null;
    if (window.XMLHttpRequest) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }

    
    if(xmlhttp==null)
    {
      alert ("Your browser does not support AJAX!");
      return false;
    }
    xmlhttp.open("GET","/year_make_model_submodel.php?year=" + year ,true);
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
            var xmlDoc=xmlhttp.responseXML.documentElement;
            
            if (xmlDoc != null)
            {
                //var ids =    xmlDoc.getElementsByTagName("id");
                var makes =  xmlDoc.getElementsByTagName("Make");
                var i;
                
                CarMake.innerHTML = "<select style='width:205px;' name='veh1_vmake' id='veh1_vmake' onchange='if(this.value){AJAXGetModel(this.value);}'><option value=''>Select...</option></select>";

                var CarMake1=document.getElementById("veh1_vmake");

                //vmakemake = Array();
                //vmakeid = Array();
                var znach;
                for (i = 0; i < makes.length; i++)
                {
                    //vmakemake[i]=makes[i].childNodes[0].nodeValue;
                    //vmakeid[i]=ids[i].childNodes[0].nodeValue;
                    //alert('-'+makes[i].childNodes[0].nodeValue+'-');
                    //alert('-'+makes[i].childNodes[0].nodeValue+'-');
                    if(i%2==1){
                        var opt=document.createElement('option');
                        opt.text=makes[i].childNodes[0].nodeValue;
                        opt.value=makes[i].childNodes[0].nodeValue;
                        try{ CarMake1.add(opt,null);} catch(ex) { CarMake1.add(opt); }
                    }
                }
                CarMake1.focus()
            }
        }
    }
    xmlhttp.send(null);
}

function AJAXGetModel(make)
{
    now_make = make;

    var CarModel=document.getElementById("vmodel");
    CarModel.innerHTML = "Load...";

    xmlhttp = null;
    if (window.XMLHttpRequest) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }


    if(xmlhttp==null)
    {
      alert ("Your browser does not support AJAX!");
      return false;
    }

    xmlhttp.open("GET","/year_make_model_submodel.php?year=" + escape(now_year) + "&make=" + escape(make) ,true);

    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
            var xmlDoc=xmlhttp.responseXML.documentElement;
            if (xmlDoc != null)
            {
                //var ids =    xmlDoc.getElementsByTagName("id");
                var makes =  xmlDoc.getElementsByTagName("Model");
                var i;

                CarModel.innerHTML = "<select style='width:205px;' name='veh1_vmodel' id='veh1_vmodel' onchange='if(this.value){AJAXGetSubModel(this.value);}'><option value=''>Select...</option></select>";

                var CarModel1=document.getElementById("veh1_vmodel");

                //vmodelmodel = Array();
                //vmodelid = Array();

                for (i = 0; i < makes.length; i++)
                {
                    //vmodelmodel[i]=makes[i].childNodes[0].nodeValue;
                    //vmodelid[i]=ids[i].childNodes[0].nodeValue;
                    if(i%2==1){
                    var opt=document.createElement('option');
                    opt.text=makes[i].childNodes[0].nodeValue;
                    opt.value=makes[i].childNodes[0].nodeValue;
                    try{ CarModel1.add(opt,null);} catch(ex) { CarModel1.add(opt); }
                    }
                }
                CarModel1.focus()
            }
        }
    }
    xmlhttp.send(null);
}

function AJAXGetSubModel(model)
{
    now_model = model;

    var CarSubmodel=document.getElementById("vsubmodel");
    CarSubmodel.innerHTML = "Load...";

    xmlhttp = null;
    if (window.XMLHttpRequest) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }

    
    if(xmlhttp==null)
    {
      alert ("Your browser does not support AJAX!");
      return false;
    }

    xmlhttp.open("GET","/year_make_model_submodel.php?make=" + escape(now_make) + "&year=" + escape(now_year) + "&model=" + escape(model) ,true);

    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
            var xmlDoc=xmlhttp.responseXML.documentElement;
            if (xmlDoc != null)
            {
                //var ids =    xmlDoc.getElementsByTagName("id");
                var makes =  xmlDoc.getElementsByTagName("SubModel");
                var i;

                CarSubmodel.innerHTML = "<select style='width:205px;' name='veh1_vsubmodel' id='veh1_vsubmodel' onchange=''></select>";

                var CarSubModel1=document.getElementById("veh1_vsubmodel");

                //vsubmodelsubmodel = Array();
                //vsubmodelid = Array();

                for (i = 0; i < makes.length; i++)
                {
                    //vsubmodelsubmodel[i]=makes[i].childNodes[0].nodeValue;
                    //vsubmodelid[i]=ids[i].childNodes[0].nodeValue;

                    var opt=document.createElement('option');
                    opt.text=makes[i].childNodes[0].nodeValue;
                    opt.value=makes[i].childNodes[0].nodeValue;
                    try{ CarSubModel1.add(opt,null);} catch(ex) { CarSubModel1.add(opt); }
                }
                CarSubModel1.focus()
            }
        }
    }
    xmlhttp.send(null);
}