var layer=new Array();
var dragObj=new Array();
var dragObjId=new Array();
//新的2009-4-20 10:33:36
function buildSelectCat(param){
	    if(IMGPATH==""||IMGPATH==null){
	    IMGPATH = '/cisweb'
	    }
	    mainTable = initJobArea()
        // dragObjId[0]=param;

	    layer[0] = document.createElement("div");
		layer[0].style.visibility='hidden';
		layer[0].style.zIndex='999';
		layer[0].innerHTML+=mainTable;
		document.body.appendChild(layer[0]);
		
		var styleWidth=layer[0].firstChild.clientWidth+'px';
		var styleHeight=layer[0].firstChild.clientHeight+'px';
		
		var layerId = param;
        
		layer[0] = set_div_style(layer[0],layerId,'0px','0px',styleWidth,'0px',"absolute","0px solid #c0d4db","default","#fff");
//		dragObj[0]=layer[0].firstChild.firstChild.firstChild.firstChild;
		dragObj[0]=document.getElementById('popupAreaTr');
		dragObj[0].style.cursor='move';
		dragObj[0].onmousedown = function(event){drag_mouse_down(event,this.parentNode.parentNode.parentNode)};
        
		if ( 1 == exp ) {
			layer[0].onselectstart=function(){return false};
			layer[0].firstChild.onresize=function(){checkAndResetStyleTop(this.parentNode)};
		}
		else {
			layer[0].firstChild.onclick=function(){checkAndResetStyleTop(this.parentNode)};
		}
		
}
function build(param){
	    if(IMGPATH==""||IMGPATH==null){
	    IMGPATH = '/cisweb'
	    }
	    mainTable = initJobArea()
        // dragObjId[0]=param;

	    layer[0] = document.createElement("div");
		layer[0].style.visibility='hidden';
		layer[0].style.zIndex='999';
		layer[0].innerHTML+=mainTable;
		document.body.appendChild(layer[0]);
		
		var styleWidth=layer[0].firstChild.clientWidth+'px';
		var styleHeight=layer[0].firstChild.clientHeight+'px';
		
		var layerId = param;
        
		layer[0] = set_div_style(layer[0],layerId,'0px','0px',styleWidth,'0px',"absolute","0px solid #c0d4db","default","#fff");
		dragObj[0]=layer[0].firstChild.firstChild.firstChild.firstChild;
		dragObj[0].style.cursor='move';
		dragObj[0].onmousedown = function(event){drag_mouse_down(event,this.parentNode.parentNode.parentNode.parentNode)};
        
		if ( 1 == exp ) {
			layer[0].onselectstart=function(){return false};
			layer[0].firstChild.onresize=function(){checkAndResetStyleTop(this.parentNode)};
		}
		else {
			layer[0].firstChild.onclick=function(){checkAndResetStyleTop(this.parentNode)};
		}
		
}

function hiddenLayerOther(layerID){
	for( var i=0;i<dragObjId.length;i++ ){
		if ( dragObjId[i] != layerID && document.getElementById(dragObjId[i]) != null ) {
			hiddenLayer(dragObjId[i]);
		}
	}
}

function displayLayer(layerID){
	if ( document.getElementById(layerID) != null){
		var dv = document.getElementById(layerID);
		hiddenLayerOther(layerID);
		if ( dv.style.visibility == "hidden" ) {
			GetCenterXY_ForLayer(dv);
			dv.style.visibility = "visible";
		}
		document.body.onmousemove = function (event){drag(event,dv)};
		document.body.onmouseup = function(){objX = 0;objY=0};
	}
	return false;
}

function hiddenLayer(){
	var argArr = hiddenLayer.arguments;
	for(var i=0;i<argArr.length;i++){
		if ( document.getElementById(argArr[i])!=null ) {
			if ( argArr[i] == 'popupArea' ) {
				document.getElementById('sub_'+argArr[i]).innerHTML='';
				document.getElementById('tr_sub_'+argArr[i]).style.display='none';
				document.getElementById('thd_'+argArr[i]).innerHTML='';
				document.getElementById('tr_thd_'+argArr[i]).style.display='none';
				document.getElementById('four_'+argArr[i]).innerHTML='';
				document.getElementById('tr_four_'+argArr[i]).style.display='none';
				document.getElementById('tr_choose').style.display='none';
			}
			document.getElementById(argArr[i]).style.visibility = "hidden";
		}
	}
}

function alertNull(){
 alert("该类别下无四级类别!\n 搜索条件只能选择四级类别才能搜索")

}

