function save_profile(site_url, user_id)
{
	document.getElementById('profile_url').disabled = true;
	document.getElementById('profile_html').disabled = true;

	var profile_url_obj = document.getElementById('profile_url');
	var profile_html_obj = document.getElementById('profile_html');

	var profile_iframe = document.getElementById('profile_iframe');
	var profile_url = URLEncode(profile_url_obj.value);
	var profile_html = URLEncode(profile_html_obj.value);

	document.getElementById('profile_loading_bar').style.display = 'block';

	//alert(site_url+'ajax.php?act=profile_save&user_id='+user_id+'&profile_url='+profile_url+'&profile_html='+profile_html);
	new Ajax.Request(site_url+'ajax.php?act=profile_save',{
		parameters: {user_id: user_id, profile_url: profile_url, profile_html: profile_html},
		onSuccess: function(transport) {
			if ( transport.responseText.indexOf('Stored') >= 0 )
			{
				if (profile_url != '')
				{
					profile_iframe.src = profile_url_obj.value;
				}
				else
				{
					profile_iframe.src = site_url+'ajax.php?act=profile_get_html&user_id='+user_id;
				}
			}
			stop_edit();
		}
	});
}

function start_edit()
{
	document.getElementById('profile_url').disabled = false;
	document.getElementById('profile_html').disabled = false;
	document.getElementById('edit_profile').style.display = 'block';
	document.getElementById('show_profile').style.display = 'none';
}

function stop_edit()
{
	document.getElementById('edit_profile').style.display = 'none';
	document.getElementById('show_profile').style.display = 'block';
	document.getElementById('profile_loading_bar').style.display = 'none';
}

function report_profile(site_url, profile_url)
{
	if(!confirm("Do you want to report this profile as inappropriate?")) return;
	
	new Ajax.Request(site_url+'ajax.php?act=profile_report',{
		parameters: {profile_url: profile_url},
		onSuccess: function(transport) {
			if ( transport.responseText.indexOf('Sent') >= 0 )
			{
				alert('Thanks for your help');
			}
		}
	});
}

function URLEncode (clearString) {
	var output = '';
	var x = 0;
	clearString = clearString.toString();
	var regex = /(^[a-zA-Z0-9_.]*)/;
	while (x < clearString.length) {
		var match = regex.exec(clearString.substr(x));
		if (match != null && match.length > 1 && match[1] != '') {
			output += match[1];
			x += match[1].length;
		} else {
			if (clearString[x] == ' ')
			output += '+';
			else {
				var charCode = clearString.charCodeAt(x);
				var hexVal = charCode.toString(16);
				output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
			}
			x++;
		}
	}
	return output;
}
//
//
//function overPicture(event, site_url, outfit_id)
//{
//	if(1 == state) return;
//	mouseOver = 1;
//
//	var x = event.clientX;
//	var y = event.clientY;
//	if ( document.getElementById('popUp') )
//	{
//		var el = document.getElementById('popUp');
//		el.parentNode.removeChild(el);
//	}
//
//	var popUp = document.createElement('div');
//	popUp.id  = 'popUp';
//
//	with(popUp.style)
//	{
//		width  = '200px';
//		position = 'fixed';
//		left = x + 10 + 'px';
//		top = y + 10 +'px';
//		border = '1px solid #ccc';
//		background = '#f0f0ff';
//		fontFamily = 'Verdana';
//		fontSize = '10px';
//		padding = '5px';
//	}
//	popUp.innerHTML = 'Downloading...';
//
//	popUp.onmouseover = function(){mouseOver = 1};
//	popUp.onmouseout  = function(){outPicture(); };
//	new Ajax.Request(site_url+'ajax.php?act=outfit_descr&outfit_id='+outfit_id,{
//		method: 'get',
//		onSuccess: function(transport) {
//			popUp.innerHTML = transport.responseText;
//		}
//	});
//
//	$$('body')[0].appendChild(popUp);
//	state = 1;
//}
//
