//To do what the css can't

function capWords(inputString) {
	var tmpStr, tmpChar, preString, postString, strlen;
	tmpStr = inputString.toLowerCase();
	stringLen = tmpStr.length;
	if (stringLen > 0)
	{
	  for (i = 0; i < stringLen; i++)
	  {
	    if (i == 0)
		{
	      tmpChar = tmpStr.substring(0,1).toUpperCase();
	      postString = tmpStr.substring(1,stringLen);
	      tmpStr = tmpChar + postString;
	    }
	    else
		{
	      tmpChar = tmpStr.substring(i,i+1);
	      if (tmpChar == " " && i < (stringLen-1))
		  {
	      tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
	      preString = tmpStr.substring(0,i+1);
	      postString = tmpStr.substring(i+2,stringLen);
	      tmpStr = preString + tmpChar + postString;
	      }
	    }
	  }
	}
	return tmpStr;
}


//---------- FILTER OBJECT FOR HANDLING FILTER HISTORY ------------
var SC_Filter = function (){
	this.fId;
	this.fName = "";
	this.fParameters = new Array();
	
	_SC_Filter_prototype_call = true;
	SC_Filter.prototype.generateRemove = generateRemove;
	SC_Filter.prototype.to_sop = to_sop;
	function generateRemove(){
		var str = "<a href='javascript:removeFilter("+this.fId+");' >";
		if ( this.fName == "SortBy"){
			str +="Sorted by " + this.fParameters[0];
		} else if ( this.fName == "SortByAttribValue" ){
			str +=capWords(this.fParameters[1]);
		} else if ( this.fName == "SortByAttribRange") {
			str +=capWords(this.fParameters[0]) + " ";
			if ( this.fParameters[0] == "Price" || this.fParameters[0] == "price" ){
				if ( allNines(this.fParameters[2]) == true ){
					str += "$"+(parseInt(this.fParameters[1])+1) + " and More";
				}else{
					str += "$"+(parseInt(this.fParameters[1])+1) + " to $" + this.fParameters[2];
				}
			} else {
				if ( allNines(this.fParameters[2]) == true ){
					str += (parseInt(this.fParameters[1])+1) + " and More";
				}else{
					str += ""+(parseInt(this.fParameters[1])+1) + " to " + this.fParameters[2];
				}
			}
		}
		str +="</a>";
		return str;
	}
	
	function to_sop(){
		return this.fId+";"+this.fName+";"+this.fParameters+";"+this.fParameters.length+";"+this.generateRemove();
	}
}

function allNines(num){
	str = ""+num
	for (var i=0;i<str.length;i++){
		if ( str.charAt(i) != "9") return false;
	}
	return true;
}

