// JavaScript Document

var productCode;
var numberOfColors;

//********** Function addToCart **********// 
// This takes the selection(s) from the   //
// dropdown and creates the URL for the   //
// product to be recieving the design.    //
// Then redirects the parent page to the  //
// new URL.                           -JC // 
//****************************************//
function addToCart(designCode, sportLong)
{
	var numColors = document.forms.addToChoices.colorChoice.value;
	var prodCode = document.forms.addToChoices.garmentChoice.value;
	var sportShort = getSport(sportLong);
	
	var newURL = "http://www.sportdecals.com/" + sportLong + "_Printed_Garments_p/" + sportShort + prodCode + numColors + ".htm?dcode=" + designCode;
	
	parent.parent.document.location = newURL;
	//return(newURL);
	
}

//********* Function dcodeGrabber *********// 
// This grabs the design code (dcode) from //
// the URL.                -JC             //  
//*****************************************//
function grabDcode()
{
	if (window.location.href.indexOf("dcode=") != -1)
	{ 
	  //alert("Test Message"); //troubleshooting
	  var tmpURL_1 = window.location.href.split("?");
	  var tmpURL_2 = tmpURL_1[1].split("dcode=");
	  document.MainForm['TEXTBOX___'+DesignOptId+'___'+DesignPC+'___'+DesignOptCatId].value = tmpURL_2[1].toUpperCase();	
	}
	else
	{  return;  }
}

//*********** Function initPage ***********// 
// This takes the info passed via URL and  //
// loads the page dynamically.        -JC  //  
//*****************************************//
function initPage()
{
	var curURL_1 = window.location.href.split("?");

	/* get the design code from the URL */
	var curURL_2 = curURL_1[1].split("dcode=");
	var curURL_2a = curURL_2[1].split("&");
	var dcode = curURL_2a[0];
	
	/* get the sport from the URL */
	var curURL_3 = curURL_1[1].split("st=");
	var sport = curURL_3[1];
	var shortSpt = getSport(sport);
	
	//var newURL = addToCart(dcode, sport);
	//alert (sport + " Design - " + dcode); // troubleshooting
	//alert (temp); // troubleshooting
	
	//document.write('<br /><table width="550" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="3"><img src="../designs/' + sport + '/' + dcode + '_a.jpg" alt="' + sport + ' Design - ' + dcode + '" border="0" width="548" /></td></tr><tr><td width="550"><form id="addToChoices" name="addToChoices"><div align="center"><select id="colorChoice" name="colorChoice"><option value="1c">1-Color</option><option value="2c">2-Color</option></select> <span class="notes"> design on a </span> <select id="garmentChoice" name="garmentChoice"><option value="switch_images/default.png">** Choose a shirt style **</option><option value="100sst">100% Short Sleeve T-Shirt</option><option value="50sst">50/50 Short Sleeve T-Shirt</option><option value="100lst">100% Long Sleeve T-Shirt</option><option value="50lst">50/50 Long Sleeve T-Shirt</option></select>&nbsp;<input type="button" name="addToBtn" id="addToBtn" value="Add to cart" onClick="addToCart(\'' + dcode + '\',\'' + sport + '\');" /></div></form></td></tr></table>');
	document.write('<br /><table width="550" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="3"><img src="../designs/' + sport + '/' + dcode + '_a.jpg" alt="' + sport + ' Design - ' + dcode + '" border="0" width="548" /></td></tr><tr><td width="550"><form id="addToChoices" name="addToChoices" action="javascript:addToCart(\''+dcode+'\',\''+sport+'\')"><div align="center"><select id="colorChoice" name="colorChoice"><option value="1c">1-Color</option><option value="2c">2-Color</option></select> <span class="notes"> design on a </span> <select id="garmentChoice" name="garmentChoice"><option value="switch_images/default.png">** Choose a shirt style **</option><option value="100sst">100% Short Sleeve T-Shirt</option><option value="50sst">50/50 Short Sleeve T-Shirt</option><option value="100lst">100% Long Sleeve T-Shirt</option><option value="50lst">50/50 Long Sleeve T-Shirt</option></select>&nbsp;<input type="submit" name="addToBtn" id="addToBtn" value="Add to cart" /> /></div></form></td></tr></table>');
	
	
}

//*********** Function getSport ***********// 
//  This gets the sport short name from the//
//  loong name.                       -JC  //  
//*****************************************//
function getSport(sportLong)
{
	sportLong = sportLong.toLowerCase();
	var sportShort;
	switch(sportLong)
	{	case "football" :
		sportShort = "fb";
		break;
		case "baseball" :
		sportShort = "bsb";
		break;
		case "softball" :
		sportShort = "sb";
		break;
		case "volleyball" :
		sportShort = "vb";
		break;
		case "soccer" :
		sportShort = "soc";
		break;
		case "basketball" :
		sportShort = "bkb";
		break;
		case "lacrosse" :
		sportShort = "lax";
		break;
		case "track" :
		sportShort = "tk";
		break;
		case "cross country" :
		sportShort = "xc";
		break;
		case "football.v3" :
		sportShort = "fb";
		break;
	}
	
	return(sportShort);
}

function setColors()
{ numberOfColors = document.forms.addToChoices.colorChoice.value; }
function setProduct()
{ productCode = document.forms.addToChoices.garmentChoice.value; }