var bV=parseInt(navigator.appVersion);
NS4=(document.layers) ? true : false;
IE5=((document.all)&&(bV>=4))?true:false;
NS6=((bV>=4) && (!document.all))?true:false;
ver5 = (IE5 || NS6) ? true : false;

function highlight(id, num, doc, row, checked, highlightColor, darkColor, lightColor) {
//if (id.length == null || id.length == undefined) {
   if (NS6) {
	     if (id.length == null  || id.length == '' || id.length == undefined) {
		    id.checked = checked;
          } else {
		   id[num].checked = checked;
       }
   } else {
	     if ( id.length == 'undefined' || id.length == null || id.length == '') {
		    id.checked = checked;
	      } else {
		   id[num].checked = checked;
	  }
  }

	if (NS6) {
		if (id.length == null || id.length == '' || id.length == undefined ) {
			selectedElement = document.getElementById(row+"_"+num);
				if (id.type=="checkbox")
			colorIt(selectedElement, id.checked, num, highlightColor, lightColor, darkColor);
		} else {
			for(i=0; i<id.length; i++) {
				selectedElement = document.getElementById(row+"_"+i);
						if (id[i].type=="checkbox")
				colorIt(selectedElement, id[i].checked, i, highlightColor, lightColor, darkColor);
				  }
			}
     } else {
		if ( id.length == 'undefined' || id.length == null || id.length == '' ) {
			selectedElement = document.getElementById(row+"_"+num);
				if (id.type=="checkbox")	
			colorIt(selectedElement, id.checked, num, highlightColor, lightColor, darkColor);
		} else {
			for(i=0; i<id.length; i++) {
				selectedElement = document.getElementById(row+"_"+i);
				if (id[i].type=="checkbox")
				colorIt(selectedElement, id[i].checked, i, highlightColor, lightColor, darkColor);
				  }
		   }
     }
}

//--- selectAll  using checkbox
function selectAll(doc, input_id, status, row_id, highlightColor, darkColor, lightColor) {
	selectallList = document.getElementsByName("selectall");
	if (selectallList.length > 0) {
		for (i=0; i< selectallList.length; i++) {
			selectall = selectallList.item(i);
			selectall.checked = status;
		}
	}
	
	if (NS6) {
	    if ( input_id.length == undefined || input_id.length == null || input_id.length == '' ) {
			highlight(input_id,0, doc, row_id, status, highlightColor, darkColor, lightColor);
		} else {
			for (var i=0; i<input_id.length; i++) {

				highlight(input_id,i, doc, row_id, status, highlightColor, darkColor, lightColor);
			}
		}
	} else {
	    if ( input_id.length == 'undefined' || input_id.length == null || input_id.length == '' ) {
			highlight(input_id,0, doc, row_id, status, highlightColor, darkColor, lightColor);
		} else {
			for (var i=0; i<input_id.length; i++) {
				highlight(input_id,i, doc, row_id, status, highlightColor, darkColor, lightColor);
			}
		}
	}
	
}
//---end selectAll  using checkbox

