var xpos;
var ypos;
var courseIndex;

function insertMyData(){

	// read the address line
	var myURL=document.URL.split(/\=/);

	
/// First get the list of courses
	/// Write the instructions to the page

	loadBanner("http://www.carteret.edu/images/newbannerTop-new.jpg")
	mpc=document.getElementById('pageContent');

	mpc.innerHTML="<h3 align=\"center\">Course Learning Outcomes and Syllabi<br />"+
		"Summer 2010</h3>"+
		"<p>Follow the instructions below to obtain Learning Outcomes, Syllabi, Course "+
		"Description, and Faculty Information</p>"+
		"<ul type=\"circle\"><li>Click <b>Course Number</b> to view Learning Objectives</li>"+
		"<li>Click <b>Section</b> to view syllabus</li>"+
		"<li>Move mouse over <b>Course Title</b> to view description</li>"+
		"<li>Click <b>Instructor</b> to view the instructor's office hours and location</li></ul>";

	newcontent=document.createElement('div');
	newcontent.setAttribute('id','newContent');
	

	mnc=document.getElementById('pageContent').appendChild(newcontent);

	mnc.innerHTML="Loading <img src=\"../pleasewait.gif\">";

	var mycoursedata=new getasyncdata("displaycllo.php?program="+myURL[1],'get','null','newContent');

	mycoursedata.requestInfo();

	var Backgroundcookie = ReadCookie("CCCBackground");
	if(Backgroundcookie.length == 0) { 
		loadBackground('Fabric');
	}else { 
		//alert("You successfully saved the "+Backgroundcookie+" background");


		loadBackground(Backgroundcookie); 
	}



}

function loadBackground(bgName){


	switch(bgName){

		case 'NavChart':
			var image="http://www.carteret.edu/NewFront/images/NavChart.gif";

		break;

		case 'Fabric':
			var image="http://www.carteret.edu/NewFront/images/vBorder.jpg";

		break;

		case 'Seal':
			var image="http://www.carteret.edu/NewFront/images/ccc_seal.gif";

		break;

		case 'PinkFlipFlops':

			var image="http://www.carteret.edu/NewFront/images/pinkflipflop.jpg";
		break;

		case 'NurseHat':

			var image="http://www.carteret.edu/NewFront/images/nurseHat.jpg";
		break;


		case 'Stethoscope':

			var image="http://www.carteret.edu/NewFront/images/stethoscope.jpg";
		break;


		case 'Welding':

			var image="http://www.carteret.edu/NewFront/images/welding.jpg";
		break;

		case 'CompassRose':

			var image="http://www.carteret.edu/NewFront/images/CompassRose.jpg";
		break;

		case 'ArtistPalette':

			var image="http://www.carteret.edu/NewFront/images/artistPalette.jpg";
		break;

		case 'Camera':

			var image="http://www.carteret.edu/NewFront/images/camera.jpg";
		break;

	}



	var myBackground=new testMyBackground("../../NewFront/php/loadBackground.php?img="+image,
					'get',null,'background');


	myBackground.requestInfo();

	return true;

}

