function addEvent()
{
var ni = document.getElementById('merchDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "merch"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "<div style=\"clear: left;margin-right: 10px; float: left;\"><select name=\"imprint_colors["+num+"]\" /><option value=\"1\">1</option><option value=\"2\">2</option><option value=\"3\">3</option><option value=\"4\">4</option><option value=\"5\">5</option><option value=\"6\">6</option></select></div><div style=\"float: left; margin-right: 10px;\"><select name=\"imprint_location["+num+"]\" /><option value=\"Front Center\">Front Center</option><option value=\"Back Center\">Back Center</option><option value=\"Left Breast\">Left Breast</option><option value=\"Other\">Other: Specify in Notes</option></select></div><div style=\"float: left; clear: right;\"><input type=\"text\" name=\"imprint_notes["+num+"]\" value=\"\" size=\"20\" /> (<a href=\"javascript:;\" onclick=\"addEvent();\">+</a> | <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">-</a>)";
ni.appendChild(newdiv);
}

function removeEvent(divNum)
{
var d = document.getElementById('merchDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}


function getColors()
{

var entryID = $("#merchandise option:selected").val();
var cpanel = "/site/colors/"+entryID;
$('#colorPanel').load(cpanel).fadeIn("slow");
$("img#preview").attr({ src: "http://www.redalertmerch.com/images/shirt_images/chooseacolor"+entryID+".jpg", alt: "Choose a Color!" });

}

function chooseColor(entryID, shirtID)
{



oldColor = $("div.selectedColor").attr("id");
$("#"+oldColor).removeClass("selectedColor").addClass("unselectedColor");
$("#color"+entryID).addClass("selectedColor");
$('div#row'+shirtID).removeClass("productrowunselected").addClass("productrowselected");
/*$('div.productrowunselected:visible').slideUp('normal');
$("div.productimg").attr({ style: $("div.selectedColor").attr("style")});
$("div.productSwatch").attr({ style: $("div.selectedColor").attr("style")});
$('div.productSelCol').show();
$("h3.selColName").html($("div.selectedColor").attr("title"));*/
$("#shirtColor").val(entryID);

formName = "#shirt"+shirtID;

var newHTML = "<input type=\'hidden\' value=\'"+$("#color"+entryID).attr("title")+"\' name=\'merchColorName\' /><input type=\'hidden\' value=\'"+$("#color"+entryID).css("color")+"\' name=\'merchColorCode\' /><input type=\'hidden\' value=\'"+shirtID+"\' name=\'merchID\' /><input type=\'hidden\' value=\'"+entryID+"\' name=\'merchColor\' />"+$(formName).html();
	$(formName).html(newHTML);
	
$(formName).trigger("submit");

}


function calculateQuantity(count)
{
var total = 0;
for (var i = 0; i < count; i++) {
     if(Number($("#quantity"+i).val())) {
       total = parseInt(total) + parseInt($("#quantity"+i).val());
     }
}
$("#totalQuantity").html(total);

}

function isReady() {
var tq = $("#totalQuantity").html();
var ok = true;

var errormsg = "The following errors were found!\r\n\r\n";

	if ($('#merchandise').val() == "--") {
		var ok = false;
		errormsg = errormsg+"You didn't choose your merchandise.\r\n";
	} 

	if ((tq == null) || (parseInt(tq) < 1)) {
		var ok = false;
		errormsg = errormsg+"You didn't tell us how many shirts you want.\r\n";
	} 
	
	
	if (ok == true) {
		$("#freeform").unbind("submit");
		return true;
	} else {
		alert(errormsg);
		$("#freeform").bind("submit", function() { return false; });
	}
}

$(document).ready(function() {

  	// Ajax Loading Image
  	 $('#stepTwo').hide();
     $('#stuffLoading').hide();
     $('#stuffLoading').ajaxStart(function() {
       $(this).show();
     }).ajaxStop(function() {
       $(this).hide();
     });
     });


