function open_window(url) 
	{ 
		mywin = window.open(url,"win",'x=0,y=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=575,height=530,left=0,top=100'); 
	}
function open_window800(url) 
	{
	mywin = window.open(url,"win",'x=0,y=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=400,left=0,top=100'); 
	}
function toggle_it(itemID,srcid)
	{
      // Toggle visibility between none and inline 
      if ((document.getElementById(itemID).style.display == 'none')) 
      { 
        document.getElementById(itemID).style.display = 'inline'; 
		document.getElementById(srcid).innerHTML = '<a href="javascript:toggle_it(\'' + itemID + '\',\'' + srcid + '\')"><img src="hideshow_minus.gif" boarder=0></a>';
      } else { 
        document.getElementById(itemID).style.display = 'none'; 
		document.getElementById(srcid).innerHTML = '<a href="javascript:toggle_it(\'' + itemID + '\',\'' + srcid + '\')"><img src="hideshow_plus.gif" boarder=0></a>';
      } 
	} // end function toggle_it
 
// AJAX XMLHttpRequester
		var httpRequest = null;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    httpRequest = new XMLHttpRequest();
		    if (httpRequest.overrideMimeType) { // start if
		    httpRequest.overrideMimeType('text/xml');
		    // See note below about this line
		   } // end if overrideMimeType
		} // end if XMLHttpRequest
		else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} // end try Msxml2 ActiveXObject
			catch (e) {
					try {
						httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
						} // end try Microsoft ActiveXObject
						catch (e) {}
					  } // end catch
		} // end else if
		if (!httpRequest) {
	            alert('Giving up :( Cannot create an XMLHTTP instance');
		} // end if httpRequest

function mouseOverDel()
		{
			document.b1.src ="http://www.x-grain.com/images/nav/itemdelxblack.gif";
		}
function mouseOutDel()
		{
			document.b1.src ="http://www.x-grain.com/images/nav/itemdelx.gif";
		}


function getGarment(setno,fg)  // Main Build Order Information OnLoad
	   {
/* ***

			var get_cartvars = getCookieValue('cartvars');
			var get_trvals   = getCookieValue('trvals');
			if (get_cartvars)
				{
// alert('true cartvars='+get_cartvars+'  trvals='+get_trvals);
				}else{

				}
*/
			var xsetno = setno;
    	    var url = "http://www.x-grain.com/a/getGarmentXML.php?setno="+xsetno+"&fg="+fg;	
    	     httpRequest.open("GET", url, true);
    	     httpRequest.onreadystatechange = processGARMfromXML;
    	     httpRequest.send(null);
	   } // end function getGarment

function processGARMfromXML()
	   {
	     if (httpRequest.readyState == 4) {
	      if (httpRequest.status == 200) {
		  		var xmldoc = httpRequest.responseXML;
				var root_node = xmldoc.getElementsByTagName('root').item(0);
				var recs = xmldoc.getElementsByTagName( 'fronts' );
				var grmtbl = new Array();
				var setno1 = new Array();
				setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
				var setno = setno1[0];
				var fg = xmldoc.getElementsByTagName( 'fg' )[0].firstChild.nodeValue;
				grmtbl[0]  = xmldoc.getElementsByTagName( 'tblblock' )[0].firstChild.nodeValue;
				var newavailtbl = grmtbl[0];
				document.getElementById('garmenttbl_' + setno).innerHTML = newavailtbl;
		getTotals();
			} else {
					var message = httpRequest.getResponseHeader("Status");
					if ((message.length == null) || (message.length <= 0)) 
					{
						alert("Error! Request status is " + httpRequest.status);
					} else {
						alert(message);
					} }
			}
		if(document.getElementById('ordernumber'))
					{
					if (setno!=undefined){
						var priorsetno = setno - 1;
						chg_addset1(priorsetno);
						}
					}
	}  // end function processGARMfromXML

function disable(id)
	{
		if (!document.getElementByID || !document.createTextNode) {
			var findsetno = id.split("_"); // split id into array
			var setno = findsetno[1]; // assign setno to 2nd array value
			var grmno = document.getElementById(id).value; // value of menu item selected
			document.getElementById('edit_' + setno).style.visibility = "visible"; // turn on edit button
			document.getElementById(id).disabled=true;
			document.getElementById('grmclr_' + setno).disabled=false;
			document.getElementById('grmclr_' + setno).options[0].selected=true;
			document.getElementById('frontstyle_' + setno).disabled=false;
			document.getElementById('lclogo_' + setno).disabled=false;
			document.getElementById('lclogo_' + setno).options[0].selected=true;
			document.getElementById('mascot_' + setno).disabled=false;
			document.getElementById('mascot_' + setno).value="";
			document.getElementById('fcolor_' + setno).disabled=false;
			document.getElementById('fcolor_' + setno).options[0].selected=true;
			document.getElementById('bcolor_' + setno).disabled=false;
			document.getElementById('bcolor_' + setno).options[0].selected=true;
			document.getElementById('qtypaid_' + setno).disabled=false;
			document.getElementById('qtypaid_' + setno).value="";
		getGrmClr(grmno, setno);
		}
	}  // end function disable

function getGrmClr(grmno,setno)
   {
   		var xgrmno = grmno;
		var xsetno = setno;
        var url = "http://www.x-grain.com/a/getGrmClr.php?grmno="+grmno+"&setno="+xsetno;
         httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processGrmClrfromXML;
         httpRequest.send(null);
   } // end function getGrmClr

function processGrmClrfromXML()
   {
     if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
		var xmldocF = httpRequest.responseXML;
		var root_node = xmldocF.getElementsByTagName('root').item(0);
		var recs = xmldocF.getElementsByTagName( 'colors' );
		var coloroptvalu = new Array();
		var coloroptval = new Array();
		var coloroptdesc = new Array();
		var coloroptdes = new Array();
		var colorsetno = new Array();
		colorsetno[0]   = xmldocF.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = colorsetno[0];
		var grmno  = xmldocF.getElementsByTagName( 'grmno' )[0].firstChild.nodeValue;
		var fieldName = 'grmclr_'+setno;
		var clearOpts = 'document.sports.grmclr_' + setno + '.options.length=0';
		eval(clearOpts);
		for ( i = 0 ; i < recs.length ; i++ ) {
			j = i+1;
			coloroptvalu[i] = xmldocF.getElementsByTagName( 'colorno' )[i].firstChild.nodeValue;
			coloroptval[j] = coloroptvalu[i];
			coloroptdesc[i] = xmldocF.getElementsByTagName( 'color' )[i].firstChild.nodeValue;
			coloroptdes[j] = coloroptdesc[i];
			colorsetno[i]   = xmldocF.getElementsByTagName( 'setno' )[i].firstChild.nodeValue;
			addOptionClr(coloroptval[j],coloroptdes[j],colorsetno[i],j);
			}
	getFrontStyle(grmno,setno)
			} else {
		   		var message = httpRequest.getResponseHeader("Status");
   				if ((message.length == null) || (message.length <= 0)) {
   				alert("Error! Request status is " + httpRequest.status);
  		 	} else {
		   	alert(message);
	   	} } }
	} // end function processGrmClrfromXML

	
function getFrontStyle(grmno,setno)
   {
   		var xgrmno = grmno;
		var xsetno = setno;
        var url = "http://www.x-grain.com/a/getFrontStyles.php?grmno="+grmno+"&setno="+xsetno;
         httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processOPTIONSfromXML;
         httpRequest.send(null);
   } // end function getFrontStyle

function processOPTIONSfromXML()
   {
     if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
		var xmldocF = httpRequest.responseXML;
		var root_node = xmldocF.getElementsByTagName('root').item(0);
		var recs = xmldocF.getElementsByTagName( 'fronts' );
		var frontoptvalu = new Array();
		var frontoptval = new Array();
		var frontoptdesc = new Array();
		var frontoptdes = new Array();
		var frontsetno = new Array();
		frontsetno[0]   = xmldocF.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = frontsetno[0];
		var grmno  = xmldocF.getElementsByTagName( 'grmno' )[0].firstChild.nodeValue;
		var fieldName = 'frontstyle_'+setno;
		var clearOpts = 'document.sports.frontstyle_' + setno + '.options.length=0';
		eval(clearOpts);
		for ( i = 0 ; i < recs.length ; i++ ) {
			j = i+1;
			frontoptvalu[i] = xmldocF.getElementsByTagName( 'styleno' )[i].firstChild.nodeValue;
			frontoptval[j] = frontoptvalu[i];
			frontoptdesc[i] = xmldocF.getElementsByTagName( 'description' )[i].firstChild.nodeValue;
			frontoptdes[j] = frontoptdesc[i];
			frontsetno[i]   = xmldocF.getElementsByTagName( 'setno' )[i].firstChild.nodeValue;
			addOptionFrt(frontoptval[j],frontoptdes[j],frontsetno[i],j);
			}
		} else {
   			var message = httpRequest.getResponseHeader("Status");
   			if ((message.length == null) || (message.length <= 0)) {
   			alert("Error! Request status is " + httpRequest.status);
   		} else {
  	 	alert(message);
   		} } }
	} // end function processOPTIONSfromXML


function getGarmDisplay(id)
	{
		var grmno = document.getElementById(id).value;
		url = 'http://www.x-grain.com/a/garment.php?grmno='+grmno;
		mywin = window.open(url,"win",'x=0,y=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=575,height=530,left=0,top=100'); 
	} // end function getGarmDisplay

function getFrontDisplay(id)
	{
		var grmno = document.getElementById(id).value;
		var findsetno = id.split("_"); // split id into array
		var setno = findsetno[1]; // assign setno to 2nd array value
		var frontstyle = document.getElementById('frontstyle_' + setno).value; // value of menu item selected
		url = 'http://www.x-grain.com/a/frontstyles.php?frontstyle='+frontstyle+'&sportname=';
		mywin = window.open(url,"win",'x=0,y=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=575,height=530,left=0,top=100'); 
	} // end function getFrontDisplay

function getGarmentList(grmno)
   {
        var url = "http://www.x-grain.com/a/getGarmentListXML.php?grmno="+grmno;
         httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processGARMListfromXML;
         httpRequest.send(null);
   } // end function getGarmentList

function processGARMListfromXML()
   {
     if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
	  		var xmldoc = httpRequest.responseXML;
		var root_node = xmldoc.getElementsByTagName('root').item(0);
		var recs = xmldoc.getElementsByTagName( 'fronts' );
		var o_grmno = new Array();
		var o_desc = new Array();
			o_grmno[0]   = xmldoc.getElementsByTagName( 'grmno' )[0].firstChild.nodeValue;
			o_desc[0]  = xmldoc.getElementsByTagName( 'description' )[0].firstChild.nodeValue;
		var grmdescr = o_desc[0];
			return (grmdescr);
		} else {
   			var message = httpRequest.getResponseHeader("Status");
   			if ((message.length == null) || (message.length <= 0)) {
   			alert("Error! Request status is " + httpRequest.status);
	   	} else {
		   	alert(message);
   		} } }
	} // end function processGARMListfromXML

function getAvailable(id)
   {
		var findsetno = id.split("_"); // split id into array
		var xsetno = findsetno[1]; // assign setno to 2nd array value
		var xgrmno = document.getElementById('garment_'+xsetno).value; // value of menu item selected
		var xclrno = document.getElementById('grmclr_'+xsetno).value; // value of menu item selected
        var url = "http://www.x-grain.com/a/getAvailableXML.php?grmno="+xgrmno+"&setno="+xsetno+"&clrno="+xclrno;
         httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processAVAILfromXML;
         httpRequest.send(null);
   } // end function getAvailable

function processAVAILfromXML()
   {
     if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
	  		var xmldoc = httpRequest.responseXML;
		var root_node = xmldoc.getElementsByTagName('root').item(0);
		var recs = xmldoc.getElementsByTagName( 'fronts' );
		var sizelabel = new Array();
		var avail = new Array();
		var setno1 = new Array();
		setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = setno1[0];
		var grmno  = xmldoc.getElementsByTagName( 'grmno' )[0].firstChild.nodeValue;
		var fieldName = 'frontstyle_'+setno;
		var newavailinfo = '<span class="formlabelblack"><b>Availability:</b> &nbsp; &nbsp;</span>';
		for ( i = 0 ; i < recs.length ; i++ ) {
			sizelabel[i] = xmldoc.getElementsByTagName( 'sizelabel' )[i].firstChild.nodeValue;
			newavailinfo += sizelabel[i];
			avail[i] = xmldoc.getElementsByTagName( 'available' )[i].firstChild.nodeValue;
			newavailinfo += avail[i];
			}
		var newavailtext = 'document.sports.available_' + setno + '.innerHTML=""';
		document.getElementById('available_' + setno).innerHTML = newavailinfo;
		} else {
   		var message = httpRequest.getResponseHeader("Status");
   		if ((message.length == null) || (message.length <= 0)) {
   		alert("Error! Request status is " + httpRequest.status);
  	 	} else {
  		 	alert(message);
	   	} } }
	} // end function processAVAILfromXML

function addOptionClr(valu,desc,setno,j)
	{
		var f = document.forms[0];
		var fieldName = 'grmclr_'+setno;
		var selectBox = f.elements[fieldName];
		var extraOption = new Option( desc, valu, 0, 0 );
		selectBox.options[selectBox.options.length] = extraOption;
	} // end function addOptionClr

function addOptionFrt(valu,desc,setno,j)
	{
		var f = document.forms[0];
		var fieldName = 'frontstyle_'+setno;
		var selectBox = f.elements[fieldName];
		var extraOption = new Option( desc, valu, 0, 0 );
		selectBox.options[selectBox.options.length] = extraOption;
	} // function addOptionFrt


function enable(id)
	{
	if (!document.getElementByID || !document.createTextNode) {
		var r=confirm("Are you sure you want to Reset this Item? \r This will remove ALL SETTINGS and ITEMS for this Set ONLY");
		if (r==false)
		{
		return false;  // cancel
		}
		var findsetno = id.split("_"); // split id into array
		var setno = findsetno[1]; // assign setno to 2nd array value
		var grmno = document.getElementById(id).value; // value of menu item selected
		document.getElementById('edit_' + setno).style.visibility = "hidden"; // turn on edit button
		document.getElementById(id).disabled=false;
		document.getElementById(id).options[0].selected=true;
		document.getElementById('grmclr_' + setno).disabled=true;
		document.getElementById('grmclr_' + setno).options[0].selected=true;
		document.getElementById('frontstyle_' + setno).disabled=true;
		document.getElementById('frontstyle_' + setno).options[0].selected=true;
		document.getElementById('lclogo_' + setno).disabled=true;
		document.getElementById('lclogo_' + setno).options[0].selected=true;
		document.getElementById('mascot_' + setno).disabled=true;
		document.getElementById('mascot_' + setno).value="";
		document.getElementById('fcolor_' + setno).disabled=true;
		document.getElementById('fcolor_' + setno).options[0].selected=true;
		document.getElementById('bcolor_' + setno).disabled=true;
		document.getElementById('bcolor_' + setno).options[0].selected=true;
		document.getElementById('qtypaid_' + setno).disabled=true;
		document.getElementById('qtypaid_' + setno).value="";
		document.getElementById('available_' + setno).innerHTML = ""; // Clear Available
		document.getElementById('itemstbl_' + setno).innerHTML = ""; // Clear items for garment
		}
	} // end function enable

function checkset(id)
	{
		if (!document.getElementByID || !document.createTextNode) {
			var findsetno = id.split("_"); // split id into array
			var setno = findsetno[1]; // assign setno to 2nd array value
			var grmno = document.getElementById(id).value; // value of menu item selected
			var clrno = document.getElementById('grmclr_'+setno).value; // value of menu item selected
			// checkform('sports');
	  // ** CHECK FORM INPUT **
		if (document.sports.schoolname) {
			if (document.sports.schoolname.value == "") {
				alert( "Please enter your School Name or Create an account and login to automatically fill in this form." );
				document.sports.schoolname.focus();
				return false;
				exit; } }
		if (document.sports.contact) {
			if (document.sports.contact.value == "") {
				alert( "Please enter the Contact for this Order." );
				document.sports.contact.focus();
				return false;
				exit; } }
		if (document.sports.address) {
			if (document.sports.address.value == "") {
				alert( "Please enter the School Address." );
				document.sports.address.focus();
				return false;
				exit; } }
		if (document.sports.city) {
			if (document.sports.city.value == "") {
				alert( "Please enter the Schools City." );
				document.sports.city.focus();
				return false;
				exit; } }
		if (document.sports.association) {
		    if (document.sports.association.value == "") {
				alert( "Please select your School Association." );
				document.sports.association.focus();
				return false;
				exit; } }
		if (document.sports.state) {
			if (document.sports.state.value == "") {
				alert( "Please enter the Schools State." );
				document.sports.state.focus();
				return false;
				exit; } }
		// Check for correct zip code
			reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		if (document.sports.zipcode) {
			if (!reZip.test(document.sports.zipcode.value)) {
		    	alert("Please enter the Schools ZipCode.");
    			document.sports.zipcode.focus();
    			return false;
				exit; } }
		// Check for correct phone number
			rePhoneNumber = new RegExp(/^[1-9]\d{2}\-\d{3}\-\d{4}$/);
		if (document.sports.phone) {
			if (!rePhoneNumber.test(document.sports.phone.value)) {
    			alert("School Phone Number Must Be Entered As: 555-555-1234");
    			document.sports.phone.focus();
    			return false;
				exit; } }
		if (document.sports.dayphone) {
			if (!rePhoneNumber.test(document.sports.dayphone.value)) {
    			alert("Day Time Phone Number Must Be Entered As: 555-555-1234");
    			document.sports.dayphone.focus();
    			return false;
				exit; } }
		if (document.sports.fax) {
   			if (!rePhoneNumber.test(document.sports.fax.value)) {
    			alert("Fax Number Must Be Entered As: 555-555-1234");
    			document.sports.fax.focus();
    			return false;
				exit; } }
		if (document.sports.email) {
//			if ( !((document.sports.email.value.indexOf("www.") > 0) && (document.sports.email.value.indexOf("@") > 0)) ) {
			if ( !((document.sports.email.value.indexOf("@") > 0)) ) {
    			alert( "Please Enter a Valid EMail Address." );
    			document.sports.email.focus();
    			return false;
				exit; } }
		if (document.sports.pymtmthd) {
			if (document.sports.pymtmthd.value == "") {
				alert( "Please select your Payment Method." );
    			document.sports.pymtmthd.focus();
    			return false;
				exit; } }
		if (document.getElementById(id).options[0].selected==true && document.getElementById(id).options[0].selected!="") {alert('Please select a Garment for ' + id); return false;}
		if (document.getElementById('grmclr_' + setno).options[0].selected==true) {alert('Please select a Garment Color for ' + id); return false;}
		if (document.getElementById('frontstyle_' + setno).options[0].selected==true) {alert('Please select a Front Style for ' + id); return false;}
		if (document.getElementById('lclogo_' + setno).options[0].selected==true) {alert('Please select a Sport for ' + id); return false;}
		if (document.getElementById('mascot_' + setno).value=="") {alert('Please select a Mascot Name for ' + id ); return false;}
		if (document.getElementById('fcolor_' + setno).options[0].selected==true) {alert('Please select a Fore Color for ' + id ); return false;}
		if (document.getElementById('bcolor_' + setno).options[0].selected==true) {alert('Please select a Back Color for ' + id ); return false;}
		if (document.getElementById('fcolor_' + setno).value==document.getElementById('bcolor_' + setno).value) {alert('Both Fore Color and Back Color are the Same for ' + id ); return false;}
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
		if (qtypaid<=0 || isNaN(parseInt(qtypaid)))
			{
			document.getElementById('qtypaid_' + setno).value = '';
			alert('Please Enter a Qty PAID for ' + id ); 
			return false;
			}
	getItem(setno, grmno, clrno, qtypaid);
			}	
	} // end function checkset

function getItem(setno, grmno, clrno, qtypaid)
   {
   		var xgrmno = grmno;
		var xsetno = setno;
   		var xclrno = clrno;
		var xqtypaid = qtypaid;
        var url = "http://www.x-grain.com/a/getItemsXML.php?setno="+xsetno+"&grmno="+xgrmno+"&clrno="+xclrno+"&qtypaid="+xqtypaid;
         httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processITEMSfromXML;
         httpRequest.send(null);
   } // end function getItem

function processITEMSfromXML()
   {
     if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
	  		var xmldoc = httpRequest.responseXML;
		var root_node = xmldoc.getElementsByTagName('root').item(0);
		var recs = xmldoc.getElementsByTagName( 'fronts' );
		var grmtbl = new Array();
		var setno1 = new Array();
		setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = setno1[0];
		grmtbl[0]  = xmldoc.getElementsByTagName( 'tblblock' )[0].firstChild.nodeValue;

		var newavailtbl = grmtbl[0];
		document.getElementById('itemstbl_' + setno).innerHTML = newavailtbl;
		} else {
   		var message = httpRequest.getResponseHeader("Status");
   		if ((message.length == null) || (message.length <= 0)) {
   		alert("Error! Request status is " + httpRequest.status);
  	 	} else {
  	 	alert(message);
  	 	} } }
	} //  end function processITEMSfromXML

function getSizing(grmno, colorno,setno, recno)
   {
   		var xgrmno = grmno;
   		var xclrno = colorno;
		var xsetno = setno;
		var xrecno = recno;
		var xselected = document.getElementById('size_' + setno + '_' + recno).innerHTML;
        var url = "http://www.x-grain.com/a/getSizingXML.php?grmno="+xgrmno+"&clrno="+xclrno+"&setno="+xsetno+"&recno="+xrecno+"&xselected="+xselected;
         httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processSIZINGfromXML;
         httpRequest.send(null);
   } // end function getSizing

function processSIZINGfromXML()
	{
	     if (httpRequest.readyState == 4) {
	      if (httpRequest.status == 200) {
		  		var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
			var recs = xmldoc.getElementsByTagName( 'fronts' );
			/*
				var setno1 = new Array();
				setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
				var setno = setno1[0];
			*/
			var setno = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
			var recno = xmldoc.getElementsByTagName( 'recno' )[0].firstChild.nodeValue;
			var sizeoptions  = xmldoc.getElementsByTagName( 'tblblock' )[0].firstChild.nodeValue;
			var newselectoption = '<select id="csize_'+setno+'_'+recno+'" size="0" onblur="chg2size(\''+setno+'\',\''+recno+'\');">'+ sizeoptions;
			document.getElementById('size_' + setno + '_' + recno).innerHTML = newselectoption;
			} else {
	   		var message = httpRequest.getResponseHeader("Status");
	   		if ((message.length == null) || (message.length <= 0)) {
	   		alert("Error! Request status is " + httpRequest.status);
	   	} else {
	   	alert(message);
	   	}
	     } }
	} // end function processSIZINGfromXML

