/* Create the distance learning orientation pages */

var firstName;
var lastName;
var emailAddress;
var birthday;


function initializeOrientation(){
	// Load the banner
	var myBannerObj=new createBanner('http://www.carteret.edu/newfrontpage/images/standardBanner3.jpg');

	myBannerObj.loadBanner();

	var newForm=document.createElement('div');
	//newForm.setAttribute('method','post');
	//newForm.setAttribute('action','storestudent.php');
	//newForm.setAttribute('onSubmit','return checkmyform(this)');



	var newtop=document.createElement('div');
	newtop.setAttribute('id','topElement');
	mdc=document.getElementById('pageContent').appendChild(newtop);
	mdc.innerHTML=firstPage;

	mdc2=document.getElementById('pageContent').appendChild(newForm);

	
	mdc2.innerHTML="<form onSubmit=\"return checkmyform(this)\">First Name: <input type=\"text\" name=\"firstName\" />"+
		" Last Name: <input type=\"text\" name=\"lastName\" /><br />"+
		"Birthday: m/d/yyyy <input type=\"text\" name=\"bday\" /><br />"+
		"Email Address: <input type=\"text\" name=\"email\" /><br />"+
		"Confirm Email Address: <input type=\"text\" name=\"confemail\" /><br />"+
		"Do you have any previous experience with Online Learning? Yes"+
		"<input type=\"radio\" name=\"experienced\" value=\"1\" /> No"+
		"<input type=\"radio\" name=\"experienced\" value=\"0\"/ ><br />"+
		"<input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";
	

	

}

// The first page is the welcome message and a form
var firstPage="<h1>Welcome to Online Learning Orientation</h1>"+
	"<p>You are here because your interest in Online Learning. This site will"+
	" help you understand whether distance learning courses are right for"+ 
	" you. If you are an experienced online learner, this orientation will"+ 
	" provide a quick check of your computer skills so you can begin your online"+
	" experience with confidence. If you are new to online learning, this orientation"+
	" will help you assess whether online learning is right for you. You will be"+ 
	" provided with self assessment resources to help you make this determination.</p>"+
	"<p>Each step in the orientation depends on how you respond to the questions asked"+
	" so you can focus on identifying what you need to be successful.</p>"+
	"<p>In general the orientation guides you through the benefits of online learning,"+
	" a student readiness checklist, resources, and a practice area.</p>"+
	"<p>The most efficient way to complete this orientation is in one sitting."+
	" You cannot save your progress. If you need to return to this site, you will"+
	" be prompted to begin the orientation from its beginning.</p>"+
	"<p>To begin, give your college some information about you before you start the"+
	" self-assessment. Be sure to click the \"Submit\" button after you complete the form.</p>"
;


// A different page is loaded based upon the former experience answer

// If the answer is yes then a list of questions are asked
var secondPageYes="";
var secondPageNo="";

var previousExperience;

/// This function is used to verify that the first form is completed before submission.
function checkmyform(myForm){

	/// Check all fields



	var checkMyForm=new checkForm(myForm);



	if(checkMyForm.checkFirstName(myForm.firstName.value)==false){
		myForm.firstName.focus();
		return false;
	} else {

		firstName=myForm.firstName.value
	}

	if(checkMyForm.checkLastName(myForm.lastName.value)==false){
		myForm.lastName.focus();
		return false;
	} else {
		lastName=myForm.lastName.value;
	}

	if(checkMyForm.checkdateFormat(myForm.bday.value)==false){
		myForm.bday.focus();
		return false;
	} else {
		birthday=myForm.bday.value;
	}

	
	if(checkMyForm.checkEmailAddress(myForm.email.value)==false){
		myForm.email.focus();
		return false;

	} else {
		emailAddress=myForm.email.value;

	}

	if(myForm.email.value != myForm.confemail.value){
		alert("Email values provided do not match");
		myForm.confemail.focus();
		return false;
	}
	

	
	if(myForm.experienced[0].checked == false && myForm.experienced[1].checked == false){

		alert("You must indicate whether or not you have previous experience");
		myForm.experienced[0].focus();
		return false;
	}

	if(myForm.experienced[0].checked == true){
		// At this point we need to store the data and load page 2--This student has previous 
		// experience with Blackboard.

		var myData="firstName="+myForm.firstName.value+"&lastName="+myForm.lastName.value+
				"&email="+myForm.email.value+"&experienced="+myForm.experienced[0].value+
				"&birthDay="+myForm.bday.value;

		var myStoreObj=new getasyncdata("storedlstudent.php","post",myData,'noreturn');

		myStoreObj.requestInfo();

		previousExperience='true';

		/// These are the 10 questions that are the Blackboard questions
		loadQuestions(myForm.firstName.value,myForm.lastName.value,myForm.email.value);

	} else {

		/// Store student information and load page 2 no experience
		
		var myData="firstName="+myForm.firstName.value+"&lastName="+myForm.lastName.value+
				"&email="+myForm.email.value+"&experienced="+myForm.experienced[1].value+
				"&birthDay="+myForm.bday.value;

		var myStoreObj=new getasyncdata("storedlstudent.php","post",myData,'noreturn');

		myStoreObj.requestInfo();

		previousExperience='false';

		loadPageTwo();

	}

	return false;


}

