var updater;
function login(msie)
{
	Modalbox.show('login.ninja', {title: 'Please sign in', width: (msie?280:250)});
}
function join()
{
	Modalbox.show('qsignup.ninja', {title: 'Please enter your email', width: 250});
}
function startUpl()
{
	Element.show('status');
	$('errors').innerHTML = '';
	updater = new Ajax.PeriodicalUpdater(
        'status',
        '/uploadStatus.ninja',
        {evalScripts: true, asynchronous:true, frequency:1, method:'post', onSuccess: function(){Element.hide('upDiv');}});
	$('upForm').submit();
}
function addToCart(p, s, q)
{
	new Ajax.Updater('cart', 'addtocart.ninja?p='+p+'&s='+s+'&q='+q, {evalScripts: true, asynchronous:true, method:'get', onSuccess: function()
	{
		Modalbox.show('confcheck.ninja', {title: 'Finished?', width: 250, height: 200});
		Effect.Appear('cart');Effect.Appear('checkout');Element.hide('tagsR');
	}});
}
function removeFromCart(p, s)
{
	new Ajax.Updater('cart', 'removefromcart.ninja?p='+p+'&s='+s, {evalScripts: true, asynchronous:true, method:'get'});
}
function hlp(mess)
{
	if ($('instr')) $('instr').innerHTML = mess;
}
function saveP(p, goUrl, tp, parentUrl)
{
	if (tp == 'm' && $('bulletin').checked) bulletin('Check out my new t-shirt designs',
		'Check out my t-shirt shop...  Just click <b>add to cart</b> to and then <b>check out</b> to buy something.  If you want to design your own clothes to wear or sell, click <a href="http://myspace.com/ninjazoo" target="_blank">http://myspace.com/ninjazoo</a> to go to the application.<br /><br />' +
		'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="380" height="230" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://www.ninjazoo.com/swf/shop2.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="FlashVars" value="id=' + shopId + '" /></object>');
	var formUrl = '/editproduct.ninja';
	if (tp) formUrl = '/tpeditproduct.ninja';
	var params = Form.serialize($('theForm'));
	var n = $F('n');
	$('MB_content').innerHTML = 'Please wait. Saving...';
	new Ajax.Request(formUrl +'?p=' + p, {method:'post', evalScripts:true, asynchronous:true, parameters:params, onComplete: function(transport)
		{
			if (transport.responseText.match(/formValid/))
			{
				if (goUrl) {if (parentUrl) window.parent.location.href = goUrl; else document.location.href = goUrl; }
				else { Modalbox.hide();$('n' + p).innerHTML = n; }
			}
			else $('MB_content').innerHTML = transport.responseText;
		}
	});
	Modalbox.hide();
	try {proxy.call('reset');}
	catch (e) {}
}
function saveI(i)
{
	var params = Form.serialize($('theForm'));
	$('MB_content').innerHTML = 'Please wait. Saving...';
	new Ajax.Request('edituserimage.ninja?i=' + i, {method:'post', evalScripts:true, asynchronous:true, parameters:params, onSuccess: function() { Modalbox.hide();}});
}
function design()
{
	Modalbox.hide();
	try {proxy.call('refr');}
	catch (e) {document.location.href = 'db.ninja';}
}
/*function addMoney(a, b)
{
	var s = (parseFloat(a) + parseFloat(b)).toString();
	if (s.length - s.indexOf(".") == 2) s = s + "0";
	return s;
}*/
function copy()
{
	var inElement = $('elCode');
	if (inElement.createTextRange)
	{
		var range = inElement.createTextRange();
    	if (range && BodyLoaded==1) range.execCommand('Copy');
	}
	else
	{
    	var flashcopier = 'flashcopier';
    	if(!document.getElementById(flashcopier))
    	{
      		var divholder = document.createElement('div');
     		divholder.id = flashcopier;
     		document.body.appendChild(divholder);
    	}
	    document.getElementById(flashcopier).innerHTML = '';
	    var divinfo = '<embed src="swf/_clipboard.swf" FlashVars="clipboard='+escape(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	    document.getElementById(flashcopier).innerHTML = divinfo;
  	}
}
function help(id)
{
	var qStr = '';
	if (id) qStr = '?id=' + id;
	Modalbox.show('help.ninja' + qStr, {title: 'Help', width: 250});
}
function tip(id, h)
{
	$('MB_content').style.height = null;
	Effect.Fade('inf' + id, {duration: 0.5});
	Modalbox.resize(0, h, {afterResize: function() {Effect.Appear('tip' + id);}});
}
function upl(tp)
{
	importJs('/js/prototype-base-extensions.js');
	importJs('/js/colorpicker.upl-0.2.js');
	Modalbox.show('/copyright.ninja' + (tp?('?tp=1&' + document.location.href.substr(document.location.href.indexOf('?') + 1)):''), {title: 'Upload', width: 400});
}
function bS(obj, xOff, yOff, ui)
{
	var html = '<div id="magiInner" style="background-color:#fff;width:100px;height:100px;"><div style="width: 100px; height: 100px;" >';
	html += '<a href="/db.ninja?ui=' + ui + '" onmouseover="Element.show(\'magiPop\')"><img alt="Design a shirt to buy" title="Design a shirt to buy" style="margin: 30px 3px 0 3px;" onmouseover="Element.show(\'magiPop\')" width="35" height="33" src="/img/buy.gif" /></a>';
	html += '<a href="/ds.ninja?ui=' + ui + '" onmouseover="Element.show(\'magiPop\')"><img alt="Design a shirt to sell" title="Design a shirt to sell" style="margin: 30px 3px 0 3px;" onmouseover="Element.show(\'magiPop\')" width="40" height="33" src="/img/sell.gif" /></a></div></div>';
	mPop(obj, xOff, yOff, html);
}
function mPop(obj, xOff, yOff, html)
{
	Position.prepare();
	var pos = Position.cumulativeOffset(obj);
	$('magiPop').style.left=xOff + pos[0]+'px';
	$('magiPop').style.top=yOff + pos[1]+'px';
	$('magiPop').innerHTML= html;
	Element.show('magiPop');
	Event.observe('magiInner', 'mouseout', function(e)
	{
		if (Event.element(e).nodeName == 'DIV') Element.hide('magiPop');
	});
}
function p(i)
{
	Modalbox.show('pmodal.ninja?p=' + i, {method: 'get', title: 'Product details', height: 600, width: 600});
}
function importJs(src)
{
	var scriptElem = document.createElement('script');
	scriptElem.setAttribute('src',src);
	scriptElem.setAttribute('type','text/javascript');
	document.getElementsByTagName('head')[0].appendChild(scriptElem);
}
function cModal(c, tp, dest, commission)
{
	$('MB_content').innerHTML = 'Please wait. Saving...';
	new Ajax.Updater('MB_content', '/currency.ninja?c=' + c + (commission?('&commission='+commission):'') + '&dest=' + dest + (tp?('&tp=' + tp + '&' + document.location.href.substr(document.location.href.indexOf('?') + 1)):''), {evalScripts:true, asynchronous:true, onComplete: function(){Modalbox.resize(0, -50);} });
}