function NameCheck(setno,line,pass)
	{
 	 // SET TO UPPER CASE
		 if(pass == 1){
			var basename = 'cname_';
			var baseno = 'cno_';
			document.sports["cname_"+setno+"_"+line].value = document.sports["cname_"+setno+"_"+line].value.toUpperCase();
			document.sports["cno_"+setno+"_"+line].value = document.sports["cno_"+setno+"_"+line].value.toUpperCase();
			var typeak = new Array(2);
			sizeid = document.getElementById('size_'+setno+'_'+line);
			sizeval = sizeid.innerHTML;
			typeak = sizeval.split("-");
		}else{
			var basename = 'name_';
			var baseno = 'no_';
			document.sports["name_"+setno+"_"+line].value = document.sports["name_"+setno+"_"+line].value.toUpperCase();
			document.sports["no_"+setno+"_"+line].value = document.sports["no_"+setno+"_"+line].value.toUpperCase();
			var typeak = new Array(2);
			typeak = document.sports["size_"+setno+"_"+line].value.split("-");
			}
	   // REMOVE LEADING AND TRAILING SPACES
			while(document.sports[basename+setno+"_"+line].value.charAt(0)==' ')
				document.sports[basename+setno+"_"+line].value = document.sports[basename+setno+"_"+line].value.ing(1);
			while(document.sports[baseno+setno+"_"+line].value.charAt(0)==' ')
				document.sports[baseno+setno+"_"+line].value = document.sports[baseno+setno+"_"+line].value.substring(1);
			while(document.sports[basename+setno+"_"+line].value.charAt(document.sports[basename+setno+"_"+line].value.length - 1)==' ')
				document.sports[basename+setno+"_"+line].value = document.sports[basename+setno+"_"+line].value.substring(0, document.sports[basename+setno+"_"+line].value.length - 1);
				namelen = document.sports[basename+setno+"_"+line].value.length;
			while(document.sports[baseno+setno+"_"+line].value.charAt(document.sports[baseno+setno+"_"+line].value.length - 1)==' ')
				document.sports[baseno+setno+"_"+line].value = document.sports[baseno+setno+"_"+line].value.substring(0, document.sports[baseno+setno+"_"+line].value.length - 1);
				NOlen = document.sports[baseno+setno+"_"+line].value.length;
	   // CHECK IF NAME WAS ENTERED
			if(namelen==0 && pass==0) return (false);
	   // CHECK FOR MULT FORCED LINE BREAKS
			caretcount=0
			for (i=0; i<=document.sports[basename+setno+"_"+line].value.length; i++) 
				{
				if(document.sports[basename+setno+"_"+line].value.charAt(i)=="^") {caretcount=caretcount+1};
				}
				if(caretcount > 1) {document.sports[basename+setno+"_"+line].value = document.sports[basename+setno+"_"+line].value.replace (/\^/g, " ")};
		// CHECK INITIAL PERIOD SPACE
			while(initialperiodspace.test(document.sports[basename+setno+"_"+line].value))
			{
			var n_array = document.sports[basename+setno+"_"+line].value.split('. ');
			document.sports[basename+setno+"_"+line].value = n_array[0]+"."+n_array[1];
			namelen = document.sports[basename+setno+"_"+line].value.length;
			}
		// REMOVE MANY SPACES WITHIN NAMES
			document.sports[basename+setno+"_"+line].value = document.sports[basename+setno+"_"+line].value.replace (/([A-Z])(\s{2,})/g, "$1 "); // remove spaces >1 between A-Z and A-Z/0-9 (not converse)
			namelen = document.sports[basename+setno+"_"+line].value.length;
			document.sports[baseno+setno+"_"+line].value = document.sports[baseno+setno+"_"+line].value.replace (/([A-Z])(\s{2,})/g, "$1 "); // remove spaces >1 between A-Z and A-Z/0-9 (not converse)
			NOlen = document.sports[baseno+setno+"_"+line].value.length;
		// SET Mc UNDER 12 CHARACTERS
			if(namelen <= 12 && (document.sports[basename+setno+"_"+line].value.substring(0,2)=="MC" || document.sports[basename+setno+"_"+line].value.substring(0,2)=="Mc"))
				{
				document.sports[basename+setno+"_"+line].value ='Mc'+document.sports[basename+setno+"_"+line].value.substring(2,namelen);
				}	
   	   // CHECK NAME FOR ILLEGAL CHARACTERS
			if(namelen<0){
				tempgood="";
				tempbad="";
				if (nametest.test(document.sports[basename+setno+"_"+line].value))
					{} // end if
				else
				{
					for(i=0;i<=namelen;i++)
					{
						tempchar = document.sports[basename+setno+"_"+line].value.substring(i,i+1);
						if(nametest.test(tempchar))
		  				{
							tempgood += tempchar;
		  				} // end if
						else
						{
						tempbad += tempchar;
  						} // end else
					} // end for
					alert ('The Following Character(s) '+tempbad+' are not allowed in the NAME FIELD and have been removed ');
					document.sports[basename+setno+"_"+line].value = tempgood; // or ''
					namelen = document.sports[basename+setno+"_"+line].value.length;
	 		  	} // end else
			} // end if namelen
		// CHECK NO FOR ILLEGAL CHARACTERS
			tempNOgood='';
			tempNObad='';
			if (nametest.test(document.sports[baseno+setno+"_"+line].value))
				{} // end if
			else
				{
				for(i=0;i<=NOlen;i++)
					{
					tempchar = document.sports[baseno+setno+"_"+line].value.substring(i,i+1);
					if(nametest.test(tempchar))
			  		{
						tempNOgood += tempchar;
			  		} // end if
					else
					{
					tempNObad += tempchar;
  					} // end else
				} // end for
				if(tempNObad.length>0)
				{
					alert ('The Following Character(s) '+tempNObad+' are not allowed in the NUMBER FIELD and have been removed ');
					document.sports[baseno+setno+"_"+line].value = tempNOgood; // or ''
					NOlen = document.sports[baseno+setno+"_"+line].value.length;
				}
	 	  	} // end else
		// COUNT WORDS AND LENGTHS OF EACH WORD
			if(namelen>0) wordcnt=1;
			forcedoneline=0;
			forcedtwolines=0;
			j=0;
			var wordlen = new Array(10);
			for (i=1; i<=namelen;i++)
				{
				j++;
				wordlen[wordcnt]=j;
				 if(document.sports[basename+setno+"_"+line].value.charAt(i)==' ' || document.sports[basename+setno+"_"+line].value.charAt(i)=='^') 
					{
					wordcnt++;
					j=-1;
					}
				 if(document.sports[basename+setno+"_"+line].value.charAt(i)=='^') forcedtwolines++;
				 if(document.sports[basename+setno+"_"+line].value.charAt(i)=='_') forcedoneline++;
				 if((typeak[0]=='Adult' || typeak[1]=='Adult') && (wordlen[1]>11 || wordlen[2]>11 || wordlen[3]>11 || wordlen[4]>11 || wordlen[5]>11 || wordlen[6]>11 || wordlen[7]>11 || wordlen[8]>11))
				   {
				 alert("Each Line can only be a Max of 11 Characters on Adult Garments");
				 document.sports[basename+setno+"_"+line].value = '';
				 namelen=document.sports[basename+setno+"_"+line].value.length;
				 document.sports[basename+setno+"_"+line].focus();
				 return (false);
				   } // end if
				 if((typeak[0]=='Kids' || typeak[0]=='Youth' || typeak[1]=='Kids' || typeak[1]=='Youth') && (wordlen[1]>7 || wordlen[2]>7 || wordlen[3]>7 || wordlen[4]>7 || wordlen[5]>7 || wordlen[6]>7 || wordlen[7]>7 || wordlen[8]>7))
				   {
				 alert("Each Line can only be a Max of 7 Characters on Kids Garments");
				 document.sports[basename+setno+"_"+line].value = '';
				 namelen = document.sports[basename+setno+"_"+line].value.length;
				 document.sports[basename+setno+"_"+line].focus();
				 return (false);
				   } // end if
			} // end for
			if(typeak[0]=='Kids'||typeak[0]=='Youth'||typeak[1]=='Kids'||typeak[1]=='Youth') maxwordlen=7;
			if(typeak[0]=='Adult'||typeak[1]=='Adult') maxwordlen=11;
			if(forcedtwolines>0 && document.sports[baseno+setno+"_"+line].value.length != 0)
			{
			document.sports[baseno+setno+"_"+line].value = '';
			namelen = document.sports[basename+setno+"_"+line].value.length;
			alert("You can not have TWO LINES and a NUMBER, You must remove one or the other. So we have removed the NUMBER for you");
			document.sports[baseno+setno+"_"+line].focus();
			return (false);
			}
		if( ((wordlen[2]>0) && (wordlen[1]+wordlen[2]+1)>maxwordlen ) && document.sports[baseno+setno+"_"+line].value.length >= 1)
			{
			document.sports[baseno+setno+"_"+line].value = '';
			namelen = document.sports[basename+setno+"_"+line].value.length;
			alert("You can not have TWO LINES and a NUMBER, You must remove one or the other. So we have removed the NUMBER for you");
			}
		if( ((wordlen[3]>0) && (wordlen[1]+wordlen[2]+wordlen[3]+2)>maxwordlen ) && document.sports[baseno+setno+"_"+line].value.length >= 1)
			{
			document.sports["no_"+setno+"_"+line].value = '';
			namelen = document.sports[basename+setno+"_"+line].value.length;
			alert("You can not have TWO LINES and a NUMBER, You must remove one or the other. So we have removed the NUMBER for you");
			}
		if( ((wordlen[4]>0) && (wordlen[1]+wordlen[2]+wordlen[3]+wordlen[4]+3)>maxwordlen ) && document.sports["no_"+setno+"_"+line].value.length >= 1)
			{
			document.sports["no_"+setno+"_"+line].value = '';
			namelen = document.sports[basename+setno+"_"+line].value.length;
			alert("You can not have TWO LINES and a NUMBER, You must remove one or the other. So we have removed the NUMBER for you");
			}
		if( ((wordlen[5]>0) && (wordlen[1]+wordlen[2]+wordlen[3]+wordlen[4]+wordlen[5]+4)>maxwordlen ) && document.sports["no_"+setno+"_"+line].value.length >= 1)
			{
			document.sports[baseno+setno+"_"+line].value = '';
			namelen = document.sports[basename+setno+"_"+line].value.length;
			alert("You can not have TWO LINES and a NUMBER, You must remove one or the other. So we have removed the NUMBER for you");
			}
		if( ((wordlen[6]>0) && (wordlen[1]+wordlen[2]+wordlen[3]+wordlen[4]+wordlen[5]+wordlen[6]+5)>maxwordlen ) && document.sports["no_"+setno+"_"+line].value.length >= 1)
			{
			document.sports["no_"+setno+"_"+line].value = '';
			namelen = document.sports[basename+setno+"_"+line].value.length;
			alert("You can not have TWO LINES and a NUMBER, You must remove one or the other. So we have removed the NUMBER for you");
			}
		if( ((wordlen[7]>0) && (wordlen[1]+wordlen[2]+wordlen[3]+wordlen[4]+wordlen[5]+wordlen[6]+wordlen[7]+6)>maxwordlen ) && document.sports["no_"+setno+"_"+line].value.length >= 1)
			{
			document.sports[baseno+setno+"_"+line].value = '';
			namelen = document.sports[basename+setno+"_"+line].value.length;
			alert("You can not have TWO LINES and a NUMBER, You must remove one or the other. So we have removed the NUMBER for you");
			}
		if( (document.sports[basename+setno+"_"+line].value.length>15) && (typeak[0]=='Kids' || typeak[0]=='Youth' || typeak[1]=='Kids' || typeak[1]=='Youth'))
			{
			document.sports[basename+setno+"_"+line].value='';
			namelen=document.sports[basename+setno+"_"+line].value.length;
			alert("You Entered too many characters for a Youth Garment");
			}
		if((typeak[0]=='Adult' || typeak[1]=='Adult') && forcedtwolines==0 && document.sports[basename+setno+"_"+line].value.length > 11)
			{
			for (i=12;i>=0;i--) {
					if(document.sports[basename+setno+"_"+line].value.charAt(i)==' ') 
					{
					line1 = document.sports[basename+setno+"_"+line].value.substring(0,i);
					line2 = document.sports[basename+setno+"_"+line].value.substring(i+1);
					document.sports[basename+setno+"_"+line].value = line1+"^"+line2;
					forcedtwolines = 1;
					break;
					} // end if
				} // end for
			} // end if
		if(( typeak[0]=='Kids' || typeak[0]=='Youth' || typeak[1]=='Kids' || typeak[1]=='Youth') && forcedtwolines==0 && document.sports[basename+setno+"_"+line].value.length > 7)
			{
			for (i=8;i>=0;i--) {
					if(document.sports[basename+setno+"_"+line].value.charAt(i)==' ') 
					{
					line1 = document.sports[basename+setno+"_"+line].value.substring(0,i);
					line2 = document.sports[basename+setno+"_"+line].value.substring(i+1);
					document.sports[basename+setno+"_"+line].value = line1+"^"+line2;
					forcedtwolines = 1;
					break;
					} // end if
				} // end for
			} // end if
		if(pass == 1) { 
					var newname = "";
					var newno = "";
					newname = document.sports["cname_"+setno+"_"+line].value;
					newno = document.sports["cno_"+setno+"_"+line].value;
					name1 = document.getElementById('name_'+setno+'_'+line);
					no1 = document.getElementById('no_'+setno+'_'+line);
					currentval = name1.innerHTML;
				if(newname == '') {
					name1.setAttribute("class","formlabelreditalic");
					name1.setAttribute("className","formlabelreditalic");
					name1.innerHTML = '(none)';
					}else{
					name1.setAttribute("class","formlabelblackbold");
					name1.setAttribute("className","formlabelblackbold");
					name1.innerHTML = newname;
					}
				if(newno == '') {
					no1.setAttribute("class","formlabelreditalic");
					no1.setAttribute("className","formlabelreditalic");
					no1.innerHTML = '(none)';
					}else{
					no1.setAttribute("class","formlabelblackbold");
					no1.setAttribute("className","formlabelblackbold");
					no1.innerHTML = newno;
					}
				var ctrvalsarray = new Array();
				ctrvals = document.getElementById('trvals_'+setno+'_'+line).value;
				ctrvalsarray = ctrvals.split(";"); // split vars into array
				cnameval = document.getElementById('name_'+setno+'_'+line).innerHTML;
					if (cnameval=="(none)") cnameval='';
				cnoval = document.getElementById('no_'+setno+'_'+line).innerHTML;
					if (cnoval=="(none)") cnoval='';
				
				if (document.getElementById('ordernumber')) {
					setvars_new = ctrvalsarray[0]+";"+ctrvalsarray[1]+";"+ctrvalsarray[2]+";"+ctrvalsarray[3]+";"+cnameval+";"+cnoval+";"+ctrvalsarray[6]+";"+ctrvalsarray[7]+";"+ctrvalsarray[8]+";"+ctrvalsarray[9];
				}else{
					setvars_new = ctrvalsarray[0]+";"+ctrvalsarray[1]+";"+ctrvalsarray[2]+";"+ctrvalsarray[3]+";"+cnameval+";"+cnoval+";"+ctrvalsarray[6]+";"+ctrvalsarray[7];
					}
				document.getElementById('trvals_'+setno+'_'+line).value = setvars_new;
						var trvararray = new Array();
		var trvars_old = document.getElementById('trvals_'+setno+'_'+line).value;
		trvararray = trvars_old.split(";");
			var aqty = trvararray[2];
			var asize = trvararray[3];
			var aname = trvararray[4];
				if (aname == "(none)") aname = '';
			var ano = trvararray[5];
				if (ano == "(none)") ano = '';
		var setvararray = new Array();
		var setvars_old = document.getElementById('cartvars_'+setno).value;
		setvararray = setvars_old.split(";");
			var agrmno = setvararray[1];
			var afrntno = setvararray[3];
		var pass = 1;
	getItemPricing(setno,line,aqty,agrmno,afrntno,asize,aname,ano,pass); 
		}
 } // end function NameCheck( )

function echeck(str)
	{
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("E-mail Address entered is Invalid, please check");
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("E-mail Address entered is Invalid, please check");
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("E-mail Address entered is Invalid, please check");
		    return false;
		}
		if (str.indexOf(at,(lat+1))!=-1){
		    alert("E-mail Address entered is Invalid, please check");
		    return false;
		 }
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("E-mail Address entered is Invalid, please check");
		    return false;
		 }
		if (str.indexOf(dot,(lat+2))==-1){
		    alert("E-mail Address entered is Invalid, please check");
		    return false;
		 }
		if (str.indexOf(" ")!=-1){
		    alert("E-mail Address entered is Invalid, please check");
		    return false;
		 }
 		 return true;			
		} // end  function echeck
	
function checkform ( form )
	{
 	 // ** CHECK FORM INPUT **
	  if (document.sports.schoolname) {
	  if (document.sports.schoolname.value == "") {
	    alert( "Please enter your School Name or Create an Account and Login to Automatically Fill in this Form." );
	    document.sports.schoolname.focus();
	    return false;
		exit;
	  } }
	  if (document.sports.contact) {
	  if (document.sports.contact.value == "") {
	    alert( "Please enter the Contact for this Order." );
	    document.sports.contact.focus();
	    return false;
		exit;
	  } }
	  if (document.sports.address) {
	  if (document.sports.address.value == "") {
	    alert( "Please enter the School Address." );
	    document.sports.address.focus();
	    return false;
		exit;
	  } }
	  if (document.sports.city) {
	  if (document.sports.city.value == "") {
	    alert( "Please enter the Schools City." );
	    document.sports.city.focus();
	    return false;
		exit;
	  } }
	  if (document.sports.association) {
	    if (document.sports.association.value == "") {
	    alert( "Please select your School Association." );
	    document.sports.association.focus();
	    return false;
		exit;
	  } }
	  if (document.sports.state) {
	  if (document.sports.state.value == "") {
	    alert( "Please enter the Schools State." );
	    document.sports.state.focus();
	    return false;
		exit;
	  } }
	// Check for correct zip code
	reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		if (document.sports.zipcode) {
	   if (!reZip.test(document.sports.zipcode.value)) {
	     alert("Please enter the Schools ZipCode.");
	     document.sports.zipcode.focus();
	     return false;
		 exit;
 	 } }
	// Check for correct phone number
	rePhoneNumber = new RegExp(/^[1-9]\d{2}\-\d{3}\-\d{4}$/);
	 if (document.sports.phone) {
	   if (!rePhoneNumber.test(document.sports.phone.value)) {
	     alert("School Phone Number Must Be Entered As: 555-555-1234");
	     document.sports.phone.focus();
	     return false;
	 	exit;
	  } }
	  if (document.sports.dayphone) {
	   if (!rePhoneNumber.test(document.sports.dayphone.value)) {
	     alert("Day Time Phone Number Must Be Entered As: 555-555-1234");
	     document.sports.dayphone.focus();
	     return false;
		 exit;
	  } }
	  if (document.sports.fax) {
	   if (!rePhoneNumber.test(document.sports.fax.value)) {
	     alert("Fax Number Must Be Entered As: 555-555-1234");
	     document.sports.fax.focus();
	     return false;
		 exit;
	  } }
	  if (document.sports.email) {
//	   if ( !((document.sports.email.value.indexOf(".") > 2) && (document.sports.email.value.indexOf("@") > 0)) ) {
	   if ( !((document.sports.email.value.indexOf("@") > 0)) ) {
	    alert( "Please Enter a Valid EMail Address." );
	    document.sports.email.focus();
	    return false;
		exit;
	  } }
		if (document.sports.pymtmthd) {
	  if (document.sports.pymtmthd.value == "") {
	    alert( "Please select your Payment Method." );
	    document.sports.pymtmthd.focus();
	    return false;
		exit;
	  } }
	  return true ;
	} // end function checkform

function textCounter( field, countfield, maxlimit )
	{
	  if ( field.value.length > maxlimit )
	  {
	    field.value = field.value.substring( 0, maxlimit );
	    alert( 'Textarea value can only be 255 characters in length.' );
	    return false;
	  }
	  else
	  {
	    countfield.value = maxlimit - field.value.length;
	  }
	} // end function textCounter

function ValidateForm()
	{
		var emailID=document.sports.email
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email Address")
			emailID.focus()
			return false
		}
		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}
		return true
 	} // end function ValidateForm

 	nametest = /^[a-zA-Z0-9 _\^\'\"\-\!\&\#\.]+$/;
	initialperiodspace = /^\w\.\s/;
	frontspace = /^\s\w/;
	sizeselected = /^(\w+)-(\w+)$/;
	posnumber = /^\d+$/;

function mascotcheck(setno)
	{
	// CHECK mascot FOR ILLEGAL CHARACTERS
		document.sports['mascot_'+setno].value.toUpperCase();
		mascotlen = document.sports["mascot_"+setno].value.length;
		tempmgood = '';
		tempmbad = '';
		if (nametest.test(document.sports["mascot_"+setno].value))
			{} // end if
		else
			{
			for(i=0;i<=mascotlen;i++)
				{
				tempchar = document.sports["mascot_"+setno].value.substring(i,i+1);
				if(nametest.test(tempchar))
		  		{
					tempmgood += tempchar;
		  		} // end if
				else
				{
				tempmbad += tempchar;
  				} // end else
			} // end for
			if(tempmbad.length>0)
			{
			alert ('The Following Character(s) '+tempmbad+' are not allowed in the MASCOT and have been removed ');
			document.sports["mascot_"+setno].value = tempmgood; // or ''
			}
	   	} // end else
		} //end function mascotcheck(setno)
	
function isposnumber(setno)
	{;
			var setnumb = setno;
			var qty = document.sports[setnumb].value;
			if ( qty<=0 || isNaN(parseInt(qty))) { 
				alert(' You must enter a Positive Number ');
				document.sports[setnumb].value = '';
				document.sports[setnumb].focus();
			}
		} // end fuction isposnumber()
  
function add_sizes()
	{
		var tot_entered=0;
		setno = document.sports.setnumber.value;
		
		for(i=1;i<9;i++){
			if(document.sports["qty_"+i]){
				if ( document.sports["qty_"+i].value<=0 || isNaN(parseInt(document.sports["qty_"+i].value))) { 
				document.sports["qty_"+i].value = '';
				}else{
				ent_qty = parseInt(document.sports["qty_"+i].value);
				tot_entered += ent_qty;
				}}			
		}
		var cur_val_obj = document.getElementById("tot_ent");
		var cur_val = cur_val_obj.innerHTML;
		var qty_ent = document.getElementById("qtypaid_"+setno).value;
		var new_val = tot_entered;
		var new_val_obj = document.createTextNode(new_val);
		document.getElementById("tot_ent").innerHTML = new_val;
		if(new_val > qty_ent){
		   alert("More were Entered in boxes than Quantity Ordered above")
			}
		} // end function add_sizes()

function getItemPricing( setno , lineno , qty , grmno , frntno , size , name , no , pass) 
	{
		var nntrue = 0;
		if((name) || (no)) nntrue = 1;
        var url = "http://www.x-grain.com/a/getItemPriceXML.php?setno="+setno+"&lineno="+lineno+"&qty="+qty+"&grmno="+grmno+"&frntno="+frntno+"&size="+size+"&nntrue="+nntrue+"&pass="+pass;
		httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processItemPricingfromXML;
         httpRequest.send(null);
		} // end function getItemPricing

function processItemPricingfromXML()
	{
		if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) 
			{
				var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
			var setno   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
			var lineno   = xmldoc.getElementsByTagName( 'lineno' )[0].firstChild.nodeValue;
			var pass   = xmldoc.getElementsByTagName( 'pass' )[0].firstChild.nodeValue;
			var extprice  = xmldoc.getElementsByTagName( 'pricing' )[0].firstChild.nodeValue;
			document.getElementById('price_'+setno+'_'+lineno).innerHTML = extprice;

				extprice = extprice.substr(1,extprice.length);
				var trvararray = new Array();
				var trvars_old = document.getElementById('trvals_'+setno+'_'+lineno).value;
				trvararray = trvars_old.split(";");
				if (document.getElementById('ordernumber')) {
					var trvals_new = trvararray[0]+';'+trvararray[1]+';'+trvararray[2]+';'+trvararray[3]+';'+trvararray[4]+';'+trvararray[5]+';'+trvararray[6]+';'+extprice+';'+trvararray[8]+';'+trvararray[9];
				}else{
					var trvals_new = trvararray[0]+';'+trvararray[1]+';'+trvararray[2]+';'+trvararray[3]+';'+trvararray[4]+';'+trvararray[5]+';'+trvararray[6]+';'+extprice;
				}
				document.getElementById('trvals_'+setno+'_'+lineno).value = trvals_new;
				getTotals();
				if (document.getElementById('ordernumber')) {
					chg_dbline_update(setno, lineno);
				}else{
					return;
				}
			} else {
			var message = httpRequest.getResponseHeader("Status");
				if ((message.length == null) || (message.length <= 0)) 
				{
				alert("Error! Request status is " + httpRequest.status);
				} else  {
						alert(message);
						}
				} }
	} // end function getItemPricing() to processItemPricingfromXML()

function CurrencyFormatted(amount)
	{
		var i = parseFloat(amount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		return s;
	}  // end of function CurrencyFormatted()

function checkform_uds ( form ) {
			var formid = form.id;
			var formvalue = form.value;
			var url = 'http://www.x-grain.com/a/x_pop_session_do.php?'+formid+'+'+formvalue;
// alert('url is '+url);
	         httpRequest.open("GET", url, true);
    	     httpRequest.onreadystatechange = processCONTACTfromXML;
    	     httpRequest.send(null);
	}

function processCONTACTfromXML()
	{
		if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) 
			{
				var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
			} else {
			var message = httpRequest.getResponseHeader("Status");
				if ((message.length == null) || (message.length <= 0)) 
				{
				alert("Error! Request status is " + httpRequest.status);
				} else  {
						alert(message);
						}
				} }

	}

/*      **********
*/

function adminResetContactInfo()
	{
		document.sports.schoolname.value = "";
		document.sports.contact.value = "";
		document.sports.address.value = "";
		document.sports.city.value = "";
		document.sports.zipcode.value = "";
		document.sports.phone.value = "";
		document.sports.dayphone.value = "";
		document.sports.ext1.value = "";
		document.sports.ext2.value = "";
		document.sports.fax.value = "";
		document.sports.email.value = "";
	}

function getResetCartVars(url)
	{
		answer = confirm(' You are about to Reset the Entire Order');
			if(!answer){
				return false;
			}else{
// alert('url is '+url);
	    	     httpRequest.open("POST", url, true);
	    	     httpRequest.onreadystatechange = getResetCartVars2;
    		     httpRequest.send(null);
			}
	}
function getResetCartVars2()
	{
		if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) 
			{
				var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
				document.getElementById("temporderno").innerHTML = 0;
				location.href="http://www.x-grain.com/a/order.php";
			} else {
			var message = httpRequest.getResponseHeader("Status");
				if ((message.length == null) || (message.length <= 0)) 
				{
				alert("Error! Request status is " + httpRequest.status);
				} else  {
						alert(message);
						}
				} }

	}

function getAddtoCart1(id)
	{
		if (!document.getElementByID || !document.createTextNode) {
		var findsetno = id.split("_"); // split id into array
		var setno = findsetno[1]; // assign setno to 2nd array value
		checkform('sports');
		if (document.getElementById(id).options[0].selected==true && document.getElementById(id).options[0].selected!="") {alert('Please select a Garment for ' + id); return false;}
			var grmno = document.getElementById(id).value; // value of garment selected	
		if (document.getElementById('grmclr_' + setno).options[0].selected==true) {alert('Please select a Garment Color for ' + id); return false;}
			var clrno = document.getElementById('grmclr_' + setno).value; // value of garment color selected
		if (document.getElementById('frontstyle_' + setno).options[0].selected==true) {alert('Please select a Front Style for ' + id); return false;}
			var frntno = document.getElementById('frontstyle_' + setno).value; // value of frontstyle selected
		if (document.getElementById('lclogo_' + setno).options[0].selected==true) {alert('Please select a Sport for ' + id); return false;}
		if (document.getElementById('mascot_' + setno).value=="") {alert('Please select a Mascot Name for ' + id ); return false;}
		if (document.getElementById('fcolor_' + setno).options[0].selected==true) {alert('Please select a Fore Color for ' + id ); return false;}
		if (document.getElementById('bcolor_' + setno).options[0].selected==true) {alert('Please select a Back Color for ' + id ); return false;}
		if (document.getElementById('fcolor_' + setno).value == document.getElementById('bcolor_' + setno).value) {alert('Both Fore Color and Back Color are the Same for ' + id ); return false;}
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
		if (qtypaid<=0 || isNaN(parseInt(qtypaid))) 
			{
			document.getElementById('qtypaid_' + setno).value = 1;
			alert('Please Enter a Qty PAID for ' + id );
			return false;
			}
		getItemPriceLoad1(setno, grmno, clrno, frntno);
		}
		} // end function getAddtoCart1
		
function getItemPriceLoad1(setno, grmno, clrno, frntno) 
	{
        var url = "http://www.x-grain.com/a/getItemPriceLoadXML.php?setno="+setno+"&grmno="+grmno+"&clrno="+clrno+"&frntno="+frntno;
		httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processItemPriceLoad1fromXML;
         httpRequest.send(null);
		} // end function getItemPriceLoad1

