var current_category, categoryHistory = [],
breadcrumbHistory = [],
programIndex = [],
categoryIndex = [],
seriesSaleIndex = [],
$pdfs,
progCatIndex = []; //, pageHistory = new PageHistory();
//utility to isolate 4 digit cat id giving a url
function getCatidFromUrl(url) {
	if( url.indexOf('catid=') == -1 && url.indexOf('tile_') == -1 && url.indexOf('load_') == -1 ){
		url = url.substring( 0 , ( url.indexOf( '?' ) != -1 ) ? url.indexOf( '?' ) : url.length );
		var menu_links = document.getElementById( "Menu_div" ).getElementsByTagName( "A" );
		for( var i = 0; i < menu_links.length; i++ ){
			if( menu_links[ i ].href == url ){ 
				var menu_id = menu_links[ i ].parentNode.id;
				return menu_id.substring( menu_id.length - 4 , menu_id.length );
			}
		}
	//return null;
	} else if ( url.indexOf('catid=') == -1 && ( url.indexOf('tile_') != -1 || url.indexOf('load_') != -1 ) ) {
		if( url.indexOf('_001') != -1 && mainID != null ){ return mainID; }
		var ufurl;
        if (url.indexOf('tile_') != -1) {
            ufurl = url.substring(url.indexOf('tile_') + 5, url.length);
        } else if (url.indexOf('load_') != -1) {
            ufurl = url.substring(url.indexOf('load_') + 5, url.length);
        }
		var menu_links = document.getElementById( "Menu_div" ).getElementsByTagName( "A" );
		for( var i = 0; i < menu_links.length; i++ ){
			if( menu_links[ i ].href.indexOf( ufurl ) != -1 && menu_links[ i ].href.substring( menu_links[ i ].href.indexOf( ufurl ) - 17 , menu_links[ i ].href.indexOf( ufurl ) ) == "jccmanhattan.org/" && menu_links[ i ].href.indexOf( ufurl ) + ufurl.length == menu_links[ i ].href.length ){//if the menu link has the string, with no more on the right and no more on the left
				var menu_id = menu_links[ i ].parentNode.id;
				return menu_id.substring( menu_id.length - 4 , menu_id.length );
			}
		}
    } else if (url.indexOf('_001') == -1) {
        if ( url.indexOf('tile_') != -1 && url.indexOf('tile_') > url.indexOf('catid') ) {
            return url.substring(url.indexOf('tile_') + 5, url.length);
        } else if ( url.indexOf('load_') != -1 && url.indexOf('load_') > url.indexOf('catid') ) {
            return url.substring(url.indexOf('load_') + 5, url.length);
        }
        return url.substring(url.indexOf('catid=') + 6, url.indexOf('catid=') + 10);
    } else {
        return mainID;
    }
}
//no longer in use, created to open a new layer simulating a window with a program inside it, pulled in by ajax
var w_open = function (c, p) {
    selectProgram();
    loadXML('cat-content.aspx?catID=' + c + "&progID=" + p, openProgram);
    var div = document.getElementById("program_window");
    div.style.textAlign = "center";
    div.innerHTML = "<img src='images/JCC_preloader4.gif' width='150' height='228'/>";
    document.getElementById("program_container").style.visibility = document.getElementById("prog_close").style.visibility = "visible";
    document.getElementById("print_program").href = "cat-content.aspx?catID=" + c + "&progID=" + p;

    var divs = getAllClass("div", "item_picked");
    for (var i = 0; i < divs.length; i++) { 
        divs[i].className = "item_div";
    }
    doFadeOut("content_placer", "program_catList_placer", "left_border", "right_border", "lt_border", "rt_border", "bottom_border", "BreadCrumb_placer", "callist_placer", "scrollArea", "scrollUp", "scrollDown", "callist_headers", "calendar_placer");
};
//right nav function for finding the correct location
function scrollToTile(ID) {
    if (ID == "001" || ID == mainID) {
        jQuery.jGlideMenu.scrollToTile(1, jQuery.jGlideMenu.defaultScrollBackSpeed);
        return;
    } else if ( ID > -1 && ID < 10000 ){//if it's a digit
		ID = getShortHREF( findMenuItem( ID ) );
	}
    for (var i = 0; i < jQuery.jGlideMenu.tileCount; i++) {
        if (jQuery.jGlideMenu.tileIndex[i] == "tile_" + ID ) {
            jQuery.jGlideMenu.scrollToTile(i + 1, jQuery.jGlideMenu.defaultScrollBackSpeed);
            return;
        }
    }
    jQuery.jGlideMenu.loadTile("tile_" + ID, jQuery.jGlideMenu.URLParams);
    //jQuery.jGlideMenu.scrollToTile(jQuery.jGlideMenu.tileCount,jQuery.jGlideMenu.defaultScrollBackSpeed);
}
//pull content for a given catID from programData.xml
function getContent(ID) {
    if (ID == "001") {
        ID = mainID;
    }
    highlight_cat = ID;
    current_category = ID;
    //loadXML('content.aspx?catID=' + ID, newCategory);
	$.ajax({
		   url:'content.aspx?catID=' + ID,
		   success:function(data){
			   	$("#content_container").html(data);
			   if( $("#content_div").length == 0){
				   location.replace( "programs.aspx?catid=" + ID );				   
			   }
				getBreadCrumbs();
		   }
	});
	
	try{
		survey.init(3);
	} catch (e ){}
	
	/*window.clearInterval( carint ); 
	
	$(".rtnav_MO").css("display","none");
    
	var $div = $("#content_container");
    var $text = $(getCategory( ID )).children( "D" ).first().text();
	if( $text == "" ){
		location.replace( "programs.aspx?catid=" + ID );
	}
	else{ 
		$div.html($text);
		//getBreadCrumbs();
	}*/
 //   document.getElementById("programs_btn").href = "programs.aspx?catid=" + ID;
}
//make an ajax call to get the breadcrumbs for the current category
function getBreadCrumbs() {
    var url = 'breadcrumbs.aspx?catID=' + current_category;
    loadXML(url, newBreadCrumbs);
}
function makeCategoryNotFound(){
	document.getElementById( "content_container" ).innerHTML = "<div id='content_div'><div id='content_cutter' align='center'>Sorry, this page could not be found.<br /><a href='/'>return to homepage</a></div></div>";
}
//clear search results layer
function searchClose() {
	var s = document.getElementById("search_results_header");
	if( s.className == 'openedSearch' ){
		if( navigator.userAgent.indexOf( "Safari" ) != -1 ){
			$("#content_div iframe").css( "display","block");
			$("#content_div object").css( "display","block");
		}
		document.getElementById("search_results_header").className = 'closedSearch';
		document.getElementById("show_search").style.visibility = 'visible';
		doFadeIn();
	}
}
//overlay search results layer
function showSearch() {
	if( navigator.userAgent.indexOf( "Safari" ) != -1 ){
		$("#content_div iframe").css( "display","none");
		$("#content_div object").css( "display","none");
	}
    document.getElementById("search_results_header").className = 'openedSearch';
    document.getElementById("show_search").style.visibility = 'hidden';
    doFadeOut();
}
//no longer in use, clear program layer
function programClose() {
    document.getElementById('prog_close').style.visibility = 'hidden';
    document.getElementById('program_container').style.visibility = 'hidden';
    if (document.getElementById('search_results').style.visibility != 'visible') {
        doFadeIn("content_placer", "program_catList_placer", "left_border", "right_border", "lt_border", "rt_border", "bottom_border", "BreadCrumb_placer", "callist_placer", "scrollArea", "scrollUp", "scrollDown", "callist_headers", "calendar_placer");
    }
}
//next two no longer in use
function loginClose() {
    document.getElementById('login_frame_container').style.visibility = 'hidden';
}
function openProgram() {
    if (xmlHttp.readyState == 4) {
        var div = document.getElementById("content_cutter");
        div.innerHTML = xmlHttp.responseText;
		if( document.getElementById( "search_frame" ) == null ){
			buildProgSiteSearch();
		}
    }
}
var temp_div;
var myDate = getDateFromURL();
var calmonth = myDate.getMonth();
var calyear = myDate.getFullYear();
var dragging;
var isScrolling = false;
//OBJECT RESPONSIBLE FOR TIME, AGE AND RECURRENCE NARROWING 
function SpanSelector(name, container, th, bh, over, middle, under, tvalue, bvalue, values, top, target) {
    this.name = name;
    this.values = values;
    this.valid = [0, this.values.length - 1];
    this.height = middle.offsetHeight;
    this.top = top;
    this.target = target;
    //STORED HEIGHT UNIT OF 1 CELL
    this.hunit = this.height / max(values.length, 1);
    //INITIAL INTERACTION VALUES
    this.top_drag = false;
    this.bottom_drag = false;
    //DIVS WITH VALUES IN THEM
    this.top_div = over;
    this.middle_div = middle;
    this.bottom_div = under;
    //HANDLE DIVS
    this.bottom_handle = bh;
    this.top_handle = th;
    //TEXT BOX DIVS THAT INDICATE SELECTED VALUES
    this.top_value = tvalue;
    this.bottom_value = bvalue;
    //DIV THAT HAS EVERYTHING
    this.container_div = container;
    this.container_div.name = this.container_div.id = container.id;
    //SO ACTION LISTENERS FOR DIVS CAN ACCESS PROPERTIES OF THIS OBJECT
    this.bottom_handle.parrent = this;
    this.container_div.parrent = this;
    this.top_handle.parrent = this;
    this.top_div.parrent = this;
    this.middle_div.parrent = this;
    this.bottom_div.parrent = this;
    this.top_value.parrent = this;
    this.bottom_value.parrent = this;
    //FUNCTION DEFINITIONS
    this.y_naut = y_naut;
    this.getValid = getValid;
    this.dragger = dragger;
    //this.start_top_drag = start_top_drag;
    //this.start_bottom_drag = start_bottom_drag;
    this.end_drag = end_drag;
    this.offset = 0;
}

//SpanSelector CLASS FUNCTION DEFINITIONS
function end_drag(evt, P) {
    //dragging was the parameter passed to this function as P
    dragging = null;
    //find the mouse location relative to the unit
	if( P == null ){ return; }
    var mouse_loc = evt.clientY - P.y_naut() - P.offset,
    y0 = P.top_div.offsetTop,
    hH = P.top_handle.offsetHeight;
    //fix if window is scrolled down
    if (document.body.scrollTop != null && P.offset == 0) {
        mouse_loc += document.body.scrollTop;
    }
    //if we're ending the top drag or it's a click that should move the top handle
    if (P.top_drag || (!P.bottom_drag && mouse_loc + hH <= (P.top_handle.offsetTop - -P.bottom_handle.offsetTop - -hH) / 2)) {
        //p is the nearest value's location to the mouse location
        var p = within(Math.round(P.values.length * (mouse_loc - (y0 - hH)) / P.height) * P.hunit, 0, P.height + y0);
        //shorten/lengthen the top div  
        P.top_div.style.height = within(p, 1, P.valid[1] * P.hunit) + 'px';
        // +21 because zero is really 36, but subtract the height of top_handle because the apparent location is its bottom
        P.top_handle.style.top = within(p + y0 - hH, y0 - hH, P.valid[1] * P.hunit + y0 - hH) + 'px';
        //set the lowest valid value the slider returns to be in accordance with the slider location
        P.valid[0] = within(Math.round(P.values.length * (toNum(P.top_div.style.height)) / P.height), 0, P.valid[1]);
        P.top_value.innerHTML = P.values[P.valid[0]];
    }
    //if we're ending the bottom drag or it's a click that should move the bottom handle
    else if (P.bottom_drag || (!P.top_drag)) {
        if (!P.bottom_drag) {
            //p is the nearest value's location to the mouse location
            var p = within(Math.round(P.values.length * (mouse_loc - (y0 - 12)) / P.height) * P.hunit + y0, 0, P.height + y0);
        } else {
            var p = within(Math.round(P.values.length * (mouse_loc - y0) / P.height) * P.hunit + y0, 0, P.height + y0);
        }
        //appears as though the bottom section is changing to cover the middle, though the middle is changing to not cover the bottom
        P.middle_div.style.height = within(p - y0, (P.valid[0] + 1) * P.hunit, P.height + 1) + 'px';
        P.bottom_handle.style.top = within(p, (P.valid[0] + 1) * P.hunit + (y0 - 1), P.height + y0 + 1) + 'px';
        //set the highest valid value the slider returns to be in accordance with the slider location
        P.valid[1] = within(Math.round(P.values.length * (toNum(P.middle_div.style.height)) / P.height) - 1, P.valid[0], P.values.length - 1);
        P.bottom_value.innerHTML = P.values[P.valid[1]];
    }
    //denote that dragging is no longer taking place in this selector
    P.bottom_drag = P.top_drag = false;
    if (P.name == 'recurrence') {
        P.target.recurrence_filter = P.getValid();
    }
    else if (P.name == 'time') {
        programFilter.stime_filter = time2date(P.top_value.innerHTML);
        programFilter.etime_filter = time2date(P.bottom_value.innerHTML);
    }
    else if (P.name == 'age') {
        programFilter.sage_filter = P.top_value.innerHTML;
        programFilter.eage_filter = P.bottom_value.innerHTML;
    }
    //erases the mouse position relative to the top of a handle  recorded at the beginning of a drag
    P.offset = 0;
	programFilter.getFilteredList();
    document.onmousemove = function (evt) {}
    document.onmouseup = function (evt) {}
}
//this is the ondrag event
function dragger(evt, P) {
    var y0 = P.top_div.offsetTop;
    if (P.top_drag) {
        var hH = 10; //P.top_handle.offsetHeight;
        var mouse_loc = evt.clientY - P.y_naut() - P.offset;
        P.valid[0] = within(Math.round(P.values.length * (mouse_loc - (y0 - hH)) / P.height), 0, P.valid[1]);
        P.top_div.style.height = within(mouse_loc - (y0 - hH), 1, P.valid[1] * P.hunit) + 'px';
        P.top_handle.style.top = within(mouse_loc, (y0 - hH), P.valid[1] * P.hunit + (y0 - hH)) + 'px';
        P.top_value.innerHTML = P.values[P.valid[0]];
        return;
    }
    else if (P.bottom_drag) {
        var mouse_loc = evt.clientY - P.y_naut() - P.offset;
        P.valid[1] = within(Math.round(P.values.length * (mouse_loc - y0) / P.height), P.valid[0] + 1, P.values.length);
        P.middle_div.style.height = within(mouse_loc - y0, (P.valid[0] + 1) * P.hunit, P.height + 1) + 'px';
        P.bottom_handle.style.top = within(mouse_loc, (P.valid[0] + 1) * P.hunit + (y0 - 1), P.height + y0 + 1) + 'px';
        P.bottom_value.innerHTML = P.values[P.valid[1] - 1];
        return;
    }
}
//ondragstart for top handle
function start_top_drag(evt, P) {
    dragging = P;
    evt = (evt) ? evt : ((window.event) ? evt : null);
    P.bottom_drag = !(P.top_drag = true);
    P.offset = evt.clientY - P.y_naut() - P.top_handle.offsetTop;
    document.onmousemove = function (evt) {
        evt = fixE(evt);
        dragger(evt, dragging);
    }
    document.onmouseup = function (evt) {
        evt = fixE(evt);
        end_drag(evt, dragging);
    }
}
//ondragstart for bottom handle
function start_bottom_drag(evt, P) {
    dragging = P;
    evt = (evt) ? evt : ((window.event) ? evt : null);
    P.top_drag = !(P.bottom_drag = true);
    P.offset = evt.clientY - P.y_naut() - P.bottom_handle.offsetTop;
    document.onmousemove = function (evt) {
        evt = fixE(evt);
        dragger(evt, dragging);
    }
    document.onmouseup = function (evt) {
        evt = fixE(evt);
        end_drag(evt, dragging);
    }
}
//returns where on the screen the top of this slider is in pixels
//this will only be correct if the correct value was passed to the constructor
function y_naut() {
    return this.top;
}
function getValid() {
    var temp = [];
    for (var i = this.valid[0]; i <= this.valid[1]; i++) {
        temp.push(this.values[i]);
    }
    return temp;
}
//*********SEARCH OBJECT*********//
function SearchBox(target) {
    this.field = document.getElementById("cal_search_txt");
	this.field.target = target;
    this.field.parrent = this;
    this.field.onfocus = function () {
        this.value = "";
        this.onfocus = null;
    };
    this.target = target;
    this.field.onkeyup = this.field.onkeypress = this.field.onchange = function () {
        this.target.name_filter = this.value;
        this.target.getFilteredList();
    };
	if( autoSearch != "" ){ 
		while( autoSearch.indexOf( "_" ) != -1 ){
			autoSearch = autoSearch.replace( "_" , " " );
		}
		this.field.value = autoSearch; 
		this.field.onkeyup(); 
		this.field.onfocus = null; 
	}
	else{ 
	}
}
//*********ITEM OBJECT***********//

