var url = "../../calendar/calendar2010.xml";
var xml = new JKL.ParseXML( url );
var data = xml.parse();

var d = new Date();
var ch = new Date();
d.setDate(d.getDate()-5); //changes todays date to 5 days into the past so events will stay displayed for 5 extra days.
var today = (d.format("yyyymmdd") );
var todaych = (ch.format("yyyymmdd") );

function sortdates(whois,which) // wire right side calendar dates
{
	if (whois=="HSE" || whois=="HSC") //checks to see if the home page is calling then sets the Jquery arguements for the homepage depeding on which browser is calling it.
	{

		var browser=navigator.appName;
		var b_version=navigator.appVersion;
		var version=parseFloat(b_version);
		if ((browser=="Microsoft Internet Explorer") && (version>=4))
		  {
		  }
		else
		  {
			$('#conferences-scroll').jScrollPane();
			$('#training-cert-info-scroll').jScrollPane();   
		  } 
	 }
	 
	 
	if (whois=="Wright" || whois=="HSE" || whois=="HSC" || whois=="HSCP")
	{
		var now = new Date();
		var date1 = now.format("yyyymmdd");
		now.setMonth(now.getMonth() + 5); // change number & +/- to effect how many months it will display
		var date2 = now.format("yyyymmdd");
	}
	
			
	for (a=0;a<data.channel.item.length;a++)	 // this tell it to cycle through the xml feed items numbers up to item 200. So you can cycle through 200 items in the xml feed before it stops looking at them.
	{	
			var newDate = data.channel.item[a].dateid ;
			var call = newDate.slice(4,6);
			var callyear = newDate.slice(0,4);
			
        Months = new Array()
           {
            Months["0" + 1] = "January"
            Months["0" + 2] = "February"
            Months["0" + 3] = "March"
            Months["0" + 4] = "April"
            Months["0" + 5] = "May"
            Months["0" + 6] = "June"
            Months["0" + 7] = "July"
            Months["0" + 8] = "August"
            Months["0" + 9] = "September"
            Months[10] = "October"
            Months[11] = "November"
            Months[12] = "December"
            }
         var monthCall = Months[call];
         var monthCallb = call;	

	switch (whois) //checks the different pages then sets their build conditions.
		{	
		case "Wright": //Wire right panel dates
			setFred = newDate >= today && newDate < date2; //sets date from todate going forward by three months then stops.
			break;
		
		case "Wcal": //Wire right panel dates
			setFredb = newDate >= today && newDate > date2; //sets date from todate going forward by three months then stops.
			break;			
		
		case "HSE": //Home site main page Events
			var setFredd  =  newDate >= today && newDate < date2;			
			break;
			
		case "HSC": //Home site main page Conferences
			var setFredd  =  newDate >= today && newDate < date2;			
			break;
			
		case "HSCP": //Home site calendar page
			var setFredc = newDate <= today; //displays dates up to today
			var setFredch = newDate <= todaych; //displays dates up to today
			break;	
			
		}




	switch (whois) 
		{	
		case "Wright":
			if (setFred){ //build for the Wire right side calendar events
			    if (data.channel.item[a].category == "Webinar" || data.channel.item[a].category == "Virtual Session" || data.channel.item[a].category == "Training" || data.channel.item[a].category == "Holidays"){
				    document.write("<a href='" + data.channel.item[a].link + "' class='right-col-small-nounder'>");
				    document.write("<b class='smdate'>" + data.channel.item[a].date+ "</b>");
				    document.write("<br/>");
				    document.write(data.channel.item[a].title) ;				
                if (!data.channel.item[a].location || data.channel.item[a].location == "Virtual Session" || data.channel.item[a].location == "3 Virtual Sessions") {
               	    var location = "";
                }else{
            	    var location = data.channel.item[a].location;
			    }
				    document.write(" <i class='calendar'>" + data.channel.item[a].category + "&#160;" + location + "</i>");
    	    	    document.write("</a>");				
		  		    document.write("<p class='dotted-bottom'></p>");			
			    }
			}
			break;
		
		case "Wcal": //builds the Wire main calendar page
			if(setFredb) 
				{	

			if(!monthCallbb) // if value is empty to start
				{

				var monthCallbb = monthCallb;
				document.write("&#160;<p/><h2>" + monthCall + "&#160;" + callyear + " </h2><p/>");
	        	document.write("<div class='cal-container-a'>"); 

            }else if(monthCallbb > true ){	// is this value true

			if(monthCallbb == monthCallb)	// if the same don't repeat
				{
					if(!calcolor)
					{
						var calcolor = 2;
						document.write("<div class='cal-container-b'>");	
					}else if(calcolor == 1)	
					{
			         	var calcolor = 2;
						document.write("<div class='cal-container-c'>");  						
					}else if(calcolor == 2)
					{
				        document.write("<div class='cal-container-b'>"); 
						var calcolor = 1;
					}					
				}else{
               		var monthCallbb =call;
					document.write("&#160;<p/><h2>" + monthCall + "&#160;" + callyear + " </h2><p/>");
					var calcolor = 2;
					document.write("<div class='cal-container-a'>");  
				}
           }else{
                var monthCallbb = null ;
            }   
				document.write("<h3 class='main-header'>" + data.channel.item[a].title + "</h3>") ;
				document.write("<br/>");
				document.write("<div class='left-float'><strong>" + data.channel.item[a].date + "</strong></div>");
			if(!data.channel.item[a].description){
				document.write("&#160;<br/>");
				}else{
					document.write("&#160;<p/>");
					document.write( data.channel.item[a].description) ;
				}				
            if (data.channel.item[a].location == null || data.channel.item[a].location == "Virtual Session" || data.channel.item[a].location == "3 Virtual Sessions")
            {
            	var location = "";
            }else{
            	var location = data.channel.item[a].location;
            }
				document.write("<div class='header-right'><i>" + data.channel.item[a].category + "&#160;" + location + "</i></div>");
				document.write("<p>&#160;</p>");
            if (data.channel.item[a].link == null) 
            {
				document.write("&#160;<br/>");
            }else{
            	document.write("<a href='"  + data.channel.item[a].link + "'  class='main-small'>For more information about this training or to register >></a>");				
            }
            document.write("</div>"); 
			}	
			break;
		
		case "WcalP": //builds the Wire calendar previous page
			if(setFredc) // this will now compare the current item to the day today
					{	
				if(!monthCallbb) // if value is empty to start
					{
					var monthCallbb = monthCallb;
					document.write("&#160;<p/><h2>" + monthCall + "&#160;" + callyear + " </h2><p/>");
				 document.write("<div class='cal-container-a'>"); 
				}else if(monthCallbb > true ){	// is this value true
	
				if(monthCallbb == monthCallb)	// if the same don't repeat
					{
						if(!calcolor)
						{
							var calcolor = 2;
							document.write("<div class='cal-container-b'>");
						}else if(calcolor == 1)	
						{
							var calcolor = 2;
							document.write("<div class='cal-container-c'>"); 
						}else if(calcolor == 2)
						{
							document.write("<div class='cal-container-b'>"); 
							var calcolor = 1;
						}
					}else{
						var monthCallbb =call;
						document.write("&#160;<p/><h2>" + monthCall + "&#160;" + callyear + " </h2><p/>");
						var calcolor = 2;
						document.write("<div class='cal-container-a'>");  
					}
			   }else{
					var monthCallbb = null ;
					document.write("&#160;<p/><h2>" + monthCall + "&#160;" + callyear + " </h2><p/>");
					document.write("<div class='cal-container-a'>");  
				
				}   
					document.write("<h3 class='main-header'>" + data.channel.item[a].title + "</h3>") ;
					document.write("<br/>");
					document.write("<div class='left-float'><strong>" + data.channel.item[a].date + "</strong></div>");
			if (!data.channel.item[a].location || data.channel.item[a].location == "Virtual Session" || data.channel.item[a].location == "3 Virtual Sessions")
				{
				var location = "";
				}else{
				var location = data.channel.item[a].location;
				}
					document.write("<div class='header-right'><i>" + data.channel.item[a].category + "&#160;" + location + "</i></div>");
					document.write("<p>&#160;</p>");
			if(!data.channel.item[a].description){
				document.write("&#160;<br/>");
				}else{
					document.write( data.channel.item[a].description) ;
				}
			if (data.channel.item[a].link == null) 
				{
					document.write("&#160;<br/>");
				}else{
					if (data.channel.item[a].location == "Broadcast by HR.com"){
						document.write("<a href='"  + data.channel.item[a].link + "'  class='main-small' target='_new'>View Event >></a>");	
					}else{
						document.write("&#160;<br/>");
					}
					
				}
				document.write("</div>"); 	
			}	
			
			break;
		
		case "HSE": //Home site main page
			if(setFredd)// this will now compare the current item to the day today
			{ 
			    if (data.channel.item[a].category == "Webinar" || data.channel.item[a].category == "Virtual Session" || data.channel.item[a].category == "Training" || data.channel.item[a].category == "Holidays"){
				    {
				        if(!calcolor || calcolor == 1)
					        {
						        var calcolor = 2;
						        document.write("<div class='training-cert-bg'>");						
					        }else if(calcolor == 2)	
					        {
			         	        var calcolor = 1;
						        document.write("<div>"); 
					        }   
			            document.write("<p class='dotted-bottom'>"); 
				        document.write("<a href='" + data.channel.item[a].link + "' class='training-cert-info'>More Info.</a>");
				        document.write("<strong>" + data.channel.item[a].title + "</strong>");
				        document.write("<br/><span class='certifications-date'>" + data.channel.item[a].date+ "</span><br/>");
				        if (data.channel.item[a].location == null)
				        {
					        var location = "";
				        }else{
					        var location = data.channel.item[a].location;
				        }
				        document.write("<em>" + data.channel.item[a].category + "&#160;" +  location  + "</em>");
				        document.write("</p>"); 
				        document.write("</div>"); 
				        }
                }				        
            }	
			break;
            
            
            case "HSC": //Home site main page EConfernces

			if(setFreddie){ // this will now compare the current item to the day today
				if (data.channel.item[a].category == "Conference"){
					if(!calcolor || calcolor == 1)
						{
							var calcolor = 2;
							document.write("<div class='training-cert-bg'>");						
						}else if(calcolor == 2)	
						{
			       		  	var calcolor = 1;
							document.write("<div>"); 
						}   
				    document.write("<p class='dotted-bottom'>"); 
					document.write("<a href='" + data.channel.item[a].link + "' class='training-cert-info'>More Info.</a>");
					document.write("<strong>" + data.channel.item[a].title + "</strong>");
					document.write("<br/><span class='certifications-date'>" + data.channel.item[a].date+ "</span><br/>");
					if (data.channel.item[a].location == null)
					{
						var location = "";
					}else{
						var location = data.channel.item[a].location;
					}
					document.write("<em>" + data.channel.item[a].category + "&#160;" +  location  + "</em>");
					document.write("</p>"); 
					document.write("</div>"); 
					}
			}
		
		break;			
		case "HSCP": //Home site calendar page			

			if(setFredch) // this will now compare the current item to the day today
			{
				var datePast = "grey"; // sets the style to this is event has passed
				var	calLink = ("");
				var	regLink = ("");
			}else{
				var datePast = "";
				var	calLink = ("<a class='calendarMicro' title='Add event to calender' href='" + data.channel.item[a].calendarlink + "'>");
				var	regLink = ("<li><a href='" + data.channel.item[a].registration + "' title='Register for Event'>Register</a></li>");
			}
			
			
		switch (which) //which title from the full calendar page are we sorting
		{				
			case "coaching":			
				var whichTitle = data.channel.item[a].title === "<b><i>Assess</i></b> Coaching Certification";
				break;
				
			case "competency":
				var whichTitle = data.channel.item[a].title === "<b><i>Assess</i></b> Competency Certification";
				break;
				
			case "development":			
				var whichTitle = data.channel.item[a].title === "<b><i>Assess</i></b> Development Certification";
				break;
			
			case "selection":
				var whichTitle = data.channel.item[a].title === "Selection Process Best Practices Seminar";
				break;		
		}
		
		var dropdown = which;		
		
			if (whichTitle)
			{	
				if (titleSet == null)
					{			
						document.write("<div class='event'>");	
						document.write("<strong class='title-color'>" + data.channel.item[a].title + "</strong>");
						var titleSet = 1;
						document.write("<br/><a href='javascript:animatedcollapse.toggle(&#39;" + dropdown +"&#39;)'>Details</a>");						
						document.write("</div>");
					}
				if (!dateSet || dateSet >= 1)
					{
						document.write("<div class='date'>");
						document.write("<span class='" + datePast +"'>" + calLink +  data.channel.item[a].date + "</a></span>") ;
						var dateSet = 1;
						document.write("</div> <!--date set close -->");
					}
				if (!locationSet || locationSet >= 1)
					{
						document.write("<div class='location'>");
						document.write("<ul>");		
						document.write("<li>" + data.channel.item[a].location + "</li>");
						document.write("</ul>");
						document.write("</div>");
						var locationSet = 1;
					}
				if (!registrationSet || registrationSet >= 1)
					{
						document.write("<div class='register'>");
						document.write("<ul>");	
						document.write(regLink);
						document.write("</ul>");
						document.write("</div>");
						var registrationSet = 1;
					}
				}		
	        break;			
		}		
	}       
			
}