var totalpro=myArray.length;
var totpages=totalpro/itemperpage;
var temp=Math.round(totpages);
if (totpages <= temp){
totpages=temp;
}else{
totpages= temp + 1;
}


function WriteData(id, value){
//document.write(value);

if(id=="prosaleprice" && value==""){
	document.getElementById(id).style.display = "none";
	}else if(id=="prosaleprice"){
		var value=number_format(value, 2, '.', '');
		document.getElementById(id).innerHTML= "<div class=\"item-white-txt\">Sale Price:</div><div class=\"green-b-txt\">$"+ value +"</div>";
		document.getElementById(id).style.display = "";
		}else if(id=="proprice" && value==""){
	document.getElementById(id).style.display = "none";
	}else if(id=="proprice"){
		var value=number_format(value, 2, '.', '');
		document.getElementById(id).innerHTML= "<div class=\"item-white-txt\">Regular Price:</div><div class=\"item-dark-yellow-txt\"  >$"+ value +"</div>";
		document.getElementById(id).style.display = "";
	}else if(id=="proavailability" && value==""){
	document.getElementById(id).style.display = "none";
	}else if(id=="proavailability"){
		document.getElementById(id).innerHTML= "<div class=\"item-white-txt\">Availability:</div><div class=\"item-dark-yellow-txt1\">"+ value +"</div>";
		document.getElementById(id).style.display = "";
	}else if(id=="prooptions" && value==""){
	document.getElementById(id).style.display = "none";
	}else if(id=="prooptions"){
		document.getElementById(id).innerHTML= value ;
		document.getElementById(id).style.display = "";
	}else{
	document.getElementById(id).innerHTML = value;	
		}
}



function ChangeClass(id, clname){
document.getElementById(id).className= clname;
}

function Pagination(first, last){

	var pagenumdatatop="";
	var pagenumdatabottom="";

		for (i=first;i<=last;i++)
		{
			var tempnumtop="<td id=\"pntop"+ i +"\" class=\"pagenumber\" align=\"right\" valign=\"middle\"><a href=\"javascript:showpage("+ i +")\"> "+ i +" </a></td><td align=\"center\" valign=\"middle\"><img src=\"http://iovistacommerce.com.p2.hostingprod.com/ystore/inhouse/advance-pagination/spacer.gif\" width=\"3\" height=\"1\"></td>";
			var tempnumbottom="<td id=\"pnbottom"+ i +"\" class=\"pagenumber\" align=\"right\" valign=\"middle\"><a href=\"javascript:showpage("+ i +")\">"+ i +"</a></td><td align=\"center\" valign=\"middle\"><img src=\"http://iovistacommerce.com.p2.hostingprod.com/ystore/inhouse/advance-pagination/spacer.gif\" width=\"3\" height=\"1\"></td>";
			
			var pagenumdatatop = pagenumdatatop + tempnumtop;
			var pagenumdatabottom = pagenumdatabottom + tempnumbottom;
			
		}
		pagenumdatatop="<table border=\"0\" align=\"right\" cellspacing=\"0\" cellpadding=\"0\"><tr>"+ pagenumdatatop +"</tr></table>";
		pagenumdatabottom="<table border=\"0\" align=\"right\" cellspacing=\"0\" cellpadding=\"0\"><tr>"+ pagenumdatabottom +"</tr></table>";
		WriteData("pagingtop", pagenumdatatop );
		WriteData("pagingbottom", pagenumdatabottom);
		
}


function showpage(page){
if(page=="all"){
	var first=0;
	var last=totalpro;
}else{
	var pagedata="";
	var last=page * itemperpage;
	var first=last - itemperpage;
	if(last >= totalpro){
	last=totalpro;
	}
}
ShowProducts(first, last);

//Showing Page
if(page=="all"){
showing="Showing all";
}else{
first=parseInt(first) + 1;
var showing = "Showing "+ first +"- "+ last +" of about "+ totalpro +".";
}
WriteData("showingtop", showing);
WriteData("showingbottom", showing);

//End Of Showing Page

//Print Pagination
if(totpages > viewpage){
	var half=viewpage/2;
	var currentpg=parseInt(page) - parseInt(half);
	var lastpg = parseInt(page) + parseInt(half);
	
	if(currentpg <= 0 ){
	currentpg=1;
	lastpg = viewpage;
	}else{currentpg=currentpg+1;}
	
	if(lastpg >= totpages){
	lastpg=totpages;
	currentpg=totpages - viewpage + 1;
	}
	if(page=="all"){
	
	}else{Pagination(currentpg, lastpg);}
	
	}else{
	Pagination(1, totpages);
}

//End Of Print Pagination
//Next Prev
var prev=parseInt(page) - 1;
var next=parseInt(page) + 1;
var prevtxt="";
var nexttxt="";
if (prev==0 || page=="all"){
prevtxt="Prev";
}else{
prevtxt="<a href=\"javascript:showpage("+ prev +")\">Prev</a>";
}
if (next > totpages || page=="all"){
nexttxt="Next";
}else{
nexttxt="<a href=\"javascript:showpage("+ next +")\">Next</a>";
}
WriteData("prevtop", prevtxt);
WriteData("nexttop", nexttxt);
WriteData("prevbottom", prevtxt);
WriteData("nextbottom", nexttxt);

//End Of Next Prev
//Change Class
if(page=="all"){
WriteData("viewalltop", "View All");
WriteData("viewallbottom", "View All");
}else{
var pantop="pntop"+ page;
var pnbottom="pnbottom"+ page;
ChangeClass(pantop, "active");
ChangeClass(pnbottom, "active");
WriteData("viewalltop", "<a id=\"viewalltop\" href=\"javascript:showpage('all');\">View All</a>");
WriteData("viewallbottom", "<a id=\"viewallbottom\" href=\"javascript:showpage('all');\">View All</a>");
}
//End Of Change Class
//if One Page
if(totpages==1){
WriteData("viewalltop", "");
WriteData("viewallbottom", "");
WriteData("pagingtop", "");
WriteData("pagingbottom", "");
WriteData("prevtop", "");
WriteData("nexttop", "");
WriteData("prevbottom", "");
WriteData("nextbottom", "");
}
//if One Page

//Set Cookie
if(page=="all"){page=cookie_value;}
	set_cookie(catid, page ,expiredate);
//End of Set Cookie

}
//For Quick View image
function HideContent(d, first, last) {
/*for(i=first; i<=last; i++){
	var idn="item"+i;
	document.getElementById(idn).style.display = "none";
	}*/
var idname="item"+d;
document.getElementById(idname).style.display = "none";
}

function ShowContent(d) {
	var idname="item"+d;

document.getElementById(idname).style.display = "block";

}
//End Quick View image