//*********ITEMLIST OBJECT***********//
var programFilter = new function(){
	this.name_filter = "";
    this.date_filter = [];
    this.stime_filter = null;
    this.etime_filter = null;
    this.age_filter = null;
    this.day_filter = [];
    this.category_filter = "";
    this.season_filter = "";
    this.recurrence_filter = [];
	this.filter = function( $trow ){
		if( !$trow.filter_obj ){
			$trow = $( $trow );
			var name = $trow.find(".item_name > a").text() + $trow.find(".desc").text() + $trow.find(".item_date").text() + $trow.find(".item_rec").text(), 
			start = getDatefrom($trow.find(".item_date").attr("sorttable_customkey")), 
			end = getDatefrom($trow.find(".item_date").attr("end")), 
			age = $trow.find(".item_age").text(), 
			day = getDatefrom($trow.find(".item_date").attr("sorttable_customkey")).getDay(), 
			category = $trow.find(".search_cp").text(), 
			season = $trow.find(".item_date div[class$='_lbl']").text(), 
			rec = $trow.find(".item_rec").text();
			var filter_obj = { name:name.toLowerCase() , start:start , end:end, age:age, day:day, category:category, season:season, rec:rec };
			$trow = $trow[0];
			$trow.filter_obj = filter_obj;
		}
		if( this.filters( $trow.filter_obj ) ){
			$($trow).css("display","table-row");
		} else {
			$($trow).css("display","none");
		}
	};
	this.filters = function(filter_obj){
		if( this.name_filter.length && filter_obj.name.indexOf( this.name_filter ) < 0 ){
			return false;
		}
		if( this.date_filter.length && !has( this.date_filter , dateToFilter(filter_obj.start)) ){
			return false;
		}
		
		if ( this.stime_filter && 
			 ( filter_obj.start.toString() == "Invalid Date" || this.stime_filter.getHours() * 60 + this.stime_filter.getMinutes() > filter_obj.start.getHours() * 60 + filter_obj.start.getMinutes() )) {
			return false;
		}
		
		var et = filter_obj.end;
		if (true){//(!et) {//for now we'll just filter by start time
			et = filter_obj.start;
		}
		if ( this.etime_filter && 
			 ( !et || et.toString() == "Invalid Date" || this.etime_filter.getHours() * 60 + this.etime_filter.getMinutes() < et.getHours() * 60 + et.getMinutes() )) {
			return false;
		}
		
		if (this.day_filter.length > 0 && !has(this.day_filter, filter_obj.start.getDay())) {
			return false;
		}
		if (this.category_filter != "" && this.category_filter != filter_obj.category) {
			return false;
		}
		if (this.season_filter != "" && this.season_filter.toLowerCase() != filter_obj.season) {
			return false;
		}
		if (filter_obj.rec == this.recurrence_filter || !this.recurrence_filter.length) {
			return true;
		}
		return false;
	}
	this.getFilteredList = function(){
		$("#data_tbl.sortable tr.item_row").each(function(){
			programFilter.filter( this );
		});
	}
}
function Item(name, start_time, end_time, age_min, age_max, age_type, recurrence, text_sched, desc, catName, catID, progID, code, regav, regphone, session_title, xlist, iName, iID ) {
    this.name = name;
    this.session_title = session_title;
    this.desc = desc;
    this.catName = catName;
    this.catID = catID;
    this.progID = progID;
    this.start_time = start_time;
    this.end_time = end_time;
    this.age_min = age_min;
    this.age_max = age_max;
    this.age_type = age_type;
    this.code = code;
    this.recurrence = recurrence;
    this.text_sched = text_sched;
    this.filter = filterItem;
    this.getCode = getItemCode;
    this.getGlance = AtAGlanceCode;
    this.hasString = hasString;
    this.regav = regav;
	this.hasDay = hasDay;
	this.regphone = regphone;
	this.xlist = xlist;
	this.iName = iName;//instructor
	this.iID = iID;
}
//check if program has occurrance on the given date
function hasDay( date ){
	if( date.length == 0 ){ return true; }
	if( has( date, dateToFilter( this.start_time ) ) ){
		return true;
    } else if ( this.recurrence == "daily" && location.href.indexOf( "programs.aspx" ) != -1 ){
		for ( var i = 0; i < date.length; i++ ){
			if( date[ i ] > dateToFilter( this.start_time ) && this.end_time != null && date[ i ] < dateToFilter( this.end_time ) ){
				return true;
			}
		}
	} else if ( this.recurrence == "weekly" && location.href.indexOf( "programs.aspx" ) != -1 ){
		var clayDate = new Date();
		for ( var i = 0; i < date.length; i++ ){
			clayDate.setMonth( ( date[ i ] % 10000 ) / 100 );
			clayDate.setFullYear( ( date[ i ] ) / 10000 );
			clayDate.setDate( date[ i ] % 100 );
			if( date[ i ] > dateToFilter( this.start_time ) && this.end_time != null && date[ i ] < dateToFilter( this.end_time ) && clayDate.getDay() == this.start_time.getDay() ){
				return true;
			}
		}
	} else if ( ( this.recurrence == "monthly" || this.recurrence == "custom" )  && location.href.indexOf( "programs.aspx" ) != -1){
		if( this.end_time != null && has( date, dateToFilter( this.end_time ) ) ){
			return true;
		}
	}
	return false;
}
//conversion of date to numeric form for button value comparison
function dateToFilter( date ){
	return date.getMonth() * 100 + date.getDate() + 10000 * date.getFullYear();
}
//check item against filter criteria
function filterItem(name, date, tmin, tmax, age, day, rec, cat, season) {
	
    if (!this.hasString(name)) {
        return false;
    }
	
   /* if (date.length > 0 && !has(date, this.start_time.getMonth() * 100 + this.start_time.getDate())) {
        return false;
    }*/
	if( !this.hasDay( date ) ){
		return false;
	}
	
    if (tmin != null && (tmin.getHours() > this.start_time.getHours() || (tmin.getHours() >= this.start_time.getHours() && tmin.getMinutes() > this.start_time.getMinutes()))) {
        return false;
    }
	
    var et = this.end_time;
    if (et == null) {
        et = this.start_time;
    }
    if (tmax != null && (tmax.getHours() < et.getHours() || (tmax.getHours() <= et.getHours() && tmax.getMinutes() < et.getMinutes()))) {
        return false;
    }
	var realMin = this.age_min, realMax = this.age_max;
	if( this.age_max.indexOf( "m" ) != -1 ){
		realMin = realMin.valueOf() / 12.0;
		realMax = realMax.substring( 0 , this.age_max.indexOf( ' ' ) );
		realMax = realMax.valueOf() / 12.0;
	}
	/*if( amax != null && amax.indexOf( "m" ) != -1 ){
		amax = amax.substring( 0 , amax.indexOf( ' ' ) );
		amax = amax.valueOf() / 12.0;
	}
	if( amin != null && amin.indexOf( "m" ) != -1 ){
		amin = amin.substring( 0 , amin.indexOf( ' ' ) );
		amin = amin.valueOf() / 12.0;
	}
    if (amin != null && amin > this.age_max) {
        return false;
    }
    if (amax != null && amax < this.age_min) {
        return false;
    }*/
	
    if (day.length > 0 && !has(day, this.start_time.getDay())) {
        return false;
    }
    if (cat != "" && cat != this.catName) {
        return false;
    }
    if (season != "" && season.toLowerCase() != this.code.substring(this.code.length - 2, this.code.length - 1).toLowerCase()) {
        return false;
    }
	
        if (this.recurrence == rec || rec == '') {
            return true;
        }
    return false;
}
//checks all the possible places a program might contain a string someone searches for
function hasString(S) {
    S = S.toLowerCase();
    if (S == null || S == "") {
        return true;
    }
    if (this.name.toLowerCase().indexOf(S) != -1) {
        return true;
    }
    if (this.iName != null && this.iName.toLowerCase().indexOf(S) != -1) {
        return true;
    }
    var tt = textTime(this.start_time);
    if (this.end_time != null) {
        tt += " - " + textTime(this.end_time);
    }
    if (tt.toLowerCase().indexOf(S) != -1) {
        return true;
    }
    if (textDay(this.start_time.getDay()).toLowerCase().indexOf(S) != -1) {
        return true;
    }
    var month = textMonth(this.start_time.getMonth()) + " " + this.start_time.getDate();
    if (month.toLowerCase().indexOf(S) != -1) {
        return true;
    }
    if (this.recurrence.toLowerCase().indexOf(S) != -1) {
        return true;
    }
    if (this.desc.toLowerCase().indexOf(S) != -1) {
        return true;
    }
    return false;
}
//get HTML code to render a program on programs.aspx

function enqueueOut( thisDiv ){
	menu_outs.push( thisDiv );
}
function exqueueOut( thisDiv ){
	for( var i = 0; i < menu_outs.length; i++ ){
		if( menu_outs[ i ] == thisDiv ){
			menu_outs.splice( i , 1 );
			//i--;
		}
	}
}
var openPorg_div = null;
function closeProgDiv(){
	if( openPorg_div != null ){
		openPorg_div.className = openPorg_div.oldClass;
	}
}
function openProgDiv( div ){
	closeProgDiv();
	openPorg_div = div;
	openPorg_div.oldClass = openPorg_div.className;
	openPorg_div.className = "item_over";
	document.getElementById( "spacer" ).style.height = "1px";	
}
function getItemCode(classMod) {
	var xlist = ( (this.xlist && location.href.indexOf("full-list.aspx") == -1 )?"xlist/":"");
	var season = this.code.substring(this.code.length - 2, this.code.length - 1).toLowerCase();
	season = ( season == 'u' ) ? "summer" : ( season == 's' ) ? "spring" : ( season == 'w' ) ? "winter" : "fall";
    var Code = "<div class='item_div" + classMod + "' onmouseout='this.childNodes[0].style.visibility = \"hidden\";'  onmouseover='this.childNodes[0].style.visibility = \"visible\";' onclick='openProgDiv( this );'>";
	
	Code += "<img src='images/moreinfo_mo.png' class='moreinfo_mo' onmouseover='openProgDiv( this.parentNode );' />";
	Code += "<table class='item_row' onmouseout='return false;'>";
    Code += "<td class='item_name' ><a href='javascript:var NW = window.open(\"cat-content.aspx?catID=" + this.catID + "&progID=" + this.progID + "#/" + this.code + "\",\"\",\"scrollbars=yes,resizable=yes,width=560,height=650\");' onclick='javascript:urchinTracker(\"/programs/prog/" + xlist + "(" + this.catID + ")" + this.code + "\");' class='prog_info_btn' onmouseover='openProgDiv( this.parentNode.parentNode.parentNode.parentNode.parentNode );'>" + this.name;
	if( this.session_title != this.name ){
		Code += "<br /><i>" + this.session_title + "</i>";
	}
	Code += "</a></td>";
	var closeText =  "onmouseover='if( openPorg_div != this.parentNode.parentNode.parentNode.parentNode ){closeProgDiv(); }'";
	if( this.text_sched != "" ){
		Code += "<td class='item_date' " + closeText + ">" + constrain( this.text_sched , 20 );
	} else if( this.recurrence == "once" || this.end_time == null ){
		Code += "<td class='item_date' " + closeText + ">" + textDay(this.start_time.getDay()) + ", " + textMonth(this.start_time.getMonth()) + " " + this.start_time.getDate();
	} else {//put something here to check if program's started
		Code += "<td class='item_date' " + closeText + ">" + textDay(this.start_time.getDay()) + ", " + textMonth(this.start_time.getMonth()) + " " + this.start_time.getDate() + " - " + textMonth(this.end_time.getMonth()) + " " + this.end_time.getDate();
		//Code += "<td class='item_date'>" + dateToFilter(this.start_time) + ", " + dateToFilter(this.end_time) + " " + "</td>";
	}
	Code += "<br /><span class='" + season + "_lbl'>" + season + "</span></td>";
    Code += "<td class='item_time' " + closeText + ">";
	if( this.start_time.getHours() == 8 && this.start_time.getMinutes() == 0 && this.end_time != null && this.end_time.getHours() == 17 && this.end_time.getMinutes() == 0 ){
		Code += "all day";
	} else {
		Code += textTime(this.start_time);
	}
    Code += "</td>";
	//BUILD IN ALL DAY CLAUSE HERE
	if( this.age_min != "0" || this.age_max != "0" ){
		Code += "<td class='item_age' " + closeText + ">" + this.age_min;
		if( this.age_max > this.age_min ){
			Code += " - " + this.age_max;
		}
		Code += ( this.age_type == 2 ) ? " months" : " years";
		Code += "</td>";
	} else {
		Code += "<td class='item_age' " + closeText + ">n/a</td>";
	}
	Code += "<td class='item_rec' " + closeText + "> " + this.recurrence + "</td>";
    Code += "</tr></table>";
	
    Code += "<div class='item_out'  onmouseout='return false;' ><div style='height:100px; overflow:hidden; width:520px;'>";
	Code += "<a href='javascript:var NW = window.open(\"cat-content.aspx?catID=" + this.catID + "&progID=" + this.progID + "#/" + this.code + "\",\"\",\"scrollbars=yes,resizable=yes,width=560,height=650\");' onclick='javascript:urchinTracker(\"/programs/prog/" + xlist + "(" + this.catID + ")" + this.code + "\");' class='prog_info_btn'><img src='dbImages/prog-" + this.progID + ".jpg' onerror='this.parentNode.removeChild( this ); return false;' align='left' border='0' class='prog_img'/></a>";
	Code += constrain( stripTags( this.desc ) , 300 );
	if( constrain( stripTags( this.desc ) , 300 ).indexOf( '...' ) > 200 ){
		Code += "(<a href='javascript:var NW = window.open(\"cat-content.aspx?catID=" + this.catID + "&progID=" + this.progID + "#/" + this.code + "\",\"\",\"scrollbars=yes,resizable=yes,width=560,height=650\");' onclick='javascript:urchinTracker(\"/programs/prog/" + xlist + "(" + this.catID + ")" + this.code + "\");' class='prog_info_btn'>read more</a>)";
	}
	Code += "</div>";
	if( this.iName != "" ){
		//Code += "<div style='height:11px; margin-top:20px;'>instructor: <a href='instructors.aspx?ID=" + this.iID + "&catid=" + this.catID + "&progID=" + this.progID + "'>" + this.iName + "</a></div>";
		Code += "<div style='height:11px; margin-top:20px;'>instructor: <a href='instructors.aspx?ID=" + this.iID + "'>" + this.iName + "</a></div>";
	}
	Code += "<div style='font-style:italic; height:21px; margin-top:20px;'><a href='category.aspx?catid=" + this.catID + "'>" + this.catName + "</a></div><br>";
    if (this.regav == 0) {
        Code += "<a href='javascript:var NW = window.open(\"cat-content.aspx?catID=" + this.catID + "&progID=" + this.progID + "#/" + this.code + "\",\"\",\"scrollbars=yes,resizable=yes,width=560,height=650\");' onclick='javascript:urchinTracker(\"/programs/prog/" + xlist + "(" + this.catID + ")" + this.code + "\");' class='prog_info_btn'><img src='images/buttons/view_prog.png' border='0' /></a> or call ";
		if( this.regphone != "" && this.regphone != null ){
			Code += this.regphone;
		} else { Code += "646-505-5708"; }
    } else {
        Code += "<a href='javascript:var NW = window.open(\"cat-content.aspx?catID=" + this.catID + "&progID=" + this.progID + "#/" + this.code + "\",\"\",\"scrollbars=yes,resizable=yes,width=560,height=650\");' onclick='javascript:urchinTracker(\"/programs/prog/" + xlist + "(" + this.catID + ")" + this.code + "\");' class='prog_info_btn'><img src='images/buttons/moreinfo_prog.png' border='0' /></a> or call ";
		if( this.regphone != "" && this.regphone != null ){
			Code += this.regphone;
		} else { Code += "646-505-5708"; }
    }
	Code += "</div>";
    Code += "</div>";
    return Code;
}