//--- selectAll  using link
function selectAll2(doc, input_id, row_id, highlightColor, darkColor, lightColor,chkID) {
	/*
	selectallList = document.getElementsByName("selectall");
	if (selectallList.length > 0) {
		for (i=0; i< selectallList.length; i++) {
			selectall = selectallList.item(i);
			selectall.checked = status;
		}
	}
	*/
	var setStatus=true;
	numberOfChecked=0;
	numberItemsAdded=0;
	if (doc.length>0) {
		for (var j=0;j<doc.length;j++) {
			var e = doc.elements[j];
			if(e.name==chkID && e.type == "checkbox") {
				if(e.checked == true)
					numberOfChecked++;
			}
			
			if(e.name==chkID && e.type == "hidden") //added for My 
				numberItemsAdded++;
		}
	}
	
	var id_len=0;
	if ( input_id.length == 'undefined' ||  input_id.length == undefined || input_id.length == null || input_id.length == '' )
		id_len=1;
	else 
		id_len=input_id.length;	
	   	
	if (numberOfChecked==(id_len-numberItemsAdded)) //all check
		setStatus=false;
	
	//alert("cnt="+numberOfChecked+" "+setStatus);
	if (NS6) {
	    if ( input_id.length == undefined || input_id.length == null || input_id.length == '' ) {
			highlight(input_id,0, doc, row_id, setStatus, highlightColor, darkColor, lightColor);
		} else {
			for (var i=0; i<input_id.length; i++) {
				highlight(input_id,i, doc, row_id, setStatus, highlightColor, darkColor, lightColor);
			}
		}
	} else {
	    if ( input_id.length == 'undefined' || input_id.length == null || input_id.length == '' ) {
			highlight(input_id,0, doc, row_id, setStatus, highlightColor, darkColor, lightColor);
		} else {
			for (var i=0; i<input_id.length; i++) {
				highlight(input_id,i, doc, row_id, setStatus, highlightColor, darkColor, lightColor);
			}
		}
	}
}
//---end selectAll  using link

/*
function selectAll(nameval, doc, input_id, status, row_id, highlightColor, darkColor, lightColor) {
	if (input_id.length == null || input_id.length == undefined) {
		highlight(input_id,0, doc, row_id, status, highlightColor, darkColor, lightColor);
		
	} else {
		for (var i=0; i<input_id.length; i++) {
			highlight(input_id,i, doc, row_id, status, highlightColor, darkColor, lightColor);
				} 
      !status ? nameval.checked = false : nameval.checked = true;
	}
}
*/

function bigbuyerPostingSelectAll(doc, input_id, status, row_id, highlightColor, darkColor, lightColor, size) {
	if (size == 1) {
		highlight(eval(input_id + "[0]']"),0, doc, row_id, status, highlightColor, darkColor, lightColor);
	} else {
		for (var i=0; i<size; i++) {
			highlight(eval(input_id + "["+ i +"]']"),i, doc, row_id, status, highlightColor, darkColor, lightColor);
		}
	}
}

function colorIt(selectedElement, checked, i, highlightColor, lightColor, darkColor) {
	if (!checked) {
		selectedElement.style.background = (i%2==0)?lightColor:darkColor;
	} else {
		selectedElement.style.background = highlightColor;
	}
}

function disableButton(doc, buttonColor, disableColor){
	removeButtonList = document.getElementsByName("removebutton");
	submitButtonList = document.getElementsByName("submitbutton");
	postButtonList = document.getElementsByName("execute");
	unpostButtonList = document.getElementsByName("unpostproduct");
	moveButtonList = document.getElementsByName("movebutton");

	enableDisableAllButtons(removeButtonList, false, buttonColor);
	enableDisableAllButtons(submitButtonList, false, buttonColor); 
	enableDisableAllButtons(postButtonList, false, buttonColor);
	enableDisableAllButtons(unpostButtonList, false, buttonColor);
	enableDisableAllButtons(moveButtonList, false, buttonColor);

	input = document.getElementsByTagName("input");
	for(j=0; j<input.length; j++) {
		if (input[j].className == "S" && input[j].checked){
			enableDisableAllButtons(removeButtonList, true, disableColor);
			enableDisableAllButtons(submitButtonList, true, disableColor);
			enableDisableAllButtons(postButtonList, true, disableColor);
			enableDisableAllButtons(unpostButtonList, true, disableColor);
			enableDisableAllButtons(moveButtonList, true, disableColor);
			break;
		}
	}

}

function enableDisableButton(button, disabled, background) {
	button.disabled = disabled;
	button.style.background = background;
}

function enableDisableAllButtons(buttonList, disabled, background) {
	if (buttonList.length > 0) {
		for (i=0; i< buttonList.length; i++) {
			enableDisableButton(buttonList.item(i), disabled, background);
		}
	}
}
