<!-- hide from old browsers

var days = new Array();
days[0] = "Sunday";
days[1] = "Monday";
days[2] = "Tuesday";
days[3] = "Wednesday";
days[4] = "Thursday";
days[5] = "Friday";
days[6] = "Saturday";

var months = new Array();
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";


function checkEmail(strng) {
	var error = "";

	var emailFilter=/^.+@.+\..{2,6}$/;

	if (!(emailFilter.test(strng))) {
		return false;
	}

	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\] ']/

	if (strng.match(illegalChars)) {
		return false;
	}

	return true;
}

function nl_validator(theForm)
{
	if(!checkEmail(theForm.newsletter.value)) {
		 alert("Please enter a valid Email Address");
		theForm.newsletter.focus();
		 return false;
	}

	return (true);
}

//DATE PICKER FUNCTIONS
function showKey() {
    $('#eventscal').toggle();
    $('#eventscallist').toggle();
    if($('#eventscala').html() == "Return to Calendar") {
        $('#eventscala').html("Click to View Key")
    } else {
        $('#eventscala').html("Return to Calendar")    
    }
    return false;
}

function getDateString(dt) {    
    var dd = new Date(dt);
    dd.setMonth(dd.getMonth()-1);
    var suffix = "th";
    
    switch (dd.getDate()) {
        case 1:
        case 21:
        case 31:
        suffix = "st";
        break;
        case 2:
        case 22:
        suffix = "nd";
        break;
        case 3:
        case 23:
        suffix = "rd";
        break;
    }
    
    return days[dd.getDay()] + ", " + dd.getDate() + suffix + " " + months[dd.getMonth()] + " " + dd.getFullYear();
}

function getMonthEvents(yr, mn, inst) {
    var tojson = { 
        'MonthValue': mn, 
        'YearValue': yr
    };
    
    $('#' + inst.id).datepicker('disable');

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/calendar.aspx/GetMonthEvents",
        data: JSON.stringify(tojson),
        dataType: "json",
        success: function(result) {
            var evs = result.d;
            var tds = $("#" + inst.id + " table").children("tbody").children("tr").children("td").children("a");
            
            $(tds).each(function() {
                
                //get the cell date
                var tdt = new Date()    
                tdt.setFullYear(yr, mn-1, $(this).html());
                tdt.setHours(0, 0, 0, 0);
                            
                //get the first date before the loop
                if($(evs).size() > 0) {
                    var edt = parseJSONDate(evs[0].eDate);
                       
                    //While the cell date is the same 
                    var ecount = 0;       
                    while($(evs).size() > 0 && tdt.getFullYear() == edt.getFullYear() && tdt.getMonth() == edt.getMonth() && tdt.getDate() == edt.getDate() ) {
                         
                        ecount++;
                        
                        //Change the class of the cell based on the event type
                        if(ecount==1) {
                            $(this).css("background", "#" + evs[0].Colour);
                        } else {
                            $(this).css("background", "#FFFFFF");
                        }
                        
                        //Remove the event from the list
                        evs.remove(0);
                                            
                        //Create the date for the next event, this should really be a function
                        if($(evs).size() > 0) {
                            edt = parseJSONDate(evs[0].eDate); 
                        }                  
                    }
                    
                    $(this).parent().attr("onclick", "");
                    
                    if(ecount>0) {
                        $(this).parent().click(function() {
                            var dtStr = "";
                            dtStr += $(this).children('a').html() + "/";
                            dtStr += mn + "/";
                            dtStr += yr;
                            slideEvent(dtStr); 
                            
                        });
                        
                        $(this).parent().mouseout(function() { 
                            $('#eventscalinfo').stop(true, false).animate({"left": "0px", "width": "210px"});
                        });
                    }
                }
            });
            $('#' + inst.id).datepicker('enable');
        },
        error: function(xhr, status, error) {
            alert(xhr.responseText);
            $('#' + inst.id).datepicker('enable');
        }
    });
}

function slideEvent(dtStr) {
    
    var tojson = { 
        'DayValue': dtStr.split("/")[0],
        'MonthValue': dtStr.split("/")[1], 
        'YearValue': dtStr.split("/")[2]
    };
        
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/calendar.aspx/GetEventDay",
        data: JSON.stringify(tojson),
        dataType: "json",
        success: function(result) {
            var msg = '<h2>Events on ' + getDateString(new Date(dtStr.split("/")[2], dtStr.split("/")[1], dtStr.split("/")[0])) + '</h2>';
            
            for(ee in result.d) {
                if(ee != 'remove') {
                    msg = msg + '<p><strong>'+result.d[ee].Name+'</strong><br />';
                    msg = msg + result.d[ee].TypeName + '</p>';
                }      
            }     
            
            $("#eventscalinfo").html(msg);
            $('#eventscalinfo').animate({"left": "-420px", "width": "400px"});
        },
        error: function(xhr, status, error) {
            alert(xhr.responseText);
        }
    });
}

//This function converts JSON date to 
function parseJSONDate(jdate) {
    var edt = new Date();           
    var s = eval(jdate.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
    edt = new Date(s);
    var mil = Date.UTC(edt.getFullYear(),edt.getMonth(), edt.getDate(), edt.getHours(), edt.getMinutes(), edt.getSeconds(), edt.getMilliseconds()); //Miliseconds since January 1, 1970
    edt = new Date(mil); //Convert to local time
    
    return edt;
}

//Remove an item from an array
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};



	
	    
// end script hiding -->