//get HTML code to render on calendar1.aspx
function AtAGlanceCode() {
    var Code = "<div class='glance_item_div'  onclick='' onmouseover='this.className = \"glance_item_over\"' onmouseout='this.className = \"glance_item_div\"'>";
    Code += "<table class='item_row' cellspacing='0' cellpadding='0' ><tr valign='top'>";
    Code += "<td rowspan='3'><img src='dbImages/prog-" + this.progID + ".jpg' onerror='this.src = \"catimages/" + this.catID + ".jpg\"; this.onerror = function(){this.parentNode.removeChild( this ); return false;};' class='prog_img' /></td>";
    Code += "<td class='item_name' style='height:40px;'>" + this.name;
	if( this.session_title != this.name ){
		Code += "<br /><i>" + this.session_title + "</i>";
	} 
	Code += "</td>";
    Code += "<td class='item_date'>" + textDay(this.start_time.getDay()) + ", " + textMonth(this.start_time.getMonth()) + " " + this.start_time.getDate();
	if( this.recurrence != "once" && this.end_time != null ){
		Code += " - " + textMonth(this.end_time.getMonth()) + " " + this.end_time.getDate();
	}
	Code += "</td>";
    //Code += "<td class='item_day'>" + textDay(this.start_time.getDay()) + "</td>";
    //Start Time
    //Code += "<td class='item_time'>" + textTime(this.start_time);
	Code += "<td class='item_time'>";
	if( this.start_time.getHours() == 8 && this.start_time.getMinutes() == 0 && this.end_time != null && this.end_time.getHours() == 17 && this.end_time.getMinutes() == 0 ){
		Code += "all day";
	} else {
		Code += textTime(this.start_time);
	}
    Code += "</td>";
    //if (this.end_time != null) {
      //  Code += " - " + textTime(this.end_time);
    //}
    Code += "</div>";
    Code += "<td class='item_rec'> " + this.recurrence + "</td>";
    Code += "</tr>";
    Code += "<tr valign='top'><td colspan='5' style='font-style:italic; padding-left:10px; height:38px;'><a href='category.aspx?catid=" + this.catID + "'>" + this.catName + "</a></td></tr>";
    Code += "<tr valign='top'><td colspan='5' style='padding-left:10px;' ><a href='javascript:var NW = window.open(\"cat-content.aspx?catID=" + this.catID + "&progID=" + this.progID + "\",\"\",\"scrollbars=yes,resizable=yes,width=560,height=650\");' onclick='javascript:urchinTracker(\"/WAG/prog/" + this.code + "\");' class='prog_info_btn'><img src='images/buttons/view_prog.png' border='0' /></a></td></tr>";
    Code += "</table>";
    Code += "</div>";
    return Code;
}
//mouse over and mouse out functions
function collapse(D) {
    var div = childByClass(D, "item_over");
    div.className = "item_out";
    var t = setTimeout("scroller.recalc();", 100);
}
function expand(div) {
    div.className = "item_over";
    scroller.recalc();
}
//*********ITEMLIST OBJECT***********//
function ItemList(items) {
    this.items = items;
    this.filter = items;
    this.name_filter = "";
    this.date_filter = [];
    this.stime_filter = null;
    this.etime_filter = null;
    this.age_filter = null;
    this.day_filter = [];
    this.category_filter = "";
    this.season_filter = "";
    this.recurrence_filter = [];
    this.getFilteredList = getFilteredList;
    this.getCode = getItemListCode;
    this.getGlanceCode = getGlanceCode;
    this.sortByName = sortByName;
    this.sortByDate = sortByDate;
    this.sortByDay = sortByDay;
    this.sortByTime = sortByTime;
    this.sortByAge = sortByAge;
    this.sortByRecurrence = sortByRecurrence;
    this.getCategoryList = getCategoryList;
    this.termList = getTermList;
	this.sortBy = function(){};
}
//run the current filters on the complete set of results, returning the filtered set
function getFilteredList() {
    var temp = [], codes = [],
    filtered = false;
    for (var i = 0; i < this.items.length; i++) {
        if (this.items[i].filter(this.name_filter.toLowerCase(), this.date_filter, this.stime_filter, this.etime_filter, this.age_filter, this.day_filter, this.recurrence_filter, this.category_filter, this.season_filter) && !has( codes , this.items[ i ].code ) ) {
            temp.push(this.items[i]);
			codes.push( this.items[ i ].code );
        } else {
            filtered = true;
        }
    }
    this.filter = temp;
    var clear = document.getElementById("filter_clear");
    if (filtered && clear != null) {
        clear.style.visibility = "visible";
    } else if (clear != null) {
        document.getElementById("filter_clear").style.visibility = "hidden";
    }
    document.getElementById("BreadCrumb_notes").innerHTML = temp.length + " program(s)";
    return new ItemList(temp);
}
//render html code for all programs on programs.aspx
function getItemListCode() {
	if( this.sortBy == function(){} ){ this.sortBy = sortByName; }
	this.sortBy();
    var temp = "";
    for (var i = 0; i < this.filter.length; i++) {
        temp += this.filter[i].getCode( ( i % 2 == 0 ) ? '1' : '' );
    }
    return temp + "<div id='spacer'></div>";
}
//render html code for all programs on calendar1.aspx
function getGlanceCode() {
    var temp = "";
    for (var i = 0; i < this.filter.length; i++) {
        temp += this.filter[i].getGlance();
    }
    return temp;
}
//build the category list dropdown in the right on programs.aspx
function getCategoryList() {
    var catList = [],
    code = "";
    for (var i = 0; i < this.items.length; i++) {
        if (!has(catList, this.items[i].catName)) {
            catList.push(this.items[i].catName);
        }
    }
	
	var bc = document.getElementById("BreadCrumbNav_2_01");
	if( bc == null ){ bc = document.getElementById("BreadCrumbNav"); }
    bc = bc.childNodes[bc.childNodes.length - 1];        
	var catName = bc.innerHTML; 
	
	var CS = document.getElementById( "category_select" );
    for (var i = 0; i < catList.length; i++) {
        var newOpt = document.createElement("option");
		newOpt.value = catList[i];
		newOpt.onclick = function(){ urchinTracker( "/programs/categoryfilter/" + this.text + "/" + getCatName( currentCat) ); };
		newOpt.text = catList[i].substring( catList[i].indexOf( '&gt;' ) + 1 , catList[i].length );
		if( navigator.appName == "Microsoft Internet Explorer" ){
			CS.add( newOpt );
		} else { 
			CS.appendChild( newOpt );
		}
    }
    return code;
}
//build the season list dropdown in the right on programs.aspx
function getTermList() {
    var termList = [], items = $("#data_tbl div[class$='_lbl']"),
    code = "";
    for (var i = 0; i < items.length; i++) {
        if (!has(termList, $(items[i]).text())) {
            termList.push($(items[i]).text());
        }
    }
	
	var bc = document.getElementById("BreadCrumbNav_2_01");
	if( bc == null ){ bc = document.getElementById("BreadCrumbNav"); }
    bc = bc.childNodes[bc.childNodes.length - 1];        
	var catName = bc.innerHTML; 
	
	var SS = document.getElementById( "season_select" );
    for (var i = 0; i < termList.length; i++) {
        var newOpt = document.createElement("option");
		newOpt.value = termList[i];
		newOpt.text = termList[i];
		newOpt.onclick = function(){ urchinTracker( "/programs/seasonfilter/" + this.text + "/" + getCatName( currentCat) ); };
		newOpt.className = termList[i] + "_lbl";
		if( navigator.appName == "Microsoft Internet Explorer" ){
			SS.add( newOpt );
		} else { 
			SS.appendChild( newOpt );
		}
    }
    return code;
}
function sortByName() {
	this.sortBy = sortByName;
    /*document.getElementById("name_sort_btn").style.textDecoration = "underline";
    document.getElementById("date_sort_btn").style.textDecoration = "none";
    document.getElementById("time_sort_btn").style.textDecoration = "none";
    document.getElementById("age_sort_btn").style.textDecoration = "none";
    document.getElementById("rec_sort_btn").style.textDecoration = "none";*/
    document.getElementById("name_sort_btn").style.background = "#999999";
    document.getElementById("date_sort_btn").style.background = "none";
    document.getElementById("time_sort_btn").style.background = "none";
    document.getElementById("age_sort_btn").style.background = "none";
    document.getElementById("rec_sort_btn").style.background = "none";
    var swap;
    var items = this.getFilteredList().items;
    for (var i = 0; i < items.length; i++) {
        for (var j = i + 1; j < items.length; j++) {
            //if ( stripTags( items[i].name ) > stripTags( items[j].name )  || ( stripTags( items[i].name ) == stripTags( items[j].name ) && stripTags( items[i].session_title ) > stripTags( items[j].session_title ) ) ) {
            if ( shouldSwap_name( items[i] , items[j] ) ) {
                swap = items[i];
                items[i] = items[j];
                items[j] = swap;
            }
        }
    }
    this.filter = items;
}
//check title and subtitle if titles are the same
function shouldSwap_name( prog1 , prog2 ){
	var t1 = stripTags( prog1.name ), 
	t2 = stripTags( prog2.name ), 
	st1 = stripTags( prog1.session_title ), 
	st2 = stripTags( prog2.session_title );
	t1 = t1.replace( '"', '' );
	t2 = t2.replace( '"', '' );
	st1 = st1.replace( '"', '' );
	st2 = st2.replace( '"', '' );
	return ( t1 > t2  || ( t1 == t2 && st1 > st2 ) );
}
function sortByDate() {
	this.sortBy = sortByDate;
    /*document.getElementById("name_sort_btn").style.textDecoration = "none";
    document.getElementById("date_sort_btn").style.textDecoration = "underline";
    document.getElementById("time_sort_btn").style.textDecoration = "none";
    document.getElementById("age_sort_btn").style.textDecoration = "none";
    document.getElementById("rec_sort_btn").style.textDecoration = "none";*/
    document.getElementById("name_sort_btn").style.background = "none";
    document.getElementById("date_sort_btn").style.background = "#999999";
    document.getElementById("time_sort_btn").style.background = "none";
    document.getElementById("age_sort_btn").style.background = "none";
    document.getElementById("rec_sort_btn").style.background = "none";
    var swap, dayless;
    var items = this.getFilteredList().items;
    /*for (var i = 0; i < items.length; i++) {
        for (var j = i + 1; j < items.length; j++) {
			dayless = items[i].start_time.getDay() > items[j].start_time.getDay();
            if ( dayless || ( items[i].start_time.getDay() == items[j].start_time.getDay() && items[i].start_time > items[j].start_time ) ) {
                swap = items[i];
                items[i] = items[j];
                items[j] = swap;
            }
        }
    }*///for group by day
    for (var i = 0; i < items.length; i++) {
        for (var j = i + 1; j < items.length; j++) {
			if ( items[i].start_time > items[j].start_time ) {
                swap = items[i];
                items[i] = items[j];
                items[j] = swap;
            }
        }
    }
    this.filter = items;
}
function sortByDay() {
	this.sortBy = sortByDay;
    /*document.getElementById("name_sort_btn").style.textDecoration = "none";
    document.getElementById("day_sort_btn").style.textDecoration = "underline";
    document.getElementById("date_sort_btn").style.textDecoration = "none";
    document.getElementById("time_sort_btn").style.textDecoration = "none";
    document.getElementById("age_sort_btn").style.textDecoration = "none";
    document.getElementById("rec_sort_btn").style.textDecoration = "none";*/
    var swap;
    var items = this.getFilteredList().items;
    for (var i = 0; i < items.length; i++) {
        for (var j = i + 1; j < items.length; j++) {
            if (items[i].start_time.getDay() > items[j].start_time.getDay()) {
                swap = items[i];
                items[i] = items[j];
                items[j] = swap;
            }
        }
    }
    this.filter = items;
}
function sortByTime() {
	this.sortBy = sortByTime;
	if( document.getElementById("time_sort_btn") != null ){
		/*document.getElementById("name_sort_btn").style.textDecoration = "none";
		document.getElementById("date_sort_btn").style.textDecoration = "none";
		document.getElementById("time_sort_btn").style.textDecoration = "underline";
		document.getElementById("age_sort_btn").style.textDecoration = "none";
		document.getElementById("rec_sort_btn").style.textDecoration = "none";*/
		document.getElementById("name_sort_btn").style.background = "none";
		document.getElementById("date_sort_btn").style.background = "none";
		document.getElementById("time_sort_btn").style.background = "#999999";
		document.getElementById("age_sort_btn").style.background = "none";
		document.getElementById("rec_sort_btn").style.background = "none";
	}
    var swap;
    var items = this.getFilteredList().items;
    for (var i = 0; i < items.length; i++) {
        for (var j = i + 1; j < items.length; j++) {
            if (items[i].start_time.getHours() > items[j].start_time.getHours() || (items[i].start_time.getHours() == items[j].start_time.getHours() && items[i].start_time.getMinutes() > items[j].start_time.getMinutes())) {
                swap = items[i];
                items[i] = items[j];
                items[j] = swap;
            }
        }
    }
    this.filter = items;
	return new ItemList( this.filter );
}
function sortByAge() {
	this.sortBy = sortByAge;
    /*document.getElementById("name_sort_btn").style.textDecoration = "none";
    document.getElementById("date_sort_btn").style.textDecoration = "none";
    document.getElementById("time_sort_btn").style.textDecoration = "none";
    document.getElementById("age_sort_btn").style.textDecoration = "underline";
    document.getElementById("rec_sort_btn").style.textDecoration = "none";*/
    document.getElementById("name_sort_btn").style.background = "none";
    document.getElementById("date_sort_btn").style.background = "none";
    document.getElementById("time_sort_btn").style.background = "none";
    document.getElementById("age_sort_btn").style.background = "#999999";
    document.getElementById("rec_sort_btn").style.background = "none";
    var swap;
    var items = this.getFilteredList().items;
    for (var i = 0; i < items.length; i++) {
        for (var j = i + 1; j < items.length; j++) {
            if (items[i].age_min * ( ( items[i].age_type == 1 ) ? 12 : 1 ) > items[j].age_min *  ( ( items[j].age_type == 1 ) ? 12 : 1 ) ) {
                swap = items[i];
                items[i] = items[j];
                items[j] = swap;
            }
        }
    }
    this.filter = items;
}
function sortByRecurrence() {
	this.sortBy = sortByRecurrence;
    /*document.getElementById("name_sort_btn").style.textDecoration = "none";
    document.getElementById("date_sort_btn").style.textDecoration = "none";
    document.getElementById("time_sort_btn").style.textDecoration = "none";
    document.getElementById("age_sort_btn").style.textDecoration = "none";
    document.getElementById("rec_sort_btn").style.textDecoration = "underline";*/
    document.getElementById("name_sort_btn").style.background = "none";
    document.getElementById("date_sort_btn").style.background = "none";
    document.getElementById("time_sort_btn").style.background = "none";
    document.getElementById("age_sort_btn").style.background = "none";
    document.getElementById("rec_sort_btn").style.background = "#999999";
    var swap;
    var items = this.getFilteredList().items;
    for (var i = 0; i < items.length; i++) {
        for (var j = i + 1; j < items.length; j++) {
            if ((items[i].recurrence == "monthly" && (items[j].recurrence == "daily" || items[j].recurrence == "weekly" || items[j].recurrence == "once")) || (items[i].recurrence == "weekly" && (items[j].recurrence == "daily" || items[j].recurrence == "once")) || (items[i].recurrence == "daily" && items[j].recurrence == "once")) {
                swap = items[i];
                items[i] = items[j];
                items[j] = swap;
            }
        }
    }
    this.filter = items;
}

//UTILITY FUNCTIONS

//enter code generated into the programs.aspx calendar and handle the case that there are no programs
function putIntoCalendar(code) {
	var Pid = getCatidFromUrl( location.href );
	Pid = ( Pid == null ) ? null : parentOf( Pid );
	if( Pid == null && location.href.indexOf( "programs" ) == -1 ){
		document.getElementById("calendar").innerHTML = ( isFiltered() ) ? code : "<span style='padding-left:10px;  padding-top:30px; font-weight:bold; color:#ff0000;'>please select a filter</span>";		
	}
	else if( Pid != 0 && !isFiltered() ){
		document.getElementById("calendar").innerHTML = ( code != "<div id='spacer'></div>" ) ? code : "<span style='padding:10px;'>no results - <br /><a href='programs.aspx?catid=" + Pid + "'><img src='/images/buttons/click_here_off.png' width='92' height='35' hspace='10' border='0' id='noprog_btn' onMouseOver='MM_swapImage(this.id,\"\",\"/images/buttons/click_here_on.png\",1)' onMouseOut='MM_swapImgRestore()' align='left' /></a> to see more programs in <b>" + stripTags( getNameFromId( Pid ) ) + "</b></span>";
	}
	else {
		document.getElementById("calendar").innerHTML = ( code != "<div id='spacer'></div>" ) ? code : "<span style='padding:10px;'>no results - please check back later</span>";
	}
    try{ scroller.recalc(); }catch( e ){}
}

function mobicheck() {
    var mobiles = new Array(
        /* begin Apple */
        "iPhone",
        "iPod",
        "iPad",
        /* end Apple */

        /* begin Android */
        "Android",
        /* end Android */

        /* begin BlackBerry */
        "BlackBerry",
        /* end BlackBerry */

        /* begin Nokia */
        "Nokia",
        "Symbian",
        /* end Nokia */

        /* begin Windows mobile */
        "PIE",
        "IEMobile",
        "PPC",
        "Windows Phone",
        "Windows CE",
        /* end Windows mobile */

        /* begin Opera */
        "Opera Mini",
        "Opera Mobi",
        /* end Opera */

        /* begin HTC */
        "HTC",
        /* end HTC */

        /* begin Palm */
        "PalmOS",
        "Xiino",
        "Minimo",
        "OPWV",
        "UP.Browser",
        "Plucker",
        /* end Palm */

        /* begin Kindle */
        "Kindle"
        /* end Kindle */
    );

    var useragent = navigator.userAgent.toLowerCase();
    for (var i = 0; i < mobiles.length; ++i) {
	if (useragent.indexOf(mobiles[i].toLowerCase()) != -1) {
	    return true;
	    break;
	}

	else {}
    }

    return false;
}

