 
var eproductcodes = new Array();
var eproductnames = new Array();
var edescriptions = new Array();
var nproductcodes = new Array();
var nproductnames = new Array();
var ndescriptions = new Array();
var esubscribed = new Array();

var hideMe="false";

var activeForm;
var successURL = "";
var actionURL = "";
var promoName = "";
var newuser;
var existinguser;
var ispackage;
var overallvalid = false;
var countries = "US,United States ,CA,Canada,AF,Afghanistan,AL,Albania,DZ,Algeria,AD,Andorra,AO,Angola,AI,Anguilla,AG,Antigua and Barbuda,AR,Argentina,AM,Armenia,AW,Aruba,AU,Australia,AT,Austria,AZ,Azerbaijan,PT,Azores,BS,Bahamas,BH,Bahrain,BD,Bangladesh,BB,Barbados,BY,Belarus,BE,Belgium,BJ,Benin,BM,Bermuda,BT,Bhutan,BO,Bolivia,BA,Bosnia-Herzegovina,BW,Botswana,BR,Brazil,BZ,British Honduras (Belize),VG,British Virgin Islands,BN,Brunei Darussalam,BG,Bulgaria,BF,Burkina Faso,MM,Burma,BI,Burundi,KH,Cambodia,CM,Cameroon,CA,Canada,CV,Cape Verde,KY,Cayman Islands,CF,Central African Republic,TD,Chad,CL,Chile,CN,China,CX,Christmas Island,CC,Cocos Island (Australia),CO,Colombia,KM,Comoros,CG,Congo (Brazzaville) Republic of the,CD,Congo Democratic Republic of the,CK,Cook Islands (New Zealand),CR,Costa Rica,CI,Cote dIvoire (Ivory Coast),HR,Croatia,CU,Cuba,CY,Cyprus,CZ,Czech Republic,DK,Denmark,DJ,Djibouti,DM,Dominica,DO,Dominican Republic,TL,East Timor (Indonesia),EC,Ecuador,EG,Egypt,SV,El Salvador,GQ,Equatorial Guinea,ER,Eritrea,EE,Estonia,ET,Ethiopia,FK,Falkland Islands,FO,Faroe Islands,FJ,Fiji,FI,Finland,FR,France,GF,French Guiana,PF,French Polynesia,TF,French West Indies (Guadeloupe or Martinique),GA,Gabon,GM,Gambia,GE,Georgia Republic of,DE,Germany,GH,Ghana,GI,Gibraltar,GB,Great Britain and Northern Ireland,GR,Greece,GL,Greenland,GD,Grenada,GP,Guadeloupe,GT,Guatemala,GN,Guinea,GW,Guinea-Bissau,GY,Guyana,HT,Haiti,HN,Honduras,HK,Hong Kong,HU,Hungary,IS,Iceland,IN,India,ID,Indonesia,IR,Iran,IQ,Iraq,IE,Ireland,IL,Israel,IT,Italy,JM,Jamaica,JP,Japan,JO,Jordan,KZ,Kazakhstan,KE,Kenya,KI,Kiribati,KW,Kuwait,KG,Kyrgyzstan,LA,Laos,LV,Latvia,LB,Lebanon,LS,Lesotho,LR,Liberia,LY,Libya,LI,Liechtenstein,LT,Lithuania,LU,Luxembourg,MO,Macao,MK,Macedonia Republic of,MG,Madagascar,MW,Malawi,MY,Malaysia,MV,Maldives,ML,Mali,MT,Malta,MQ,Martinique,MR,Mauritania,MU,Mauritius,YT,Mayotte (France),MX,Mexico,MD,Moldova,MC,Monaco (France),MS,Montserrat,MA,Morocco,MZ,Mozambique,NA,Namibia,NR,Nauru,NP,Nepal,NL,Netherlands,AN,Netherlands Antilles,NC,New Caledonia,NZ,New Zealand,NI,Nicaragua,NE,Niger,NG,Nigeria,NU,Niue (New Zealand),NF,Norfolk Island (Australia),KP,North Korea,NO,Norway,OM,Oman,PK,Pakistan,PA,Panama,PG,Papua New Guinea,PY,Paraguay,IR,Persia (Iran),PE,Peru,PH,Philippines,PN,Pitcairn Island,PL,Poland,QA,Qatar,RE,Reunion,RO,Romania,RU,Russia,RW,Rwanda,SH,Saint Helena,SL,Saint Lucia,PM,Saint Pierre and Miquelon,VC,Saint Vincent and the Grenadines,SM,San Marino,ST,Sao Tome and Principe,SA,Saudi Arabia,SN,Senegal,YU,Serbia-Montenegro,SC,Seychelles,SG,Singapore,SK,Slovak Republic,SI,Slovenia,SB,Solomon Islands,SO,Somalia,ZA,South Africa,GS,South Georgia (Falkland Islands),KR,South Korea,ES,Spain,LK,Sri Lanka,KN,St. Christopher and Nevis,SD,Sudan,SR,Suriname,SZ,Swaziland,SE,Sweden,CH,Switzerland,TW,Taiwan,TJ,Tajikistan,TZ,Tanzania,TH,Thailand,TG,Togo,TK,Tokelau (Union) Group (Western Samoa),TO,Tonga,TT,Trinidad and Tobago,TN,Tunisia,TR,Turkey,TM,Turkmenistan,TC,Turks and Caicos Islands,TV,Tuvalu,UG,Uganda,UA,Ukraine,AE,United Arab Emirates,US,United States,UY,Uruguay,UZ,Uzbekistan,VU,Vanuatu,VA,Vatican City,VE,Venezuela,VN,Vietnam,WF,Wallis and Futuna Islands,WS,Western Samoa,YE,Yemen,ZM,Zambia,ZW,Zimbabwe"

