	function Search(data)
	{
		this.data = data;
	}
	
	Search.prototype.BindOption = Search_BindOption;
	Search.prototype.GetResultData = Search_GetResultData;
	Search.prototype.ShowResult = Search_ShowResult;
	
	function Search_BindOption(OptionsId)
	{
	    if ($(OptionsId))
	   { 
		    var o = $(OptionsId);
			o.options.length = 1;
		    for (var prop in this.data)
		    {
			    var OptionName = this.data[prop]["省份"];
			    var OptionValue = OptionName;
    			
    			var n = 0;
			    for (n=0; n<o.options.length; n++)
			    {
			        if (OptionValue == o.options[n].value)
			            break;
			    }
    			
    			if (n == o.options.length)
    			{
        			var option = new Option(OptionName, OptionValue, false, false);
        			o.options[n] = option;
    			}
    			
		    }
		}
	}
	
	function Search_GetResultData(field, value)
	{
	    var props = [];
	    if (value)
	   { 
	        for (var prop in this.data)
	            if (this.data[prop][field] == value)
	                props[props.length] = prop;
	    }
        else
		{
            //props = $H(this.data).keys();
			alert("请选择好省份！");
		}
        return props;
	}
	
	function Search_ShowResult()
	{
	   var props = arguments[0];
	   var html = "";
	   for (var index=0; index<props.length; index++)
	   {
           var prop = props[index];
		   if (this.data[prop]["isPos"])
		   {
			   	html += "<h4>" + prop + "<img src='../images/icon_pos.jpg' alt='' style='vertical-align:middle;' /></h4>";
		   }
		   else
		   {
		   		html += "<h4>" + prop + "</h4>";
		   }
	       for (var pro in this.data[prop])
	       {
		   		if (this.data[prop][pro]&&(this.data[prop][pro]!="isPos"))
	                html += "<p>" + pro.valueOf() + "：" + this.data[prop][pro] + "</p>";    
	       }
	   }
	    $("result").innerHTML = html;
	}
	
	function urlShow()
	{
		var dataType = GRM.request("dataType");
		var field = decodeURI(GRM.request("field"));
		
		if (dataType && field)
		{
			switch (dataType)
			{
				case "svw":
					s = new Search(dealer_svw);
					break;
				case "skoda":
					s = new Search(dealer_skoda);
					break;
			}
			s.ShowResult(s.GetResultData("省份", field));
		}
	}
	
	Event.observe(window, "load", function(){

		urlShow();

		$("cartype").selectedIndex = 0;
		$("dealer").selectedIndex = 0;
		
		
		$("cartype").onchange = function()
		{
            switch ($("cartype").value)
            {
            case "svw":
				s = new Search(dealer_svw);
				s.BindOption("dealer");
				break;
            case "skoda":
				s = new Search(dealer_skoda);
				s.BindOption("dealer");
				break;
			default:
				$("dealer").options.length = 1;
            }
		};
		
		if($("search"))
		{
			$("search").onclick = function()
			{
				if ($("cartype").value=="")
				{
					alert("请选择好经销商！");
				} else
				{
					s.ShowResult(s.GetResultData("省份", $("dealer").value));
				}
			};
		}

		if($("search_index"))
		{
			$("search_index").onclick = function()
			{
				if ($("cartype").value=="" || $("dealer").value=="")
				{
					alert("请选择好经销商以及省份!");
				} else
				{
					location.href="../xchange/dealer.html?dataType="+ $("cartype").value +"&field="+ encodeURI($("dealer").value);
				}
			};
		}
		
		
    }, false)
   /* $j(document).ready(function()
    {

		urlShow();

		$("cartype").selectedIndex = 0;
		$("dealer").selectedIndex = 0;
		
		
		$("cartype").onchange = function()
		{
            switch ($("cartype").value)
            {
            case "svw":
				s = new Search(dealer_svw);
				s.BindOption("dealer");
				break;
            case "skoda":
				s = new Search(dealer_skoda);
				s.BindOption("dealer");
				break;
			default:
				$("dealer").options.length = 1;
            }
		};
		
		if($("search"))
		{
			$("search").onclick = function()
			{
				if ($("cartype").value=="")
				{
					alert("请选择好经销商！");
				} else
				{
					s.ShowResult(s.GetResultData("省份", $("dealer").value));
				}
			};
		}

		if($("search_index"))
		{
			$("search_index").onclick = function()
			{
				if ($("cartype").value=="" || $("dealer").value=="")
				{
					alert("请选择好经销商以及省份!");
				} else
				{
					location.href="../xchange/dealer.html?dataType="+ $("cartype").value +"&field="+ encodeURI($("dealer").value);
				}
			};
		}
		
		
    }); 
	*/