function toNum(S) {
    return S.substring(0, S.indexOf('px'));
}
function min() {
    var a = min.arguments;
    var M = a[0];
    for (var i = 0; i < a.length; i++) {
        if (a[i] < M) {
            M = a[i];
        }
    }
    return M;
}
function max() {
    var a = max.arguments;
    var M = a[0];
    for (var i = 0; i < a.length; i++) {
        if (a[i] > M) {
            M = a[i];
        }
    }
    return M;
}
function within(a, b, c) {
    if (a < b) {
        return b;
    }
    if (a > c) {
        return c;
    }
    return a;
}
function textDay(d) {
    if (d % 7 == 0) {
        return "Sun";
    }
    if (d % 7 == 1) {
        return "Mon";
    }
    if (d % 7 == 2) {
        return "Tue";
    }
    if (d % 7 == 3) {
        return "Wed";
    }
    if (d % 7 == 4) {
        return "Thu";
    }
    if (d % 7 == 5) {
        return "Fri";
    }
    return "Sat";
}
function textMonth(d) {
    if (d == 0) {
        return "Jan";
    }
    if (d == 1) {
        return "Feb";
    }
    if (d == 2) {
        return "Mar";
    }
    if (d == 3) {
        return "Apr";
    }
    if (d == 4) {
        return "May";
    }
    if (d == 5) {
        return "Jun";
    }
    if (d == 6) {
        return "Jul";
    }
    if (d == 7) {
        return "Aug";
    }
    if (d == 8) {
        return "Sep";
    }
    if (d == 9) {
        return "Oct";
    }
    if (d == 10) {
        return "Nov";
    }
    return "Dec";
}
//print the text version of the current month
function thisMonth() {
    return textMonth(calmonth) + " " + calyear;
}
function selectWeek( dateString ){
	var date = new Date();
	date.setDate( dateString.substring( 6 , 8 ) );
	date.setMonth( dateString.substring( 4 , 6 ) );
	date.setFullYear( dateString.substring( 0 , 4 ) );
	date.setDate( dateString.substring( 6 , 8 ) );
	date.setMonth( dateString.substring( 4 , 6 ) );
	date.setFullYear( dateString.substring( 0 , 4 ) );
	
	while( date.getDay() != 0 ){
		date.setDate(date.getDate() - 1);
	}
	var day_buttons = [];
	var hasEmpty = false;
	for( var i = 0; i < 7; i++ ){
		day_buttons.push( document.getElementById( getCalendarDateId( date ) ) );
		if( day_buttons[ day_buttons.length - 1 ].className.indexOf( "date_on_link" ) == -1 ){
			hasEmpty = true;
		}
		date.setDate( date.getDate() + 1 );
	}
	for( var i = 0; i < 7; i++ ){
		if( day_buttons[ i ].className.indexOf( "date_on_link" ) == -1 && hasEmpty ){
			try{day_buttons[ i ].onclick();}catch(e){}
		} else if( !hasEmpty ) {//in this case all buttons have been clicked on for the week
			try{day_buttons[ i ].onclick();}catch(e){}
		}
	}
}
//used to print out the calendar filter initially and every time the month is changed
function printCal() {
    var code = '<table id="cal_chart_tbl" cellpadding="0" cellspacing="0"><tr>';
    var date = new Date();
    date.setDate(1);
    date.setMonth(calmonth);
    date.setFullYear(calyear);
    var offset = date.getDay(), filter, onclick;
	var predate = date;
	predate.setDate( 1 - offset );
	
	var bc = document.getElementById("BreadCrumbNav_2_01");
	if( bc == null ){ bc = document.getElementById("BreadCrumbNav"); }
    bc = bc.childNodes[bc.childNodes.length - 1];        
	var catName = bc.innerHTML; 
	
    for (var i = 0; i < offset; i++) {
		onclick = "onclick='dateFilter(" + dateToFilter( predate ) + "); getDateClass(this); getColor( this ); urchinTracker(\"/programs/datefilter/" + catName + "\");' onMouseOver='this.style.backgroundColor = \"#dddddd\";' onMouseOut='this.style.backgroundColor = \"\";'";
        if (i != 0) {
			try {
				if (has(programFilter.date_filter, dateToFilter( predate ) ) ) {
					code += "<td " + onclick + " valign='middle' class='date_on_link' id='" + getCalendarDateId( predate ) + "' title='" + predate.toString() + "'>-</td>";
				} else {
					code += "<td " + onclick + " valign='middle' class='date_off_link' id='" + getCalendarDateId( predate ) + "' title='" + predate.toString() + "'>-</td>";
				}
			}catch(e) {
                code += "<td " + onclick + " valign='middle' class='date_off_link' id='" + getCalendarDateId( predate ) + "' title='" + predate.toString() + "'>-</td>";
            }
        }
        else {
			code += "<td onclick='selectWeek(\"" + dateToFilter( date ) + "\")' style='border-left:none; border-top:none; font-size:8px; text-align:left; cursor:pointer; background-color:#ffffff; color:#4040ff;' onmouseover='this.parentNode.style.backgroundColor = \"#dddddd\";' onmouseout='this.parentNode.style.backgroundColor = \"#ffffff\";' >&gt;</td>";
			try {
				if (has(programFilter.date_filter, dateToFilter( predate ) ) ) {
					code += "<td " + onclick + " valign='middle' style='border-left:none;' class='date_on_link' id='" + getCalendarDateId( predate ) + "' title='" + predate.toString() + "'>-</td>";
				} else {
					code += "<td " + onclick + " valign='middle' style='border-left:none;' class='date_off_link' id='" + getCalendarDateId( predate ) + "' title='" + predate.toString() + "'>-</td>";
				}
			}catch(e) {
                code += "<td " + onclick + " valign='middle' style='border-left:none;' class='date_off_link' id='" + getCalendarDateId( predate ) + "' title='" + predate.toString() + "'>-</td>";
            }
        }
		predate.setDate( predate.getDate() + 1 );
    }
    //date.setDate(date.getDay());
	

    for (var i = 1; i < 43 - offset; i++) {
        date.setDate(i);
        onclick = " onclick='dateFilter(" + dateToFilter( date ) + "); getDateClass(this); urchinTracker(\"/programs/datefilter/" + catName + "\");' onMouseOver='this.style.backgroundColor = \"#dddddd\";' onMouseOut='this.style.backgroundColor = \"\";'";
//date.setMonth(calmonth);
        if ((i + offset) % 7 == 1) {
            code += "</tr><tr><td onclick='selectWeek(\"" + dateToFilter( date ) + "\")'  style='border-left:none; border-top:none; font-size:8px; text-align:left; cursor:pointer; background-color:#ffffff; color:#4040ff;' onmouseover='this.parentNode.style.backgroundColor = \"#dddddd\";' onmouseout='this.parentNode.style.backgroundColor = \"#ffffff\";'>&gt;</td><td valign='middle' style='border-left:none;'";
        } else {
            code += "<td valign='middle'";
        }
        if (i != date.getDate()) {
            try {
				if (has(programFilter.date_filter, dateToFilter( date ) ) ) {
					code += onclick + " class='date_on_link' id='" + getCalendarDateId( date ) + "' title='" + date.toString() + "'>-</td>";
				} else {
					code += onclick + " class='date_off_link' id='" + getCalendarDateId( date ) + "' title='" + date.toString() + "'>-</td>";
				}
			}catch(e) {
                code += onclick + " class='date_off_link' id='" + getCalendarDateId( date ) + "' title='" + date.toString() + "'>-</td>";
            }
			date.setMonth(calmonth);
			date.setFullYear(calyear);
            //code += " class='date_off_link'>-</td>";
        }
        else {
            try {
                if (has(programFilter.date_filter, dateToFilter( date ) ) ) {
                    code += " class='date_on_link'";
                }
                else {
                    code += " class='date_off_link'";
                }
            } catch(e) {
                code += " class='date_off_link'";
            }
            code += onclick + " id='" + getCalendarDateId( date ) + "' title='" + date.toString() + "'>" + date.getDate() + "</td>";
        }
    }

    return code + "</tr></table>";
}
function getCalendarDateId( date ){
	return "date" + date.getYear() + "" + date.getMonth() + "" + date.getDate();
}
function getNextMonthDateId( date ){
	date.setMonth( date.getMonth() + 1 );
	return "date" + date.getYear() + "" + date.getMonth() + "" + date.getDate();
}
function digits( num , L ){
	var string = "" + num;
	while( num < Math.pow( 10 , L - 1 ) && L > 1 ){
		L--;
		string = "0" + string;
	}
	return string;
}
function printHomeCal() {
    var code = '<table id="cal_chart_tbl" cellpadding="0" cellspacing="0"><tr>';
    var date = new Date();
    date.setDate(1);
    date.setMonth(calmonth);
    date.setFullYear(calyear);
    var offset = date.getDay(), filter, onclick;
	var predate = date;
	predate.setDate( 1 - offset );
	
    for (var i = 0; i < offset; i++) {
        if (i != 0) {
			code += "<td valign='middle' class='date_off_link' title='" + predate.toString() + "'>-</td>";
        }
        else {
			code += "<td style='border-left:none; border-top:none; font-size:8px; text-align:left; cursor:pointer; background-color:#ffffff; color:#4040ff;' onmouseover='this.parentNode.style.backgroundColor = \"#dddddd\";' onmouseout='this.parentNode.style.backgroundColor = \"\";'><a href='full-list.aspx?week=" + date.getFullYear() + "" + digits( date.getMonth() , 2 ) + "" + digits( date.getDate() , 2 ) + "' style='color:#4040ff;' >&gt;</a></td>";
			code += "<td valign='middle' style='border-left:none;' class='date_off_link' title='" + predate.toString() + "'>-</td>";
        }
		predate.setDate( predate.getDate() + 1 );
    }
    //date.setDate(date.getDay());
	

    for (var i = 1; i < 43 - offset; i++) {
        date.setDate(i);
//date.setMonth(calmonth);
        if ((i + offset) % 7 == 1) {
            code += "</tr><tr><td style='border-left:none; border-top:none; font-size:8px; text-align:left; cursor:pointer; background-color:#ffffff; color:#4040ff;' onmouseover='this.parentNode.style.backgroundColor = \"#dddddd\";' onmouseout='this.parentNode.style.backgroundColor = \"\";'><a href='full-list.aspx?week=" + date.getFullYear() + "" + digits( date.getMonth() , 2 ) + "" + digits( date.getDate() , 2 ) + "' style='color:#4040ff;'  >&gt;</a></td><td valign='middle' style='border-left:none;' title='" + date.toString() + "'";
        } else {
            code += "<td valign='middle' title='" + date.toString() + "'";
        }
        if (i != date.getDate()) {
            code += onclick + " class='date_off_link'>-</td>";
			date.setMonth(calmonth);
			date.setFullYear(calyear);
            //code += " class='date_off_link'>-</td>";
        }
        else {
            code += " class='date_off_link'";
			
			code += " onMouseOver='this.style.backgroundColor = \"#dddddd\";' onMouseOut='this.style.backgroundColor = \"\"'><a href='full-list.aspx?date=" + date.getFullYear() + "" + digits( date.getMonth() , 2 ) + "" + digits( date.getDate() , 2 ) + "'  id='date" + date.getYear() + "" + date.getMonth() + "" + date.getDate() + "'>" + date.getDate() + "</a></td>";
        }
    }

    return code + "</tr></table>";
}
function getDateFromURL(){
	var date = new Date();
	if( location.search.toLowerCase().indexOf( "?date=" ) == -1 && location.search.toLowerCase().indexOf( "?week=" ) == -1 ){ return date; }
	date.setDate( 1 );
	date.setFullYear( location.search.substring( 6 , 10 ) );
	date.setMonth( location.search.substring( 10 , 12 ) );
	date.setDate( location.search.substring( 12 , 14 ) );
	date.setFullYear( location.search.substring( 6 , 10 ) );
	date.setMonth( location.search.substring( 10 , 12 ) );
	date.setDate( location.search.substring( 12 , 14 ) );
	return date;
}
var today = "";
function getThisDate(){
	var date = new Date();
	today = "date" + date.getYear() + "" + date.getMonth() + "" + date.getDate();
}
function markCurrentDate(){
	if( today == "" ){ getThisDate(); }
	var currentDate = document.getElementById( today );
	if( currentDate != null ){
		if( currentDate.className.indexOf( 'date_on_link' ) != -1 ){
			currentDate.className = 'date_on_link date_this_link';
			return true;
		}
		currentDate.className = 'date_this_link';
		return true;
	}
	return false;
}
function childByClass(obj, className) {
	if( obj == null ){ return null; }
    for (var i = 0; i < obj.childNodes.length; i++) {
        if (obj.childNodes[i].className == className) {
            return obj.childNodes[i];
        }
    }
    return null;
}
function childrenByTag(obj, tagName) {
	if( obj == null ){ return []; }
    var children = [];
    for (var i = 0; i < obj.childNodes.length; i++) {
        if (obj.childNodes[i].tagName.toLowerCase() == tagName.toLowerCase()) {
            children.push(obj.childNodes[i]);
        }
    }
    return children;
}
function getLinksUnder(div) {
    var subDivs = childrenByTag(childByClass(div, "subholder"), "div"),
    subLinks = [];
    for (var i = 0; i < subDivs.length; i++) {
        subLinks.push(childrenByTag(subDivs[i], "a")[0]);
    }
    return subLinks;
}
function getAllClass(tag, className) {
    var tagged = document.getElementsByTagName(tag),
    results = [];
    for (var i = 0; i < tagged.length; i++) {
        if (tagged[i].className.indexOf(className) != -1) {
            results.push(tagged[i]);
        }
    }
    return results;
}
function getColor(obj) {
    if (obj.className.indexOf("_on") == -1) {
        obj.style.color = "#000000";
    }
    else {
        obj.style.color = "#999999"; 
    }
}
function getDayClass(obj) {
    if (obj.className.indexOf("on") != -1) {
        obj.className = 'day_off_link';
    }
    else {
        obj.className = 'day_on_link';
    }
}
function getDateClass(obj) {
    if (obj.className.indexOf("on") != -1) {
        obj.className = 'date_off_link';
		if( obj.id == today ){
			obj.className = 'date_this_link';
		}	
    }
    else if( obj.className.indexOf( 'date_this_link' ) != -1 ){
        obj.className = 'date_on_link date_this_link';
		return;
    }
    else{
        obj.className = 'date_on_link';
		return;
    }
}
function lastMonth() {
    calmonth--;
    if (calmonth < 0) {
        calmonth = 11;
        calyear--;
    }
}
function nextMonth() {
    calmonth++;
    if (calmonth > 11) {
        calmonth = 0;
        calyear++;
    }
}
function dateFilter(d) {
    if (has(programFilter.date_filter, d)) {
        for (var i = 0; i < programFilter.date_filter.length; i++) {
            if (d == programFilter.date_filter[i]) {
                programFilter.date_filter.splice(i, 1);
            }
        }
    } else {
        programFilter.date_filter.push(d);
    }
    if (programFilter.date_filter.length == 0) {
        programFilter.date_filter = [];
    }
	programFilter.getFilteredList();
}

function textTime(d) {
    var S = d.getHours() % 12;
    if (S == 0) {
        S = 12;
    }
    if (d.getMinutes() != 0) {
        S += ":" + d.getMinutes();
    }
    if (d.getHours() / 12 < 1) {
		if( S == 12 ){ return ""; }
        return S + "am";
    }
    return S + "pm";
}
function time2date(str) {
    if (str.indexOf("12") != -1 && str.indexOf(":12") == -1) {
        if (str.indexOf('a') != -1) {
            str = "11:59pm";
        } else {
            str = '0' + str.substring(2, str.length);
        }
    }
    var date = new Date();
    if (str.indexOf(':') != -1) {
        date.setHours(str.substring(0, str.indexOf(':')));
        date.setMinutes(str.substring(str.indexOf(':') + 1, str.indexOf(':') + 3));
    }
    else {
        date.setHours(str.substring(0, str.indexOf('m') - 1));
        date.setMinutes(0);
    }
    if (str.indexOf('p') != -1) {
        date.setHours(date.getHours() + 12);
	}
    return date;
}
function getDatefrom(str) {
    if (str == null) {
        return null;
    }
    var date = new Date();
    try {
		var year, month, day, hour, minute;
        //date.setYear(str.substring(0, 4));
		year = str.substring(0, 4);
        str = str.substring(str.indexOf('-') + 1, str.length);
        //date.setMonth(str.substring(0, 2) - 1);
		month = str.substring(0, 2);
        str = str.substring(str.indexOf('-') + 1, str.length);
        //date.setDate(str.substring(0, 2));
		day = str.substring(0, 2);
        str = str.substring(str.indexOf('T') + 1, str.length);
        //date.setHours(str.substring(0, 2));
		hour = str.substring(0, 2);
        str = str.substring(str.indexOf(':') + 1, str.length);
        //date.setMinutes(str.substring(0, 2));
		minute = str.substring(0, 2);
		date.setMinutes(minute);
		date.setHours(hour);
		date.setDate(day);//must do date before month or will carry over on 31st's  changed by daniel on "May 31 '10" (really June 1)
		date.setMonth(month - 1);
		date.setYear(year);

		/* go again, for the second round
		 * changed by Tatyana on Nov. 4, 2010,
		 * as per Daniel's suggestion */
		date.setMinutes(minute);
		date.setHours(hour);
		date.setDate(day);//must do date before month or will carry over on 31st's  changed by daniel on "May 31 '10" (really June 1)
		date.setMonth(month - 1);
		date.setYear(year);
    } catch(e) {
        alert(e + " on converting " + str);
    }
    return date;
}
function has(A, v) {
    for (var i = 0; i < A.length; i++) {
        if (A[i] == v) {
            return true;
        }
    }
    return false;
}
function toggleDay(d) {
    if (has(programs.day_filter, d)) {
        for (var i = 0; i < programs.day_filter.length; i++) {
            if (d == programs.day_filter[i]) {
                programs.day_filter.splice(i, 1);
            }
        }
    } else {
        programs.day_filter.push(d);
    }
    if (programs.day_filter.length == 0) {
        programs.day_filter = [];
    }
	programs.getFilteredList();
    var code = programs.getCode();
    putIntoCalendar(code);
}
function dragHandleMouseUp(evt) {}
function scrollButton(y, divName) {
    var div = document.getElementById(divName);
    div.scrollTop += y;
    div.onDrag();
}
function wheel(event) {
    if (!isScrolling) {
        return;
    }
    var delta = 0;
    if (!event)
    event = window.event;
    if (event.wheelDelta) {
        /* IE/Opera. */
        delta = event.wheelDelta / 120;
        if (window.opera) delta = -delta;
    } else if (event.detail) {
        delta = -event.detail / 3;
    }
    if (delta) if (delta < 0) {
        scrollButton(20);
    }
    else {
        scrollButton(-20);
    }
    if (event.preventDefault) event.preventDefault();
    event.returnValue = false;
}
function fixE(e) {
    if (typeof e == 'undefined') e = window.event;
    if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
    if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
    if (typeof e.pageX == 'undefined') e.pageX = window.pageXOffset + e.clientX;
    if (typeof e.pageY == 'undefined') e.pageY = window.pageYOffset + e.clientY;

    return e;
}
function checkForCrumbs(div, ID) {
    if (div.id.indexOf(ID) != -1) {
        return 1;
    }
    var iter;
    for (var i = 0; i < div.childNodes.length; i++) {
        iter = checkForCrumbs(div.childNodes[i], ID);
        if (iter == 1) {
            return aText(div.childNodes[i]);
        } else if (iter != -1) {
            return aText(div.childNodes[i]) + iter;
        }
    }
    return -1;
}