var ItemController = function ()
{
  // CONFIGURATIONS
  //Items
  this.itemEntityTagName= "itemEntity"; // TAG
  this.itemDivToShow= "divToShow-"; // DIV
  this.showItemsTable = "showItemsTable"; //TABLE
  this.itemAttributeTagName= "input"; // INPUT
  this.itemAttributeName = "name"; // TAG attribute
  this.itemAttributeValue = "value"; // TAG attribute
  this.itemAttributeUniqueValues = "uniqueValues"; // TAG attribute
  
  //Attribute headers
  this.attributeHeaderName = "SC_AttributeHeader";
  
  //Pagination
  this.itemSortFromIndex = "SC_itemSortFromIndex"; // SPAN
  this.itemSortTillIndex = "SC_itemSortTillIndex"; // SPAN
  this.itemSortTotalCount = "SC_itemSortTotalCount"; // SPAN
  this.itemSortCurrentPage = "SC_itemSortCurrentPage"; // INPUT
  this.itemSortMaxPerPage = "SC_itemSortMaxPerPage"; //INPUT
  this.itemSortMaxPerPageDefault = "SC_itemSortMaxPerPageDefault"; //INPUT
  this.itemSortPaginationLinks = "SC_itemSortPaginationLinks"; // SPAN
  this.itemSortPaginationDiv = "SC_Pagination"; // DIV
  this.itemSortNextPage = "SC_itemSortNextPage"; // A
  this.itemSortPrevPage = "SC_itemSortPrevPage"; // A

  //Pagination limits
  this.useNetSuiteLimit = false;
  this.netSuiteMaxItemLimit = 50;
  this.reportMsgs = (document.URL.indexOf("warnings=true") != -1);
  
  //Filters
  this.sortByAttributeField = "";
  
  //Pagination extra buttons
  this.itemSortViewAll = "SC_viewAll"; // A
  this.itemSortViewPagination = "SC_viewPagination"; // A
  this.itemsByRow = "itemsByRow";

  //Sorting controls
  this.itemSortBy = "SC_itemSortBy";
  this.itemSortBySelect = "SC_itemSortBySelect";
  this.filterHistoryDiv = "SC_filterHistoryDiv";
  
   
  //CLASS VARIABLES FOR INFORMATION CONTAINING
  //-----------------------------------------
  this.items = new Array(); //It contains every item
  this.filteredItems = new Array(); //It contains only the items that are currently showing
  
  this.attributeHeaders = new Array();
  this.currentFilters = new Array();
  this.nextFilterId = 1;
  // Here comes the variables for the HTML controls.
  
  //-----------------------------------------
  
  
  // initialize the member function references 
  // for the class prototype
	_ItemController_prototype_called = true;
	ItemController.prototype.loadData = loadData;
	ItemController.prototype.catchEveryAttributeHeader = catchEveryAttributeHeader;
	ItemController.prototype.catchEveryItem = catchEveryItem;
	ItemController.prototype.addSC_Item = addSC_Item;
	
	ItemController.prototype.addItemIdToShow = addItemIdToShow;
	ItemController.prototype.getItemById = getItemById;
	ItemController.prototype.showFilteredItems = showFilteredItems;
	ItemController.prototype.sortByAttribute = sortByAttribute;
	ItemController.prototype.clearShowTable = clearShowTable;
	ItemController.prototype.sortByAttributeValue = sortByAttributeValue;
	ItemController.prototype.sortByAttributeRange = sortByAttributeRange;
	ItemController.prototype.resetFilters = resetFilters;
	ItemController.prototype.reloadRangesSorts = reloadRangesSorts;
	ItemController.prototype.showFilteredItemsSetCP = showFilteredItemsSetCP;
	ItemController.prototype.makePagination = makePagination;
	ItemController.prototype.applyFilters = applyFilters;
	ItemController.prototype.removeFilter = removeFilter;
	ItemController.prototype.addFilter = addFilter;
	ItemController.prototype.listEveryItem = listEveryItem;
 
	//----------------LOAD-------------------
	function loadData(){
		this.catchEveryItem();
		this.catchEveryAttributeHeader();
		this.showFilteredItems();
	}

  // Getting every item in the this.items array
  function catchEveryItem()
  {
  	var itemTags = document.getElementsByTagName('div');
	var itemDiv = null;
	var item = null;
	var attributesTags = null;
	var attributeInput = null;
	
	for ( var i = 0; i<itemTags.length;i++){
		itemDiv = itemTags[i];
		if ( itemDiv.title == this.itemEntityTagName){ 
			attributesTags = itemDiv.getElementsByTagName(this.itemAttributeTagName);
			item = new SC_Item(itemDiv.id);
			for (var x=0;x<attributesTags.length;x++){
				attributeInput = attributesTags[x];
				item.addAttribute((item.getId()+x),attributeInput.name, attributeInput.value, attributeInput.getAttribute('uniqueValues'));
			}//End attributes rolling
			this.addSC_Item(item);
			this.addItemIdToShow(item);
		}//End if itemDiv.name == itemEntityTagName
	}//End itemDivs rolling
	if (this.reportMsgs==true){ alert(this.items.length + " Items where found and stored."); }
  }
  
  // Getting every diferent attribute names
  function addSC_Item(scItem)
  {//Checking if the item alredy exists.
	for (var i=0;i<this.items.length;i++){
		var item = this.items[i];
		if (item.getId() == scItem.getId()){
			return 0;
		}
	}
	this.items[this.items.length] = scItem;
	return 1;
  }
  
  function getItemById(itemId){
  	for (var i=0;i<this.items.length;i++){
  		if ( this.items[i].getId() == itemId){
  			return this.items[i];
  		}
  	}
  	return 0;
  }
  
  //---------------------------------------------------------------
  //---------------      ATRIBUTE HEADERS      --------------------
  function catchEveryAttributeHeader(){
  	var tags = document.getElementsByTagName('span');
  	var span = null;
  	var ah = null;
  	for (var i=0;i<tags.length;i++){
  		if ( tags[i].title == this.attributeHeaderName){
  			span = tags[i];
  			ah = new SC_AttributeHeader("");
  			ah.scLoad(this.items,span.innerHTML);
  			ah.attributeName = span.id.split('-')[0];
  			ah.createTags();
  			this.attributeHeaders[this.attributeHeaders.length] = ah;  			
  		}
  	}
  }
  
  
  //------------------------ITEMS TO SHOW--------------------------
  function addItemIdToShow(item)
  {//Checking if the item alredy exists.
	this.filteredItems[this.filteredItems.length] = item;
	return 1;
  }
  
  function showFilteredItems(){
  	try{
	  	this.clearShowTable();
	  	var paginationDiv = document.getElementById(this.itemSortPaginationDiv);
	  	var itemsToShow = this.filteredItems;
	  	if (paginationDiv != null){
	  		itemsToShow = this.makePagination(itemsToShow);
	  	}
	  	var tbl = document.getElementById(this.showItemsTable);
	  	tbl.style.display="block";
	  	var byRow = parseInt(document.getElementById('itemsByRow').innerHTML);
	  	var rowCount = 0;
	  	for ( var i=0;i<itemsToShow.length;i++){
	  		
	  		var isPagedItem = false;
	  		var oTd = document.createElement('TD');
	  		var internalId=itemsToShow[i].getId();
	  		var idiv = document.getElementById(this.itemDivToShow+internalId);
	  		
	  		if ( idiv == null){
	  			if ( internalId.indexOf('pItem|') != -1){
	  				if (this.reportMsgs == true) alert("The item that will be added now is a pagination item");
	  				idiv = itemsToShow[i].getAttributeByName('divToShow').getValue().toLowerCase();
	  				isPagedItem = true;
	  			}
	  		}
	  		var x=0;
			if ((i % byRow)==0){
				if ( tbl.rows[rowCount] == null){
					oRow = document.createElement('TR');	
				} else {
					
					oRow = tbl.rows[rowCount];
				}
				rowCount = rowCount +1;
			}
			if ( isPagedItem == false ) {
				oTd.innerHTML = idiv.innerHTML;
			} else {
				oTd.innerHTML = idiv;
				isPagedItem = false;
			}
			oRow.appendChild(oTd);
			tbl.appendChild(oRow);
	  	}
	 	this.reloadRangesSorts();
	 	//ONLY FOR GOLDEN
	 	callCellJS();
	 	//---------------
	 } catch (e) {
	 	if ( this.reportMsgs == true ) alert (e);		
 	}
  }
  
  function showFilteredItemsSetCP(currentPage){
  	document.getElementById(this.itemSortCurrentPage).value = currentPage;
  	this.showFilteredItems();
  }
  
  function makePagination(itemsToShow){
  	try{
	  	var fromIndex = document.getElementById(this.itemSortFromIndex);
		var tillIndex = document.getElementById(this.itemSortTillIndex);
		var totalCount = itemsToShow.length;
	    document.getElementById(this.itemSortTotalCount).innerHTML = totalCount;
	
		var currentPage = parseInt(document.getElementById(this.itemSortCurrentPage).value);
		var maxPerPage = parseInt(document.getElementById(this.itemSortMaxPerPage).value);
		var startIndex = ((currentPage * maxPerPage)-maxPerPage);
		fromIndex.innerHTML = startIndex+1;
		var endIndex = startIndex + maxPerPage;
		var itemsForPage = new Array();
		var i= 0;
		for ( i = startIndex; i<endIndex && i<itemsToShow.length;i++){
			itemsForPage[itemsForPage.length] = itemsToShow[i];
		}
		tillIndex.innerHTML = i;
		itemsToShow = itemsForPage; // dejo en los items para mostrar solo el de la pagina
		//-------------------------------
		//SC_itemSortPaginationLinks
		//---Making pagination Links-----
		var pagLinksDiv = document.getElementById(this.itemSortPaginationLinks);
		
		var maxPages = (totalCount / maxPerPage);
		var decimales = (parseFloat(maxPages) - parseInt(maxPages));
	    if ( decimales >0){
	        maxPages = maxPages - decimales+1;// porq empieza d 1
	    }
	    pagLinksDiv.innerHTML = " ";
		for ( var i =1; i<=maxPages;i++){
			var ahr = document.createElement('A');
			ahr.href = "javascript:showSetCP("+i+");";
			ahr.innerHTML = i;
			
			var spc = document.createElement('span');
			spc.innerHTML = "&nbsp;";		
			pagLinksDiv.appendChild(ahr);
			pagLinksDiv.appendChild(spc);
			//pagLinksDiv.innerHTML+= " <a href=\"javascript:showSetCP("+i+");\">"+i+"</a> ";
		}
	return itemsForPage;
} catch (e) {alert(e);}
  }
    
  function reloadRangesSorts(){
  	for (var i=0;i<this.attributeHeaders.length;i++){
  		this.attributeHeaders[i].scReLoad(this.filteredItems);
  	}
  }
  
  function sortByAttribute(attribName){
	  try{
	  	this.sortByAttributeField = attribName;
	  	var itemsAr = this.filteredItems;
	  	var item = null;
	  	var respAr = new Array();
	  	var toSortAr = null;
	  	for (var i=0;i<itemsAr.length;i++){
	  		item = itemsAr[i];
	  		toSortAr =  new Array();
	  		toSortAr[0] = item.getAttributeByName(attribName).getValue();
	  		toSortAr[1] = item.getId();
	  		respAr[respAr.length]=toSortAr;
	  	}
	  	//Sorting the array.
	  	respAr = respAr.sort();
		this.filteredItems = new Array();
	  	for (var i=0;i<respAr.length;i++){
	  		//Modfying the items
	  		this.filteredItems[i] = this.getItemById(respAr[i][1]);
	  	}
	  } catch (e) {
	  	if ( this.reportMsgs == true ) alert(e);
	  }
  }
  
  //Clear the table that shows the items
  function clearShowTable(){
  	var tbl = document.getElementById(this.showItemsTable);
  	while( tbl.rows.length>0){
  		tbl.deleteRow(0);
  	}
  }
  //---------------------------------------------------------------
  
  //----------------SORT ITEMS BY ATTRIB VALUE---------------------
  function sortByAttributeValue(attribName, attribValue){
  	var newFiltered = new Array();
  	for (var i=0; i<this.filteredItems.length;i++){
  		var attrib = this.filteredItems[i].getAttributeByName(attribName)
  		if ( attrib != null ){
  			if (attrib.getValue().indexOf(attribValue) != -1){
  				newFiltered[newFiltered.length]=this.filteredItems[i];
  			}
  		}
  	}
  	this.filteredItems = newFiltered;
  }
  //---------------------------------------------------------------
  
  //----------------SORT ITEMS BY ATTRIB VALUE---------------------
  function sortByAttributeRange(attribName, minRange, maxRange){
  	var newFiltered = new Array();
  	for (var i=0; i<this.filteredItems.length;i++){
  		var item = this.filteredItems[i];
  		if ( item != null ){
  			if (item.getNumericAttributeValueByName(attribName) >= minRange && item.getNumericAttributeValueByName(attribName) < maxRange){
  				newFiltered[newFiltered.length]=this.filteredItems[i];
  			}
  		}
  	}
  	this.filteredItems = newFiltered;
  }
  //---------------------------------------------------------------
  //---------------- RESTART FILTERS ------------------------------
  function resetFilters(){
  	this.filteredItems = this.items;
  	this.currentFilters = new Array();
  	this.nextFilterId = 1;
  	this.showFilteredItems();
  }
  //---------------------------------------------------------------
  
  function addFilter(fsita){
   try{	
  	//Parameter checking
  	if ( fsita.fName == "SortBy" ){
  		if ( fsita.fParameters.length < 1){
			if ( this.reportMsgs == true ) alert("Filter (SortBy) not added: Wrong number of paramters "+( fsita.fParameters.length > 0)+"["+fsita.fParameters.length+"]");
			return;
  		}
  	} else if ( fsita.fName == "sortByAttribValue" ){
  		if ( fsita.fParameters.length < 2) {
  			if ( this.reportMsgs == true ) alert("Filter (sortByAttribValue) not added: Wrong number of paramters "+( fsita.fParameters.length > 1)+"["+fsita.fParameters.length+"]");
  			return;
  		}
	} else if ( fsita.fName == "sortByAttribRange") {
		if ( fsita.fParameters.length < 3){
			if ( this.reportMsgs == true ) alert("Filter (SortByAttribRange) not added: Wrong number of paramters "+( fsita.fParameters.length > 1)+"["+fsita.fParameters.length+"]");
			return;
		}
	}
	//Uniqueness checking
	var filt;
	for (var i=0; i<this.currentFilters.length;i++){
		filt = this.currentFilters[i];
		if ( filt.fName == fsita.fName){
			//I don't need to check parameters length again
			var eq = true;
			for ( var j = 0;j<filt.fParameters.length;j++){
				if ( filt.fParameters[j] !=  fsita.fParameters[j]) { 
					eq = false;
				}
			}
			if ( eq == true){
				if ( this.reportMsgs == true ) alert("Filter ("+fsita.fName+") not added: Filter already added ")
				return ;
			}
		}
	}
	//Every check done, adding the filter
  	fsita.fId = this.nextFilterId;
  	this.nextFilterId += 1;
  	this.currentFilters[this.currentFilters.length] = fsita;
  	if ( this.reportMsgs == true ) alert("Filter ("+fsita.fName+") added Succesfully ("+fsita.to_sop()+") ");			
  	this.applyFilters();
   } catch (e) {
   	if ( this.reportMsgs == true ) alert(e);
   }
   
  }
  
  function removeFilter(fId){
  	var alterFilters = new Array();
  	for ( var i=0; i<this.currentFilters.length; i++){
  		if ( this.currentFilters[i].fId != fId ){
  			alterFilters[alterFilters.length] = this.currentFilters[i];
  		}
  	}
  	this.currentFilters = alterFilters;
  	this.applyFilters();
  }
  
  function applyFilters(){
	var fsita ="";
	var fhdiv = document.getElementById(this.filterHistoryDiv);
	fhdiv.innerHTML = '';
	//Finding the Sort By 

	this.filteredItems = this.items;
  	for ( var i=0; i<this.currentFilters.length; i++){
  		fsita = this.currentFilters[i];
		if ( fsita.fName == "SortByAttribValue" ){
			if ( fsita.fParameters[1].indexOf("|") == -1 ){
				this.sortByAttributeValue(fsita.fParameters[0],fsita.fParameters[1]);
			} else {
				this.sortByAttributeValue(fsita.fParameters[0],fsita.fParameters[1].split("|"));
			}
		} else if ( fsita.fName == "SortByAttribRange") {
			this.sortByAttributeRange(fsita.fParameters[0],fsita.fParameters[1],fsita.fParameters[2]);
		}
		fhdiv.innerHTML += fsita.generateRemove();
		fhdiv.innerHTML += '<br/>';
  	}
  	if (this.sortByAttributeField != ""){
  		this.sortByAttribute(this.sortByAttributeField);
  	}
  	this.showFilteredItemsSetCP(1);
  	
  }
  
  function listEveryItem(){
  	var str= "";
  	for (var i=0;i<this.items.length;i++){
  		str += this.items[i].getId() + " - " + this.items[i].getAttributeByName('Price').getValue() + " | \n";
  	}
  	alert (str);
  }
}