var states = "N/A,None,AL,Alabama,AK,Alaska,AB,Alberta,AS,American Samoa,AZ,Arizona,AR,Arkansas,AA,Armed Forces America,AE,Armed Forces Other Areas,AP,Armed Forces Pacific,BC,British Columbia,CA,California,CO,Colorado,CT,Connecticut,DE,Delaware,DC,District of Columbia,FL,Florida,GA,Georgia,GU,Guam,HI,Hawaii,ID,Idaho,IL,Illinois,IN,Indiana,IA,Iowa,KS,Kansas,KY,Kentucky,LA,Louisiana,ME,Maine,MB,Manitoba,MH,Marshall Islands,MD,Maryland,MA,Massachusetts,MI,Michigan,FM,Micronesia,MN,Minnesota,MS,Mississippi,MO,Missouri,MT,Montana,NE,Nebraska,NV,Nevada,NB,New Brunswick,NH,New Hampshire,NJ,New Jersey,NM,New Mexico,NY,New York,NF,Newfoundland,NC,North Carolina,ND,North Dakota,MP,Northern Mariana Islands,NT,Northwest Territories,N/A,Not Applicable,NS,Nova Scotia,NU,Nunavut,OH,Ohio,OK,Oklahoma,ON,Ontario,OR,Oregon,PW,Palau,PA,Pennsylvania,PE,Prince Edward Island,PR,Puerto Rico,QC,Quebec,RI,Rhode Island,SK,Saskatchewan,SC,South Carolina,SD,South Dakota,TN,Tennessee,TX,Texas,UT,Utah,VT,Vermont,VI,Virgin Islands,VA,Virginia,WA,Washington,WV,West Virginia,WI,Wisconsin,WY,Wyoming,YK,Yukon"


function addProduct(code,pname,description,newuser,existinguser) {
	if (existinguser) {
		eproductcodes.push(code);
		eproductnames.push(pname);
		edescriptions.push(description);
	}
	if (newuser) {
		nproductcodes.push(code);
		nproductnames.push(pname)	
		ndescriptions.push(description);
	}
	esubscribed[i] = false;
}

