function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
}

function finalForm(player){
					//this function creates the form for ordering
					
					//these variables are for the cookie values, and the values for the inputs, depending on status
					var nameCookie = '';
					var addressCookie = '';
					var phoneCookie = '';
					//these if/elses check to see if the cookie is set already, if so then sets the vairable,
					// if not then sets it to a blank 
					if(GetCookie('username')!=null){
						nameCookie = GetCookie('username');
					}else{
						nameCookie = '';
					}
					if(GetCookie('userAdd')!=null){
						addressCookie = GetCookie('userAdd');
					}else{
						addressCookie = '';
					}
					if(GetCookie('userPhone')!=null){
						phoneCookie = GetCookie('userPhone');
					}else{
						phoneCookie = '';
					}
					
					//create a div for the entire form
					var con = document.getElementById('container');
					var finalDiv = document.createElement('div');
					con.appendChild(finalDiv);
					finalDiv.setAttribute('id', 'finalFormDiv');
					
					//create the fieldset for the bordering
					var field = document.createElement('fieldset');
					//field.setAttribute('legend', 'Purchasing Information');	
					finalDiv.appendChild(field);
					//create the legend for the personal info title, for effect
					var leg = document.createElement('legend');
				//	leg.setAttribute('text','Purchasing Info');
					var legName = document.createTextNode('Purchasing Info');
					leg.appendChild(legName);
					field.appendChild(leg);
					//create the form 
					var finalForm = document.createElement('form');
					finalForm.setAttribute('id', 'formName');	
					finalForm.setAttribute('name', 'formName');	
					finalForm.setAttribute('action', "javascript:makeCookies('index.html')");	
					finalForm.setAttribute('method', 'POST');	

					field.appendChild(finalForm);

					var hText1 = document.createTextNode('You Have Chosen to Purchase the Jersey of: ');
					var hText2 = document.createTextNode(player);
					finalForm.appendChild(hText1);
					finalForm.appendChild(hText2);
					//finalForm.appendChild(brfunct());
					//create labels for position in css... also create all the inputs and attach them to the form
					var label1 = document.createElement('label');
					label1.setAttribute('for','userName');
					var userN = document.createTextNode('Enter Name: ');
					label1.appendChild(userN);
					finalForm.appendChild(label1);
					
					var nameInput = document.createElement('input');
					nameInput.setAttribute('type', 'text');	
					nameInput.setAttribute('name', 'userName');	
					nameInput.setAttribute('value',nameCookie);
					nameInput.setAttribute('class','formInputField');
					finalForm.appendChild(nameInput);
					
					
					
					var label2 = document.createElement('label');
					label2.setAttribute('for','userAddress');
					var addr = document.createTextNode('Enter Address: ');
					label2.appendChild(addr);
					finalForm.appendChild(label2);
					
					var nameInput2 = document.createElement('input');
					nameInput2.setAttribute('type', 'text');	
					nameInput2.setAttribute('name', 'address');	
					nameInput2.setAttribute('value', addressCookie);
					nameInput2.setAttribute('class','formInputField');
					finalForm.appendChild(nameInput2);
					
					
					
					var label4 = document.createElement('label');
					label4.setAttribute('for','userPhone');
					var phone = document.createTextNode('Enter Phone: ');
					label4.appendChild(phone);
					finalForm.appendChild(label4);
					
					var nameInput3 = document.createElement('input');
					nameInput3.setAttribute('type', 'text');	
					nameInput3.setAttribute('name', 'phone');	
					nameInput3.setAttribute('value', phoneCookie);
					nameInput3.setAttribute('class','formInputField');
					finalForm.appendChild(nameInput3);
					
					
					
					var label3 = document.createElement('label');
					label3.setAttribute('for','credit');
					var credit = document.createTextNode('Enter Credit Card#: ');
					label3.appendChild(credit);
					finalForm.appendChild(label3);
					
					var nameInput3 = document.createElement('input');
					nameInput3.setAttribute('type', 'text');	
					nameInput3.setAttribute('name', 'credit');	
					nameInput3.setAttribute('value','');
					nameInput3.setAttribute('class','formInputField');
					finalForm.appendChild(nameInput3);
					
					
					
					var label5 = document.createElement('label');
					label5.setAttribute('for','credit');
					var creditCo = document.createTextNode('Enter Credit Card Company: ');
					label5.appendChild(creditCo);
					finalForm.appendChild(label5);
					
					var nameInput5 = document.createElement('input');
					nameInput5.setAttribute('type', 'text');	
					nameInput5.setAttribute('name', 'creditCo');	
					nameInput5.setAttribute('value','');
					nameInput5.setAttribute('class','formInputField');
					finalForm.appendChild(nameInput5);
					
					
					
					
					
					
					var sub = document.createElement('input');
					sub.setAttribute('type', 'submit');	
					sub.setAttribute('value', 'submit');
					//sub.setAttribute('action', function(){makeCookies();});	
					//sub.setAttribute('method', 'post');	
					
					//attach the entire form to the form div we previously created	
					finalForm.appendChild(sub);
					
}



function finalPrintout(playerN){
					//this function creates all the player name and picture print outs and appends it to the document
					var path = 'media/players/'+playerN;
					
					var con = document.getElementById('container');
					var finalPrint = document.createElement('div');
					con.appendChild(finalPrint);
					finalPrint.setAttribute('id', 'finalPrint');
					
					var pName = document.createTextNode(playerN);
					finalPrint.appendChild(pName);
					
					var imgEl = document.createElement('img');
					imgEl.setAttribute('src', path+'.jpg');
					
					finalPrint.appendChild(imgEl);
					
}