function aText(div) {
    for (var i = 0; i < div.childNodes.length; i++) {
        if (div.childNodes[i].tagName.toLowerCase() == "a") {
            return div.childNodes[i].innerHTML;
        }
    }
    return "error on " + div.id;
}
function startScrolling() {
    if (window.addEventListener) {
        window.addEventListener('DOMMouseScroll', wheel, false);
    }
    window.onmousewheel = document.onmousewheel = wheel;
    window.onkeydown = document.onkeydown = window.onkeypress = document.onkeypress = function (evt) {
        if (!isScrolling) {
            return;
        }
        evt = fixE(evt);
        if (evt.keyCode == 38) {
            scrollButton(-24);
        } else if (evt.keyCode == 40) {
            scrollButton(24);
        } else if (evt.keyCode == 32) {
            scrollButton(100);
        } else if ((evt.keyCode == 189 || evt.keyCode == 187)) {
            scroller.recalc();
        }
    }
    window.onkeyup = document.onkeyup = function (evt) {
        int = window.clearInterval(int)
    };
}
function stopScrolling() {
    if (window.addEventListener) {
        window.removeEventListener('DOMMouseScroll', wheel, false);
    }
    window.onmousewheel = document.onmousewheel = function () {};
    window.onkeydown = document.onkeydown = function () {};
    window.onkeyup = document.onkeyup = function () {};
}
function toggleVisibility(div_name, btn) {
    var div = document.getElementById(div_name);
    if (div.style.visibility != "visible") {
        div.style.visibility = "visible";
        MM_swapImage(btn.id, '', 'images/buttons/select_open.jpg', 1);
    } else {
        div.style.visibility = "hidden";
        MM_swapImage(btn.id, '', 'images/buttons/select_btn.jpg', 1);
    }
}
function hideDivs() {
    var a = hideDivs.arguments;
    for (var i = 0; i < a.length; i++) {
        document.getElementById(a[i]).style.visibility = "hidden";
    }
}
function SiteSearchC() {
    document.getElementById("search_results").innerHTML = "<img src='images/JCC_preloader4.gif' width='150' height='228' style='position:absolute; left:170px;'/>";
    var div = document.getElementById("cat_search_results");
    var srch = document.getElementById("SearchTerms");
    document.getElementById("search_results_header").className = "openedSearch";
    document.getElementById("show_search").style.visibility = "hidden";
    FlipSearch('p');
    loadXML("search-cat.php?search=" + srch.value, categorySearchMaker);
    selectSearch();
    doFadeOut("content_placer", "program_catList_placer", "left_border", "right_border", "lt_border", "rt_border", "bottom_border", "BreadCrumb_placer", "callist_placer", "scrollArea", "scrollUp", "scrollDown", "callist_headers", "calendar_placer");

    var p_btn = document.getElementById("search_programs_btn");
    var c_btn = document.getElementById("search_overview_btn");
    MM_swapImage(c_btn.id, '', 'images/buttons/overview_btn.png', 1);
    MM_swapImage(p_btn.id, '', 'images/buttons/programs_on.png', 1);
    c_btn.parentNode.store = 'P';
}
function SiteSearchP() {
    var div = document.getElementById("search_results");
    var srch = document.getElementById("SearchTerms");
    div.style.zIndex = "13";
    div.onDrag = setScrollBar;
    document.getElementById("cat_search_results").onDrag = setScrollBar;
    loadXML("search-prog.php?search=" + srch.value, programSearchMaker);
}
function FlipSearch(to) {
	//test code
	/*var dd = new Date();
	document.getElementById("SearchTerms").value = dd.getSeconds() + " : " + dd.getMilliseconds();*/
	//var c = document.getElementById("cat_search_results");
    var p = document.getElementById("search_results");
    var s = document.getElementById("searchScroller");
   /* if (! (p.style.zIndex < c.style.zIndex) && to != 'p') {
        try {
            p.style.zIndex = 13;
            c.style.zIndex = 14;
            s.target = c;
            s.target.onDrag = setScrollBar;
            s.target.target = s;
            s.onDrag = searchScroll;
            s.recalc();
        } catch(e) {
        }
    } else {*/
        p.style.zIndex = 14;
        //c.style.zIndex = 13;
        s.target = p;
        s.target.onDrag = setScrollBar;
        s.target.target = s;
        s.onDrag = searchScroll;
        s.recalc();
   // }
}
function selectProgram() {
    var s = document.getElementById("search_results_header");
    var p = document.getElementById("program_container");
    s.style.zIndex = 3;
    p.style.zIndex = 5;
    s.style.filter = "alpha( 90 )";
    p.style.filter = "alpha( 100 )";
}
function selectSearch() {
    var s = document.getElementById("search_results_header");
    s.style.zIndex = 5;
    s.style.filter = "alpha( 100 )";
}
function programFilter() {
    document.getElementById("calendar").innerHTML = programs.getFilteredList().getCode();
    scroller.recalc();
}
function unMarkProgramCategory() {
    var children = document.getElementById("program_catList_div").childNodes;
    for (var i = 0; i < children.length; i++) {
        if (children[i].className == "program_cat_pick") {
            children[i].className = "prog_cat_btn";
            children[i].onmouseout = function () {
                this.className = "prog_cat_btn";
            };
            children[i].onmouseover = function () {
                this.className = "program_cat_pick";
            };
        }
    }
    scroller.recalc();
}
function unMarkProgramSeason() {
    var children = document.getElementById("program_catList_div").childNodes;
    for (var i = 0; i < children.length; i++) {
        if (children[i].className == "program_term_pick") {
            children[i].className = "prog_term_btn";
            children[i].onmouseout = function () {
                this.className = "prog_term_btn";
            };
            children[i].onmouseover = function () {
                this.className = "program_term_pick";
            };
        }
    }
    scroller.recalc();
}
function doFadeOut() {
    document.getElementById("transer").style.width = "954px";
    document.getElementById("transer").style.height = "600px";
	if( document.getElementById("content_div") != null ){
		document.getElementById("transer").style.height = document.getElementById("content_div").offsetHeight + 50 + "px";
	}
}
function doFadeIn() {
    document.getElementById("transer").style.width = "1px";
    document.getElementById("transer").style.height = "1px";
}
function totalOffsetTop(div) {
    if (div.parentNode != null && div.parentNode != document.body && div.parentNode.offsetTop != null) {
        return div.offsetTop + totalOffsetTop(div.parentNode);
    } else {
        return div.offsetTop;
    }
}
function isFiltered(){
	return !(
		programs.name_filter == "" &&
		( programs.date_filter == [] || programs.date_filter == "" ) &&
		programs.stime_filter == null &&
		programs.etime_filter == null &&
		programs.sage_filter == null &&
		programs.eage_filter == null &&
		( programs.day_filter == [] || programs.day_filter == "" ) &&
		programs.category_filter == "" &&
		programs.season_filter == "" &&
		( programs.recurrence_filter == [] || programs.recurrence_filter == "" )
	);
}
function ClearAllFilters() {
    programs.name_filter = "";
    programs.date_filter = [];
    programs.stime_filter = null;
    programs.etime_filter = null;
    programs.sage_filter = null;
    programs.eage_filter = null;
    programs.day_filter = [];
    programs.category_filter = "";
    programs.season_filter = "";
    programs.recurrence_filter = [];

    //programFilter();
	putIntoCalendar(programs.getCode());

    var div = document.getElementById("age_th");
    div.style.top = "24px";
    div = document.getElementById("time_th");
    div.style.top = "24px";


    div = document.getElementById("age_bh");
    div.style.top = "135px";
    div = document.getElementById("time_bh");
    div.style.top = "135px";


    div = document.getElementById("ttop_div");
    div.style.height = "1px";
    div = document.getElementById("atop_div");
    div.style.height = "1px";


    div = document.getElementById("tmiddle_div");
    div.style.height = "104px";
    div = document.getElementById("amiddle_div");
    div.style.height = "104px";
	
    document.getElementById("category_select").selectedIndex = 0;
    document.getElementById("season_select").selectedIndex = 0;
    document.getElementById("schedule_select").selectedIndex = 0;

	var day_on_link = $(".day_on_link");
	day_on_link.filter( function(){ this.className = "day_off_link"; return true; } );
	var date_on_link = $(".date_on_link");
	date_on_link.filter( function(){ this.className = "date_off_link"; return true; } );
	
    document.getElementById("cal_tbl").innerHTML = printCal();
	markCurrentDate();
	
    document.getElementById("cal_search_txt").onfocus = function () {
        this.value = "";
        this.onfocus = function () {};
    };
	
    document.getElementById("atop_value").innerHTML = A.values[0];
    document.getElementById("abottom_value").innerHTML = A.values[A.values.length - 1];
    A.valid = [0, A.values.length - 1];
	
    document.getElementById("ttop_value").innerHTML = T.values[0];
    document.getElementById("tbottom_value").innerHTML = T.values[T.values.length - 1];
    T.valid = [0, T.values.length - 1];
}
function placeSearch() {
    var sd = document.getElementById("search_div");
    var sizer = document.getElementById("size_reference");
    var top = document.body.scrollTop;
    var height = sizer.offsetHeight;
    var left = document.body.scrollLeft;
    var width = sizer.offsetWidth;
    try {
        sd.style.top = ((height - -top) - sd.offsetHeight) + "px";
        sd.style.left = ((width - -left) - sd.offsetWidth) + "px";
    } catch(e) {
        alert("placeSearch: " + e.toSource());
    }
}
function scrollFor(scroller, div) {
    if (div.scrollHeight <= div.offsetHeight) {
        scroller.style.visibility = "hidden";
        return;
    }
    scroller.style.visibility = "inherit";
    scroller.target = div;
    scroller.onDrag = function (A, B, C, D) {
        this.target.scrollTop = (this.offsetTop - this.minY) * (this.target.scrollHeight - this.target.offsetHeight) / (this.maxY - this.minY);
    }
    div.target = scroller;
    div.onDrag = function (A, B, C, D) {
        this.target.y = this.target.minY + this.scrollTop * this.target.maxY / (this.scrollHeight - this.offsetHeight);
        this.target.y = this.target.lastY = within(this.target.y, this.target.minY, this.target.maxY);
        this.target.style.top = this.target.y + "px";
    }
}
function MenuSlide() {
    var div = document.getElementById("Menu_div");
    if (menu_out) {
        transX = new XTransformation(div, -div.offsetWidth, 0, 20, 1.6, 80, 20);
    } else {
        transX = new XTransformation(div, 20, 0, 20, 1.6, 80, 20);
    }
    menu_out = !menu_out;
}
function AccountSlide() {
    var div = document.getElementById("Account_div");
    if (account_out) {
        transX = new XTransformation(div, -div.offsetWidth, 0, 20, 1.6, 80, 20, "x");
    } else {
        transX = new XTransformation(div, 23, 0, 20, 1.6, 80, 20, "x");
    }
    account_out = !account_out;
}
function onLogin(txt) {
    document.getElementById("Account_btn").innerHTML = txt;
}
function openImage(div) {
    div.className = "item_open";
    document.getElementById("spacer").style.height = "1px";
    var cN = div.childNodes;
    for (var i = 0; i < cN.length; i++) {
        if (cN[i].tagName == "DIV") {
            cN = cN[i].childNodes;
            break;
        }
    }
    for (var i = 0; i < cN.length; i++) {
        if (cN[i].tagName == "DIV") {
            if (cN[i].y != null) {
                cN[i].style.top = cN[i].y + "px";
            } else {
                cN[i].style.top = "0px";
                cN[i].y = 0;
            }
            break;
        }
    }
}
function closeImage(div) {
    document.getElementById("spacer").style.height = "215px";
    var cN = div.childNodes;
    for (var i = 0; i < cN.length; i++) {
        if (cN[i].tagName == "DIV") {
            cN = cN[i].childNodes;
            break;
        }
    }
    for (var i = 0; i < cN.length; i++) {
        if (cN[i].tagName == "DIV") {
            cN[i].style.top = "0px";
            div.className = "item_closed";
            break;
        }
    }
}
function scrollItem(div, dY) {
    if (div.className == "item_closed") {
        return true;
    }
    var cN = div.childNodes;
    for (var i = 0; i < cN.length; i++) {
        if (cN[i].tagName == "DIV") {
            var H = cN[i].offsetHeight;
            cN = cN[i].childNodes;
            break;
        }
    }
    for (var i = 0; i < cN.length; i++) {
        if (cN[i].tagName == "DIV") {
            cN[i].y = cN[i].y - dY;
            cN[i].y = within(cN[i].y, Math.min(H - cN[i].offsetHeight, 0), 0);
            cN[i].style.top = cN[i].y + "px";
            break;
        }
    }
    return true;
}
function scrollItemAction(scroll_btn, dY) {
    scroll_btn.dY = dY;
    if (scrollItem(scroll_btn.parentNode, dY)) {
        var self = scroll_btn;
        scroll_btn.int = setInterval(function () {
            scrollItem(self.parentNode, self.dY);
        },
        15);
    }
}
function resetChildClass(div, className, nodeName) {
    var cN = div.childNodes;
    for (var i = 0; i < cN.length; i++) {
        if (cN[i].nodeName != "#text" && (nodeName == null || cN[i].nodeName.toLowerCase() == nodeName.toLowerCase())) {
            cN[i].className = className;
        }
    }
}
function ActiveSiteSearch() {
    var results = document.getElementById("search_results");
    var value = document.getElementById("SearchTerms").value;
    if (value == "") {
        return;
    }
    if (value.toLowerCase().indexOf("fuck") != -1) {
        document.getElementById("search_results").innerHTML = "Hey! No more of that!";
        return;
    }
	results.innerHTML = "";
	//added by daniel 7/12/10 to keep track of search terms
	if( document.getElementById( "search_frame" ).src.indexOf( "searchterms.php?q=" + value.toLowerCase() ) == -1 && document.getElementById( "search_frame" ).src.indexOf( "searchterms.php?q=" + escape( value.toLowerCase() ) ) == -1 ){
		document.getElementById( "search_frame" ).src = "searchterms.php?q=" + value.toLowerCase();
	}
	
	if( value.toLowerCase() == "camp" || value.toLowerCase() == "camps" ){
		for (var i = 0; i < categoryIndex.length; i++) {
			if ( categoryIndex[i].getAttribute("T").toLowerCase() == "camps" ) {
				writeSearchCat( categoryIndex[i] , value );
				break;
			}		
		}
	}
	if( value.toLowerCase() == "babysitting" || value.toLowerCase() == "baby sitting" ){
		for (var i = 0; i < categoryIndex.length; i++) {
			if ( categoryIndex[i].getAttribute("T").toLowerCase() == "camps" ) {
				//writeSearchCat( categoryIndex[i] , value );
				//break;
				results.innerHTML = "<ul><li><a href='category.aspx?catid=2632#/nil_09'>babysitting hours</a></li></ul>";
			}		
		}
	}
	if( value.toLowerCase().indexOf( "evening" ) >= 0 || value.toLowerCase().indexOf( "evenning" ) >= 0 || value.toLowerCase().indexOf( "stars" ) >= 0 ){
		results.innerHTML = "<ul><li><a href='evening_under_the_stars.html'>evening under the stars</a></li></ul>";
	}
	if( value.toLowerCase() == "podcast" || value.toLowerCase() == "pod cast" ){
		results.innerHTML = "<ul><li><a href='http://www.jccdigital.org/podcast/' target='_blank' style='color:#4040ff;'>JCC Conversations <b>Podcast</b> Playlist - The JCC in Manhattan</a></li></ul>";
	}
	if( value.toLowerCase().indexOf( "calendar" ) != -1 ){
		results.innerHTML += "<ul><li><a href='full-list.aspx' style='color:#4040ff;'>The JCC in Manhattan - Calendar | All Programs</a></li></ul>";
	}
	
	$( $pdfs ).filter( function(){ 
	if(this.innerHTML)
		return ( this.innerHTML.toLowerCase().indexOf( value.toLowerCase() ) != -1 || this.title.toLowerCase().indexOf( value.toLowerCase() ) != -1 );
	} ).each( function(){
		results.innerHTML = "<ul><li><a href='" + this.href + "' style='color:#4040ff;' target='_blank'>" + this.title + "(PDF)</a></li></ul>";
	});
	
	results.innerHTML += "<div style='padding:10px; font-weight:bold;'><span id='prog_num'></span> results in specific programs for &quot;" + value + "&quot;</div>";
	var cCode = "";
	var progs = [], start, end, count = 0, classMod = '', hasThis, used = [];
    count = 0;
        /*for (var i = 0; i < categoryIndex.length; i++) {
			has = searchBits(categoryIndex[i], value);
            if ( has ) {
				count = 0;
				writeSearchCat( categoryIndex[i] , value );
				
				progs = categoryIndex[i].childNodes;
				for (var j = 0; j < progs.length; j++) {
					if ( progs[ j ].tagName == "P" && searchBits( progs[j], value ) ) {
						count++;
						writeSearchProg( progs[j] , value , categoryIndex[i].getAttribute("CID") );
					}
				}
            }
        }*/
	
	
	for (var i = 0; i < programIndex.length; i++) {
		if ( !isCrossListed( programIndex[i] ) && searchTits( programIndex[i], value ) && !has( used , programIndex[i].getAttribute("SID") ) ) {
			used.push( programIndex[i].getAttribute("SID") );
			writeSearchProg( programIndex[i] , value , programIndex[i].parentNode.getAttribute("CID") );
		}
	}
	for (var i = 0; i < programIndex.length; i++) {
		if ( !isCrossListed( programIndex[i] ) && searchBits( programIndex[i], value , false ) && !has( used , programIndex[i].getAttribute("SID") ) ) {
			used.push( programIndex[i].getAttribute("SID") );
			writeSearchProg( programIndex[i] , value , programIndex[i].parentNode.getAttribute("CID") );
		}
	}
	for (var i = 0; i < programIndex.length; i++) {
		if ( !isCrossListed( programIndex[i] ) && searchBits( programIndex[i], value , true ) && !has( used , programIndex[i].getAttribute("SID") ) ) {
			used.push( programIndex[i].getAttribute("SID") );
			writeSearchProg( programIndex[i] , value , programIndex[i].parentNode.getAttribute("CID") );
		}
	}
	document.getElementById( "prog_num" ).innerHTML = used.length;
	used = [];
	results.innerHTML += "<div style='padding:10px; font-weight:bold;'><br /><br /><span id='cat_num'></span> results in general categories for &quot;" + value + "&quot;</div>";
	for (var i = 0; i < categoryIndex.length; i++) {
		hasThis = searchTits(categoryIndex[i], value) && categoryIndex[i].getAttribute("CID") != 2975;
        if ( hasThis ) {
			used.push( categoryIndex[i].getAttribute("CID") );
			count = 0;
			writeSearchCat( categoryIndex[i] , value );
		}
	}
	for (var i = 0; i < categoryIndex.length; i++) {
		hasThis = searchBits(categoryIndex[i], value, false) && categoryIndex[i].getAttribute("CID") != 2975;
        if ( hasThis && !has( used , categoryIndex[i].getAttribute("CID") ) ) {
			used.push( categoryIndex[i].getAttribute("CID") );
			count = 0;
			writeSearchCat( categoryIndex[i] , value );
		}
	}
	for (var i = 0; i < categoryIndex.length; i++) {
		hasThis = searchBits(categoryIndex[i], value, true) && categoryIndex[i].getAttribute("CID") != 2975;
        if ( hasThis && !has( used , categoryIndex[i].getAttribute("CID") ) ) {
			used.push( categoryIndex[i].getAttribute("CID") );
			count = 0;
			writeSearchCat( categoryIndex[i] , value );
		}		
	}
	document.getElementById( "cat_num" ).innerHTML = used.length;
	
	used = [];
	results.innerHTML += "<div style='padding:10px; font-weight:bold;'><br /><br /><span id='ss_num'></span> results in series sales for &quot;" + value + "&quot;</div>";
	for (var i = 0; i < seriesSaleIndex.length; i++) {
		hasThis = searchTits(seriesSaleIndex[i], value);
        if ( hasThis ) {
			used.push( seriesSaleIndex[i].getAttribute("PID") );
			count = 0;
			writeSearchSeries( seriesSaleIndex[i] , value , seriesSaleIndex[i].parentNode.parentNode.getAttribute("CID") );
		}
	}
	for (var i = 0; i < seriesSaleIndex.length; i++) {
		hasThis = searchBits(seriesSaleIndex[i], value, false);
        if ( hasThis && !has( used , seriesSaleIndex[i].getAttribute("PID") ) ) {
			used.push( seriesSaleIndex[i].getAttribute("PID") );
			count = 0;
			writeSearchSeries( seriesSaleIndex[i] , value , seriesSaleIndex[i].parentNode.parentNode.getAttribute("CID") );
		}
	}
	for (var i = 0; i < seriesSaleIndex.length; i++) {
		hasThis = searchBits(seriesSaleIndex[i], value, true);
        if ( hasThis && !has( used , seriesSaleIndex[i].getAttribute("PID") ) ) {
			used.push( seriesSaleIndex[i].getAttribute("PID") );
			count = 0;
			writeSearchSeries( seriesSaleIndex[i] , value , seriesSaleIndex[i].parentNode.parentNode.getAttribute("CID") );
		}		
	}
	document.getElementById( "ss_num" ).innerHTML = used.length;// + " / " + seriesSaleIndex.length;
	
    showSearch();
    selectSearch();
    FlipSearch('p');
}
function isCrossListed( prog ){
	return ( getText(prog.getElementsByTagName("CP")[0]).indexOf( prog.parentNode.getAttribute("T") ) == -1 );
}
function writeSearchProg( prog , value , catid ){
	var linkToCategory = getCatHREFfromID( catid );
	var start = getDatefrom(getText(prog.getElementsByTagName("S")[0]));
	try{end = getDatefrom(getText(prog.getElementsByTagName("E")[0]));}catch(e){}
	var newDiv = document.createElement("div");
						newDiv.className = 'item_over';
						var pCode = "";
						pCode = "<table class='item_row'><tr>";
						pCode += "<td class='search_name' ><a href='javascript:var NW = window.open(\"cat-content.aspx?catid=" + catid + "&progID=" + prog.getAttribute("PID") + "\", \"\" , \"scrollbars=yes, resizable=yes, width=560, height=650\" );' onclick='javascript:urchinTracker(\"/search/" + value + "/prog/" + getText(prog.getElementsByTagName("R")[0] ) +"\");' class='prog_info_btn'>" + getText(prog.getElementsByTagName("PT")[0]);
						if( getText(prog.getElementsByTagName("PT")[0]) != getText(prog.getElementsByTagName("T")[0]) ){ 
							pCode += "<br><i>" + getText(prog.getElementsByTagName("T")[0] ) + "</i>";
						} 
						pCode += "</a></td>";
						pCode += "<td class='search_date'>"; 
						var rec = getText( prog.getElementsByTagName("RT")[0] );
						if( getText(prog.getElementsByTagName("TX")[0]) == "" ){
							pCode += textDay(start.getDay()) + ", " + textMonth(start.getMonth()) + " " + start.getDate();
							if (rec != "S" && end != null) {
								pCode += " - " + textMonth(end.getMonth()) + " " + end.getDate();
							}
						} else {
							pCode += constrain( getText(prog.getElementsByTagName("TX")[0]) , 20 );
						}
						pCode += "</td>";
						pCode += "<td class='search_time'>" + textTime(start);
						pCode += "</td>";
						//End Time
						//pCode += "<td class='search_age'>" + getText(prog.getElementsByTagName("AL")[0]) + " - " + getText(prog.getElementsByTagName("AH")[0]) + "</td>";
						if (rec == "S") {
							rec = "once";
						}
						if (rec == "W") {
							rec = "weekly";
						}
						if (rec == "D") {
							rec = "daily";
						}
						if (rec == "M") {
							rec = "monthly";
						}
						if (rec == "C" || rec == "T") {
							rec = "see details";
						}
						pCode += "<td class='search_rec'> " + rec + "</td>";
						pCode += "</tr></table>";
						
						//Description
						pCode += "<div class='item_out' >";
						var txt =formatForSearch( getText(prog.getElementsByTagName("D")[0] ) , value.split( " " ) );
						pCode += txt;
						if( txt.indexOf( '...' ) > 90 ){
							pCode += "(<a href='javascript:var NW = window.open(\"cat-content.aspx?catID=" + catid + "&progID=" + prog.getAttribute("PID") + "\",\"\",\"scrollbars=yes,resizable=yes,width=560,height=650\");' onclick='javascript:urchinTracker(\"/search/" + value + "/prog/" + getText(prog.getElementsByTagName("R")[0] ) +"\");' class='prog_info_btn'>read more</a>)";
						}
						pCode += "<br />";
						if( prog.getElementsByTagName("INSTR")[0] != null ){
							pCode += "<div style='height:11px; margin-top:20px;'>instructor: <a href='instructors.aspx?ID=" + prog.getElementsByTagName("INSTR")[0].getAttribute("IID") + "'>" + prog.getElementsByTagName("INSTR")[0].getAttribute("FN") + " " + prog.getElementsByTagName("INSTR")[0].getAttribute("LN") + "</a>";
							pCode += "</div>";
						}
						
						var catParse = prog.parentNode;
						var catName = catParse.getAttribute("T");
						while( catParse.parentNode.tagName == "C" ){ 
							catName = catParse.parentNode.getAttribute("T") + " &gt; " + catName; 
							catParse = catParse.parentNode;
						}
						
						pCode += "<div style='font-style:italic; height:21px; margin-top:20px;'><a href='" + linkToCategory + "' onclick='javascript:urchinTracker(\"/search/" + value + "/progBreadCrumb/" + catid + "-" + prog.getAttribute("PID") +"\");'>" + catName + "</a>";
						pCode += "</div>";
						
						pCode += "<a href='javascript:var NW = window.open(\"cat-content.aspx?catid=" + catid + "&progID=" + prog.getAttribute("PID") + "\", \"\" , \"scrollbars=yes, resizable=yes, width=560, height=650\" );' onclick='javascript:urchinTracker(\"/search/" + value + "/prog/" + getText(prog.getElementsByTagName("R")[0] ) +"\");' class='prog_info_btn' style='padding:15px;'><img src='images/buttons/view_prog.png' border='0' /></a>";
						pCode += "</div>";
						//pCode += "</div>";
						newDiv.innerHTML = pCode;
						document.getElementById("search_results").appendChild(newDiv);
}


