var lt = '<xsl:text disable-output-escaping="yes">&lt;</xsl:text>';
var gt = '<xsl:text disable-output-escaping="yes">&gt;</xsl:text>';

function preLoadImages(){
var t='<layer top="-100" left="0" visibility=""><div style="position:absolute; top:-100px; left:0px; visibility:hidden">';
for(i=0;i<arguments.length;i++)t+='<img src="'+arguments[i]+'" height="10" width="10">';
t+='</div></layer>';
document.write(t);
}

preLoadImages('lime/images/lime_menu_bg.gif','lime/images/lime_menu_rollover_bg.gif','lime/images/lime_menu_selected_bg.gif');

function SelectAllRecipients(boxfrom)
{
	for (n=0; n < boxfrom.length; n++)
		boxfrom.options[n].selected = true;
}

function MoveRecipient(frombox, tobox) 
{
	var idx = frombox.selectedIndex;
	
	if (idx == -1)
	{
		alert('Please choose a recipient before using this button');
	}
	else
	{
		var chosen = frombox.options[idx].text;
		var id = frombox.options[idx].value;
		
//		if (!fnd) tobox.options[tobox.options.length] = new Option(chosen, tobox.options.length);
		tobox.options[tobox.options.length] = new Option(chosen, id);

		// Now go get rid of it from the avail box..	
		nomatch = new Array();
		for (n=0; n < frombox.length;n++)
			{
				if(frombox.options[n].text != chosen)
					nomatch[nomatch.length] = new Array(frombox.options[n].value, frombox.options[n].text);
			}
		frombox.options.length = 0;
		if (nomatch.length != 0) 
			for (n=0;n<nomatch.length;n++)
				frombox.options[n] = new Option(nomatch[n][1], nomatch[n] [0]);
	}
}

function MoveAllRecipients(frombox, tobox)
{
	// Move all items from the frombox to the tobox
	for (n=0; n < frombox.length; n++)
	{
		tobox.options[tobox.options.length] = new Option(frombox.options[n].text, frombox.options[n].value);
	}
	
	// Now clear the frombox
	frombox.options.length = 0;
}

function doswap(theitem, newimg) {
	document.images[theitem].src = newimg;
}

function gotopage(page)
{
	if (page=='')
		document.frmMain.page.value='';
	else
		document.frmMain.page.value='lime/' + page;
	
	document.frmMain.submit();
	return false;
}

function dologin()
{
	document.frmMain.logginin.value = '1';
	document.frmMain.submit();
	return(false);
}

function dologout()
{
	document.frmMain.logginout.value='1';
	document.frmMain.submit();
	return(false);
}

function selectitem(item, type, parent)
{
	document.frmMain.selecteditem.value = item;
	document.frmMain.selectedtype.value = type;
	document.frmMain.selectedparent.value = parent;
	document.frmMain.submit();
	return(false);
}

function deleteitem(type, item)
{
	if (!confirm('Do you really want to delete this ' + type + '?'))
		return;

	document.frmMain.selecteditem.value = item;
	document.frmMain.selectedtype.value = type;
	if (type == 'item' || type == 'category')
		document.frmMain.deleteit.value = type + item;  // This is the new way of specifying the item to be deleted so that no other item can be deleted by mistake
	else
		document.frmMain.deleteit.value = '1';
	document.frmMain.submit();
	return(false);
}

function testrule(ruleid)
{
	window.open('testrule.aspx?selecteditem=' + ruleid,'testrule','width=400,height=300')
}

function uploadimage(itemid, itemimageid)
{
	// Allow the user to upload an image and attach it to the selected item
	window.open('_common/uploadimage.aspx?itemimageid=' + itemimageid + '&itemid=' + itemid,'uploadimage','width=400,height=250');
}		

function uploadcategoryimage(categoryid, itemimageid)
{
	// Allow the user to upload an image and attach it to the selected item
	window.open('_common/uploadimage.aspx?itemimageid=' + itemimageid + '&categoryid=' + categoryid,'uploadimage','width=400,height=250');
}		

function displayinvitation(itemid, imagewidth, imageheight)
{

	var W = 500;
	var H = 500;

	if (imagewidth > 450)
		W = imagewidth + 50;
	
	if (imageheight > 400);			
		H = imageheight + 100;

	window.open('invitation_details.aspx?selectedtype=item' + '&selecteditem=' + itemid,'_blank','width=' + W + ',height=' + H + ',scrollbars=yes');

	return(false);
}