function processItemPriceLoad1fromXML()
	{
		if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) 
			{
			var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
			var recs = xmldoc.getElementsByTagName( 'fronts' );
		var grmtbl = new Array();
		var setno1 = new Array();
		setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = setno1[0];
		grmtbl[0]  = xmldoc.getElementsByTagName( 'tblblock' )[0].firstChild.nodeValue;
		var arraystring = grmtbl[0];
			var id = 'garment_'+setno;
			var grmno = document.getElementById(id).value; // value of garment selected	
			var grmclr = document.getElementById('grmclr_' + setno).value; // value of garment color selected
			var frntno = document.getElementById('frontstyle_' + setno).value; // value of frontstyle selected
			var lclogo = document.getElementById('lclogo_' + setno).value; // value of lclogo selected
			var mascot = document.getElementById('mascot_' + setno).value; // value of mascot entered
			var fcolor = document.getElementById('fcolor_' + setno).value; // value of fore color selected
			var bcolor = document.getElementById('bcolor_' + setno).value; // value of back color selected
			var fg = document.getElementById('fg_' + setno).value;
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
			var arrayline = new Array();
			var arrayline = arraystring.split("#");
			var arrayitems = new Array();
			var arraycompare = new Array();
			var arrayprice = new Array();
			var arraylinelen = arrayline.length;
			for (j=0 ; j < (arraylinelen) ; j++) 
			{
				arrayitems = arrayline[j].split(";");
				arraycompare[j] = arrayitems[0]+';'+arrayitems[1]+';'+arrayitems[2]+';'+arrayitems[3];
				arrayprice[j] = arrayitems[4];
			}
		var carttable = "";
		var cartcont = document.getElementById('shopping_cart').innerHTML;
		var cartfirst = cartcont.substr(0,7);
		if( cartfirst == '<CENTER' || cartfirst == '<center') {
			document.getElementById('shopping_cart').innerHTML = " ";
			if(document.getElementById('finalizeorder')) var orderstatus = document.getElementById('finalizeorder').innerHTML;
			if(orderstatus == '') setOrderStatus();
			var x = document.getElementById(id);
			var grmdescr = x.options[x.selectedIndex].text;
			x = document.getElementById('grmclr_' + setno);
			var garmclr = x.options[x.selectedIndex].text;
			x = document.getElementById('frontstyle_' + setno);
			var frtstyl = x.options[x.selectedIndex].text;
			carttable = "\n"+'<div id="cartset_'+setno+'">'+"\n";
		}else{
			carttable = document.getElementById('shopping_cart').innerHTML;
			if(document.getElementById('finalizeorder')) var orderstatus = document.getElementById('finalizeorder').innerHTML;
			if(orderstatus == '') setOrderStatus();
			var x = document.getElementById(id);
			var grmdescr = x.options[x.selectedIndex].text;
			x = document.getElementById('grmclr_' + setno);
			var garmclr = x.options[x.selectedIndex].text;
			x = document.getElementById('frontstyle_' + setno);
			var frtstyl = x.options[x.selectedIndex].text;
			carttable += "\n"+'<div id="cartset_'+setno+'">'+"\n";
		}
/* ***** 1 ***** */
			var cartvars_value=setno+';'+grmno+';'+grmclr+';'+frntno+';'+lclogo+';'+mascot+';'+fcolor+';'+bcolor+';1';
			carttable += '	<table width="100%">'+"\n";
			carttable += '	<tbody>'+"\n";
			carttable += '		<tr onMouseOver="this.bgColor=\'#CCFFFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'+"\n";
			carttable += '		<td>'+"\n";
			carttable += '			<span id="setlabel_'+setno+'" class="formlabelblackbold">Set: '+setno+'.</td>'+"\n";
			carttable += '		<td class="formlabelblackbold">'+"\n";
//			carttable += '<input id="cartvars_'+setno+'" name="cartvars_'+setno+'" value="'+setno+';'+grmno+';'+grmclr+';'+frntno+';'+lclogo+';'+mascot+';'+fcolor+';'+bcolor+'" type="hidden">'+grmdescr+' - '+garmclr+'</td>'+"\n";
			carttable += '<input id="cartvars_'+setno+'" name="cartvars_'+setno+'" value="'+cartvars_value+'" type="hidden">'+grmdescr+' - '+garmclr+'</td>'+"\n";

			carttable += '		<td><span id="frontstyle_'+setno+'" class="formlabelblackbold">'+frtstyl+'</span>'+"\n";
			carttable += '			<span id="chgfrontstyle_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgfrontstyle(\'frontstyle_'+setno+'\',\'1\'))" title="Change Front Style">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change front style"></a></span></td>'+"\n";

			carttable += '		<td><span id="mascot_'+setno+'" class="formlabelblackbold">'+mascot+'</span>'+"\n";
			carttable += '			<span id="chgmascot_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgmascot(\'mascot_'+setno+'\',\'1\'))" title="Change Mascot">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change mascot"></a></span></td>'+"\n";

			carttable += '		<td><span id="lclogo_'+setno+'" class="formlabelblackbold">'+lclogo+'</span>'+"\n";
			carttable += '			<span id="chglclogo_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chglclogo(\'lclogo_'+setno+'\',\'1\'))" title="Change Sport">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change sport"></a></span></td>'+"\n";
			carttable += '		<td><span id="fcolor_'+setno+'" class="formlabelblackbold">'+fcolor+'</span>'+"\n";
			carttable += '			<span id="chgfcolor_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgfcolor(\'fcolor_'+setno+'\',\'1\'))" title="Change Fore Color">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change Fore Color"></a></span></td>'+"\n";
			carttable += '		<td><span id="bcolor_'+setno+'" class="formlabelblackbold">'+bcolor+'</span>'+"\n";
			carttable += '			<span id="chgbcolor_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgbcolor(\'bcolor_'+setno+'\',\'1\'))" title="Change Back Color">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change Back Color"></a></span></td>'+"\n";
			carttable += '		<td align="right" width="60"><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> -->'+"\n";
			carttable += '<!--			<span id="del_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelsmall" href="javascript:void(onclick=setdel(\'set_'+setno+'\'))" title="Delete Set">'+"\n";
			carttable += '				<img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete set"></a></span> -->'+"\n";
			carttable += '		</tr>'+"\n";
			carttable += '	</tbody>'+"\n";
			carttable += '	</table>'+"\n\n";
			
			carttable += '	<table id="table_'+setno+'">'+"\n";
			carttable += '	<tbody>'+"\n";
			carttable += '		<tr>'+"\n";
			carttable += '		<td width="235"></td>'+"\n";
			carttable += '		<td width="40" align="center"><u>Line</u></td>'+"\n";
			carttable += '		<td width="40" align="center"><u>Qty</u></td>'+"\n";
			carttable += '		<td width="105" align="center"><u>Size</u></td>'+"\n";
			carttable += '		<td width="260"><u>Name</u></td>'+"\n";
			carttable += '		<td width="60"><u>Number</u></td>'+"\n";
			carttable += '		<td width="75" align="right"><u>Price</u></td>'+"\n";
			carttable += '		<td width="30" align="center"><u>Free</u></td>'+"\n";
			carttable += '		<td width="60"></td>'+"\n";
			carttable += '		</tr>'+"\n\n";
		var sizearray = new Array();
		var namearray = new Array();
		var noarray = new Array();
		var itemprice = "";
		var i = 1;
		while(i <= qtypaid){
				carttable += '		<tr id="tr_'+setno+'_'+i+'" onMouseOver="this.bgColor=\'#CCCCFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">';
			if (document.getElementById('size_'+setno+'_'+i).options[0].selected==true) {alert('Please select a Size for Line ' + i); return false;}
				carttable += '<td width="235" align="right"><input id="itemid_'+setno+'_'+i+'" value="0" type="hidden"><input id="styleno_'+setno+'" value="1" type="hidden"></td>';
				carttable += '<td width="40" align="center">';
				carttable += '<span id="line_'+setno+'_'+i+'" className="formlabelgray" class="formlabelgray">'+i+'</span></td>';
				carttable += '<td width="40" align="center">';
				var qty = 1;
				carttable += '<span id="qty_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">1</span></td>'+"\n\t\t\t";
			sizearray[i] = document.getElementById('size_'+setno+'_'+i).value;
			if (document.getElementById('size_'+setno+'_'+i).options[0].selected!=true) {sizearray[i] = document.getElementById('size_'+setno+'_'+i).value;}
				carttable += '<td align="left" width="105">';
				carttable += '<span id="size_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">'+sizearray[i]+'</span>';
				carttable += '<span id="chgsize_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">';
				carttable += '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgsize(\'csize_'+setno+'_'+i+'\',\'1\'))" title="Change Size">';
				carttable += '<img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change size"></a></span></td>'+"\n\t\t\t";
			namearray[i] = document.getElementById('name_'+ setno + '_' + i).value;
				if(namearray[i] == ""){
					carttable += '<td align="left" width="260">';
					carttable += '<span id="name_'+setno+'_'+i+'" className="formlabelreditalic" class="formlabelreditalic">(none)</span>';
					carttable += '<span id="chgname_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">';
					carttable += '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgname(\'name_'+setno+'_'+i+'\',\'1\'))" title="Change Name">';
					carttable += '<img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change name"></a></span></td>'+"\n\t\t\t";
				} else{
					carttable += '<td align="left" width="260">';
					carttable += '<span id="name_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">'+namearray[i]+'</span>';
					carttable += '<span id="chgname_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">';
					carttable += '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgname(\'name_'+setno+'_'+i+'\',\'1\'))" title="Change Name">';
					carttable += '<img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change name"></a></span></td>'+"\n\t\t\t";
				}
			noarray[i] = document.getElementById('no_'+ setno + '_' + i).value;
				if(noarray[i] == ""){
					carttable += '<td align="left" width="60">';
					carttable += '<span id="no_'+setno+'_'+i+'" className="formlabelreditalic" class="formlabelreditalic">(none)</span>';
					carttable += '<span id="chgno_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">'
					carttable += '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgno(\'cno_'+setno+'_'+i+'\',\'1\'))" title="Change Number">';
					carttable += '<img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change number"></a></span></td>'+"\n\t\t\t";
				}else{
					carttable += '<td align="left" width="60">';
					carttable += '<span id="no_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">'+noarray[i]+'</span>';
					carttable += '<span id="chgno_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">';
					carttable += '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgno(\'cno_'+setno+'_'+i+'\',\'1\'))" title="Change Number">';
					carttable += '<img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change number"></a></span></td>'+"\n\t\t\t";
				}
					carttable += '<td align="right" width="75">';
		var hasnameno = 0;
		var priceshow = 0;
		if (namearray[i] || noarray[i]) hasnameno = 1;
		var valuecompare = grmno+';'+frntno.substr(0,1)+';'+sizearray[i]+';'+hasnameno;
		for (k=0 ; k < (arraylinelen) ; k++) 
			{
				if ( valuecompare == arraycompare[k] ) {
					priceshow = arrayprice[k];
					}
			}
					carttable += '<span id="price_'+setno+'_'+i+'" className="formlabelprice" class="formlabelprice">$'+priceshow+'</span></td>'+"\n\t\t\t";
					carttable += '<td align="center" className="formlabelfree" class="formlabelfree" width="30"><input type="checkbox" id="free_'+setno+'_'+i+'" name="nfree_'+setno+'_'+i+'" value=""  onClick="setFG(\'free_'+setno+'_'+i+'\');">'+"\n";
				if(document.getElementById('ordernumber')) {
					 carttable += '<input id="trvals_'+setno+'_'+i+'" name="trvals_'+setno+'_'+i+'" value="'+setno+';'+i+';1;'+sizearray[i]+';'+namearray[i]+';'+noarray[i]+';'+fg+';'+priceshow+';0;0" type="hidden"></td>'+"\n\t\t\t";
					}else{
/* ***** 1 ***** */
					 if(i==1){
							 var trvals_value = setno+';'+i+';1;'+sizearray[i]+';'+namearray[i]+';'+noarray[i]+';'+fg+';'+priceshow;
							}else{
							 trvals_value += '!#!'+setno+';'+i+';1;'+sizearray[i]+';'+namearray[i]+';'+noarray[i]+';'+fg+';'+priceshow;
							}


					 carttable += '<input id="trvals_'+setno+'_'+i+'" name="trvals_'+setno+'_'+i+'" value="'+setno+';'+i+';1;'+sizearray[i]+';'+namearray[i]+';'+noarray[i]+';'+fg+';'+priceshow+'" type="hidden"></td>'+"\n\t\t\t";
					}
					carttable += '<td align="left" width="30"><span><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> --></span>';
					carttable += '<!-- <span id="del_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">';
					carttable += '<a className="formlabelsmall" class="formlabelsmall" href="javascript:void(onclick=itemdel(\'tr_'+setno+'_'+i+'\'))" title="Delete Item">';
					carttable += '<img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete item"></a></span> --></td>'+"\n\t\t\t";
					i++;
					carttable += '</tr>'+"\n\n";
			}
				carttable += '		<tr id="tr_'+setno+'_'+i+'" onMouseOver="this.bgColor=\'#CCCCFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">';
					carttable += '		<td width="235"></td>'+"\n";
					carttable += '		<td width="40" align="center"><span id="line_'+setno+'_'+i+'" class="formlabelgray"></span></td>'+"\n";
					carttable += '		<td width="40" align="center"><span id="qty_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="105" align="center"><span id="size_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="260"><span id="name_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="60"><span id="no_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="75" align="right"><span id="price_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="30" align="center"><span id="free_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="60" align="left"><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> -->'+"\n";
					carttable += '				<span id="add_'+setno+'_'+i+'">'+"\n";
					carttable += '					<a class="formlabelsmall" href="javascript:void(onclick=itemadd(\'tr_'+setno+'_'+i+'\'))">'+"\n";
					carttable += '					<img src="http://www.x-grain.com/images/nav/itemaddblue.gif" alt="add item to this set"></a></span></td>'+"\n";
					carttable += '	</tr>'+"\n";
				carttable += '	</tbody>'+"\n";
				carttable += '	</table>'+"\n";
				carttable += '<!-- end cartset div --></div>'+"\n";
				document.getElementById('shopping_cart').innerHTML = carttable;
/* ***** 1 ***** */
/*
				var existing_cartvars = getCookieValue('cartvars');
				if(existing_cartvars)
					{
						var new_cartvars = existing_cartvars+'!@!'+ cartvars_value;
						writeSessionCookie('cartvars',new_cartvars);
					}else{
						writeSessionCookie('cartvars',cartvars_value);
					}
				var existing_trvals = getCookieValue('trvals');
				if(existing_trvals)
					{
						var new_trvals = existing_trvals+'!@!'+ trvals_value;
						writeSessionCookie('trvals',new_trvals);
					}else{
						writeSessionCookie('trvals',trvals_value);
					}
*/

				var nextset = parseInt(setno) + 1;
				document.getElementById('garmenttbl_' + setno).innerHTML = "Please wait.......";
				document.getElementById('garmenttbl_' + setno).setAttribute('id','garmenttbl_'+nextset);
	getGarment(nextset,0);
			} else {
				var message = httpRequest.getResponseHeader("Status");
				if ((message.length == null) || (message.length <= 0)) 
				{
				alert("Error! Request status is " + httpRequest.status);
				} else  {
						alert(message);
						}
				} }
	}  // end function getAddtoCart1() to getItemPriceLoad1() to processItemPriceLoad1fromXML()		
		
 
		
		
function getAddtoCart2(id)
	{
		if (!document.getElementByID || !document.createTextNode) {
		var findsetno = id.split("_"); // split id into array
		var setno = findsetno[1]; // assign setno to 2nd array value
		checkform('sports');
		if (document.getElementById(id).options[0].selected==true && document.getElementById(id).options[0].selected!="") {alert('Please select a Garment for ' + id); return false;}
			var grmno = document.getElementById(id).value; // value of garment selected
		if (document.getElementById('grmclr_' + setno).options[0].selected==true) {alert('Please select a Garment Color for ' + id); return false;}
			var clrno = document.getElementById('grmclr_' + setno).value; // value of garment color selected
		if (document.getElementById('frontstyle_' + setno).options[0].selected==true) {alert('Please select a Front Style for ' + id); return false;}
			var frntno = document.getElementById('frontstyle_' + setno).value; // value of frontstyle selected
		if (document.getElementById('lclogo_' + setno).options[0].selected==true) {alert('Please select a Sport for ' + id); return false;}
		if (document.getElementById('mascot_' + setno).value=="") {alert('Please select a Mascot Name for ' + id ); return false;}
		if (document.getElementById('fcolor_' + setno).options[0].selected==true) {alert('Please select a Fore Color for ' + id ); return false;}
		if (document.getElementById('bcolor_' + setno).options[0].selected==true) {alert('Please select a Back Color for ' + id ); return false;}
		if (document.getElementById('fcolor_' + setno).value == document.getElementById('bcolor_' + setno).value) {alert('Both Fore Color and Back Color are the Same for ' + id ); return false;}
		if (document.getElementById('qtypaid_' + setno).value=="") {alert('Please Enter a Qty PAID for ' + id ); return false;}
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
			var tot_ent = document.getElementById('tot_ent').innerHTML; // value of Entered
		if ( qtypaid != tot_ent) {alert('Qty PAID and Total ENTERED do not Match for ' + id ); return false;}

		getItemPriceLoad2(setno, grmno, clrno, frntno);
		}
		} // end function getAddtoCart2		

function getItemPriceLoad2(setno, grmno, clrno, frntno) 
	{
        var url = "http://www.x-grain.com/a/getItemPriceLoadXML.php?setno="+setno+"&grmno="+grmno+"&clrno="+clrno+"&frntno="+frntno;
		httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processItemPriceLoad2fromXML;
         httpRequest.send(null);
		} // end function getItemPriceLoad2

function processItemPriceLoad2fromXML()
	{
		if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) 
			{
			var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
			var recs = xmldoc.getElementsByTagName( 'fronts' );
		var grmtbl = new Array();
		var setno1 = new Array();
		setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = setno1[0];
		grmtbl[0]  = xmldoc.getElementsByTagName( 'tblblock' )[0].firstChild.nodeValue;
		var arraystring = grmtbl[0];
			var id = 'garment_'+setno;
			var grmno = document.getElementById(id).value; // value of garment selected	
			var grmclr = document.getElementById('grmclr_' + setno).value; // value of garment color selected
			var frntno = document.getElementById('frontstyle_' + setno).value; // value of frontstyle selected
			var lclogo = document.getElementById('lclogo_' + setno).value; // value of lclogo selected
			var mascot = document.getElementById('mascot_' + setno).value; // value of mascot entered
			var fcolor = document.getElementById('fcolor_' + setno).value; // value of fore color selected
			var bcolor = document.getElementById('bcolor_' + setno).value; // value of back color selected
			var fg = document.getElementById('fg_' + setno).value;
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
			var arrayline = new Array();
			var arrayline = arraystring.split("#");
			var arrayitems = new Array();
			var arraycompare = new Array();
			var arrayprice = new Array();
			var arraylinelen = arrayline.length;
			for (j=0 ; j < (arraylinelen) ; j++) 
			{
				arrayitems = arrayline[j].split(";");
				arraycompare[j] = arrayitems[0]+';'+arrayitems[1]+';'+arrayitems[2]+';'+arrayitems[3];
				arrayprice[j] = arrayitems[4];
			}
		var carttable = "";
		var cartcont = document.getElementById('shopping_cart').innerHTML;
		var cartfirst = cartcont.substr(0,7);
		if( cartfirst == '<CENTER' || cartfirst == '<center') {
			document.getElementById('shopping_cart').innerHTML = " ";
			if (document.getElementById('finalizeorder')) var orderstatus = document.getElementById('finalizeorder').innerHTML;
			if(orderstatus == '') setOrderStatus();
			var x = document.getElementById(id);
			var grmdescr = x.options[x.selectedIndex].text;
			x = document.getElementById('grmclr_' + setno);
			var garmclr = x.options[x.selectedIndex].text;
			x = document.getElementById('frontstyle_' + setno);
			var frtstyl = x.options[x.selectedIndex].text;
			carttable = "\n"+'<div id="cartset_'+setno+'">'+"\n";
		}else{
			carttable = document.getElementById('shopping_cart').innerHTML;
			if(document.getElementById('finalizeorder')) var orderstatus = document.getElementById('finalizeorder').innerHTML;
			if(orderstatus == '') setOrderStatus();
			var x = document.getElementById(id);
			var grmdescr = x.options[x.selectedIndex].text;
			x = document.getElementById('grmclr_' + setno);
			var garmclr = x.options[x.selectedIndex].text;
			x = document.getElementById('frontstyle_' + setno);
			var frtstyl = x.options[x.selectedIndex].text;
			carttable += "\n"+'<div id="cartset_'+setno+'">'+"\n";
		}
/* ***** 2 ***** */
			var cartvars_value=setno+';'+grmno+';'+grmclr+';'+frntno+';'+lclogo+';'+mascot+';'+fcolor+';'+bcolor+';2';
			carttable += '	<table width="100%">'+"\n";
			carttable += '	<tbody>'+"\n";
			carttable += '		<tr onMouseOver="this.bgColor=\'#CCFFFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'+"\n";
			carttable += '		<td>'+"\n";
			carttable += '			<span id="setlabel_'+setno+'" class="formlabelblackbold">Set: '+setno+'.</td>'+"\n";
			carttable += '		<td class="formlabelblackbold">'+"\n";
//			carttable += '<input type="hidden" id="cartvars_'+setno+'" name="cartvars_'+setno+'" value="'+setno+';'+grmno+';'+grmclr+';'+frntno+';'+lclogo+';'+mascot+';'+fcolor+';'+bcolor+'">'+grmdescr+' - '+garmclr+'</td>'+"\n";
			carttable += '<input id="cartvars_'+setno+'" name="cartvars_'+setno+'" value="'+cartvars_value+'" type="hidden">'+grmdescr+' - '+garmclr+'</td>'+"\n";

			carttable += '		<td><span id="frontstyle_'+setno+'" class="formlabelblackbold">'+frtstyl+'</span>'+"\n";
			carttable += '			<span id="chgfrontstyle_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgfrontstyle(\'frontstyle_'+setno+'\',\'1\'))" title="Change Front Style">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change front style"></a></span></td>'+"\n";
			carttable += '		<td><span id="mascot_'+setno+'" class="formlabelblackbold">'+mascot+'</span>'+"\n";
			carttable += '			<span id="chgmascot_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgmascot(\'mascot_'+setno+'\',\'1\'))" title="Change Mascot">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change mascot"></a></td>'+"\n";
			carttable += '		<td><span id="lclogo_'+setno+'" class="formlabelblackbold">'+lclogo+'</span>'+"\n";
			carttable += '			<span id="chglclogo_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chglclogo(\'lclogo_'+setno+'\',\'1\'))" title="Change Sport">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change sport"></a></td>'+"\n";
			carttable += '		<td><span id="fcolor_'+setno+'" class="formlabelblackbold">'+fcolor+'</span>'+"\n";
			carttable += '			<span id="chgfcolor_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgfcolor(\'fcolor_'+setno+'\',\'1\'))" title="Change Fore Color">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change Fore Color"></a></td>'+"\n";
			carttable += '		<td><span id="bcolor_'+setno+'" class="formlabelblackbold">'+bcolor+'</span>'+"\n";
			carttable += '			<span id="chgbcolor_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgbcolor(\'bcolor_'+setno+'\',\'1\'))" title="Change Back Color">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change Back Color"></a></td>'+"\n";
			carttable += '		<td width="60" align="right"><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> -->'+"\n";
			carttable += '<!--			<span id="del_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelsmall" href="javascript:void(onclick=setdel(\'set_'+setno+'\'))">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete set"></a></span>-->'+"\n";
			carttable += '		</tr>'+"\n";
			carttable += '	</tbody>'+"\n";
			carttable += '	</table>'+"\n\n";
			carttable += '	<table id="table_'+setno+'">'+"\n";
			carttable += '	<tbody>'+"\n";
			carttable += '		<tr>'+"\n";
			carttable += '		<td width="235"></td>'+"\n";
			carttable += '		<td width="40" align="center"><u>Line</u></td>'+"\n";
			carttable += '		<td width="40" align="center"><u>Qty</u></td>'+"\n";
			carttable += '		<td width="105" align="center"><u>Size</u></td>'+"\n";
			carttable += '		<td width="260" align="left"><u>Name</u></td>'+"\n";
			carttable += '		<td width="60" align="left"><u>Number</u></td>'+"\n";
			carttable += '		<td width="75" align="right"><u>Price</u></td>'+"\n";
			carttable += '		<td width="30" align="center"><u>Free</u></td>'+"\n";
			carttable += '		<td width="60"></td>'+"\n";
			carttable += '		</tr>'+"\n";
		var cartlbl = "";
		var cartqty = "";
		var lineno = 0;
		var i = 1;
		while(i <= 8){
			if(document.getElementById('qty_' + i))
				{
				if (document.getElementById('qty_' + i).value>0) 
					{
						cartlbl = document.getElementById('qty_' + i).name;
						cartqty = document.getElementById('qty_' + i).value;
					for(m=1 ; m <= cartqty ; m++) 
					{	
						lineno++;
						carttable += '		<tr id="tr_'+setno+'_'+lineno+'" onMouseOver="this.bgColor=\'#CCCCFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'+"\n";
						carttable += '			<td align="right" width="235"><input id="itemid_'+setno+'_'+lineno+'" value="0" type="hidden"><input id="styleno_'+setno+'" value="2" type="hidden"></td>'+"\n";
						carttable += '			<td width="40" align="center">'+"\n";
						carttable += '				<span id="line_'+setno+'_'+lineno+'" className="formlabelgray" class="formlabelgray">'+lineno+'</span></td>'+"\n";
						carttable += '			<td width="40" align="center">'+"\n";
						carttable += '				<span id="qty_'+setno+'_'+lineno+'" className="formlabelblackbold" class="formlabelblackbold">1</span></td>'+"\n";
						carttable += '			<td width="105" align="left">'+"\n";
						carttable += '				<span id="size_'+setno+'_'+lineno+'" className="formlabelblackbold" class="formlabelblackbold">'+cartlbl+'</span>'+"\n";
						carttable += '				<span id="chgsize_'+setno+'_'+lineno+'" className="formlabelblackbold" class="formlabelblackbold">'+"\n";
						carttable += '					<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgsize(\'csize_'+setno+'_'+lineno+'\',\'2\'))" title="Change Size">'+"\n";
						carttable += '					 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change size"></a></span></td>'+"\n";
						carttable += '			<td width="260" align="left">'+"\n";
						carttable += '				<span id="name_'+setno+'_'+lineno+'" className="formlabelreditalic" class="formlabelreditalic">(n/a)</span></td>'+"\n";
						carttable += '			<td width="60" align="left">'+"\n";
						carttable += '				<span id="no_'+setno+'_'+lineno+'" className="formlabelreditalic" class="formlabelreditalic">(n/a)</span></td>'+"\n";
						carttable += '			<td width="75" align="right">'+"\n";
							var hasnameno = 0;
							var priceshow = 0;
							var priceshow1 = 0;
							var valuecompare = grmno+';'+frntno.substr(0,1)+';'+cartlbl+';'+hasnameno;
								for (k=0 ; k < (arraylinelen) ; k++) 
								{
									if ( valuecompare == arraycompare[k] ) 
									{
										priceshow1 = (arrayprice[k] * 1);
										priceshow = CurrencyFormatted(priceshow1);
									}
								}
						carttable += '				<span id="price_'+setno+'_'+lineno+'" className="formlabelprice" class="formlabelprice">$'+priceshow+'</span></td>'+"\n";
						carttable += '			<td width="30" align="center" className="formlabelfree" class="formlabelfree"><input type="checkbox" id="free_'+setno+'_'+lineno+'" name="nfree_'+setno+'_'+lineno+'" value=""  onClick="setFG(\'free_'+setno+'_'+lineno+'\');">'+"\n";
					if(document.getElementById('ordernumber')) {
						carttable += '<input id="trvals_'+setno+'_'+lineno+'" name="trvals_'+setno+'_'+lineno+'" value="'+setno+';'+lineno+';1;'+cartlbl+';;;0;'+priceshow+';0;0" type="hidden"></td>'+"\n";
						}else{
/* ***** 2 ***** */
					 if(lineno==1){
							 var trvals_value = setno+';'+lineno+';1;'+cartlbl+';;;0;'+priceshow;
							}else{
							 trvals_value += '!#!'+setno+';'+lineno+';1;'+cartlbl+';;;0;'+priceshow;
							}


						carttable += '<input id="trvals_'+setno+'_'+lineno+'" name="trvals_'+setno+'_'+lineno+'" value="'+setno+';'+lineno+';1;'+cartlbl+';;;0;'+priceshow+'" type="hidden"></td>'+"\n";
						}
						carttable += '			<td width="60" align="left"><span><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> --></span>'+"\n";
						carttable += '<!--				<span id="del_'+setno+'_'+lineno+'" className="formlabelblackbold" class="formlabelblackbold">'+"\n";
						carttable += '					<a className="formlabelsmall"  class="formlabelsmall" href="javascript:void(onclick=itemdel(\'tr_'+setno+'_'+lineno+'\'))" title="Delete Item">'+"\n";
						carttable += '					 <img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete item"></a></span>--></td>'+"\n";
						carttable += '		</tr>'+"\n\n";
					} // end for loop each item
					} // end if value gt 0
				} // end if value exist
				i++;
			}  // end while loop by size 
					lineno++;
					carttable += '		<tr id="tr_'+setno+'_'+lineno+'" onMouseOver="this.bgColor=\'#CCCCFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'+"\n";
					carttable += '		<td width="235"></td>'+"\n";
					carttable += '		<td width="40" align="center"><span id="line_'+setno+'_'+lineno+'" class="formlabelgray"></span></td>'+"\n";
					carttable += '		<td width="40" align="center"><span id="qty_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="105" align="center"><span id="size_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="260" align="left"><span id="name_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="60" align="left"><span id="no_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="75" align="right"><span id="price_'+setno+'_'+lineno+'" className="formlabelblackbold" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="30" align="center"><span id="free_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="60" align="left"><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> -->'+"\n";
					carttable += '				<span id="add_'+setno+'_'+lineno+'">'+"\n";
					carttable += '					<a class="formlabelsmall" href="javascript:void(onclick=itemadd(\'tr_'+setno+'_'+lineno+'\'))">'+"\n";
					carttable += '					<img src="http://www.x-grain.com/images/nav/itemaddblue.gif" alt="add item to this set"></a></span></td>'+"\n";
					carttable += '	</tr>'+"\n";
					carttable += '	</tbody>'+"\n";
					carttable += '	</table>'+"\n";
					carttable += '<!-- end cartset div --></div>'+"\n";
		document.getElementById('shopping_cart').innerHTML = carttable;

/* ***** 2 ***** */
/*
				var existing_cartvars = getCookieValue('cartvars');
				if(existing_cartvars)
					{
						var new_cartvars = existing_cartvars+'!@!'+ cartvars_value;
						writeSessionCookie('cartvars',new_cartvars);
					}else{
						writeSessionCookie('cartvars',cartvars_value);
					}
				var existing_trvals = getCookieValue('trvals');
				if(existing_trvals)
					{
						var new_trvals = existing_trvals+'!@!'+ trvals_value;
						writeSessionCookie('trvals',new_trvals);
					}else{
						writeSessionCookie('trvals',trvals_value);
					}
*/
		var nextset = parseInt(setno) + 1;
			document.getElementById('garmenttbl_' + setno).innerHTML = "Please wait.......";
			document.getElementById('garmenttbl_' + setno).setAttribute('id','garmenttbl_'+nextset);
			getGarment(nextset,0);	
			} }
	} // end function getAddtoCart2() to getItemPriceLoad2() to processItemPriceLoad2fromXML()
		