function ReadCookie(n) {
	var cookiecontent = new String();
 	if(document.cookie.length > 0) {
		var cookiename = n+ '=';
		var cookiebegin = document.cookie.indexOf(cookiename);
		var cookieend = 0;
	if(cookiebegin > -1) {
		cookiebegin += cookiename.length;
		cookieend = document.cookie.indexOf(";",cookiebegin);
		if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
	}
	return unescape(cookiecontent);
} // function ReadCookie()


function closecllo(){
	if(document.getElementById('showcllo') != null){
		md=document.getElementById("newContent");

		md.removeChild(md.lastChild);

	}


}

function getmypip(firstName,lastName){

	window.open("displayemployee.php?fn="+firstName+"&ln="+lastName);

}

function getmycllo(courseIndex,event){

 	courseIndex=courseIndex;
	var IE = document.all?true:false;

	if(IE){
  		xpos=event.clientX -80;
		ypos=event.clientY+document.documentElement.scrollTop-150;

	} else {
   		xpos = event.pageX;
		ypos= event.pageY -150;
	}


	if(document.getElementById('showcllo')){
		md=document.getElementById("newContent");

		md.removeChild(md.lastChild);

	}

	newarea=document.createElement('div');
	newarea.setAttribute('id','showcllo');
	newarea.style.zIndex='6';

	newarea.style.position='absolute';
	newarea.style.top=ypos+"px";
	newarea.style.left=xpos+"px";
	newarea.style.background='#8dcff4';



	myd=document.getElementById("newContent").appendChild(newarea);

	

	var myGetCllO= new getasyncdata("getmycllo.php?idx="+courseIndex,
			'get',
			'null',
			'showcllo');

	myGetCllO.requestInfo();
}

/// display Course information
function getmycourseinfo(courseIndex,event){

	courseIndex=courseIndex;
    	var IE = document.all?true:false;

   	if(IE){
  		xpos=event.clientX -80;
		ypos=event.clientY+document.documentElement.scrollTop-150;

	} else {
   		xpos = event.pageX;
		ypos= event.pageY-150;
	}


 	if(document.getElementById('showcourse') != null){
		md=document.getElementById("newContent");

		md.removeChild(md.lastChild);

	}

	newarea=document.createElement('div');
	newarea.setAttribute('id','showcourse');
	newarea.style.zIndex='26';

	newarea.style.position='absolute';
	newarea.style.top=ypos+"px";
	newarea.style.left=xpos+"px";
	newarea.style.background='#8dcff4';



	myd=document.getElementById("newContent").appendChild(newarea);

	var myGetCllO= new getasyncdata("getmycourseinfo.php?idx="+courseIndex,
			'get',
			'null',
			'showcourse');

	myGetCllO.requestInfo();
}

function closecourseinfo(){
	if(document.getElementById('showcourse') != null){
		md=document.getElementById("newContent");

		md.removeChild(md.lastChild);

	}


}

function loadBanner(bannerImage){

		this.bannerImage=bannerImage;

		myBanner=document.createElement('img');
 		myBanner.setAttribute('src',this.bannerImage);
	
		myBannerHeading=document.createElement('h1');
		mySecondHeading=document.createElement('h2');


		//// IE is non-standard in their approach to creating spans and adding text
		//// Here we check for IE using document.all. If it is IE the build the banner
		//// based upon the IE approach
		if(document.all){
			myShadowText=document.createElement("<span class='banner'>");
			mySecondShadow=document.createElement("<span class='bannerShadow'>");
			myAddress=document.createElement("<span class='collegeAddress'>");


			myBannerHeading.innerText="Carteret";
			myShadowText.innerText="Carteret";
			mySecondHeading.innerText="Community College";
			mySecondShadow.innerText="Community College";
		} else {

			myShadowText=document.createElement('span');
			myShadowText.setAttribute('class','banner');
			mySecondShadow=document.createElement('span');
			mySecondShadow.setAttribute('class','bannerShadow');
			myAddress=document.createElement('span');
			myAddress.setAttribute('class','collegeAddress');

			myBannerHeading.textContent="Carteret";
			myShadowText.textContent="Carteret";
			mySecondHeading.textContent="Community College";
			mySecondShadow.textContent="Community College";


		}

		myAddress.innerHTML="3505 Arendell Street<br/>"+
			"Morehead City, NC 28557-2989<br />"+
			"Telephone 252-222-6000";

		document.getElementById("banner").appendChild(myBanner);		
		


}

function testMyBackground(myURL,reqType,myData,pgType){

	this.myURL=myURL;
	this.reqType=reqType;
	this.myData=myData;
	this.pgType=pgType;

	this.getHTTPObject=function(){ 
  		var xmlhttp; 

  		if(window.XMLHttpRequest){ 
   		 	xmlhttp = new XMLHttpRequest(); 
 		} 
 		else if (window.ActiveXObject){ 
    			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    			if (!xmlhttp){ 
        			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
    			} 
    
		} 


  		return xmlhttp; 

  
	} 

	var http=this.getHTTPObject();

	this.handleHttpResponse=function(){

       		 if (http.readyState == 4) { 
             		if(http.status==200) { 
                 		 var results=http.responseText;

				if(pgType=='loadAnn'){
					addScrollers(results);
				} else { 

					if(pgType !='background'){
						document.getElementById(pgType).innerHTML=results;
					}else{

						document.body.style.backgroundImage="url("+results+")";
					}

				}
				
             		} 
         	} 
	}
            
	this.requestInfo=function () {

		if(reqType=="get"){
		         
       	 		http.open("GET",this.myURL,true); 
        		http.onreadystatechange = this.handleHttpResponse; 

		} else {

			if(reqType =="get-false"){
				http.open("GET",this.myURL,false); 
        			http.onreadystatechange = this.handleHttpResponse; 

			} else {
			         
        			http.open("POST",this.myURL,true); 
				http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        			http.onreadystatechange = this.handleHttpResponse;
			} 
     	
		} 

		http.send(this.myData);
	} 
}
