//used to get full source of images that appears on navigation panel
var site='bathroom-glass-vanities';
var newtable=document.getElementById("main");
// JScript File
function swaptheImage(obj){
	obj.src=obj.src.replace("paging_","paging-over1_");
	}

function swaptheImageback(obj){
	obj.src=obj.src.replace("paging-over1_","paging_");
	}

function sortByItem(a,b)
    {
        if (a.Name < b.Name)
          return -1;
        else
          return 1;
    }
    function sortByPrice2(a,b)
    {
      return a.Sale_Price - b.Sale_Price;
    }
	function sortByPrice(a,b)
    {
      return b.Sale_Price - a.Sale_Price;
    }
	function sortByPopular(a,b)
  {
      return b.Popularity - a.Popularity;
    }
	function sortBySale(a,b)
  {
      return b.Regularsale - a.Regularsale;
    }
	
	function sortByQuick(a,b)
    {
        if (a.Quick > b.Quick)
          return -1;
        else
          return 1;
    }
function sortByBrand(a,b)
    {
        if (a.Brand < b.Brand)
          return -1;
        else
          return 1;
    }
	function sortByBrand2(a,b)
    {
        if (a.Brand > b.Brand)
          return -1;
        else
          return 1;
    }
myElementArray.items.sort(sortBySale);
	sortit='';

function getSortingMethod(dd){
	sel3=dd.selectedIndex;
    sortit=document.getElementById("sorting").options[sel3].value;
//	alert(sortit);
	setTimeout("myElementArray.items.sort(" + sortit + ")",0)
	//alert('ddd');
	//myElementArray.items.sort(sortit)
	goToPage(0);
	}	
/*crates alert if there is no quick ship items on page*/	
function createQuickAlert(){
	
	if (sortit=='sortByQuick'){
    if(	myElementArray.items[0].Quick =='y'){}
	else {
	var tbody=document.createElement("tbody");
newtable.appendChild(tbody);
var row=document.createElement("tr");
tbody.appendChild(row);

var cell2=document.createElement("td");
cell2.setAttribute('colspan',5);
cell2.colSpan=5;
cell2.setAttribute('align','center')
row.appendChild(cell2);
  cell2.setAttribute('className','AlertText');
    cell2.className="AlertText";
var al=document.createTextNode('Sorry there is no Quick Ship Items . Please see our other items Below');
cell2.appendChild(al);

	}
	
	};
	}
var numitems=myElementArray.items.length;

var itemsperpage=10;
var pnum=42

var numpages=Math.ceil(numitems/itemsperpage);

var reallows=Math.round(numitems/2);


goToPage(0);
function goToPage(pnum){

var commandString = "movePageAsync(" + pnum + ")";
setTimeout(commandString, 100);

}



function movePageAsync(pnum)
{
	
    sel=document.getElementById("dropItPerPage").selectedIndex;
    var itemsperpage=document.getElementById("dropItPerPage").options[sel].value;
   
	var rowtoshow= pnum*itemsperpage/2;
    var lastoshow=(pnum+1)*itemsperpage / 2;
	    if (lastoshow >reallows) {
	    lastoshow=reallows;
	    }
    var numpages=Math.ceil(numitems/itemsperpage);
    if (numpages==0){numpages=1};
	
    showItems(rowtoshow,lastoshow);
	
    createPaginString(numpages,pnum)
}

function ChangePageLay(){


}


function cleanTable(){


    while(newtable.hasChildNodes())
    {
	    newtable.removeChild(newtable.childNodes[0]);
    }
createQuickAlert()
}

function showItems(rowtoshow,lastoshow){
cleanTable();
setTimeout("ShowItemsAsync(" + rowtoshow + "," + lastoshow + ")",100);
}