function writeSearchSeries( prog , value , catid ){
	var linkTo = getCatHREFfromID( catid );
	var newDiv = document.createElement("div");
						newDiv.className = 'item_over';
						var pCode = "<table class='item_row'><tr>";
						pCode += "<td class='search_name' >" + getText(prog.getElementsByTagName("T")[0]);
						pCode += "</td>";
						pCode += "</tr></table>";
						//Description
						pCode += "<div class='item_out' >";
						var txt =formatForSearch( getText(prog.getElementsByTagName("D")[0] ) , value.split( " " ) );
						pCode += txt;
						if( txt.indexOf( '...' ) > 90 ){
							pCode += "(<a href='javascript:var NW = window.open(\"series-sales.aspx?catID=" + catid + "&progID=" + prog.getAttribute("PID") + "\",\"\",\"scrollbars=yes,resizable=yes,width=560,height=650\");' onclick='javascript:urchinTracker(\"/search/" + value + "/series/" + catid + "-" + prog.getAttribute("PID") +"\");' class='prog_info_btn'>read more</a>)";
						}
						pCode += "<br />";
						
						var catParse = prog.parentNode.parentNode;
						var catName = catParse.getAttribute("T");
						while( catParse.parentNode.tagName == "C" ){ 
							catName = catParse.parentNode.getAttribute("T") + " &gt; " + catName; 
							catParse = catParse.parentNode;
						}
						
						pCode += "<div style='font-style:italic; height:21px; margin-top:20px;'><a href='category.aspx?catid=" + catid + "'>" + catName + "</a>";
						pCode += "</div>";
						
						pCode += "<a href='javascript:var NW = window.open(\"series-sales.aspx?catid=" + catid + "&progID=" + prog.getAttribute("PID") + "\", \"\" , \"scrollbars=yes, resizable=yes, width=560, height=650\" );' onclick='javascript:urchinTracker(\"/search/" + value + "/series/" + catid + "-" + prog.getAttribute("PID") +"\");' class='prog_info_btn' style='padding:15px;'><img src='images/buttons/view_prog.png' border='0' /></a>";
						
						pCode += "</div>";
						//pCode += "</div>";
						newDiv.innerHTML = pCode;
						document.getElementById("search_results").appendChild(newDiv);
}
function writeSearchCat( cat , value ){
	var linkTo = getCatHREFfromID( cat.getAttribute("CID") );
	var newDiv = document.createElement("div");
				newDiv.className = "jccheader";
				newDiv.style.borderBottom = "2px #cccccc solid";
				newDiv.innerHTML = "<a href='" + linkTo + "' onclick='javascript:urchinTracker(\"/search/" + value + "/cat/" + cat.getAttribute("T").replace(/&/gi, "and") +"\");' >" + cat.getAttribute("T") + "&nbsp;&nbsp;&nbsp;</a>";
                document.getElementById("search_results").appendChild(newDiv);
				
				var newDiv = document.createElement("p");
				newDiv.style.paddingLeft = "20px";
				newDiv.style.paddingRight = "20px";
				
				//if applicable add the parent Name in the breadcrumbs - daniel 7/13/10
				var catName = cat.getAttribute("T"), catParse = cat;
				while( catParse.parentNode.tagName == "C" ){ 
					catName = catParse.parentNode.getAttribute("T") + " &gt; " + catName; 
					catParse = catParse.parentNode;
				}
				
				newDiv.innerHTML = formatForSearch( stripTags( getText(cat.getElementsByTagName("D")[0] ) ) , value.split( " " ) ) + "<br /><br /><a href='" + linkTo + "' style='font-style:italic;' onclick='javascript:urchinTracker(\"/search/" + value + "/cat/" + cat.getAttribute("T").replace(/&/gi, "and") +"\");'>" + catName + "</a><br /><br />";
                document.getElementById("search_results").appendChild(newDiv);
}
function searchBits(Node, str, doSplit) {
    if( doSplit ){ var strs = str.toLowerCase().split(" "); }
	else{var strs = [ str ]; }
	var searchString = "";
	if( Node.tagName == "C" ){
		searchString += Node.getAttribute("T") + " " + Node.getAttribute("CID");
		if( Node.getElementsByTagName("D")[0] != null ){
			searchString += " " + getText(Node.getElementsByTagName("D")[0]);
		}
		if( Node.getElementsByTagName("K")[0] != null ){
			searchString += " " + getText(Node.getElementsByTagName("K")[0]);
		}
		/*var progs = Node.getElementsByTagName("P");
		for (var i = 0; i < progs.length; i++) {
			searchString += " " + progs[ i ].getAttribute("PID") + " " + getText(progs[i]);
		}*/
		searchString  = searchString.toLowerCase();
		for (var i = 0; i < strs.length; i++) {
			if (searchString.indexOf(strs[i]) == -1) {
				return false;
			}
		}
	} else if( Node.tagName == "P" ){
		var instructors = "";
		for( var i = 0; i<Node.getElementsByTagName("INSTR").length; i++ ){
			instructors += Node.getElementsByTagName("INSTR")[ i ].getAttribute("FN") + " " + Node.getElementsByTagName("INSTR")[ i ].getAttribute("LN") + " " + Node.getElementsByTagName("INSTR")[ i ].getAttribute("IID") + " ";
		}
		searchString += getText( Node ) + " " + Node.getAttribute("PID") + instructors;
		searchString  = searchString.toLowerCase();
		for (var i = 0; i < strs.length; i++) {
			if (searchString.indexOf(strs[i]) == -1) {
				return false;
			}
		}
	} else if( Node.tagName == "SSO" ){
		searchString += getText( Node ) + " " + Node.getAttribute("PID");
		searchString  = searchString.toLowerCase();
		for (var i = 0; i < strs.length; i++) {
			if (searchString.indexOf(strs[i]) == -1) {
				return false;
			}
		}
	}
	return formatForSearch( searchString , strs );
}
function searchTits(Node, str) {
    var strs = str.toLowerCase().split(" ");
	//else{var strs = [ str ]; }
	var searchString = "";
	if( Node.tagName == "C" ){
		searchString += Node.getAttribute("T") + " " + Node.getAttribute("CID");
		
		searchString  = searchString.toLowerCase();
		for (var i = 0; i < strs.length; i++) {
			if (searchString.indexOf(strs[i]) == -1) {
				return false;
			}
		}
	} else if( Node.tagName == "P" ){
		searchString += getText( Node.getElementsByTagName("PT")[0] ) + " " + getText( Node.getElementsByTagName("T")[0] );
		searchString  = searchString.toLowerCase();
		for (var i = 0; i < strs.length; i++) {
			if (searchString.indexOf(strs[i]) == -1) {
				return false;
			}
		}
	} else if( Node.tagName == "SSO" ){
		searchString += getText( Node.getElementsByTagName("T")[0] );
		searchString  = searchString.toLowerCase();
		for (var i = 0; i < strs.length; i++) {
			if (searchString.indexOf(strs[i]) == -1) {
				return false;
			}
		}
	}
	return formatForSearch( searchString , strs );
}
function getCategory( ID ){
    for (var i = 0; i < categoryIndex.length; i++) {
		if( categoryIndex[ i ].getAttribute( "CID" ) == ID ){
			return categoryIndex[ i ];
		}
	}
}
function hasProgs( cat ){
	if( $.type(cat) != "number" && $.type(cat) != "string" ){//cat.getElementsByTagName ){
		return $(cat).attr("progs") == "True"; 
	} else { 
		return hasProgs(getCategory( cat ));
	}
}
function hasInstructors( cat ){
	if( $.type(cat) != "number" && $.type(cat) != "string" ){
		return $(cat).attr("instr") == "True"; 
	} else { 
		return hasInstructors(getCategory( cat ));
	}
}
function buildInstructorList( cat ){
	/*var instructor_div = document.getElementById( "instructors_div" );
	var instructors = cat.getElementsByTagName("INSTR");
	//make list unique
	var uniques = [], uniqueIDs = [];
	for( var i = 0; i<instructors.length; i++ ){
		if( !has( uniqueIDs , instructors[ i ].getAttribute( "IID" ) ) ){
			uniques.push( instructors[ i ] );
			uniqueIDs.push( instructors[ i ].getAttribute( "IID" ) );
		}
	}
	
	var code = "<ul>";
	for( var i = 0; i < uniques.length; i++ ){
		code += "<li><a href='instructors.aspx?ID=" + uniques[ i ].getAttribute( "IID" ) + "'>" + uniques[ i ].getAttribute( "FN" ) + " " + uniques[ i ].getAttribute( "LN" ) + "</a></li>"; 
	}
	code += "</ul>";
	return code;*/
	var $dest = $("#instructors" + cat);
	if( $dest.attr("rel") != current_category ){
		$dest.html('<div align="center"><img src="images/loader.gif" /></div>');
		urchinTracker("rightnav/instructors/" + getCatHREFfromID( current_category ) );
		$.ajax({
			url: "instructors.py?catid=" + current_category,
			success: function(data) {
				$dest.html(data);
				$dest.attr("rel" , current_category );
			}
		});
	}
}

