var domain = "http://www.tatstore.com/fba";

function choose_stencil (num, cat) {
	//show loading wheel
	$("#stencil_button_"+num).html('Selecting');
	
	var data = [];

	
	data.push("stencil_num="+num);
	data.push("cat="+cat);
	
	post = data.join("&");
	
	fba_ajax(domain+'/includes/ajax.php?a=choose_stencil', post, 'res_choose_stencil');	
}

function res_choose_stencil (ret) {
	arr = ret.split("||**||");
	
	$("#stencil_button_"+arr[1]).html(arr[0]);
	
	$("#stencil_box_"+arr[1]).addClass("stencil_selected");
	
	if ($(".jGrowl").length) {
	} else {
		$.jGrowl('You have&nbsp;<span id=jGrowl_items></span>&nbsp;'+arr[3]+' selected.', { sticky: true, header: 'Stencils Update' });		
	}
	$("#jGrowl_items").text(arr[2]);
}

function remove_stencil (num, cat) {
	//show loading wheel
	$("#stencil_button_"+num).html('Removing');

	var data = [];

	data.push("stencil_num="+num);
	data.push("cat="+cat);
	
	post = data.join("&");
	
	fba_ajax(domain+'/includes/ajax.php?a=remove_stencil', post, 'res_remove_stencil');	
}

function res_remove_stencil (ret) {
	arr = ret.split("||**||");
	
	$("#stencil_button_"+arr[1]).html(arr[0]);
	$("#stencil_box_"+arr[1]).removeClass("stencil_selected");
	if ($(".jGrowl").length) {
	} else {
		$.jGrowl('You have&nbsp;<span id=jGrowl_items></span>&nbsp;'+arr[3]+' selected.', { sticky: true, header: 'Stencils Update' });		
	}
	$("#jGrowl_items").text(arr[2]);
}

function save_data () {
	var data = [];
	
	$("input[name^='cb_']:text, select[name^='cb_']").each(function(i){
		data.push($(this).attr("name").substring(3)+"="+$(this).val());	
	});
	
	post = data.join("&");
	
	fba_ajax(domain+'/includes/ajax.php?a=save_data', post, 'res_save_data');
	
	window.location = "http://www.tatstore.com/fba/thank_you.php";
}

function fba_ajax (aurl, adata, aretfunc) {
	$.ajax({
	   type: "POST",
	   url: aurl,
	   data: adata,
	   success: function(msg) {
			eval(aretfunc+'(msg);');
	   }
	});
}

function mouseOverStencils (num) {
	$("#stencil_box_"+num).addClass("stencil_hover");
}

function mouseOutStencils (num) {
	$("#stencil_box_"+num).removeClass("stencil_hover");
}

function printHeadline (x) {
	var y=document.getElementById(x).value;
	document.getElementById("preview_" + x).innerHTML=y;
}

function change_bg_color (bgc) {
	$("#banner_preview").css("background-color","#"+bgc);

}

function change_headline_font (font) {
	
	//
	// NOTE ABOUT REGULAR EXPRESSION
	// the character(s) after the /\b and before the . are what the thing searches for
	//
	
	document.getElementById("preview_banner_headline").className = document.getElementById("preview_banner_headline").className.replace(/\bf.*?\b/g, '');
	$("#preview_banner_headline").addClass("f_headline_"+font);
}

function change_headline_color (color) {
	document.getElementById("preview_banner_headline").className = document.getElementById("preview_banner_headline").className.replace(/\bc.*?\b/g, '');
	$("#preview_banner_headline").addClass("c_headline_"+color);
}

function change_subheadline_font (font) {
	document.getElementById("preview_banner_subheadline").className = document.getElementById("preview_banner_subheadline").className.replace(/\bf.*?\b/g, '');
	$("#preview_banner_subheadline").addClass("f_headline_"+font);
}

function change_subheadline_color (color) {
	document.getElementById("preview_banner_subheadline").className = document.getElementById("preview_banner_subheadline").className.replace(/\bc.*?\b/g, '');
	$("#preview_banner_subheadline").addClass("c_headline_"+color);
}