function loadPageTwo(){

	var md=document.getElementById('pageContent');
		md.style.border='none';

	var myHTML="<div style=\"border:solid\"><h1>Step 1: Blackboard Practice Course</h1></div>"+
		"<p>Please click the \"Demo Course\" button below to take a Blackboard cemonstration course</p>"+
		"<p>When you arrive at the main page, please choose \"User Login\", and use the following login info:</p>"+
		"<p><b>Username: </b>online</p><p><b>Password: </b>student</p>"+
		"<input type=\"button\" name=\"bblaunch\" value=\"Demo Course\" onClick=\"window.open('http://blackboard.carteret.edu')\" /><br />"+
		"<p><b><i>The login and password will give you access to the Practice Blackboard ONLY.</b><p>"+
		"<p>When you return, please take the assessment quiz below and submit your results.</p>"+
		"<div style=\"border:solid\"><b>For further assistance:</b><br />"+
		"If you are in need of assistance, or have some additional questions; please feel free to contact via email, the following "+
		"administratior:<br /><ul><li>Joseph Croom <a href=\"mailto:dlorientation@carteret.edu\">dlorientation@carteret.edu</a></li></ul></div>"+
		"<div style=\"border:solid\"><h1>Step 2: Assessment</h1></div>";
		


	/// Working here
	md.innerHTML=myHTML;

	/// Add the test to the page
	launchBBTest();
	

	

}



// If the answer to the experience question is yes then verify that the student has accomplisted all
// of the tasks. 
function loadQuestions(firstName,lastName,emailAddress){

	var newForm=document.createElement('div');
	//newForm.setAttribute('onSubmit','return checkYesAnswers(this)');

	var myString="<form onSubmit=\"return checkYesAnswers(this,firstName,lastName,emailAddress)\">Great "+firstName+" "+lastName+"! Before continuing your Online education, please ensure that"+
		 " you have completed and/or understand the following topics listed below:<br \>"+
		"<input type=\"checkbox\" name=\"yeslist\" value=\"1\" />I have successfully logged into a Blackboard course.<br />"+ 
		"<input type=\"checkbox\" name=\"yeslist\" value=\"2\" />"+
		"I have connected to a Blackboard course without getting a login error when using an Internet Service such as AOL.<br />"+
		"<input type=\"checkbox\" name=\"yeslist\" value=\"3\" />"+
		"I have found the Announcements in a Blackboard course.<br />"+
		"<input type=\"checkbox\" name=\"yeslist\" value=\"4\" />"+
		"I have entered the \"Tools\" area of a Blackboard course and updated my \"personal information\""+
		" so that my first name is listed correctly.<br />"+
		"<input type=\"checkbox\" name=\"yeslist\" value=\"5\" />"+
		"I have entered the \"Tools\" area of a Blackboard course and updated my \"personal information\" with my correct email address.<br />"+ 
		"<input type=\"checkbox\" name=\"yeslist\"value=\"6\" />"+
		"I have found the Syllabus area of a Blackboard course and completed the assignments listed.<br />"+
		"<input type=\"checkbox\" name=\"yeslist\" value=\"7\" />"+
		"I have navigated to a Discussion Board in a Blackboard Course.<br />"+
		"<input type=\"checkbox\" name=\"yeslist\" value=\"8\" />"+ 
		"I have started a thread in the Discussion area of a Blackboard Course.<br />"+
		"<input type=\"checkbox\" name=\"yeslist\" value=\"9\" />"+
		"I have submitted a file in a Blackboard Assignment.<br />"+
		"<input type=\"checkbox\" name=\"yeslist\" value=\"10\" />"+
		"I have checked my grades through the \"Tools\" section of a Blackboard course. (How to check your grades)<br />"+
		"<input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";

	md=document.getElementById('pageContent');
	md.removeChild(md.firstChild);

	md.innerHTML="";
	md.appendChild(newForm).innerHTML=myString;



}