//---------------------FOR PAGINATION -----------------------------
	function setPagination(){
		document.getElementById(itemctrl.itemSortMaxPerPage).value = document.getElementById(itemctrl.itemSortMaxPerPageDefault).value;
		document.getElementById(itemctrl.itemSortPaginationDiv).style.display="block";
		itemctrl.showFilteredItemsSetCP(1);
	}
	  
	function unsetPagination(){
		document.getElementById(itemctrl.itemSortMaxPerPage).value = parseInt(document.getElementById(itemctrl.itemSortTotalCount).innerHTML);
		document.getElementById(itemctrl.itemSortPaginationDiv).style.display="none";
		itemctrl.showFilteredItemsSetCP(1);
	}
	
	function prevPage(){
		var currentPage = document.getElementById(itemctrl.itemSortCurrentPage);
		if (currentPage.value > 1){
			itemctrl.showFilteredItemsSetCP(parseInt(currentPage.value) -1);
		}
	}
	
	function nextPage(){
		var currentPageCtrl = document.getElementById(itemctrl.itemSortCurrentPage);
	    var currentPage = currentPageCtrl.value;
	
		var itemCount = parseInt(document.getElementById(itemctrl.itemSortTotalCount).innerHTML);
		var maxPerPage = parseInt(document.getElementById(itemctrl.itemSortMaxPerPage).value);
	
		var maxPages = (itemCount / maxPerPage);
		var decimales = (parseFloat(maxPages) - parseInt(maxPages));
	    if ( decimales >0){
	        maxPages = maxPages - decimales+1;// porq empieza d 1
	    }
		if (currentPage < maxPages){
			itemctrl.showFilteredItemsSetCP(parseInt(currentPage) +1);
		}
	}
	function showSetCP(cp){
		itemctrl.showFilteredItemsSetCP(cp);
	}
	