function getAddtoCart3(id)
	{
		if (!document.getElementByID || !document.createTextNode) {
		var findsetno = id.split("_"); // split id into array
		var setno = findsetno[1]; // assign setno to 2nd array value
		checkform('sports');
		if (document.getElementById(id).options[0].selected==true && document.getElementById(id).options[0].selected!="") {alert('Please select a Garment for ' + id); return false;}
			var grmno = document.getElementById(id).value; // value of garment selected
		if (document.getElementById('grmclr_' + setno).options[0].selected==true) {alert('Please select a Garment Color for ' + id); return false;}
			var clrno = document.getElementById('grmclr_' + setno).value; // value of garment color selected
		if (document.getElementById('frontstyle_' + setno).options[0].selected==true) {alert('Please select a Front Style for ' + id); return false;}
			var frntno = document.getElementById('frontstyle_' + setno).value; // value of frontstyle selected
		if (document.getElementById('lclogo_' + setno).options[0].selected==true) {alert('Please select a Sport for ' + id); return false;}
			var lclogo = document.getElementById('lclogo_' + setno).value; // value of lclogo selected
		if (document.getElementById('mascot_' + setno).value=="") {alert('Please select a Mascot Name for ' + id ); return false;}
			var mascot = document.getElementById('mascot_' + setno).value; // value of mascot entered
		if (document.getElementById('fcolor_' + setno).options[0].selected==true) {alert('Please select a Fore Color for ' + id ); return false;}
			var fcolor = document.getElementById('fcolor_' + setno).value; // value of fore color selected
		if (document.getElementById('bcolor_' + setno).options[0].selected==true) {alert('Please select a Back Color for ' + id ); return false;}
			var bcolor = document.getElementById('bcolor_' + setno).value; // value of back color selected
		if (document.getElementById('fcolor_' + setno).value == document.getElementById('bcolor_' + setno).value) {alert('Both Fore Color and Back Color are the Same for ' + id ); return false;}
		if (document.getElementById('qtypaid_' + setno).value=="") {alert('Please Enter a Qty PAID for ' + id ); return false;}
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
			var tot_ent = document.getElementById('tot_ent').innerText; // value of Entered			
		getItemPriceLoad3(setno, grmno, clrno, frntno);
		}
	} // end function getAddtoCart3

function getItemPriceLoad3(setno, grmno, clrno, frntno) 
	{
        var url = "http://www.x-grain.com/a/getItemPriceLoadXML.php?setno="+setno+"&grmno="+grmno+"&clrno="+clrno+"&frntno="+frntno;
		httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processItemPriceLoad3fromXML;
         httpRequest.send(null);
		} // end function getItemPriceLoad3

function processItemPriceLoad3fromXML()
	{
		if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) 
			{
			var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
			var recs = xmldoc.getElementsByTagName( 'fronts' );
		var grmtbl = new Array();
		var setno1 = new Array();

//		setno1[0]   = xmldoc.getElementsByTagName('setno').childNode[0].nodeValue;
		setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = setno1[0];
		grmtbl[0]  = xmldoc.getElementsByTagName( 'tblblock' )[0].firstChild.nodeValue;
		var arraystring = grmtbl[0];
			var id = 'garment_'+setno;
			var grmno = document.getElementById(id).value; // value of garment selected
			var grmclr = document.getElementById('grmclr_' + setno).value; // value of garment color selected
			var frntno = document.getElementById('frontstyle_' + setno).value; // value of frontstyle selected
			var lclogo = document.getElementById('lclogo_' + setno).value; // value of lclogo selected
			var mascot = document.getElementById('mascot_' + setno).value; // value of mascot entered
			var fcolor = document.getElementById('fcolor_' + setno).value; // value of fore color selected
			var bcolor = document.getElementById('bcolor_' + setno).value; // value of back color selected
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
			var arrayline = new Array();
			var arrayline = arraystring.split("#");
			var arrayitems = new Array();
			var arraycompare = new Array();
			var arrayprice = new Array();
			var arraylinelen = arrayline.length;
			for (j=0 ; j < (arraylinelen) ; j++) 
			{
				arrayitems = arrayline[j].split(";");
				arraycompare[j] = arrayitems[0]+';'+arrayitems[1]+';'+arrayitems[2]+';'+arrayitems[3];
				arrayprice[j] = arrayitems[4];
			}
		var carttable = "";
		var cartcont = document.getElementById('shopping_cart').innerHTML;
		var cartfirst = cartcont.substr(0,7);
		if( cartfirst == '<CENTER' || cartfirst == '<center') {
			document.getElementById('shopping_cart').innerHTML = " ";
			if (document.getElementById('finalizeorder')) var orderstatus = document.getElementById('finalizeorder').innerHTML;
			if(orderstatus == '') setOrderStatus();			
			var x = document.getElementById(id);
			var grmdescr = x.options[x.selectedIndex].text;
			x = document.getElementById('grmclr_' + setno);
			var garmclr = x.options[x.selectedIndex].text;
			x = document.getElementById('frontstyle_' + setno);
			var frtstyl = x.options[x.selectedIndex].text;
			carttable = '<div id="cartset_'+setno+'">'+"\n";
		}else{
			carttable = document.getElementById('shopping_cart').innerHTML;
			if (document.getElementById('finalizeorder')) var orderstatus = document.getElementById('finalizeorder').innerHTML;
			if(orderstatus == '') setOrderStatus();
			var x = document.getElementById(id);
			var grmdescr = x.options[x.selectedIndex].text;
			x = document.getElementById('grmclr_' + setno);
			var garmclr = x.options[x.selectedIndex].text;
			x = document.getElementById('frontstyle_' + setno);
			var frtstyl = x.options[x.selectedIndex].text;
			carttable += '<div id="cartset_'+setno+'">'+"\n";
		}
/* ***** 3 ***** */
			var cartvars_value=setno+';'+grmno+';'+grmclr+';'+frntno+';'+lclogo+';'+mascot+';'+fcolor+';'+bcolor+';3';		
			carttable += '	<table width="100%">'+"\n";
			carttable += '	<tbody>'+"\n";
			carttable += '		<tr onMouseOver="this.bgColor=\'#CCFFFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'+"\n";
			carttable += '		<td>'+"\n";
			carttable += '			<span id="setlabel_'+setno+'" class="formlabelblackbold">Set: '+setno+'.</td>'+"\n";
			carttable += '		<td class="formlabelblackbold">'+"\n";
//			carttable += '<input type="hidden" name="cartvars_'+setno+'" id="cartvars_'+setno+'" value="'+setno+';'+grmno+';'+grmclr+';'+frntno+';'+lclogo+';'+mascot+';'+fcolor+';'+bcolor+'">'+grmdescr+' - '+garmclr+'</td>'+"\n";
			carttable += '<input id="cartvars_'+setno+'" name="cartvars_'+setno+'" value="'+cartvars_value+'" type="hidden">'+grmdescr+' - '+garmclr+'</td>'+"\n";

			carttable += '		<td><span id="frontstyle_'+setno+'" class="formlabelblackbold">'+frtstyl+'</span>'+"\n";
			carttable += '			<span id="chgfrontstyle_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgfrontstyle(\'frontstyle_'+setno+'\',\'1\'))" title="Change Front Style">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change front style"></a></span></td>'+"\n";
			carttable += '		<td><span id="mascot_'+setno+'" class="formlabelblackbold">'+mascot+'</span>'+"\n";
			carttable += '			<span id="chgmascot_'+setno+'" class="formlabelblackbold">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgmascot(\'mascot_'+setno+'\',\'1\'))" title="Change Mascot">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change mascot"></a></span></td>'+"\n";
			carttable += '		<td>'+"\n";
			carttable += '			<span id="lclogo_'+setno+'" class="formlabelblackbold">'+lclogo+'</span>'+"\n";
			carttable += '			<span id="chglclogo_'+setno+'" class="formlabelblackbold">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chglclogo(\'lclogo_'+setno+'\',\'1\'))" title="Change Sport">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change sport"></a></span></td>'+"\n";
			carttable += '		<td>'+"\n";
			carttable += '			<span id="fcolor_'+setno+'" class="formlabelblackbold">'+fcolor+'</span>'+"\n";
			carttable += '			<span id="chgfcolor_'+setno+'" class="formlabelblackbold">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgfcolor(\'fcolor_'+setno+'\',\'1\'))" title="Change Fore Color">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change Fore Color"></a></span></td>'+"\n";
			carttable += '		<td>'+"\n";
			carttable += '			<span id="bcolor_'+setno+'" class="formlabelblackbold">'+bcolor+'</span>'+"\n";
			carttable += '			<span id="chgbcolor_'+setno+'" class="formlabelblackbold">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgbcolor(\'bcolor_'+setno+'\',\'1\'))" title="Change Back Color">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change Back Color"></a></span></td>'+"\n";
			carttable += '		<td width="60" align="right"><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> -->'+"\n";
			carttable += '<!--			<span id="del_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelsmall" href="javascript:void(onclick=setdel(\'set_'+setno+'\'))">'+"\n";
			carttable += '				<img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete set"></a></span>--></td>'+"\n";
			carttable += '		</tr>'+"\n";
			carttable += '	</tbody>'+"\n";
			carttable += '	</table>'+"\n\n";
			carttable += '	<table id="table_'+setno+'">'+"\n";
			carttable += '	<tbody>'+"\n";
			carttable += '		<tr>'+"\n";
			carttable += '			<td width="235"></td>'+"\n";
			carttable += '			<td width="40" align="center"><u>Line</u></td>'+"\n";
			carttable += '			<td width="40" align="center"><u>Qty</u></td>'+"\n";
			carttable += '			<td width="105" align="center"><u>Size</u></td>'+"\n";
			carttable += '			<td width="260" align="left"><u>Name</u></td>'+"\n";
			carttable += '			<td width="60" align="left"><u>Number</u></td>'+"\n";
			carttable += '			<td width="75" align="right"><u>Price</u></td>'+"\n";
			carttable += '			<td width="30" align="center"><u>Free</u></td>'+"\n";
			carttable += '			<td width="60" align="left"></td>'+"\n";
			carttable += '		</tr>'+"\n";
		var cartlbl = "";
		var cartqty = "";
		var lineno = 0;
		var i = 1;
				if (document.getElementById('qtypaid_' + setno).value>0) 
				{
					cartlbl = "Universal";
					cartqty = document.getElementById('qtypaid_' + setno).value;
					for( m=1 ; m <= cartqty ; m++)
					{
						lineno++;
						carttable += '		<tr id="tr_'+setno+'_'+lineno+'" onMouseOver="this.bgColor=\'#CCCCFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'+"\n\t\t\t";
						carttable += '<td width="235" align="right"><input id="itemid_'+setno+'_'+lineno+'" value="0" type="hidden"><input id="styleno_'+setno+'" value="3" type="hidden"></td>'+"\n\t\t\t";
						carttable += '<td width="40" align="center">';
						carttable += '<span id="line_'+setno+'_'+lineno+'" className="formlabelgray" class="formlabelgray">'+lineno+'</span></td>'+"\n\t\t\t";
						carttable += '<td width="40" align="center">';
						carttable += '<span id="qty_'+setno+'_'+lineno+'" className="formlabelblackbold" class="formlabelblackbold">1</span></td>'+"\n\t\t\t";
						carttable += '<td width="105" align="left">';
						carttable += '<span id="size_'+setno+'_'+lineno+'" className="formlabelblackbold" class="formlabelblackbold">'+cartlbl+'</span></td>'+"\n\t\t\t";
						carttable += '<td width="260" align="left"><span id="name_'+setno+'_'+lineno+'" className="formlabelreditalic" class="formlabelreditalic">(n/a)</span></td>'+"\n\t\t\t";
						carttable += '<td width="60" align="left"><span id="no_'+setno+'_'+lineno+'" className="formlabelreditalic" class="formlabelreditalic">(n/a)</span></td>'+"\n\t\t\t";
						carttable += '<td width="75" align="right">';
							var hasnameno = 0;
							var priceshow = 0;
							var priceshow1 = 0;
							var valuecompare = grmno+';'+frntno.substr(0,1)+';'+cartlbl+';'+hasnameno;
							for (k=0 ; k < (arraylinelen) ; k++) 
								{
									if ( valuecompare == arraycompare[k] ) 
										{
										priceshow1 = (arrayprice[k] * 1);
										priceshow = CurrencyFormatted(priceshow1);
										}
								}
						carttable += '<span id="price_'+setno+'_'+lineno+'" className="formlabelprice" class="formlabelprice">$'+priceshow+'</span></td>';
						carttable += '<td width="30" align="center" className="formlabelfree" class="formlabelfree"><input type="checkbox" id="free_'+setno+'_'+lineno+'" name="nfree_'+setno+'_'+lineno+'" value="" onClick="setFG(\'free_'+setno+'_'+lineno+'\');">'+"\n";
					if(document.getElementById('ordernumber')) {	
						carttable += '<input id="trvals_'+setno+'_'+lineno+'" name="trvals_'+setno+'_'+lineno+'" value="'+setno+';'+lineno+';1;'+cartlbl+';;;0;'+priceshow+';0;0" type="hidden"></td>'+"\n\t\t\t";
						}else{
/* ***** 3 ***** */
					 if(lineno==1){
							 var trvals_value = setno+';'+lineno+';1;'+cartlbl+';;;0;'+priceshow;
							}else{
							 trvals_value += '!#!'+setno+';'+lineno+';1;'+cartlbl+';;;0;'+priceshow;
							}


						carttable += '<input id="trvals_'+setno+'_'+lineno+'" name="trvals_'+setno+'_'+lineno+'" value="'+setno+';'+lineno+';1;'+cartlbl+';;;0;'+priceshow+'" type="hidden"></td>'+"\n\t\t\t";
						}
						carttable += '<td width="60" align="left"><span><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> --></span>';
						carttable += '<!-- <span id="del_'+setno+'_'+lineno+'" className="formlabelblackbold" class="formlabelblackbold">';
						carttable += '<a className="formlabelsmall" class="formlabelsmall" href="javascript:void(onclick=itemdel(\'tr_'+setno+'_'+lineno+'\'))" title="Delete Item">';
						carttable += '<img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete item"></a></span> --></td>'+"\n\t\t";
						carttable += '</tr>'+"\n\n";
					}
					}else{
						alert('Must Enter Quantity Paid for ' + id ); return false;		
					}
					lineno++;
					carttable += '		<tr id="tr_'+setno+'_'+lineno+'" onMouseOver="this.bgColor=\'#CCCCFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'+"\n";
					carttable += '		<td width="235"></td>'+"\n";
					carttable += '		<td width="40"><span id="line_'+setno+'_'+lineno+'" class="formlabelgray"></span></td>'+"\n";
					carttable += '		<td width="40"><span id="qty_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="105"><span id="size_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="260"><span id="name_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="60"><span id="no_'+setno+'_'+lineno+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="75"></td>'+"\n";
					carttable += '		<td width="30"></td>'+"\n";
					carttable += '		<td width="60" align="left"><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> -->'+"\n";
					carttable += '				<span id="add_'+setno+'_'+lineno+'">'+"\n";
					carttable += '					<a class="formlabelsmall" href="javascript:void(onclick=itemadd(\'tr_'+setno+'_'+lineno+'\'))">'+"\n";
					carttable += '					<img src="http://www.x-grain.com/images/nav/itemaddblue.gif" alt="add item to this set"></a></span></td>'+"\n";
					carttable += '	</tr>'+"\n";				
					carttable += '	</tbody>'+"\n";
					carttable += '	</table>'+"\n";
					carttable += '<!-- end cartset div --></div> '+"\n";
				document.getElementById('shopping_cart').innerHTML = carttable;
/* ***** 3 ***** */
/*
				var existing_cartvars = getCookieValue('cartvars');
				if(existing_cartvars)
					{
						var new_cartvars = existing_cartvars+'!@!'+ cartvars_value;
						writeSessionCookie('cartvars',new_cartvars);
					}else{
						writeSessionCookie('cartvars',cartvars_value);
					}
				var existing_trvals = getCookieValue('trvals');
				if(existing_trvals)
					{
						var new_trvals = existing_trvals+'!@!'+ trvals_value;
						writeSessionCookie('trvals',new_trvals);
					}else{
						writeSessionCookie('trvals',trvals_value);
					}
*/
				var nextset = parseInt(setno) + 1;
				document.getElementById('garmenttbl_' + setno).innerHTML = "Please wait.......";
				document.getElementById('garmenttbl_' + setno).setAttribute('id','garmenttbl_'+nextset);
	getGarment(nextset,0);
			} }
	} // end function getAddtoCart3() to getItemPriceLoad3() to processItemPriceLoad3fromXML()


function getAddtoCart4(id)
	{
		if (!document.getElementByID || !document.createTextNode) {
		var findsetno = id.split("_"); // split id into array
		var setno = findsetno[1]; // assign setno to 2nd array value
		checkform('sports');
		if (document.getElementById(id).options[0].selected==true && document.getElementById(id).options[0].selected!="") {alert('Please select a Garment for ' + id); return false;}
			var grmno = document.getElementById(id).value; // value of garment selected	
		if (document.getElementById('grmclr_' + setno).options[0].selected==true) {alert('Please select a Garment Color for ' + id); return false;}
			var clrno = document.getElementById('grmclr_' + setno).value; // value of garment color selected
		if (document.getElementById('frontstyle_' + setno).options[0].selected==true) {alert('Please select a Front Style for ' + id); return false;}
			var frntno = document.getElementById('frontstyle_' + setno).value; // value of frontstyle selected
		if (document.getElementById('lclogo_' + setno).options[0].selected==true) {alert('Please select a Sport for ' + id); return false;}
		if (document.getElementById('mascot_' + setno).value=="") {alert('Please select a Mascot Name for ' + id ); return false;}
		if (document.getElementById('fcolor_' + setno).options[0].selected==true) {alert('Please select a Fore Color for ' + id ); return false;}
		if (document.getElementById('bcolor_' + setno).options[0].selected==true) {alert('Please select a Back Color for ' + id ); return false;}
		if (document.getElementById('fcolor_' + setno).value == document.getElementById('bcolor_' + setno).value) {alert('Both Fore Color and Back Color are the Same for ' + id ); return false;}
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
		if (qtypaid<=0 || isNaN(parseInt(qtypaid))) 
			{
			document.getElementById('qtypaid_' + setno).value = 1;
			alert('Please Enter a Qty PAID for ' + id );
			return false;
			}
		getItemPriceLoad4(setno, grmno, clrno, frntno);
		}
	} // end function getAddtoCart4
		
function getItemPriceLoad4(setno, grmno, clrno, frntno) 
	{
        var url = "http://www.x-grain.com/a/getItemPriceLoadXML.php?setno="+setno+"&grmno="+grmno+"&clrno="+clrno+"&frntno="+frntno;
		httpRequest.open("GET", url, true);
         httpRequest.onreadystatechange = processItemPriceLoad4fromXML;
         httpRequest.send(null);
		} // end function getItemPriceLoad4