function save(show,value){
  form.gccode.value=value;
	
	if ( document.getElementsByName("btnSltArea")[0] != null ) {
		document.getElementsByName("btnSltArea")[0].value = show;
	}
	if ( document.getElementsByName("btnSltArea")[1] != null ) {
		document.getElementsByName("btnSltArea")[1].value = show;
	}
 	cancel();
 	hiddenLayer("popupArea");

}
function showSubjobarea(show,value,tag){
	var htmlDiv1 = '';
	var lineImg = '';
	var tr = '';
	if(goodsType2Name[tag].length == 0){
		sltJobarea(show,value);
	}
	
	else {
		
		var j = (6 - goodsType2Name[tag].length%6) == 6 ? 0 : (6 - goodsType2Name[tag].length%6);
		htmlDiv1+= "<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#FFFFFF>";
		htmlDiv1+= "<tr><td colspan=6 align=left>&nbsp;&nbsp;请选择二级类别</td></tr>";
		htmlDiv1+= "<tr>";
		
		for(var k=0;k<goodsType2Name[tag].length;k++){
			if(k%6 == 5){
				lineImg='';
				tr="</tr><tr>";
			}
			else {
				lineImg="<img src=\""+IMGPATH+"/images/line_bg.gif\">";
				tr='';
			}			
			htmlDiv1+= "<td width=100 height=20 align=center><span onmouseover=\"this.style.color=\'#ff7300\'\" onmouseout=\"this.style.color=\'\'\" style=\"cursor:pointer\" onclick=\"show_third_lev(\'"+goodsType2Name[tag][k]+"\',\'"+goodsType2Id[tag][k]+"\',\'"+tag+"\',\'"+k+"\')\">"+goodsType2Name[tag][k]+"</span></td>";
			htmlDiv1+= "<td width=1 height=20 align=center valign=middle>"+lineImg+"</td>";
			htmlDiv1+=tr;
		}
		if(j > 0){
			for(var l=1;l<=j;l++){
				lineImg=( j == l )?"":"<img src=\""+IMGPATH+"/images/line_bg.gif\">";
				htmlDiv1+= "<td width=100 height=20>&nbsp;</td>";
				htmlDiv1+= "<td width=1 height=20 align=center valign=middle>"+lineImg+"</td>";
			}
			htmlDiv1+= "</tr>";
		}
		htmlDiv1+= "</table></td></tr></table>";
		if ( document.getElementById('popupArea')!=null && document.getElementById('sub_popupArea') ) {
			document.getElementById('sub_popupArea').innerHTML=htmlDiv1;
			document.getElementById('tr_sub_popupArea').style.display="";
			document.getElementById('thd_popupArea').innerHTML='';
			document.getElementById('tr_thd_popupArea').style.display='none';
			document.getElementById('four_popupArea').innerHTML='';
			document.getElementById('tr_four_popupArea').style.display='none';
			document.getElementById('choose').innerHTML ="您当前选择的类别是："+show+"<span><a onclick=\"javascript:save(\'"+show+"\',\'"+value+"\');hiddenLayer(\'popupArea\');\" style=\"cursor:pointer;\">    [确定选择]</a></span>";
			document.getElementById('tr_choose').style.display="";
		}
	}
}
function show_third_lev(show,value,tag,tag1){
	var htmlDiv1 = '';
	var lineImg = '';
	var tr = '';
	
	if(goodsType3Id[tag][tag1].length == 0){
		sltJobarea(show,value);
	}
	else {
	    
		var j = (6 - goodsType3Id[tag][tag1].length%6) == 6 ? 0 : (6 - goodsType3Id[tag][tag1].length%6);
		htmlDiv1+= "<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#FFFFFF>";
		htmlDiv1+= "<tr><td colspan=6 align=left>&nbsp;&nbsp;请选择三级类别</td></tr>";
		htmlDiv1+= "<tr>";
		
		for(var k=0;k<goodsType3Id[tag][tag1].length;k++){
			if(k%6 == 5){
				lineImg='';
				tr="</tr><tr>";
			}
			else {
				lineImg="<img src=\""+IMGPATH+"/images/line_bg.gif\">";
				tr='';
			}			
			htmlDiv1+= "<td width=100 height=20 align=center><span onmouseover=this.style.color=\'#ff7300\' onmouseout=\"this.style.color=\'\'\" style=\"cursor:pointer\" onclick=\"show_four_lev(\'"+goodsType3Name[tag][tag1][k]+"\',\'"+goodsType3Id[tag][tag1][k]+"\',\'"+tag+"\',\'"+tag1+"\',\'"+k+"\');\">"+goodsType3Name[tag][tag1][k]+"</span></td>";
			htmlDiv1+= "<td width=1 height=20 align=center valign=middle>"+lineImg+"</td>";
			htmlDiv1+=tr;
		}
		if(j > 0){
			for(var l=1;l<=j;l++){
				lineImg=( j == l )?'':"<img src=\""+IMGPATH+"/images/line_bg.gif\">";
				htmlDiv1+= "<td width=100 height=20>&nbsp;</td>";
				htmlDiv1+= "<td width=1 height=20 align=center valign=middle>"+lineImg+"</td>";
			}
			htmlDiv1+= "</tr>";
		}
		htmlDiv1+= "</table></td></tr></table>";
		if ( document.getElementById('sub_popupArea')!=null && document.getElementById('thd_popupArea') ) {
			  
			  document.getElementById('thd_popupArea').innerHTML=htmlDiv1;
			  document.getElementById('tr_thd_popupArea').style.display='';
			  document.getElementById('four_popupArea').innerHTML='';
			  document.getElementById('tr_four_popupArea').style.display='none';
			  document.getElementById('choose').innerHTML ="您当前选择的类别是："+show+"<span><a onclick=\"javascript:save(\'"+show+"\',\'"+value+"\');hiddenLayer(\'popupArea\');\" style=\"cursor:pointer;\">    [确定选择]</a></span>";
	          document.getElementById('tr_choose').style.display="";
		}
	}
}