//------------------------------------------
//--------------FILTERS.--------------------
	function resetFilters(){
		itemctrl.resetFilters();
		document.getElementById(itemctrl.filterHistoryDiv).innerHTML = "";
		addFinishLinksGlobal();
	}

	function addFilter(fName, fParam1, fParam2, fParam3){
		var fsita = new SC_Filter();
		fsita.fName = fName;
		if ( fParam3 != null){
			fsita.fParameters[0] = fParam1;
			fsita.fParameters[1] = fParam2;
			fsita.fParameters[2] = fParam3;
		} else if (fParam2 != null){
			fsita.fParameters[0] = fParam1;
			fsita.fParameters[1] = fParam2;
		} else if (fParam1 != null){
			fsita.fParameters[0] = fParam1;	
		}
		if (fsita.fParameters.length>0){
			itemctrl.addFilter(fsita);
			addFinishLinksGlobal();
		}
	}
	
	function sortBy(attribName){
		itemctrl.sortByAttribute(attribName)
		itemctrl.showFilteredItems();
	}
	
	function removeFilter(fId){
		itemctrl.removeFilter(fId);
		addFinishLinksGlobal();
	}
	
	function addFinishLinksGlobal(){
		addFinishLinks("SC_FinishLinks","finish");
		addFinishLinks("SC_RoomLinks","room","yhea");
		addFinishLinks("SC_TypeLinks","type");
		addFinishLinks("SC_StyleLinks","style");
		hideAllFilters();
	}
	
	function hideAllFilters(){
		var idiv = document.getElementById('narrow2');
		var spans = idiv.getElementsByTagName('span');
		var x = spans.length;
		while(x--){
			if (spans[x].id.indexOf('AH-span') == -1 ) spans[x].style.display="none";
		}
	}
	function addFinishLinks(spanId,attribName, rooms){
		function addFinish(pList,str){
		    for ( var i=0;i<pList.length;i++){
		        if (pList[i][0] == str){
		            pList[i][1] = pList[i][1] + 1 
		            return false;
		        }
		      }
		    var nomCount = new Array();
		    nomCount[0] = str;
		    nomCount[1] = parseInt(1);
		    list[list.length]=nomCount;
		    return true;
		}
		var list = new Array();
		if (rooms != null){
			for (var i=0;i<itemctrl.filteredItems.length;i++){
			    var item = itemctrl.filteredItems[i];
			    var vlus = item.getAttributeByName(attribName).getValue().split(',');
			    var vlen = vlus.length;
			    for(var o=0;o<vlen;o++){
			    	addFinish(list,vlus[o]);
			    }
			}
		} else{
			for (var i=0;i<itemctrl.filteredItems.length;i++){
			    var item = itemctrl.filteredItems[i];
			    addFinish(list,item.getAttributeByName(attribName).getValue());
			}
		}
		
		//Creating the tags
		var finishLinks = document.getElementById(spanId);
		finishLinks.innerHTML = "";
		for (var i=0;i<list.length;i++){
			var tags = document.createElement("A");
			if ( list[i][1] >0){
				tags.href="javascript:addFilter('SortByAttribValue','"+attribName+"','"+list[i][0]+"');";
				tags.innerHTML=capWords(list[i][0])+"<strong> ("+list[i][1]+")</strong>"
				finishLinks.appendChild(tags);
				finishLinks.innerHTML +="<br/>";
			}
		}
		/*if (finishLinks.getElementsByTagName('a').length <=1){
			document.getElementById('SC_FinishLinks-p').style.display="none";
		}*/
	}

