﻿<!--

var checkdivptr;	// at load time this gets set to the div where the checked panels appear
var curcheck = "";	//used to store a list of all the checked panels by id, separated by a triple colon

//generic function takes a node and a classname and returns all immediate children in that class
function getArraybyClass(nnode, cclass) {
	var retarr = new Array();
	if (!nnode.firstChild) {return retarr};
	for (var i = 0; i<nnode.childNodes.length; i++) {
		if (nnode.childNodes[i].className) {
			if (nnode.childNodes[i].className==cclass) {
				retarr[retarr.length]=nnode.childNodes[i];
			};
		};
	};
	return retarr;
};

// call this function when the user checks (or unchecks) a whole panel
function do_pancheck(evt,obj) {
	if (BrowserDetect.browser != "Explorer") {evt.stopPropagation()};
	if (obj.checked) {checkpanel(obj.parentNode.parentNode.id)}
	else {uncheckpanel(obj.parentNode.parentNode.id)};
	document.getElementById("container").focus();
};

//MAKE SURE TO INCLUDE CODE THAT KEEPS TRACK OF CHECKED AND UNCHECKED SO THEY CAN BE RESTORED WHEN THE USER SWITCHES SORTS; ALSO THEY CAN BE STORED AS A COOKIE

function insertinorder (toinsert, idx) {
// this code creates an array of sessions titles to help place the panels in order
	var checksesstit = new Array(12);
	for (var i=1; i < 13; i++) {	
		checksesstit[i-1] = document.getElementById("aa"+( (i<10) ? "0"+i : i+"" ) );
	};
	sessnum = idx.substring(3,5) - 0;
	nextdiv = checksesstit[sessnum-1].nextSibling;
	notdone = true;
	while (notdone) {
		if (!nextdiv) {
			checkdivptr.appendChild(toinsert);
			toinsert.getElementsByTagName("input")[0].checked=true;	// just for IE
			break;
		} else if ( nextdiv.className != "paneldiv" || ( (nextdiv.id) && nextdiv.id.indexOf("ck") != -1 && nextdiv.id > "ck"+idx ) ) {
			checkdivptr.insertBefore(toinsert, nextdiv)
			toinsert.getElementsByTagName("input")[0].checked=true;	// just for IE
			break;
		}  else {
			nextdiv = nextdiv.nextSibling;
		};
	};


/*	var temarray = new Array();
	temarray = getArraybyClass(checkdivptr, "paneldiv");
	if (temarray.length==0) {
//alert("temarray length = 0");
		checkdivptr.appendChild(toinsert);
		toinsert.getElementsByTagName("input")[0].checked=true;
	}
	else {
		for (var i=0; i<temarray.length; i++) {
			if (temarray[i].id) {
//alert("? ck"+idx+" < "+temarray[i].id);
				if (("ck"+idx) < temarray[i].id) {
					checkdivptr.insertBefore(toinsert,temarray[i]);
					toinsert.getElementsByTagName("input")[0].checked=true;
					break;
				};
				if (i==temarray.length-1) { //if it goes last
					checkdivptr.appendChild(toinsert); 
					toinsert.getElementsByTagName("input")[0].checked=true;	// just for IE
					break;
				};
			};
		};
	}; */
};

function checkpanel(idx) {
	//first check to see whether the div idx already exists in the checkeddiv
	if (document.getElementById("ck"+idx)) {return};
	//next clone the panel that was checked
	var newpanel = document.getElementById(idx).cloneNode(true);
	//alter all of the ids so that they remain unique
	alterids(newpanel,"ck");
	//fix the ordering issue (probably by alphabetical idx)
	insertinorder(newpanel,idx);
	if (window.addEventListener) {
		getUniquebyClass(newpanel,"paneltit").addEventListener("click", panelclick, true);
	};
	if (curcheck.indexOf(":::"+idx)==-1) {curcheck += ":::"+idx};
};

function uncheckpanel(idx) {
	// if uncheck was done within the checkeddiv, then first uncheck the bigdiv box
	if (idx.indexOf("ck")==0) {	//eventually, this may need to check whether we are in "time" or "alpha" sort and act accordingly
		idx = idx.substring(2);
		var orig = document.getElementById(idx);
		if (orig) {	// if there is an orig, then we are in "time" view otherwise we are in alpha view
			orig.getElementsByTagName("input")[0].checked=false;
		}
		else {
			checkpanelparts(idx,false);
		};
	};
	var checkone =  document.getElementById("ck"+idx);
	if (checkone) {
		checkone.parentNode.removeChild(checkone);
		strix = curcheck.indexOf(idx);
		curcheck = curcheck.substring(0,strix-3) + curcheck.substring(strix+idx.length);
	};
};