function showHideInstructors(captainCat){
	var inWay = $("#content_div div").filter(function(){return $(this).offset().left > 780;});
	inWay.attr("class","inInstructorsWay");
	var vis = 'visible'; 
	var mo = $( "#instructors" + captainCat );
	if( mo.css("display") == "none" ){
		buildInstructorList(captainCat);
		$( "#instructors_toggle_" + captainCat ).css("background-image","url(http://dev.jccmanhattan.org/images/buttons/up.gif)");
		mo.css("display","block");
		inWay.css("display","none");
	}
	else{
		mo.css("display","none");
		$( "#instructors_toggle_" + captainCat ).css("background-image","url(http://dev.jccmanhattan.org/images/buttons/down.gif)");
		$(".inInstructorsWay").css("display","block");
	}
	var jGlideDiv = $("#jGlide_001");
	jGlideDiv.height(max(jGlideDiv[0].scrollHeight,500));
}

function getCaptainCat( ID ){
	var catItem = findMenuItem( ID );
	if( getLevel( catItem ) == 1 ){
		return ID;
	} else if( getLevel( catItem ) == 2 && catItem.childNodes[ 2 ] != null ){
		return ID;
	} else {
		return parentOf( ID );
	}	
}
function formatForSearch( searchString , strs ){
	searchString = stripTags( searchString );
	//while( searchString.indexOf( /\s{2}/g ) != -1 ){
		searchString = searchString.replace(/\s+/g, ' ');
	//}
	searchString = constrain( searchString , 100 );
	for (var i = 0; i < strs.length; i++) {
		searchString = searchString.replace( strs[ i ] , "<b>" + strs[ i ] + "</b>" );
	}
	return searchString;
}
function stripTags( str ){
	if( str == null ){ return ""; }
		//str = str.replace(/<script[^>]*?>[\s\S]*?<\/script>/gi, '');
		str = str.replace(/<script[^>]*?>[\s\S\r\n]*?<\/script>/gi, '');
	str = str.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = str.replace(/<\/?[^>]+(>|$)/g, " ");
 		return strTagStrippedText;
}
function constrain(str, n) {
    if (str.length > n) {
        str = str.substring(0, n - 3) + " ...";
    }
    return str;
}
function getFaders(){
}