function show_four_lev(show,value,tag,tag1,tag2){
	var htmlDiv1 = '';
	var lineImg = '';
	var tr = '';
	if(goodsType4Id[tag][tag1][tag2].length == 0){
		sltJobarea();
	}
	else {
	    
		var j = (6 - goodsType4Id[tag][tag1][tag2].length%6) == 6 ? 0 : (6 - goodsType4Id[tag][tag1][tag2].length%6);
		htmlDiv1+= "<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#FFFFFF>";
		htmlDiv1+= "<tr><td colspan=6 align=left>&nbsp;&nbsp;请选择四级类别</td></tr>";
		htmlDiv1+= "<tr>";
		
		for(var k=0;k<goodsType4Id[tag][tag1][tag2].length;k++){
			if(k%6 == 5){
				lineImg='';
				tr="</tr><tr>";
			}
			else {
				lineImg="<img src=\""+IMGPATH+"/images/line_bg.gif\">";
				tr='';
			}			
			htmlDiv1+= "<td width=100 height=20 align=center><span onmouseover=\"this.style.color=\'#ff7300\'\" onmouseout=\"this.style.color=\'\'\" style=\"cursor:pointer\" onclick=\"sltJobarea(\'"+goodsType4Name[tag][tag1][tag2][k]+"\',\'"+goodsType4Id[tag][tag1][tag2][k]+"\');\">"+goodsType4Name[tag][tag1][tag2][k]+"</span></td>";
			htmlDiv1+= "<td width=1 height=20 align=center valign=middle>"+lineImg+"</td>";
			htmlDiv1+=tr;
		}
		if(j > 0){
			for(var l=1;l<=j;l++){
				lineImg=( j == l )?'':"<img src=\""+IMGPATH+"/images/line_bg.gif\">";
				htmlDiv1+= "<td width=100 height=20>&nbsp;</td>";
				htmlDiv1+= "<td width=1 height=20 align=center valign=middle>"+lineImg+"</td>";
			}
			htmlDiv1+= "</tr>";
		}
		htmlDiv1+= "</table></td></tr></table>";
		
		if ( document.getElementById('thd_popupArea')!=null && document.getElementById('four_popupArea') ) {
			document.getElementById('four_popupArea').innerHTML=htmlDiv1;
			document.getElementById('tr_four_popupArea').style.display='';
			document.getElementById('choose').innerHTML ="您当前选择的类别是："+show+"<span><a onclick=\"javascript:save(\'"+show+"\',\'"+value+"\');hiddenLayer(\'popupArea\');\" style=\"cursor:pointer;\">    [确定选择]</a></span>";
	        document.getElementById('tr_choose').style.display="";
		}
	}
}



function sltJobarea(show,value){
    
	document.getElementById('choose').innerHTML ="您当前选择的类别是："+show+"<span><a onclick=\"javascript:save(\'"+show+"\',\'"+value+"\');hiddenLayer(\'popupArea\');\" style=\"cursor:pointer;\">    [确定选择]</a></span>";
	document.getElementById('tr_choose').style.display="";
}