function ShowItemsAsync(rowtoshow, lastoshow)
{
	
var tbody=document.createElement("tbody");
newtable.appendChild(tbody);
tbody.setAttribute('class','PlainBodyText')
for (i=rowtoshow;i<lastoshow;i++){
//createTableRowAll(i,tbody);
var row=document.createElement("tr");
var pp1=i*2;
if (pp1<myElementArray.items.length){
		createCell(i*2,row);	
		}
var cell3=document.createElement("td");
    cell3.setAttribute('width','10px');
	row.appendChild(cell3);
	var pp=i*2+1;
if (pp<myElementArray.items.length-1){
		createCell(i*2+1,row);	
		} else {cell3=document.createElement("td");
    cell3.setAttribute('width','108px');
	row.appendChild(cell3);
	cell4=document.createElement("td");
	 cell4.setAttribute('width','178px');
 	row.appendChild(cell4);
	}
	
tbody.appendChild(row);
createTableRowBrake(tbody);
}
}

function createCell(itemToDisp,row){
	var cell = document.createElement("td");
var cell2=document.createElement("td");
cell.setAttribute('className','BorderOnMS');
     cell.className='BorderOnMS';

var a = document.createElement('a');
a.setAttribute('href',myElementArray.items[itemToDisp].Id.toLowerCase()+'.html');
    var im = document.createElement('img');
    im.setAttribute('src', 'http://www.luxaris.com/luxstores/images/small/'+myElementArray.items[itemToDisp].image1);
    im.setAttribute('alt', myElementArray.items[itemToDisp].Name);
    a.appendChild(im);
    cell.appendChild(a);

    cell2.setAttribute('className','HomePageTD');
    cell2.className="HomePageTD";
   // cell2.setAttribute('style','vertical-align: top; width: 167px;');
    var div=document.createElement("div");
    div.setAttribute('className','cell');
    div.className="cell";
	
        var a2= document.createElement('a');
        a2.setAttribute('href',myElementArray.items[itemToDisp].Id.toLowerCase()+'.html');
        tit=document.createTextNode(myElementArray.items[itemToDisp].Name);
        var linebr=document.createElement('br');
        var linebr2=document.createElement('br');

var Pricetextsp=document.createElement('Span');
Pricetextsp.setAttribute('Class','RetailPrice');
Pricetextsp.className="RetailPrice";
  
        Pricetextsp2=document.createTextNode('Retail Price: $');
        var Pricetextsp3=document.createElement('span');
		
        Pricetextsp3.setAttribute('Class','RetailPriceStr');
        Pricetextsp3.className="RetailPriceStr";
        Pricetextsp4=document.createTextNode(addCommas(toDollarsAndCents(myElementArray.items[itemToDisp].Price)));
         Pricetextsp3.appendChild(Pricetextsp4);     
         Pricetextsp.appendChild(Pricetextsp2);  
         Pricetextsp.appendChild(Pricetextsp3) ;  
      
	  
	  var saleprtextsp= document.createElement('span');
	   a2.appendChild(tit);
    div.appendChild(a2);
    div.appendChild(linebr);div.appendChild(Pricetextsp);div.appendChild(linebr2); 
	  if (myElementArray.items[itemToDisp].Map!=null) {
		  
		  createMapString(div)
	  	  
	  } else {
        if (myElementArray.items[itemToDisp].Regularsale!=0){
			saleprtextsp.setAttribute('class','OurPriceStr');
			saleprtextsp.className="OurPriceStr";
			         saleprtextsp3=document.createTextNode(addCommas(toDollarsAndCents(myElementArray.items[itemToDisp].Regularsale/10)));
					 var sale=document.createElement('span');
					 sale.setAttribute('Class','SalePrice');
					 sale.className="SalePrice";
					 var saleimage=document.createElement('img');
					 saleimage.setAttribute('class','saletag');
					 saleimage.className="saletag";
		
					 saleimage.setAttribute('src','http://site.bathshowerstore.com/images/sale-tag.gif')
					 sale.appendChild(saleimage);
					 var linebr3=document.createElement('br');
					 var sprice=document.createTextNode('$'+addCommas(toDollarsAndCents(myElementArray.items[itemToDisp].Sale_Price)));
					 sale.appendChild(sprice);

			}
			else {
			saleprtextsp.setAttribute('class','OurPrice');
          	saleprtextsp.className="OurPrice";
         
         	saleprtextsp3=document.createTextNode(addCommas(toDollarsAndCents(myElementArray.items[itemToDisp].Sale_Price)));
		 	}
		 
         saleprtextsp2=document.createTextNode('Our Price: $');
		 saleprtextsp.appendChild(saleprtextsp2);
         saleprtextsp.appendChild(saleprtextsp3);
	
		  
		 
	  }
 
   
   div.appendChild(saleprtextsp); 
	
	if (myElementArray.items[itemToDisp].Regularsale!=0) {
	div.appendChild(linebr3)
	div.appendChild(sale);
	}
	 if (myElementArray.items[itemToDisp].Steam!=null) {
		  	createSteamString(div)}
	cell2.appendChild(div);    

	row.appendChild(cell);
row.appendChild(cell2);
	}
