var flag = new Array();
function searchProduct(linkURL,CategoryID)
{
	var date = new Date();	
	//CategoryID传递给分类商品展示组件
	self.location=linkURL + "?ProductPicker_action=Searchcategory&CategoryID=" + CategoryID + "&time=" + date.getTime();	
}

/*
	   加载时如果按钮数量大于最大可显示值，隐藏多于部分
*/
 function load(maxLength,total,CompName0){
  var flag = new Array(total);
  var lastValue = 0;  
  CompName = CompName0 + "_";
  if(parseInt(total)>parseInt(maxLength)){
		lastValue = parseInt(maxLength);
	}else{
		lastValue = parseInt(total);
	}
	firstValue = 1;
	for(var i=lastValue + 1;i<=total;i++){
			document.all(CompName + "button" + i).style.display="none";	
			document.all(CompName + "tr" + i).style.display="none";	
			document.all(CompName + "td" + i).style.display="none";	
			document.all(CompName + "trselect" + i).style.display="none";	
			document.all(CompName + "tdselect" + i).style.display="none";	
			document.all(CompName + "select" + i).style.display="none";
	}
	for(var i=lastValue+ 1;i<=total;i++){
	 flag[i]=0;
	}
}
/*function load(maxLength,total,CompName0){
  var lastValue = 0;
  CompName = CompName0 + "_";
  if(parseInt(total)>parseInt(maxLength)){
		lastValue = parseInt(maxLength);
	}else{
		lastValue = parseInt(total);
	}
	firstValue = 1;
	for(var i=lastValue + 1;i<=total;i++){
			document.all(CompName + "button" + i).style.display="none";	
			document.all(CompName + "tr" + i).style.display="none";	
			document.all(CompName + "td" + i).style.display="none";	
			document.all(CompName + "trselect" + i).style.display="none";	
			document.all(CompName + "tdselect" + i).style.display="none";	
			document.all(CompName + "select" + i).style.display="none";
	}
}*/

function isLastDisplay(CompName){
	var isLast = false;
	if(document.all(CompName + "pos").value==document.all(CompName + "LastValue").value){
		isLast = true;
	}
	return isLast;
}

/* 是否显示的最上一个按钮 */
function isFirstDisplay(CompName){
	var isFirst = false;
	if(document.all(CompName + "pos").value==document.all(CompName + "FirstValue").value){
		isFirst = true;
	}
	return isFirst;
}
/* 
   向上移动按钮组 
   如果未显示的按钮数量leftNum小于可显示的最大值maxLength;则上移leftNum,
   否则上移maxLength,lastValue 值增加上移量l,leftNum
*/   
function moveupButtons(maxLength,total,CompName){
  
	for(i = parseInt(document.all(CompName + "FirstValue").value);i<=parseInt(document.all(CompName + "LastValue").value);i++){
		document.all(CompName + "tr" + i).style.display = "none";
		document.all(CompName + "td" + i).style.display = "none";
		document.all(CompName + "button" + i).style.display = "none";
	}
  var leftNum = total - parseInt(document.all(CompName + "LastValue").value);
	var moveNum = 0;
	if(leftNum>maxLength){
		moveNum = maxLength;
	}else{
		moveNum = leftNum;
	}
	
  
	document.all(CompName + "LastValue").value =parseInt(document.all(CompName + "LastValue").value)+ moveNum;
	document.all(CompName + "FirstValue").value = parseInt(document.all(CompName + "FirstValue").value) + moveNum;
		
	for(k = parseInt(document.all(CompName + "FirstValue").value);k<=parseInt(document.all(CompName + "LastValue").value);k++){
	  document.all(CompName + "tr" + k).style.display = "block";
	  document.all(CompName + "td" + k).style.display = "block";
	  document.all(CompName + "button" + k).style.display = "block";
	}
}
/* 
   向下移动按钮组 
*/   
function movedownButtons(maxLength,total,CompName){
  
	for(var i = parseInt(document.all(CompName + "FirstValue").value);i<=parseInt(document.all(CompName + "LastValue").value);i++){
		document.all(CompName + "tr" + i).style.display = "none";
		document.all(CompName + "td" + i).style.display = "none";
		document.all(CompName + "button" + i).style.display = "none";
	}
	var leftNum = parseInt(document.all(CompName + "FirstValue").value)-1;
	var moveNum = 0;
	if(leftNum>maxLength){
		moveNum = maxLength;
	}else{
		moveNum = leftNum;
	}
  
  
	document.all(CompName + "LastValue").value = parseInt(document.all(CompName + "LastValue").value)- moveNum;
	document.all(CompName + "FirstValue").value = parseInt(document.all(CompName + "FirstValue").value) - moveNum;
	
	
	for(k = parseInt(document.all(CompName + "FirstValue").value);k<=parseInt(document.all(CompName + "LastValue").value);k++){
	   document.all(CompName + "tr" + k).style.display = "block";
	   document.all(CompName + "td" + k).style.display = "block";
	   document.all(CompName + "button" + k).style.display = "block";
  }
	
}
//打开对应于二级分类的列表框
/* function openSelect(button,total,childNum,CompName){
  var aa = eval(button);
  var leng = CompName.length;
 // var state = eval(CompName + "posSelectState");
 var ProductCategoryExhibitLadder1_posSelectState = eval(ProductCategoryExhibitLadder1_posSelectState);
  document.all(CompName + "pos").value = aa.id.substring(leng+6,aa.id.length);
  for(var i=1;i<=parseInt(total);i++){
    document.all(CompName + "trselect" + i).style.display = "none";
    document.all(CompName + "tdselect" + i).style.display = "none";
	  document.all(CompName + "select" + i).style.display = "none";
	}
	//如果有子元素，显示列表框,并设打开标志位为真
	if(parseInt(childNum)>0){
	if(document.all(ProductCategoryExhibitLadder1_posSelectState).value == true){	  
	   document.all(CompName + "trselect" + document.all(CompName + "pos").value).style.display = "none";
	   document.all(CompName + "tdselect" + document.all(CompName + "pos").value).style.display = "none";
	   document.all(CompName + "select" + document.all(CompName + "pos").value).style.display = "none";
		 document.all(ProductCategoryExhibitLadder1_posSelectState).value = false;
	  // alert("test1");
		 }	  
	 else{ 			 
		 document.all(CompName + "trselect" + document.all(CompName + "pos").value).style.display = "block";
	   document.all(CompName + "tdselect" + document.all(CompName + "pos").value).style.display = "block";
		 document.all(CompName + "select" + document.all(CompName + "pos").value).style.display = "block";	  
	   document.all(ProductCategoryExhibitLadder1_posSelectState).value = true;
		 //alert("test2");
	  }
 }
}*/
  function openSelect(button,total,childNum,CompName){
  var aa = eval(button);
  var leng = CompName.length;
  var j=0;
  var ProductCategoryExhibitLadder1_pos = eval (ProductCategoryExhibitLadder1_pos);  
  document.all(CompName + "pos").value = aa.id.substring(leng+6,aa.id.length);
 /*  for(var i=1;i<=parseInt(total);i++){
   document.all(CompName + "trselect" + i).style.display = "none";
   document.all(CompName + "tdselect" + i).style.display = "none";
	 document.all(CompName + "select" + i).style.display = "none";
	} */
	//如果有子元素,并且打开标志位为真时隐藏列表框,并设打开标志位为假;否则显示列表框,并设打开标志位为真。
  var ProductCategoryExhibitLadder1_posSelectState = eval (CompName +"posSelectState");  
	if(parseInt(childNum)>0){	
	if(flag[document.all(CompName + "pos").value] == 1){    
	   document.all(CompName + "trselect" + document.all(CompName + "pos").value).style.display = "none";
	   document.all(CompName + "tdselect" + document.all(CompName + "pos").value).style.display = "none";
	   document.all(CompName + "select" + document.all(CompName + "pos").value).style.display = "none";	
	   flag[document.all(CompName + "pos").value] = 0;		
		}  
	 else{	
	   document.all(CompName + "trselect" + document.all(CompName + "pos").value).style.display = "block";
	   document.all(CompName + "tdselect" + document.all(CompName + "pos").value).style.display = "block";
	   document.all(CompName + "select" + document.all(CompName + "pos").value).style.display = "block";
	   flag[document.all(CompName + "pos").value] = 1;	  
	   }	
}
}
 
