<!--
var curCat;
var fltrCat = '';
var fltrABC = '';
var rowClass = 'retailerRow';
var altClass = 'retailerAltRow';
//var utilRoot = '../Util/GetShop.aspx';
var siteRoot = '<%= SiteName%>';
var pgIcon = '/ShoppingCentreSites/Images/icon_goto_page.gif';
var isEditting = false;

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

function genList(abc,cat) {
	genEditList(abc,cat,false);
	return;
}

function genEditList(abc,cat,isEdit){
	var i;
	var j;
	var htm;
	var itm;
	var lbl;
	
	fltrCat = cat;
	fltrABC = abc;
	curCat ='';
	rowBg='';
	
	htm='<table border="0" cellspacing="0" cellpadding="0" width="100%">';
	htm+='<tr class="siteMapLevel2">'
		+ '<td height="40">Category</td><td width="10"></td><td>Store</td><td>Shop</td><td>Phone</td>';
	if (isEdit==true){
		htm += '<td></td>';
	}
	htm += '</tr>';

	for(i=0;i<=arrShops.length-1;i++){
		itm=arrShops[i];
		htm+=getRowHTM(itm[0],itm[1],itm[2],itm[3],itm[4],isEdit,i);
	}
	htm+='</tr>';
	
	//Write the htm back to the page
	//Broser check required here
	if(document.all){
		lbl=self.document.all['spnCategories'];
	}
	else{
		lbl=self.document.getElementById('spnCategories');
	}
			
	
	if(lbl==undefined){
		alert('Your browser does not support the functionality required by this page.');
		return;
	}
	lbl.innerHTML=htm;
}

function getRowHTM(abc,cat,mnmc,shop,phone,isEdit, rowIdx){
	var ret = '<tr>';
	var td = '<td>';
	var editLink = '<a class="lnk edit" onclick="javascript:doEdit(' + rowIdx + ');" >edit</a>&nbsp;<a class="lnk del" onclick="javascript:deleteRow(\'' + rowIdx + '\');" >del</a>';
	//var link = url; //utilRoot + '?shop=' + shop + '&mnmc=' + mnmc + '&site=' + siteRoot;
	
	//Check the filters
	if(! (fltrCat==cat || fltrCat=='')){
		return '';
	}
	if(! (fltrABC==abc || fltrABC=='')){
		return '';
	}
	
	if(cat==undefined){
		return '';
	}
	
	//Check if this is the first category
	if(curCat!=cat){
		curCat=cat;
		if(rowClass == 'retailerRow'){
			rowClass = altClass;
		}
		else{
			rowClass = 'retailerRow';
		}
		
		td='<td class="' + rowClass + '">';
		ret+= td + '<b>' + cat + '</b></td>';
	}
	else{
		td='<td class="' + rowClass + '">';
		ret+= td +'&nbsp;</td>';
	}
	
	//Add the cols
	//if(showLink=='Y'){
	//	ret+='<td class="' + rowClass + '" align="right"><img src="' + pgIcon + '" width="12">&nbsp;</td>' + td + '<a href="' + link + '">' + shop + '</a></td>';
	//}
	//else{
		ret+=td + '</td>' + td + shop + '</td>';
	//}
	ret+= td + mnmc + '</td>';
	ret+= td + phone + '</td>';
	if(isEdit==true)
	{
	//alert(editLink);
	ret+= '<td class="editLinks ' + rowClass + '">' + editLink + '</td>';
	}
	
	ret+='</tr>';
	
	return ret;
}
function showLrgImage(img){
	//alert(img.src);
	var win = window.open(img.src,'img','menubar=no,location=no,resizable=yes,scrollbars=yes,status=no');
}

function doEdit(rowIdx)
{
	document.getElementById('txtCategory').value = arrShops[rowIdx][1];
	document.getElementById('txtRetailer').value = arrShops[rowIdx][3];
	document.getElementById('txtShopCode').value = arrShops[rowIdx][2];
	document.getElementById('txtPhone').value = arrShops[rowIdx][4];
	document.getElementById('inputRowIndex').value = rowIdx;
	isEditting = true;
}

function escapeString(str)
{
	if (str != undefined)
	{
	 str = str.replace("'","\\'");
	}

alert(str);
	
	return str
}

function clearEditBoxes()
{
	document.getElementById('txtCategory').value = '';
	document.getElementById('txtRetailer').value = '';
	document.getElementById('txtShopCode').value = '';
	document.getElementById('txtPhone').value = '';
	document.getElementById('inputRowIndex').value = '';
	isEditting = false;
}

function deleteRow(mnmc)
{
	__doPostBack('delete', mnmc );
}

function beforeSave()
{
	if (isEditting == false)
	{
		var newMnmc = document.getElementById('txtShopCode').value;
		for(i=0;i<=arrShops.length-1;i++){
			itm=arrShops[i];
			if (itm[2].trim() == newMnmc.trim())
			{
				return confirm('There is already a listing for shop "' + newMnmc + '", do you want to continue and add a another listing?');
			}
		}
		
		return true;
	}
}
//-->