function initJobArea(){
	var htmlDiv = '';
	
	
	var j = (6 - goodsType1Name.length%6) == 6 ? 0 : (6 - goodsType1Name.length%6);
	htmlDiv+="<table width=645 border=0 cellspacing=0 cellpadding=0 bgcolor=#999999>";
	
    htmlDiv+="<tr id='popupAreaTr'>  <td style=color:#FFFFFF; align=left valign=middle width=599 height=27 background=\""+IMGPATH+"/images/"+php_bgPicture+"\">&nbsp;&nbsp;<img src=\""+IMGPATH+"/images/"+php_arrow+"\">&nbsp;请选择指数类别</td>  <td align=left valign=middle width=50 height=27 background=\""+IMGPATH+"/images/"+php_bgPicture+"\"><span><a onclick=\"javascript:cancel();hiddenLayer(\'popupArea\');\" style=\"color:#FFFFFF;cursor:pointer;\">[关闭]</a></span></td></tr>";
    
    htmlDiv+="<tr><td colspan=2 width=645 valign=top><table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#FFFFFF>";
	htmlDiv+="<tr><td width=100 height=20 align=center><span onclick=\"javascript:sltJobarea(\'总指数\',\'ROOTINDEX\')\" style=\"cursor:pointer;\" onmouseover=\"this.style.color=\'#ff7300\'\" onmouseout=\"this.style.color=\'\'\">总指数</span></td><td colspan=5></td></tr>" + "<tr>";
	
	var lineImg='';
	var tr='';
	for(var k=0;k<goodsType1Name.length;k++){
		if(k%6 == 5){
			lineImg='';
			tr="</tr><tr>";
		}
		else {
			lineImg="<img src=\""+IMGPATH+"/images/line_bg.gif\">";
			tr='';
		}
		htmlDiv+="<td width=100 height=20 align=center><span style=\"cursor:pointer\" onmouseover=\"this.style.color=\'#ff7300\'\" onmouseout=\"this.style.color=\'\'\" onclick=\"showSubjobarea(\'"+goodsType1Name[k]+"\',\'"+goodsType1Id[k]+"\',\'"+k+"\');\">"+goodsType1Name[k]+"</span></td>";
		htmlDiv+="<td width=1 height=20 align=center valign=middle>"+lineImg+"</td>";
		htmlDiv+=tr;
	}
	if(j > 0){
		for(var l=1;l<=j;l++){
			lineImg=( j == l )?"":"<img src=\""+IMGPATH+"/images/line_bg.gif\">";
			htmlDiv+="<td width=100 height=20>&nbsp;</td>";
			htmlDiv+="<td width=1 height=20 align=center valign=middle>"+lineImg+"</td>";
		}
		htmlDiv+="</tr>";
	}
	htmlDiv+="</table>";
	htmlDiv = htmlDiv+"</td></tr>";
	htmlDiv+= "<tr><td colspan=2 height=1 bgcolor=\""+php_bgColor+"\"></td></tr>";
	htmlDiv+= "<tr id=\"tr_sub_popupArea\" style=\"display:none\"><td id=\"sub_popupArea\" colspan=2 width=645 valign=top></td></tr>";
	htmlDiv+= "<tr><td colspan=2 height=1 bgcolor=\""+php_bgColor+"\"></td></tr>";
	htmlDiv+= "<tr id=\"tr_thd_popupArea\" style=\"display:none\"><td id=\"thd_popupArea\" colspan=2 width=645 valign=top></td></tr>";
	htmlDiv+= "<tr><td colspan=2 height=1 bgcolor=\""+php_bgColor+"\"></td></tr>";
	htmlDiv+= "<tr id=\"tr_four_popupArea\" style=\"display:none\"><td id=\"four_popupArea\" colspan=2 width=645 valign=top></td></tr>";
	htmlDiv+= "<tr><td colspan=2 height=1 bgcolor=\""+php_bgColor+"\"></td></tr>";
	htmlDiv+= "<tr id=\"tr_choose\" style=\"display:none\"><td style=\"color:#ffffff; align=left; valign=middle; width=599; height=27 ;background-color:#ffffff;\" id=\"choose\" colspan=2 width=645 valign=top background=\""+IMGPATH+"/images/"+php_bgPicture+"\"></td></tr></table>";
	
	
	return htmlDiv;
}



