//Author:Lauren
//Remove price grid columns on item list and accounting item pages

//getElementsByClass source: http://www.dustindiaz.com/top-ten-javascript/
function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if ( node == null )
	node = document;
if ( tag == null )
	tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
for (i = 0, j = 0; i < elsLen; i++) {
	if ( pattern.test(els[i].className) ) {
		classElements[j] = els[i];
		j++;
	}
}
return classElements;
}

function removeRows(gridLayout, links) {
var lastNum = 6; //4 columns
/*
if ((productLine.indexOf('Drinkware') != -1) || (productLine.indexOf('Umbrella') != -1) || (productLine.indexOf('Jewelry') != -1) || (productLine.indexOf('Fleece') != -1)){
  lastNum = 7;//5 columns
}*/

if (gridLayout == 'horiz'){
	var firstClassMatch = getElementsByClass('bglt')[0].getElementsByTagName('tbody')[0].getElementsByTagName('tr');
	for (i = 0; i < firstClassMatch.length; i++) {
	  //FIRST ROW
	  if (i == 0) {// first quantity amount-1st row 2nd col
		firstClassMatch[i].getElementsByTagName('td')[1].style.display = "none";
		//count cols
		var firstRow = firstClassMatch[0];
		var firstRowCols = firstRow.getElementsByTagName('td');
		for (j=0;j<firstRowCols.length;j++){
		   //if greater than or equal to row 6
		   //0 header; 1 min remove; 2,3,4,5 show; 6&+ remove
		   if ( ("<%=getCurrentAttribute('customer','pricelevel')%>"=="Key Account (NET)") && (3 <= j && j <= 5) ){
				firstClassMatch[i].getElementsByTagName('td')[j].style.display = "none";
			}
		   if (j >= 6) {
				var firstRowj6orOver =  firstClassMatch[i].getElementsByTagName('td')[j];
				firstClassMatch[i].getElementsByTagName('td')[j].style.display = "none";
		   }//end if
		}//end for
	  }//end if
	  //SECOND ROW
	  if (i == 1) {//first price amount-2nd row 2nd col
		firstClassMatch[i].getElementsByTagName('td')[1].style.display = "none";
		var secondRow = firstClassMatch[1];
		var secondRowCols = secondRow.getElementsByTagName('td');
		  for (j=0;j<secondRowCols.length;j++){
			//if greater than or equal to row 6
			//0 header; 1 min remove; 2,3,4,5 show; 6&+ remove
			if ( ("<%=getCurrentAttribute('customer','pricelevel')%>"=="Key Account (NET)") && (3 <= j && j <= 5) ){
				firstClassMatch[i].getElementsByTagName('td')[j].style.display = "none";
			}
			if (j >= 6) {
				 firstClassMatch[i].getElementsByTagName('td')[j].style.display = "none";
			}//end if
		 }//end for
	   }//end if
	}//end for
}
if (gridLayout == 'vert'){
	//vertical grid
	//var comparetables = getElementsByClass('compare');
	//for (a = 0; a < comparetables.length; a++) {
		//if (comparetables[a].getElementsByTagName('input')){
			//var bglttables = comparetables[a].getElementsByClass('bglt');
			var bglttables = getElementsByClass('bglt');
			for (i = 0; i < bglttables.length; i++) {
			var row = bglttables[i].getElementsByTagName('tbody')[0].getElementsByTagName('tr');
			 for (j = 0; j < row.length; j++) {
			 //FIRST ROW
			  if (j == 1) {
			   row[j].style.display = "none";
			  }
			  if ( ("<%=getCurrentAttribute('customer','pricelevel')%>"=="Key Account (NET)") && (3 <= j && j <= 5) ){
			   row[j].style.display = "none";
			  }
			  if (j >= lastNum) {
			   row[j].style.display = "none";
			  }
			 }//end for
			}//end for
		//}//end if
	//}//end for
}//end if
}//end function