function cards_addtoorder(itemid)
{
	// Add an item to the user's order basket
	var type='item';
	window.open('addtoorder.aspx?selectedtype=' + type + '&selecteditem=' + itemid + '&itemid=' + itemid,'addtoorder','width=450,height=400');
	return(false);
}

function invitations_addcategory(parentcategoryname, siteid)
{
//			window.open('invitations_addcategory.aspx?selectedtype=' + selectedtype,'addcategory','width=400,height=500');

	document.frmMain.selectedtype.value = 'category';
	document.frmMain.selecteditem.value = 0;
	document.frmMain.mode.value = 'editcategory';
	document.frmMain.parentcategoryname.value = parentcategoryname;
	document.frmMain.parentcategoryid.value = 0;
	document.frmMain.selectedparent.value = siteid;
	document.frmMain.submit();
		
	return(false);
}

function invitations_editcategory(categoryid)
{
//			window.open('invitations_addcategory.aspx?selectedtype=category' + amp + 'selecteditem=' + categoryid,'addcategory','width=400,height=500');

	document.frmMain.selectedtype.value = 'category';
	document.frmMain.selecteditem.value = categoryid;
	document.frmMain.selectedparent.value = '';
	document.frmMain.mode.value = 'editcategory';
	document.frmMain.submit();
	
	return(false);
}

function invitations_addinvite(categoryid)
{
//	window.open('invitations_addinvitation.aspx?selectedtype=item' + amp + 'selectedparent=' + categoryid,'addinvitation','width=400,height=500');

	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = '';
	document.frmMain.selectedparent.value = categoryid;
	document.frmMain.mode.value = 'edititem';
	document.frmMain.submit();
	
	return(false);
}

function invitations_editinvite(categoryid, itemid)
{
//			window.open('invitations_addinvitation.aspx?selecteditem=' + itemid + amp +'selectedtype=item' + amp + 'selectedparent=' + categoryid,'editinvitation','width=400,height=500');

	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = itemid;
	document.frmMain.selectedparent.value = categoryid;
	document.frmMain.mode.value = 'edititem';
	document.frmMain.submit();
	
	return(false);
}

function edititem(itemid)
{
//			window.open('edititem.aspx?selecteditem=' + itemid + amp + 'selectedtype=item','edititem','width=700,height=500');
	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = itemid;
	document.frmMain.selectedparent.value = parent;
	document.frmMain.mode.value = 'edititem';
	document.frmMain.submit();

	return(false);
}

function cards_addcategory()
{
	window.open('cards_addcategory.aspx','addcategory','width=400,height=200');
}

function photos_addcategory(siteid, parentcategoryid, parentcategoryname)
{
	document.frmMain.selectedparent.value = siteid
	document.frmMain.selectedtype.value = 'category';
	document.frmMain.selecteditem.value = 0;
	document.frmMain.mode.value = 'editcategory'
	document.frmMain.selectedparentcategory.value = parentcategoryid;
	document.frmMain.parentcategoryname.value = parentcategoryname;
	document.frmMain.submit();
	return(false);
}

function cards_addcard(categoryid)
{
//	window.open('cards_addcard.aspx?selectedtype=item' + '&selectedparent=' + categoryid,'addcard','width=400,height=400');
}

function cards_editcategory(categoryid)
{
//	window.open('cards_addcategory.aspx?selectedtype=category' + '&selecteditem=' + categoryid,'addcategory','width=400,height=200');
	
	document.frmMain.selectedtype.value = 'category';
	document.frmMain.selecteditem.value = categoryid;
	document.frmMain.mode.value = 'editcategory'
	document.frmMain.submit();
	return(false);	
}

function cards_editsubcategory(categoryparentid, categoryid)
{
	window.open('cards_addcategory.aspx?categoryparentid=' + categoryparentid + '&selectedtype=category' + '&selecteditem=' + categoryid,'addcategory','width=400,height=200');
}

function cards_editintroitem(itemid)
{
	window.open( 'cards_introitem.aspx?selecteditem=' + itemid + '&selectedtype=item','edititem','width=400,height=400');
}

function cards_addintroitem(categoryid)
{
	window.open( 'cards_introitem.aspx?selectedtype=item' + '&selectedparent=' + categoryid,'edititem','width=400,height=400');
}

function cards_editcard(categoryid, itemid)
{
//			window.open( 'cards_addcard.aspx?selecteditem=' + itemid + amp + 'selectedtype=item' + amp + 'selectedparent=' + categoryid,'editcard','width=400,height=400');

	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = itemid;
	document.frmMain.selectedparent.value = categoryid;
	document.frmMain.mode.popup = '';
	document.frmMain.mode.value = 'edititem';
	document.frmMain.submit();
}

