<!--


//-----------------------------------------
// Javascript functions for list.htm
//
// created September 1st, 2001
//
// Copyright © 2001 <kendall@paradigm.nu>
//-----------------------------------------

// *******************************************************
// ******* Change these variables to suit your needs *****
// *******************************************************

var listTitle 	= 'My Lightbox' // The title of the List Window
var bgColor		= '#FFFFFF' // Background color (default is white)
var winName		= 'myList'	// Name of the popup window (for targeting)

// The browser attributes of the popup window
var winAttrib	= 'width=350,height=480,scrollbars=yes,resizable,menubar=yes'

// Various Error Messages
var errMsg1		= 'You must provide a name for the Item that you are adding!'
var errMsg2		= 'You must provide a description for the Item that you are adding!'
var errMsg3		= 'Are you sure you want to remove your lightbox?'

// **************************************************
// DON'T EDIT BELOW HERE UNLESS YOU KNOW JAVASCRIPT!


// MAIN PROGRAM ::::::::::>
// #############################################################################

// Process the Form
function addItem(item, desc){		
// grab the field values
	// if the item name is blank give an alert
	if(item == ""){
	alert(errMsg1)
	}
	else {
			// if the item description is blank give an alert
			if(desc == ""){
			alert(errMsg2)
			//document.userinput.description.focus()
			}
			// otherwise, if everything is filled in properly...
			else{	
				// check to see if the Item cookie exists 
				checkCookie(item, desc) 				
			}
	}		
}

// View the List
function viewList(){
	
	// if there is no cookie then give an alert	
	if (!document.cookie){ 
			alert('You don\'t have a lighbox!') 
	}
	else{
			// grab the cookie values and split it apart
			var the_cookie = document.cookie;
			var broken_cookie = the_cookie.split(";");
			// open a new window
			myList=window.open('',winName,winAttrib)
			// print a header
			header();
			// open a table
			myList.document.write('<font face="Verdana, Arial, Helvetica, sans-serif" size="3"><b>My Lightbox</b></font><br><br>')
			myList.document.write('<table align="center" border="0" cellpadding="0" width="100%" cellspacing="5" bgcolor="#CCCCCC">')
			// cycle through the cookies print
			// each one out in a table row
			var i=0;	
			while(i < broken_cookie.length){
				var the_name = broken_cookie[i];
				var the_name = unescape(the_name);
				var oneItem = the_name.split("=")
				// this prevents "undefined" error messages
				if (!oneItem[1]){
				myList.document.write('<b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Image ID</font></b>: '+oneItem[0]+'<br><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Description</b>:</font> </td></tr>')
				}
				else{
					if (oneItem[1]){
					myList.document.write('<tr><td><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Image ID</b>: '+oneItem[0]+'</font><br><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Description</b>: '+oneItem[1]+'</font></td></tr>')
					}
				}
				i++
			}
			// close up all the stuff we opened
			myList.document.write('</table>')
			myList.document.write('<form><center><input type="button" value="Close Window" onClick="self.close()"></center></form>')
			footer();
			myList.focus();
	}
}

// Delete the List
function deleteList(){
	// ask them if they are sure
	if(confirm(errMsg3)){
			// if so, cycle through the messages
			var the_cookie = document.cookie;
			var broken_cookie = the_cookie.split(";");
			var i=0;	
			while(i < broken_cookie.length){
				var the_name = broken_cookie[i];
				var the_name = unescape(the_name);
				var myName  = the_name.split("=")
				// and delete all the cookies
				delCookie (myName[0])							
				i++
			}
	// give feedback to the user		
	alert('Your lightbox has been deleted!')	
	}	
	else {
			void(null); // otherwise, don't do anything
	}
	
}

// SUBROUTINES ::::::::::>
// #############################################################################

 //Uncomment For Debugging
//function showCookie(){
// alert(document.cookie)
// }


// Check to see if we have a cookie
function checkCookie(item, desc){
	// if there is one with the same 
	// name, we should give them a choice
	if (getCookie(item)){
	//alert ('You already have an Item named: ' +item+ '.\nYou cannot have two items with the same name!\nIf you add a second Item with the same name, the first one will disappear!\nYou will now be given a chance to keep or replace your existing Item:')
	alert ('THIS IMAGE IS ALREADY IN YOUR LIGHBOX\n\nImage name -- '+desc)
		//if(confirm('Click OK to replace the the existing Item with your new one.\nClick CANCEL to keep your existing Item.')){
		// if they click OK then overwrite the cookie
		//createCookie(item,desc)
		//}
		//else{
		// otherwise, just go back to the form field
		//document.userinput.name.focus()
		//}
	}
	else {
	// if there is no cookie with the
	// same name then create a new cookie
	createCookie(item,desc)
	// give a confirmation
	alert('Your Image has been added to your lightbox!')
	// clear the fields
	resetForm(); 
	}
	
} 