// this recursive function goes through the whole tree of children for a node nptr and alters the id of each by adding adder to it
//it also has a kluge to turn on any check boxes that are off
function alterids(nptr,adder) {
	if (nptr.tagName) {
		if (nptr.tagName.toLowerCase()=="input" && nptr.type=="checkbox") {
			nptr.checked=true;
		};
		if (nptr.id.length>0) {nptr.setAttribute("id",adder+nptr.id)};
		//some custom code to alter the event dispatcher for the hide/reveal code
		if (nptr.className=="speakerdiv" || nptr.className=="chairdiv") {
			tstr = nptr.innerHTML;
			strix = tstr.indexOf(", 'idt");
			if (strix!=-1) {
				nptr.innerHTML = tstr.substring(0,strix+3)+"ck"+tstr.substring(strix+3,tstr.length);
			}
		};		
	};
	var inc = 0;
	while (nptr.childNodes[inc]) {
		alterids(nptr.childNodes[inc],adder);
		inc++;
	};
};

//call this function when the user checks or unchecks an individual speaker
// Note: the checkboxes for individual speakers are added in the sorting init code but aren't part of the original html
function do_speakcheck(evt,obj) {
	if (BrowserDetect.browser != "Explorer") {evt.stopPropagation()};
	if (obj.checked) {checkspeak(obj.parentNode.parentNode.id)}
	else {uncheckspeak(obj.parentNode.parentNode.id)};
	document.getElementById("container").focus();
};

function getPanelById(searchdiv, idy) {
	var arrdiv = getArraybyClass(searchdiv,"paneldiv");
	for (var i=0; i<arrdiv.length; i++) {
		if (arrdiv[i].id == idy) {return arrdiv[i]};
	};
};

function docheckmarks(tododivs,checker) {
	for (var i=0; i<tododivs.length; i++) {
		onespeak = document.getElementById(tododivs[i].id.substring(2));
		if (onespeak) {onespeak.getElementsByTagName("input")[0].checked=checker};
		onespeak = document.getElementById("xx"+tododivs[i].id.substring(4));
		if (onespeak) {onespeak.getElementsByTagName("input")[0].checked=checker};
	};
};


//this function turns on/off (checker = true/false) the checkboxes of individual panelists on a whole panel
function checkpanelparts(idx,checker) {
	//remember to look for team panelists
	var expanel = document.getElementById("ck"+idx);
	if (expanel) {
		var speakarr = getArraybyClass(expanel, "speakerdiv");
		docheckmarks(speakarr,checker);
		speakarr = getArraybyClass(expanel,"chairdiv");
		docheckmarks(speakarr,checker);
	};
};
	

//when the user checks an individual speaker or chair, the whole panel gets moved to the checked div and the other speakers in that panel also get a check mark
function checkspeak(idx) {
	var panelid = idx.substring(0,idx.length-1);
	if (panelid.indexOf("xx") == 0) {panelid = "id"+panelid.substring(2);};
	var panelptr = document.getElementById("ck"+panelid);	//check to see if panel already up top
	if (!panelptr) {	//if document is already up top, do nothing
		var newpanel = getPanelById(clonetimediv,panelid).cloneNode(true);
		//alter all of the ids so that they remain unique
		alterids(newpanel,"ck");
		//fix the ordering issue (probably by alphabetical idx)
		insertinorder(newpanel,panelid);
		if (window.addEventListener) {
			getUniquebyClass(newpanel,"paneltit").addEventListener("click", panelclick, true);
		};
		if (curcheck.indexOf(":::"+idx.substring(0,idx.length-1))==-1) {curcheck += ":::"+idx.substring(0,idx.length-1)};
		//now go through this panel and get each paper id and make sure it is checked
		checkpanelparts(panelid,true);
	};		
};

//when the user unchecks an individual speaker or chair, nothing happens
function uncheckspeak(idx) {
	return;
};

function revivechecked(curtype) {	//puts check marks in the bigdiv as appropriate; curtype is the current sort type
	var strarr = curcheck.split(":::");
	if (!strarr) {return};
	for (var i=0; i<strarr.length; i++) {
		if (!strarr[i]) {continue;};
		if (curtype == "alpha") {
			checkpanelparts(strarr[i],true);
		} else if (curtype == "time") {
			var orig = document.getElementById(strarr[i]);
			if (orig) {if (orig.getElementsByTagName("input")[0]) {orig.getElementsByTagName("input")[0].checked=true;}};
		};
	};
};

function assertchecked() {
	var charr = curcheck.split(":::");
	for (var i=0; i<charr.length; i++) {
	if (!charr[i]) {continue;};
		checkpanel(charr[i]);
	};
	revivechecked("time");	
};
	

//-->