//------------------------------------------

 function callCellJS(){
  	var allCells = document.getElementById(itemctrl.showItemsTable).getElementsByTagName('td');
  	var cell;
  	for ( var i=0; i<allCells.length; i++){
  		cell = allCells[i];
  		//Showing corner new image
		var div = getElementsLikeId('special-','div', cell)[0];
		var special= getElementsLikeId('spvalue-','input', cell)[0].value;
		var routeImageSpecial="/site/images/new_c.gif";
		var routeImageNoSpecial="/site/images/pix.gif";
		if(special.toLowerCase() == "yes"){
		 div.innerHTML = "<img src=" + routeImageSpecial + " border='0'>";
		} else if(special.toLowerCase() == "no"){
		 div.innerHTML = "<img src=" + routeImageNoSpecial + " border='0'>";
		}
		//-----------------------
  	}
  }
  
  function getElementsLikeId(likeid, tagName, container){
	var retObjs = new Array();
  	try{
  		var tags = container.getElementsByTagName(tagName);
  		for( var i=0;i<tags.length;i++){
  			if ( tags[i].id.toLowerCase().indexOf(likeid.toLowerCase()) != -1 ){
  				retObjs[retObjs.length] = tags[i];
  			}
  		}
  	}catch (e) {}
  	return retObjs;
  }


