﻿// JScript File

$('document').ready(function(){

   
    $('#calendar_section').each(function(){
        $this = $(this);
        
        var cells = this.getElementsByTagName("td");
        var i = 0;     
        var cellheight;
        var cellwidth;
        var str = String(window.location);
        var calendarid;
        
        //set calendar views current year base on hidden text
        var currentyear = document.getElementById("ctl00_Calendar1_selectedyear").value;
        
        //get current month calendar is displaying
        var headertable = cells[0].getElementsByTagName("table");
        var monthcell = headertable[0].getElementsByTagName("td");
        var currentmonth = GetMonth(monthcell[1].innerHTML);
        
        //determine which section this page is located in in order to set calendarid
        if(str.match("parents")){
            calendarid = 6;
        }
        else if(str.match("commission")){
            calendarid = 8;
        }
        else if(str.match("community")){
            calendarid = 10;
        }
        else if(str.match("education")){
            calendarid = 12;
        }
        else if(str.match("aboutus")){
            calendarid = 14;
        }   
        else{//default to home
            calendarid = 4;
        }
        
        for(i = 0;i < cells.length;i++){ 
                      
            //strip inline style from anchor and reapply the css style being ignored
            //for getAttribute method className must be used
            if(cells[i].getAttribute('class') == "day_background" || cells[i].getAttribute('className')== "day_background"){
                cellheight = cells[i].clientHeight;
                cellwidth = cells[i].clientWidth;
                //alert(cellheight);
                //make sure cell height is exactly 25px on all browsers
                //must take the difference between clientHeight and 25px, then add subtract the difference from 25px
                //alert(cellheight);
                if(cellheight != "25px" && cellheight >= 24){
                    cells[i].style.height = 25 - (cellheight - 25)+"px";
                    //cells[i].style.height = "25px";
                }
                else{
                    cells[i].style.height = "21px";
                }
                //alert(cells[i].style.height);
                if(cellwidth != "25px")
                {  
                    cells[i].style.width = "25px";  
                }
                var links = cells[i].getElementsByTagName("a");
                
                for(j = 0;j < links.length;j++){                    
                    links[j].style.color = '';
                    links[j].className = "day_background";
                    links[j].href = "../../calendar.aspx?calendarid="+calendarid+"&month="+currentmonth+"&year="+currentyear;
                    links[j].target = "_blank";
                }            
            }
            //repeat step taken about for cells with the selected_day class applied
            if(cells[i].getAttribute('className') == "selected_day" || cells[i].getAttribute('class') == "selected_day"){
                scellheight = cells[i].clientHeight;
                scellwidth =  cells[i].clientWidth;
                //cells[i].style.backgroundColor = "#fbe9b6"; 
                //alert(scellheight);
                if(scellheight != "25px" && scellheight >= 24){
                    cells[i].style.height = 25 - (scellheight - 25)+"px";
                }
                else{
                    cells[i].style.height = "21px";
                }
                if(scellwidth != "25px")
                {
                   //scells[i].style.width = "25px";    
                }
                var links = cells[i].getElementsByTagName("a");
                for(m = 0;m < links.length;m++){                    
                    links[m].style.color = '#666666';
                    links[m].href = "../../calendar.aspx?calendarid="+calendarid+"&month="+currentmonth+"&year="+currentyear;
                    links[m].target = "_blank";
                } 
            }
            
            //repeat step taken about for cells with the event class applied
            if(cells[i].getAttribute('className') == "event_day" || cells[i].getAttribute('class') == "event_day"){
                ecellheight = cells[i].clientHeight;
                ecellwidth = cells[i].clientWidth;
                
                if(ecellheight != "25px" && ecellheight >= 24){
                    cells[i].style.height = 25 - (ecellheight - 25)+"px";
                }
                else{
                    cells[i].style.height = "21px";
                }
                if(ecellwidth != "25px")
                {
                   //ecells[i].style.width = "25px";    
                }
                var links = cells[i].getElementsByTagName("a");
                for(k = 0;k < links.length;k++){                    
                    links[k].style.color = '#ffffff';
                    links[k].href = "../../calendar.aspx?calendarid="+calendarid+"&month="+currentmonth+"&year="+currentyear;
                    links[k].target = "_blank";
                } 
            }
        }//end Foreach
        
        
        //do not display any rows that only contain cells from other months
        var rows = this.getElementsByTagName("tr");
        for(k = 0;k < rows.length;k++){
            var othermonths = 0;
            thecolumns = rows[k].getElementsByTagName("td");
            
            for(m = 0;m < thecolumns.length;m++){
                if(thecolumns[m].getAttribute('className') == "other_month" || thecolumns[m].getAttribute('class') == "other_month"){
                    othermonths++;
                }
            }
            
            //if no columns from this month were found do no display this row
            if(othermonths == 7){
                rows[k].style.display = 'none';
            }/**/
        }
        
    });
});