function processItemPriceLoad4fromXML()
	{
		if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) 
			{
			var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
			var recs = xmldoc.getElementsByTagName( 'fronts' );
		var grmtbl = new Array();
		var setno1 = new Array();
		setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = setno1[0];
		grmtbl[0]  = xmldoc.getElementsByTagName( 'tblblock' )[0].firstChild.nodeValue;
		var arraystring = grmtbl[0];
			var id = 'garment_'+setno;
			var grmno = document.getElementById(id).value; // value of garment selected	
			var grmclr = document.getElementById('grmclr_' + setno).value; // value of garment color selected
			var frntno = document.getElementById('frontstyle_' + setno).value; // value of frontstyle selected
			var lclogo = document.getElementById('lclogo_' + setno).value; // value of lclogo selected
			var mascot = document.getElementById('mascot_' + setno).value; // value of mascot entered
			var fcolor = document.getElementById('fcolor_' + setno).value; // value of fore color selected
			var bcolor = document.getElementById('bcolor_' + setno).value; // value of back color selected
			var fg = document.getElementById('fg_' + setno).value;
			var qtypaid = document.getElementById('qtypaid_' + setno).value; // value of Paid Qty
			var arrayline = new Array();
			var arrayline = arraystring.split("#");
			var arrayitems = new Array();
			var arraycompare = new Array();
			var arrayprice = new Array();
			var arraylinelen = arrayline.length;
			for (j=0 ; j < (arraylinelen) ; j++) 
			{
				arrayitems = arrayline[j].split(";");
				arraycompare[j] = arrayitems[0]+';'+arrayitems[1]+';'+arrayitems[2]+';'+arrayitems[3];
				arrayprice[j] = arrayitems[4];
			}
		var carttable = "";
		var cartcont = document.getElementById('shopping_cart').innerHTML;
		var cartfirst = cartcont.substr(0,7);
		if( cartfirst == '<CENTER' || cartfirst == '<center') {
			document.getElementById('shopping_cart').innerHTML = " ";
			if(document.getElementById('finalizeorder')) var orderstatus = document.getElementById('finalizeorder').innerHTML;
			if(orderstatus == '') setOrderStatus();
			var x = document.getElementById(id);
			var grmdescr = x.options[x.selectedIndex].text;
			x = document.getElementById('grmclr_' + setno);
			var garmclr = x.options[x.selectedIndex].text;
			x = document.getElementById('frontstyle_' + setno);
			var frtstyl = x.options[x.selectedIndex].text;
			carttable = "\n"+'<div id="cartset_'+setno+'">'+"\n";
		}else{
			carttable = document.getElementById('shopping_cart').innerHTML;
			if(document.getElementById('finalizeorder')) var orderstatus = document.getElementById('finalizeorder').innerHTML;
			if(orderstatus == '') setOrderStatus();
			var x = document.getElementById(id);
			var grmdescr = x.options[x.selectedIndex].text;
			x = document.getElementById('grmclr_' + setno);
			var garmclr = x.options[x.selectedIndex].text;
			x = document.getElementById('frontstyle_' + setno);
			var frtstyl = x.options[x.selectedIndex].text;
			carttable += "\n"+'<div id="cartset_'+setno+'">'+"\n";
		}
/* ***** 4 ***** */
			var cartvars_value=setno+';'+grmno+';'+grmclr+';'+frntno+';'+lclogo+';'+mascot+';'+fcolor+';'+bcolor+';4';
			carttable += '	<table width="100%">'+"\n";
			carttable += '	<tbody>'+"\n";
			carttable += '		<tr onMouseOver="this.bgColor=\'#CCFFFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'+"\n";
			carttable += '		<td>'+"\n";
			carttable += '			<span id="setlabel_'+setno+'" class="formlabelblackbold">Set: '+setno+'.</td>'+"\n";
			carttable += '		<td class="formlabelblackbold">'+"\n";
//			carttable += '<input id="cartvars_'+setno+'" name="cartvars_'+setno+'" value="'+setno+';'+grmno+';'+grmclr+';'+frntno+';'+lclogo+';'+mascot+';'+fcolor+';'+bcolor+'" type="hidden">'+grmdescr+' - '+garmclr+'</td>'+"\n";
			carttable += '<input id="cartvars_'+setno+'" name="cartvars_'+setno+'" value="'+cartvars_value+'" type="hidden">'+grmdescr+' - '+garmclr+'</td>'+"\n";

			carttable += '		<td><span id="frontstyle_'+setno+'" class="formlabelblackbold">'+frtstyl+'</span>'+"\n";
			carttable += '			<span id="chgfrontstyle_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgfrontstyle(\'frontstyle_'+setno+'\',\'1\'))" title="Change Front Style">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change front style"></a></span></td>'+"\n";
			carttable += '		<td><span id="mascot_'+setno+'" class="formlabelblackbold">'+mascot+'</span>'+"\n";
			carttable += '			<span id="chgmascot_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgmascot(\'mascot_'+setno+'\',\'1\'))" title="Change Mascot">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change mascot"></a></span></td>'+"\n";
			carttable += '		<td><span id="lclogo_'+setno+'" class="formlabelblackbold">'+lclogo+'</span>'+"\n";
			carttable += '			<span id="chglclogo_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chglclogo(\'lclogo_'+setno+'\',\'1\'))" title="Change Sport">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change sport"></a></span></td>'+"\n";
			carttable += '		<td><span id="fcolor_'+setno+'" class="formlabelblackbold">'+fcolor+'</span>'+"\n";
			carttable += '			<span id="chgfcolor_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgfcolor(\'fcolor_'+setno+'\',\'1\'))" title="Change Fore Color">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change Fore Color"></a></span></td>'+"\n";
			carttable += '		<td><span id="bcolor_'+setno+'" class="formlabelblackbold">'+bcolor+'</span>'+"\n";
			carttable += '			<span id="chgbcolor_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelblue" href="javascript:void(onclick=chgbcolor(\'bcolor_'+setno+'\',\'1\'))" title="Change Back Color">'+"\n";
			carttable += '				 <img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change Back Color"></a></span></td>'+"\n";
			carttable += '		<td align="right" width="60"><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> -->'+"\n";
			carttable += '<!--			<span id="del_'+setno+'">'+"\n";
			carttable += '				<a class="formlabelsmall" href="javascript:void(onclick=setdel(\'set_'+setno+'\'))" title="Delete Set">'+"\n";
			carttable += '				<img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete set"></a></span> -->'+"\n";
			carttable += '		</tr>'+"\n";
			carttable += '	</tbody>'+"\n";
			carttable += '	</table>'+"\n\n";
			carttable += '	<table id="table_'+setno+'">'+"\n";
			carttable += '	<tbody>'+"\n";
			carttable += '		<tr>'+"\n";
			carttable += '		<td width="235"></td>'+"\n";
			carttable += '		<td width="40" align="center"><u>Line</u></td>'+"\n";
			carttable += '		<td width="40" align="center"><u>Qty</u></td>'+"\n";
			carttable += '		<td width="105" align="center"><u>Size</u></td>'+"\n";
			carttable += '		<td width="260"><u>Name</u></td>'+"\n";
			carttable += '		<td width="60"><u>Number</u></td>'+"\n";
			carttable += '		<td width="75" align="right"><u>Price</u></td>'+"\n";
			carttable += '		<td width="30" align="center"><u>Free</u></td>'+"\n";
			carttable += '		<td width="60"></td>'+"\n";
			carttable += '		</tr>'+"\n\n";
				var sizearray = new Array();
				var namearray = new Array();
				var noarray = new Array();
				var itemprice = "";
				var i = 1;
			while(i <= qtypaid){
				carttable += '		<tr id="tr_'+setno+'_'+i+'" onMouseOver="this.bgColor=\'#CCCCFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">';
			if (document.getElementById('size_'+setno+'_'+i).options[0].selected==true) {alert('Please select a Size for Line ' + i); return false;}
				carttable += '<td width="235" align="right"><input id="itemid_'+setno+'_'+i+'" value="0" type="hidden"><input id="styleno_'+setno+'" value="1" type="hidden"></td>';
				carttable += '<td width="40" align="center">';
				carttable += '<span id="line_'+setno+'_'+i+'" className="formlabelgray" class="formlabelgray">'+i+'</span></td>';
				carttable += '<td width="40" align="center">';
				var qty = 1;
				carttable += '<span id="qty_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">1</span></td>'+"\n\t\t\t";
			sizearray[i] = document.getElementById('size_'+setno+'_'+i).value;
			if (document.getElementById('size_'+setno+'_'+i).options[0].selected!=true) {sizearray[i] = document.getElementById('size_'+setno+'_'+i).value;}
				carttable += '<td align="left" width="105">';
				carttable += '<span id="size_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">'+sizearray[i]+'</span>';
				carttable += '<span id="chgsize_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">';
				carttable += '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgsize(\'csize_'+setno+'_'+i+'\',\'1\'))" title="Change Size">';
				carttable += '<img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change size"></a></span></td>'+"\n\t\t\t";
			namearray[i] = document.getElementById('name_'+ setno + '_' + i).value;
				if(namearray[i] == ""){
					carttable += '<td align="left" width="260">';
					carttable += '<span id="name_'+setno+'_'+i+'" className="formlabelreditalic" class="formlabelreditalic">(none)</span>';
				}
			noarray[i] = document.getElementById('no_'+ setno + '_' + i).value;
				if(noarray[i] == ""){
					carttable += '<td align="left" width="60">';
					carttable += '<span id="no_'+setno+'_'+i+'" className="formlabelreditalic" class="formlabelreditalic">(none)</span>';
					carttable += '<span id="chgno_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">'
					carttable += '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgno(\'cno_'+setno+'_'+i+'\',\'1\'))" title="Change Number">';
					carttable += '<img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change number"></a></span></td>'+"\n\t\t\t";
				}else{
					carttable += '<td align="left" width="60">';
					carttable += '<span id="no_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">'+noarray[i]+'</span>';
					carttable += '<span id="chgno_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">';
					carttable += '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgno(\'cno_'+setno+'_'+i+'\',\'1\'))" title="Change Number">';
					carttable += '<img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change number"></a></span></td>'+"\n\t\t\t";
				}
					carttable += '<td align="right" width="75">';
			var hasnameno = 0;
			var priceshow = 0;
			if (namearray[i] || noarray[i]) hasnameno = 1;
			var valuecompare = grmno+';'+frntno.substr(0,1)+';'+sizearray[i]+';'+hasnameno;
			for (k=0 ; k < (arraylinelen) ; k++) 
				{
				if ( valuecompare == arraycompare[k] ) {
					priceshow = arrayprice[k];
					}
				}
					carttable += '<span id="price_'+setno+'_'+i+'" className="formlabelprice" class="formlabelprice">$'+priceshow+'</span></td>'+"\n\t\t\t";
					carttable += '<td align="center" className="formlabelfree" class="formlabelfree" width="30"><input type="checkbox" id="free_'+setno+'_'+i+'" name="nfree_'+setno+'_'+i+'" value=""  onClick="setFG(\'free_'+setno+'_'+i+'\');">'+"\n";
				if(document.getElementById('ordernumber')) {
					carttable += '<input id="trvals_'+setno+'_'+i+'" name="trvals_'+setno+'_'+i+'" value="'+setno+';'+i+';1;'+sizearray[i]+';'+namearray[i]+';'+noarray[i]+';'+fg+';'+priceshow+';0;0" type="hidden"></td>'+"\n\t\t\t";
					}else{
/* ***** 4 ***** */
					 if(i==1){
							 var trvals_value = setno+';'+i+';1;'+sizearray[i]+';'+namearray[i]+';'+noarray[i]+';'+fg+';'+priceshow;
							}else{
							 trvals_value += '!#!'+setno+';'+i+';1;'+sizearray[i]+';'+namearray[i]+';'+noarray[i]+';'+fg+';'+priceshow;
							}


					carttable += '<input id="trvals_'+setno+'_'+i+'" name="trvals_'+setno+'_'+i+'" value="'+setno+';'+i+';1;'+sizearray[i]+';'+namearray[i]+';'+noarray[i]+';'+fg+';'+priceshow+'" type="hidden"></td>'+"\n\t\t\t";
					}
					carttable += '<td align="left" width="30"><span><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> --></span>';
					carttable += '<!--<span id="del_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold">';
					carttable += '<a className="formlabelsmall" class="formlabelsmall" href="javascript:void(onclick=itemdel(\'tr_'+setno+'_'+i+'\'))" title="Delete Item">';
					carttable += '<img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete item"></a></span> --></td>'+"\n\t\t\t";
					
				i++;
					carttable += '</tr>'+"\n\n";
				}
				carttable += '		<tr id="tr_'+setno+'_'+i+'" onMouseOver="this.bgColor=\'#CCCCFF\';" onMouseOut="this.bgColor=\'#FFFFFF\';">';
					carttable += '		<td width="235"></td>'+"\n";
					carttable += '		<td width="40" align="center"><span id="line_'+setno+'_'+i+'" class="formlabelgray"></span></td>'+"\n";
					carttable += '		<td width="40" align="center"><span id="qty_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="105" align="center"><span id="size_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="260"><span id="name_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="60"><span id="no_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="75" align="right"><span id="price_'+setno+'_'+i+'" className="formlabelblackbold" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="30" align="center"><span id="free_'+setno+'_'+i+'" class="formlabelblackbold"></span></td>'+"\n";
					carttable += '		<td width="60" align="left"><!-- <img src="http://www.x-grain.com/images/nav/arrowleft.gif"> -->'+"\n";
					carttable += '				<span id="add_'+setno+'_'+i+'">'+"\n";
					carttable += '					<a class="formlabelsmall" href="javascript:void(onclick=itemadd(\'tr_'+setno+'_'+i+'\'))">'+"\n";
					carttable += '					<img src="http://www.x-grain.com/images/nav/itemaddblue.gif" alt="add item to this set"></a></span></td>'+"\n";

					carttable += '	</tr>'+"\n";
				carttable += '	</tbody>'+"\n";
				carttable += '	</table>'+"\n";
				carttable += '<!-- end cartset div --></div>'+"\n";
				document.getElementById('shopping_cart').innerHTML = carttable;
/* ***** 4 ***** */
/*
				var existing_cartvars = getCookieValue('cartvars');
				if(existing_cartvars)
					{
						var new_cartvars = existing_cartvars+'!@!'+ cartvars_value;
						writeSessionCookie('cartvars',new_cartvars);
					}else{
						writeSessionCookie('cartvars',cartvars_value);
					}
				var existing_trvals = getCookieValue('trvals');
				if(existing_trvals)
					{
						var new_trvals = existing_trvals+'!@!'+ trvals_value;
						writeSessionCookie('trvals',new_trvals);
					}else{
						writeSessionCookie('trvals',trvals_value);
					}
*/
				var nextset = parseInt(setno) + 1;
				document.getElementById('garmenttbl_' + setno).innerHTML = "Please wait.......";
				document.getElementById('garmenttbl_' + setno).setAttribute('id','garmenttbl_'+nextset);
	getGarment(nextset,0);
				} else {
				var message = httpRequest.getResponseHeader("Status");
					if ((message.length == null) || (message.length <= 0)) 
					{
					alert("Error! Request status is " + httpRequest.status);
					} else  {
							alert(message);
					} }
			}
		}  // end function getAddtoCart4() to getItemPriceLoad4() to processItemPriceLoad4fromXML()	

function chgfrontstyle(setname,styleno)
	{
			var setarray = setname.split("_"); 
			var fieldname = setarray[0];
			var setno = setarray[1];
			var cartvars = document.getElementById('cartvars_'+setno).value;
			var grmarray = cartvars.split(";");
			var grmno = grmarray[1];
			var colorno = grmarray[2];
			var styleno = grmarray[3];
			var frontstyle_old = document.getElementById(setname).innerHTML;
			var frontstylefirst6 = frontstyle_old.substr(0,6);
				if( frontstylefirst6 == '<SELEC' || frontstylefirst6 == '<selec') {
					frontstyle_old = document.getElementById("newfrontstyle_"+setno).value;
					document.getElementById(setname).innerHTML = frontstyle_old;
					return;
				}else{
					document.getElementById(setname).innerHTML = '<select name="frontstyle_'+setno+'" id="newfrontstyle_'+setno+'" size="0" onchange="return chg2frontstyle(\''+setno+'\');"><option selected value="'+styleno+'">'+frontstyle_old+'</option></select>';
				}	
			var url = "http://www.x-grain.com/a/getFrontStyleschg.php?grmno="+grmno+"&setno="+setno+"&stylenoi="+styleno;
     	    httpRequest.open("GET", url, true);
     	    httpRequest.onreadystatechange = processFRONTSTYLEchgfromXML;
     	    httpRequest.send(null);
 	}  // End function chgforntstyle

function processFRONTSTYLEchgfromXML()
	{
     if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
		var xmldocF = httpRequest.responseXML;
		var root_node = xmldocF.getElementsByTagName('root').item(0);
		var recs = xmldocF.getElementsByTagName( 'fronts' );
		var frontoptvalu = new Array();
		var frontoptval = new Array();
		var frontoptdesc = new Array();
		var frontoptdes = new Array();
		var frontsetno = new Array();
		frontsetno[0]   = xmldocF.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = frontsetno[0];
		var grmno  = xmldocF.getElementsByTagName( 'grmno' )[0].firstChild.nodeValue;
		var fieldName = 'frontstyle_'+setno;
		var clearOpts = 'document.sports.newfrontstyle_' + setno + '.options.length=0';
		eval(clearOpts);
		for ( i = 0 ; i < recs.length ; i++ ) {
			j = i+1;
			frontoptvalu[i] = xmldocF.getElementsByTagName( 'styleno' )[i].firstChild.nodeValue;
			frontoptval[j] = frontoptvalu[i];
			frontoptdesc[i] = xmldocF.getElementsByTagName( 'description' )[i].firstChild.nodeValue;
			frontoptdes[j] = frontoptdesc[i];
			frontsetno[i]   = xmldocF.getElementsByTagName( 'setno' )[i].firstChild.nodeValue;
	addOptionFrt(frontoptval[j],frontoptdes[j],frontsetno[i],j);
			}
		} else {
   			var message = httpRequest.getResponseHeader("Status");
   			if ((message.length == null) || (message.length <= 0)) {
   				alert("Error! Request status is " + httpRequest.status);
   			} else {
  			 	alert(message);
   			} } }

	}  // End function processFRONTSTYLEchgfromXML

function chg2frontstyle(setno)
	{
			var selObj = document.getElementById("newfrontstyle_"+setno);
			var selIndex = selObj.selectedIndex;
			var newfrontstyle = selObj.value;
			var newfrontstylename = selObj.options[selIndex].text;
			document.getElementById("frontstyle_"+setno).innerHTML = newfrontstylename;
			var cartvarsObj = document.getElementById('cartvars_'+setno).value;
			var grmarray = cartvarsObj.split(";");
			document.getElementById('cartvars_'+setno).value = setno+";"+grmarray[1]+";"+grmarray[2]+";"+newfrontstyle+";"+grmarray[4]+";"+grmarray[5]+";"+grmarray[6]+";"+grmarray[7];
			var grmno = grmarray[1];
			var clrno = grmarray[2];
			var frntno = newfrontstyle;
			var url = "http://www.x-grain.com/a/getItemPriceLoadXML.php?setno="+setno+"&grmno="+grmno+"&clrno="+clrno+"&frntno="+frntno;
			httpRequest.open("GET", url, true);
        	httpRequest.onreadystatechange = chg3UpdatePricing;
        	httpRequest.send(null);

	} // end function chg2frontstyle

function chg3UpdatePricing()
	{
		if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) 
			{
			var xmldoc = httpRequest.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);
			var recs = xmldoc.getElementsByTagName( 'fronts' );
		var grmtbl = new Array();
		var setno1 = new Array();
		setno1[0]   = xmldoc.getElementsByTagName( 'setno' )[0].firstChild.nodeValue;
		var setno = setno1[0];
		grmtbl[0]  = xmldoc.getElementsByTagName( 'tblblock' )[0].firstChild.nodeValue;
		var arraystring = grmtbl[0];
			var arrayline = new Array();
			var arrayline = arraystring.split("#");
			var arraylinelen = arrayline.length;
			var arrayitems = new Array();
			var arraycompare = new Array();
			var arrayprice = new Array();
			for ( i = 1 ; i < arraylinelen-1 ; i++ ) 
				{
				arrayitems = arrayline[i].split(';');
				arraycompare[i] = arrayitems[0]+';'+arrayitems[1]+';'+arrayitems[2]+';'+arrayitems[3];
				arrayprice[i] = arrayitems[4];
				}
			var lineno = 1, grmno = 0, frntno = 0, trvals = 0, comparetr = 0, hasnameno = 0, idobj='';
			cartvars  = document.getElementById('cartvars_' + setno).value;
			cartvar   = cartvars.split(';');
			grmno   = cartvar[1];
			frntno  = cartvar[3];
			while(typeof(document.getElementById('trvals_' + setno + '_' + lineno).value) === 'string')
				{
					hasnameno = 0;
					trvals  = document.getElementById('trvals_' + setno + '_' + lineno).value;
					trval   = trvals.split(';');
					if(trval[4]!='' || trval[5]!='') { hasnameno = 1; }
					comparetr = grmno+';'+frntno.substr(0,1)+';'+trval[3]+';'+hasnameno;
					for( j = 1; j < arraylinelen-1 ; j++ )
						{
						if ( comparetr == arraycompare[j] )
							{
								document.getElementById('price_' + setno + '_' + lineno).innerHTML = '$'+ CurrencyFormatted(arrayprice[j]);
								document.getElementById('trvals_' + setno + '_' + lineno).value = trval[0]+';'+trval[1]+';'+trval[2]+';'+trval[3]+';'+trval[4]+';'+trval[5]+';'+trval[6]+';'+arrayprice[j];
							} // end if
						} // end for

					lineno++;
				try {
					idobj = (typeof document.getElementById('trvals_' + setno + '_' + lineno).value);
					}
				catch(err) {
					break;
					}

				} // end while undefined
		getTotals();

		}}

	} // end function chg3frontstyle

function chgmascot(setname,styleno)
	{
		var findsetno = setname.split("_"); // split id into array
		var setnumber = findsetno[1]; // assign setno to 2nd array value
		var mascot_old = document.getElementById(setname).innerHTML;
		var mascotfirst = mascot_old.substr(0,6);
		if( mascotfirst == '<INPUT' || mascotfirst == '<input') {
			mascot_old = document.getElementById("newmascot_"+setnumber).value;
			document.getElementById(setname).innerHTML = mascot_old;
		}else{
			document.getElementById(setname).innerHTML = '<input name="mascot_'+setnumber+'" id="newmascot_'+setnumber+'" size="30" maxlength="40" value="'+mascot_old+'" onchange="return mascot2check(\''+setnumber+'\');">';
		}	
	}  // end function chgmascot
	
function mascot2check(setno)
	{
	// CHECK mascot FOR ILLEGAL CHARACTERS
		document.sports["newmascot_"+setno].value.toUpperCase();
		mascotlen = document.sports["newmascot_"+setno].value.length;
		tempmgood='';
		tempmbad='';
		if (nametest.test(document.sports["newmascot_"+setno].value))
			{} // end if
		else
			{
			for(i=0;i<=mascotlen;i++)
				{
				tempchar = document.sports["newmascot_"+setno].value.substring(i,i+1);
				if(nametest.test(tempchar))
		  		{
					tempmgood += tempchar;
		  		} // end if
				else
				{
				tempmbad += tempchar;
  				} // end else
			} // end for
			if(tempmbad.length>0)
			{
			alert ('The Following Character(s) '+tempmbad+' are not allowed in the MASCOT and have been removed ');
			document.sports["newmascot_"+setno].value = tempmgood; // or ''
			}
	   	} // end else
			var vararray = new Array();
			var setvars_old = document.getElementById('cartvars_'+setno).value;
			vararray = setvars_old.split(";"); // split vars into array
			var mascot_new = document.getElementById('newmascot_'+setno).value;
			setvars_new = vararray[0]+";"+vararray[1]+";"+vararray[2]+";"+vararray[3]+";"+vararray[4]+";"+mascot_new+";"+vararray[6]+";"+vararray[7];
		document.getElementById('cartvars_'+setno).value = setvars_new;
		document.getElementById('mascot_'+setno).innerHTML = mascot_new;
	} // end fuction chgmascot() and mascot2check()

function chglclogo(setname,styleno)
	{
		var findsetno = setname.split("_"); // split id into array
		var setnumber = findsetno[1]; // assign setno to 2nd array value
		var lclogo_old = document.getElementById(setname).innerHTML;
		var lclogofirst = lclogo_old.substr(0,6);
		if( lclogofirst == '<SELEC' || lclogofirst == '<selec') {
			lclogo_old = document.getElementById("newlclogo_"+setnumber).value;
			document.getElementById(setname).innerHTML = lclogo_old;
		}else{
			document.getElementById(setname).innerHTML = '<select name="lclogo_'+setnumber+'" id="newlclogo_'+setnumber+'" size="0" onchange="return chg2lclogo(\''+setnumber+'\');"><option selected value="'+lclogo_old+'">'+lclogo_old+'</option><option value="Athletics">Athletics</option><option value="Band">Band</option><option value="Baseball">Baseball</option><option value="Basketball">Basketball</option><option value="Cheerleading">Cheerleading</option><option value="Choir">Choir</option><option value="Cross_CountryNew">Cross_Country</option><option value="FastPitch">FastPitch</option><option value="FieldHockey">FieldHockey</option><option value="Football">Football</option><option value="Golf">Golf</option><option value="Hockey">Hockey</option><option value="LaCrosse">LaCrosse</option><option value="Lifeguard">Lifeguard</option><option value="Soccer">Soccer</option><option value="Softball">Softball</option><option value="Swimming">Swimming</option><option value="Tennis">Tennis</option><option value="Text_Only">Text_Only</option><option value="Track">Track</option><option value="Volleyball">Volleyball</option><option value="Wrestling">Wrestling</option><option value="Mascot">Mascot</option><option value="CustomLogo">Custom Logo</option></select>';
		}	
	} // end function chglclogo

function chg2lclogo(setno) 
	{
			var vararray = new Array();
			var setvars_old = document.getElementById('cartvars_'+setno).value;
			vararray = setvars_old.split(";"); // split vars into array
			var lclogo_new = document.getElementById('newlclogo_'+setno).value;
			var setvars_new = vararray[0]+";"+vararray[1]+";"+vararray[2]+";"+vararray[3]+";"+lclogo_new+";"+vararray[5]+";"+vararray[6]+";"+vararray[7];
		document.getElementById('cartvars_'+setno).value = setvars_new;
		document.getElementById('lclogo_'+setno).innerHTML = lclogo_new;
	} // end function chglclogo() and chg2lclogo()

function chgfcolor(setname,styleno)
	{
		var findsetno = setname.split("_"); // split id into array
		var setnumber = findsetno[1]; // assign setno to 2nd array value
		var fcolor_old = document.getElementById(setname).innerHTML;
		var fcolorfirst = fcolor_old.substr(0,6);
		if( fcolorfirst == '<SELEC' || fcolorfirst == '<selec') {
			fcolor_old = document.getElementById("newfcolor_"+setnumber).value;
			document.getElementById(setname).innerHTML = fcolor_old;
		}else{
			document.getElementById(setname).innerHTML = '<select name="fcolor_'+setnumber+'" id="newfcolor_'+setnumber+'" size="0" onchange="return chg2fcolor(\''+setnumber+'\');"><option selected value="'+fcolor_old+'">'+fcolor_old+'</option><option value="Navy_Blue">Navy_Blue</option><option value="Royal_Blue">Royal Blue</option><option value="Columbia_Blue">Columbia Blue</option><option value="Black">Black</option><option value="Red">Red</option><option value="Cardinal">Cardinal</option><option value="White">White</option><option value="Michigan_Gold">Michigan Gold</option><option value="Vegas_Gold">Vegas Gold</option><option value="Dark_Green">Dark_Green</option><option value="Kelly_Green">Kelly_Green</option><option value="Purple">Purple</option><option value="Gray">Gray</option><option value="Orange">Orange</option><option value="Maroon">Maroon</option><option value="Yellow">Yellow</option><option value="Brown">Brown</option><option value="Teal">Teal</option></select>';
		}	
	} // end function fcolor

function chg2fcolor(setno) 
	{
		var vararray = new Array();
		var setvars_old = document.getElementById('cartvars_'+setno).value;
		vararray = setvars_old.split(";"); // split vars into array
		var fcolor_new = document.getElementById('newfcolor_'+setno).value;
		if (fcolor_new == vararray[6]) {
			alert('Fore Color and Back Color are both ' + fcolor_new + '. Please select a different color');
			document.getElementById('fcolor_'+setno).innerHTML = '<select name="fcolor_'+setno+'" id="newfcolor_'+setno+'" size="0" onchange="return chg2fcolor(\''+setno+'\');"><option selected value=""></option><option value="Navy_Blue">Navy_Blue</option><option value="Royal_Blue">Royal Blue</option><option value="Columbia_Blue">Columbia Blue</option><option value="Black">Black</option><option value="Red">Red</option><option value="Cardinal">Cardinal</option><option value="White">White</option><option value="Michigan_Gold">Michigan Gold</option><option value="Vegas_Gold">Vegas Gold</option><option value="Dark_Green">Dark_Green</option><option value="Kelly_Green">Kelly_Green</option><option value="Purple">Purple</option><option value="Gray">Gray</option><option value="Orange">Orange</option><option value="Maroon">Maroon</option><option value="Yellow">Yellow</option><option value="Brown">Brown</option><option value="Teal">Teal</option></select>';
		}else{
			var setvars_new = vararray[0]+";"+vararray[1]+";"+vararray[2]+";"+vararray[3]+";"+vararray[4]+";"+vararray[5]+";"+fcolor_new+";"+vararray[7];
			document.getElementById('cartvars_'+setno).value = setvars_new;
			document.getElementById('fcolor_'+setno).innerHTML = fcolor_new;
		}
	} // end fuction chgfcolor() and chg2fcolor()

