﻿// call when the page load

$(document).ready(function(){   
    getPartRequest();	 
});


// send a request to get a data using jsonp

function getPartRequest(){
    $.ajax({
        type: "GET",        
        url:"http://www.getusedparts.com/getPartData.asp?callback=sendData",
        dataType: "jsonp"             
    });
}


// Display data in the items list 

function sendData(data)
{

 if(data.result == "success")
 {
        var htmlstr="";
        
        for(var index=0;index<data.requestpartdata.length;index++) // to display all the items in the list
        {
            var location = "";
            location = data.requestpartdata[index].location;
                if(index%2==1) // check for displaying item in the alternate image
                {
                    if(location.search(",")>0) // check weather the state is available or not
                    {
                        htmlstr="<div class='roundedDiv'><p style='padding-top:14px;'><span style='font-weight:bold;'>"+ data.requestpartdata[index].firstname+ " </span>in <span style='font-weight:bold;'><a  target='' href='http://getusedparts.com/partrequestlistingbycountry.asp?country="+ data.requestpartdata[index].country +"&countryId=" + data.requestpartdata[index].countryid + "&state=" + data.requestpartdata[index].state + "&stateId=" + data.requestpartdata[index].stateid + "&source=fromstate'>" + data.requestpartdata[index].location + "</a> </span>needs a <span style='font-weight:bold;'><a target='' href='http://getusedparts.com/partrequestdetail.asp?year="+data.requestpartdata[index].year+"&yearId="+data.requestpartdata[index].yearid+"&make="+data.requestpartdata[index].make+"&makeId="+data.requestpartdata[index].makeid+"&model="+data.requestpartdata[index].model+"&modelId="+data.requestpartdata[index].modelid+"&part="+data.requestpartdata[index].part+"&partId="+data.requestpartdata[index].partid+"&reqid="+data.requestpartdata[index].reqid+"'>"+ data.requestpartdata[index].part +"</a></span> for a <span style='font-weight:bold;'> <a target='' href='http://getusedparts.com/makelisting.asp?year="+ data.requestpartdata[index].year +"&yearId=" + data.requestpartdata[index].yearid+"'>" + data.requestpartdata[index].year +"</a>&nbsp;<a target='' href='http://getusedparts.com/modellisting.asp?year="+data.requestpartdata[index].year+"&yearId="+data.requestpartdata[index].yearid+"&make="+data.requestpartdata[index].make+"&makeId="+data.requestpartdata[index].makeid +"'>"+data.requestpartdata[index].make+"</a>&nbsp;<a target='' href='http://getusedparts.com/partlisting.asp?year="+data.requestpartdata[index].year +"&yearId="+data.requestpartdata[index].yearid +"&make="+data.requestpartdata[index].make +"&makeId="+data.requestpartdata[index].makeid +"&model="+data.requestpartdata[index].model +"&modelId="+data.requestpartdata[index].modelid+"'>"+ data.requestpartdata[index].model +"</a></span><p></div>"                         
                        $('<li/></li>').addClass('item').html(htmlstr).appendTo('#main_ul');                     
                    }
                    else
                    {
                        htmlstr="<div class='roundedDiv'><p style='padding-top:14px;'><span style='font-weight:bold;'>"+ data.requestpartdata[index].firstname+ " </span>in <span style='font-weight:bold;'><a  target='' href='http://getusedparts.com/partrequestlistingbycountry.asp?country="+ data.requestpartdata[index].country +"&countryId=" + data.requestpartdata[index].countryid +  "&source=fromcountry'>" + data.requestpartdata[index].location + "</a> </span>needs a <span style='font-weight:bold;'><a target='' href='http://getusedparts.com/partrequestdetail.asp?year="+data.requestpartdata[index].year+"&yearId="+data.requestpartdata[index].yearid+"&make="+data.requestpartdata[index].make+"&makeId="+data.requestpartdata[index].makeid+"&model="+data.requestpartdata[index].model+"&modelId="+data.requestpartdata[index].modelid+"&part="+data.requestpartdata[index].part+"&partId="+data.requestpartdata[index].partid+"&reqid="+data.requestpartdata[index].reqid+"'>"+ data.requestpartdata[index].part +"</a></span> for a <span style='font-weight:bold;'> <a target='' href='http://getusedparts.com/makelisting.asp?year="+ data.requestpartdata[index].year +"&yearId=" + data.requestpartdata[index].yearid+"'>" + data.requestpartdata[index].year +"</a>&nbsp;<a target='' href='http://getusedparts.com/modellisting.asp?year="+data.requestpartdata[index].year+"&yearId="+data.requestpartdata[index].yearid+"&make="+data.requestpartdata[index].make+"&makeId="+data.requestpartdata[index].makeid +"'>"+data.requestpartdata[index].make+"</a>&nbsp;<a target='' href='http://getusedparts.com/partlisting.asp?year="+data.requestpartdata[index].year +"&yearId="+data.requestpartdata[index].yearid +"&make="+data.requestpartdata[index].make +"&makeId="+data.requestpartdata[index].makeid +"&model="+data.requestpartdata[index].model +"&modelId="+data.requestpartdata[index].modelid+"'>"+ data.requestpartdata[index].model +"</a></span><p></div>"
                        $('<li/></li>').addClass('item').html(htmlstr).appendTo('#main_ul');
                    }
                }
                else
                {
                    if(location.search(",")>0) // check weather the state is available or not
                    {
                        htmlstr="<div class='roundedDivAlt'><p style='padding-top:14px;'><span style='font-weight:bold;'>"+ data.requestpartdata[index].firstname+ " </span>in <span style='font-weight:bold;'><a  target='' href='http://getusedparts.com/partrequestlistingbycountry.asp?country="+ data.requestpartdata[index].country +"&countryId=" + data.requestpartdata[index].countryid + "&state=" + data.requestpartdata[index].state + "&stateId=" + data.requestpartdata[index].stateid + "&source=fromstate'>" + data.requestpartdata[index].location + "</a> </span>needs a <span style='font-weight:bold;'><a target='' href='http://getusedparts.com/partrequestdetail.asp?year="+data.requestpartdata[index].year+"&yearId="+data.requestpartdata[index].yearid+"&make="+data.requestpartdata[index].make+"&makeId="+data.requestpartdata[index].makeid+"&model="+data.requestpartdata[index].model+"&modelId="+data.requestpartdata[index].modelid+"&part="+data.requestpartdata[index].part+"&partId="+data.requestpartdata[index].partid+"&reqid="+data.requestpartdata[index].reqid+"'>"+ data.requestpartdata[index].part +"</a></span> for a <span style='font-weight:bold;'> <a target='' href='http://getusedparts.com/makelisting.asp?year="+ data.requestpartdata[index].year +"&yearId=" + data.requestpartdata[index].yearid+"'>" + data.requestpartdata[index].year +"</a>&nbsp;<a target='' href='http://getusedparts.com/modellisting.asp?year="+data.requestpartdata[index].year+"&yearId="+data.requestpartdata[index].yearid+"&make="+data.requestpartdata[index].make+"&makeId="+data.requestpartdata[index].makeid +"'>"+data.requestpartdata[index].make+"</a>&nbsp;<a target='' href='http://getusedparts.com/partlisting.asp?year="+data.requestpartdata[index].year +"&yearId="+data.requestpartdata[index].yearid +"&make="+data.requestpartdata[index].make +"&makeId="+data.requestpartdata[index].makeid +"&model="+data.requestpartdata[index].model +"&modelId="+data.requestpartdata[index].modelid+"'>"+ data.requestpartdata[index].model +"</a></span><p></div>"                        
                        $('<li></li>').addClass('item').html(htmlstr).appendTo('#main_ul');
                    }
                    else
                    {
                        htmlstr="<div class='roundedDivAlt'><p style='padding-top:14px;'><span style='font-weight:bold;'>"+ data.requestpartdata[index].firstname+ " </span>in <span style='font-weight:bold;'><a  target='' href='http://getusedparts.com/partrequestlistingbycountry.asp?country="+ data.requestpartdata[index].country +"&countryId=" + data.requestpartdata[index].countryid +  "&source=fromcountry'>" + data.requestpartdata[index].location + "</a> </span>needs a <span style='font-weight:bold;'><a target='' href='http://getusedparts.com/partrequestdetail.asp?year="+data.requestpartdata[index].year+"&yearId="+data.requestpartdata[index].yearid+"&make="+data.requestpartdata[index].make+"&makeId="+data.requestpartdata[index].makeid+"&model="+data.requestpartdata[index].model+"&modelId="+data.requestpartdata[index].modelid+"&part="+data.requestpartdata[index].part+"&partId="+data.requestpartdata[index].partid+"&reqid="+data.requestpartdata[index].reqid+"'>"+ data.requestpartdata[index].part +"</a></span> for a <span style='font-weight:bold;'> <a target='' href='http://getusedparts.com/makelisting.asp?year="+ data.requestpartdata[index].year +"&yearId=" + data.requestpartdata[index].yearid+"'>" + data.requestpartdata[index].year +"</a>&nbsp;<a target='' href='http://getusedparts.com/modellisting.asp?year="+data.requestpartdata[index].year+"&yearId="+data.requestpartdata[index].yearid+"&make="+data.requestpartdata[index].make+"&makeId="+data.requestpartdata[index].makeid +"'>"+data.requestpartdata[index].make+"</a>&nbsp;<a target='' href='http://getusedparts.com/partlisting.asp?year="+data.requestpartdata[index].year +"&yearId="+data.requestpartdata[index].yearid +"&make="+data.requestpartdata[index].make +"&makeId="+data.requestpartdata[index].makeid +"&model="+data.requestpartdata[index].model +"&modelId="+data.requestpartdata[index].modelid+"'>"+ data.requestpartdata[index].model +"</a></span><p></div>"
                        $('<li></li>').addClass('item').html(htmlstr).appendTo('#main_ul');
                    }
                }
            }
                // set the animation style of the items data display
                $('.items').vTicker({speed: 2000, animation: 'fade',showItems:3,direction: 'down',height: 159});
   }
   
}

