var validurl      = /^(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
var validimgurl   = /^(http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(?:\/\S*)?(?:[a-zA-Z0-9_\ \-\.])+\.(?:jpg|jpeg|gif|png))$/;
var validhashurl  = /^#[[a-zA-Z0-9\-\.\/]+/;
var validemail    = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var valid_date	  = /^[\d\-]{10}$/;
var validname     = /^([a-zA-Z\-'])+ *([a-zA-Z\- '])*$/;
var validphone    = /^[0-9\- \.\+]{10,}$/;
var validdigit    = /^\d+$/;
var validaddress  = /^([a-zA-Z0-9\- ']){2,}$/;
var validpostcode = /^[a-zA-Z0-9 ]{5,}$/;
var validprice    = /^\d{1,}(\.\d{2})?$/;
var validfloat    = /^\d{1,}(\.\d{1,2})?$/;
/*-----------------------------------------------------------------------------*/
function toggleTab() 
{
	if(document.getElementById('dataForm').changes.value == 1)
	{
		var output = '<br /><br /><h3>Discard Changes?</h3><p>You made changes that you have not saved.</p><p>Do you want to continue and lose these changes?</p>';
			output +='<button type="button" onclick="doTab(\''+arguments[0]+'\');">Yes</button> <button type="button" onclick="hideModal();">No</button>';
		showModal(output, 'You Made Changes', 300,180,'','modal');
	}
	else
	{
		var theAction = '';
		if(arguments[2] && arguments[2].length > 0 )
		{	
			doTab(arguments[0],arguments[1],arguments[2]);
			theAction = arguments[0]+'/'+arguments[1]+'/'+arguments[2];
		}
		else if(arguments[1] && arguments[1].length > 0)
		{	
			doTab(arguments[0],arguments[1]);
			theAction = arguments[0]+'/'+arguments[1];
		}
		else
		{	
			doTab(arguments[0]);
			theAction = arguments[0];
		}
		window.location = '#/'+theAction;
		backArray.push(theAction);
		while(forwardArray.length >0) forwardArray.pop();
	}
}
function toggleItemTab()
{
	var myLink = document.getElementById(arguments[0]);
	var theLinks = document.getElementById(arguments[0]).parentNode.childNodes; 
	for( var i=0; i<theLinks.length; i++ )
	{
		if(theLinks[i].className == 'topTabActive') theLinks[i].className = 'topTab'; 
		if(theLinks[i].className == 'subTabActive')  theLinks[i].className = 'subTab'; 
		if(document.getElementById((theLinks[i].id)+'Box')) document.getElementById((theLinks[i].id)+'Box').style.display = 'none';
	}
	if(myLink.className == 'topTab') myLink.className = 'topTabActive';
	if(myLink.className == 'subTab') myLink.className = 'subTabActive';
	if(document.getElementById(arguments[0]+'Box'))
		document.getElementById(arguments[0]+'Box').style.display = 'block';
	myLink.blur();
}
function doBackButton()
{
	if(backArray.length >0)
	{
		var toForward = backArray.pop();
		var forwardTemp = forwardArray.slice();
		forwardTemp.push(toForward);
		var theAction = backArray.pop();
		if(!theAction) theAction = 'summary';
		var parts = theAction.split('/');
		toggleTab(parts[0],parts[1],parts[2]);
		forwardArray = forwardTemp.slice();
	}
}
function doRefresh()
{
	if(backArray.length >0)
	{
		var theAction = backArray.pop();
		if(!theAction) theAction = 'summary';
		var parts = theAction.split('/');
		toggleTab(parts[0],parts[1],parts[2]);
	}
	else
		toggleTab('summary');
}
function doForwardButton()
{
	if(forwardArray.length >0)
	{
		var theAction = forwardArray.pop();
		var forwardTemp = forwardArray.slice();
		if(!theAction) theAction = 'summary';
		var parts = theAction.split('/');
		toggleTab(parts[0],parts[1],parts[2]);
		forwardArray = forwardTemp.slice();
	}
}
function doTab() /* this.id */
{
	unsetChanges();
	var myLink = document.getElementById(arguments[0]);
	document.getElementById('dataForm').currenttab.value = arguments[0];
	var theLinks = document.getElementById(arguments[0]).parentNode.childNodes; 
	for( var i=0; i<theLinks.length; i++ )
	{
		if(theLinks[i].className == 'topTabActive') theLinks[i].className = 'topTab'; 
		if(theLinks[i].className == 'subTabActive')  theLinks[i].className = 'subTab'; 
		if(document.getElementById((theLinks[i].id)+'Box')) document.getElementById((theLinks[i].id)+'Box').style.display = 'none';
	}
	if(myLink.className == 'topTab') myLink.className = 'topTabActive';
	if(myLink.className == 'subTab') myLink.className = 'subTabActive';
	if(document.getElementById(arguments[0]+'Box'))
		document.getElementById(arguments[0]+'Box').style.display = 'block';
	myLink.firstChild.blur();
	if(!arguments[1])
	{
		var output = '<br /><br /><p>Updating...</p>';
		output +='<img src="/micromarket/console/images/ajax-bar.gif" alt="checking" />';
		showModal(output, 'Contacting Server...', 250,150);
		doPush('command='+arguments[0]+'&userid='+document.getElementById('dataForm').userid.value+'&currenttab='+arguments[0]);
	}
	else
	{
		var output = '<br /><br /><p>Updating...</p>'+'<img src="/micromarket/console/images/ajax-bar.gif" alt="checking" />';
		showModal(output, 'Contacting Server...', 250,150);
		if(!arguments[2])
		doPush('command='+arguments[1]+'&userid='+document.getElementById('dataForm').userid.value+'&currenttab='+arguments[1]);
		else
		doPush('command='+arguments[1]+'&userid='+document.getElementById('dataForm').userid.value+'&currenttab='+arguments[1]+'&id='+arguments[2]);
	}
}
/*-----------------------------------------------------------------------------*/
function doNag() /* this.id */
{
	if(document.getElementById('dataForm') && document.getElementById('dataForm').userid.value >0)
	{
		var commandstring = "";
		if(document.getElementById('showItemPopupBox') && document.getElementById('modalWindow').style.display == 'block')
			commandstring += "command=itempopup&itemid="+document.getElementById('itemIdForm').itemid.value;	
		else
			commandstring += 'command=&newmail='+document.getElementById('dataForm').newMailTotal.value+'&newfriends='+document.getElementById('dataForm').newFriendsTotal.value+'&newquestions='+document.getElementById('dataForm').newQuestionsTotal.value;
		commandstring += '&userid='+document.getElementById('dataForm').userid.value+'&session='+document.getElementById('dataForm').session.value;
		doScreenNag(commandstring);
	}
}
function doShop()
{
	var m = 'modal';
	var url = '/shop';
	if(arguments[0]) url = arguments[0];
	window.location = url;
}
function showImage()
{
	var m = 'modal';
	var url = arguments[0];
	var w = 640;
	var h = 480;
	var output = "<div style=\"width:"+ (w-10) +"px; height:"+ (h-80) +"px;\"><img src=\""+url+"\" style=\"max-width:"+ (w-10) +"px; max-height:"+ (h-80) +"px; padding:0px; margin:0px;\"></div>";
		output += "<p class=\"button230focus\" style=\"float:right;\"><a href=\"javascript:hideModal('"+m+"');\" title=\"\">Close</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
	showModal(output,'Viewing Image',w,h,'close',m);
}
function doAttach() /* srcfield, previewboxID, width, height*/
{
	var theUrl = document.getElementById(arguments[0]).value;
	var theElement = arguments[1];
	var w = 200;
	var h = 150;
	if(arguments[2]){ w = arguments[2];}
	if(arguments[3]){ h = arguments[3];}
	doPush("command=previewurl&userid="+document.getElementById('dataForm').userid.value+"&url="+theUrl+"&element="+theElement+"&width="+w+"&height="+h);
}
function youtubeIDextract(url)
{
	var isvalid = url.match(/http:\/\/(www\.)?youtube.com\//);
	if(isvalid)
		return url.replace(/^[^v]+v.(.{11}).*/,"$1");
	else
		return false;
}
function vimeoIDextract(url)
{
	var isvalid = url.match(/http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/);
	if(isvalid)
		return isvalid[2];
	else
		return false;
}
/*- WIZARD FUNCTIONS ----------------------------------------------------------*/
function doWizard() 
{
	var markup = "<p>Loading wizard....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
	showModal(markup,'Ad Placement Wizard',930,540);
	var commandstring = 'command=&userid='+document.getElementById('dataForm').userid.value+'&session='+document.getElementById('dataForm').session.value;
	doWizardPush(commandstring);
}
function doWizardStage() 
{
	var commandstring = "";
	if(document.getElementById('wizardForm'))
	{
		var errors = Array();
		var wizform   = document.getElementById('wizardForm');
		commandstring += 'command='+wizform.command.value+'&userid='+document.getElementById('dataForm').userid.value+'&session='+document.getElementById('dataForm').session.value+'&currency='+wizform.currency.value;
		
		if(wizform.command.value == 'salearea')
		{
			if(arguments[0])
				wizform.currency.value = arguments[0];		
			wizform.parent_id.value = '';
			wizform.department.value = '';
			wizform.section.value = '';
		}
		if(wizform.command.value == 'saletype')
		{
			if(arguments[0]>0)
				wizform.salearea.value = arguments[0];		
			wizform.parent_id.value = '';
			wizform.department.value = '';
			wizform.section.value = '';
		}
		if(wizform.command.value == 'department')
		{
			if(arguments[0]>0)
				wizform.parent_id.value = arguments[0];
			wizform.department.value = '';
			wizform.section.value = '';
		}
		if(wizform.command.value == 'section')
		{
			if(arguments[0]>0)
				wizform.department.value = arguments[0];
			wizform.section.value = '';
		}
		if(wizform.command.value == 'details')
		{
			if(arguments[0]>0)
				wizform.section.value = arguments[0];
		}
		if(wizform.command.value == 'images' && document.getElementById('inputForm'))
		{
			var inputform = document.getElementById('inputForm');
			wizform.title.value 	= inputform.ititle.value;
			wizform.desc.value 		= inputform.idesc.value;
			wizform.content.value 	= inputform.icontent.value;
			if(inputform.iquantity)	{wizform.quantity.value = inputform.iquantity.value;}else{wizform.quantity.value= "1";}
			if(inputform.iprice)	{wizform.price.value 	= inputform.iprice.value;	}else{wizform.price.value 	= "";}
			if(inputform.istyle)	{wizform.fstyle.value 	= inputform.istyle.value;	}else{wizform.fstyle.value 	= "";}
			if(inputform.isize)		{wizform.fsize.value 	= inputform.isize.value;	}else{wizform.fsize.value 	= "";}
			if(inputform.iheight)	{wizform.fheight.value 	= inputform.iheight.value;	}else{wizform.fheight.value = "";}
			if(inputform.inebari)	{wizform.nebari.value 	= inputform.inebari.value;	}else{wizform.nebari.value 	= "";}
			if(inputform.itrunk)	{wizform.trunk.value 	= inputform.itrunk.value;	}else{wizform.trunk.value 	= "";}
			if(inputform.ipot)		{wizform.pot.value 		= inputform.ipot.value;		}else{wizform.pot.value 	= "";}
			if(inputform.ipostage)		{wizform.postage.value 		= inputform.ipostage.value;		}else{wizform.postage.value 	= "";}
			if(inputform.isendto)		{wizform.sendto.value 		= inputform.isendto.value;		}else{wizform.sendto.value 	= 0;}
		}
		if(wizform.command.value == 'complete')
		{
			if(!validemail.test(wizform.paypal.value) && wizform.paypal.value != "")
			{ errors.push('Invalid email address for paypal'); }
		}
		if(wizform.command.value == 'images' || wizform.command.value == 'complete')
		{
			if(wizform.title.value.length <6) { errors.push("Please provide a title of at least 6 characters"); }
			if(wizform.desc.value.length <10) { errors.push("Please provide a short description of at least 10 characters"); }
			if(parseInt(wizform.quantity.value) < parseInt(wizform.minquantity.value))
			{errors.push("Not enough items for sale - minimum for this sale type is "+wizform.minquantity.value);}
			if(!validdigit.test(wizform.quantity.value) || wizform.quantity.value < 1)
			{ errors.push('Invalid quantity for sale'); }
			
			if(document.getElementById('inputForm'))
			{
				if(inputform.iprice && !validprice.test(wizform.price.value) )	{errors.push("Invalid amount in price field.");}
			}
			if(wizform.fheight && !validfloat.test(wizform.fheight.value) && wizform.fheight.value != "" )	{errors.push("Please only use numbers in the height field.");}
			if(wizform.nebari && !validfloat.test(wizform.nebari.value)  && wizform.nebari.value != "")	{errors.push("Please only use numbers in the nebari field.");}
			if(wizform.trunk && !validfloat.test(wizform.trunk.value)  && wizform.trunk.value != "")		{errors.push("Please only use numbers in the trunk field.");}
		}
		if (errors.length > 0)
		{
			var theHeight = parseInt(60 + (errors.length * 20)); 
			var output = '<p>'+errors.join('</p><p>')+'</p>';
				output +='<button onclick="hideModalModal();">OK</button>';
			showModalModal(output, 'Form Errors!', 350,theHeight);
		}
		else
		{
			commandstring += '&trader='+wizform.trader.value+'&parent_id='+wizform.parent_id.value;
			commandstring += '&department='+wizform.department.value+'&section='+wizform.section.value;
			commandstring += '&itemid='+wizform.itemid.value+'&salearea='+wizform.salearea.value;
			commandstring += '&quantity='+wizform.quantity.value;
			/*----------------------------------*/
			commandstring += '&title='+escape(wizform.title.value)+'&desc='+escape(wizform.desc.value);
			commandstring += '&content='+escape(wizform.content.value)+'&price='+wizform.price.value;
			commandstring += '&fstyle='+wizform.fstyle.value+'&fsize='+wizform.fsize.value;
			commandstring += '&fheight='+wizform.fheight.value+'&nebari='+wizform.nebari.value;
			commandstring += '&trunk='+wizform.trunk.value+'&pot='+escape(wizform.pot.value);
			/*----------------------------------*/
			commandstring += '&image0='+wizform.image0.value+'&image1='+wizform.image1.value+'&image2='+wizform.image2.value+'&image3='+wizform.image3.value;
			/*----------------------------------*/
			commandstring += '&postage='+escape(wizform.postage.value)+'&sendto='+wizform.sendto.value+'&currency='+wizform.currency.value;
			/*----------------------------------*/
			commandstring += '&youtube='+wizform.youtube.value+'&vimeo='+wizform.vimeo.value;
			commandstring += '&viewing='+wizform.viewing.value+'&paypal='+wizform.paypal.value;
			doWizardPush(commandstring);
		}
	}
}
function wizBack() /* optional arg */
{
	var myAction = "";
	if(arguments[0] && arguments[0] != "")
		myAction = "document.getElementById('wizardForm').command.value = '"+arguments[0]+"';doWizardStage(); ";
	else
		myAction = "doWizard();";
	var output =  '<h2 class="thehighlight">Step Back and Lose Changes?</h2><p>Do you wish to step back from this stage of the wizard?</p><p class="button230unfocus" style="float:right;"><a href="javascript:'+myAction+'hideModalModal();" title="Step Back">Step Back</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p class="button230focus" style="float:right;"><a href="javascript:hideModalModal();" title="Cancel">Return to Wizard</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
	showModalModal(output,'Step Back?','340','150');
}
function changeWizItemImage()
{
		var theField = arguments[0];
		var theID = arguments[1];
		var theScreen = 'wizard';
		var uploadpath = "/images/trading/items";
		var markup = "<iframe id=\"uploadFrame\" name=\"uploadFrame\" style=\"width:400px;height:80px;float:right;\" src=\"/micromarket/console/uploadform.php?dir="+uploadpath+"&id="+theID+"&field="+theField+"&screen="+theScreen+"\" scrolling=\"no\"></iframe><h3><a href=\"javascript:hideModalModal();\" title=\"\">Close</a></h3>";
		showModalModal(markup,'Change Image',420,135);
}
function wizardVideoUrl() /* srcfield, previewboxID, width, height, */
{
		var theUrl = document.getElementById(arguments[0]).value;
		
		if(youtubeIDextract(theUrl)!=false)
		{
			document.getElementById('wizardForm').youtube.value = theUrl;
			document.getElementById('wizardForm').vimeo.value = '';
			doAttach (arguments[0],arguments[1],arguments[2],arguments[3]);
		}
		else if(vimeoIDextract(theUrl)!=false)
		{
			document.getElementById('wizardForm').youtube.value = '';
			document.getElementById('wizardForm').vimeo.value = theUrl;
			
			doAttach (arguments[0],arguments[1],arguments[2],arguments[3]);
		}
		else
		{
			document.getElementById('wizardForm').youtube.value = '';
			document.getElementById('wizardForm').vimeo.value = '';
		}
}
/*----WALL FUNCTIONS ----------------------------------------------------------*/
function toggleCommunityWall() { toggleTab('summary','summary',arguments[0]); }
function moreWallPosts()
{
	var theForm = document.getElementById('wallForm');
		theForm.first.value = parseInt(parseInt(theForm.first.value)+parseInt(theForm.pagelength.value));
	var commandstring  = "command=morewallposts&userid="+document.getElementById('dataForm').userid.value+"&first="+theForm.first.value+"&pagelength="+theForm.pagelength.value+"&id="+theForm.filter.value;
		doPush(commandstring);
}
function toggleAttachBox()
{
	if(document.getElementById('attachBox'))
	{
		if(document.getElementById('attachBox').style.display == "none") document.getElementById('attachBox').style.display = "block";
		else if(document.getElementById('attachBox').style.display == "block") 
		{
			document.getElementById('wallForm').attachUrl.value = "";
			document.getElementById('wallForm').content.value = "";
			document.getElementById('attachPreview').innerHTML = "";
			document.getElementById('attachBox').style.display = "none";
		}
	}
}
function saveWallPost() 
{
	var theForm = document.getElementById('wallForm');
	var errors = new Array();
	if(theForm.title.value == "")
		{ errors.push('You have not written anything yet'); }
	if (errors.length > 0)
	{
		var theHeight = parseInt(80 + (errors.length * 20)); 
		showModal('<p><br />'+errors.join('</p><p>')+'<br /></p><p class=\"button110focus\" style=\"margin-left:65px;\"><a href="javascript:hideModal(\'modal\');">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>', 'Oops!', 250,theHeight);
	}
	else
	{
		var commandstring  = "command=savewallpost&userid="+document.getElementById('dataForm').userid.value+"&title="+theForm.title.value+"&content="+escape(theForm.content.value);
			doPush(commandstring);
			unsetChanges();
	}
}
function deleteWallPost() 
{
	var output = "<p>Are you sure you want to delete this post?</p><p><strong>This action can NOT be undone.</strong></p>";
		output +='<p class=\"button110focus\" style=\"margin-left:20px;float:left;\"><a href="javascript:hideModal(\'modalModal\');">Cancel</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p class=\"button110unfocus\" style=\"float:left;\"><a href="javascript:doDeleteWallPost(\''+arguments[0]+'\');">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
	showModalModal(output,'Delete Post?',280,120);
}
function doDeleteWallPost() 
{
	doPush("command=deletewallpost&userid="+document.getElementById('dataForm').userid.value+"&id="+arguments[0]);
}
function wallComment() { document.getElementById(arguments[0]).style.display = 'block'; }
function doWallComment() 
{
	var theMessage = document.getElementById('wallCommentContent'+arguments[0]);
	var errors = new Array();
	if(theMessage.value == "") { errors.push('You have not typed a comment.'); }
	if (errors.length > 0)
	{
		var theHeight = parseInt(60 + (errors.length * 20)); 
		var output = '<p>'+errors.join('</p><p>')+'</p><button onclick="hideModalModal();">OK</button>';
		showModalModal(output, 'Form Errors!', 250,theHeight);
	}
	else
	{
		var commandstring  = "command=savewallcomment&userid="+document.getElementById('dataForm').userid.value+"&id="+arguments[0]+"&content="+theMessage.value;
			doPush(commandstring);
			unsetChanges();
	}
}
function deleteWallComment()  
{
	var output = '<p>Are you sure you want to delete this comment?</p><p><strong>This action can NOT be undone.</strong></p><p class="button110focus" style="margin-left:20px;float:left;"><a href="javascript:hideModal(\'modalModal\');">Cancel</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p class=\"button110unfocus\" style=\"float:left;\"><a href="javascript:doDeleteWallComment(\''+arguments[0]+'\');">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
	showModalModal(output,'Delete Comment?',280,120);
}
function doDeleteWallComment() { doPush("command=deletewallcomment&userid="+document.getElementById('dataForm').userid.value+"&id="+arguments[0]); }
/*-MARKETPLACE FUNCTIONS ------------------------------------------------------*/
function getMarketPlaceFields()
{
	var formID = arguments[0];
	var commandstring = "first="+document.getElementById(formID).first.value+"&total="+document.getElementById(formID).total.value+"&pagelength="+document.getElementById(formID).pagelength.value+"&department="+document.getElementById(formID).filterDepartment.value+"&section="+document.getElementById(formID).filterSection.value+"&size="+document.getElementById(formID).filterSize.value+"&style="+document.getElementById(formID).filterStyle.value+"&salearea="+document.getElementById(formID).salearea.value+"&trader="+document.getElementById(formID).trader.value+"&order="+document.getElementById(formID).order.value;
	if(document.getElementById(formID).filterLocation) { commandstring += "&flocation="+document.getElementById(formID).filterLocation.value; }
	return commandstring;
}
function fetchFilterSections()
{
	var formID = arguments[0];
	document.getElementById(formID).first.value = 0;
	document.getElementById(formID).filterSection.value = "";
	document.getElementById(formID).filterSize.value = "";
	document.getElementById(formID).filterStyle.value = "";
	var commandstring  = "command=fetchmarketplacefiltersections&userid="+document.getElementById('dataForm').userid.value+"&formID="+formID+"&"+getMarketPlaceFields(formID);	
	doPush(commandstring);
}
function fetchFilterSizes()
{
	var formID = arguments[0];
	document.getElementById(formID).first.value = 0;
	document.getElementById(formID).filterSize.value = "";
	document.getElementById(formID).filterStyle.value = "";
	var commandstring  = "command=fetchmarketplacefiltersizes&userid="+document.getElementById('dataForm').userid.value+"&formID="+formID+"&"+getMarketPlaceFields(formID);	
	doPush(commandstring);
}
function fetchFilterStyles()
{
	var formID = arguments[0];
	document.getElementById(formID).first.value = 0;
	document.getElementById(formID).filterStyle.value = "";
	var commandstring  = "command=fetchmarketplacefilterstyles&userid="+document.getElementById('dataForm').userid.value+"&formID="+formID+"&"+getMarketPlaceFields(formID);	
	doPush(commandstring);
}
function setMarketplaceArea()
{
	document.getElementById('marketplaceFilterForm').first.value = 0;
	document.getElementById('marketplaceFilterForm').salearea.value = arguments[0];
	var commandstring  = "command=marketplace&userid="+document.getElementById('dataForm').userid.value+"&currenttab="+document.getElementById('dataForm').currenttab.value+"&salearea="+arguments[0];	
	doPush(commandstring);
}
function marketplacePage()
{
	var commandstring  = "command=marketplacepage&userid="+document.getElementById('dataForm').userid.value+"&currenttab="+document.getElementById('dataForm').currenttab.value;
	if(arguments[0]) 
	{
		var first = arguments[0];
		document.getElementById(document.getElementById('dataForm').currenttab.value+'FilterForm').first.value = arguments[0];
	}
		commandstring += "&"+getMarketPlaceFields(document.getElementById('dataForm').currenttab.value+'FilterForm');	
	doPush(commandstring);
}
/*- BUYING FUNCTIONS ----------------------------------------------------------*/
function setBuyingFolder()
{
	document.getElementById('buyingFilterForm').first.value = 0;
	document.getElementById('buyingFilterForm').folder.value = arguments[0];
	buyingPage(0);
}
function buyingPage()
{
	if(arguments[0]) 
	{
		var first = arguments[0];
		document.getElementById('buyingFilterForm').first.value = arguments[0];
	}
	var commandstring  = "command=buyingpage&userid="+document.getElementById('dataForm').userid.value+"&currenttab="+document.getElementById('dataForm').currenttab.value+"&folder="+document.getElementById('buyingFilterForm').folder.value+"&first="+document.getElementById('buyingFilterForm').first.value+"&total="+document.getElementById('buyingFilterForm').total.value+"&pagelength="+document.getElementById('buyingFilterForm').pagelength.value;	
		doPush(commandstring);
}
/*- SELLING -------------------------------------------------------------------*/
function setSellingArea()
{
	document.getElementById('sellingFilterForm').first.value = 0;
	document.getElementById('sellingFilterForm').salearea.value = arguments[0];
	sellingPage(0);
}
function sellingPage()
{
	if(arguments[0]) 
	{
		var first = arguments[0];
		document.getElementById('sellingFilterForm').first.value = arguments[0];
	}
	var commandstring  = "command=sellingpage&userid="+document.getElementById('dataForm').userid.value+"&currenttab="+document.getElementById('dataForm').currenttab.value+"&"+getMarketPlaceFields('sellingFilterForm');	
	doPush(commandstring);
}
/*- QUESTIONS -----------------------------------------------------------------*/
function setQuestionsFolder()
{
	document.getElementById('questionsFilterForm').first.value = 0;
	document.getElementById('questionsFilterForm').folder.value = arguments[0];
	questionsPage(0);
}
/*-----------------------------------------------------------------------------*/
function questionsPage()
{
	if(arguments[0]) 
	{
		var first = arguments[0];
		document.getElementById('questionsFilterForm').first.value = arguments[0];
	}
	var commandstring  = "command=questionspage&userid="+document.getElementById('dataForm').userid.value+"&currenttab="+document.getElementById('dataForm').currenttab.value+"&folder="+document.getElementById('questionsFilterForm').folder.value+"&first="+document.getElementById('questionsFilterForm').first.value+"&total="+document.getElementById('questionsFilterForm').total.value+"&pagelength="+document.getElementById('questionsFilterForm').pagelength.value;	
		doPush(commandstring);
}
/*--ACCOUNT FUNCTIONS ---------------------------------------------------------*/
function setAccountFolder()
{
	document.getElementById('accountFilterForm').first.value = 0;
	document.getElementById('accountFilterForm').folder.value = arguments[0];
	accountPage(0);
}
/*-----------------------------------------------------------------------------*/
function accountPage()
{
	if(arguments[0])  document.getElementById('accountFilterForm').first.value = arguments[0];
	var commandstring  = "command=accountpage&userid="+document.getElementById('dataForm').userid.value+"&currenttab="+document.getElementById('dataForm').currenttab.value+"&folder="+document.getElementById('accountFilterForm').folder.value+"&first="+document.getElementById('accountFilterForm').first.value+"&total="+document.getElementById('accountFilterForm').total.value+"&pagelength="+document.getElementById('accountFilterForm').pagelength.value;	
		doPush(commandstring);
}
/*- MYBASHO FUNCTIONS ---------------------------------------------------------*/

/*- MAIL FUNCTIONS ------------------------------------------------------------*/
function setMailFolder()
{
	document.getElementById('mailFilterForm').first.value = 0;
	if(arguments[0])
		document.getElementById('mailFilterForm').folder.value = arguments[0];
	mailPage(0);
}
/*-----------------------------------------------------------------------------*/
function mailPage()
{
	if(arguments[0])  document.getElementById('mailFilterForm').first.value = arguments[0];

	var commandstring  = "command=mailpage&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&folder="+document.getElementById('mailFilterForm').folder.value;
		commandstring += "&first="+document.getElementById('mailFilterForm').first.value;
		commandstring += "&total="+document.getElementById('mailFilterForm').total.value;
		commandstring += "&pagelength="+document.getElementById('mailFilterForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function showMail() /* messageid */
{
	if(arguments[0]) 
	{
		var markup = "<p>Loading....</p>";
			markup += "<p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
		showModal(markup,'Message',800,500);
		
		var commandstring = "command=showmail";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&folder="+document.getElementById('mailFilterForm').folder.value;
		commandstring += "&first="+document.getElementById('mailFilterForm').first.value;
		commandstring += "&total="+document.getElementById('mailFilterForm').total.value;
		commandstring += "&pagelength="+document.getElementById('mailFilterForm').pagelength.value;	
		commandstring += "&message="+arguments[0];
		doPush(commandstring);
	}
}
/*-----------------------------------------------------------------------------*/
function newMessage() /* user [messageid] [subject] */
{
	var markup = "<p>Loading....</p>";
		markup += "<p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
	showModal(markup,'Compose Message',800,500);
	
	var commandstring = "";
	if(arguments[0]) 
	{
		commandstring = "command=newmail";
		commandstring += "&recipient="+arguments[0];
		if(arguments[1]) 
			commandstring += "&message="+arguments[1];
		if(arguments[2]) 
			commandstring += "&subject="+arguments[2];
	}
	else
		commandstring = "command=mailrecipients";

	commandstring += "&userid="+document.getElementById('dataForm').userid.value;
	commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
	doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function sendMessage()
{
	var theForm = document.getElementById('newMessageForm');
	var errors = new Array();
	if(theForm.subject.value.length < 2)
		{ errors.push('Please provide a message subject'); }
	if(theForm.message.value.length < 2)
		{ errors.push('Please type your message before sending'); }
	if (errors.length > 0)
	{
		var output = '<br /><br /><p>'+errors.join('</p><p>')+'</p>';
			output +='<button onclick="hideModalModal();">OK</button>';
		showModalModal(output, 'Form Errors!', 250,150);
	}
	else
	{
		var commandstring  = "command=sendmail&userid="+document.getElementById('dataForm').userid.value;
			commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		/* if tab is mail it will need updating */
			if(document.getElementById('dataForm').currenttab.value == 'mail')
			{
				commandstring += "&folder="+document.getElementById('mailFilterForm').folder.value;
				commandstring += "&first="+document.getElementById('mailFilterForm').first.value;
				commandstring += "&total="+document.getElementById('mailFilterForm').total.value;
				commandstring += "&pagelength="+document.getElementById('mailFilterForm').pagelength.value;	
			}
			commandstring += "&recipient="+theForm.recipient.value;
			commandstring += "&subject="+escape(theForm.subject.value);
			commandstring += "&message="+escape(theForm.message.value);
			doPush(commandstring);
	}
}
/* PROFILE FUNCTIONS ----------------------------------------------------------*/
function toggleProfileTab() /* this.id */
{
	unsetChanges();
	
	var myLink = document.getElementById(arguments[0]);

	var theParent = document.getElementById('profileListBoxHeading');
	var theLinks = theParent.childNodes; 
	for( var i=0; i<theLinks.length; i++ )
	{
		if(theLinks[i].tagName == 'A'  )
		{
			theLinks[i].style.color = 'rgb(255,255,255)';
		}
	}
	myLink.style.color = 'rgb(154,204,153)';
	myLink.blur();
	if(arguments[0] != "myprofile")
	{
		var output = '<br /><br /><p>Updating...</p>';
		output +='<img src="/micromarket/console/images/ajax-bar.gif" alt="checking" />';
		showModal(output, 'Contacting Server...', 250,150);
		doPush('command='+arguments[0]+'&userid='+document.getElementById('dataForm').userid.value+'&currenttab='+document.getElementById('dataForm').currenttab.value+'&profiletab='+arguments[0]);
	}
}
/*-----------------------------------------------------------------------------*/
function updateProfileSetting()
{
	if(arguments[0])
	{
	var commandstring  = "command=profiledefault&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&setting="+arguments[0].id;
		commandstring += "&value="+arguments[0].value;
		doPush(commandstring);
	}
}
/*-----------------------------------------------------------------------------*/
function updateProfileSettingDefault()
{
	if(arguments[0])
	{
	var commandstring  = "command=profilesettingsdefault&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&setting="+arguments[0].id;
		commandstring += "&value="+arguments[0].value;
		doPush(commandstring);
	}
}
/*-----------------------------------------------------------------------------*/
function changeProfileImage()
{
		var markup = "<iframe id=\"uploadFrame\" name=\"uploadFrame\" style=\"width:400px;height:80px;float:right;\" src=\"/micromarket/console/uploadform.php?dir=/images/trading/traders&id="+document.getElementById('dataForm').userid.value+"\" scrolling=\"no\"></iframe>";
			markup += "<h3><a href=\"javascript:hideModal();\" title=\"\">Close</a></h3>";
		showModal(markup,'Change Image',420,135);
}
/*-----------------------------------------------------------------------------*/
function editAboutMe()
{
 document.getElementById('aboutMeDisplay').style.display = 'none';
	document.getElementById('aboutMeField').style.display = 'block';
 document.getElementById('profileAboutMeForm').aboutMe.focus();
}
/*-----------------------------------------------------------------------------*/
function discardAboutMe()
{
	document.getElementById('profileAboutMeForm').reset();
	document.getElementById('aboutMeDisplay').style.display = 'block';
	document.getElementById('aboutMeField').style.display = 'none';
			unsetChanges();
}
/*-----------------------------------------------------------------------------*/
function saveAboutMe()
{
	var commandstring  = "command=profileaboutme&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&content="+document.getElementById('profileAboutMeForm').aboutMe.value;
		doPush(commandstring);
			unsetChanges();
}
/*-----------------------------------------------------------------------------*/
function editContact()
{
	document.getElementById('contactDisplay').style.display = 'none';
	document.getElementById('contactField').style.display = 'block';
}
/*-----------------------------------------------------------------------------*/
function discardContact()
{
	document.getElementById('profileContactForm').reset();
	document.getElementById('contactDisplay').style.display = 'block';
	document.getElementById('contactField').style.display = 'none';
			unsetChanges();
}
/*-----------------------------------------------------------------------------*/
function saveContact()
{
	var theForm = document.getElementById('profileContactForm');
	var errors = new Array();
	if(theForm.country.value < 1)
		{ errors.push('Please select your country'); }
	if(theForm.region.value < 1)
		{ errors.push('Please select your region'); }
	if(!validaddress.test(theForm.address1.value) && theForm.address1.value != "")
		{ errors.push('Invalid first line of address'); }
	if(!validaddress.test(theForm.address2.value) && theForm.address2.value != "")
		{ errors.push('Invalid second line of address'); }
	if(!validaddress.test(theForm.address3.value) && theForm.address3.value != "")
		{ errors.push('Invalid third line of address'); }
	if(!validaddress.test(theForm.address4.value) && theForm.address4.value != "")
		{ errors.push('Invalid fourth line of address'); }
	if(!validpostcode.test(theForm.postcode.value) && theForm.postcode.value != "")
		{ errors.push('Invalid postcode, letters numbers and spaces only'); }
	if(!validphone.test(theForm.tel.value) && theForm.tel.value != "")
		{ errors.push('Invalid phone number, numbers and spaces only'); }
	if(!validphone.test(theForm.mob.value) && theForm.mob.value != "")
		{ errors.push('Invalid mobile number, numbers and spaces only'); }
	if(!validemail.test(theForm.paypal.value) && theForm.paypal.value != "")
		{ errors.push('Invalid PayPal Email Address'); }
		
	if (errors.length > 0)
	{
		var theHeight = parseInt(70 + (errors.length * 20)); 
		
		var output = '<p>'+errors.join('</p><p>')+'</p>';
			output +='<p class=\"button110focus\" style=\"text-align:center;\"><a href="javascript:hideModalModal();">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
		showModalModal(output, 'Form Errors!', 250,theHeight);
	}
	else
	{
		unsetChanges();
		var commandstring  = "command=profilecontact&userid="+document.getElementById('dataForm').userid.value;
			commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
			commandstring += "&title="+theForm.title.value;
			commandstring += "&description="+theForm.desc.value;
			commandstring += "&paypal="+theForm.paypal.value;
			commandstring += "&country="+theForm.country.value;
			commandstring += "&address1="+theForm.address1.value;
			commandstring += "&address2="+theForm.address2.value;
			commandstring += "&address3="+theForm.address3.value;
			commandstring += "&address4="+theForm.address4.value;
			commandstring += "&region="+theForm.region.value;
			commandstring += "&postcode="+theForm.postcode.value;
			commandstring += "&tel="+theForm.tel.value;
			commandstring += "&mob="+theForm.mob.value;
			doPush(commandstring);
	}
}
/*-----------------------------------------------------------------------------*/
function changeRegions()
{
	var formid = arguments[0];
	var countryfield = arguments[1];
	var regionfield = arguments[2];
	
	var commandstring = "command=fetchdata&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&fetch=region";
		commandstring += "&country="+document.getElementById(formid).country.value;
		commandstring += "&regionfield="+regionfield;
		commandstring += "&formid="+formid;
		doPush(commandstring);
	setChanges();
}
/*----BLOG ITEMS --------------------------------------------------------------*/
function addBlogItem()
{
		var markup = "<p>Loading....</p>";
			markup += "<p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
		showModal(markup,'Add New Item',800,550);
		
		var commandstring = "command=addblogitem";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&profiletab=bonsai";
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function editBlogItem()
{
	if(arguments[0]) 
	{
		var markup = "<p>Loading....</p>";
			markup += "<p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
		showModal(markup,'Edit Item',800,550);
		
		var commandstring = "command=editblogitem";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&item="+arguments[0];
		commandstring += "&profiletab=bonsai";
		doPush(commandstring);
	}
}
/*-----------------------------------------------------------------------------*/
function changeBlogItemImage()
{
		var theField = arguments[0];
		var theID = arguments[1];
		var theScreen = 'blogitemedit';
		
		var uploadpath = "/images/community/blogitems";
		
		var markup = "<iframe id=\"uploadFrame\" name=\"uploadFrame\" style=\"width:400px;height:80px;float:right;\" ";
			markup += " src=\"/micromarket/console/uploadform.php?dir="+uploadpath+"&id="+theID+"&field="+theField+"&screen="+theScreen+"\" scrolling=\"no\"></iframe>";
			markup += "<h3><a href=\"javascript:hideModalModal();\" title=\"\">Close</a></h3>";
		showModalModal(markup,'Change Image',420,135);
}
/*-----------------------------------------------------------------------------*/
function saveBlogItem()
{
	var theForm = document.getElementById('blogItemForm');
	var errors = new Array();
	if(theForm.section.value < 1)
		{ errors.push('Please choose a species'); }
	if(theForm.blogitemtitle.value == "")
		{ errors.push('Please provide a title'); }
	if(theForm.blogitemdesc.value == "")
		{ errors.push('Please provide a short description'); }


	if (errors.length > 0)
	{
		var theHeight = parseInt(60 + (errors.length * 20)); 
		
		var output = '<p>'+errors.join('</p><p>')+'</p>';
			output +='<p class=\"button110focus\" style=\"text-align:center;\"><a href="javascript:hideModalModal();">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
		showModalModal(output, 'Form Errors!', 250,theHeight);
	}
	else
	{
		var settings = "<SETTINGS>\n";
			settings += "<IMAGE0>"+theForm.image0.value+"</IMAGE0>\n";
			settings += "<IMAGE1>"+theForm.image1.value+"</IMAGE1>\n";
			settings += "<IMAGE2>"+theForm.image2.value+"</IMAGE2>\n";
			settings += "<IMAGE3>"+theForm.image3.value+"</IMAGE3>\n";
			settings += "<STYLE>"+theForm.sstyle.value+"</STYLE>\n";
			settings += "<SIZE>"+theForm.ssize.value+"</SIZE>\n";
			settings += "<HEIGHT>"+theForm.sheight.value+"</HEIGHT>\n";
			settings += "<NEBARI>"+theForm.nebari.value+"</NEBARI>\n";
			settings += "<TRUNK>"+theForm.trunk.value+"</TRUNK>\n";
			settings += "<POT>"+theForm.blogitempot.value+"</POT>\n";
			settings += "</SETTINGS>\n";
			
		var defaults = "<DEFAULTS>\n";
			defaults += "<POTTED>"+theForm.potted.value+"</POTTED>\n";
			defaults += "<WIRED>"+theForm.wired.value+"</WIRED>\n";
			defaults += "<STYLED>"+theForm.styled.value+"</STYLED>\n";
			defaults += "<PRUNED>"+theForm.pruned.value+"</PRUNED>\n";
			defaults += "<PEST>"+theForm.pest.value+"</PEST>\n";
			defaults += "<FUNG>"+theForm.fung.value+"</FUNG>\n";
			defaults += "<BURST>"+theForm.burst.value+"</BURST>\n";
			defaults += "<FLOWER>"+theForm.flower.value+"</FLOWER>\n";
			defaults += "<DEFLOWER>"+theForm.deflower.value+"</DEFLOWER>\n";
			defaults += "<DECANDLE>"+theForm.decandle.value+"</DECANDLE>\n";
			defaults += "</DEFAULTS>\n";

		var commandstring  = "command=saveblogitem&userid="+document.getElementById('dataForm').userid.value;
			commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
			
			commandstring += "&blogitem="+theForm.id.value;
			commandstring += "&title="+theForm.blogitemtitle.value;
			commandstring += "&description="+theForm.blogitemdesc.value;
			
			commandstring += "&trader="+document.getElementById('dataForm').userid.value;
			commandstring += "&content="+theForm.content.value;
			
			commandstring += "&section="+theForm.section.value;
			commandstring += "&thesettings="+settings;
			commandstring += "&thedefaults="+defaults;
			doPush(commandstring);
			unsetChanges();
	}
}
/*-----------------------------------------------------------------------------*/
function deleteBlogItem()
{
		var markup = "<h1>Permanently Remove Item?</h1>";
			markup += "<p>Are you sure you want to delete this item from your profile?</p>";
			markup += "<p><strong>This action can NOT be undone.</strong></p>";
			markup += "<p class=\"button110focus\" style=\"margin-left:85px;float:left;\"><a href=\"javascript:hideModal();\" title=\"\">Cancel</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
			markup += "<p class=\"button110unfocus\" style=\"float:left;\"><a href=\"javascript:doDeleteBlogItem('"+arguments[0]+"');\" title=\"\">Delete</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
		showModal(markup,'Delete Item?',400,150);
}
/*-----------------------------------------------------------------------------*/
function doDeleteBlogItem()
{
		var commandstring = "command=deleteblogitem";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&profiletab=bonsai";
		commandstring += "&blogitem="+arguments[0];
		doPush(commandstring);
		hideModal();
}
/*----BLOG FUNCTIONS ----------------------------------------------------------*/
function addBlogPost() /* blogitem */
{
		showModal("<p>Loading....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>",'Add New Item',600,550,'','modal');
		var theForm = document.getElementById('blogPageForm');
		var commandstring = "command=addblogpost";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&blogitem="+arguments[0];
		
		commandstring += "&first="+theForm.first.value;
		commandstring += "&pagelength="+theForm.pagelength.value;
		commandstring += "&comments="+theForm.comments.value;
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function editBlogPost() /* post , blogitem */
{
	if(arguments[0]) 
	{
		showModal("<p>Loading....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>",'Edit Post',600,550);
		
		var theForm = document.getElementById('blogPageForm');
		var commandstring = "command=editblogpost";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&blogpost="+arguments[0];
		commandstring += "&blogitem="+arguments[1];
		
		commandstring += "&first="+theForm.first.value;
		commandstring += "&pagelength="+theForm.pagelength.value;
		commandstring += "&comments="+theForm.comments.value;
		doPush(commandstring);
	}
}
/*-----------------------------------------------------------------------------*/
function changeBlogPostImage()
{
		var theField = arguments[0];
		var theID = arguments[1];
		var theScreen = 'blogpostedit';
		
		var uploadpath = "/images/community/blogposts";
		var markup = "<iframe id=\"uploadFrame\" name=\"uploadFrame\" style=\"width:400px;height:80px;float:right;\" ";
			markup += " src=\"/micromarket/console/uploadform.php?dir="+uploadpath+"&id="+theID+"&field="+theField+"&screen="+theScreen+"\" scrolling=\"no\"></iframe>";
			markup += "<h3><a href=\"javascript:hideModalModal();\" title=\"\">Close</a></h3>";
		showModalModal(markup,'Change Image',420,135);
}
/*-----------------------------------------------------------------------------*/
function saveBlogPost() 
{
	var theForm = document.getElementById('blogPostForm');
	var errors = new Array();
	if(theForm.title.value == "")
		{ errors.push('Please type a title for your post.'); }
	if(theForm.content.value == "")
		{ errors.push('You have not typed any content into your post.'); }
	if (errors.length > 0)
	{
		var theHeight = parseInt(60 + (errors.length * 20)); 
		
		var output = '<p>'+errors.join('</p><p>')+'</p>';
			output +='<button onclick="hideModalModal();">OK</button>';
		showModalModal(output, 'Form Errors!', 250,theHeight);
	}
	else
	{
		var commandstring  = "command=saveblogpost&userid="+document.getElementById('dataForm').userid.value;
			commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
			commandstring += "&blogpost="+theForm.id.value;
			commandstring += "&title="+theForm.title.value;
			commandstring += "&trader="+document.getElementById('dataForm').userid.value;
			commandstring += "&content="+theForm.content.value;
			commandstring += "&blogitem="+theForm.blogitem.value;
			commandstring += "&image="+theForm.image.value;
		commandstring += "&first="+theForm.first.value;
		commandstring += "&pagelength="+theForm.pagelength.value;
		commandstring += "&comments="+theForm.comments.value;
			doPush(commandstring);
			unsetChanges();
	}
}
/*-----------------------------------------------------------------------------*/
function deleteBlogPost()  /* post , blogitem */
{
		var markup = "<h2>Permanently Remove Post and Comments?</h2>";
			markup += "<p>Are you sure you want to delete this post and all its comments from your blog?</p>";
			markup += "<p><strong>This action can NOT be undone.</strong></p>";
			markup += "<p>&nbsp;</p>";
			markup += "<p class=\"button230unfocus\" style=\"float:right;\"><a href=\"javascript:doDeleteBlogPost('"+arguments[0]+"','"+arguments[1]+"');\" title=\"\">";
			markup += "Delete Item</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
			markup += "<p class=\"button230focus\" style=\"float:right;\"><a href=\"javascript:hideModal();\" title=\"\">";
			markup += "Cancel</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
		showModal(markup,'Delete Post and Comments?',360,190);
}
/*-----------------------------------------------------------------------------*/
function doDeleteBlogPost()  /* post , blogitem  */
{
		var theForm = document.getElementById('blogPageForm');
		var commandstring = "command=deleteblogpost";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&blogpost="+arguments[0];
		commandstring += "&blogitem="+arguments[1];
		
		commandstring += "&first="+theForm.first.value;
		commandstring += "&pagelength="+theForm.pagelength.value;
		commandstring += "&comments="+theForm.comments.value;
		doPush(commandstring);
		hideModal();
}
/*-----------------------------------------------------------------------------*/
function blogPage()
{
	if(arguments[0]) document.getElementById('blogPageForm').first.value = arguments[0];

	var commandstring  = "command=blog&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&first="+document.getElementById('blogPageForm').first.value;
		commandstring += "&comments="+document.getElementById('blogPageForm').comments.value;
		commandstring += "&pagelength="+document.getElementById('blogPageForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function profileBonsaiBlogPage()
{
	if(arguments[0]) 
	{
		var first = arguments[0];
		document.getElementById('blogProfilePageForm').first.value = arguments[0];
	}

	var commandstring  = "command=bonsai&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&profiletab=bonsai";
		commandstring += "&blogitem="+document.getElementById('blogProfilePageForm').blogitem.value;
		commandstring += "&first="+document.getElementById('blogProfilePageForm').first.value;
		commandstring += "&comments="+document.getElementById('blogProfilePageForm').comments.value;
		commandstring += "&pagelength="+document.getElementById('blogProfilePageForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function myProfileBlogPage()
{
	if(arguments[0]) 
	{
		var first = arguments[0];
		document.getElementById('blogProfilePageForm').first.value = arguments[0];
	}

	var commandstring  = "command=bonsai&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&profiletab=";
		commandstring += "&blogitem="+document.getElementById('blogProfilePageForm').blogitem.value;
		commandstring += "&first="+document.getElementById('blogProfilePageForm').first.value;
		commandstring += "&comments="+document.getElementById('blogProfilePageForm').comments.value;
		commandstring += "&pagelength="+document.getElementById('blogProfilePageForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function myCommunityBlogPage()
{
	if(arguments[0]) 
	{
		var first = arguments[0];
		document.getElementById('blogCommunityPageForm').first.value = arguments[0];
	}

	var commandstring  = "command=community&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&profiletab="+document.getElementById('blogCommunityPageForm').profiletab.value;
		commandstring += "&blogitem="+document.getElementById('blogCommunityPageForm').blogitem.value;
		commandstring += "&profile="+document.getElementById('blogCommunityPageForm').profile.value;
		commandstring += "&first="+document.getElementById('blogCommunityPageForm').first.value;
		commandstring += "&comments="+document.getElementById('blogCommunityPageForm').comments.value;
		commandstring += "&pagelength="+document.getElementById('blogCommunityPageForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function communityBonsaiBlogPage()
{
	if(arguments[0]) 
	{
		var first = arguments[0];
		document.getElementById('blogCommunityPageForm').first.value = arguments[0];
	}

	var commandstring  = "command=community&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&profiletab=bonsai";
		commandstring += "&blogitem="+document.getElementById('blogCommunityPageForm').blogitem.value;
		commandstring += "&profile="+document.getElementById('blogCommunityPageForm').profile.value;
		commandstring += "&first="+document.getElementById('blogCommunityPageForm').first.value;
		commandstring += "&comments="+document.getElementById('blogCommunityPageForm').comments.value;
		commandstring += "&pagelength="+document.getElementById('blogCommunityPageForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function addComment() /* blogpost, profiletab, blogitem */
{
		var markup = "<p>Loading....</p>";
			markup += "<p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
		showModal(markup,'Add A Comment',400,300);
		
		var commandstring = "command=addblogcomment";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&blogpost="+arguments[0];
		commandstring += "&profiletab="+arguments[1];
		commandstring += "&blogitem="+arguments[2];
		
		if(document.getElementById('blogProfilePageForm'))
		{
			var theForm = document.getElementById('blogProfilePageForm');
			commandstring += "&first="+theForm.first.value;
			commandstring += "&pagelength="+theForm.pagelength.value;
			commandstring += "&comments="+theForm.comments.value;
		}
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function saveBlogComment() 
{
	var theForm = document.getElementById('blogCommentForm');
	var errors = new Array();
	if(theForm.content.value == "")
		{ errors.push('You have not typed a comment.'); }
	if (errors.length > 0)
	{
		var theHeight = parseInt(60 + (errors.length * 20)); 
		
		var output = '<p>'+errors.join('</p><p>')+'</p>';
			output +='<button onclick="hideModalModal();">OK</button>';
		showModalModal(output, 'Form Errors!', 250,theHeight);
	}
	else
	{
		var commandstring  = "command=saveblogcomment&userid="+document.getElementById('dataForm').userid.value;
			commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
			commandstring += "&profiletab="+theForm.profiletab.value;
			commandstring += "&blogpost="+theForm.blogpost.value;
			commandstring += "&blogitem="+theForm.blogitem.value;
			commandstring += "&trader="+document.getElementById('dataForm').userid.value;
			commandstring += "&content="+theForm.content.value;
			commandstring += "&first="+theForm.first.value;
			commandstring += "&pagelength="+theForm.pagelength.value;
			commandstring += "&comments="+theForm.comments.value;
			doPush(commandstring);
			unsetChanges();
	}
}
/*-----------------------------------------------------------------------------*/
function deleteComment()  /* comment , blogitem ,profiletab */
{
		var markup = "<h1>Permanently Remove Comment?</h1><p>Are you sure you want to delete this comment from the blog?</p><p><strong>This action can NOT be undone.</strong></p>";
			markup += "<h1><a href=\"javascript:doDeleteComment('"+arguments[0]+"','"+arguments[1]+"','"+arguments[2]+"');\" title=\"\">";
			markup += "<img src=\"/api/icons/trash.png\" style=\"width:20px;border:0px;\">Delete Item</a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:hideModal();\" title=\"\">";
			markup += "<img src=\"/api/icons/cancel.png\" style=\"width:20px;border:0px;\">Cancel</a></h1>";
		showModal(markup,'Delete Post and Comments?',430,150);
}
/*-----------------------------------------------------------------------------*/
function doDeleteComment()  /* comment , blogitem ,profiletab */
{
		var commandstring = "command=deleteblogcomment";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&blogcomment="+arguments[0];
		commandstring += "&blogitem="+arguments[1];
		commandstring += "&profiletab="+arguments[2];
		
		if(document.getElementById('blogProfilePageForm'))
		{
			var theForm = document.getElementById('blogProfilePageForm');
			commandstring += "&first="+theForm.first.value;
			commandstring += "&pagelength="+theForm.pagelength.value;
			commandstring += "&comments="+theForm.comments.value;
		}
		doPush(commandstring);
		hideModal();
}
/*-----------------------------------------------------------------------------*/
function showBlogItem()
{
	toggleTab('mybasho','blogitems',arguments[0]);
}
/*---- LIBRARY FUNCTIONS ------------------------------------------------------*/
function libraryPage()
{
	if(arguments[0]) toggleTab('library','library','f'+arguments[0]+'|s'+document.getElementById('libraryPageForm').section.value);
}
/*-----------------------------------------------------------------------------*/
function saveArticleComment() 
{
	var theForm = document.getElementById('articleCommentForm');
	var errors = new Array();
	if(theForm.content.value == "")
		{ errors.push('You have not typed a comment.'); }
	if (errors.length > 0)
	{
		var theHeight = parseInt(60 + (errors.length * 20)); 
		
		var output = '<p>'+errors.join('</p><p>')+'</p>';
			output +='<button onclick="hideModalModal();">OK</button>';
		showModalModal(output, 'Form Errors!', 250,theHeight);
	}
	else
	{
		var commandstring  = "command=savearticlecomment&userid="+document.getElementById('dataForm').userid.value;
			commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
			commandstring += "&parent_id="+theForm.parent_id.value;
			commandstring += "&trader="+document.getElementById('dataForm').userid.value;
			commandstring += "&content="+theForm.content.value;
			theForm.content.value = "";
			doPush(commandstring);
			unsetChanges();
	}
}
/*-----------------------------------------------------------------------------*/
function deleteArticleComment()  /* comment articleid */
{
		var markup = "<h3>Permanently Remove This Comment?</h3>";
			markup += "<p>Are you sure you want to delete this comment?</p>";
			markup += "<p><strong>This action can NOT be undone.</strong></p>";
			markup += "<h3><a href=\"javascript:doDeleteArticleComment('"+arguments[0]+"','"+arguments[1]+"');\" title=\"\">";
			markup += "<img src=\"/api/icons/trash.png\" style=\"width:20px;border:0px;\">Delete Comment</a>";
			markup += "&nbsp;&nbsp;&nbsp;";
			markup += "<a href=\"javascript:hideModal();\" title=\"\">";
			markup += "<img src=\"/api/icons/cancel.png\" style=\"width:20px;border:0px;\">Cancel</a></h3>";
		showModal(markup,'Delete Comment?',330,150);
}
/*-----------------------------------------------------------------------------*/
function doDeleteArticleComment()  /* comment articleid */
{
		var commandstring = "command=deletearticlecomment";
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&comment="+arguments[0];
		commandstring += "&parent_id="+arguments[1];
		doPush(commandstring);
		hideModal();
}
/* PASSWORD FUNCTIONS ---------------------------------------------------------*/
function checkPasswordChange()
{
	var theForm = document.getElementById('passChangeForm');
	var errors = new Array();
	if(theForm.oldpassword.value == "")
		{ errors.push('Please type in your old password'); }
	if(theForm.newpassword.value.length <8 )
		{ errors.push('Please provide a longer password<br /> minimum 8 characters'); }
	if(theForm.newpassword.value != theForm.newpassword2.value)
		{ errors.push('New password fields to not match'); }


	if (errors.length > 0)
	{
		var theHeight = parseInt(80 + (errors.length * 20)); 
		
		var output = '<p>'+errors.join('</p><p>')+'</p>';
			output +='<p class=\"button110focus\" style=\"text-align:center;\"><a href="javascript:hideModal();">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
		showModal(output, 'Form Errors!', 300,theHeight);
	}
	else
	{
		var markup = "<h1>Confirm Password Change??</h1>";
			markup += "<p>Are you sure you want to change your password?</p>";
			markup += "<p class=\"button110focus\" style=\"margin-left:85px;float:left;\"><a href=\"javascript:hideModal();\" title=\"\">Cancel</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
			markup += "<p class=\"button110unfocus\" style=\"float:left;\"><a href=\"javascript:doChangePassword();\" title=\"\">Change</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
		showModal(markup,'Confirm Change',400,120);
	}
}
/*-----------------------------------------------------------------------------*/
function doChangePassword()
{
	var theForm = document.getElementById('passChangeForm');
	var commandstring  = "command=changepassword&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&profiletab=passchange";
				
		commandstring += "&oldpass="+theForm.oldpassword.value;
		commandstring += "&newpass="+theForm.newpassword.value;
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function checkEmailChange()
{
	var theForm = document.getElementById('emailChangeForm');
	var errors = new Array();
	if(!validemail.test(theForm.oldemail.value))
		{ errors.push('Please type in your current email address'); }
	if(!validemail.test(theForm.newemail.value) )
		{ errors.push('The new email address supplied is not valid'); }
	if(theForm.newemail.value != theForm.newemail2.value)
		{ errors.push('New email fields to not match'); }


	if (errors.length > 0)
	{
		var theHeight = parseInt(80 + (errors.length * 20)); 
		
		var output = '<p>'+errors.join('</p><p>')+'</p>';
			output +='<p class=\"button110focus\" style=\"text-align:center;\"><a href="javascript:hideModal();">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
		showModal(output, 'Form Errors!', 300,theHeight);
	}
	else
	{
		var markup = "<h1>Confirm Email Change?</h1>";
			markup += "<p>Are you sure you want to change your email address?</p>";
			markup += "<p><strong>Make sure your mailbox will accept the new password email!</strong></p>";
			markup += "<p class=\"button110focus\" style=\"margin-left:85px;float:left;\"><a href=\"javascript:hideModal();\" title=\"\">Cancel</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
			markup += "<p class=\"button110unfocus\" style=\"float:left;\"><a href=\"javascript:doChangeEmail();\" title=\"\">Delete</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
		showModal(markup,'Confirm Change',400,120);
	}
}
/*-----------------------------------------------------------------------------*/
function doChangeEmail()
{
	var theForm = document.getElementById('emailChangeForm');
	var commandstring  = "command=changeemail&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&profiletab=passchange";
				
		commandstring += "&oldemail="+theForm.oldemail.value;
		commandstring += "&newemail="+theForm.newemail.value;
		doPush(commandstring);
}
/* DIRECTORY FUNCTIONS --------------------------------------------------------*/
function userDirectory()
{
	showModal("<p>Loading....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>",'User Directory',800,590);
	var commandstring  = "command=directory&userid="+document.getElementById('dataForm').userid.value+"&currenttab="+document.getElementById('dataForm').currenttab.value;
	doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function directoryPage()
{
	if(arguments[0]) 
		document.getElementById('directoryFilterForm').first.value = arguments[0];
	if(arguments[1]) 
		document.getElementById('directoryFilterForm').country.value = arguments[1];
	var commandstring  = "command=directory&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&country="+document.getElementById('directoryFilterForm').country.value;
		commandstring += "&letter="+document.getElementById('directoryFilterForm').letter.value;
		commandstring += "&first="+document.getElementById('directoryFilterForm').first.value;
		commandstring += "&total="+document.getElementById('directoryFilterForm').total.value;
		commandstring += "&pagelength="+document.getElementById('directoryFilterForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function doDirectorySearch()
{
	document.getElementById('directoryFilterForm').first.value = 0;
	document.getElementById('directoryFilterForm').country.value = '';
	document.getElementById('directoryFilterForm').letter.value = '';
	var commandstring  = "command=directory&userid="+document.getElementById('dataForm').userid.value+"&currenttab="+document.getElementById('dataForm').currenttab.value+"&searchquery="+document.getElementById('directoryFilterForm').searchquery.value+"&country="+document.getElementById('directoryFilterForm').country.value+"&letter="+document.getElementById('directoryFilterForm').letter.value+"&first="+document.getElementById('directoryFilterForm').first.value+"&total="+document.getElementById('directoryFilterForm').total.value+"&pagelength="+document.getElementById('directoryFilterForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function moreDirectoryFriends()
{
	var theForm = document.getElementById('directoryFilterForm');
		theForm.friendsfirst.value = parseInt(parseInt(theForm.friendsfirst.value)+parseInt(theForm.friendspagelength.value));
	var commandstring  = "command=moredirectoryfriends&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&first="+theForm.friendsfirst.value+"&friendspagelength="+theForm.friendspagelength.value+"&id="+theForm.filter.value;
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function moreDirectoryBlogs()
{
	var theForm = document.getElementById('directoryFilterForm');
		theForm.blogfirst.value = parseInt(parseInt(theForm.blogfirst.value)+parseInt(theForm.blogpagelength.value));
	var commandstring  = "command=moredirectoryblogs&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&first="+theForm.blogfirst.value+"&blogpagelength="+theForm.blogpagelength.value+"&id="+theForm.filter.value;
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function showUser(){toggleTab('mybasho','directory','u'+arguments[0]);}
/*-----------------------------------------------------------------------------*/
function showDirectoryBlogItem(){toggleTab('mybasho','directory','u'+arguments[0]+'|tblogitems|i'+arguments[1]);}
/*-----------------------------------------------------------------------------*/
/* USER AND FRIENDS FUNCTIONS -------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
function friendsPage()
{
	if(arguments[0]) 
	{
		document.getElementById('friendsFilterForm').first.value = arguments[0];
		document.getElementById('friendsFilterForm').folder.value = '';
	}

	var commandstring  = "command=friendspage&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&folder="+document.getElementById('friendsFilterForm').folder.value;
		commandstring += "&first="+document.getElementById('friendsFilterForm').first.value;
		commandstring += "&total="+document.getElementById('friendsFilterForm').total.value;
		commandstring += "&pagelength="+document.getElementById('friendsFilterForm').pagelength.value;	
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function doUserSearch()
{
	var commandstring  = "command=friendssearch&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		commandstring += "&folder=search&searchquery="+document.getElementById('friendsSearchForm').friendQuery.value;
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function doFriendAction()
{
		var commandstring  = arguments[0];
		commandstring += "&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		if( document.getElementById('requestMessageForm') )
		{
			commandstring += "&requestmessage="+document.getElementById('requestMessageForm').requestmessage.value;
		}
		if( document.getElementById('dataForm').currenttab.value == 'friends')
		{
			commandstring += "&folder="+document.getElementById('friendsFilterForm').folder.value;
			commandstring += "&first="+document.getElementById('friendsFilterForm').first.value;
			commandstring += "&total="+document.getElementById('friendsFilterForm').total.value;
			commandstring += "&pagelength="+document.getElementById('friendsFilterForm').pagelength.value;	
		}
		doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function doFriendActionConfirm() /* message , commandstring */
{
	var output =  '<h2 class="thehighlight">Confirm Action!</h2><h4>'+arguments[0]+'</h4>';
	var theBoxHeight = 120;
	if(arguments[1].indexOf('requestfriend') >0)
	{
		output += '<form id="requestMessageForm"><p>Type an introductory message below to accompany your request. Max 150 chars.</p><textarea id="requestmessage"  onkeypress="return disableEnter(event);" onkeyup="limitFieldLength(\'requestmessage\',\'150\');" style="width:230px; height:75px; overflow-y:auto;"></textarea></form>';
		theBoxHeight = 250;
	}
	output += '<div style="width:280px;"><p class="button110unfocus" style="float:right;"><a href="javascript:doFriendAction(\''+arguments[1]+'\');hideModal();" title="Yes">Yes</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p class="button110focus" style="float:right;"><a href="javascript:hideModal();" title="Close">No</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></div>';
	showModal(output,'Confirm Action','300',theBoxHeight);
}
/*-----------------------------------------------------------------------------*/
function requestFriend()
{
	if(arguments[0]) 
		doFriendActionConfirm("Request the friendship of this person?","command=requestfriend&friendid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function doRequestSent()
{
	var output =  '<h1 style="clear:both; float:left;"><img src="/api/icons/ok.png" style="width:32px;height:32px;padding:0px 5px 0px 5px;vertical-align:middle;"/>Friendship Requested</h1>';
		output += '<h3 style="clear:both; padding:5px; height:50px;">Your request has been sent and awaits confirmation.</h3><h1><a href="javascript:hideModal();" title="Yes"><img src="/api/icons/ok.png" style="border:0px;"/>OK</a>';
	showModal(output,'Request Sent','250','180');
}
/*-----------------------------------------------------------------------------*/
function acceptFriendRequest()
{
	if(arguments[0]) 
		doFriendActionConfirm("Accept this friend request?","command=acceptfriend&requestid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function ignoreFriendRequest()
{
	if(arguments[0]) 
	doFriendActionConfirm("Ignore this friend request?","command=ignorefriend&requestid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function removeFriend()
{
	if(arguments[0]) 
		doFriendActionConfirm("Remove this friend from your list?","command=removefriend&friendid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function blockUser()
{
	if(arguments[0]) 
		doFriendActionConfirm("Block this person from seeing your profile?","command=blockfriend&blockid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function removeBlock()
{
	if(arguments[0]) 
		doFriendActionConfirm("Remove the block from this person?","command=removeblock&blockid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function showFriendRequests()
{
	document.getElementById('friendsFilterForm').first.value = 0;
	document.getElementById('friendsFilterForm').folder.value = 'requests';
	friendsPage(0);
}
/*-----------------------------------------------------------------------------*/
/* ITEM FUNCTIONS -------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
function confirmDelist() /* id, price */
{
	var markup = "<h1>Permanently Remove Item From Sale?</h1><p>Are you sure you want to de-list this item and remove it from sale?</p>";
		markup += "<h4>The fee for de-listing this item is <strong>"+arguments[1]+" GBP</strong>.</h4><p><strong>This action can NOT be undone</strong></p>";
		markup += "<h1><a href=\"javascript:doDelist('"+arguments[0]+"');\" title=\"\"><img src=\"/api/icons/trash.png\" style=\"width:20px;border:0px;\">De-list Item</a>&nbsp;&nbsp;&nbsp;";
		markup += "<a href=\"javascript:hideModal();\" title=\"\"><img src=\"/api/icons/cancel.png\" style=\"width:20px;border:0px;\">Cancel</a></h1>";
	showModal(markup,'De-list Item?',400,150);
	hideModalModal();
}
/*-----------------------------------------------------------------------------*/
function doDelist() /* id */
{
	var commandstring  = "command=delistitem&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0];
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
	doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function confirmBuy() /* id, price */
{
	var markup = "<h1>Buy This Item Now?</h1><p>Are you sure you want to buy this item from the seller?</p><p>By confirming this you will be agreeing to buy the item from the seller at the price offered.</p>";
		markup += "<h2><a href=\"javascript:doBuy('"+arguments[0]+"');\" title=\"\">";
		markup += "<img src=\"/api/icons/ok.png\" style=\"width:20px;border:0px;\">Buy This Item Now</a>&nbsp;&nbsp;&nbsp;";
		markup += "<a href=\"javascript:hideModalModal();\" title=\"\"><img src=\"/api/icons/cancel.png\" style=\"width:20px;border:0px;\">Cancel</a></h2>";
	showModalModal(markup,'Buy This Item?',300,150);
}
/*-----------------------------------------------------------------------------*/
function doBuy() /* id */
{
	var commandstring  = "command=buyitem&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0];
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
	switch(document.getElementById('dataForm').currenttab.value)
	{
		case 'community':
			commandstring += "&profiletab="+document.getElementById('blogCommunityPageForm').profiletab.value;
			commandstring += "&blogitem="+document.getElementById('blogCommunityPageForm').blogitem.value;
			commandstring += "&profile="+document.getElementById('blogCommunityPageForm').profile.value;
			commandstring += "&first="+document.getElementById('blogCommunityPageForm').first.value;
			commandstring += "&comments="+document.getElementById('blogCommunityPageForm').comments.value;
			commandstring += "&pagelength="+document.getElementById('blogCommunityPageForm').pagelength.value;	
			break;
		case 'marketplace':
			commandstring += "&"+getMarketPlaceFields('marketplaceFilterForm');	
			break;
		case 'buying':
			commandstring += "&folder="+document.getElementById('buyingFilterForm').folder.value;
			commandstring += "&first="+document.getElementById('buyingFilterForm').first.value;
			commandstring += "&total="+document.getElementById('buyingFilterForm').total.value;
			commandstring += "&pagelength="+document.getElementById('buyingFilterForm').pagelength.value;	
			break;
	}
	doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function confirmBid() /* id */
{
	doBid(arguments[0]);
	hideModalModal();
}
/*-----------------------------------------------------------------------------*/
function doBid() /* id */
{
	var commandstring  = "command=addbid&userid="+document.getElementById('dataForm').userid.value;
		commandstring += "&itemid="+arguments[0]+"&bid="+document.getElementById('bidForm').bid.value;
		commandstring += "&currenttab="+document.getElementById('dataForm').currenttab.value;
	switch(document.getElementById('dataForm').currenttab.value)
	{
		case 'community':
			commandstring += "&profiletab="+document.getElementById('blogCommunityPageForm').profiletab.value;
			commandstring += "&blogitem="+document.getElementById('blogCommunityPageForm').blogitem.value;
			commandstring += "&profile="+document.getElementById('blogCommunityPageForm').profile.value;
			commandstring += "&first="+document.getElementById('blogCommunityPageForm').first.value;
			commandstring += "&comments="+document.getElementById('blogCommunityPageForm').comments.value;
			commandstring += "&pagelength="+document.getElementById('blogCommunityPageForm').pagelength.value;	
			break;
		case 'marketplace':
			if(document.getElementById('marketplaceFilterForm'))
			commandstring += "&"+getMarketPlaceFields('marketplaceFilterForm');	
			break;
		case 'buying':
			commandstring += "&folder="+document.getElementById('buyingFilterForm').folder.value;
			commandstring += "&first="+document.getElementById('buyingFilterForm').first.value;
			commandstring += "&total="+document.getElementById('buyingFilterForm').total.value;
			commandstring += "&pagelength="+document.getElementById('buyingFilterForm').pagelength.value;	
			break;
	}
	doPush(commandstring);
}
/*-----------------------------------------------------------------------------*/
function showItem()
{
	if(arguments[0]) 
	{
		showModal("<p>Loading item....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>",'Viewing Item',800,610);
		doPush("command=showitem&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0]);
	}
}
/*-----------------------------------------------------------------------------*/
function addWatch()
{
	doPush("command=addwatch&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function unWatch()
{
	var output  = "command=unwatch&userid="+document.getElementById('dataForm').userid.value;
		output += "&itemid="+arguments[0]+"&folder="+arguments[1];
		
		output += "&currenttab="+document.getElementById('dataForm').currenttab.value;
		output += "&first="+document.getElementById('buyingFilterForm').first.value;
		output += "&total="+document.getElementById('buyingFilterForm').total.value;
		output += "&pagelength="+document.getElementById('buyingFilterForm').pagelength.value;
		doPush(output);
}
/*-----------------------------------------------------------------------------*/
function toggleItemImage()
{
	var theUrl = "/api/thumbnail.php?w=480&h=320&img="+arguments[0];
	
	document.getElementById('mainItemPopupImage').src = theUrl;
}
/*-----------------------------------------------------------------------------*/
/* QUESTIONS FUNCTIONS --------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
function showAskQuestion()
{
	doPush("command=askbox&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function doAskQuestion()
{
	if(document.getElementById('askQuestionForm').theQuestion.value.length > 10)
	{
		var output  = "command=askquestion&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0];
			output += "&question="+escape(document.getElementById('askQuestionForm').theQuestion.value);
			doPush(output);
	}
	else
	{
		var markup = "<h1>Form Error</h1><p><strong>Please type a more detailed question.</strong></p><br /><br /><h2><a href=\"javascript:hideModal('modalModal');\" title=\"\">Close</a></h2>";
		showModal(markup,'Error',300,200,'','modalModal');
	}
}
/*-----------------------------------------------------------------------------*/
function showQuestion()
{
	var markup = "<p>Loading question....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
	showModal(markup,'Viewing Question',800,600);
	var output  = "command=showquestion&userid="+document.getElementById('dataForm').userid.value+"&questionid="+arguments[0];
		doPush(output);
}
/*-----------------------------------------------------------------------------*/
function doAnswerQuestion()
{
	if(document.getElementById('answerQuestionForm').theAnswer.value.length > 10)
	{
	var output  = "command=answerquestion&userid="+document.getElementById('dataForm').userid.value+"&questionid="+arguments[0];
		output += "&answer="+escape(document.getElementById('answerQuestionForm').theAnswer.value);
		doPush(output);
	}
	else
	{
		var markup = "<h1>Form Error</h1><p><strong>Please type a more detailed answer.</strong></p><br /><br /><h2><a href=\"javascript:hideModalModal();\" title=\"\">Close</a></h2>";
		showModalModal(markup,'Error',300,200);
	}
}
/*-----------------------------------------------------------------------------*/
function doUpdateQuestions()
{
	var output  = "command=updatequestionlist&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0];
		doPush(output);
}
/*-----------------------------------------------------------------------------*/
/*-- VIEWINGS FUNCTIONS -------------------------------------------------------*/
function showAskViewing()
{
	doPush("command=viewingbox&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0]);
}
/*-----------------------------------------------------------------------------*/
function showViewing()
{
	var markup = "<p>Loading....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
	showModal(markup,'Viewing Request',800,600);
	var output  = "command=showviewing&userid="+document.getElementById('dataForm').userid.value+"&viewingid="+arguments[0];
		doPush(output);
}
/*-----------------------------------------------------------------------------*/
function doUpdateViewing()
{
	var output  = "command=updateviewinglist&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0];
		doPush(output);
}
/*-----------------------------------------------------------------------------*/
function doAskViewing()
{
	if(document.getElementById('askViewingForm').message.value.length > 10)
	{
	var output  = "command=askviewing&userid="+document.getElementById('dataForm').userid.value+"&itemid="+arguments[0];
		output += "&message="+escape(document.getElementById('askViewingForm').message.value);
		doPush(output);
	}
	else
	{
		var markup = "<h1>Form Error</h1><p><strong>Please type a question.</strong></p><br /><br /><h2><a href=\"javascript:hideModalModal();\" title=\"\">Close</a></h2>";
		showModalModal(markup,'Error',300,200);
	}
}
/*-----------------------------------------------------------------------------*/
function doReplyViewing()
{
	if(document.getElementById('viewingReplyForm').message.value.length > 2)
	{
	var output  = "command=replyviewing&userid="+document.getElementById('dataForm').userid.value;
		output += "&message="+escape(document.getElementById('viewingReplyForm').message.value);
		output += "&sender="+escape(document.getElementById('viewingReplyForm').sender.value);
		output += "&recipient="+escape(document.getElementById('viewingReplyForm').recipient.value);
		output += "&item="+escape(document.getElementById('viewingReplyForm').itemid.value);
		doPush(output);
	}
	else
	{
		var markup = "<h1>Form Error</h1><p><strong>Please type a more detailed message.</strong></p><br /><br /><h2><a href=\"javascript:hideModalModal();\" title=\"\">Close</a></h2>";
		showModalModal(markup,'Error',300,200);
	}
}
/*-----------------------------------------------------------------------------*/
/* REGISTER FUNCTIONS ---------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
function checkRegister()
{
	var errors = new Array();
	var theForm = document.getElementById('registerForm');
	if(theForm.username.value == "") 							{ errors.push('Please type your chosen username'); }
	if(!validemail.test(theForm.email.value)) 					{ errors.push('Please provide a valid email address'); }
	if(theForm.email.value != theForm.email2.value ) 			{ errors.push('The two email addresses do not match'); }
	if(theForm.country.value <1 ) 								{ errors.push('Please choose your country from the list'); }
	if(theForm.country.value >0 && theForm.region.value <1 ) 	{ errors.push('Please choose your region from the list'); }
	if(!theForm.agreeterms.checked) 							{ errors.push('Please agree to the Terms of Use'); }
	if (errors.length > 0)
		showModal('<br /><p>'+errors.join('</p><p>')+'</p><button onclick="hideModal();">OK</button>', 'Form Errors!', 250,180);
	else
	{
		showModal('<br /><br /><p>Processing Registration Please Wait...</p><img src="/micromarket/console/images/ajax-bar.gif" alt="checking" />', 'Contacting Server...', 250,150);
		setTimeout("doRegister()",250);
	}
}
/*-----------------------------------------------------------------------------*/
function doRegister()
{
	var theForm = document.getElementById('registerForm');
	var dataString = "command=register&email="+theForm.email.value+"&username="+theForm.username.value+"&country="+theForm.country.value+"&region="+theForm.region.value;
	doPush(dataString);
}
/*-----------------------------------------------------------------------------*/
/* LOGIN FUNCTIONS ------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
function checkLogin()
{
	var errors = new Array();
	if(document.getElementById('loginForm').email.value == ""){ errors.push('Please type your username or email address'); }
	if(document.getElementById('loginForm').password.value == "" ){ errors.push('Please provide a password'); }

	if (errors.length > 0)
		showModal('<br /><p>'+errors.join('</p><p>')+'</p><button onclick="hideModal();">OK</button>', 'Form Errors!', 270,120);
	else
	{
		showModal('<br /><br /><p>Checking Login Please Wait...</p><img src="/micromarket/console/images/ajax-bar.gif" alt="checking" />', 'Contacting Server...', 250,150);
		setTimeout("doLogin()",250);
	}
}
/*-----------------------------------------------------------------------------*/
function doLogin()
{
	var rem = "";
	if(document.getElementById('loginForm').remember.checked == true ){ rem = "&remember=1"; }
	doPush("command=checklogin&email="+document.getElementById('loginForm').email.value+"&password="+document.getElementById('loginForm').password.value+rem);
	setTimeout("hideModal()",1500);
}
/*-----------------------------------------------------------------------------*/
function checkForgot()
{
	var errors = new Array();
	if(!validemail.test(document.getElementById('loginForm').email.value)){ errors.push('Invalid email address'); }

	if (errors.length > 0)
		showModal('<br /><br /><p>'+errors.join('</p><p>')+'</p><button onclick="hideModal();">OK</button>', 'Form Error!', 250,150);
	else
	{
		showModal('<br /><br /><p>Checking Email Please Wait...</p><img src="/micromarket/console/images/ajax-bar.gif" alt="checking" />', 'Contacting Server...', 250,150);
		setTimeout("doForgot()",250);
	}
}
/*-----------------------------------------------------------------------------*/
function doForgot()
{
	doPush("command=resetpassword&email="+document.getElementById('loginForm').email.value);
	setTimeout("hideModal()",1500);
}
function showLoginModal()
{
	showModal('<p>Please respond to the welcome screen popup before continuing</p>','Check the Welcome Screen First','250','80','none','modal');
}
function doLogout()
{
	var output = "<p>Are you sure you want to log out?</p>";
		output +='<p class=\"button110focus\" style=\"margin-left:20px;float:left;\"><a href="javascript:hideModal(\'modalModal\');">No</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p class=\"button110unfocus\" style=\"float:left;\"><a href="javascript:logOut();">Yes</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>';
	showModalModal(output,'Log Out?',280,120);
}
function logOut()
{
	window.location = "/micromarket/console/logout.php";
}
/*-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
function linkShare() /* url, title */
{
	var markup = "<br /><iframe src =\"/micromarket/console/linkshare.php?url="+arguments[0]+"&title="+escape(arguments[1])+"\" width=\"600\" height=\"430\" style=\"border:0px;\"></iframe>";
	showModalModal(markup,'Share Link',640,480);
}
/*-----------------------------------------------------------------------------*/
function showTerms() /* */
{
	var markup = "<br /><iframe src =\"/micromarket/terms.html\" width=\"600\" height=\"400\"></iframe><p class=\"button110focus\" style=\"float:right; text-align:center;\"><a href=\"javascript:hideModal();\" title=\"\">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
	showModal(markup,'Terms and Conditions',640,480);
	hideModalModal();
}
/*-----------------------------------------------------------------------------*/
function showCommunityGuide() /*  */
{
	var markup = "<br /><iframe src =\"/micromarket/community.html\" width=\"600\" height=\"400\"></iframe><p class=\"button110focus\" style=\"float:right; text-align:center;\"><a href=\"javascript:hideModal();\" title=\"\">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
	showModal(markup,'Community Guide',640,480);
	hideModalModal();
}
/*-----------------------------------------------------------------------------*/
function showMarketplaceGuide() /*  */
{
	var markup = "<br /><iframe src =\"/micromarket/marketplace.html\" width=\"600\" height=\"400\"></iframe><p class=\"button110focus\" style=\"float:right; text-align:center;\"><a href=\"javascript:hideModal();\" title=\"\">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";
	showModal(markup,'Marketplace Guide',640,480);
	hideModalModal();
}
/*-----------------------------------------------------------------------------*/
function showPayment() /* payment id */
{
	if(arguments[0]) 
	{
		showModal("<p>Loading item....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>",'Viewing Payment Details',800,500);
		var output  = "command=showpayment&userid="+document.getElementById('dataForm').userid.value+"&paymentid="+arguments[0];
		doPush(output);
	}
}
/*-----------------------------------------------------------------------------*/
function printReceipt()
{
	window.open('/micromarket/console/templates/popup_receipt.html','reportwin','left=20,top=20,width=960,height=500,toolbar=0,location=0,status=0,menubar=1,resizable=1,scrollbars=1');
}
/*-----------------------------------------------------------------------------*/
function paymentWindow() /* */
{
/*
// EMAIL PAYMENT NOTIFICATION MARKUP
	var markup = "<p>Loading wizard....</p>";
		markup += "<p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>";
	showModal(markup,'Make Payment',800,540);
	var commandstring = "";
		commandstring += 'command=';
		commandstring += '&userid='+document.getElementById('dataForm').userid.value;
		commandstring += '&session='+document.getElementById('dataForm').session.value;
		doPaymentPush(commandstring);

// WORLDPAY MARKUP
		var markup = "<iframe id=\"uploadFrame\" name=\"uploadFrame\" style=\"width:790px;height:480px;float:right;\" ";
			markup += " src=\"/micromarket/console/wppayment.php?&userid="+document.getElementById('dataForm').userid.value+"\" scrolling=\"yes\"></iframe>";
			markup += "<h3><a href=\"javascript:hideModal();toggleTab('marketplace','account');\" title=\"\">Close</a></h3>";
	showModal(markup,'Make Payment',800,540);
*/
		var url = "/micromarket/console/pppayment.php?&userid="+document.getElementById('dataForm').userid.value;
		window.open(url,'paymentFrame','width=960,height=540,scrollbars=yes,toolbar=no,location=yes,directories=no,menubar=no,copyhistory=no');
		hideModal();
}
/*-----------------------------------------------------------------------------*/
function doPaymentStage() /* */
{
	var commandstring = "";
	if(document.getElementById('paymentForm'))
	{
		var errors = Array();
		var payform   = document.getElementById('paymentForm');
		commandstring += 'command='+payform.command.value;
		commandstring += '&userid='+document.getElementById('dataForm').userid.value;
		commandstring += '&session='+document.getElementById('dataForm').session.value;
		if(payform.command.value == 'senddetails')
		{
			commandstring += '&fname='+payform.title.value+'&lname='+payform.desc.value+'&country='+payform.country.value+'&address1='+payform.address1.value;
			commandstring += '&address2='+payform.address2.value+'&address3='+payform.address3.value+'&address4='+payform.address4.value+'&region='+payform.region.value;
			commandstring += '&postcode='+payform.postcode.value+'&tel='+payform.tel.value+'&mob='+payform.mob.value+'&total='+payform.total.value;
			commandstring += '&fees='+payform.fees.value;
			if(!validname.test(payform.title.value)) { errors.push('Invalid first name'); }
			if(!validaddress.test(payform.desc.value)) { errors.push('Invalid last name'); }
			if(payform.country.value < 1) { errors.push('Please select your country'); }
			if(!validaddress.test(payform.address1.value)) { errors.push('Invalid first line of address'); }
			if(!validaddress.test(payform.address2.value) && payform.address2.value != "") { errors.push('Invalid second line of address'); }
			if(!validaddress.test(payform.address3.value) && payform.address3.value != "") { errors.push('Invalid third line of address'); }
			if(!validaddress.test(payform.address4.value) && payform.address4.value != "") { errors.push('Invalid fourth line of address'); }
			if(payform.region.value < 1) { errors.push('Please select your region'); }
			if(!validpostcode.test(payform.postcode.value)) { errors.push('Invalid postcode, letters numbers and spaces only'); }
			if(!validphone.test(payform.tel.value)) { errors.push('Invalid phone number, numbers and spaces only'); }
			if(!validphone.test(payform.mob.value) && payform.mob.value != "") { errors.push('Invalid mobile number, numbers and spaces only'); }
			if(!payform.invoiceConfirm.checked) { errors.push('Please tick the confirmation box'); }
		}
		if (errors.length > 0)
		{
			var theHeight = parseInt(60 + (errors.length * 20)); 
			showModalModal('<p>'+errors.join('</p><p>')+'</p><button onclick="hideModalModal();">OK</button>', 'Form Errors!', 350,theHeight);
		}
		else
			doPaymentPush(commandstring);
	}
}
/*-----------------------------------------------------------------------------*/
function showMembershipOptions()
{
	showModal("<p>Loading wizard....</p><p><a href=\"javascript:hideModal();\" title=\"\">Close</a></p>",'Membership Wizard',860,500);
	doPush("command=domembership&userid="+document.getElementById('dataForm').userid.value);
}
/*-----------------------------------------------------------------------------*/
function addMembership()
{
	if(document.getElementById('check'+arguments[0]).checked == true)
	{
		var url = "/micromarket/console/ppmembership.php?&userid="+document.getElementById('dataForm').userid.value+"&memid="+arguments[0];
		window.open(url,'membershipFrame','width=960,height=540,scrollbars=yes,toolbar=no,location=yes,directories=no,menubar=no,copyhistory=no');
		hideModal();
	}
	else
		showModalModal('<br /><p>Please click the confirmation checkbox</p><br /><p class="button110focus" style="margin-left:30px; text-align:center;"><a href="javascript:hideModalModal();">OK</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>', 'Please Confirm!', 240,130);
}
/*-----------------------------------------------------------------------------*/
function paypalSeller()
{
	if(parseInt(arguments[0]) >0)
	{
		var url = "/micromarket/console/ppseller.php?userid="+document.getElementById('dataForm').userid.value+"&saleid="+arguments[0];
		window.open(url,'paypalsellerFrame','width=960,height=540,scrollbars=yes,toolbar=no,location=yes,directories=no,menubar=no,copyhistory=no');
	}
}
/*-----------------------------------------------------------------------------*/
/* GENERAL FUNCTIONS ----------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
function doBrowser()
{
	var url = 'http://www.google.com';
	if(arguments[0]) url = arguments[0];
	
	var timeStamp = new Date().getTime();
	url = url + '?' + timeStamp;
	var w = getAvailWidth() - 40;
	if(arguments[1]) w = arguments[1];
	var h = getAvailHeight() - 60;
	if(arguments[2]) h = arguments[2];
	var output = "<iframe style=\"width:"+ (w-5) +"px; height:"+ (h-22) +"px; padding:0px; margin:0px;\" src=\""+url+"\"></iframe>";
	showModal(output,'Live Site Browser',w,h);
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
/*-----------------------------------------------------------------------------*/
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
/*-----------------------------------------------------------------------------*/
function limitFieldLength() /*field id, length */
{
	var theField = document.getElementById(arguments[0]);
	var theLength = parseFloat(arguments[1]);
	var theValue = theField.value;
	if(theField.value.length > theLength)
		theField.value = theValue.substring(0,theLength);
}
/*-----------------------------------------------------------------------------*/
function disableEnter(e)
{
     var key;
	 if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
     return (key != 13);
}
/*-----------------------------------------------------------------------------*/
function enableEnterSubmit(e,f)
{
     var key;
	 if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
     if(key == 13)
	 eval(f);
}
/*-----------------------------------------------------------------------------*/
function doClearField(field) /* id */
{
	document.getElementById(field).value = "";
	document.getElementById(field).onchange();
}
/*-----------------------------------------------------------------------------*/
function setChanges()
{
	if(document.getElementById('changes'))
		document.getElementById('changes').value = 1;
}
/*-----------------------------------------------------------------------------*/
function unsetChanges()
{
	if(document.getElementById('changes'))
		document.getElementById('changes').value = 0;
}
/*-----------------------------------------------------------------------------*/
function AttachEvent(obj,evt,fnc,useCapture)
{
	if (!useCapture) useCapture=false;
	if (obj.addEventListener)
	{
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} 
	else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	else
	{
		MyAttachEvent(obj,evt,fnc);
		obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
	}
} 
/*-----------------------------------------------------------------------------*/
	function MyAttachEvent(obj,evt,fnc)
	{
		if (!obj.myEvents) obj.myEvents={};
		if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
		var evts = obj.myEvents[evt];
		evts[evts.length]=fnc;
	}
/*-----------------------------------------------------------------------------*/
	function MyFireEvent(obj,evt)
	{
		if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
		var evts = obj.myEvents[evt];
		for (var i=0,len=evts.length;i<len;i++) evts[i]();
	}
/*-----------------------------------------------------------------------------*/
function getAvailWidth() 
{
	var width = 0;
	if( document.documentElement && document.documentElement.clientWidth ) 
		width = document.documentElement.clientWidth;
	else if( document.body && document.body.clientWidth ) 
		width = document.body.clientWidth;
	else if( window.innerWidth ) 
		width = window.innerWidth - 18;
	return width;
}
/*-----------------------------------------------------------------------------*/
function getAvailHeight() 
{
	var height = 0;
	if( document.documentElement && document.documentElement.clientHeight ) 
		height = document.documentElement.clientHeight;
	else if( document.body && document.body.clientHeight ) 
		height = document.body.clientHeight;
	else if( window.innerHeight ) 
		height = window.innerHeight - 18;
	return height;
}
/*-----------------------------------------------------------------------------*/
function getScrollX() 
{
	var scrollX = 0;
	if( document.documentElement && document.documentElement.scrollLeft ) 
		scrollX = document.documentElement.scrollLeft;
	else if( document.body && document.body.scrollLeft ) 
		scrollX = document.body.scrollLeft;
	else if( window.pageXOffset ) 
		scrollX = window.pageXOffset;
	else if( window.scrollX ) 
		scrollX = window.scrollX;
	return scrollX;
}
/*-----------------------------------------------------------------------------*/
function getScrollY() 
{
	var scrollY = 0;
	if( document.documentElement && document.documentElement.scrollTop )
		scrollY = document.documentElement.scrollTop;
	else if( document.body && document.body.scrollTop )
		scrollY = document.body.scrollTop;
	else if( window.pageYOffset )
		scrollY = window.pageYOffset;
	else if( window.scrollY ) 
		scrollY = window.scrollY;
	return scrollY;
}
/*-----------------------------------------------------------------------------*/
/* MODAL DIALOGUE FUNCTIONS		                                               */
/*-----------------------------------------------------------------------------*/
function positionModal(m)
{
	if (!m) m = 'modal';
	var availWidth = getAvailWidth();
	var availHeight = getAvailHeight();
	var scrollX = getScrollX();
	var scrollY = getScrollY();
	var modalScreen  = document.getElementById(m+'Screen');
	var modalWindow    = document.getElementById(m+'Window');
	var w = modalWindow.style.width.replace(/px/,"");
	var h = modalWindow.style.height.replace(/px/,"");
	modalScreen.style.width = (availWidth + scrollX) + 'px';
	modalScreen.style.height = (availHeight + scrollY) + 'px';
	modalWindow.style.marginLeft = (((availWidth - w)/2) + scrollX) + 'px';
	modalWindow.style.marginTop = (((availHeight - h)/2 ) + scrollY) + 'px';
}
/*-----------------------------------------------------------------------------*/
function positionModalModal()
{
	positionModal('modalModal');
}
/*-----------------------------------------------------------------------------*/
function showModal(msg,title,w,h,btn,m)
{
	if(!m) m = 'modal';
	if(m == 'modal') //hide form fields
	{
		// HIDE ALL OBJECT TAGS
		var theObjects = document.getElementsByTagName("object");
		for(var i=0;i<theObjects.length;i++) { theObjects[i].style.display = 'none'; }
		// HIDE ALL EMBED TAGS
		var theEmbeds = document.getElementsByTagName("embed");
		for(var i=0;i<theEmbeds.length;i++) { theEmbeds[i].style.display = 'none'; }
		// HIDE ALL SELECT TAGS
		var theElements = document.getElementsByTagName("select");
		for(var i=0;i<theElements.length;i++) { theElements[i].style.display = 'none'; }
		//show modal form fields
		if(document.getElementById('screenForm'))
		{
			var modalElements = document.getElementById('screenForm').elements;
			for(var i=0;i<modalElements.length;i++) { if(modalElements[i].tagName == "SELECT") {modalElements[i].style.display = 'inline'; } }
		}
	}
	if (!title) title = 'Attention!';
	if (!w) w = 300;
	if (!h) h = 200;
	if (!btn) btn = 'close';
	var modalScreen  = document.getElementById(m+'Screen');
	var modalWindow  = document.getElementById(m+'Window');
	var modalButtons = document.getElementById(m+'Buttons');
	var controlButtons = new Array();
	var btns = btn.split(",");
	for(var a=0; a<btns.length; a++)
	{
		switch(btns[a])
		{
			case 'close':
				controlButtons.push('<a href="javascript:hideModal(\''+m+'\');">X</a>');
				break;
		}
	}
	modalWindow.style.width = w + 'px';
	modalWindow.style.height = h + 'px';
	positionModal(m);
	document.getElementById(m+'Title').innerHTML = title;
	document.getElementById(m+'Content').innerHTML = msg;
	modalButtons.innerHTML = "";
	for(var i=0; i<controlButtons.length; i++) modalButtons.innerHTML += controlButtons[i];
	modalScreen.style.display = 'block';
	modalWindow.style.display = 'block';
}
/*-----------------------------------------------------------------------------*/
function showModalModal(msg,title,w,h,btn)
{
	if (!title) title = 'Attention!';
	if (!w) w = 300;
	if (!h) h = 200;
	if (!btn) btn = 'close';
	showModal(msg,title,w,h,btn,'modalModal');
}
/*-----------------------------------------------------------------------------*/
function resizeModal(w,h,m)
{
	if (!w) w = 300;
	if (!h) h = 200;
	if (!m) m = 'modal';
	var modalScreen  = document.getElementById(m+'Screen');
	var modalWindow  = document.getElementById(m+'Window');
	modalWindow.style.width = w + 'px';
	modalWindow.style.height = h + 'px';
	positionModal(m);
	modalScreen.style.display = 'block';
	modalWindow.style.display = 'block';
}
/*-----------------------------------------------------------------------------*/
function resizeModalModal(w,h)
{
	if (!w) w = 300;
	if (!h) h = 200;
	resizeModal(w,h,'modalModal');
}
/*-----------------------------------------------------------------------------*/
function hideModal(m)
{
	if (!m) m = 'modal';
	if(m == 'modal') 
	{
		//show form fields
		var theElements = document.getElementsByTagName("select");
		for(var i=0;i<theElements.length;i++) { theElements[i].style.display = 'inline'; }
		// SHOW OBJECT TAGS
		var theObjects = document.getElementsByTagName("object");
		for(var i=0;i<theObjects.length;i++) { theObjects[i].style.display = 'inline'; }
		// SHOW ALL EMBED TAGS
		var theEmbeds = document.getElementsByTagName("embed");
		for(var i=0;i<theEmbeds.length;i++) { theEmbeds[i].style.display = 'inline'; }
	}
	document.getElementById(m+'Screen').style.display = 'none';
	document.getElementById(m+'Window').style.display = 'none';
	document.getElementById(m+'Content').innerHTML = '';
}
/*-----------------------------------------------------------------------------*/
function hideModalModal()
{
	hideModal('modalModal');
}
/*-----------------------------------------------------------------------------*/
function updateModal()
{
	/* do it twice to stop the scrollbars screwing up the screen width */
	positionModal('modal');
	positionModal('modal');
	if(document.getElementById('modalModalScreen').display == 'block')
		positionModalModal('modalModal');
}
/*-----------------------------------------------------------------------------*/
/* AJAX FUNCTIONS -------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
function makeAJAX()
{
	this.ajaxRequest;
	try 
	{
		this.ajaxRequest = new XMLHttpRequest();
		if (this.ajaxRequest.overrideMimeType) 
		{
			this.ajaxRequest.overrideMimeType('text/xml');
		}
	} 
	catch (trymicrosoft) 
	{
		try 
		{
			this.ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (othermicrosoft) 
		{
			try 
			{
				this.ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (failed) 
			{
				this.ajaxRequest = false;
			}
		}
	}
	
	if (!this.ajaxRequest)
	alert("Error initializing XMLHttpRequest!");
	return this.ajaxRequest;
}
/*-----------------------------------------------------------------------------*/
function doPush()
{
	var url = "/micromarket/console/ajax.php";
	
	if(document.getElementById('dataForm').session)
		arguments[0] += "&session="+document.getElementById('dataForm').session.value;
		
	var postvars = 'data='+escape(arguments[0]);
	
		ajaxRequest.open("POST", url, true);
		ajaxRequest.onreadystatechange = updatePage;
		ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxRequest.setRequestHeader("Content-length", postvars.length);
		ajaxRequest.setRequestHeader("Connection", "close");
		ajaxRequest.send(postvars);
}
/*-----------------------------------------------------------------------------*/
function updatePage()
{
	if (ajaxRequest.readyState == 4) 
	{
		if (ajaxRequest.status == 200) 
		{
			var output = ajaxRequest.responseText;
			// pull out the displayed content
			var xhtmlstart = output.search(/<xhtml>/);
			var xhtmlend = output.search(/<\/xhtml>/);
			if(xhtmlstart != -1)
			{
				var thexhtml = output.substring((xhtmlstart + 7) ,xhtmlend);
				// pull out the element id to update
				var theElement = "";
				var elementstart = output.search(/<element>/);
				var elementend = output.search(/<\/element>/);
				if(elementstart != -1)
					theElement = output.substring((elementstart + 9) ,elementend);
				if(theElement.length == 0)
					theElement = 'screenContent';
				if(document.getElementById(theElement))
					document.getElementById(theElement).innerHTML = unescape(thexhtml);
				
				// pull out initialised script calls
				var jsstart = output.search(/<script>/);
				var jsend = output.search(/<\/script>/);
				if(jsstart != -1)
				{
					var thescript = output.substring((jsstart + 8) ,jsend);
					eval(unescape(thescript));
				}
			}
		} 
		// SHOW ERROR HERE
	}
	// SHOW ANIMATION
}
/*-----------------------------------------------------------------------------*/
function doScreenNag()
{
	var url = "/micromarket/console/ajaxscreennag.php";
	var postvars = 'data='+escape(arguments[0]);
	ajaxScreenNagRequest.open("POST", url, true);
	ajaxScreenNagRequest.onreadystatechange = updateScreenNag;
	ajaxScreenNagRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxScreenNagRequest.setRequestHeader("Content-length", postvars.length);
	ajaxScreenNagRequest.setRequestHeader("Connection", "close");
	ajaxScreenNagRequest.send(postvars);  
}
/*-----------------------------------------------------------------------------*/
function updateScreenNag()
{
	if (ajaxScreenNagRequest.readyState == 4) 
	{
		if (ajaxScreenNagRequest.status == 200) 
		{
			var output = ajaxScreenNagRequest.responseText;
			// pull out the displayed content
			var xhtmlstart = output.search(/<xhtml>/);
			var xhtmlend = output.search(/<\/xhtml>/);
			if(xhtmlstart != -1)
			{
				var thexhtml = output.substring((xhtmlstart + 7) ,xhtmlend);
				// pull out the element id to update
				var theElement = "";
				var elementstart = output.search(/<element>/);
				var elementend = output.search(/<\/element>/);
				if(elementstart != -1)
					theElement = output.substring((elementstart + 9) ,elementend);
				if(theElement.length == 0)
					theElement = 'screenContent';
				if(document.getElementById(theElement))
					document.getElementById(theElement).innerHTML = unescape(thexhtml);
				
				// pull out initialised script calls
				var jsstart = output.search(/<script>/);
				var jsend = output.search(/<\/script>/);
				if(jsstart != -1)
				{
					var thescript = output.substring((jsstart + 8) ,jsend);
					eval(unescape(thescript));
				}
			}
		} 
		// SHOW ERROR HERE
	}
	// SHOW ANIMATION
}
/*-----------------------------------------------------------------------------*/
function doWizardPush()
{
	var url = "/micromarket/console/ajaxwizard.php";
	var postvars = 'data='+escape(arguments[0]);
	ajaxWizardRequest.open("POST", url, true);
	ajaxWizardRequest.onreadystatechange = updateWizard;
	ajaxWizardRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxWizardRequest.setRequestHeader("Content-length", postvars.length);
	ajaxWizardRequest.setRequestHeader("Connection", "close");
	ajaxWizardRequest.send(postvars);  
}
/*-----------------------------------------------------------------------------*/
function updateWizard()
{
	if (ajaxWizardRequest.readyState == 4) 
	{
		if (ajaxWizardRequest.status == 200) 
		{
			var output = ajaxWizardRequest.responseText;
			// pull out the displayed content
			var xhtmlstart = output.search(/<xhtml>/);
			var xhtmlend = output.search(/<\/xhtml>/);
			if(xhtmlstart != -1)
			{
				var thexhtml = output.substring((xhtmlstart + 7) ,xhtmlend);
				// pull out the element id to update
				var theElement = "";
				var elementstart = output.search(/<element>/);
				var elementend = output.search(/<\/element>/);
				if(elementstart != -1)
					theElement = output.substring((elementstart + 9) ,elementend);
				if(theElement.length == 0)
					theElement = 'screenContent';
				if(document.getElementById(theElement))
					document.getElementById(theElement).innerHTML = unescape(thexhtml);
				
				// pull out initialised script calls
				var jsstart = output.search(/<script>/);
				var jsend = output.search(/<\/script>/);
				if(jsstart != -1)
				{
					var thescript = output.substring((jsstart + 8) ,jsend);
					eval(unescape(thescript));
				}
			}
		} 
		// SHOW ERROR HERE
	}
	// SHOW ANIMATION
}
/*-----------------------------------------------------------------------------*/
function doPaymentPush()
{
	var url = "/micromarket/console/ajaxpayment.php";
	var postvars = 'data='+escape(arguments[0]);
	ajaxPaymentRequest.open("POST", url, true);
	ajaxPaymentRequest.onreadystatechange = updatePayment;
	ajaxPaymentRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxPaymentRequest.setRequestHeader("Content-length", postvars.length);
	ajaxPaymentRequest.setRequestHeader("Connection", "close");
	ajaxPaymentRequest.send(postvars);  
}
/*-----------------------------------------------------------------------------*/
function updatePayment()
{
	if (ajaxPaymentRequest.readyState == 4) 
	{
		if (ajaxPaymentRequest.status == 200) 
		{
			var output = ajaxPaymentRequest.responseText;
			// pull out the displayed content
			var xhtmlstart = output.search(/<xhtml>/);
			var xhtmlend = output.search(/<\/xhtml>/);
			if(xhtmlstart != -1)
			{
				var thexhtml = output.substring((xhtmlstart + 7) ,xhtmlend);
				// pull out the element id to update
				var theElement = "";
				var elementstart = output.search(/<element>/);
				var elementend = output.search(/<\/element>/);
				if(elementstart != -1)
					theElement = output.substring((elementstart + 9) ,elementend);
				if(theElement.length == 0)
					theElement = 'screenContent';
				if(document.getElementById(theElement))
					document.getElementById(theElement).innerHTML = unescape(thexhtml);
				
				// pull out initialised script calls
				var jsstart = output.search(/<script>/);
				var jsend = output.search(/<\/script>/);
				if(jsstart != -1)
				{
					var thescript = output.substring((jsstart + 8) ,jsend);
					eval(unescape(thescript));
				}
			}
		} 
		// SHOW ERROR HERE
	}
	// SHOW ANIMATION
}
/*-----------------------------------------------------------------------------*/
function init()
{
	ajaxRequest = new makeAJAX();
	ajaxScreenNagRequest = new makeAJAX();
	ajaxWizardRequest = new makeAJAX();
	ajaxPaymentRequest = new makeAJAX();
	AttachEvent(window,'scroll',updateModal,false);
	AttachEvent(window,'resize',updateModal,false);
	var nagger=self.setInterval("doNag()",1000);
	if(window.location.hash.length>1)
	{
		var parts = window.location.hash.split('/');
			toggleTab(parts[1],parts[2],parts[3]);
	}
	else if(document.getElementById('dataForm'))
	toggleTab('summary');
}
/*-----------------------------------------------------------------------------*/
var backArray = new Array();
var forwardArray = new Array();
window.onload = init;