function chgbcolor(setname,styleno)
	{
		var findsetno = setname.split("_"); // split id into array
		var setnumber = findsetno[1]; // assign setno to 2nd array value
		var bcolor_old = document.getElementById(setname).innerHTML;
		var bcolorfirst = bcolor_old.substr(0,6);
		if( bcolorfirst == '<SELEC' || bcolorfirst == '<selec') {
			bcolor_old = document.getElementById("newbcolor_"+setnumber).value;
			document.getElementById(setname).innerHTML = bcolor_old;
		}else{
			document.getElementById(setname).innerHTML = '<select name="bcolor_'+setnumber+'" id="newbcolor_'+setnumber+'" size="0" onchange="return chg2bcolor(\''+setnumber+'\');"><option selected value="'+bcolor_old+'">'+bcolor_old+'</option><option value="Navy_Blue">Navy_Blue</option><option value="Royal_Blue">Royal Blue</option><option value="Columbia_Blue">Columbia Blue</option><option value="Black">Black</option><option value="Red">Red</option><option value="Cardinal">Cardinal</option><option value="White">White</option><option value="Michigan_Gold">Michigan Gold</option><option value="Vegas_Gold">Vegas Gold</option><option value="Dark_Green">Dark_Green</option><option value="Kelly_Green">Kelly_Green</option><option value="Purple">Purple</option><option value="Gray">Gray</option><option value="Orange">Orange</option><option value="Maroon">Maroon</option><option value="Yellow">Yellow</option><option value="Brown">Brown</option><option value="Teal">Teal</option></select>';
		}	
	} // end function chgbcolor

function chg2bcolor(setno)
	{
		var vararray = new Array();
		var setvars_old = document.getElementById('cartvars_'+setno).value;
		vararray = setvars_old.split(";"); // split vars into array
		var bcolor_new = document.getElementById('newbcolor_'+setno).value;
				if (bcolor_new == vararray[5]) {
			alert('Fore Color and Back Color are both ' + bcolor_new + '. Please select a different color');
			document.getElementById('bcolor_'+setno).innerHTML = '<select name="bcolor_'+setno+'" id="newbcolor_'+setno+'" size="0" onchange="return chg2bcolor(\''+setno+'\');"><option selected value=""></option><option value="Navy_Blue">Navy_Blue</option><option value="Royal_Blue">Royal Blue</option><option value="Columbia_Blue">Columbia Blue</option><option value="Black">Black</option><option value="Red">Red</option><option value="Cardinal">Cardinal</option><option value="White">White</option><option value="Michigan_Gold">Michigan Gold</option><option value="Vegas_Gold">Vegas Gold</option><option value="Dark_Green">Dark_Green</option><option value="Kelly_Green">Kelly_Green</option><option value="Purple">Purple</option><option value="Gray">Gray</option><option value="Orange">Orange</option><option value="Maroon">Maroon</option><option value="Yellow">Yellow</option><option value="Brown">Brown</option><option value="Teal">Teal</option></select>';
		}else{
			var setvars_new = vararray[0]+";"+vararray[1]+";"+vararray[2]+";"+vararray[3]+";"+vararray[4]+";"+vararray[5]+";"+vararray[6]+";"+bcolor_new;
			document.getElementById('cartvars_'+setno).value = setvars_new;
			document.getElementById('bcolor_'+setno).innerHTML = bcolor_new;
		}
	} // end function chgbcolor()  and chg2bcolor

function chgqty(setname,styleno,qtyold)
	{
	var setarray = setname.split("_"); // split id into array
	var fieldname = setarray[0];
	var setno = setarray[1];
	var recno = setarray[2];
	if('cqty_'+setno+'_'+recno){
		var qtyval_old = document.getElementById('qty_'+setno+'_'+recno).innerHTML;
		}else{
		var qtyval_old = document.getElementById('cqty_'+setno+'_'+recno).innerHTML;
		}
	var qtyval6 = qtyval_old.substr(0,6);
	if( qtyval6 == '<INPUT' || qtyval6 == '<input') {
			qtyval_old = document.getElementById("qty_"+setno+"_"+recno).value;
			document.getElementById(setname).innerHTML = qtyold;
		}else{
			document.getElementById(setname).innerHTML = '<input name="qty_'+setno+'_'+recno+'" id="cqty_'+setno+'_'+recno+'" size="3" maxlength="3" value="'+qtyval_old+'" onchange="return chg2qty(\''+setno+'\',\''+recno+'\',\''+qtyval_old+'\');">';
		}
	} // end function chgqty

function chg2qty(setno,recno,qtyold)
	{
		var trvararray = new Array();
		var trvars_old = document.getElementById('trvals_'+setno+'_'+recno).value;
		trvararray = trvars_old.split(";");
			var asize = trvararray[3];
			var aname = trvararray[4];
			var ano = trvararray[5];
		var setvararray = new Array();
		var setvars_old = document.getElementById('cartvars_'+setno).value;
		setvararray = setvars_old.split(";");
			var agrmno = setvararray[1];
			var afrntno = setvararray[2];
		var pass = 1;
		var qtyval_new = Math.abs(document.getElementById("cqty_"+setno+"_"+recno).value);
		if( qtyval_new <= 0 || isNaN(parseInt(qtyval_new))) 
			{
			qtyval_new = 1;
			alert('This must be a positive number so we set it to 1 qty for you');
			}
		var settrvars_new = trvararray[0]+";"+trvararray[1]+";"+qtyval_new+";"+trvararray[3]+";"+trvararray[4]+";"+trvararray[5]+";"+trvararray[6]+";"+trvararray[7];
			document.getElementById("trvals_"+setno+"_"+recno).value = settrvars_new;
			document.getElementById('qty_'+setno+'_'+recno).innerHTML = qtyval_new;
			getItemPricing(setno,recno,qtyval_new,agrmno,afrntno,asize,aname,ano,pass); 
	} // end fuction chgqty() and chg2qty

function chgsize(setname,styleno)
	{
		var setarray = setname.split("_"); 
		var fieldname = setarray[0];
		var setno = setarray[1];
		var recno = setarray[2];
		var old_val = document.getElementById('size_'+setno+'_'+recno).innerHTML;
		var old_val6 = old_val.substr(0,6);
		if( old_val6 == '<SELEC' || old_val6 == '<selec') {
			var trvararray = new Array();
			var trvars_old = document.getElementById('trvals_'+setno+'_'+recno).value;
			trvararray = trvars_old.split(";");
				var asize = trvararray[3];
			document.getElementById('size_'+setno+'_'+recno).innerHTML = asize;
		}else{
			var cartvars = document.getElementById('cartvars_'+setno).value;
			var grmarray = cartvars.split(";");
			var grmno = grmarray[1];
			var colorno = grmarray[2];
			var sizevars = '\''+grmno+'\',\''+colorno+'\',\''+setno+'\',\''+recno+'\'';
	getSizing(grmno,colorno,setno,recno);
 	} }  // End function chgsize

function chg2size(setno,recno)
	{
		var trvararray = new Array();
		var trvars_old = document.getElementById('trvals_'+setno+'_'+recno).value;
		trvararray = trvars_old.split(";");
			var aqty = trvararray[2];
			var aname = trvararray[4];
			var ano = trvararray[5];
		var setvararray = new Array();
		var setvars_old = document.getElementById('cartvars_'+setno).value;
		setvararray = setvars_old.split(";");
			var agrmno = setvararray[1];
			var afrntno = setvararray[3];
		var pass = 1;
		var sizeval_new = document.getElementById("csize_"+setno+"_"+recno).value;
		if(document.getElementById( "itemid_" + setno + "_" + recno)) {
			var settrvals_new = trvararray[0]+";"+trvararray[1]+";"+trvararray[2]+";"+sizeval_new+";"+trvararray[4]+";"+trvararray[5]+";"+trvararray[6]+";"+trvararray[7]+";0;0";
		}else{
			var settrvals_new = trvararray[0]+";"+trvararray[1]+";"+trvararray[2]+";"+sizeval_new+";"+trvararray[4]+";"+trvararray[5]+";"+trvararray[6]+";"+trvararray[7];
		}
			document.getElementById("trvals_"+setno+"_"+recno).value = settrvals_new;
			document.getElementById('size_'+setno+'_'+recno).innerHTML = sizeval_new;
	getItemPricing(setno,recno,aqty,agrmno,afrntno,sizeval_new,aname,ano,pass); 
	} // end fuction chgsize() and chg2size()

function chgname(setname,styleno)
	{
	var setarray = setname.split("_");
	var fieldname = setarray[0];
	var setno = setarray[1];
	var recno = setarray[2];
	var nameval_old = document.getElementById('name_'+setno+'_'+recno).innerHTML;
		if (nameval_old == "(none)" || nameval_old == "(n/a)") {	var name_none_or_na = nameval_old; }
	var noval_old = document.getElementById('no_'+setno+'_'+recno).innerHTML;
		if (noval_old == "(none)" || noval_old == "(n/a)") {	var no_none_or_na = noval_old; }
	if(nameval_old == '(none)' || !nameval_old){ nameval_old = '';}
	if(noval_old == '(none)' || !noval_old){ noval_old = '';}
	if(nameval_old == '(n/a)' || !nameval_old){ nameval_old = '';}
	if(noval_old == '(n/a)' || !noval_old){ noval_old = '';}
	var nameval6 = nameval_old.substr(0,6);
	if( nameval6 == '<INPUT' || nameval6 == '<input') {
			nameval_old = document.getElementById("cname_"+setno+"_"+recno).value;
			noval_old = document.getElementById("cno_"+setno+"_"+recno).value;
			if(nameval_old == '') nameval_old = name_none_or_na;
			if(noval_old == '') noval_old = 'no_none_or_na';
			document.getElementById("cname_"+setno+"_"+recno).innerHTML = nameval_old;
			document.getElementById("cno_"+setno+"_"+recno).innerHTML = noval_old;
		}else{
			namenewinput = '<input type="text" id="cname_'+setno+'_'+recno+'" maxLength="20" size="34" width="34" value="'+nameval_old+'" onBlur="NameCheck(\''+setno+'\',\''+recno+'\',\'1\');">';
			nonewinput = '<input type="text" id="cno_'+setno+'_'+recno+'" maxLength="5" size="5" width="5" value="'+noval_old+'" onBlur="NameCheck(\''+setno+'\',\''+recno+'\',\'1\');">';
			document.getElementById('name_'+setno+'_'+recno).innerHTML = namenewinput;
			document.getElementById('no_'+setno+'_'+recno).innerHTML = nonewinput;
			document.getElementById("cname_"+setno+"_"+recno).focus();
		}

	} // end fuction chgname()

function chgno(setname,styleno)
	{
	var setarray = setname.split("_");
	var fieldname = setarray[0];
	var setno = setarray[1];
	var recno = setarray[2];
	var nameval_old = document.getElementById('name_'+setno+'_'+recno).innerHTML;
		if (nameval_old == "(none)" || nameval_old == "(n/a)") {	var name_none_or_na = nameval_old; }
	var noval_old = document.getElementById('no_'+setno+'_'+recno).innerHTML;
		if (noval_old == "(none)" || noval_old == "(n/a)") {	var no_none_or_na = noval_old; }
	if(nameval_old == '(none)' || !nameval_old){ nameval_old = '';}
	if(nameval_old == '(n/a)' || !nameval_old){ nameval_old = '';}
	if(noval_old == '(none)' || !noval_old){ noval_old = '';}
	if(noval_old == '(n/a)' || !noval_old){ noval_old = '';}
	var nameval6 = nameval_old.substr(0,6);
	if( nameval6 == '<INPUT' || nameval6 == '<input') {
			nameval_old = document.getElementById("cname_"+setno+"_"+recno).value;
			if(nameval_old == '') nameval_old = name_none_or_na;
			document.getElementById(setname).innerHTML = nameval_old;
		}else{
			namenewinput = '<input type="text" id="cname_'+setno+'_'+recno+'" maxLength="20" size="34" width="34" value="'+nameval_old+'" onBlur="NameCheck(\''+setno+'\',\''+recno+'\',\'1\');">';
			nonewinput = '<input type="text" id="cno_'+setno+'_'+recno+'" maxLength="5" size="5" width="5" value="'+noval_old+'" onBlur="NameCheck(\''+setno+'\',\''+recno+'\',\'1\');">';
			document.getElementById('name_'+setno+'_'+recno).innerHTML = namenewinput;
			document.getElementById('no_'+setno+'_'+recno).innerHTML = nonewinput;
			document.getElementById("cno_"+setno+"_"+recno).focus();
		}
	} // end fuction chgno