// This function is used to verify that the student familiar with blackboard has performed all of the tasks
// necessary to take an online class
function checkYesAnswers(myForm,firstName,lastName,emailAddress){

	var numberChecked=0;

	for($countChecked=0;$countChecked<myForm.yeslist.length;$countChecked++){

		if(myForm.yeslist[$countChecked].checked == true){
			numberChecked += 1;
		}

	}
	// Still need to store this grade even though they have taken BlackBoard courses before?

	if(numberChecked < 10){
		var finalGrade=(numberChecked/10)*100;

	} else {
		var finalGrade="100";
	}

	var testType="bbTest";
	var myQuestionString="";
	////

	var myData="firstName="+firstName+"&lastName="+lastName+"&email="+emailAddress+
		"&testType="+testType+"&finalGrade="+finalGrade+"&qnum="+myQuestionString+
		"&bday="+birthday;


	var myStoreObj=new getasyncdata("mailgrade.php","post",myData,'noreturn');

	myStoreObj.requestInfo();

	// Launch the system requirements


	showSystemRequirements(firstName,lastName,emailAddress);

/*
	if(numberChecked < 10){

		showSystemRequirements();

	} else {
		/// Assume that they have the system they need if they have taken
		/// online classes before.
		launchDLPractice();

	}
*/

	return false;
}

// Show the connection requirements for online learning
function showSystemRequirements(firstName,lastName,emailAddress){

	md=document.getElementById('pageContent');
	md.removeChild(md.firstChild);

	md.style.border='none';

	md.innerHTML="Loading.....";


	var myDataObj=new getasyncdata("systemRequirements.php?firstName="+firstName+"&lastName="+lastName+"&emailAddress="+emailAddress,'get','null','pageContent');

	myDataObj.requestInfo();


	
}

