
function chooseBackground(){

	/// 


	mbs=document.getElementById('myBackground');
	setMyBackground=document.createElement('div');
	setMyBackground.setAttribute('id','bgWindowSet');
	setMyBackground.style.position='absolute';
	setMyBackground.style.zIndex='5';
	setMyBackground.style.top='150px';
	setMyBackground.style.left='350px';
	setMyBackground.style.border='outset';
	setMyBackground.style.borderWidth='3px';
	setMyBackground.style.backgroundColor='oldLace';
	setMyBackground.style.padding='20px';

	setMyBackground.innerHTML="<input type=\"button\" name=\"setBackground\" value=\"Set\" "+
		" onClick=\"javascript:saveBackground();\" />"+
		"<input type=\"button\" name=\"closeWindow\" value=\"Close\" "+
		" onClick=\"javascript: closeBGSet()\" />"+
		"<p>One can choose a personal background for this site by selecting"+
		" from the list below. The backgrounds can be previewed by selecting the radio button"+
		" left of each background. Once you choose the background click the \"Set\""+
		" button.</p><p>One must have cookies enabled on your browser to allow"+
		" selection storage.Click the following link to test your browser setting"+
		"<a href=\"#\" onclick=\"javascript:testSetting()\"> Test Browser Settings </a>"+
		"If cookies are not enabled click the following link to learn how to enable"+
		" cookies on your browser: "+ 
		"<a href=\"http://www.google.com/support/websearch/bin/answer.py?answer=35851\""+
		" target=\"_blank\">How to enable cookies</a>";


	mbs.appendChild(setMyBackground);

	// Create an instance of the form elements object

	var myBgWindow=document.getElementById('bgWindowSet');

	bgForm=new createFormObject(myBgWindow);
	
	/// Create the radio buttons
	bgForm.createRadioButtonAction('bgChoice','ArtistPalette',"loadBackground('ArtistPalette')");
	bgForm.createRadioButtonAction('bgChoice','Camera',"loadBackground('Camera')");
	bgForm.createRadioButtonAction('bgChoice','CompassRose',"loadBackground('CompassRose')");
	bgForm.createRadioButtonAction('bgChoice','Fabric',"loadBackground('Fabric')");
	bgForm.createRadioButtonAction('bgChoice','NavChart',"loadBackground('NavChart')");
	bgForm.createRadioButtonAction('bgChoice','PinkFlipFlops', "loadBackground('PinkFlipFlops')");
	bgForm.createRadioButtonAction('bgChoice','NurseHat',"loadBackground('NurseHat')");
	bgForm.createRadioButtonAction('bgChoice','Seal',"loadBackground('Seal')");
	bgForm.createRadioButtonAction('bgChoice','Stethoscope',"loadBackground('Stethoscope')");
	bgForm.createRadioButtonAction('bgChoice','Welding',"loadBackground('Welding')");
	
	
/*
	SetCookie("CCCBackground", "fabric", 3000);


	var Backgroundcookie = ReadCookie("CCCBackground");
	if(Backgroundcookie.length == 0) { 
		alert("Failed to set cookie. It appears that cookies are not enabled on your browser."); 
	}else { 
		alert("You successfully saved the "+Backgroundcookie+" background"); 
	}

*/

}

///
function saveBackground(){

	var bgName="";

	var myckbx=document.getElementById('bgWindowSet');


	for(ckbx=0;ckbx<myckbx.childNodes.length;ckbx++){
		
		if(myckbx.childNodes[ckbx].nodeName == 'SPAN'){

			for(spannode=0;spannode<myckbx.childNodes[ckbx].childNodes.length;spannode++){


				if(myckbx.childNodes[ckbx].childNodes[spannode].nodeName == 'INPUT'){

					if(myckbx.childNodes[ckbx].childNodes[spannode].checked){

						bgName=myckbx.childNodes[ckbx].childNodes[spannode].value;

					}
				}

			}
			

		}

	}

	
	if(bgName != ""){
		SetCookie("CCCBackground", bgName , 3000);

		var Backgroundcookie = ReadCookie("CCCBackground");
		if(Backgroundcookie.length == 0) { 
			alert("Failed to set cookie. It appears that cookies are not enabled on your browser."); 
		}else { 
			alert("You successfully saved the "+Backgroundcookie+" background"); 
		}

	}

}

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;

}


/// Close the background select dialog
function closeBGSet(){
	mbs=document.getElementById('myBackground');

	mbs.removeChild(mbs.firstChild);


}




function testSetting(){

	SetCookie("testSet", "test", 1);


	var Backgroundcookie = ReadCookie("testSet");
	if(Backgroundcookie.length == 0) { 
		alert("Failed to set cookie. Verify that cookies are enabled for your browser"); 
	}else { 
		alert("Congradulations! Cookies are enable."); 
	}

}


function SetCookie() {
if(arguments.length < 2) { return; }
	var n = arguments[0];
	var v = arguments[1];
	var d = 0;
if(arguments.length > 2) {
	d = parseInt(arguments[2]); 
}

var exp = '';

if(d > 0) {
	var now = new Date();
	then = now.getTime() + (d * 24 * 60 * 60 * 1000);
	now.setTime(then);
	exp = '; expires=' + now.toGMTString();
	}
document.cookie = n + "=" + escape(String(v)) + '; path=/' + exp;
} // function SetCookie()

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 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);
	} 
}