function itemdel(setname)
	{	
		var setarray = setname.split("_");
		var fieldname = setarray[0];
		var setno = setarray[1];
		var recno = setarray[2];
		var nextrecno = parseInt(recno)+1;
		var trvalsnext = 'trvals_'+setno+'_'+nextrecno;
		if( (recno == 1) && (!document.getElementById( "trvals_" + setno + "_" + nextrecno ) ) ) {
			answer = confirm(' This is the Only Record in this Set, You will be removing this Item and the Entire Set!');
			if(!answer){
				return false;
				}else{
				setdel('set_'+setno);
				return false;
				}
			}
		if( (recno != 1) && (!document.getElementById( "trvals_" + setno + "_" + nextrecno ) ) ) {
			var tablename = 'table_'+setno;
			var trname = 'tr_'+setno+'_'+recno;
			var trnext = 'tr_'+setno+'_'+nextrecno;
			var tableid = document.getElementById('table_'+setno);
			var rowid = document.getElementById('tr_'+setno+'_'+recno);
			var tbody = tableid.getElementsByTagName("tbody")[0];
			var myTrElements = tbody.getElementsByName("tr");
			var counttr = myTrElements.length;
			var trvalsarrayd = new Array();
			var trvals_rec = document.getElementById( "trvals_" + setno + "_" + recno).value;
			var trvalsarrayd = trvals_rec.split(";"); // split vars into array
			if (document.getElementById('ordernumber')) {
				chg_dbline_del(setno, recno);
		//	}else{
		//		return;
			}
		tbody.removeChild( rowid );
		var prevrecno = recno;
				if(document.getElementById( "tr_" + setno + "_" + nextrecno)) document.getElementById( "tr_" + setno + "_" + nextrecno).id = "tr_" + setno + "_" + prevrecno;
				if(document.getElementById( "itemid_" + setno + "_" + nextrecno)) document.getElementById( "itemid_" + setno + "_" + nextrecno).id = "itemid_" + setno + "_" + prevrecno;
				if(document.getElementById( "line_" + setno + "_" + nextrecno)) document.getElementById( "line_" + setno + "_" + nextrecno).id = "line_" + setno + "_" + prevrecno;
				if(document.getElementById( "qty_" + setno + "_" + nextrecno)) document.getElementById( "qty_" + setno + "_" + nextrecno).id = "qty_" + setno + "_" + prevrecno;
				if(document.getElementById( "size_" + setno + "_" + nextrecno)) document.getElementById( "size_" + setno + "_" + nextrecno).id = "size_" + setno + "_" + prevrecno;
				if(document.getElementById( "name_" + setno + "_" + nextrecno)) document.getElementById( "name_" + setno + "_" + nextrecno).id = "name_" + setno + "_" + prevrecno;
				if(document.getElementById( "no_" + setno + "_" + nextrecno)) document.getElementById( "no_" + setno + "_" + nextrecno).id = "no_" + setno + "_" + prevrecno;
				if(document.getElementById( "price_" + setno + "_" + nextrecno)) document.getElementById( "price_" + setno + "_" + nextrecno).id = "price_" + setno + "_" + prevrecno;
				if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).setAttribute("name","nfree_" + setno + "_" + prevrecno);
				if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).setAttribute("onClick",'setFG(\'free_'+setno+'_'+prevrecno+'\')');
				// if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).setAttribute("onClick",'setFG(\'free_'+setno+'_'+prevrecno+'\')');
				if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).id = "free_" + setno + "_" + prevrecno;
				if(document.getElementById( "add_" + setno + "_" + nextrecno)) document.getElementById( "add_" + setno + "_" + nextrecno).innerHTML = '<a class="formlabelsmall" href="javascript:void(onclick=itemadd(\'tr_'+setno+'_'+prevrecno+'\'))" title="Add Item"><img src="http://www.x-grain.com/images/nav/itemaddblue.gif" alt="add item to this set"></a>';
				if(document.getElementById( "add_" + setno + "_" + nextrecno)) document.getElementById( "add_" + setno + "_" + nextrecno).id = "add_" + setno + "_" + prevrecno;
					removeAllFG();
					getTotals();
				}
		if( (recno >= 1) && (document.getElementById( "trvals_" + setno + "_" + nextrecno ) ) ) {
			var tablename = 'table_'+setno;
			var trname = 'tr_'+setno+'_'+recno;
			var trnext = 'tr_'+setno+'_'+nextrecno;
			var tableid = document.getElementById('table_'+setno);
			var rowid = document.getElementById('tr_'+setno+'_'+recno);
			var tbody = tableid.getElementsByTagName("tbody")[0];
			var trvalsarrayd = new Array();
			var trvals_rec = document.getElementById( "trvals_" + setno + "_" + recno).value;
			var trvalsarrayd = trvals_rec.split(";"); // split vars into array
			if (document.getElementById('ordernumber')) {
				chg_dbline_del(setno, recno);
				}
			var myTrElements = document.getElementById('table_'+setno).getElementsByTagName("tbody")[0].getElementsByTagName("tr");
				var counttr = myTrElements.length;
			document.getElementById( "trvals_" + setno + "_" + recno).value = "0;0;0;0;0;0";
			tbody.removeChild( rowid );
			var prevrecno = recno;
			var trvalsarray = new Array();
			while (document.getElementById( "trvals_" + setno + "_" + nextrecno)) 
				{
					document.getElementById( "line_" + setno + "_" + nextrecno).innerHTML = prevrecno;
					styleno = document.getElementById( "styleno_" + setno).value;
					currentqty = document.getElementById( "qty_" + setno + "_" + nextrecno).innerHTML;
					if(document.getElementById( "itemid_" + setno + "_" + nextrecno)) document.getElementById( "itemid_" + setno + "_" + nextrecno).id = "itemid_" + setno + "_" + prevrecno;
					if(document.getElementById( "chgqty_" + setno + "_" + nextrecno)) document.getElementById( "chgqty_" + setno + "_" + nextrecno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=chgqty(\'qty_'+setno+'_'+prevrecno+'\',\''+styleno+'\',\''+currentqty+'\'))" title="Change Quantity"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change quantity"></a>';
					if(document.getElementById( "chgsize_" + setno + "_" + nextrecno)) document.getElementById( "chgsize_" + setno + "_" + nextrecno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=chgsize(\'csize_'+setno+'_'+prevrecno+'\',\''+styleno+'\'))" title="Change Size"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change size"></a>';
					if(document.getElementById( "chgname_" + setno + "_" + nextrecno)) document.getElementById( "chgname_" + setno + "_" + nextrecno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=chgname(\'cname_'+setno+'_'+prevrecno+'\',\''+styleno+'\'))" title="Change Name"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change name"></a>';
					if(document.getElementById( "chgno_" + setno + "_" + nextrecno)) document.getElementById( "chgno_" + setno + "_" + nextrecno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=chgno(\'cno_'+setno+'_'+prevrecno+'\',\''+styleno+'\'))" title="Change Number"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change number"></a>';
				if(	document.getElementById( "ordernumber")){
					if(document.getElementById( "del_" + setno + "_" + nextrecno)) document.getElementById( "del_" + setno + "_" + nextrecno).innerHTML = '<a class="formlabelsmall" href="javascript:void(onclick=itemdel(\'tr_'+setno+'_'+prevrecno+'\',\''+styleno+'\'))"><img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete item"></a>';
					}else{
					if(document.getElementById( "del_" + setno + "_" + nextrecno)) document.getElementById( "del_" + setno + "_" + nextrecno).innerHTML = '<a class="formlabelsmall" href="javascript:void(onclick=itemdel(\'tr_'+setno+'_'+prevrecno+'\'))"><img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete item"></a>';
					}
					if(document.getElementById( "tr_" + setno + "_" + nextrecno)) document.getElementById( "tr_" + setno + "_" + nextrecno).id = "tr_" + setno + "_" + prevrecno;
					if(document.getElementById( "line_" + setno + "_" + nextrecno)) document.getElementById( "line_" + setno + "_" + nextrecno).id = "line_" + setno + "_" + prevrecno;
					if(document.getElementById( "qty_" + setno + "_" + nextrecno)) document.getElementById( "qty_" + setno + "_" + nextrecno).id = "qty_" + setno + "_" + prevrecno;
					if(document.getElementById( "chgqty_" + setno + "_" + nextrecno)) document.getElementById( "chgqty_" + setno + "_" + nextrecno).id = "chgqty_" + setno + "_" + prevrecno;
					if(document.getElementById( "size_" + setno + "_" + nextrecno)) document.getElementById( "size_" + setno + "_" + nextrecno).id = "size_" + setno + "_" + prevrecno;
					if(document.getElementById( "chgsize_" + setno + "_" + nextrecno)) document.getElementById( "chgsize_" + setno + "_" + nextrecno).id = "chgsize_" + setno + "_" + prevrecno;
					if(document.getElementById( "name_" + setno + "_" + nextrecno)) document.getElementById( "name_" + setno + "_" + nextrecno).id = "name_" + setno + "_" + prevrecno;
					if(document.getElementById( "chgname_" + setno + "_" + nextrecno)) document.getElementById( "chgname_" + setno + "_" + nextrecno).id = "chgname_" + setno + "_" + prevrecno;
					if(document.getElementById( "no_" + setno + "_" + nextrecno)) document.getElementById( "no_" + setno + "_" + nextrecno).id = "no_" + setno + "_" + prevrecno;
					if(document.getElementById( "price_" + setno + "_" + nextrecno)) document.getElementById( "price_" + setno + "_" + nextrecno).id = "price_" + setno + "_" + prevrecno;
					if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).setAttribute("name","nfree_" + setno + "_" + prevrecno);
					if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).setAttribute("onClick",'setFG(\'free_'+setno+'_'+prevrecno+'\')');
					// if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).setAttribute("onClick",'setFG(\'free_'+setno+'_'+prevrecno+'\')');
					if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).id = "free_" + setno + "_" + prevrecno;
					if(document.getElementById( "chgno_" + setno + "_" + nextrecno)) document.getElementById( "chgno_" + setno + "_" + nextrecno).id = "chgno_" + setno + "_" + prevrecno;
					if(document.getElementById( "del_" + setno + "_" + nextrecno)) document.getElementById( "del_" + setno + "_" + nextrecno).id = "del_" + setno + "_" + prevrecno;
					if(document.getElementById( "trvals_" + setno + "_" + nextrecno))
						{
						trvalsold = document.getElementById( "trvals_" + setno + "_" + nextrecno).value;
						trvalsarray = trvalsold.split(";"); // split vars into array
						trvalsnew = setno+";"+prevrecno+";"+trvalsarray[2]+";"+trvalsarray[3]+";"+trvalsarray[4]+";"+trvalsarray[5]+";"+trvalsarray[6]+";"+trvalsarray[7];
						document.getElementById( "trvals_" + setno + "_" + nextrecno).setAttribute("name","trvals_" + setno + "_" + prevrecno);
						document.getElementById( "trvals_" + setno + "_" + nextrecno).value = trvalsnew;
						document.getElementById( "trvals_" + setno + "_" + nextrecno).id = "trvals_" + setno + "_" + prevrecno;
						}
					prevrecno++;
					nextrecno++;
				}
				if(document.getElementById( "tr_" + setno + "_" + nextrecno)) document.getElementById( "tr_" + setno + "_" + nextrecno).id = "tr_" + setno + "_" + prevrecno;
				if(document.getElementById( "itemid_" + setno + "_" + nextrecno)) document.getElementById( "itemid_" + setno + "_" + nextrecno).id = "itemid_" + setno + "_" + prevrecno;
				if(document.getElementById( "line_" + setno + "_" + nextrecno)) document.getElementById( "line_" + setno + "_" + nextrecno).id = "line_" + setno + "_" + prevrecno;
				if(document.getElementById( "qty_" + setno + "_" + nextrecno)) document.getElementById( "qty_" + setno + "_" + nextrecno).id = "qty_" + setno + "_" + prevrecno;
				if(document.getElementById( "size_" + setno + "_" + nextrecno)) document.getElementById( "size_" + setno + "_" + nextrecno).id = "size_" + setno + "_" + prevrecno;
				if(document.getElementById( "name_" + setno + "_" + nextrecno)) document.getElementById( "name_" + setno + "_" + nextrecno).id = "name_" + setno + "_" + prevrecno;
				if(document.getElementById( "no_" + setno + "_" + nextrecno)) document.getElementById( "no_" + setno + "_" + nextrecno).id = "no_" + setno + "_" + prevrecno;
				if(document.getElementById( "price_" + setno + "_" + nextrecno)) document.getElementById( "price_" + setno + "_" + nextrecno).id = "price_" + setno + "_" + prevrecno;
				if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).setAttribute("name","nfree_" + setno + "_" + prevrecno);
				if(document.getElementById( "free_" + setno + "_" + nextrecno)) document.getElementById( "free_" + setno + "_" + nextrecno).id = "free_" + setno + "_" + prevrecno;
				if(document.getElementById( "add_" + setno + "_" + nextrecno)) document.getElementById( "add_" + setno + "_" + nextrecno).innerHTML = '<a class="formlabelsmall" href="javascript:void(onclick=itemadd(\'tr_'+setno+'_'+prevrecno+'\'))" title="Add Item"><img src="http://www.x-grain.com/images/nav/itemaddblue.gif" alt="add item to this set"></a>';
				if(document.getElementById( "add_" + setno + "_" + nextrecno)) document.getElementById( "add_" + setno + "_" + nextrecno).id = "add_" + setno + "_" + prevrecno;
				if(document.getElementById('freeusedqty').innerHTML != 0 )
					{
						var cartcont = document.getElementById('shopping_cart').innerHTML;
						document.getElementById('shopping_cart').innerHTML = cartcont;
						removeAllFG();
					}else{
						var cartcont = document.getElementById('shopping_cart').innerHTML;
						document.getElementById('shopping_cart').innerHTML = cartcont;
						getTotals();
					}
		}
	} // end function itemdel()
	
function itemadd(setname)
	{	
		var setarray = setname.split("_");
		var fieldname = setarray[0];
		var setno = setarray[1];
		var recno = setarray[2];
		var nextrecno = parseInt(recno)+1;
		var prevrecno = recno;
		var prevrecno = recno;
		if (document.getElementById( "styleno_" + setno)) var styleno = document.getElementById( "styleno_" + setno).value;
			if(document.getElementById( "tr_" + setno + "_" + prevrecno)) document.getElementById( "tr_" + setno + "_" + prevrecno).id = "tr_" + setno + "_" + nextrecno;
			if(document.getElementById( "line_" + setno + "_" + prevrecno)) document.getElementById( "line_" + setno + "_" + prevrecno).id = "line_" + setno + "_" + nextrecno;
			if(document.getElementById( "qty_" + setno + "_" + prevrecno)) document.getElementById( "qty_" + setno + "_" + prevrecno).id = "qty_" + setno + "_" + nextrecno;
			if(document.getElementById( "size_" + setno + "_" + prevrecno)) document.getElementById( "size_" + setno + "_" + prevrecno).id = "size_" + setno + "_" + nextrecno;
			if(document.getElementById( "name_" + setno + "_" + prevrecno)) document.getElementById( "name_" + setno + "_" + prevrecno).id = "name_" + setno + "_" + nextrecno;
			if(document.getElementById( "no_" + setno + "_" + prevrecno)) document.getElementById( "no_" + setno + "_" + prevrecno).id = "no_" + setno + "_" + nextrecno;
			if(document.getElementById( "add_" + setno + "_" + prevrecno)) document.getElementById( "add_" + setno + "_" + prevrecno).innerHTML = '<a class="formlabelsmall" href="javascript:void(onclick=itemadd(\'tr_'+setno+'_'+nextrecno+'\'))" title="Add Item"><img src="http://www.x-grain.com/images/nav/itemaddblue.gif" alt="add item to this set"></a>';
			if(document.getElementById( "add_" + setno + "_" + prevrecno)) document.getElementById( "add_" + setno + "_" + prevrecno).id = "add_" + setno + "_" + nextrecno;
		var tablename = 'table_'+setno;
		var trname = 'tr_'+setno+'_'+nextrecno;
		var trnext = 'tr_'+setno+'_'+nextrecno;
		var tableid = document.getElementById('table_'+setno);
		var rowid = document.getElementById('tr_'+setno+'_'+recno);
		var tbody = tableid.getElementsByTagName("tbody")[0];
		var newrow = tbody.insertRow(prevrecno);
			newrow.appendChild(document.createTextNode("\n\t\t\t"));
			newrow.setAttribute('onmouseout','this.bgColor=\'#FFFFFF\';');
			newrow.setAttribute('onmouseover','this.bgColor=\'#CCCCFF\';');
			newrow.setAttribute('id','tr_'+setno+'_'+prevrecno);
	var newcell1 = newrow.insertCell(0);
			newcell1.setAttribute('align','right');
			newcell1.setAttribute('width','250');
			var newinput1 = document.createElement("input");
				newinput1.setAttribute('type','hidden');
				newinput1.setAttribute('value','0');
				newinput1.setAttribute('id','itemid_'+setno+'_'+prevrecno);
			var newinput2 = document.createElement("input");
				newinput2.setAttribute('type','hidden');
				newinput2.setAttribute('value',styleno);
				newinput2.setAttribute('id','styleno_'+setno);
			newcell1.appendChild(newinput1);
			newcell1.appendChild(newinput2);
	var newcell2 = newrow.insertCell(1);
		var parentDiv = newcell2.parentNode;
		parentDiv.insertBefore(document.createTextNode("\n\t\t\t"),newcell2);
			newcell2.setAttribute('align','center');
			newcell2.setAttribute('width','40');
			var newspan2 = document.createElement("span");
				newspan2.setAttribute('class','formlabelgray');
				newspan2.setAttribute('className','formlabelgray');
				newspan2.setAttribute('id','line_'+setno+'_'+prevrecno);
				var newlineno2 = document.createTextNode(prevrecno);
			newcell2.appendChild(newspan2);
			newspan2.appendChild(newlineno2);
	var newcell3 = newrow.insertCell(2);
		var parentDiv = newcell3.parentNode;
		parentDiv.insertBefore(document.createTextNode("\n\t\t\t"),newcell3);
		// newcell3.appendChild(document.createTextNode("\n\t\t\t"));
			newcell3.setAttribute('align','center');
			newcell3.setAttribute('width','40');
			var newspan3_1 = document.createElement("span");
				newspan3_1.setAttribute('class','formlabelblackbold');
				newspan3_1.setAttribute('className','formlabelblackbold');
				newspan3_1.setAttribute('id','qty_'+setno+'_'+prevrecno);
				var newqty3 = document.createTextNode('1');
		if(styleno == 1 || styleno == 2 || styleno == 3) {
			newcell3.appendChild(newspan3_1);
			newspan3_1.appendChild(newqty3);
			}else{
			var newspan3_2 = document.createElement("span");
				newspan3_2.setAttribute('class','formlabelblackbold');
				newspan3_2.setAttribute('className','formlabelblackbold');
				newspan3_2.setAttribute('id','chgqty_'+setno+'_'+prevrecno);
				var newanchor3_2 = document.createElement('a');			
					newanchor3_2.setAttribute('title','Change Quantity');
					newanchor3_2.setAttribute('href','javascript:void(onclick=chgqty(\'qty_'+setno+'_'+prevrecno+'\',\''+styleno+'\',\'1\'))');
					newanchor3_2.setAttribute('class','formlabelblue');
					newanchor3_2.setAttribute('className','formlabelblue');
				var newimg3_2 = document.createElement('img');
					newimg3_2.setAttribute('alt','change quantity');
					newimg3_2.setAttribute('src','http://www.x-grain.com/images/nav/pencil.gif');
			newcell3.appendChild(newspan3_1);
			newcell3.appendChild(newspan3_2);
			newspan3_1.appendChild(newqty3);
			newspan3_2.appendChild(newanchor3_2);
			newanchor3_2.appendChild(newimg3_2);	
			}
	var newcell4 = newrow.insertCell(3);
		var parentDiv = newcell4.parentNode;
		parentDiv.insertBefore(document.createTextNode("\n\t\t\t"),newcell4);
		//	newcell4.appendChild(document.createTextNode("\n\t\t\t"));
			newcell4.setAttribute('align','left');
			newcell4.setAttribute('width','90');
			var newspan4_1 = document.createElement("span");
				newspan4_1.setAttribute('class','formlabelblackbold');
				newspan4_1.setAttribute('className','formlabelblackbold');
				newspan4_1.setAttribute('id','size_'+setno+'_'+prevrecno);
		if(styleno == 3) {
				var newsize4_1 = document.createTextNode('Universal');
				var newspan4_2 = document.createElement("span");
				newspan4_2.setAttribute('class','formlabelblackbold');
				newspan4_2.setAttribute('className','formlabelblackbold');
				newspan4_2.setAttribute('id','chgsize_'+setno+'_'+prevrecno);
				newcell4.appendChild(newspan4_1);
				newcell4.appendChild(newspan4_2);
				newspan4_1.appendChild(newsize4_1);
			}else{
//				var newsize4_1 = document.createTextNode('Adult-S');
				var newsize4_1 = document.createTextNode('S-Adult');
				var newspan4_2 = document.createElement("span");
				newspan4_2.setAttribute('class','formlabelblackbold');
				newspan4_2.setAttribute('className','formlabelblackbold');
				newspan4_2.setAttribute('id','chgsize_'+setno+'_'+prevrecno);
				var newanchor4_2 = document.createElement('a');			
					newanchor4_2.setAttribute('title','Change Size');
		if(document.getElementById("ordernumber") ) {
						newanchor4_2.setAttribute('href','javascript:void(onclick=chg_size1(\'csize_'+setno+'_'+prevrecno+'\'))');
					}else{
						newanchor4_2.setAttribute('href','javascript:void(onclick=chgsize(\'csize_'+setno+'_'+prevrecno+'\',\''+styleno+'\'))');
					}
					newanchor4_2.setAttribute('class','formlabelblue');
					newanchor4_2.setAttribute('className','formlabelblue');
				var newimg4_2 = document.createElement('img');
					newimg4_2.setAttribute('alt','change size');
					newimg4_2.setAttribute('src','http://www.x-grain.com/images/nav/pencil.gif');
				newcell4.appendChild(newspan4_1);
				newcell4.appendChild(newspan4_2);
				newspan4_1.appendChild(newsize4_1);
				newspan4_2.appendChild(newanchor4_2);
				newanchor4_2.appendChild(newimg4_2);
				}
	var newcell5 = newrow.insertCell(4);
		var parentDiv = newcell5.parentNode;
		parentDiv.insertBefore(document.createTextNode("\n\t\t\t"),newcell5);
		// newcell5.appendChild(document.createTextNode("\n\t\t\t"));
		newcell5.setAttribute('align','left');
		newcell5.setAttribute('width','260');
		var newspan5_1 = document.createElement("span");
			newspan5_1.setAttribute('class','formlabelreditalic');
			newspan5_1.setAttribute('className','formlabelreditalic');
			newspan5_1.setAttribute('id','name_'+setno+'_'+prevrecno);
		if(styleno == 1){	
			var newname5_1 = document.createTextNode('(none)');
				var newspan5_2 = document.createElement("span");
					newspan5_2.setAttribute('class','formlabelblackbold');
					newspan5_2.setAttribute('className','formlabelblackbold');
					newspan5_2.setAttribute('id','chgname_'+setno+'_'+prevrecno);
				var newanchor5_2 = document.createElement('a');			
					newanchor5_2.setAttribute('title','Change Name');
		if(document.getElementById("ordernumber") ) {
						newanchor5_2.setAttribute('href','javascript:void(onclick=chg_name1(\'name_'+setno+'_'+prevrecno+'\'))');
					}else{
						newanchor5_2.setAttribute('href','javascript:void(onclick=chgname(\'name_'+setno+'_'+prevrecno+'\',\''+styleno+'\'))');
					}
					newanchor5_2.setAttribute('class','formlabelblue');
					newanchor5_2.setAttribute('className','formlabelblue');
				var newimg5_2 = document.createElement('img');
					newimg5_2.setAttribute('alt','change name');
					newimg5_2.setAttribute('src','http://www.x-grain.com/images/nav/pencil.gif');
				newcell5.appendChild(newspan5_1);
				newcell5.appendChild(newspan5_2);
				newspan5_1.appendChild(newname5_1);
				newspan5_2.appendChild(newanchor5_2);
				newanchor5_2.appendChild(newimg5_2);
			}else{
			var newname5_1 = document.createTextNode('(n/a)');
				newspan5_1.appendChild(newname5_1);
				newcell5.appendChild(newspan5_1);
			}
	var newcell6 = newrow.insertCell(5);
		var parentDiv = newcell6.parentNode;
		parentDiv.insertBefore(document.createTextNode("\n\t\t\t"),newcell6);
		// newcell6.appendChild(document.createTextNode("\n\t\t\t"));
		newcell6.setAttribute('align','left');
		newcell6.setAttribute('width','60');
		var newspan6_1 = document.createElement("span");
			newspan6_1.setAttribute('class','formlabelreditalic');
			newspan6_1.setAttribute('className','formlabelreditalic');
			newspan6_1.setAttribute('id','no_'+setno+'_'+prevrecno);
		if(styleno == 1){	
			var newno6_1 = document.createTextNode('(none)');
				var newspan6_2 = document.createElement("span");
					newspan6_2.setAttribute('class','formlabelblackbold');
					newspan6_2.setAttribute('className','formlabelblackbold');
					newspan6_2.setAttribute('id','chgno_'+setno+'_'+prevrecno);
				var newanchor6_2 = document.createElement('a');			
					newanchor6_2.setAttribute('title','Change Number');
		if(document.getElementById("ordernumber")) {
						newanchor6_2.setAttribute('href','javascript:void(onclick=chg_no1(\'cno_'+setno+'_'+prevrecno+'\'))');
					}else{
						newanchor6_2.setAttribute('href','javascript:void(onclick=chgno(\'cno_'+setno+'_'+prevrecno+'\',\''+styleno+'\'))');
					}
					newanchor6_2.setAttribute('class','formlabelblue');
					newanchor6_2.setAttribute('className','formlabelblue');
				var newimg6_2 = document.createElement('img');
					newimg6_2.setAttribute('alt','change number');
					newimg6_2.setAttribute('src','http://www.x-grain.com/images/nav/pencil.gif');
				newcell6.appendChild(newspan6_1);
				newcell6.appendChild(newspan6_2);
				newspan6_1.appendChild(newno6_1);
				newspan6_2.appendChild(newanchor6_2);
				newanchor6_2.appendChild(newimg6_2);
				}else{
			var newno6_1 = document.createTextNode('(n/a)');
				newcell6.appendChild(newspan6_1);
				newspan6_1.appendChild(newno6_1);
			}		
	var newcell7 = newrow.insertCell(6);
		var parentDiv = newcell7.parentNode;
		parentDiv.insertBefore(document.createTextNode("\n\t\t\t"),newcell7);
		// newcell7.appendChild(document.createTextNode("\n\t\t\t"));
		newcell7.setAttribute('align','right');
		newcell7.setAttribute('width','75');
		var newspan7_1 = document.createElement("span");
			newspan7_1.setAttribute('class','formlabelprice');
			newspan7_1.setAttribute('className','formlabelprice');
			newspan7_1.setAttribute('id','price_'+setno+'_'+prevrecno);
		newcell7.appendChild(newspan7_1);

	var newcell8 = newrow.insertCell(7);
		var parentDiv = newcell8.parentNode;
		parentDiv.insertBefore(document.createTextNode("\n\t\t\t"),newcell8);
		// newcell8.appendChild(document.createTextNode("\n\t\t\t"));
		newcell8.setAttribute('align','center');
		newcell8.setAttribute('width','30');
		newcell8.setAttribute('class','formlabelfree');
		newcell8.setAttribute('className','formlabelfree');
		var newinput2 = document.createElement("input");
			// newinput2.appendChild(document.createTextNode("\n"));
			newinput2.setAttribute('type','checkbox');
			newinput2.setAttribute('onClick','setFG(\'free_'+setno+'_'+prevrecno+'\');');
			// newinput2.setAttribute('onclick','setFG(\'free_'+setno+'_'+prevrecno+'\');');
			newinput2.setAttribute('value','');
			newinput2.setAttribute('name','nfree_'+setno+'_'+prevrecno);
			newinput2.setAttribute('id','free_'+setno+'_'+prevrecno);
		var newinputfree = '<input id="free_'+setno+'_'+prevrecno+'" name="nfree_'+setno+'_'+prevrecno+'" value="" onClick="setFG(\'free_'+setno+'_'+prevrecno+'\');" type="checkbox">';
		var newinput3 = document.createElement("input");
			// newinput3.appendChild(document.createTextNode("\n\t\t\t"));
			newinput3.setAttribute('type','hidden');
	if(document.getElementById("ordernumber") ) {
//				newinput3.setAttribute('value',setno+';'+prevrecno+';1;Adult-S;;;0;0;0;0');
				newinput3.setAttribute('value',setno+';'+prevrecno+';1;S-Adult;;;0;0;0;0');
			}else{
//				newinput3.setAttribute('value',setno+';'+prevrecno+';1;Adult-S;;;0;0');
				newinput3.setAttribute('value',setno+';'+prevrecno+';1;S-Adult;;;0;0');
			}
			newinput3.setAttribute('name','trvals_'+setno+'_'+prevrecno);
			newinput3.setAttribute('id','trvals_'+setno+'_'+prevrecno);
		newcell8.innerHTML = '<input id="free_'+setno+'_'+prevrecno+'" name="nfree_'+setno+'_'+prevrecno+'" value="" onClick="setFG(\'free_'+setno+'_'+prevrecno+'\');" type="checkbox">'+"\n";
		newcell8.appendChild(newinput3);
	var newcell9 = newrow.insertCell(8);
		var parentDiv = newcell9.parentNode;
		parentDiv.insertBefore(document.createTextNode("\n\t\t\t"),newcell9);
		parentDiv.appendChild(document.createTextNode("\n\n\n"));
		newcell9.setAttribute('align','left');
		newcell9.setAttribute('width','60');
		var newimg9_1 = document.createElement('img');
			newimg9_1.setAttribute('src','http://www.x-grain.com/images/nav/arrowleft.gif');
		var newspan9_0 = document.createElement("span");
		var newspan9_1 = document.createElement("span");
			newspan9_1.setAttribute('class','formlabelblackbold');
			newspan9_1.setAttribute('className','formlabelblackbold');
			newspan9_1.setAttribute('id','del_'+setno+'_'+prevrecno);
		var newspan9_2 = document.createElement("span");
		var newanchor9_1 = document.createElement('a');			
			newanchor9_1.setAttribute('title','Delete Item');
			newanchor9_1.setAttribute('href','javascript:void(onclick=itemdel(\'tr_'+setno+'_'+prevrecno+'\'))');
			newanchor9_1.setAttribute('class','formlabelsmall');
			newanchor9_1.setAttribute('className','formlabelsmall');
		var newimg9_2 = document.createElement('img');
			newimg9_2.setAttribute('alt','delete item');
			newimg9_2.setAttribute('src','http://www.x-grain.com/images/nav/itemdelx.gif');
		newspan9_0.appendChild(newimg9_1);
		newcell9.appendChild(newspan9_0);
		newcell9.appendChild(newspan9_1);
			newspan9_1.appendChild(newanchor9_1);
//			newanchor9_1.appendChild(newimg9_2);
		newcell9.appendChild(newspan9_2);
	if(document.getElementById("ordernumber") ) 
		{
			chg_dbline_add(setno, prevrecno);
		}else{
			chgsize('csize_'+setno+'_'+prevrecno , styleno);
		}
	} // end fuction itemadd()

function setdel(setname)
	{
	answer = confirm(' Clicking OK will remove this SET and all the ITEMS under it. This will also Mark all your Free Garments to PAID!');
		if(!answer){
			return false;
			}else{
			var setarray = setname.split("_");
			var fieldname = setarray[0];
			var setno = setarray[1];
			var nextsetno = parseInt(setno)+1;
			if( (setno == 1) && (!document.getElementById('cartset_'+nextsetno)))
				{
		// alert('Is Set 1 and no other sets exists return to empty cart')
					var cartarray = new Array();
					if (document.getElementById('ordernumber')) var on = document.getElementById('ordernumber').value;
					var cartvars = document.getElementById('cartvars_'+setno).value;
					cartarray = cartvars.split(";");
					var gm = cartarray[1];
					var st = cartarray[2];
					var sp = cartarray[3];
					var ma = cartarray[4];
					var fc = cartarray[5];
					var bc = cartarray[6];
					var conf_pg = cartarray[7];
					// if (!conf_pg){
					if (!document.getElementById('ordernumber')){
						var emptycart = '<center><p><br>Shopping Cart is Empty<br><br></p>';
						document.getElementById('shopping_cart').innerHTML = emptycart;
						if(document.getElementById('finalizeorder')) document.getElementById('finalizeorder').innerHTML = "";
						var nextsetno = parseInt(setno)+1;
						document.getElementById('garmenttbl_' + nextsetno).innerHTML = "Please wait.......";
						document.getElementById('garmenttbl_' + nextsetno).setAttribute('id','garmenttbl_'+setno);
				getTotals();
				getGarment(1,0);
					}else{
						var emptycart = '<center><p><br>Shopping Cart is Empty<br><br></p>';
						document.getElementById('shopping_cart').innerHTML = emptycart;
						if(document.getElementById('finalizeorder')) document.getElementById('finalizeorder').innerHTML = "";
						var nextsetno = parseInt(setno)+1;
						document.getElementById('garmenttbl_' + nextsetno).innerHTML = "Please wait.......";
						document.getElementById('garmenttbl_' + nextsetno).setAttribute('id','garmenttbl_'+setno);
						var url='http://www.x-grain.com/a/chg_del_dbline2.php?on='+on+'&gm='+gm+'&st='+st+'&sp='+sp+'&ma='+ma+'&fc='+fc+'&bc='+bc;
						httpRequest.open("GET", url, true);
						httpRequest.onreadystatechange = chg_dbline_del3;
						httpRequest.send(null);
					}

				}
			if( (setno != 1) && (!document.getElementById('cartset_'+nextsetno)))
				{
		// alert('Is Last Set and no other sets exists Delete Set and Reset getGarment');
					var cartarray = new Array();
					if (document.getElementById('ordernumber')) var on = document.getElementById('ordernumber').value;
					var cartvars = document.getElementById('cartvars_'+setno).value;
					cartarray = cartvars.split(";");
					var gm = cartarray[1];
					var st = cartarray[2];
					var sp = cartarray[3];
					var ma = cartarray[4];
					var fc = cartarray[5];
					var bc = cartarray[6];
					var conf_pg = cartarray[7];
					// if (!conf_pg){
					if (!document.getElementById('ordernumber')){
						document.getElementById('cartset_'+setno).innerHTML = '';
						var removediv = document.getElementById('cartset_'+setno);
						var cartdiv = document.getElementById('shopping_cart');
						cartdiv.removeChild(removediv);
						var nextsetno = parseInt(setno)+1;
						document.getElementById('garmenttbl_' + nextsetno).innerHTML = "Please wait.......";
						document.getElementById('garmenttbl_' + nextsetno).setAttribute('id','garmenttbl_'+setno);
						if(document.getElementById('freeusedqty').value > 0){
							removeAllFG();
							}
			getTotals();
			getGarment(setno,0);					
					}else{
						var url='http://www.x-grain.com/a/chg_del_dbline2.php?on='+on+'&gm='+gm+'&st='+st+'&sp='+sp+'&ma='+ma+'&fc='+fc+'&bc='+bc;
						httpRequest.open("GET", url, true);
						httpRequest.onreadystatechange = chg_dbline_del3;
						httpRequest.send(null);
						}
					
				}
			if( (setno >= 1) && (document.getElementById('cartset_'+nextsetno)))
				{
		// alert('Is Middle Set, Delete Set, Renumber remainder of Sets and Reset getGarment');
					var cartarray = new Array();
					if (document.getElementById('ordernumber')) var on = document.getElementById('ordernumber').value;
					var cartvars = document.getElementById("cartvars_" + setno).value;
					cartarray = cartvars.split(";");
					var gm = cartarray[1];
					var st = cartarray[2];
					var sp = cartarray[3];
					var ma = cartarray[4];
					var fc = cartarray[5];
					var bc = cartarray[6];
					var conf_pg = cartarray[7];
					// if (!conf_pg){
					if (!document.getElementById('ordernumber')){
						document.getElementById('cartset_'+setno).innerHTML = '';
						var removediv = document.getElementById('cartset_'+setno);
						var cartdiv = document.getElementById('shopping_cart');
						cartdiv.removeChild(removediv);
						var nextsetno = parseInt(setno)+1;
						var prevsetno = parseInt(setno);
						var cartvarsarray = new Array();
						var trvalsarray = new Array();
						while(document.getElementById('cartset_'+nextsetno)) {
								styleno = document.getElementById( "styleno_" + nextsetno).value;
							if(document.getElementById( "cartset_" + nextsetno)) document.getElementById( "cartset_" + nextsetno).id = "cartset_" + prevsetno;
							if(document.getElementById( "setlabel_" + nextsetno)) document.getElementById( "setlabel_" + nextsetno).innerHTML = "Set: " + prevsetno + ".";
							if(document.getElementById( "setlabel_" + nextsetno)) document.getElementById( "setlabel_" + nextsetno).id = "setlabel_" + prevsetno;
							if(document.getElementById( "cartvars_" + nextsetno)) cartvarsold = document.getElementById( "cartvars_" + nextsetno).value;
								cartvarsarray = cartvarsold.split(";"); // split vars into array
								cartvarsnew = prevsetno+";"+cartvarsarray[1]+";"+cartvarsarray[2]+";"+cartvarsarray[3]+";"+cartvarsarray[4]+";"+cartvarsarray[5]+";"+cartvarsarray[6];
								document.getElementById( "cartvars_" + nextsetno).value = cartvarsnew;
							if(document.getElementById( "cartvars_" + nextsetno)) document.getElementById( "cartvars_" + nextsetno).name = "cartvars_" + prevsetno;
							if(document.getElementById( "cartvars_" + nextsetno)) document.getElementById( "cartvars_" + nextsetno).id = "cartvars_" + prevsetno;
							if(document.getElementById( "mascot_" + nextsetno)) document.getElementById( "mascot_" + nextsetno).id = "mascot_" + prevsetno;
							if(document.getElementById( "chgmascot_" + nextsetno)) document.getElementById( "chgmascot_" + nextsetno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=chgmascot(\'mascot_'+prevsetno+'\',\''+styleno+'\'))" title="Change Mascot"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change mascot"></a>';
							if(document.getElementById( "chgmascot_" + nextsetno)) document.getElementById( "chgmascot_" + nextsetno).id = "chgmascot_" + prevsetno;
							if(document.getElementById( "lclogo_" + nextsetno)) document.getElementById( "lclogo_" + nextsetno).id = "lclogo_" + prevsetno;
							if(document.getElementById( "chglclogo_" + nextsetno)) document.getElementById( "chglclogo_" + nextsetno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=chglclogo(\'lclogo_'+prevsetno+'\',\''+styleno+'\'))" title="Change Sport"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change sport"></a>';
							if(document.getElementById( "chglclogo_" + nextsetno)) document.getElementById( "chglclogo_" + nextsetno).id = "chglclogo_" + prevsetno;
							if(document.getElementById( "fcolor_" + nextsetno)) document.getElementById( "fcolor_" + nextsetno).id = "fcolor_" + prevsetno;
							if(document.getElementById( "chgfcolor_" + nextsetno)) document.getElementById( "chgfcolor_" + nextsetno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=chgfcolor(\'fcolor_'+prevsetno+'\',\''+styleno+'\'))" title="Change Fore Color"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change fore color"></a>';
							if(document.getElementById( "chgfcolor_" + nextsetno)) document.getElementById( "chgfcolor_" + nextsetno).id = "chgfcolor_" + prevsetno;
							if(document.getElementById( "bcolor_" + nextsetno)) document.getElementById( "bcolor_" + nextsetno).id = "bcolor_" + prevsetno;
							if(document.getElementById( "chgbcolor_" + nextsetno)) document.getElementById( "chgbcolor_" + nextsetno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=chgbcolor(\'bcolor_'+prevsetno+'\',\''+styleno+'\'))" title="Change Back Color"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change back color"></a>';
							if(document.getElementById( "chgbcolor_" + nextsetno)) document.getElementById( "chgbcolor_" + nextsetno).id = "chgbcolor_" + prevsetno;
							if(document.getElementById( "del_" + nextsetno)) document.getElementById( "del_" + nextsetno).innerHTML = '<a class="formlabelblue" href="javascript:void(onclick=setdel(\'set_'+prevsetno+'\',\''+styleno+'\'))" title="Delete Set"><img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete set"></a>';
							if(document.getElementById( "del_" + nextsetno)) document.getElementById( "del_" + nextsetno).id = "del_" + prevsetno;
							if(document.getElementById( "table_" + nextsetno)) document.getElementById( "table_" + nextsetno).id = "table_" + prevsetno;
							var prevrecno = 1;
							var nextrecno = 1;
							while (document.getElementById( "trvals_" + nextsetno + "_" + nextrecno)) {
								if(document.getElementById( "tr_" + nextsetno + "_" + nextrecno)) document.getElementById( "tr_" + nextsetno + "_" + nextrecno).id = "tr_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "styleno_" + nextsetno)) document.getElementById( "styleno_" + nextsetno).id = "styleno_" + prevsetno;
								if(document.getElementById( "line_" + nextsetno + "_" + nextrecno)) document.getElementById( "line_" + nextsetno + "_" + nextrecno).id = "line_" + prevsetno + "_" + nextrecno;
								currentqty = document.getElementById( "qty_" + nextsetno + "_" + nextrecno).value;
								if(document.getElementById( "chgqty_" + nextsetno + "_" + nextrecno)) document.getElementById( "chgqty_" + nextsetno + "_" + nextrecno).innerHTML = '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgqty(\'qty_'+prevsetno+'_'+nextrecno+'\',\''+styleno+'\',\''+currentqty+'\'))" title="Change Quantity"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change quantity"></a>';
								if(document.getElementById( "qty_" + nextsetno + "_" + nextrecno)) document.getElementById( "qty_" + nextsetno + "_" + nextrecno).id = "qty_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "chgqty_" + nextsetno + "_" + nextrecno)) document.getElementById( "chgqty_" + nextsetno + "_" + nextrecno).id = "chgqty_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "chgsize_" + nextsetno + "_" + nextrecno)) document.getElementById( "chgsize_" + nextsetno + "_" + nextrecno).innerHTML = '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgsize(\'csize_'+prevsetno+'_'+nextrecno+'\',\''+styleno+'\'))" title="Change Size"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change size"></a>';
								if(document.getElementById( "chgsize_" + nextsetno + "_" + nextrecno)) document.getElementById( "chgsize_" + nextsetno + "_" + nextrecno).id = "chgsize_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "size_" + nextsetno + "_" + nextrecno)) document.getElementById( "size_" + nextsetno + "_" + nextrecno).id = "size_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "chgname_" + nextsetno + "_" + nextrecno)) document.getElementById( "chgname_" + nextsetno + "_" + nextrecno).innerHTML = '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgname(\'cname_'+prevsetno+'_'+nextrecno+'\',\''+styleno+'\'))" title="Change Name"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change name"></a>';
								if(document.getElementById( "name_" + nextsetno + "_" + nextrecno)) document.getElementById( "name_" + nextsetno + "_" + nextrecno).id = "name_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "chgname_" + nextsetno + "_" + nextrecno)) document.getElementById( "chgname_" + nextsetno + "_" + nextrecno).id = "chgname_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "chgno_" + nextsetno + "_" + nextrecno)) document.getElementById( "chgno_" + nextsetno + "_" + nextrecno).innerHTML = '<a className="formlabelblue" class="formlabelblue" href="javascript:void(onclick=chgno(\'cno_'+prevsetno+'_'+nextrecno+'\',\''+styleno+'\'))" title="Change Number"><img src="http://www.x-grain.com/images/nav/pencil.gif" alt="change number"></a>';
								if(document.getElementById( "no_" + nextsetno + "_" + nextrecno)) document.getElementById( "no_" + nextsetno + "_" + nextrecno).id = "no_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "chgno_" + nextsetno + "_" + nextrecno)) document.getElementById( "chgno_" + nextsetno + "_" + nextrecno).id = "chgno_" + prevsetno + "_" + prevrecno;
								if(document.getElementById( "del_" + nextsetno + "_" + nextrecno)) document.getElementById( "del_" + nextsetno + "_" + nextrecno).innerHTML = '<a className="formlabelsmall" class="formlabelsmall" href="javascript:void(onclick=itemdel(\'tr_'+prevsetno+'_'+nextrecno+'\',\'1\'))"><img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="delete item"></a>';
								if(document.getElementById( "del_" + nextsetno + "_" + nextrecno)) document.getElementById( "del_" + nextsetno + "_" + nextrecno).id = "del_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "price_" + nextsetno + "_" + nextrecno)) document.getElementById( "price_" + nextsetno + "_" + nextrecno).id = "price_" + prevsetno + "_" + nextrecno;
								if(document.getElementById( "free_" + nextsetno + "_" + nextrecno)) document.getElementById( "free_" + nextsetno + "_" + nextrecno).id = "free_" + prevsetno + "_" + nextrecno;
								document.getElementById( "free_" + prevsetno + "_" + nextrecno).setAttribute('onClick','setFG(\'free_'+prevsetno+'_'+nextrecno+'\');');
								// document.getElementById( "free_" + prevsetno + "_" + nextrecno).setAttribute('onclick','setFG(\'free_'+prevsetno+'_'+nextrecno+'\')');
								document.getElementById( "free_" + prevsetno + "_" + nextrecno).setAttribute('name','nfree_'+prevsetno+'_'+nextrecno);
								if(document.getElementById( "trvals_" + nextsetno + "_" + nextrecno))
									{
									trvalsold = document.getElementById( "trvals_" + nextsetno + "_" + nextrecno).value;
									trvalsarray = trvalsold.split(";"); // split vars into array
									trvalsnew = prevsetno+";"+trvalsarray[1]+";"+trvalsarray[2]+";"+trvalsarray[3]+";"+trvalsarray[4]+";"+trvalsarray[5]+";"+trvalsarray[6]+";"+trvalsarray[7];
									document.getElementById( "trvals_" + nextsetno + "_" + nextrecno).value = trvalsnew;
									document.getElementById( "trvals_" + nextsetno + "_" + nextrecno).id = "trvals_" + prevsetno + "_" + nextrecno;
									document.getElementById( "trvals_" + prevsetno + "_" + nextrecno).setAttribute('name','trvals_'+prevsetno+'_'+nextrecno);
									}
								prevrecno++;
								nextrecno++;
								}
							if(document.getElementById( "tr_" + nextsetno + "_" + nextrecno)) document.getElementById( "tr_" + nextsetno + "_" + nextrecno).id = "tr_" + prevsetno + "_" + nextrecno;
							if(document.getElementById( "line_" + nextsetno + "_" + nextrecno)) document.getElementById( "line_" + nextsetno + "_" + nextrecno).id = "line_" + prevsetno + "_" + nextrecno;
							if(document.getElementById( "qty_" + nextsetno + "_" + nextrecno)) document.getElementById( "qty_" + nextsetno + "_" + nextrecno).id = "qty_" + prevsetno + "_" + nextrecno;
							if(document.getElementById( "size_" + nextsetno + "_" + nextrecno)) document.getElementById( "size_" + nextsetno + "_" + nextrecno).id = "size_" + prevsetno + "_" + nextrecno;
							if(document.getElementById( "name_" + nextsetno + "_" + nextrecno)) document.getElementById( "name_" + nextsetno + "_" + nextrecno).id = "name_" + prevsetno + "_" + nextrecno;
							if(document.getElementById( "no_" + nextsetno + "_" + nextrecno)) document.getElementById( "no_" + nextsetno + "_" + nextrecno).id = "no_" + prevsetno + "_" + nextrecno;
							if(document.getElementById( "add_" + nextsetno + "_" + nextrecno)) document.getElementById( "add_" + nextsetno + "_" + nextrecno).innerHTML = '<a class="formlabelsmall" href="javascript:void(onclick=itemadd(\'tr_'+prevsetno+'_'+nextrecno+'\'))"><img src="http://www.x-grain.com/images/nav/itemdelx.gif" alt="add item"></a>';
							if(document.getElementById( "add_" + nextsetno + "_" + nextrecno)) document.getElementById( "add_" + nextsetno + "_" + nextrecno).id = "add_" + prevsetno + "_" + nextrecno;
						prevsetno++;
						nextsetno++;
						}
						document.getElementById('garmenttbl_' + nextsetno).innerHTML = "Please wait.......";
						document.getElementById('garmenttbl_' + nextsetno).setAttribute('id','garmenttbl_'+prevsetno);
						removeAllFG();
						getTotals();
						getGarment(prevsetno,0);
					}else{
						var url='http://www.x-grain.com/a/chg_del_dbline2.php?on='+on+'&gm='+gm+'&st='+st+'&sp='+sp+'&ma='+ma+'&fc='+fc+'&bc='+bc;
						httpRequest.open("GET", url, true);
						httpRequest.onreadystatechange = chg_dbline_del3;
						httpRequest.send(null);
					}
				}
			return false;
		}
	} // end function setdel()

function getTotals()
	{
		var setno = 1;
		if(!document.getElementById('cartvars_'+setno)) 
		{
			var paidqty = 0;
				document.getElementById('paidqty').innerHTML = paidqty;
			var paidamt1 = "0.00";
				document.getElementById('paidamt1').innerHTML = '$' + paidamt1;
				document.getElementById('paidamt2').innerHTML = '$' + paidamt1;
				document.getElementById('gtotal').innerHTML = paidamt1;
				document.getElementById('grandtotalamt').innerHTML = paidamt1;
			var avgprice = 0;
				document.getElementById('paidavg1').innerHTML = '$' + avgprice;
			var freequalqty = 0;
				document.getElementById('freequalqty').innerHTML = freequalqty;
			var freequalamt = 0;
				document.getElementById('freequalamt').innerHTML = freequalamt;
			var freeusedqty = 0;
				document.getElementById('freeusedqty').innerHTML = freeusedqty;
			var freeusedamt = 0;
				document.getElementById('freeusedamt').innerHTML = '$' + freeusedamt;
			var freeoverunder = 0;
				document.getElementById('freeoverunder').innerHTML = '$' + freeoverunder;
				return false;
		}else{
			
			var paidqty = 0;
			var paidamt1 = 0;
			var avgprice = 0;
			var freequalqty = 0;
			var freequalamt = 0;
			var freeusedqty = 0;
			var freeusedamt = 0;
			var freeoverunder = 0;
			var trsetvals;
			var trsetvalsarray = new Array();

			while (document.getElementById('cartvars_'+setno))
				{
				var prevrecno = 0;
				var currentrecno = 0;
				var recno = 1;
				while (document.getElementById('trvals_'+setno+'_'+recno))
					{
						trsetvals = document.getElementById('trvals_'+setno+'_'+recno).value;
						trsetvalsarray = trsetvals.split(";"); // split vars into array
						currentrecno = trsetvalsarray[1];
						if(prevrecno != currentrecno){
							if (trsetvalsarray[6]=="0") paidqty += parseInt(trsetvalsarray[2]);
							if (trsetvalsarray[6]=="0") paidamt1 += parseInt(trsetvalsarray[7]);
							if (trsetvalsarray[6]=="1") freeusedqty += parseInt(trsetvalsarray[2]);
							if (trsetvalsarray[6]=="1") freeusedamt += parseInt(trsetvalsarray[7]);
							
							}
						prevrecno = currentrecno;
						recno++;
					}
				setno++;
				}
				if( paidqty < 15) freequalqty = 0;
				if( (paidqty > 14) && (paidqty < 28) ) freequalqty = 1;
				if( (paidqty > 27) && (paidqty < 40) ) freequalqty = 2;
				if( (paidqty > 39) && (paidqty < 52) ) freequalqty = 3;
				if( (paidqty > 51) && (paidqty < 64) ) freequalqty = 4;
				if( (paidqty > 63) && (paidqty < 78) ) freequalqty = 6;
				if( (paidqty > 77) && (paidqty < 93) ) freequalqty = 8;
				if( (paidqty > 92) && (paidqty < 106) ) freequalqty = 9;
				if( (paidqty > 105) && (paidqty < 118) ) freequalqty = 10;
				if( (paidqty > 117) && (paidqty < 130) ) freequalqty = 11;
				if( (paidqty > 129) && (paidqty < 142) ) freequalqty = 12;
				if( (paidqty > 141) && (paidqty < 156) ) freequalqty = 14;
				if( (paidqty > 155) && (paidqty < 171) ) freequalqty = 16;
				if( (paidqty > 170) && (paidqty < 184) ) freequalqty = 17;
				if( (paidqty > 183) && (paidqty < 196) ) freequalqty = 18;
				if( (paidqty > 195) && (paidqty < 208) ) freequalqty = 19;
				if( (paidqty > 207) && (paidqty < 220) ) freequalqty = 20;
				if( (paidqty > 219) && (paidqty < 234) ) freequalqty = 22;
				if( (paidqty > 233) && (paidqty < 249) ) freequalqty = 24;
				if( (paidqty > 248) && (paidqty < 262) ) freequalqty = 25;
				if( (paidqty > 261) && (paidqty < 274) ) freequalqty = 26;
				if( (paidqty > 273) && (paidqty < 286) ) freequalqty = 27;
				if( (paidqty > 285) && (paidqty < 298) ) freequalqty = 28;
				if( (paidqty > 297) && (paidqty < 312) ) freequalqty = 30;
				if( (paidqty > 311) && (paidqty < 327) ) freequalqty = 32;
				if( (paidqty > 326) && (paidqty < 340) ) freequalqty = 33;
				if( (paidqty > 339) && (paidqty < 352) ) freequalqty = 34;
				if( (paidqty > 351) && (paidqty < 364) ) freequalqty = 35;
				if( (paidqty > 363) && (paidqty < 376) ) freequalqty = 36;
				if( (paidqty > 375) && (paidqty < 390) ) freequalqty = 38;
				if( (paidqty > 389) && (paidqty < 405) ) freequalqty = 40;
				if( (paidqty > 404) && (paidqty < 418) ) freequalqty = 41;
				if( (paidqty > 417) && (paidqty < 430) ) freequalqty = 42;
				if( (paidqty > 429) && (paidqty < 442) ) freequalqty = 43;
				if( (paidqty > 441) && (paidqty < 454) ) freequalqty = 44;
				if( (paidqty > 453) && (paidqty < 468) ) freequalqty = 46;
				if( (paidqty > 467) && (paidqty < 483) ) freequalqty = 48;
				if( (paidqty > 482) && (paidqty < 496) ) freequalqty = 49;
				if( (paidqty > 495) && (paidqty < 508) ) freequalqty = 50;
				var avgcalc = paidamt1 / paidqty ;
				freeoverunder = (parseInt(freequalqty)*parseFloat(avgcalc))-(parseFloat(freeusedamt));
				if (freeoverunder < 0 ) {
					freeoverunder = Math.abs(freeoverunder);
		// alert('freeoverunder =   '+freeoverunder);
					}else{
					freeoverunder = 0;
		// alert('freeoverunder =   '+freeoverunder);
					}
				freeoverunder = CurrencyFormatted(freeoverunder);
				paidamt1 = CurrencyFormatted( (paidamt1) );
				if ( paidqty <8 ) {
					document.getElementById('handlingamt').innerHTML = "12.00";
					}else{
					document.getElementById('handlingamt').innerHTML = "0.00";
					}
				if (document.getElementById('logosetupamt')) var logosetupamt = document.getElementById('logosetupamt').innerHTML;
				if (document.getElementById('residentialamt')) var residentialamt = document.getElementById('residentialamt').innerHTML;
				if (document.getElementById('handlingamt')) var handlingamt = document.getElementById('handlingamt').innerHTML;
				if (document.getElementById('multilogoamt')) var multilogoamt = document.getElementById('multilogoamt').innerHTML;
				// grandtotal = Number(paidamt1) + Number(freeoverunder);
				grandtotal = Number(paidamt1) + Number(logosetupamt) + Number(residentialamt) + Number(handlingamt) + Number(multilogoamt) + Number(freeoverunder);
		// alert('grand total =   '+grandtotal);
					if ( paidqty <8 ) {
				document.getElementById('handlingamt').innerHTML = "12.00";
					}
				document.getElementById('paidqty').innerHTML = paidqty;
					paidamt1 = CurrencyFormatted(paidamt1);
				document.getElementById('paidamt1').innerHTML = '$' + paidamt1;
				document.getElementById('paidamt2').innerHTML = '$' + paidamt1;
					avgprice = CurrencyFormatted(avgcalc);
				document.getElementById('paidavg1').innerHTML = '$' + avgprice;
				document.getElementById('freequalqty').innerHTML = freequalqty;
					// freequalamt = Number(freequalqty * avgprice,2);
					freequalamt = CurrencyFormatted(freequalqty * avgprice);
				document.getElementById('freequalamt').innerHTML = freequalamt;
				document.getElementById('freeusedqty').innerHTML = freeusedqty;
					freeusedamt = CurrencyFormatted(freeusedamt);
				document.getElementById('freeusedamt').innerHTML = freeusedamt;
				document.getElementById('freeoverunder').innerHTML = CurrencyFormatted(Math.abs(freeoverunder));
				document.getElementById('freeoverunder2').innerHTML = CurrencyFormatted(Math.abs(freeoverunder));
				document.getElementById('gtotal').innerHTML = CurrencyFormatted(grandtotal);
				document.getElementById('grandtotalamt').innerHTML = CurrencyFormatted(grandtotal);
				
		}
	} // end function getTotals()
	
function setFG(recno) 
	{
		var setarray = recno.split('_');
		var setno = setarray[1];
		var lineno = setarray[2];
		var freequalqty = document.getElementById('freequalqty').innerHTML;
		var freeusedqty = document.getElementById('freeusedqty').innerHTML;

		var freeborder = parseInt(freequalqty) - parseInt(freeusedqty);
		var paidqty = document.getElementById('paidqty').innerHTML;
		var trvalsline = document.getElementById('trvals_'+setno+'_'+lineno).value;
		var trvalsarray = trvalsline.split(";");

if (document.getElementById('free_'+setno+'_'+lineno).checked == true) var checkedtrue = "true";
if (document.getElementById('free_'+setno+'_'+lineno).value == "checked") var valuechecked = "true";

// alert('freequalqty is '+freequalqty+'  freeusedqty is '+freeusedqty+'  freeborder is '+freeborder+'  checkedtrue is '+checkedtrue+'  valuechecked is '+valuechecked);

		if ( (document.getElementById('free_'+setno+'_'+lineno).checked == true) && (paidqty == 15 || paidqty == 28 || paidqty == 40 || paidqty == 52 || paidqty == 64 || paidqty == 78 || paidqty == 93 || paidqty == 106 || paidqty == 118 || paidqty == 130 || paidqty == 142 || paidqty == 156 || paidqty == 171 || paidqty == 184 || paidqty == 196 || paidqty == 208 || paidqty == 220 || paidqty == 234 || paidqty == 249 || paidqty == 262 || paidqty == 274 || paidqty == 286 || paidqty == 298 || paidqty == 312 || paidqty == 327 || paidqty == 340 || paidqty == 352 || paidqty == 364 || paidqty == 376 || paidqty == 390 || paidqty == 405 || paidqty == 418 || paidqty == 430 || paidqty == 442 || paidqty == 454 || paidqty == 468 || paidqty == 483 || paidqty == 496 || paidqty == 508) && (freeborder == 1) )
			{
			
			alert('Since your at '+paidqty+' PAID items, you must ADD an additional item to mark one as FREE');
			document.getElementById('free_'+setno+'_'+lineno).checked = false;
			return false;
			}
/*
		if ( (document.getElementById('free_'+setno+'_'+lineno).checked == true) && (document.getElementById('free_'+setno+'_'+lineno).value == "checked") )
			{
				document.getElementById('free_'+setno+'_'+lineno).checked = false;
				document.getElementById('free_'+setno+'_'+lineno).value = "";
					document.getElementById('trvals_'+setno+'_'+lineno).value = trvalsarray[0]+';'+trvalsarray[1]+';'+trvalsarray[2]+';'+trvalsarray[3]+';'+trvalsarray[4]+';'+trvalsarray[5]+';0;'+trvalsarray[7];
				document.getElementById('price_'+setno+'_'+lineno).setAttribute('class','formlabelprice');
				document.getElementById('price_'+setno+'_'+lineno).setAttribute('className','formlabelprice');
				getTotals();
				return false;
			}
*/
		if ( (freeborder > 0 ) && (document.getElementById('free_'+setno+'_'+lineno).checked == true) )
			{
				document.getElementById('free_'+setno+'_'+lineno).checked = true;
				document.getElementById('free_'+setno+'_'+lineno).value = "checked";
					document.getElementById('trvals_'+setno+'_'+lineno).value = trvalsarray[0]+';'+trvalsarray[1]+';'+trvalsarray[2]+';'+trvalsarray[3]+';'+trvalsarray[4]+';'+trvalsarray[5]+';1;'+trvalsarray[7];
				document.getElementById('price_'+setno+'_'+lineno).setAttribute('class','formlabelgreenbold');
				document.getElementById('price_'+setno+'_'+lineno).setAttribute('className','formlabelgreenbold');
				getTotals();
			}else{
				document.getElementById('free_'+setno+'_'+lineno).checked = false;
				document.getElementById('free_'+setno+'_'+lineno).value = "";
					document.getElementById('trvals_'+setno+'_'+lineno).value = trvalsarray[0]+';'+trvalsarray[1]+';'+trvalsarray[2]+';'+trvalsarray[3]+';'+trvalsarray[4]+';'+trvalsarray[5]+';0;'+trvalsarray[7];
				document.getElementById('price_'+setno+'_'+lineno).setAttribute('class','formlabelprice');
				document.getElementById('price_'+setno+'_'+lineno).setAttribute('className','formlabelprice');
				getTotals();
			}

	} // end function setFG

function setOrderStatus()
	{
		if(document.getElementById('finalizeorder')) document.getElementById('finalizeorder').innerHTML = '<p><center><br><a href="javascript:document.sports.submit()" title="Submit Order" onmouseover="document.subbutton.src=\'http://www.x-grain.com/images/nav/submit_red.jpg\'" onmouseout="document.subbutton.src=\'http://www.x-grain.com/images/nav/submit_gray.jpg\'"><img src="http://www.x-grain.com/images/nav/submit_gray.jpg" NAME="subbutton" alt="submit order"></a><!-- <input type="submit" value="Submit This Order"> --><br><br></center></p>'
		} // end function setOrderStatus()

function removeAllFG() 
	{
		var setno = 1;
		var freeusedqty = document.getElementById('freeusedqty').innerHTML;
		if(freeusedqty == 0) 
		{
				getTotals();
				return false;
		}else{
			var fct = 0;
			var fcttoclear ="";
			var trsetvals;
			var trsetvalsarray = new Array();
			var newtrsetvals;
			while (document.getElementById('cartvars_'+setno))
				{
				var recno = 1;
				while (document.getElementById('trvals_'+setno+'_'+recno))
					{
						trsetvals = document.getElementById('trvals_'+setno+'_'+recno).value;
						trsetvalsarray = trsetvals.split(";"); // split vars into array
						if (trsetvalsarray[6]=="1") 
							{
							if(document.getElementById('ordernumber')) {
								newtrsetvals = trsetvalsarray[0]+";"+trsetvalsarray[1]+";"+trsetvalsarray[2]+";"+trsetvalsarray[3]+";"+trsetvalsarray[4]+";"+trsetvalsarray[5]+";0;"+trsetvalsarray[7]+";"+trsetvalsarray[8]+";"+trsetvalsarray[9];
								document.getElementById('price_'+setno+'_'+recno).setAttribute('class','formlabelprice');
								document.getElementById('price_'+setno+'_'+recno).setAttribute('className','formlabelprice');
								document.getElementById('trvals_'+setno+'_'+recno).value = newtrsetvals;
								document.getElementById('free_'+setno+'_'+recno).value = "";
								document.getElementById('free_'+setno+'_'+recno).checked = false;
								fct = fct + 1;
								fcttoclear = fcttoclear+setno+'-'+recno+'&';
							}else{
								newtrsetvals = trsetvalsarray[0]+";"+trsetvalsarray[1]+";"+trsetvalsarray[2]+";"+trsetvalsarray[3]+";"+trsetvalsarray[4]+";"+trsetvalsarray[5]+";0;"+trsetvalsarray[7];
								document.getElementById('price_'+setno+'_'+recno).setAttribute('class','formlabelprice');
								document.getElementById('price_'+setno+'_'+recno).setAttribute('className','formlabelprice');
								document.getElementById('trvals_'+setno+'_'+recno).value = newtrsetvals;
								document.getElementById('free_'+setno+'_'+recno).value = "";
								document.getElementById('free_'+setno+'_'+recno).checked = false;
							}

							}
						recno++;
					}
				setno++;
				}
				alert('Deleting Items or Sets has RESET ALL Free Garments you may have Checked ');
				getTotals();
		}
	} // end function removeAllFG

function writeSessionCookie(cookieName, cookieValue)
	{
		if (testSessionCookie())
		{
		document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
		return true;
 		}
		else return false;
	} // end function writeSessionCookie

function getCookieValue (cookieName)
	{
		var exp = new RegExp (escape(cookieName) + "=([^;]+)");
		if (exp.test (document.cookie + ";"))
			{
			exp.exec (document.cookie + ";");
			return unescape(RegExp.$1);
			}
			else return false;
	} // end function getCookieValue

function testSessionCookie () 
	{
		document.cookie ="testSessionCookie=Enabled";
		if (getCookieValue ("testSessionCookie")=="Enabled")
			return true 
		else
		return false;
	} // end function testSessionCookie

function FinalizeOrder()
	{

	} // end function FinalizeOrder		
	