function createMapString(div) {

	var MapString=document.createElement("span");
	var maptext="<a class='map-price' href=javascript:popup('http://site.bathroom-glass-vanities.com/lowest-price.html')>Add to cart to get price <img src='http://site.bathroom-glass-vanities.com/images/info3.jpg' alt='Click here for additional Price Information' border='0'></a>";
		MapString.innerHTML=maptext;
	div.appendChild(MapString);
	}
function createSteamString(div) {

	var SteamString=document.createElement("span");
	var maptext="<a class='' href=javascript:popImage('http://www.luxstores.com/images/steam-explanation.jpg')><img src='http://www.luxstores.com/images/steam_inside.gif' alt='Click here for additional Price Information' border='0'></a>";
		SteamString.innerHTML=maptext;
	div.appendChild(SteamString);
	}



function createTableRowBrake(tbody){
var row=document.createElement("tr");
var cell = document.createElement("td");
cell.setAttribute('colspan','5');
row.setAttribute('height','10px');
row.appendChild(cell);
tbody.appendChild(row);
}



function createPaginString(numpages,pnum){

//<span id="prpage"></span><span id="numberpage"></span><span id="nextpage"></span>
//http://site.bathroom-glass-vanities.com/images/next-but.jpg
document.getElementById("numberpage").innerHTML='';
document.getElementById("prpage").innerHTML='<img src="http://www.luxstores.com/'+site+'/paging-empty_r1_c5.gif">';
document.getElementById("nextpage").innerHTML='<img src="http://www.luxstores.com/'+site+'/paging-empty_r1_c5.gif">';
document.getElementById("lastpage").innerHTML='<img src="http://www.luxstores.com/'+site+'/paging-empty_r1_c6.gif">';
document.getElementById("firstpage").innerHTML='<img src="http://www.luxstores.com/'+site+'/paging-empty_r1_c2.gif">';

//alert('cleaned');
if (pnum!=20000){
	

document.getElementById("numberpage").innerHTML='<span class=description>Page ' + (pnum+1) + ' of ' + numpages+'</span>';
if (pnum >= 1) {
document.getElementById("firstpage").innerHTML='<img style="cursor:hand;cursor:pointer;" src="http://www.luxstores.com/'+site+'/paging_r1_c2.gif" onclick="goToPage('+ 0 +')"  onMouseOver="swaptheImage(this)" onMouseOut="swaptheImageback(this)"/>'
}
if (pnum>0){
//go to prev
document.getElementById("prpage").innerHTML='<img style="cursor:hand;cursor:pointer;" src="http://www.luxstores.com/'+site+'/paging_r1_c3.gif" onclick="goToPage('+ (pnum-1)+')"  onMouseOver="swaptheImage(this)" onMouseOut="swaptheImageback(this)">'; 
}
//alert('g');


if (pnum<numpages-1){
document.getElementById("nextpage").innerHTML='<img style="cursor:hand;cursor:pointer;" src="http://www.luxstores.com/'+site+'/paging_r1_c5.gif" onclick="goToPage('+ (pnum+1)+')"  onMouseOver="swaptheImage(this)" onMouseOut="swaptheImageback(this)">'; 
}
if ( pnum<numpages-1) {
document.getElementById("lastpage").innerHTML='<img style="cursor:hand;cursor:pointer;" src="http://www.luxstores.com/'+site+'/paging_r1_c6.gif" onclick="goToPage('+ (numpages-1) +')"  onMouseOver="swaptheImage(this)" onMouseOut="swaptheImageback(this)"/>'
}

}
else {

document.getElementById("dropItPerPage").selectedIndex=document.getElementById("dropItPerPage").length-1;
//document.getElementById("numberpage").innerHTML='Page ' + numpages + ' of ' + numpages;
}
 createPaginStringBottom(numpages,pnum)
}