function buildForm() {
	var qq = String.fromCharCode(34);
	var q = String.fromCharCode(38);
	var states = buildStates();
	var countries = buildCountries();
	var days = buildDays();
	var months = buildMonths();
	var years = buildYears();

	document.write('<table border=0 cellpadding=0 cellspacing=12>');
	document.write('<tr><td valign=top>');
	
	if (existinguser) {
		document.write('<hr>');
		document.write('<h4>Existing Subscribers<br></h4><div class=' + qq + 'body' + qq + '>(If you are a coaching member, have purchased from our proshop, have registered for a CTS promotion or subscribed to a CTS newsletter, simply enter your username, password, and email address below to sign up.)</div>');
		document.write('<form name='+qq+'existing'+qq+' method=post action=' + qq + actionURL + qq + ' onsubmit='+qq+'return validateForm(this);'+qq+'>');
		document.write('<input type='+qq+'hidden'+qq+' name='+qq+'usertype'+qq+' value='+qq+'existing'+qq+' />');
		document.write('<input type='+qq+'hidden'+qq+' name='+qq+'successURL'+qq+' value=' + qq +successURL + qq +' />');
		document.write('<input type='+qq+'hidden'+qq+' name='+qq+'promoName'+qq+' value='+qq+ promoName +qq+'>');
		document.write('<table border=0 cellpadding=0 cellspacing=10><tr><td>');
		document.write('<table border=0 cellpadding=0 cellspacing=0 >');
		document.write('<tr id='+qq+'username1item'+qq+' class='+qq+'item'+qq+'><td  class='+qq+'caption'+qq+'>Username<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'LoginID'+qq+' value='+qq+''+qq+' onblur='+qq+'validatelogon(this.form);'+qq+'><div id='+qq+'username1instructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'password1item'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Password<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' type='+qq+'password'+qq+' name='+qq+'Password'+qq+' value='+qq+''+qq+' onblur='+qq+'validatelogon(this.form);'+qq+'><div id='+qq+'password1instructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'email1item'+qq+' class='+qq+'item'+qq+'><td class='+qq+'caption'+qq+'>Email Address<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'email'+qq+' value='+qq+''+qq+'><div id='+qq+'email1instructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'confirmemail1item'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'Caption'+qq+'>Confirm Email<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'confirmemail'+qq+' value='+qq+''+qq+'><div id='+qq+'confirmemail1instructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('</table>');
		document.write('<a target=' + qq + '_blank' + qq + ' href=' + qq + 'http://secure.trainright.com/storefront/custforgotpassword.aspx' + qq + '>' + 'Forgot Your Password?' + '</a>');
		document.write('</tr>');
		
		for (var i=0;i<eproductcodes.length;i++) {
			if (edescriptions[i].length==0) {var inputtype="hidden";} else {inputtype="checkbox"}
			if (inputtype=="hidden") {
				document.write('<tr><td>');
				document.write('<div id=' + qq + "productarea" + i + qq + '>');
			document.write('<INPUT type=' + qq + 'hidden' + qq +' value=' + qq +  eproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>');		
				document.write('</div>');
				document.write('</td></tr>');
			} else {
				document.write('<tr><td>');
				document.write('<div id=' + qq + "productarea" + i + qq + '>');
				document.write('<INPUT class=' + qq + 'field' + qq + 'type=' + qq + 'checkbox' + qq +' CHECKED value=' + qq +  eproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>' + edescriptions[i]);
				document.write('</div>');
				document.write('</td></tr>');
			}
		}
		
		document.write('<tr><td>');
		document.write('<div class='+qq+'centered'+qq+'id='+qq+'btnSubmit1'+qq+'><INPUT class=noborder id=btnSubmit type=image src='+qq+'http://www.trainright.com/assets/promotions/enterbutton.gif'+qq+' border=0 name=btnSubmit1></div>');
		document.write('</td></tr>');
		document.write('</table>');
		document.write('</form>');
		//document.write('</div>');
		document.write('');
		
		
	}

	document.write('</td><td>');

	if (newuser) {
		document.write('<hr>');
		document.write('<h4>New Subscribers</h4><br>');
		document.write('<form name='+qq+'new'+qq+' method=post action=' + qq + actionURL + qq + ' onsubmit='+qq+'return validateForm(this);'+qq+'>');
		document.write('<input type='+qq+'hidden'+qq+' name='+qq+'successURL'+qq+' value='+ qq + successURL + qq + ' />');
		document.write('<input type='+qq+'hidden'+qq+' name='+qq+'usertype'+qq+' value='+qq+'new'+qq+'>');
		document.write('<input type='+qq+'hidden'+qq+' name='+qq+'promoName'+qq+' value='+qq+ promoName +qq+'>');
		document.write('<table border=0 cellpadding=0 cellspacing=10>');
		document.write('<tr><td valign='+qq+'top'+qq+'>');
		document.write('<table border=0 cellpadding=0 cellspacing=0>');
		
		document.write('<tr id='+qq+'usernameitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Username<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'LoginID'+qq+' value='+qq+''+qq+' onblur='+qq+'validatelogon(this.form);'+qq+' maxlength='+qq+'25'+qq+'><div id='+qq+'usernameinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'passworditem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td  class='+qq+'caption'+qq+'>Password<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' type='+qq+'password'+qq+' name='+qq+'Password'+qq+' value='+qq+''+qq+' onblur='+qq+'validatelogon(this.form);'+qq+' maxlength='+qq+'25'+qq+'><div id='+qq+'passwordinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'firstnameitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>First Name:<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'firstname'+qq+' value='+qq+''+qq+' maxlength='+qq+'15'+qq+'><div id='+qq+'firstnameinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'lastnameitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Last Name:<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'lastname'+qq+' value='+qq+''+qq+' maxlength='+qq+'25'+qq+'><div id='+qq+'lastnameinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		/* document.write('<tr id='+qq+'address1item'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Address<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'address1'+qq+' value='+qq+''+qq+' maxlength='+qq+'31'+qq+' ><div id='+qq+'address1instructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'address2item'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Address (Cont):</td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'address2'+qq+' value='+qq+''+qq+' maxlength='+qq+'31'+qq+'><div id='+qq+'address2instructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'cityitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>City<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'city'+qq+' value='+qq+''+qq+'  maxlength='+qq+'31'+qq+'><div id='+qq+'cityinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'stateitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>State/Province:<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><select class='+qq+'textinput'+qq+' name='+qq+'state'+qq+'><option></option>' + states + '</select><div id='+qq+'stateinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'countryitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Country:<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><select class='+qq+'textinput'+qq+' name='+qq+'country'+qq+'><option></option>' + countries + '</select><div id='+qq+'countryinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		*/
		document.write('<tr id='+qq+'zipitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Zip/Postal Code:<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'zip'+qq+' value='+qq+''+qq+'  maxlength='+qq+'11'+qq+'><div id='+qq+'zipinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		//document.write('<tr id='+qq+'phoneitem'+qq+' class='+qq+'item'+qq+'>');
		//document.write('<td class='+qq+'caption'+qq+'>Phone:<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'phone'+qq+' value='+qq+''+qq+' ><div id='+qq+'phoneinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'emailitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Email Address<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'email'+qq+' value='+qq+''+qq+'><div id='+qq+'emailinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'confirmemailitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'Caption'+qq+'>Confirm Email<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><input class='+qq+'textinput'+qq+' name='+qq+'confirmemail'+qq+' value='+qq+''+qq+'><div id='+qq+'confirmemailinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		/* document.write('<tr id='+qq+'dobitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Date of Birth<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><select class='+qq+'field'+qq+' name='+qq+'Month'+qq+'>' + months + '</select>&nbsp;/&nbsp;<select  class='+qq+'field'+qq+' name='+qq+'Day'+qq+'>' + days + '</select>&nbsp;/&nbsp;<select class='+qq+'field'+qq+' name='+qq+'Year'+qq+'>' + years + '</select><div id='+qq+'dobinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		document.write('<tr id='+qq+'genderitem'+qq+' class='+qq+'item'+qq+'>');
		document.write('<td class='+qq+'caption'+qq+'>Gender<div class='+qq+'req'+qq+'>&nbsp;*&nbsp;</div></td><td class='+qq+'field'+qq+'><select name='+qq+'gender'+qq+' class='+qq+'field'+qq+'><option value='+qq+'Male'+qq+'>Male</option><option value='+qq+'Female'+qq+'>Female</option></select><div id='+qq+'genderinstructions'+qq+' class='+qq+'instructions'+qq+'></div></td></tr>');
		*/
		document.write('</table>');
		document.write('</td><td valign='+qq+'top'+qq+'>');
		/*
		document.write('<table cellpadding=0 cellspacing=0 border=0>');
		if (ispackage) {
		
			document.write('<tr><td valign='+qq+'top'+qq+'>');
			document.write('<div id='+qq+'sport1item'+qq+'><div class='+qq+'captiontop'+qq+'><span class='+qq+'req'+qq+'>&nbsp;*&nbsp;</span>Tell us what sport you would like:</div><div class='+qq+'field'+qq+'>');
			document.write(' <input  type='+qq+'radio'+qq+' value='+qq+'Cycling'+qq+' name='+qq+'SportID'+qq+' id='+qq+'SportIDCycling'+qq+' />Cycling ');
			document.write('<input  type='+qq+'radio'+qq+' value='+qq+'Running'+qq+' name='+qq+'SportID'+qq+' id='+qq+'SportIDRunning'+qq+'/>Running ');
		
			document.write('</div><div id='+qq+'sport1instructions'+qq+' class='+qq+'instructions'+qq+'></div></div>');
			document.write('</td></tr>');
			document.write('<tr><td>&nbsp;</td></tr>');
		} else {
			document.write('<tr><td>');
			document.write('<div id='+qq+'sport2item'+qq+'><div class='+qq+'captiontop'+qq+'>Sports you participate in: <i>[optional]</i></div><div class='+qq+'field'+qq+'>');
			document.write(' <div><input  type='+qq+'checkbox'+qq+' value=1 name='+qq+'Cycling'+qq+' />Cycling</div>');
			document.write('<div><input  type='+qq+'checkbox'+qq+' value=1 name='+qq+'Multisport'+qq+' />Multisport</div>');
			document.write('<div><input  type='+qq+'checkbox'+qq+' value=1 name='+qq+'Running'+qq+' />Running</div>');
			document.write('<div><input type='+qq+'checkbox'+qq+' value=1 name='+qq+'Racing'+qq+' />Racing</div>');
			document.write('<div><input type='+qq+'checkbox'+qq+' value=1 name='+qq+'Other'+qq+' />Other</div>');
			document.write('</div><div id='+qq+'sport2instructions'+qq+' class='+qq+'instructions'+qq+'></div></div>');
			document.write('</td></tr>');
			document.write('<tr><td>&nbsp;</td></tr>');
		}
		document.write('<tr><td>');
		document.write('<div id='+qq+'fititem'+qq+'><div class='+qq+'captiontop'+qq+'>How Fit Are You? <i>[optional]</i></div><div class='+qq+'field'+qq+'>');
		document.write(' <div><input  type='+qq+'radio'+qq+' value='+qq+'Not Fit'+qq+' name='+qq+'FitnessLevel'+qq+' />Not Fit</div>');
		document.write('<div><input  type='+qq+'radio'+qq+' value='+qq+'Active'+qq+' name='+qq+'FitnessLevel'+qq+' />Active</div>');
		document.write('<div><input  type='+qq+'radio'+qq+' value='+qq+'Extremely Fit'+qq+'  name='+qq+'FitnessLevel'+qq+' />Extremely Fit</div>');
		document.write('</div><div id='+qq+'fitinstructions'+qq+' class='+qq+'instructions'+qq+'></div></div>');
		document.write('</td></tr>');
		document.write('<tr><td>&nbsp;</td></tr>');
		document.write('<tr><td>');
		document.write('<div id='+qq+'coacheditem'+qq+'><div class='+qq+'captiontop'+qq+'>Have You Ever Been Coached Before? <i>[optional]</i></div><div class='+qq+'field'+qq+'>');
		document.write(' <div><input  type='+qq+'radio'+qq+' value='+qq+'Yes'+qq+' name='+qq+'BeenCoached'+qq+' />Yes</div>');
		document.write('<div><input  type='+qq+'radio'+qq+' value='+qq+'No'+qq+' name='+qq+'BeenCoached'+qq+' />No</div>');
		document.write('</div><div id='+qq+'coachedinstructions'+qq+' class='+qq+'instructions'+qq+'></div></div>');
		document.write('</td></tr>');
		document.write('<tr><td>&nbsp;</td></tr>');
		document.write('<tr><td>');
		document.write('<div id='+qq+'frequencyitem'+qq+'><div class='+qq+'captiontop'+qq+'>How Often Do You Train? <i>[optional]</i></div><div class='+qq+'field'+qq+'>');
		document.write(' <SELECT class='+qq+'field'+qq+' name=TrainingFrequency> <OPTION value='+qq+''+qq+' selected></OPTION> <OPTION value='+qq+'0 to 2 times a week'+qq+'>0 to 2 times a week</OPTION> <OPTION value='+qq+'3 to 4 times a week'+qq+'>3 to 4 times a week</OPTION> <OPTION value='+qq+'5 or more times a week'+qq+'>5 or more times a week</OPTION></SELECT>');
		document.write('</div><div id='+qq+'frequencyinstructions'+qq+' class='+qq+'instructions'+qq+'></div></div>');
		document.write('</td></tr>');
		document.write('</table>');
		*/
		document.write('</td></tr>');
		
		for (var i=0;i<nproductcodes.length;i++) {
			if (ndescriptions[i].length==0) {var inputtype="hidden";} else {inputtype="checkbox"}
			if (inputtype=="hidden") {
				document.write('<tr><td>');
				document.write('<div id=' + qq + "productarea" + i + qq + '>');
				document.write ('<INPUT type=' + qq + 'hidden' + qq +' value=' + qq +  nproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>');
				document.write('</div>');
				document.write('</td></tr>');
			} else {
				document.write('<tr><td colspan=2>');
				document.write('<div id=' + qq + "productarea" + i + qq + '>');
				document.write ('<INPUT class=' + qq + 'field' + qq + 'type=' + qq + 'checkbox' + qq +' CHECKED value=' + qq +  nproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>' +  ndescriptions[i].replace("^","&#39;"));
				document.write('</div>');
				document.write('</td></tr>');
			}
		}
		
		document.write('<tr><td colspan=2><div class='+qq+'centered'+qq+'><INPUT class=noborder id=btnSubmit type=image src='+qq+'http://www.trainright.com/assets/promotions/enterbutton.gif'+qq+' border=0 name=btnSubmit></div></td></tr>');
		document.write('</form>');
		document.write('</table>');
		
	}
	document.write('</td></tr></table>');
	
}

//Ajax functions to pre-screen the username and password to make sure that the server will not send an error.

/*
function getNewHTTPObject()
{
        var xmlhttp;

        /** Special IE only code ... */
        /*@cc_on
          @if (@_jscript_version >= 5)
              try
              {
                  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
              }
              catch (e)
              {
                  try
                  {
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  catch (E)
                  {
                      xmlhttp = false;
                  }
             }
          @else
             xmlhttp = false;
        @end @*/

        /** Every other browser on the planet 
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
            try
            {
                xmlhttp = new XMLHttpRequest();
            }
            catch (e)
            {
                xmlhttp = false;
            }
        }

        return xmlhttp;
}
*/


/*
 * Returns a new XMLHttpRequest object, or false if this browser
 * doesn't support it
 */
function getNewHTTPObject() {

  var xmlreq = false;

  if (window.XMLHttpRequest) {

    // Create XMLHttpRequest object in non-Microsoft browsers
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    // Create XMLHttpRequest via MS ActiveX
    try {
      // Try to create XMLHttpRequest in later versions
      // of Internet Explorer

      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1) {

      // Failed to create required ActiveXObject

      try {
        // Try version supported by older versions
        // of Internet Explorer

        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e2) {

        // Unable to create an XMLHttpRequest with ActiveX
      }
    }
  }

  return xmlreq;
}


var xmlHttp = getNewHTTPObject();


function getDynamicData(username,password,productcode)
{
	if ((username.length>0)&&(password.length>0)&&(productcode.length>0)) {
		  overallvalid = false;
		  var url = "checkcustomer.asp?username=" + username + "&password=" + password + "&productcode=" + productcode;
			//alert(url);
		  xmlHttp.open('GET', url, true);
		  xmlHttp.onreadystatechange = callbackFunction;
		  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		  xmlHttp.setRequestHeader('Content-Length',0);
		  xmlHttp.send(null);
	}
}

function callbackFunction()
{

  if (xmlHttp.readyState != 4)
    return;
  var result = xmlHttp.responseText;
	//alert(result);

	if (activeForm=='existing') {
		if (result.indexOf('False')>=0) {
			overallvalid = false;
			showError('username1','Unable to find your account.  Please check username and password.');
			showError('password1',' ');
		} else {
			overallvalid = true;
			clearError('username1');
			clearError('password1');
			checkProducts(result);
		}
	}	
	
	if (activeForm=='new') {
		if (result.indexOf('True')>=0) {
			overallvalid = false;
			showError('username','This username has already been taken.  Please choose a different username.');
			showError('password',' ');
		} else {
			overallvalid = true;
			clearError('username');
			clearError('password');
		}
	}	


  /* if you've returned javascript instead of xml or text, 
  you can eval(result) to access the javascript variables returned.
  */
}

function showError(inp,msg) {
	var instr =inp + "instructions";
	var item =inp + "item";
	document.getElementById(instr).innerHTML=msg;
	document.getElementById(instr).style.display='block';
	document.getElementById(item).style.backgroundColor='#FFCCCC';
}

function clearError(inp) {
	var instr =inp + "instructions";
	var item =inp + "item";
	document.getElementById(item).style.backgroundColor='#FFFFFF';
	document.getElementById(instr).style.display='none';
}

function checkProducts(res) {

	for (var i=0;i<eproductcodes.length;i++) {
		var x = eproductcodes[i];
		var instr = "productarea" + i;
		if (res.indexOf(x)>=0) {
			esubscribed[i] = true;	
		} else {
			esubscribed[i] = false;
		}
		document.getElementById(instr).innerHTML = buildSubscription(i);
		if (eproductcodes[i]==7026 && esubscribed[i]==true) {
		   document.getElementById("btnSubmit1").style.display='none';
		   
		}
	}
			
}

function buildSubscription(i) {
	var qq = String.fromCharCode(34);
	var q = String.fromCharCode(38);
	var h = "";

		if (edescriptions[i].length==0) {
			if (!esubscribed[i]) {
				h +='<INPUT type=' + qq + 'hidden' + qq +' value=' + qq +  eproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>';
			} else {
				if (eproductcodes[i]==7026) {
					h +='<INPUT type=' + qq + 'hidden' + qq +' value=' + qq + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '><B>You have already registered for this promotion. To redownload the workouts click <a href='+qq+ download_url +qq+'>here.</a></B>'
					hideMe='true';
				} else {
						if (hideMe=='false') {
							h +='<INPUT type=' + qq + 'hidden' + qq +' value=' + qq + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>You are already subscribed to: '  + eproductnames[i];	
						} else {h +='<INPUT type=' + qq + 'hidden' + qq +' value=' + qq +  eproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>';
						}
				}
			}
		} else {
			if (!esubscribed[i]) { 
				if (hideMe=="false") {
					h +='<INPUT class=' + qq + 'field' + qq + 'type=' + qq + 'checkbox' + qq +' CHECKED value=' + qq +  eproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>' +  edescriptions[i]
				} else { h +='<INPUT type=' + qq + 'hidden' + qq +' value=' + qq +  eproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>'}
			} else {
				if (eproductcodes[i]==7026) {
					h +='<INPUT type=' + qq + 'hidden' + qq +' value=' + qq + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '><B>You have already registered for this promotion. To redownload the workouts click <a href='+qq+ download_url +qq+'>here.</a></B>'
					hideMe=1;
				} else {
						if (hideMe=="false") {
							h +='<INPUT type=' + qq + 'hidden' + qq +' value=' + qq + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>You are already subscribed to: '  + eproductnames[i]	
						} else {h +='<INPUT type=' + qq + 'hidden' + qq +' value=' + qq +  eproductcodes[i] + qq + ' name=' + qq  + 'Product' + (i+1) + qq + '>' 
						}
				}
			}
		}
	return h;
}

function validateForm(oForm) {
	
	var valid = true;
	var err;
	
	if (oForm.name=='existing') {

		if (ispackage) {
			if (valid) {
				if ((!oForm.SportIDCycling.checked)&&(!oForm.SportIDRunning.checked)) {
					valid = false;
					showError('sport1','Must choose a sport.');
				} else {
					clearError('sport1');
				}
			}		
		}
	
		//Existing  user form.
		if (valid) {
			if ((oForm.LoginID.value.length==0)||(oForm.Password.value.length==0)) {
				valid=false;
				err='Please enter username and password.';
				showError('username1',err);
			}
		}

		if (valid) {
			if ((oForm.promoName.value.indexOf('AMD')>=0)&&(oForm.email.value.indexOf('amd')<0)) {valid=false;err='This promotion is only available to AMD employees.';showError('email1',err);} else {clearError('email1');}
		}

		if (valid) {
			if ((oForm.email.value.indexOf('@')<0)||(oForm.email.value.indexOf('.')<0)) {valid=false;err='Invalid email address.';showError('email1',err);} else {clearError('email1');}
		}


		if (valid) {
			if (oForm.email.value!=oForm.confirmemail.value) {valid=false;err='Email addresses do not match.';showError('confirmemail1',err);} else {clearError('confirmemail1');}
		}
	
		if (valid) valid = checkRequired(oForm.LoginID,'username1','Username');
		if (valid) valid = checkRequired(oForm.Password,'password1','Password');
		if (valid) valid = checkRequired(oForm.email,'email1','Email Address');
		if (valid) valid = checkRequired(oForm.confirmemail,'confirmemail1','Confirm Email');
		
	} else {
	
		//New user form.

		if (ispackage) {	
			if (valid) {
				if ((!oForm.SportIDCycling.checked)&&(!oForm.SportIDRunning.checked)) {
					valid = false;
					showError('sport1','Must choose a sport.');
				} else {
					clearError('sport1');
				}
			}	
		}

		if (valid) {

				if ((oForm.LoginID.value.length==0)||(oForm.Password.value.length==0)) {
				valid=false;
				err='Please enter username and password.';
				showError('username',err);
			}
		}
		
		if (valid) {
			if ((oForm.promoName.value.indexOf('AMD')>=0)&&(oForm.email.value.indexOf('amd')<0)) {valid=false;err='This promotion is only available to AMD employees.';showError('email',err);} else {clearError('email');}
		}
		if (valid) {
			if ((oForm.email.value.indexOf('@')<0)||(oForm.email.value.indexOf('.')<0)) {valid=false;err='Invalid email address.';showError('email',err);} else {clearError('email');}
		}
		if (valid) {
			if (oForm.email.value!=oForm.confirmemail.value) {valid=false;err='Email addresses do not match.';showError('confirmemail',err);} else {clearError('confirmemail');}
		}

		if (valid) valid = checkRequired(oForm.LoginID,'username','Username');
		if (valid) valid = checkRequired(oForm.Password,'password','Password');
		if (valid) valid = checkRequired(oForm.email,'email','Email Address');
		if (valid) valid = checkRequired(oForm.confirmemail,'confirmemail','Confirm Email');
		if (valid) valid = checkRequired(oForm.firstname,'firstname','First Name');
		if (valid) valid = checkRequired(oForm.lastname,'lastname','Last Name');
		if (valid) valid = checkRequired(oForm.address1,'address1','Address');
		if (valid) valid = checkRequired(oForm.city,'city','City');
		if (valid) valid = checkRequired(oForm.state,'state','State');
		if (valid) valid = checkRequired(oForm.country,'country','Country');
		if (valid) valid = checkRequired(oForm.zip,'zip','Zip/Postal Code');
		if (valid) valid = checkRequired(oForm.phone,'phone','Phone');
		//if (valid) valid = checkRequired(oForm.dob,'dob','Year Born');
		//if (valid) valid = checkRequired(oForm.gender,'gender','Gender');	
	}
	
	if (valid) valid = overallvalid;
	return valid;
	
}

function checkRequired2(oInput,inp,cap) {
	var valid = true;
	
	if ((oInput.value!="Cycling")||(oInput.value!="Running")) {
		valid = false;
		showError(inp,cap + " is required.");
	} else {
		clearError(inp);
	}
	return valid;
}

function checkRequired(oInput,inp,cap) {
	var valid = true;
	
	if (oInput.value.length==0) {
		valid = false;
		showError(inp,cap + " is required.");
	} else {
		clearError(inp);
	}
	return valid;
}

function validatelogon(oForm) {
	activeForm = oForm.usertype.value;
	getDynamicData(oForm.LoginID.value,oForm.Password.value,oForm.Product1.value);
}

function buildCountries() {
	var html = '';
	var arrCountries = countries.split(",");
	for (var i=0;i<(arrCountries.length/2);i++) {
		html = html + '<option value=' + arrCountries[i*2] + '>' + arrCountries[(i*2)+1] + '</option>';
	}

	return html;
}

function buildStates() {
	var html = '';
	var arrStates = states.split(",");
	for (var i=0;i<(arrStates.length/2);i++) {
		html = html + '<option value=' + arrStates[i*2] + '>' + arrStates[(i*2)+1] + '</option>';
	}
	
	return html;
}

function buildYears() {
	var html ='';
	for (var i=2006;i>=1932;i--) {
		html = html + '<option value=' + i + '>' + i + '</option>';
	}
	return html;
}

function buildMonths() {
	var html ='';
	arrMonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	for (var i =1;i<=12;i++) {
		html = html + '<option value=' + i + '>' + arrMonths[i-1] + '</option>';
	}
	return html;
} 

function buildDays() {
	var html ='';
	for (var i=1;i<=31;i++) {
		html = html + '<option value=' + i + '>' + i + '</option>';
	}
	return html;
}