function closeMe(){
    var win = window.open("","_self");
    win.close();
}

function GetMonth(month){
    var monthindex = 1;
    if(month == "January" || month == "enero"){
        monthindex = 1;
    }
    else if(month == "February" || month == "febrero"){
        monthindex = 2;
    }
    else if(month == "March" || month == "marzo"){
        monthindex = 3;
    }
    else if(month == "April" || month == "abril"){
        monthindex = 4;
    }
    else if(month == "May" || month == "mayo"){
        monthindex = 5;
    }
    else if(month == "June" || month == "junio"){
        monthindex = 6;
    }
    else if(month == "July" || month == "julio"){
        monthindex = 7;
    }
    else if(month == "August" || month == "agosto"){
        monthindex = 8;
    }
    else if(month == "September" || month == "septiembre"){
        monthindex = 9;
    }
    else if(month == "October" || month == "octubre"){
        monthindex = 10;
    }
    else if(month == "November" || month == "noviembre"){
        monthindex = 11;
    }
    else if(month == "December" || month == "diciembre"){
        monthindex = 12;
    }
    return monthindex
}

function font_size(isIncrease){
    $body = $('body');
    current_size = $body.css('font-size');
    var num = parseFloat(current_size);
    
    if(isIncrease){
        if(num < 22){++num;}
    } 
    else
    {
        if(num > 9){--num;}
    }
    $body.css('font-size', num + 'px');
    createCookie('font_size_preference', num + 'px', 365);
}

function font_reset(){
    $('body').css('font-size', '12px');
    eraseCookie('font_size_preference');
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}    

function submitEmailForm(theForm)
{
    var emailValue;
    var actionUrl;
    emailValue = theForm.Email.value;
    actionUrl = 'http://www.simplesend.com/simple/members.asp?Task=Join';
  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \"Email Address\" field.");
    theForm.Email.focus();
    return (false);
  }
  if (theForm.Email.value.length < 7)
  {
    alert("Please enter at least 7 characters in the \"Email Address\" field.");
    theForm.Email.focus();
    return (false);
  }
  if (theForm.Email.value.length > 255)
  {
    alert("Please enter at most 255 characters in the \"Email Address\" field.");
    theForm.Email.focus();
    return (false);
  }
  
  theForm.action = actionUrl;
  theForm.submit();  
}

//open page content in new window for print
function printContent(){
    printWin = window.open('/print.html','mywin','left=20,top=20,width=700,height=700,toolbar=1,resizable=1,scrollbars=yes');
    printWin.focus();
    src_title = document.title;
    //src_value = "<img src='/portals/0/skins/uhc/assets/images/logo.gif' alt='UHC logo'/>";
    src_value += $('#content').html();
    counter = 10;
    waitfortarget();
}
function waitfortarget(){
    counter--;
    if ( ! printWin.document.getElementById('print_content')){
        //do nothing
        if (counter > 0){
            timer=setTimeout("waitfortarget()", 1000);
        }
        else{
            alert('Unable to load print version. Please try again later.');
        }
    }
    else{
        donetarget();
    }
}
function donetarget(){
    printWin.document.title = src_title;
    printWin.document.getElementById('print_content').innerHTML = src_value;
    printWin.print();
}