/* Product Finder mod
/includes/templates/YOUR_TEMPLATE/jscript/jscript_model_year.php
@license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
@version $Id: jscript_model_year.php 2010-09-29
*/

$(document).ready(function(){
    $("#pCath").change(pCathList);
    $("#cPath").change(cPathList);
    $("#cPath2").change(modelList);
    $("#select_model").change(yearList);
    $("#select_year").change(function() {
        var baseDirectory=document.getElementById("basemodulepath").value;
        var cPath0=$("#pCath").val();
        var cPath1=$("#cPath").val();
        var cPath2=$("#cPath2").val();
        var cPath3=$("#select_model").val();
        var cPath4=$("#select_year").val();
        $("#loader").show();
        window.location=(baseDirectory+"index.php?main_page=index&cPath="+cPath0+"_"+cPath1+"_"+cPath2+"_"+cPath3+"_"+cPath4);
    }
             );
  });

function buildSelect(id, data) {
    if(data!=""){
        arrayVar     = new Array();
        arrayVarId   = new Array();
        arrayVarName = new Array();

        arrayVar     = data.split("|");
        arrayVarId   = arrayVar[0].split("^");
        arrayVarName = arrayVar[1].split("^");
        $('#' + id).html("");
        $('#' + id).append("<option value=''>Please Select</option>");
        for(i=0; i < arrayVarId.length ;i++) {
            $('#'+id).append('<option value="'+arrayVarId[i]+'">'+arrayVarName[i]+'</option>');
        }
    }
}
var pCathList=function pCath_list(){
	                        var baseDirectory=document.getElementById("basemodulepath").value;
							var cPath=document.getElementById("pCath").value;
						    $.ajax({
                                type: 'POST',
                                url:baseDirectory+"modellist.php",
                                data:"cPath="+cPath+"&my=1",
                                success: function(data){
								    buildSelect('cPath', data);    
								},
                                beforeSend: function() {
                                    $('#loader').show()
                                },
                                complete: function(){
                                     $('#loader').hide()
                                }
			                 });
			   		};

var cPathList=function cpath_list(){
	                        var baseDirectory=document.getElementById("basemodulepath").value;
							var cPath=document.getElementById("cPath").value;
						    $.ajax({
                                type: 'POST',
                                url:baseDirectory+"modellist.php",
                                data:"cPath="+cPath+"&my=1",
                                success: function(data){
								    buildSelect('cPath2', data);    
								},
                                beforeSend: function() {
                                    $('#loader').show()
                                },
                                complete: function(){
                                     $('#loader').hide()
                                }

			                 });
			   		};

var cPath2List=function cpath2_list(){
	                        var baseDirectory=document.getElementById("basemodulepath").value;
							var cPath=document.getElementById("cPath").value;
						    $.ajax({
                                type: 'POST',
                                url:baseDirectory+"modellist.php",
                                data:"cPath="+cPath+"&my=1",
                                success: function(data){
								    buildSelect('select_model', data);    
								},
                                beforeSend: function() {
                                    $('#loader').show()
                                },
                                complete: function(){
                                     $('#loader').hide()
                                }

			                 });
			   		};


var modelList=function model_list(){
	                        var baseDirectory=document.getElementById("basemodulepath").value;
							var cPath=document.getElementById("cPath2").value;
						    $.ajax({
                                type: 'POST',
                                url:baseDirectory+"modellist.php",
                                data:"cPath="+cPath+"&my=1",
                                success: function(data){
								    buildSelect('select_model', data);    
								},
                                beforeSend: function() {
                                    $('#loader').show()
                                },
                                complete: function(){
                                     $('#loader').hide()
                                }

			                 });
			   		};
var yearList=function year_list(){
	                        var baseDirectory=document.getElementById("basemodulepath").value;
							var cPath=document.getElementById("select_model").value;
						    $.ajax({
                            type: 'POST',
                            url:baseDirectory+"modellist.php",
                            data:"cPath="+cPath+"&my=2",
                            success: function(data){
                                buildSelect('select_year', data);
                                },
                                beforeSend: function() {
                                    $('#loader').show()
                                },
                                complete: function(){
                                     $('#loader').hide()
                                }

			                 });
			   	     };

