function updatepreview()
{
	$preview = "<font color=" + $("#fontcolor").val() +">1 " + $("#link_text").val();
	$("#preview").html($preview);
}

function updateimagepreview()
{
	$preview = "<img src=\"http://www.priceocean.com/ouimg.php?out=1&fcolor=" +  $("#img_fontcolor").val()  +"&bgcolor=" +  $("#img_bgcolor").val()  + "\">";
	$("#imagepreview").html($preview);
}

function genonlineuserscode()
{
	var code = $("#codeform").val();
	code = code.replace(/fontcolor/,$("#fontcolor").val());
	code = code.replace(/lab_text/,$("#link_text").val());
	
	$.facebox(function() { 
		$.get('reg.php',  {digi:Math.random()}, function(data) {
		code = code.replace(/userid/g,data.id);
		$.facebox('<textarea cols="60" rows="10" onclick="this.focus();this.select()" readonly style="width:588px;">' + code + '</textarea><br>Please do not alter this code (Except for changing the color of the text). We periodically inspect and delete counters that have been tampered with.');
		
  }, "json")
 
}) 

}

function genimgcounter()
{
	var code = $("#imgcodeform").val();
	code = code.replace(/imgfcolorval/,$("#img_fontcolor").val());
	code = code.replace(/imgbgcolorval/,$("#img_bgcolor").val());
	
	$.facebox(function() { 
		$.get('reg.php',  {digi:Math.random()}, function(data) {
		code = code.replace(/userid/g,data.id);
		$.facebox('<textarea cols="60" rows="10" onclick="this.focus();this.select()" readonly style="width:588px;">' + code + '</textarea><br>Please do not alter this code (Except for changing the color of the text). We periodically inspect and delete counters that have been tampered with.');
		
  }, "json")
 
}) 

}


$(document).ready(function() {

$("#fontcolor").ColorPicker({
	onSubmit: function(hsb, hex, rgb, el) {
		var color = "#" + hex;
		$(el).val(color);
		$(el).ColorPickerHide();
		$(el).change();
	},
	onBeforeShow: function () {
		$(this).ColorPickerSetColor(this.value);
	},
	onChange: function (hsb, hex, rgb) {
		var color = "#" + hex;
		$('#fontcolor').val(color);
	}

}).bind('keyup', function(){
	$(this).ColorPickerSetColor(this.value);
});


$("#img_fontcolor").ColorPicker({
	onSubmit: function(hsb, hex, rgb, el) {
		var color = hex;
		$(el).val(color);
		$(el).ColorPickerHide();
		$(el).change();
	},
	onBeforeShow: function () {
		$(this).ColorPickerSetColor(this.value);
	},
	onChange: function (hsb, hex, rgb) {
		var color = hex;
		$('#img_fontcolor').val(color);
	}

}).bind('keyup', function(){
	$(this).ColorPickerSetColor(this.value);
});

$("#img_bgcolor").ColorPicker({
	onSubmit: function(hsb, hex, rgb, el) {
		var color = hex;
		$(el).val(color);
		$(el).ColorPickerHide();
		$(el).change();
	},
	onBeforeShow: function () {
		$(this).ColorPickerSetColor(this.value);
	},
	onChange: function (hsb, hex, rgb) {
		var color =  hex;
		$('#img_bgcolor').val(color);
	}

}).bind('keyup', function(){
	$(this).ColorPickerSetColor(this.value);
});

updatepreview();
updateimagepreview();

});