function displaycardintro(itemid, imagewidth, imageheight)
{
	var W = 500;
	var H = 500;

	if (imagewidth > 450);			
		W = imagewidth + 50;
	
	if(imageheight > 400);			
		H = imageheight + 100;

	window.open('card_introdetails.aspx?selectedtype=item&selecteditem=' + itemid,'_blank','width=' + W + ',height=' + H + ',scrollbars=yes');

	return(false);
}

function displaycard(itemid)
{
	window.open('card_details.aspx?selectedtype=item' + '&selecteditem=' + itemid,'_blank','width=500,height=500,scrollbars=yes');
	return(false);
}

function displayphoto(itemid)
{
//	window.open('card_details.aspx?selectedtype=item' + '&selecteditem=' + itemid,'_blank','width=500,height=500,scrollbars=yes');
	document.frmMain.selecteditem.value = itemid
	document.frmMain.selectedtype.value = 'item';
	document.frmMain.submit();
	return(false);
}

function outlets_addoutlet(categoryid)
{
//	window.open('outlet_details.aspx?selectedtype=item' + '&selectedparent=' + categoryid,'outletdetails','width=500,height=400');
	
	document.frmMain.selectedparent.value = categoryid
	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = 0;
	document.frmMain.mode.value = 'edititem';
	document.frmMain.mode.popup = '';

//	document.frmMain.selectedparent.value = siteid
//	document.frmMain.selectedtype.value = 'category';
//	document.frmMain.selecteditem.value = 0;
//	document.frmMain.mode.value = 'editcategory'
//	document.frmMain.selectedparentcategory.value = parentcategoryid;
//	document.frmMain.parentcategoryname.value = parentcategoryname;
	document.frmMain.submit();
	return(false);
}

function outlets_editoutlet(categoryid, itemid)
{
//	window.open('outlet_details.aspx?selecteditem=' + itemid + '&selectedtype=item' + '&selectedparent=' + categoryid,'outletdetails','width=500,height=400,scrollbars=yes');
	
	document.frmMain.selectedparent.value = categoryid
	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = itemid;
	document.frmMain.mode.value = 'edititem';
	document.frmMain.mode.popup = '';
	
//	document.frmMain.selectedparentcategory.value = parentcategoryid;
//	document.frmMain.parentcategoryname.value = parentcategoryname;
	document.frmMain.submit();
	return(false);	
}

function addnews(categoryid)
{
//			window.open('news_details.aspx?selectedtype=item' + amp + 'selectedparent=' + categoryid,'newsdetails','width=700,height=500');
	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = 0;
	document.frmMain.selectedparent.value = categoryid;
	document.frmMain.mode.value = 'edititem';
	document.frmMain.submit();
	return(false);
}

function editnews(categoryid, itemid)
{
//			window.open('news_details.aspx?selecteditem=' + itemid + amp + 'selectedtype=item' + amp + 'selectedparent=' + categoryid,'newsdetails','width=700,height=500');
	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = itemid;
	document.frmMain.selectedparent.value = categoryid;
	document.frmMain.mode.popup = '';
	document.frmMain.mode.value = 'edititem';
	document.frmMain.submit();
	return(false);
}

function cards_addsubcategory(categoryid)
{
	window.open('cards_addcategory.aspx?categoryparentid=' + categoryid + '&selectedtype=category','addsubcategory','width=400,height=200');
}

function addcategory(siteid, parentcategoryid, parentcategoryname)
{
	document.frmMain.selectedparent.value = siteid
	document.frmMain.selectedtype.value = 'category';
	document.frmMain.selecteditem.value = 0;
	document.frmMain.mode.value = 'editcategory'
	document.frmMain.selectedparentcategory.value = parentcategoryid;
	document.frmMain.parentcategoryname.value = parentcategoryname;
	document.frmMain.submit();
	return(false);
}

function additem(categoryid)
{
//			window.open('edititem.aspx?selectedtype=item' + amp + 'selectedparent=' + categoryid,'edititem','width=700,height=500,toolbar=yes,status=yes');
	document.frmMain.selectedparent.value = categoryid
	document.frmMain.selectedtype.value = 'item';
	document.frmMain.selecteditem.value = 0;
	document.frmMain.mode.value = 'edititem'
	document.frmMain.submit();
	return(false);
}

function additemtoorder(itemid, qty)
{
	document.frmMain.addtoorder.value=itemid;
	document.frmMain.addtoorderqty.value=qty;
	document.frmMain.submit();
}

function cards_clearorder()
{
	document.frmMain.clearorderbasket.value = "1";
	document.frmMain.submit();
}