var typeStep=1;
var loadFlag=false;
var typeLoadFlag=false;
var map = new classMap();
function typeStruct(id,description,remark){
	this.id=id;
	this.description=description;
	this.remark=remark;	
}
firstType=new Array();
secondType=new Array();


function isnull(str)
{if(str==null||str=="")return true;
 return false;
}
var typeObj1=null;
var typeObj2=null;

function initObj(objName1,objName2){
	typeObj1=document.getElementById(objName1);
	typeObj2=document.getElementById(objName2);	
}

function initFirstType(pid,fromIndex)
{
	try{
	if(typeObj1==null)
		initObj("firstType","secondType");
	typeLoadFlag=true;
	if(isnull(fromIndex)) fromIndex=1;
	var fIndex=parseInt(fromIndex);
	var index=0;
	for(var i=fIndex;i<firstType.length;i++)	{
			if(firstType[i].id==pid) index=i+typeStep-fIndex;
			oOption = document.createElement("OPTION");
			oOption.value=firstType[i].id;
			oOption.text=firstType[i].description;
			typeObj1.options.add(oOption);			
	}
		typeObj1.selectedIndex=index;
	}catch(ex){}
}
function setTypeById(pid,cid,fromIndex)
{	
	if(typeObj1==null)
		initObj("firstType","secondType");
	if(isnull(pid)) pid=-1;
	if(isnull(cid)) cid=-1;
	clearObj(typeObj1);
	clearObj(typeObj2);
	initFirstType(parseInt(pid),fromIndex);
	if(parseInt(pid)>=0) setSecondTypeById(parseInt(pid),parseInt(cid));

}

function setSecondTypeById(pid,cid)
{
	var index=0;
	if(parseInt(pid)>=0){
		var item;
		item = map.get(parseInt(pid));
		for(var i=0;i<item.length;i++){
				if(item[i].id == cid) index=i+typeStep;
				oOption = document.createElement("OPTION");
				oOption.value=item[i].id;
				oOption.text=item[i].description;
				typeObj2.options.add(oOption);	
		}
		typeObj2.selectedIndex=index;
	}
}
function getSecondType()
{
	clearObj(typeObj2);
	var pid=typeObj1.options[typeObj1.selectedIndex].value;
	setSecondTypeById(pid,-1)
	
}
function clearObj(ObjId)
{
  var i;
  if(ObjId.length<1) return;
  for(i=ObjId.length-1;i>=0+typeStep;i--)
			ObjId.remove(i);
}

function drawTypeList(fLen,sLen){
	loadFlag=true;
	var sTable="";
	var tableHead='<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>';
	var tableFoot='</td></tr></table>';
	var item;
	for(var i=0;i<firstType.length;i++)	{
		sTable+='<ul><a href="searchProduct.action?fid='+firstType[i].id+'">'+firstType[i].description+'</a>';
		var item = map.get(parseInt(firstType[i].id));
		for(var j=0;j<item.length;j++){
			sTable+='<li><a href="searchProduct.action?sid='+item[j].id+'">'+item[j].description+'</a></li>';
		}
		sTable+='</ul>';			
	}
	sTable=tableHead+sTable+tableFoot;
	document.getElementById("divTypeList").innerHTML=sTable;
	
		
	
}