//pbrp1categorycontent.jsp
//validation on click of compare button in category detail page
function checknProducts()
{
	var count = document.PBRCategoryDataBean.hdnTotalProducts.value;
	var checkInput = "true";
	var nChecked = 0 ; 
	for(j=1;j<=count;j++) 
	{
		if(eval("document.PBRCategoryDataBean.prod"+j))
		{
			if(eval("document.PBRCategoryDataBean.prod"+j+".checked"))
			{
				nChecked = nChecked + 1;
			}
		}
	}
	if(nChecked < 2)
	{
		alert(document.PBRCategoryDataBean.minselected.value);
		//disableCheck(count);
		checkInput = false;
	}
	else if(nChecked > 5)
	{
		alert(document.PBRCategoryDataBean.maxselected.value);
		//disableCheck(count);
		checkInput = false;
	}
	if(checkInput == "true")
	{
		document.forms["PBRCategoryDataBean"].submit();
	}
	return false;
}

//pbrp1categorycontent.jsp
//validation on click of compare button in category detail page
function disableCheck(count)
{
  for(j=1;j<=count;j++) 
	{
	  if(eval("document.PBRCategoryDataBean.prod"+j))
		{
			if(eval("document.PBRCategoryDataBean.prod"+j+".checked"))
			{
			  eval("document.PBRCategoryDataBean.prod"+j+".checked =false ")
			}
		}
	}
}

/* Start : Written by Bhaskar Gadupudi : WIPRO*/
//pbrp1productcomparisoncontent.jsp
//remove product link functionality in product comparion page

	function removeEmptyRows(CellAtIndex)
	{
		//alert("Test");
		table = document.getElementById("prod-comp-table");
		var totproducts = document.forms["PBRCategoryDataBean"].hdnTotalProducts.value;
		var objectExistence = "undefined";
		/* Start : Looping all rows starts from 2nd ROW */
		for (var i = 1 ; i < table.rows.length-1; )
		{
				/*Start : Check whether ROW is visible*/
				if(table.rows[i].style.visibility != "hidden")
				{
					var row = table.rows[i];
					flag = 0 ;
					/* Start : Iterating each cell in row */
					for ( var j=CellAtIndex; j<=totproducts; j++)
					{
						var cellToRemove = row.cells[j];

/*alert("Before innerHTML");
alert("cellToRemove.innerHTML"+cellToRemove.innerHTML);*/
						/*Start : Check for cell contains any value other than hypen */
						if(cellToRemove.innerHTML != "-")
						{
							flag = 1;
						}
						/*End : Check for cell contains any value other than hypen */
					}
					/* End : Iterating each cell in row */
					/*Start : If all the cells contains hypen values please remove that ROW*/
					if(flag != 1)
					{
						table.deleteRow( i);
						table.rows[1].setAttribute('id','firstRow');
					}
					else
					{
						/* Need to increment I value b'coz we are deleting row 	*/			
						i++;
					}
					/*End : If all the cells contains hypen values please remove that ROW*/
				}
				/*End : Check whether ROW is visible*/
		}
		/* End : Looping all rows starts from 2nd ROW */
	}

/* End : Written by Bhaskar Gadupudi : WIPRO*/


//pbrp1productcomparisoncontent.jsp
//remove product link functionality in product comparion page
function swap(removeCellAtIndex)
{
/*Start : This code will be done the swapping the cell to be invisible */
	table = document.getElementById("prod-comp-table");
	var totproducts = document.forms["PBRCategoryDataBean"].hdnTotalProducts.value;
	var objectExistence = "undefined";
	if (table.rows[0].cells[3] != objectExistence)
	{
		if(table.rows[0].cells[3].style.visibility != "hidden")
		{
			for (var i = 0 ; i < table.rows.length; i++)
			{
				var row = table.rows[i];
				for ( var j=removeCellAtIndex; j<=totproducts; j++)
				{

					var cellToRemove = row.cells[j];
						cellToRemove.innerHTML="-";

					if ( (j+1) <= totproducts )
					{
						var cellAfterCellToRemove = row.cells[j+1];
						row.insertBefore(cellAfterCellToRemove, cellToRemove);
					}
				}
				table.rows[i].cells[j-1].style.visibility = "hidden";
			}
		}
		else
		{

				return true;
		}
	}
/*End : This code will be done the swapping the cell to be invisible */
/* Start : Added by Bhaskar Gadupudi for removing empty rows in prod comparision output */
		var Remove = 0;
		/* To Iterate row by Row  existing table*/
		for (var i = 1 ; i < table.rows.length; )
		{
				/* Check for the visibility of the ROW*/
				if(table.rows[i].style.visibility != "hidden")
				{
				
						var row = table.rows[i];
						flag = 0 ;
						/* To iterate all spec values to check whether any row which is having no comparision spec value */
						for ( var j=1; j<=totproducts; j++)
						{
								var cellToRemove = row.cells[j];
								/*Start : Check for cell contains any value other than hypen */
								if(cellToRemove.innerHTML != "-")// && j != removeCellAtIndex)
								{
										flag = 1;
								}
								/*End : Check for cell contains any value other than hypen */
								/*else if(cellToRemove.innerHTML == "Yes")
								{
										flag = 1;
								}*/
								/* End iterate all spec values to check whether any row which is having no comparision spec value */
								/* To remove Remove links if onlly 2 products available */
								if(i == (table.rows.length-1) )
								{
/*alert(cellToRemove.innerHTML);*/
										if(cellToRemove.innerHTML != '-') 
										{
/*alert("HI in side if Remove  ");*/
												Remove++;
										}
								}
						/* END remove Remove links if onlly 2 products available */
						}
						/* To remove Remove links if onlly 2 products available */

						if(Remove == 2)
						{
								table.deleteRow( i);
								table.rows[1].setAttribute('id','firstRow');
						}
						/* END remove Remove links if onlly 2 products available */
						/* To delete a row if all spec values are "-" */		
						if(flag != 1)
						{
								table.deleteRow( i);
								table.rows[1].setAttribute('id','firstRow');
						}
						else
						{
								i++;
						}
						/* END delete a row if all spec values are "-" */
				}
		}
/* End Iterate row by Row */
/* End : Added by Bhaskar Gadupudi for removing empty rows in prod comparision output */
}


