
function theme_rate(id, rating)
{
	$("#div_rate").hide("slow");
	
	$("#div_rate").load("/profiles/ajax.php?do=rate&id=" + id + "&rating=" + rating, function(){ });

}

// -------------------------------

var ajaxStore = "";

function submit_handler(step)
{
	if (step < 1)
	{
		window.location = '/profiles/help';
		return;
	}
		
	if (step == 2)
	{
		$("#submit_step1").hide("slow");
		$("#submit_step2").show("slow");
		return;
	}
		
	if (step == 3)
	{
		if ($("#profile_version").val() == 'old')
		{
			$("#profile_type").append("<option value='1'>Classic</option>");
			$("#profile_type").append("<option value='2'>Blocks</option>");
			$("#profile_type").append("<option value='3'>Grunny</option>");
			$("#profile_type").append("<option value='0'>Custom</option>");
		}
		else
		{
			$("#profile_type").append("<option value='6'>2 or 3-Column</option>");
			$("#profile_type").append("<option value='5'>3-Column</option>");
			$("#profile_type").append("<option value='4'>2-Column</option>");
		}
			
		$("#submit_step2").hide("slow");
		$("#submit_step3").show("slow");
		return;
	}
		
	if (step == 4)
	{
		if ($("#profile_creator").val() == '')
		{
			alert("Please enter your GaiaOnline username.");
			return;
		}
		
		if ($("#profile_title").val() == '')
		{
			alert("Please enter a profile title.");
			return;
		}
	
		$("#submit_step3").hide("slow");
		$("#submit_step4").show("slow");
		
		$.post("ajax.php",
			{ 
			post_do: "submit",
			profile_type: document.getElementById('profile_type').options[document.getElementById('profile_type').selectedIndex].value,
			profile_creator: $("#profile_creator").val(),
			profile_title: $("#profile_title").val(),
			profile_desc: $("#profile_desc").val(),
			profile_css: $("#profile_css").val()	
			},
			function(data){
				$("#submit_step5_info").html(data);
				submit_handler(5);
			}
		);
		
		return;
	}
	
	if (step == 5)
	{
		$("#submit_step4").hide("slow");
		$("#submit_step5").show("slow");
		
	}
}

// -------------------------------


function youtube_convertLink()
{
	var original = el("youtube_convert_from").value;
	var result = "";
	
	if (original.indexOf("watch?v=") > 0)
	{
		result = "http://www.youtube.com/v/" + original.substr( (original.indexOf("watch?v=") + 8) );
		
		if (result.indexOf("&eurl") > 0)
			result = result.substring(0, result.indexOf("&eurl"));
			
		el("youtube_convert_to").value = result;
		$("#youtube_autoplay").show();
		return;	
	}
	
	if (original.indexOf("value=") > 0)
	{
		result = original.substring( (original.indexOf("value=") + 7), (original.indexOf("></param>") - 1) );
		el("youtube_convert_to").value = result;
		$("#youtube_autoplay").show();
		return;	
	}
	
	if (original.indexOf("youtube.com/v/") > 0)
	{
		el("youtube_convert_to").value = original;
		$("#youtube_autoplay").show();
		return;	
	}
	
	el("youtube_convert_to").value = "Failed to convert link.";
	return;
		
	// <object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/1HpHyMQR058"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/1HpHyMQR058" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
	// http://youtube.com/watch?v=1HpHyMQR058
}


function youtube_autoplay()
{
	$("#youtube_autoplay").hide();
	el("youtube_convert_to").value += '&autoplay=1';
}

function youtube_keycheck(e, c)
{
	if(e && e.which)
	{
		e = e;
		var characterCode = e.which;
	}
	else
	{
		e = event;
		var characterCode = e.keyCode;
	}

	if(characterCode == 13)
	{
		if (c == 'convert')
			youtube_convertLink();
			
		if (c == 'search')
			youtube_searchVideos();
	}
}

function youtube_searchVideos()
{
	var search = el("youtube_search").value;

	var data = Math.floor(Math.random()*6) + 1;
	data  = "<img align='middle' class='icon_info' src='http://www.tektek.org/site/c" + data + ".gif' /> &nbsp; ";
	data += "<strong>Searching, please wait.</strong>";
	
	$("#youtube_results").html(data);
	
	$("#ajax_buffer").load("/profiles/ajax.php?do=search&search=" + escape(search), function(){youtube_searchResults();});
}

function youtube_searchResults()
{
	// we redirect from the buffer instead of direct due to an IE bug
	$("#youtube_results").html($("#ajax_buffer").html());
}

//--------------------------------------
//
//  00X - Misc
//
//--------------------------------------

Array.prototype.inArray = function (value)
{
    for (var i = 0; i < this.length; i++)
        if (this[i] === value)
            return true;
    return false;
}

Array.prototype.clear = function()
{
  this.length = 0;
}

function el(x)
{
	return document.getElementById(''+x+'');
}

function elShow(x)
{
	document.getElementById(''+x+'').style.display = 'block';
}

function elHide(x)
{
	document.getElementById(''+x+'').style.display = 'none';	
}