function showPLmenu(){
	var _html = 
		'<table class="pl_menu" width="100%" border="0" cellpadding="0" cellspacing="0">' + 
		  '<tr>' + 
		    '<td class="pl_menu_left">&nbsp;</td>' + 
			'<td width="180">' + pl_label['SORT'] + ' ' + 
			'<select class="pl_sort" name="sort_by" size="1">' + getSortValue() + '</select>&nbsp;&nbsp;&nbsp;' + 
			'<a class="pl_sortdir" href="javascript:void(0);" title="'+pl.sort_dir+'">' + 
			'  <img src="'+pl.pl_imgpath+pl.sort_dir+'.gif" border="0" /></a>' + 
			'</td>' + 
			'<td width="150">' + pl_label['RESULT_PER_PAGE'] + ' ' + 
			'<select class="pl_result" name="pl_result" size="1">' + getPerPageValue() + '</select>' + 
			'</td>' + 
			'<td width="54" class="pl_viewText">&nbsp;&nbsp;' + pl_label['VIEW'] + '</td>' + 
			'<td width="46"><a href="javascript:void(0);" class="pl_viewbuttons" title="grid">' + 
			'  <img src="'+pl.pl_imgpath+'az_pl_grid.gif" border="0" /></a></td>' + 
			'<td width="42" class="pl_viewText">' + pl_label['GRID'] + '</td>' + 
			'<td class="pl_menu_sep"></td>' + 
			'<td width="48"><a href="javascript:void(0);" class="pl_viewbuttons" title="list">' + 
			'  <img src="'+pl.pl_imgpath+'az_pl_list.gif" border="0" /></a></td>' + 
			'<td width="30" class="pl_viewText">' + pl_label['LIST'] + '</td>' + 
			'<td width="160" class="pl_pagenav">&nbsp;</td>' + 
			'<td class="pl_menu_right">&nbsp;</td>' + 
		  '</tr>' + 
		'</table>';
	return _html;
}