//“按钮组”向上移动
function moveup(maxLength,total,CompName){
  	
	if(parseInt(document.all(CompName + "FirstValue").value)!=parseInt(total)){
		moveupButtons(parseInt(maxLength),parseInt(total),CompName);
	}
	
	//Make only the select after the clicked button visible
	for(var i=1;i<=parseInt(total);i++){
	  document.all(CompName + "trselect" + i).style.display = "none";
	  document.all(CompName + "tdselect" + i).style.display = "none";
		document.all(CompName + "select" + i).style.display = "none";
	}
	
	if(parseInt(document.all(CompName + "pos").value)<=parseInt(document.all(CompName + "LastValue").value) && parseInt(document.all(CompName + "pos").value)>=parseInt(document.all(CompName + "FirstValue").value) && document.all(CompName + "posSelectState").value){
		document.all(CompName + "trselect" + document.all(CompName + "pos").value).style.display = "block";
		document.all(CompName + "tdselect" + document.all(CompName + "pos").value).style.display = "block";
		document.all(CompName + "select" + document.all(CompName + "pos").value).style.display = "block";
	}
	
	
}
//“按钮组”向下移动
function movedown(maxLength,total,CompName){

  if(parseInt(document.all(CompName + "FirstValue").value)!=1) {
		movedownButtons(parseInt(maxLength),parseInt(total),CompName);
	}
	
	//Make only the select after the clicked button visible
	for(var i=1;i<=parseInt(total);i++){
	  document.all(CompName + "trselect" + i).style.display = "none";
	  document.all(CompName + "tdselect" + i).style.display = "none";
	  document.all(CompName + "select" + i).style.display = "none";
		
	}
	//如果被点击的div(select)位置在First,Last之间，则显示
	if(parseInt(document.all(CompName + "pos").value)<=parseInt(document.all(CompName + "LastValue").value) && parseInt(document.all(CompName + "pos").value)>=parseInt(document.all(CompName + "FirstValue").value) && document.all(CompName + "posSelectState").value){
		document.all(CompName + "trselect" + document.all(CompName + "pos").value).style.display = "block";
		document.all(CompName + "tdselect" + document.all(CompName + "pos").value).style.display = "block";
		document.all(CompName + "select" + document.all(CompName + "pos").value).style.display = "block";
	}
}
