﻿// JScript File


sfHover = function() {
	var sfEls = document.getElementById("sidenav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			this.style.zIndex = 1000000000;
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			this.style.zIndex = 1000000000;
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


			
// this array consists of the id attributes of the divs we wish to alternate between
var divs_to_fade = new Array('box-1', 'box-2', 'box-3', 'box-4', 'box-5', 'box-6', 'box-7', 'box-8', 'box-9', 'box-10', 'box-11');

// the starting index in the above array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
var i = 0;

// the number of milliseconds between swaps.  Default is five seconds.
var wait = 5000;

// the function that performs the fade
function swapFade() {
	Effect.Fade(divs_to_fade[i], { duration:1, from:1.0, to:0.0 });
	i++;
	if (i == 10) i = 0;
	Effect.Appear(divs_to_fade[i], { duration:1, from:0.0, to:1.0 });
}

// the onload event handler that starts the fading.
function startPage() {
	setInterval('swapFade()',wait);
}

// Exploding strings to arrays
function explodeArray(item,delimiter) {
    tempArray=new Array(1);
    var Count=0;
    var tempString=new String(item);
    while (tempString.indexOf(delimiter)>0) {
        tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
        tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
        Count=Count+1
    }
    tempArray[Count]=tempString;
    return tempArray;
}

function checkKeycode() {
    var searchBox = document.getElementById('ct100_txtSearchText');
    var keycode;
    
    if(window.event) {
        keycode = window.event.keycode;
        if(keycode == 13)
        {
            CallSearch();
        }
    }
}

function CallSearch() {
    var searchBox = document.getElementByID('ct100_txtSearchText');
    
    if(searchBox.value != "")
    {
        var searchText = searchBox.value;
        var path = 'search.aspx?searchtext=' + searchText;
        location.href = path;
        return false;
    } else {
        searchBox.style.backgroundColor = "#C63D33";
        searchBox.style.color = "#FFFFFF";
        window.location.href = "/search/";
    }
    return true;
}

function clearFormat() {
    searchBox.style.backgroundColor = "#FFFFFF";
    searchBox.style.color = "#000000";
    return true;
}

document.onload = checkKeycode;
function nl2br (str, is_xhtml) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Philip Peterson
    // +   improved by: Onno Marsman
    // +   improved by: Atli Þór
    // +   bugfixed by: Onno Marsman
    // *     example 1: nl2br('Kevin\nvan\nZonneveld');
    // *     returns 1: 'Kevin<br />\nvan<br />\nZonneveld'
    // *     example 2: nl2br("\nOne\nTwo\n\nThree\n", false);
    // *     returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
    // *     example 3: nl2br("\nOne\nTwo\n\nThree\n", true);
    // *     returns 3: '<br />\nOne<br />\nTwo<br />\n<br />\nThree<br />\n'
 
    breakTag = '<br />';
    if (typeof is_xhtml != 'undefined' && !is_xhtml) {
        breakTag = '<br>';
    }
 
    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}

function startTinyMCE()
{
	tinyMCE.init({mode : "textareas",theme : "advanced",cleanup_on_startup : true,editor_deselector : "nomce",
	    theme_advanced_buttons1 : "bold,italic,underline,link,unlink,bullist,blockquote,undo", 
	    theme_advanced_buttons2 : "", 
	    theme_advanced_buttons3 : "" 
	});
}

function CSCEvent()
{
this.startTime = '';
this.endTime = '';
this.eName = '';
this.description = '';
}
CSCEvent.prototype.genHTML = function () {
var html = "";
html += '<div class="agendatime">'+this.startTime;

if(this.endTime != '')
{
html+= ' – '+this.endTime;
}
html +='</div>';

html += '<div class="agendapost">';
html += '<strong>'+this.eName+'<br/></strong>';
html += this.description;
html += '</div>';

return html;
}

var cscEvents = new Object();
function addEvent()
{
	var ni = document.getElementById('myList');
	var numi = document.getElementById('theValue');
	var num = (document.getElementById("theValue").value -1)+ 2;
	numi.value = num;
	var divIdName = "myList_myList"+num;
	var newdiv = document.createElement('li');
	newdiv.setAttribute("id",divIdName);
	newdiv.setAttribute("class","handle");
	var arrnum = num - 1;

	

	newdiv.innerHTML = '<div class="fleft small">' +
	'<input type="text" name="times" onchange="updateEvent(\''+divIdName+'\')" onkeypress="updateEvent(\''+divIdName+'\')" id="'+divIdName+'_times" class="text">' +
	  '<label>Start Time</label>'+
	'</div>'+
	'<div class="fleft small">' +
	'<input type="text" name="timee" onchange="updateEvent(\''+divIdName+'\')" onkeypress="updateEvent(\''+divIdName+'\')" id="'+divIdName+'_timee" class="text">' +
	  '<label>End Time</label>'+
	'</div>'+
	'<br class="clear" />'+
	'<div class="medium">' +
	  '<input type="text" name="name[]" onchange="updateEvent(\''+divIdName+'\')" onkeypress="updateEvent(\''+divIdName+'\')" id="'+divIdName+'_name" class="text">' +
	  '<label>Name</label>'+
	'</div>'+
	'<br class="clear" />'+
	'<div class="">'+
	  '<textarea name="description" onchange="updateEvent(\''+divIdName+'\')" onkeypress="updateEvent(\''+divIdName+'\')" id="'+divIdName+'_description" class="evdesc"></textarea>' +
	  '<label>Description</label>' +
	'</div>' +
	'</div>' +
	'<div class="removerow"><a href="javascript:;" onchange="updateEvent(\''+divIdName+'\')" onkeypress="updateEvent(\''+divIdName+'\')" onclick="removeEvent(\''+divIdName+'\')">Remove</a></div>' +
	'<br class="clear" />';
	ni.appendChild(newdiv);
//	Sortable.create("myList",{handle:'handle',dropOnEmpty:true,containment:["myList"],constraint:false});
	thisEvent = new CSCEvent();
	cscEvents[divIdName] = thisEvent;
	startTinyMCE();

}

function updateEvent(divNum)
{
	
	cscEvents[divNum].startTime = document.getElementById(divNum+'_times').value;
	cscEvents[divNum].endTime = document.getElementById(divNum+'_timee').value;
	cscEvents[divNum].eName = document.getElementById(divNum+'_name').value;
	//cscEvents[divNum].description = document.getElementById(divNum+'_description').value;
	cscEvents[divNum].description = tinyMCE.get(divNum+'_description').getContent();
	updateEventPreview(true);
	
}

function updateEventPreview(dontupdateall)
{
	var newHTML = '';
	newHTML += '<div class="agendadate">'+document.getElementById('eventDate').value+'</div>';
	for( var i in cscEvents)
	{
		if(!dontupdateall)
		{
			updateEvent(i);
		}
		if(cscEvents[i] != undefined)
		{
		eHTML = cscEvents[i].genHTML();
		if(eHTML != '')
		{
			newHTML += eHTML;
		}
		}
	}

	document.getElementById('agendaPreview').innerHTML = newHTML;
	document.getElementById('agendaHTML').value = newHTML;

}


function removeEvent(divNum)
{
	var d = document.getElementById('myList');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
	delete(cscEvents[divNum]);
	updateEventPreview();
}

function checkForm(form)
{
	if($('title').value == "")
	{
		alert('Please fill in a title.');
		return false;	
	} else {
		return true;
	}
}