function showPLcontent(pl_data){
	var _html = '';
	var _pbox = '';
	
	switch(pl.view){
		case "list":
			_pbox = '<table id="pl_list" align="center" border="0" cellspacing="1" cellpadding="2">';
			if(pl_data.length < 1){
				_pbox += '<tr class="pl_list_data"><td><p>' + pl_label['NO_RECORDS_FOUND'] + '</p></td></tr>';
			}
			$(pl_data).each(function(i, data){
				imgpath = pl.imgpath + data['image'];
				imgDimension = (view[pl.view][1] ? 'width="'+view[pl.view][1]+'" ' : '') + (view[pl.view][2] ? 'height="'+view[pl.view][2]+'" ' : '');
				pdesc = data['desc'].length > 100 ? data['desc'].substr(0,100)+'...' : data['desc'];
				
				_pbox += '<tr class="pl_list_data">' + 
				         '<td align="center" width="170">' + 
						 '<a href="' + imgpath + '" rel="facebox" title="' + pl_label['ZOOM'] + '">' + 
						   '<img class="borderedPic" src="'+imgpath+'" border="1" ' + imgDimension + ' /></a>' + 
						 '</td>' + 
				         '<td valign="middle" ' + (data['attribute'] ? '' : 'colspan="2"') + '>' + 
						 '<div class="pl_title">' + data['title'] + '</div>' + 
						 '<p class="pl_desc">' + pdesc + '</p>' + 
						 '<div class="cart_wrapper">' + 
						 '<div id="cart'+data['id']+'" class="pl_cart">' + (data['cart']>0 ? '(' + data['cart'] + ') ' + pl_label['IN_CART'] : '') +'</div>' + 
						 '<div id="err'+data['id']+'" class="pl_errorbox"><img src="'+pl.loading1+'" border="0" width="16" /></div>' + 
						 '</div>' + 
						 '</td>' + 
						 (data['attribute'] ? '<td><form id="az_pl_form'+data['id']+'" name="pl_cart_quantity" method="post">' + 
						 '<div class="pl_attribute">' + data['attribute'] + '</div></form></td>' : '') + 
				         '<td width="180" class="pl_price">' + getPrice(data['price'], data['sprice'], '<br />') + 
						 '<table class="pl_buttons" align="center" border="0" cellspacing="0" cellpadding="0"><tr>' + 
				         '<td><a href="'+pl.xmlsrc+'?task=viewinfo&'+pl.params+'&pid='+data['id']+'" rel="facebox" title="'+pl_label['DETAILS']+'">' + 
						 pl_azButton(pl_label['MORE_INFO'], '2') + '</a></td>' + 
						 '<td class="pl_button_sep"></td>' + 
				         '<td>' + ( data['attr_status'] > 1 ? '<a href="'+pl.xmlsrc+'?task=viewinfo&'+pl.params+'&pid='+data['id']+'" rel="facebox" title="'+data['id']+'">' : '<a href="javascript:void(0)" title="' + data['id'] + '" class="addtocart">' ) + 
						 pl_azButton(pl_label['ADD_TO_CART'], '') + '</a></td>' + 
				         '</tr></table>' + 
						 '</td>' + 
				         '</tr>';
				if(((i+1)%view[pl.view][0])==0 && i < (pl_data.length-1)){
					_pbox += '<tr><td colspan="4" align="center"><div class="pl_hor_sep"><img src="'+pl.pl_imgpath+'spacer.gif" border="0" width="1" height="1" /></div></td></tr>';
				}
			});
			_pbox += '</table>';
			_html += pl_productBox(_pbox);
		break;
		
		case "grid":
			_html += '<table id="pl_grid" align="center" border="0" cellspacing="0" cellpadding="0"><tr>';
			$(pl_data).each(function(i, data){
				imgpath = pl.imgpath + data['image'];
				imgDimension = (view[pl.view][1] ? 'width="'+view[pl.view][1]+'" ' : '') + (view[pl.view][2] ? 'height="'+view[pl.view][2]+'" ' : '');
				ptitle = data['title'].length > 12 ? data['title'].substr(0,12)+'...' : data['title'];
				pdesc = data['desc'].length > 100 ? data['desc'].substr(0,100)+'...' : data['desc'];
				
				_pbox = '<table class="azprod_table" width="100%" border="0" cellspacing="0" cellpadding="0"><tr>' + 
				         '<td valign="top">' + 
				         '<div class="pl_price">' + getPrice(data['price'], data['sprice'], '') + '</div>' + 
						 '<div class="pl_title">' + data['title'] + '</div>' + 
				         '<p class="pl_desc">' + pdesc + '</p>' + 
				         '<table class="pl_buttons" align="center" border="0" cellspacing="0" cellpadding="0"><tr>' + 
				         '<td><a href="'+pl.xmlsrc+'?task=viewinfo&'+pl.params+'&pid='+data['id']+'" rel="facebox" title="'+pl_label['DETAILS']+'">' + 
						 pl_azButton(pl_label['MORE_INFO'], '2') + '</a></td>' + 
						 '<td class="pl_button_sep"></td>' + 
				         '<td>' + ( data['attr_status'] > 0 ? '<a href="'+pl.xmlsrc+'?task=viewinfo&'+pl.params+'&pid='+data['id']+'" rel="facebox" title="' + data['id'] + '">' : '<a href="javascript:void(0)" title="' + data['id'] + '" class="addtocart">' ) + 
						 pl_azButton(pl_label['ADD_TO_CART'], '') + '</a></td>' + 
				         '</tr></table>' + 
				         '</td>' + 
						 '<td valign="middle" align="center" style="padding:0 8px 0 2px;">' + 
				         '<a href="' + imgpath + '" rel="facebox" title="' + pl_label['DETAILS'] + '">' + 
				         '<img class="borderedPic" src="'+imgpath+'" border="0" ' + imgDimension + ' />' + 
				         '</a>' + 
						 '<div class="cart_wrapper">' + 
						 '<div id="cart'+data['id']+'" class="pl_cart">' + (data['cart']>0 ? '(' + data['cart'] + ') ' + pl_label['IN_CART'] : '') +'</div>' + 
						 '<div id="err'+data['id']+'" class="pl_errorbox"><img src="'+pl.loading1+'" border="0" width="16" /></div>' + 
						 '</div>' + 
				         '</td>' + 
				         '</tr></table>';
				_html += '<td class="pl_grid_data">' + pl_productBox(_pbox) + '</td>';
				if(((i+1)%view[pl.view][0])==0 && i < (pl_data.length-1)){
					_html += '</tr><tr><td class="pl_hor_sep" colspan="'+(view[pl.view][0]+1)+'"><img src="'+pl.pl_imgpath+'spacer.gif" border="0" width="1" height="6" /></td></tr><tr>';
				}else{
					if(((i+1)%pl.limit)!=0 && i < (pl_data.length-1)) _html += '<td class="pl_ver_sep"><img src="'+pl.pl_imgpath+'spacer.gif" border="0" width="3" height="1" /></td>';
				}
			});
			if ( pl_data.length % view[pl.view][0]  ) {
				//we need to add some empty td
				var add = pl_data.length % view[pl.view][0];
				for( var j=1; j <= add; j++) _html += '<td>&nbsp;</td>';
			}
			if(pl_data.length < 1) _html += '<td><p>' + pl_label['NO_RECORDS_FOUND'] + '</p></td>';
			_html += '</tr></table>';
		break;
	}
		
	$("#pl_content").html(_html);
	
	pl_fixHeight();
	
	$("a.addtocart").click(function(){
		if($(".pl_errorbox").is(":animated")==false){
			var id = $("form#az_pl_form"+this.title).serialize() ? '&' + $("form#az_pl_form"+this.title).serialize()+'&pid='+this.title : ''
			addtocart(this.title, id);
		}
		$(this).blur();
	});
	
	jQuery('a[rel*=facebox]').facebox();
	$('#facebox').bgiframe();
}