function selectInRight( obj ){
	clearSelectInRight();
	obj.className = ( obj.className == "jGM_more" ) ? "jGM_more rt_pick" : "rt_pick";
}
function clearSelectInRight(){
	 $(".rt_pick").filter( function(){ 
									 this.className = ( this.className == "jGM_more rt_pick" ) ? "jGM_more" : ""; 
									 return false;
									 } );	
}
//mainly for use with highlights
function hasSessions( progID ){
	var first = 0;
	for( var i = 0; i< programIndex.length; i++ ){
		if( programIndex[ i ].getAttribute( "PID" ) == progID ){
			if( first != 0 && first != programIndex[ i ].getAttribute( "SID" ) ){ 
				return true; 
			} else { 
				first = programIndex[ i ].getAttribute( "SID" ); 
			}
		}
	}
	return false;
}
//***********XML PARSING******************//
var xmlHttp, xmlHttp_c;
var calList = [];
var programs;
var catID = location.search.substring(location.search.indexOf("catid=") + 6, location.search.indexOf("catid=") + 10);
function loadXML(url, fun) {
	try{
		if( fun == getHighlightsM ){
			getAJAXhighlights(null,"red","red");
			return;
		} else if( fun == getHighlights ){
			getAJAXhighlights(null,null,null);
			return;
		}
	}catch(e){}
    //var xmlHttp = 
    GetXmlHttpObject();
    if (xmlHttp == null) {
        confirm("Your browser does not support AJAX!");
        return;
    }
    xmlHttp.onreadystatechange = fun;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function GetXmlHttpObject() {
    xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch(e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function siteSearchSetup() {
    if (xmlHttp.readyState == 4) {
        buildProgSiteSearch();
    }
}
var data;
function redirectTo() {
    if (xmlHttp.readyState == 4) {
		if( isProgramCode() ){
			goToProgram();
		} else {
			document.getElementById( "content_cutter" ).innerHTML = '<div class="jccheader">page not found</div><hr /><div class="mainAlignment" style="height: 150px;"><img src="/images/JCClogo.png" alt="logo" style="float: left; border: 0 none; margin-right: 15px; margin-bottom: 10px; margin-left: 15px; margin-top: 5px;" />Please <A href="/default.aspx">click here</A> to go back to our <a href="/">home page</a>.</div>';
	        buildProgSiteSearch();
		}
    }
}
function isProgramCode(){
	if( location.pathname.length != 11 ){
		return false;
	}
	return true;
}
function goToProgram() {
    data = xmlHttp.responseXML.documentElement;
    programIndex = data.getElementsByTagName("P");
    categoryIndex = data.getElementsByTagName("C");
    seriesSaleIndex = data.getElementsByTagName("SSO");
	var catid, progid;
	var progcode = location.pathname.substring( 1 , 11 ).toUpperCase();
    for (var i = 0; i < programIndex.length; i++) {
		if( progcode == getText(programIndex[i].getElementsByTagName("R")[0]) ){
			progid = programIndex[i].getAttribute('PID')
        	catid = programIndex[i].parentNode.getAttribute('CID');
			break;
		}
    }
	if( catid != null && progid != null ){
		loadXML( "viewprogram.aspx?catid=" + catid + "&progid=" + progid , openProgram );
	}
	else{
		document.getElementById( "content_cutter" ).innerHTML = '<div class="jccheader">page not found</div><hr /><div class="mainAlignment" style="height: 150px;"><img src="/images/JCClogo.png" alt="logo" style="float: left; border: 0 none; margin-right: 15px; margin-bottom: 10px; margin-left: 15px; margin-top: 5px;" />Please <A href="/default.aspx">click here</A> to go back to our <a href="/">home page</a>.</div>';
		buildProgSiteSearch(); 
	}
}
function buildProgSiteSearch() {
	//added by daniel 7/12/10 to keep track of search terms
	try{
	if( document.getElementById( "search_frame" ) == null ){
		var newFrame = document.createElement("iframe");
		newFrame.style.display = "none";
		newFrame.id = "search_frame";
		document.getElementById( "search_results_header" ).appendChild( newFrame );	
	}//end
	if( data == null ){
		data = xmlHttp.responseXML.documentElement; 
		programIndex = data.getElementsByTagName("P");
		categoryIndex = data.getElementsByTagName("C");
		seriesSaleIndex = data.getElementsByTagName("SSO");
		
	}
	
	var $data = $( $.parseXML( xmlHttp.responseText ) );
	$pdfs = $( $( $data.find( 'D:contains(".pdf")' ) ).text() ).find('a[href$=".pdf"]');
		
	if( document.getElementById( "content_div" ) != null && document.getElementById( "BreadCrumbNav" ) != null && document.getElementById( "BreadCrumbNav" ).innerHTML != ""){	
			buildRightNav();
			buildInstructorList( getCategory( current_category ) );
		}else if( document.getElementById( "content_div" ) != null ){
			setTimeout( "buildRightNav()", 1000);
		}
    /*for (var i = 0; i < programIndex.length; i++) {
        progCatIndex[i] = programIndex[i].parentNode.getAttribute('CID');
    }*/
		setUpSearchEvents();
	}catch(error){  
		//alert( error ); 
		setTimeout( "buildProgSiteSearch()", 1000); 
	}
    
}
function jQueryResultsToList( $r ){
	var $l = $();
	$r.each( function(){ $l = $l.add( this ); } );
	return $l;
}
function setUpSearchEvents(){
	var field = document.getElementById("SearchTerms");
	if (navigator.appName == "Microsoft Internet Explorer") {
		document.onkeyup = function () {
			if( event.keyCode == 27 ){ 
				searchClose(); 
			}
		}
		/*field.onkeyup = field.onkeypress = function () {
			if( event.keyCode != 27 ){ 
				clearTimeout(t_o);
				t_o = setTimeout("ActiveSiteSearch()", 500);
			}
		}*/
	} else {
		document.onkeyup = function (e) {
			if( e != null && e.keyCode != null && e.keyCode == 27 ){ 
				searchClose(); 
			}
		}
		/*field.onkeyup = field.onkeypress = function (e) {
			if( e != null && e.keyCode != null && e.keyCode != 27 ){ 
				clearTimeout(t_o);
				t_o = setTimeout("ActiveSiteSearch()", 500);
			}
		}*/
	}
	/*if (field.value != "site search") {
		ActiveSiteSearch();
	}*/
}
	
var t_o;
function siteSearchSetup2() {
    if (xmlHttp.readyState == 4) {
        try {
            data = xmlHttp.responseXML.documentElement;
        } catch(e) {
        }
        categoryIndex = data.getElementsByTagName("DecendantCategories");
        var field = document.getElementById("SearchTerms");
        field.onkeyup = field.onkeypress = function () {
            clearTimeout(t_o);
            t_o = setTimeout("ActiveSiteSearch()", 500);
        }
        if (field.value != "site search") {
            field.onkeyup();
        }
    }
}
function makeMenu() {
    if (xmlHttp.readyState == 4) {
        document.getElementById("Menu_div").innerHTML = xmlHttp.responseText;
        applyMouseEvents();
    }
}
function xmlCalendarReader() {
    if (xmlHttp.readyState == 4) {
        var xmlDoc = xmlHttp.responseXML.documentElement;
		
		data = xmlHttp.responseXML.documentElement; 
		programIndex = data.getElementsByTagName("P");
		categoryIndex = data.getElementsByTagName("C");
		seriesSaleIndex = data.getElementsByTagName("SSO");
		
        var results = xmlDoc.getElementsByTagName("Results");
        //buildProgSiteSearch();
        var list = ListPrograms(xmlDoc, getCatidFromUrl( location.href ) );
        programs = new ItemList(list);
        if (document.getElementById("program_catList_div") != null) {
			programs.termList();
			programs.getCategoryList();
        }
		programs.sortByDate();
        putIntoCalendar(programs.getCode());
        T.target = programs;
        search_field = new SearchBox(programs);
    }
}
function xmlCalendarReader1() {
    if (xmlHttp.readyState == 4) {
        var xmlDoc = xmlHttp.responseXML.documentElement;
        var results = xmlDoc.getElementsByTagName("Results");
        try {
            var list = ListAllPrograms(xmlDoc);
        } catch(e) {
            alert(e);
        }
        //buildProgSiteSearch();
        programs = new ItemList(list);

        var day = new Date();
        programs.day_filter = [day.getDay()];
        programs.date_filter = [ dateToFilter( day ) ];//[day.getMonth() * 100 + day.getDate()];
        day.setDate(day.getDate() + 1);
        programs.date_filter.push(dateToFilter( day ));
        day.setDate(day.getDate() + 1);
        programs.date_filter.push(dateToFilter( day ));
        day.setDate(day.getDate() + 1);
        programs.date_filter.push(dateToFilter( day ));
        day.setDate(day.getDate() + 1);
        programs.date_filter.push(dateToFilter( day ));
        day.setDate(day.getDate() + 1);
        programs.date_filter.push(dateToFilter( day ));
        day.setDate(day.getDate() + 1);
        programs.date_filter.push(dateToFilter( day ));
		
		

        document.getElementById("Sunday_content").innerHTML = programs.sortByTime().getGlanceCode();
        programs.day_filter[0]++;
        programs.day_filter[0] %= 7;
		
		document.getElementById( 'Sunday_tab' ).onclick();
		
		
        document.getElementById("Monday_content").innerHTML = programs.sortByTime().getGlanceCode();
        programs.day_filter[0]++;
        programs.day_filter[0] %= 7;
        document.getElementById("Teusday_content").innerHTML = programs.sortByTime().getGlanceCode();
        programs.day_filter[0]++;
        programs.day_filter[0] %= 7;
        document.getElementById("Wednesday_content").innerHTML = programs.sortByTime().getGlanceCode();
        programs.day_filter[0]++;
        programs.day_filter[0] %= 7;
        document.getElementById("Thursday_content").innerHTML = programs.sortByTime().getGlanceCode();
        programs.day_filter[0]++;
        programs.day_filter[0] %= 7;
        document.getElementById("Friday_content").innerHTML = programs.sortByTime().getGlanceCode();
        programs.day_filter[0]++;
        programs.day_filter[0] %= 7;
        document.getElementById("Saturday_content").innerHTML = programs.sortByTime().getGlanceCode();

        makeWheelable(document.getElementById('Sunday_content'));
        makeWheelable(document.getElementById('Monday_content'));
        makeWheelable(document.getElementById('Teusday_content'));
        makeWheelable(document.getElementById('Wednesday_content'));
        makeWheelable(document.getElementById('Thursday_content'));
        makeWheelable(document.getElementById('Friday_content'));
        makeWheelable(document.getElementById('Saturday_content'));

        makeDraggable(document.getElementById('Sunday_scroller'), document.getElementById('Sunday_scroller'), 8, 8, 1, 201);
        makeDraggable(document.getElementById('Monday_scroller'), document.getElementById('Monday_scroller'), 8, 8, 1, 201);
        makeDraggable(document.getElementById('Tuesday_scroller'), document.getElementById('Tuesday_scroller'), 8, 8, 1, 201);
        makeDraggable(document.getElementById('Wednesday_scroller'), document.getElementById('Wednesday_scroller'), 8, 8, 1, 201);
        makeDraggable(document.getElementById('Thursday_scroller'), document.getElementById('Thursday_scroller'), 8, 8, 1, 201);
        makeDraggable(document.getElementById('Friday_scroller'), document.getElementById('Friday_scroller'), 8, 8, 1, 201);
        makeDraggable(document.getElementById('Saturday_scroller'), document.getElementById('Saturday_scroller'), 8, 8, 1, 201);

        makeClickDragable(document.getElementById('Sunday_scroller'));
        makeClickDragable(document.getElementById('Monday_scroller'));
        makeClickDragable(document.getElementById('Tuesday_scroller'));
        makeClickDragable(document.getElementById('Wednesday_scroller'));
        makeClickDragable(document.getElementById('Thursday_scroller'));
        makeClickDragable(document.getElementById('Friday_scroller'));
        makeClickDragable(document.getElementById('Saturday_scroller'));

        scrollFor(document.getElementById('Sunday_scroller'), document.getElementById('Sunday_content'));
        scrollFor(document.getElementById('Monday_scroller'), document.getElementById('Monday_content'));
        scrollFor(document.getElementById('Tuesday_scroller'), document.getElementById('Teusday_content'));
        scrollFor(document.getElementById('Wednesday_scroller'), document.getElementById('Wednesday_content'));
        scrollFor(document.getElementById('Thursday_scroller'), document.getElementById('Thursday_content'));
        scrollFor(document.getElementById('Friday_scroller'), document.getElementById('Friday_content'));
        scrollFor(document.getElementById('Saturday_scroller'), document.getElementById('Saturday_content'));
    }
}
function xmlCalendarReader2() {
    if (xmlHttp.readyState == 4) {
        var xmlDoc = xmlHttp.responseXML.documentElement;
        var results = xmlDoc.getElementsByTagName("Results");
        //buildProgSiteSearch();
        var list = ListAllPrograms(xmlDoc);
        programs = new ItemList(list);
		
        if (document.getElementById("program_catList_div") != null) {
			programs.termList();
			programs.getCategoryList();
        }
		//programs.sortByName();
        putIntoCalendar(programs.getCode());
        T.target = programs;
        search_field = new SearchBox(programs);
		selectToday();
    }
}
function selectToday(){
	if( location.href.indexOf( "?week=" ) == -1 ){
		var date = getDateFromURL();
		var today_btn = document.getElementById( "date" + date.getYear() + "" + date.getMonth() + "" + date.getDate() );
		if( today_btn != null ){ today_btn.onclick(); }
	} else {
		var date = getDateFromURL();
		selectWeek( dateToFilter( date ).toString() );
	}
}
function newCategory() {
    if (xmlHttp.readyState == 4) {
        var div = document.getElementById("content_container");
        div.innerHTML = xmlHttp.responseText;
        getBreadCrumbs();
    }
}
function newBreadCrumbs() {
    if (xmlHttp.readyState == 4) {
        try {
            var div = document.getElementById("BreadCrumb_div");
            div.innerHTML = xmlHttp.responseText;
            deepLinkBreadCrumbs();
            /*if (document.getElementById("highlights_holder") != null) {
                getHighlights_dynamic( data );
            } else if (document.getElementById("highlights_holderM") != null) {
                getHighlightsM_dynamic( data );
            }*/
            if (document.getElementById('content_div') == null) {
               // return;
            }
			getFaders();
        } catch(e) {}
        var to = window.setTimeout( function(){ 
		if( document.getElementById( "content_div" ) == null && document.getElementById( "BreadCrumbNav" ).innerHTML != "" ){
			//location.href = "programs.aspx?catid=" + getCatidFromUrl( location.href );
			//location.href = getCatHREFfromID( location.href ) + "?page=programs";
		} else if( document.getElementById( "BreadCrumbNav" ).innerHTML == "" ){
			makeCategoryNotFound();
		}
		
		showCategoryAlerts();
		outBoundLinkCheck();
		$( ".gallery_div .jccheader" ).click( toggleGallery );
		
		//$( "#content_div script" ).filter( function(){ eval( this.innerHTML ); } );
		
		var bc = document.getElementById("BreadCrumbNav_2_01");
		if( bc == null ){ bc = document.getElementById("BreadCrumbNav"); }
		var pageTitle = "the JCC in Manhattan - ";
		var preBC = bc.getElementsByTagName( "A" );
		for( var i = 0; i<preBC.length; i++ ){
			pageTitle += preBC[ i ].innerHTML + " | ";
		}
        bc = bc.childNodes[bc.childNodes.length - 1];
		pageTitle += bc.innerHTML;
		pageTitle = pageTitle.replace( "&amp;" , "&" );
		document.title = pageTitle; 

		/*if( document.getElementById( "more_options_div" ) != null ){
			template += '<div id="mo' + current_category + '" class="rtnav_MO">' + document.getElementById( "more_options_div" ).innerHTML + '</div>';
		}*/
        scrollToTile( getUFURL(location.href) );
		var captCat = getCaptainCat( current_category );
		var progBUTT = document.getElementById( "fdsovgnosdfiu" + captCat );
		if( progBUTT != null ){//progBUTT is null if this is a redirect to another real category
			//progBUTT.href = "programs.aspx?catid=" + current_category;
			progBUTT.href = getCatHREFfromID( current_category ) + "?page=programs";
			if( hasProgs( current_category ) ){
				progBUTT.style.display = "block";
				progBUTT.innerHTML = "programs for " + getNameFromId( current_category );
				var cat = getCategory( current_category );
				$("#instructors_toggle_" + captCat).html("instructors for " + getCatName(cat));
				$( "#instructors_toggle_" + captCat ).css("background-image","url(http://dev.jccmanhattan.org/images/buttons/down.gif)");
				//$("#instructors" + captCat).html(buildInstructorList(cat));
				if( !hasInstructors(current_category)){//$("#instructors" + captCat + " li").length == 0 ){
					$("#instructors_toggle_" + captCat).css("display","none");
				} else {
					$("#instructors_toggle_" + captCat).css("display","block");
				}
				$("#instructors" + captCat).css("display","none");
			} else {
				progBUTT.style.display = "none";
				$("#instructors_toggle_" + captCat).css("display","none");
				$("#instructors" + captCat).css("display","none");
			}
		} else {
			$( ".rtresource_link" ).filter( function(){
				if( this.parentNode.innerHTML.indexOf( getNameFromId( current_category ) ) == -1 ){
					return false;
				}
				this.href = getCatHREFfromID( current_category ) + "?page=programs";
				if( hasProgs( current_category ) ){
					this.style.display = "none";
					this.innerHTML = "view " + getNameFromId( current_category ) + " programs";
				} else {
					this.style.visibility = "hidden";
				}
			} );
		}
		defaultMissingImg();
		} , 100 );
    }
}
function toggleGallery(){
	var ID = this.parentNode.id;
	var player = $( "#" + ID + " .gallery_player_div" );
	var icon = $( "#" + ID + " .jccheader" );
	if( player.html() == "" ){
		player.html( "<iframe src='http://player.vimeo.com/video/" + ID + "?title=0&byline=0&portrait=0&color=eeeeee&autoplay=1&loop=1' width='500' height='375' frameborder'0'>" );
		icon.css( "background-image" , "url(images/gallery_close.png)" );
	} else {
		player.html( "" );
		icon.css( "background-image" , "url(images/gallery_open.png)" );
	}
}
function showCategoryAlerts(){
	var a_div = document.getElementById("cat_alerts_div");
	var a_btn = document.getElementById("cat_alerts_btn");
	if( a_div != null && a_div.innerHTML != "" ){
		MM_preloadImages('images/buttons/alert_close.png');
		a_btn.style.display = "block";
		a_btn.onclick = openCategoryAlertsDiv;
		if( a_btn.rel == "now" ){
			window.setTimeout( function(){ document.getElementById("cat_alerts_btn").onclick(); } , 2000 );
		}
	}
}
function outBoundLinkCheck(){
	$( '#content_div a' ).filter( function(){ 
		var url = this.href.toLowerCase();
		if( url.indexOf( "jccmanhattan.org" ) == -1 && url.indexOf( "javascript:" ) == -1 && url.indexOf( "mailto:" ) == -1 && url.charAt( 0 ) != "#" && url != "" && this.innerHTML.toLowerCase().indexOf( "<img" ) == -1 ){
			this.className = "extlink";
			this.onclick = function () {
				urchinTracker('/outbound/' + this.href.substring( this.href.indexOf( this.hostname ) , this.href.length ) );
	 		};
			this.target = "_blank";
		}
	} );
}
function openCategoryAlertsDiv(){
	document.getElementById("cat_alerts_div").style.display = "block";
	//this.rel = this.innerHTML;
	//this.innerHTML += "<span style='color:#000000'> - x</span>";
	this.childNodes[ 0 ].style.backgroundImage = "url('images/buttons/alert_close.png')";
	this.onclick = closeCategoryAlertsDiv;
}
function closeCategoryAlertsDiv(){
	document.getElementById("cat_alerts_div").style.display = "none";
	//this.innerHTML = this.rel;
	this.childNodes[ 0 ].style.backgroundImage = "url('images/buttons/alert.png')";
	this.onclick = openCategoryAlertsDiv;
}
function getUFURL( url ){
    if (url.indexOf('tile_') != -1) {
		url = url.substring(url.indexOf('tile_') + 5, url.length);
    } else if (url.indexOf('load_') != -1) {
    	url = url.substring(url.indexOf('load_') + 5, url.length);
    }
	return url;
}
function categorySearchMaker() {
    if (xmlHttp.readyState == 4) {
        var div = document.getElementById("cat_search_results");
        div.innerHTML = xmlHttp.responseText;
        div.target = document.getElementById("searchScroller");
        div.onDrag = setScrollBar;
        div.style.position = "absolute";
        SiteSearchP();
    }
}
function programSearchMaker() {
    if (xmlHttp.readyState == 4) {
        var div = document.getElementById("search_results");
        div.innerHTML = xmlHttp.responseText;
        if (div.innerHTML == "") {
            div.innerHTML = "no programs to display for \"<b>" + document.getElementById("SearchTerms").value + "</b>\"";
        }
        div.target = document.getElementById("searchScroller");
        div.onDrag = setScrollBar;
        div.target.recalc();
        div.style.position = "absolute";
    }
}
//NOT IN USE --- SCROLL DOWN
function makeCalList(results) {
    var start, end;
    if (navigator.appName == "Microsoft Internet Explorer") {
        for (var i = 0; i < results.length; i++) {
            var myCat = results[i].getElementsByTagName("CategoryID")[0].text;
            if (myCat == catID) {
                start = getDatefrom(results[i].getElementsByTagName("StartDateTime")[0].text);
                try {
                    end = getDatefrom(results[i].getElementsByTagName("EndDateTime")[0].text);
                } catch(e) {
                    end = null;
                }
                calList.push(new Item(results[i].getElementsByTagName("Title")[0].text, start, end, 1, 2, "weekly", results[i].getElementsByTagName("CategoryID")[0].text, results[i].getElementsByTagName("ProgramID")[0].text, results[i].getElementsByTagName("RegistrationCode")[0].text));
            }
        }
    } else {
        for (var i = 0; i < results.length; i++) {
            if (results[i].getElementsByTagName("CategoryID")[0].textContent == catID) {;
                start = getDatefrom(results[i].getElementsByTagName("StartDateTime")[0].textContent);
                try {
                    end = getDatefrom(results[i].getElementsByTagName("EndDateTime")[0].textContent);
                } catch(e) {
                    end = null;
                }
                calList.push(new Item(results[i].getElementsByTagName("Title")[0].textContent, start, end, 1, 2, "weekly", results[i].getElementsByTagName("CategoryID")[0].textContent, results[i].getElementsByTagName("ProgramID")[0].textContent, results[i].getElementsByTagName("RegistrationCode")[0].textContent));
            }
        }
    }
    return calList;
}
function getText(node) {
	if( node == null ){ return ""; }
    if (navigator.appName == "Microsoft Internet Explorer") {
        return node.text;
    } else if ( node != null ){
   		return node.textContent;
	}
	return "";
}
function ListPrograms(xml, cid) {
    var cat = [],
    protoprogs = [],
    progs = [],
    start,
    end,
    title,
    subtitle,
    minAge,
    maxAge,
	ageType,
    rec,
	tx,
    description,
    catname,
    catid,
    progid,
    subList,
    prog_code,
    regav,
	regphone,
	instr,
	xlist,
	iName,
	iID;
	
	//cat = getCategory( cid );
	//if( cat == null ){ return progs; }
	protoprogs = $(xml).find( "P" );
	for (var i = 0; i < protoprogs.length; i++) {
		start = getDatefrom(getText(protoprogs[i].getElementsByTagName("S")[0]));
            try {
                end = getDatefrom(getText(protoprogs[i].getElementsByTagName("E")[0]));
            } catch(e) {
                end = null;
            }
            title = getText(protoprogs[i].getElementsByTagName("PT")[0]);
            title = title.replace('"', "&quot;");
            title = title.replace("'", "&acute;");
            subtitle = getText(protoprogs[i].getElementsByTagName("T")[0]);
            subtitle = subtitle.replace('"', "&quot;");
            subtitle = subtitle.replace("'", "&acute;");
            catid = protoprogs[i].parentNode.getAttribute('CID');
            catname = protoprogs[i].getElementsByTagName("CP")[0];
            catname = getText(catname);
			xlist = catname.indexOf( protoprogs[i].parentNode.getAttribute('T') ) == -1;
            catname = catname.replace('"', "&quot;");
            catname = catname.replace("'", "&acute;");
            progid = protoprogs[i].getAttribute("PID");
            minAge = getText(protoprogs[i].getElementsByTagName("AL")[0]);
            maxAge = getText(protoprogs[i].getElementsByTagName("AH")[0]);
            ageType = getText(protoprogs[i].getElementsByTagName("AT")[0]);
            rec = getText(protoprogs[i].getElementsByTagName("RT")[0]);
            tx = getText(protoprogs[i].getElementsByTagName("TX")[0]);
            prog_code = getText(protoprogs[i].getElementsByTagName("R")[0]);
            regav = getText(protoprogs[i].getElementsByTagName("B")[0]);
			regphone = getText(protoprogs[i].getElementsByTagName("RP")[0]);
			instr = protoprogs[i].getElementsByTagName("INSTR")[0];
			iName = ( instr != null ) ? instr.getAttribute( "FN" ) + " " + instr.getAttribute( "LN" ) : "";
			iID = ( instr != null ) ? instr.getAttribute( "IID" ) : "";
            if (rec == "S") {
                rec = "once";
            }
            if (rec == "W") {
                rec = "weekly";
            }
            if (rec == "D") {
                rec = "daily";
            }
            if (rec == "M") {
                rec = "monthly";
            }
            if (rec == "C" || rec == "T") {
                rec = "see details";
            }
            description = (protoprogs[i].getElementsByTagName("D")[0] == null) ? "" : getText(protoprogs[i].getElementsByTagName("D")[0]);
            progs.push(new Item(title, start, end, minAge, maxAge, ageType, rec, tx, description, catname, catid, progid, prog_code, regav, regphone, subtitle, xlist, iName , iID ) );
	}
    return progs;
}

//recursively check for a category match in nested xml and return all programs if so
function ListAllPrograms(xml) {
    var cat = [],
    protoprogs = [],
    progs = [],
    start,
    end,
    title,
    subtitle,
    minAge,
    maxAge,
	ageType,
    rec,
	tx,
    description,
    catname,
    catid,
    progid,
    subList,
    prog_code,
    regav,
	regphone,
	instr,
	xlist,
	iName,
	iID;
	
	protoprogs = $(xml).find("P");
	for (var i = 0; i < protoprogs.length; i++) {
		start = getDatefrom(getText(protoprogs[i].getElementsByTagName("S")[0]));
            try {
                end = getDatefrom(getText(protoprogs[i].getElementsByTagName("E")[0]));
            } catch(e) {
                end = null;
            }
            title = getText(protoprogs[i].getElementsByTagName("PT")[0]);
            title = title.replace('"', "&quot;");
            title = title.replace("'", "&acute;");
            subtitle = getText(protoprogs[i].getElementsByTagName("T")[0]);
            subtitle = subtitle.replace('"', "&quot;");
            subtitle = subtitle.replace("'", "&acute;");
            catid = protoprogs[i].parentNode.getAttribute('CID');
            catname = protoprogs[i].getElementsByTagName("CP")[0];
            catname = getText(catname);
			xlist = catname.indexOf( protoprogs[i].parentNode.getAttribute('T') ) == -1;
            catname = catname.replace('"', "&quot;");
            catname = catname.replace("'", "&acute;");
            progid = protoprogs[i].getAttribute("PID");
            minAge = getText(protoprogs[i].getElementsByTagName("AL")[0]);
            maxAge = getText(protoprogs[i].getElementsByTagName("AH")[0]);
            ageType = getText(protoprogs[i].getElementsByTagName("AT")[0]);
            rec = getText(protoprogs[i].getElementsByTagName("RT")[0]);
            tx = getText(protoprogs[i].getElementsByTagName("TX")[0]);
            prog_code = getText(protoprogs[i].getElementsByTagName("R")[0]);
            regav = getText(protoprogs[i].getElementsByTagName("B")[0]);
			regphone = getText(protoprogs[i].getElementsByTagName("RP")[0]);
			instr = protoprogs[i].getElementsByTagName("INSTR")[0];
			iName = ( instr != null ) ? instr.getAttribute( "FN" ) + " " + instr.getAttribute( "LN" ) : "";
			iID = ( instr != null ) ? instr.getAttribute( "IID" ) : "";
            if (rec == "S") {
                rec = "once";
            }
            if (rec == "W") {
                rec = "weekly";
            }
            if (rec == "D") {
                rec = "daily";
            }
            if (rec == "M") {
                rec = "monthly";
            }
            if (rec == "C" || rec == "T") {
                rec = "see details";
            }
            description = (protoprogs[i].getElementsByTagName("D")[0] == null) ? "" : getText(protoprogs[i].getElementsByTagName("D")[0]);
            progs.push(new Item(title, start, end, minAge, maxAge, ageType, rec, tx, description, catname, catid, progid, prog_code, regav, regphone, subtitle, xlist, iName , iID ) );
	}
    return progs;
}