// Set A Persistant Cookie
// this type of cookie gets written
// to the hard drive in a text file
function createCookie(item,desc){
	// get the current date
	var expdate = new Date (); 
	// set the expiration (default is one year - note the days)
	expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 365));
	// call the function
	setCookie (item, desc, expdate);
}

// Generic Cookie Functions:

// set the cookie
function setCookie (name, value, expires) {
    if (!expires) expires = new Date();
    document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() +  "; path=/"; 
}     

// call a cookie by name
function getCookie (name) {
    var dcookie = document.cookie; 
    var cname = name + "=";
    var clen = dcookie.length;
    var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
            if (dcookie.substring(cbegin, vbegin) == cname) { 
            var vend = dcookie.indexOf (";", vbegin);
                if (vend == -1) vend = clen;
            return unescape(dcookie.substring(vbegin, vend));
            }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
            if (cbegin == 0) break;
        }
    return null;
}

// delete cookie
function delCookie(name) {
	// one for Netscape
	if (navigator.appName=="Netscape") {
	var expireNow = new Date();
    document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
	}
	else{
	// one for Explorer
	var expire = new Date ();
	expire.setTime (expire.getTime() - (24 * 60 * 60 * 1000)); 
	document.cookie = name + "=; expires=" + expire.toGMTString(); 
	//alert(name+" deleted")
	}
}


function updateCookie(name, id, value){
	// get the current date
	var expdate = new Date (); 
	// set the expiration (default is one year - note the days)
	expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 365));
	// call the function
	setCookie (item, desc, expdate);
}

// Clear All the Form Fields
function resetForm(){
	//document.userinput.name.value=""
	//document.userinput.description.value=""
}

// Write HTML Header
function header(){
	myList.document.write('\n')
	myList.document.write('<head>\n')
	myList.document.write('<title>'+listTitle+'</title>\n')
	myList.document.write('</head>\n')
	myList.document.write('\n\n')
}

// Write HTML Footer
function footer(){
	myList.document.write('<br><br>\n')
	myList.document.write('\n')
	myList.document.write('\n\n')
	myList.document.close();
}



function showHideSection(section)
{	
	if(document.getElementById(section).style.display == 'none')
	{
		//opacity(section, 0, 100, 500);
		document.getElementById(section).style.display = 'block';
		
		//document.getElementById('img' + section).src = 'elements/minus.gif';
		saveStyles();
	}
	else
	{
		//document.getElementById(section).style.display = 'none';
		//document.getElementById('img' + section).src = 'elements/plus.gif';
		saveStyles();
	}
}

function collapseSections(section)
{
		var i, n_elems, strVAR, strVAR2, strVAR3, strCheck, elems = document.getElementsByTagName("div");
		n_elems = elems.length; 
		strVAR3 = '';
		for (i = 0; i < n_elems; i++) 
		{
			strVAR = elems[i].style.display;
			strVAR2 = elems[i].id;					
					
			strCheck = strVAR2.indexOf('SubNav');
			
			if(!strCheck){
				//alert(strVAR2);
				//strVAR3 = strVAR3 + (strVAR2+','+strVAR+'-')
				if(section!=strVAR2){
					
				document.getElementById(strVAR2).style.display = 'none';
				
				}
				//alert(strVAR2);			
			}
			
		}	
		//createCookie('SubNav', strVAR3);	
		saveStyles();
}

function saveStyles()
{
		var i, n_elems, strVAR, strVAR2, strVAR3, strCheck, elems = document.getElementsByTagName("div");
		n_elems = elems.length; 
		strVAR3 = '';
		for (i = 0; i < n_elems; i++) 
		{
			strVAR = elems[i].style.display;
			strVAR2 = elems[i].id;					
					
			strCheck = strVAR2.indexOf('SubNav');
			if(!strCheck){
				//alert(strVAR2);
				strVAR3 = strVAR3 + (strVAR2+','+strVAR+'-')
							
			}
		}	
		createCookie('SubNav', strVAR3);	
}





function loadStyles()
{
		if(getCookie('SubNav')){
			var the_cookie = getCookie('SubNav');
			//var the_cookie = the_cookie_raw.replace(/\s/g,'')
			//alert(the_cookie);
			var ss = the_cookie.split("-");
			var i=0;
			//alert(ss.length);
			//return;
			for (i=0; i<(ss.length-1); i+=1) {
				var args = ss[i].split(",");
				strName = args[0];		
				strValue = args[1];			
				var strName2 = args[0].replace(/\s/g,'')
				//alert(i+' - '+strName2);
				if(strValue=='none'){
					document.getElementById(strName2).style.display = 'none';
					//document.getElementById('img' + strName2).src = 'elements/plus.gif';
				}else{
					
					//opacity(strName2, 0, 100, 500);
					document.getElementById(strName2).style.display = 'block';
					//document.getElementById('img' + strName2).src = 'elements/minus.gif';
					}
			}	
		}	
}
// end sample.js
//-->