function popAddtoCart(obj, pid) {
	var id = '&' + $("form#az_popForm").serialize()
	obj.blur()
	addtocart(pid, id)
}

function getPerPageValue(){
	var opt = "";
	$.each(display, function(key, value) {
		opt += '<option value="' + value + '"'+(pl.limit==value ? ' selected="selected"' : '' )+'>' + value + '</option>';
	});
	
	return opt;
}

function getSortValue(){
	var opt = "";
	opt += '<option value="latest"'+(pl.sortby=="latest" ? ' selected="selected"' : '' )+'>'+pl_label['LATEST']+'</option>' + 
		   '<option value="name"'+(pl.sortby=="name" ? ' selected="selected"' : '' )+'>'+pl_label['NAME']+'</option>' + 
		   '<option value="price"'+(pl.sortby=="price" ? ' selected="selected"' : '' )+'>'+pl_label['PRICE']+'</option>' + 
		   '<option value="brand"'+(pl.sortby=="brand" ? ' selected="selected"' : '' )+'>'+pl_label['BRAND']+'</option>';
	
	return opt;
}

function pl_fixHeight() {
	//var maxH = 0;
	var maxH2 = 0;
	$('.pl_grid_data .pl_title').each(function(i){
		//maxH = $(this).height() > maxH ? $(this).height() : maxH;
		maxH2 = $('.azprod_table:eq('+i+')').height() > maxH2 ? $('.azprod_table:eq('+i+')').height() : maxH2;
		if((i+1)%view[pl.view][0] == 0){
			for(var x=i; x >= parseInt((i+1)-view[pl.view][0]); x--){
				//$('.pl_title:eq(' + x + ')').height(maxH);
				$('.azprod_table:eq(' + x + ')').height(maxH2);
			}
			//maxH = 0;
			maxH2 = 0;
		}
	});
}

function pl_azButton(alt, bnum) {
	var image_button = '<nobr><span class="az-button-left'+bnum+'" title="' + alt + '">&nbsp;</span><span class="az-button-middle'+bnum+'" title="' + alt + '">&nbsp;' + alt +'&nbsp;</span><span class="az-button-right'+bnum+'" title="' + alt + '">&nbsp;</span></nobr>';
	return image_button;
}

function pl_productBoxBorder(boxclass) {
	var _html = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="' + boxclass + '"><tr>' + 
			'<td class="' + boxclass + 'L"><img src="'+pl.pl_imgpath+'spacer.gif" border="0"></td>' + 
			'<td width="100%" class="' + boxclass + 'C">&nbsp;</td>' + 
			'<td class="' + boxclass + 'R"><img src="'+pl.pl_imgpath+'spacer.gif" border="0"></td>' + 
			'</tr></table>';
	return _html;
}

function pl_productBox(contents) {
	var _html = '<table width="100%" border="0" cellspacing="0" cellpadding="0">' + 
			'<tr><td colspan="3">' + pl_productBoxBorder('pl_prodBoxHeader') + '</td></tr>' + 
			'<tr>' + 
			  '<td class="pl_prodBoxL"><img src="'+pl.pl_imgpath+'spacer.gif" border="0" width="1" height="1" /></td>' + 
			  '<td width="100%" class="pl_prodBoxC">' + contents + '</td>' + 
			  '<td class="pl_prodBoxR"><img src="'+pl.pl_imgpath+'spacer.gif" border="0" width="1" height="1" /></td>' + 
			'</tr>' + 
			'<tr><td colspan="3">' + pl_productBoxBorder('pl_prodBoxFooter') + '</td></tr>' + 
			'</table>';
	return _html;
}

function getPrice(price, sprice, sep){
	if(!sprice == 0){
		price = '<s>' + price + '</s> ' + sep + sprice;
	}
	return price;
}

function getLoading1(){
	return '<img src="'+pl.loading1+'" border="0" width="16" height="16" />';
}