/// This is the additional info should the student not believe they have a system that meets the requirements.
function showadditionaInfo(){

	md1=document.getElementById("changeButtons")
	md1.style.border='solid';
	md1.style.backgroundColor='yellow';
	
	md1.innerHTML="<p><input type=\"radio\" name=\"gototest\" onClick=\"javascript:launchDLPractice();\" />Go to the Distance Learning practice area.</p>";


	md2=document.getElementById("additionalInfo");
	md2.style.display='block';
	

}
var myStudentId;
function studyHabits(){

	var myURL=document.URL.split(/\?/);
	

	myStudentId=myURL[1];

	var myBannerObj=new createBanner('http://www.carteret.edu/newfrontpage/images/standardBanner3.jpg');

	myBannerObj.loadBanner();


	launchDLPractice();


}
function launchDLPractice(){

	var pgcnt=document.getElementById('pageContent');
		pgcnt.style.border='none';

	
	var newForm=document.createElement('div');
	//newForm.setAttribute('onSubmit','return gradeMyTest(this,\'18\')');
	//newForm.setAttribute('id','dlTest');

	var myElementObj=new createFormObject(newForm);

	var experienceHTML="<form id=\"dlTest\" onSubmit=\"return gradeMyTest(this,'18','preTest')\"><b>Experience</b><br />"+
		"1. I am usually a self-motivated learner and usually accept responsibility for completing assignments, including preparing for examinations, with minimal oversight from my instructor. <br /> "+
		myElementObj.createYesNoButton('Q1')+"<br />"+ 
		"2. In previous courses, I usually am able to create and follow a schedule without procrastinating and without \"face-to-face\" meetings with an instructor or fellow students to help me complete my assignments. <br />"+
		myElementObj.createYesNoButton('Q2')+"<br />"+ 
		"3. I understand that an online learning course requires at least as much time and effort as a classroom course (if not more). <br />"+
		myElementObj.createYesNoButton('Q3')+"<br />"+ 
		"4. I usually am able to comprehend what I read, including textbooks, study-guides, course syllabus, and other supplementary materials. <br />"+
		myElementObj.createYesNoButton('Q4')+"<br />"+ 
		"5. I have been able to recognize the difference between an objective test and an essay exam. <br />"+
		myElementObj.createYesNoButton('Q5')+"<br />"+ 
		"6. My reading and writing skills have been adequate for successful completion of courses I have taken. <br />"+
		myElementObj.createYesNoButton('Q6')+"<br />";

	var equipmentAndAccess="<b>Equipment and Access</b><br />"+
		"1. I own (or have routine unhampered access to) a computer that is connected to the Internet. <br />"+
		myElementObj.createYesNoButton('Q7')+"<br />"+
		"2. I have browsed the Internet with Internet Explorer (or other browser). <br />"+
		myElementObj.createYesNoButton('Q8')+"<br />"+ 
		"3. I have updated or would be able to update my Web browser.<br />"+
		myElementObj.createYesNoButton('Q9')+"<br />"+ 
		"4. The computer I use has a DVD drive for viewing instructional material where required. <br />"+
		myElementObj.createYesNoButton('Q10')+"<br />"+ 
		"5. I have the software needed to take an online learning course. <br />"+
		myElementObj.createYesNoButton('Q11')+"<br />"+ 
		"6. I have quickly learned new technology skills. <br />"+
		myElementObj.createYesNoButton('Q12')+"<br />";

	var computerAndSoftware="<b>Computer and Software Skills</b><br />"+
		"1. I have started my computer and software without help. <br />"+
		myElementObj.createYesNoButton('Q13')+"<br />"+
		"2. I have searched the Internet and been able to save text, images, audio, or video from Web sites. <br />"+
		myElementObj.createYesNoButton('Q14')+"<br />"+
		"3. I have been able to print text or play back audio or video files from Web sites. <br />"+
		myElementObj.createYesNoButton('Q15')+"<br />"+
		"4. I have downloaded and installed any plug-ins needed to use online video or audio files. <br />"+
		myElementObj.createYesNoButton('Q16')+"<br />"+
		"5. I have sent, received, and replied to E-mail messages. <br />"+
		myElementObj.createYesNoButton('Q17')+"<br />"+
		"6. I have written with a word processing program and have been able to copy and paste text. <br />"+
		myElementObj.createYesNoButton('Q18')+"<br />";


	document.getElementById('pageContent').innerHTML="";
	md=document.getElementById('pageContent').appendChild(newForm);
	md.innerHTML=experienceHTML+equipmentAndAccess+computerAndSoftware+
		"<input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";

	md2=document.getElementsByTagName('input');
	md2[0].focus();
	

}

function launchBBTest(){

	var numberQuestions='12';
	var newForm=document.createElement('div');
	//newForm.setAttribute('onSubmit','return gradeMyTest(this,\'10\')');
	//newForm.setAttribute('id','dlTest');

	var myElementObj=new createFormObject(newForm);


	var blackboardSkills="<form id=\"dlTest\" onSubmit=\"return gradeMyTest(this,'10','bbTest')\"><b>Blackboard Skills</b><br />"+
		"1 I have logged into the Blackboard Demo course successfully. <br />"+
		myElementObj.createYesNoButton('Q1')+"<br />"+
		"2 I have connected to a Blackboard course without getting a login error when using an Internet Service Provider (ISP like Earthlink or AOL). <br />"+
		myElementObj.createYesNoButton('Q2')+"<br />"+
		"3 I have found the Announcements in a Blackboard course. <br />"+
		myElementObj.createYesNoButton('Q3')+"<br />"+
		"4 I have found the Staff Information link and have successfully completed the Hands on Practice. <br />"+
		myElementObj.createYesNoButton('Q4')+"<br />"+
		"5 I have found the Course Information link and have successfully completed the Hands on Practice. <br />"+
		myElementObj.createYesNoButton('Q5')+"<br />"+
		"6 I have found the Course Documents link and have successfully completed the Hands on Practice. <br />"+
		myElementObj.createYesNoButton('Q6')+"<br />"+
		"7 I have found the Assignments link and have successfully"+
			" viewed the instructional video on how to upload an assignment to the Assignment Manager.<br />"+
		myElementObj.createYesNoButton('Q7')+"<br />"+
		"8 I have found the Discussion Board link and have successfully completed the Hands on Practice. <br />"+
		myElementObj.createYesNoButton('Q8')+"<br />"+
		"9. I have found the External Links link and have clicked on the sample link. <br />"+
		myElementObj.createYesNoButton('Q9')+"<br />"+
		"10. I have logged out of the Blackboard Demo course successfully.<br />"+
		myElementObj.createYesNoButton('Q10')+"<br />";


	md=document.getElementById('pageContent').appendChild(newForm);

	md.innerHTML=blackboardSkills+"<input type=\"submit\" name=\"submit\" value=\"Submit\"></form>";
		

}