function createPaginStringBottom(numpages,pnum){

//<span id="prpage"></span><span id="numberpage"></span><span id="nextpage"></span>
//http://site.bathroom-glass-vanities.com/images/next-but.jpg
document.getElementById("numberpage2").innerHTML='';
document.getElementById("prpage2").innerHTML='<img src="http://www.luxstores.com/'+site+'/paging-empty_r1_c5.gif">';
document.getElementById("nextpage2").innerHTML='<img src="http://www.luxstores.com/'+site+'/paging-empty_r1_c5.gif">';
document.getElementById("lastpage2").innerHTML='<img src="http://www.luxstores.com/'+site+'/paging-empty_r1_c6.gif">';
document.getElementById("firstpage2").innerHTML='<img src="http://www.luxstores.com/'+site+'/paging-empty_r1_c2.gif">';

//alert('cleaned');
if (pnum!=20000){
	

document.getElementById("numberpage2").innerHTML='<span class=description>Page ' + (pnum+1) + ' of ' + numpages+'</span>';
if (pnum >= 1) {
document.getElementById("firstpage2").innerHTML='<img style="cursor:hand;cursor:pointer;" src="http://www.luxstores.com/'+site+'/paging_r1_c2.gif" onclick="goToPage('+ 0 +')" onMouseOver="swaptheImage(this)" onMouseOut="swaptheImageback(this)"/>'
}
if (pnum>0){
//go to prev
document.getElementById("prpage2").innerHTML='<img style="cursor:hand;cursor:pointer;" src="http://www.luxstores.com/'+site+'/paging_r1_c3.gif" onclick="goToPage('+ (pnum-1)+')"  onMouseOver="swaptheImage(this)" onMouseOut="swaptheImageback(this)">'; 
}
//alert('g');


if (pnum<numpages-1){
document.getElementById("nextpage2").innerHTML='<img style="cursor:hand;cursor:pointer;" src="http://www.luxstores.com/'+site+'/paging_r1_c5.gif" onclick="goToPage('+ (pnum+1)+')"  onMouseOver="swaptheImage(this)" onMouseOut="swaptheImageback(this)">'; 
}
if ( pnum<numpages-1) {
document.getElementById("lastpage2").innerHTML='<img style="cursor:hand;cursor:pointer;" src="http://www.luxstores.com/'+site+'/paging_r1_c6.gif" onclick="goToPage('+ (numpages-1) +')"/  onMouseOver="swaptheImage(this)" onMouseOut="swaptheImageback(this)">'
}

}

}

function toDollarsAndCents(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t 
}

function addCommas(nStr)
{
       nStr += '';
      var x = nStr.split('.');
      var x1 = x[0];
      var x2 = x.length > 1 ? '.' + x[1] : '';
       var rgx = /(\d+)(\d{3})/;
       while (rgx.test(x1)) {
               x1 = x1.replace(rgx, '$1' + ',' + '$2');
       }
       return x1 + x2;
}