﻿<!--
var showFM, brandDD, modelDD, brand, model, pro_count;

function populateBrandModel(){
	populateBrand();
	populateModel();
}


function populateBrand() { 
	showFM = document.forms["formSearch"];
	brandDD = showFM.brand;
	//modelDD = showFM.model;
	var count_sub = 1;	
	var pro_count;
//alert('ddd');
	for (var i = 0; i < phone_brand_model_arr.length; i++) {
		brandDD.options.length += 1;
		var theData = phone_brand_model_arr[i]
		var theOption = brandDD.options[brandDD.options.length - 1];		
		theOption.text = theData["label"];
		theOption.value = theData["id"];

			if(theOption.value==brand){
				pro_count = count_sub;	
			}
				count_sub = eval(count_sub +1)	
	}	

		if(brand>0)
			brandDD.selectedIndex = pro_count;	
		else
			brandDD.selectedIndex = 0;
		
	brandDD.disabled = false;	
}

function populateModel() { 
	showFM = document.forms["formSearch"];
	brandDD = showFM.brand;
	modelDD = showFM.model;
	var count_sub = 1;	
	var model_count;
	var count_brand = 1;
	var brand_count;
	//alert(brandDD.value)
	//alert(model)
	if (modelDD.selectedIndex != -1) { 
		var selectedmodel = modelDD.options[modelDD.selectedIndex].value;
	} else {
		var selectedmodel = "";
	}

	for (var g = 0; g < phone_brand_model_arr.length; g++) {
		var theData = phone_brand_model_arr[g]
		var theOption = brandDD.options[brandDD.options.length - 1];		
		theOption.value = theData["id"];

			if(theOption.value==brandDD.value){
				brand_count = count_brand;	
			}
				count_brand = eval(count_brand +1)
	}	
	//alert(brand_count)
	
	if(brand_count>=1){
		var modelList = phone_brand_model_arr[brand_count-1]["id"]-1;
		var model_arr = phone_brand_model_arr[modelList]["model"];
	}
	else
		var model_arr = '';
	
	modelDD.options.length = 1;
	modelDD.options[0].text = '全部手机型号';
	modelDD.options[0].value = "";

	for (var j = 0; j < model_arr.length; j++) {
		modelDD.options.length += 1;
		var themodelData = model_arr[j]
		var themodelOption = modelDD.options[modelDD.options.length - 1];					

		themodelOption.text = themodelData["label"];
		themodelOption.value = themodelData["id"];	

		if(themodelOption.value==model){
			model_count = count_sub;	
		}
		count_sub = eval(count_sub +1)
	}		
	//alert(model_count)

	if(model>0)
		modelDD.selectedIndex = model_count;
	else
		modelDD.selectedIndex = 0;
		
	modelDD.disabled = false;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(populateBrandModel);
//-->