function gradeMyTest(myForm,numberQuestions,testType){

	var missedQuestions=new Array();

	md=document.getElementsByTagName('input');

	var tempName="";
	var myChecked = false;
	var retry = false;

	for(testQuestion=0;testQuestion<md.length;testQuestion++){

		if(md[testQuestion].type=='radio'){
			if(md[testQuestion].name == tempName){
				
				if(myChecked == false){

					if(md[testQuestion].checked == false){
						alert("All questions must be answered");
						testQuestion=md.length;
						retry=true;

					} else {
						myChecked=md[testQuestion].checked;
						missedQuestions.push(md[testQuestion].name);
						
					}

				}
									
			} else {
				tempName=md[testQuestion].name;
				myChecked=md[testQuestion].checked;

			}

		}
		
	}

	if(retry == false){
		var mygrade=((numberQuestions-missedQuestions.length)/numberQuestions)*100;

		var myfinalgrade=mygrade.toPrecision(4);

		//alert(myfinalgrade);

		if(testType !="preTest"){

			storeGrade(missedQuestions,testType,myfinalgrade);

		} else {
			storePreTest(missedQuestions,myfinalgrade,myStudentId);
		}
	}

	return false;
}


function storeGrade(missedQuestions,testType,finalGrade){

	/// send the orientation grade to the
	var myQuestionString;

	for(numquestions=0;numquestions<missedQuestions.length;numquestions++){
		if(numquestions==0){
			myQuestionString=missedQuestions[numquestions];
		} else {
			myQuestionString=myQuestionString+","+missedQuestions[numquestions];
		}


	}

	//alert(myQuestionString);

 	
	var myData="firstName="+firstName+"&lastName="+lastName+"&email="+emailAddress+
		"&testType="+testType+"&finalGrade="+finalGrade+"&qnum="+myQuestionString+
		"&bday="+birthday;



	var myStoreObj=new getasyncdata("mailgrade.php","post",myData,'noreturn');

	myStoreObj.requestInfo();

	//alert(missedQuestions);

	/// Launch the system requirements

	showSystemRequirements(firstName,lastName,emailAddress);

	

}

function storePreTest(missedQuestions,myfinalgrade,myStudentId){


	/// send the orientation grade to the
	var myQuestionString;

	for(numquestions=0;numquestions<missedQuestions.length;numquestions++){
		if(numquestions==0){
			myQuestionString=missedQuestions[numquestions];
		} else {
			myQuestionString=myQuestionString+","+missedQuestions[numquestions];
		}


	}
	var myData="id="+myStudentId+"&finalGrade="+myfinalgrade+"&testType=preTest&qnum="+myQuestionString;

	var myStoreObj=new getasyncdata("storepretest.php","post",myData,'noreturn');

	myStoreObj.requestInfo();

	md=document.getElementById('pageContent');
	md.style.height='200px';
	

	md.innerHTML="<p>Thank you for your interest in Carteret Community College. "+
		"You have now completed the Distance Learning Orientation. Your score and information was sent to "+
		"the Student Enrollment Resources. You will receive an email in the next 24 hours that will let you know whether or not you have passed the orientation."+
		" If you have any questions please contact Student Enrollment Resources at 252-222-6154.";


	setTimeout("window.location='http://www.carteret.edu'","15000");

		



}
