/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var courseData;
$(document).ready(function(){
    
    var id_text,courseName,
    coursePrice,
    courseInstructor,
    courseStdate,
    courseEndDate,
    courseTimes,
    courseType,
    courseDuration,
    courseURL;
    $.get("coursedata.xml?uncache="+Math.random(), function(data){
        
        courseData = data;
        var currentPage = document.location.href;
        var splitURL = (currentPage.split("/"));
        currentPage = splitURL[splitURL.length-1];
        // alert(currentPage);
        var index1 = currentPage.indexOf("_");
        var index2 = currentPage.indexOf(".html");
        // alert(index1 + " , " + index2);
        var course_name = currentPage.substr(index1+1,currentPage.length-1- index1-5);
        
		//Fix made by Mani - Refreshing the page after clicking on 'Upcoming Courses' / 'Audience' / 'Course Outline' / 'Print' was not populating
		//the courses - This fix will take care of that.
		if(course_name.indexOf("#") != -1)
			course_name = course_name.substring(0, course_name.indexOf(".html"));

		//alert(course_name);

        var appendTableRows= "<div class=\"request_course\">Please call our Sales Representatives for getting more information about this course. Our Sales Rep are very knowledgable and they will help you decide the course that suits your needs and do not forget to ask about current offers.</div>";
		if("schedules" != course_name)
			
        var indexLoop = 0;

        /*if("schedules" == course_name){
            var onlineBuffer = "";
            onlineBuffer+="<tr><th width=\"20%\">Course</th><th width=\"10%\">Start Date</th><th width=\"10%\">End Date</th><th width=\"10%\">Duration</th><th width=\"10%\">Cost</th><th width=\"15%\">&nbsp;</th></tr>";
            var inclassBuffer = "";
            inclassBuffer+="<tr><th width=\"20%\">Course</th><th width=\"10%\">Start Date</th><th width=\"10%\">End Date</th><th width=\"10%\">Duration</th><th width=\"10%\">Cost</th><th width=\"15%\">&nbsp;</th></tr>";
            var onlineIndex=0;
            var inclassIndex=0;
         $(courseData).find('course').each(function(){
                id_text = $(this).find('id').text();
                courseTypeCheck = $(this).find('type').text();
                // alert(id_text);
                 coursePrice = $(this).find('cost').text();
                    courseInstructor = $(this).find('instructor').text();
                    courseType = $(this).find('type').text();
                    courseStdate = $(this).find('start_date').text();
                    courseEndDate = $(this).find('end_date').text();
                    courseTimes = $(this).find('timings').text();
                    courseDuration = $(this).find('duration').text();
                    courseName = $(this).find('title').text();
                    courseURL = $(this).find('href').text();
                if(courseTypeCheck.indexOf("Virtual/Online")!=-1){

                   
                    if(onlineIndex %2 == 0){
                        onlineBuffer+=" <tr class=\"even\">";
                    }
                    else {
                        onlineBuffer+=" <tr class=\"odd\">";
                    }
                    onlineBuffer+="<td> <a href=\"course_"+courseURL+"\">"+courseName+"</a></td>";
                    onlineBuffer+="<td>"+courseStdate+"</td>";
                    onlineBuffer+="<td>"+courseEndDate+"</td>";
                    onlineBuffer+="<td>"+courseDuration+"</td>";
                   // onlineBuffer+="<td align=\"center\"><img src=\"images/clock.png\" width=\"25\" onmouseover=\"Tip('"+courseTimes+"', BGCOLOR, '#CCCCCC')\" onmouseout=\"UnTip()\"/></td>";
                   // onlineBuffer+="<td>"+courseInstructor+"</td>";
                    onlineBuffer+="<td>"+coursePrice+"</td>";
                    onlineBuffer+="<td ><a style=\"text-decoration:underline;cursor:hand;cursor:pointer;\" id=\""+id_text+"\" title=\"Register\" onClick=\"registerClass(this,'"+id_text+"')\" >More Info &amp; Register</a></td>";
                    onlineBuffer+="</tr>";

                    onlineIndex++;
                }else{
                    if(inclassIndex %2 == 0){
                        inclassBuffer+=" <tr class=\"even\">";
                    }
                    else {
                        inclassBuffer+=" <tr class=\"odd\">";
                    }
                    inclassBuffer+="<td><a <a href=\"course_"+courseURL+"\">"+courseName+"</a></td>";
                    inclassBuffer+="<td>"+courseStdate+"</td>";
                    inclassBuffer+="<td>"+courseEndDate+"</td>";
                    inclassBuffer+="<td>"+courseDuration+"</td>";
                    //inclassBuffer+="<td align=\"center\"><img src=\"images/clock.png\" width=\"25\" onmouseover=\"Tip('"+courseTimes+"', BGCOLOR, '#CCCCCC')\" onmouseout=\"UnTip()\"/></td>";
                    //inclassBuffer+="<td>"+courseInstructor+"</td>";
                    inclassBuffer+="<td>"+coursePrice+"</td>";
                    inclassBuffer+="<td ><a style=\"text-decoration:underline;cursor:hand;cursor:pointer;\" id=\""+id_text+"\" title=\"Register\" onClick=\"registerClass(this,'"+id_text+"')\" >More Info &amp; Register</a></td>";
                    inclassBuffer+="</tr>";

                    inclassIndex++;
                }
            });
           // alert(onlineBuffer);
            $("#online_schedule_info").html(onlineBuffer);
            $("#inclass_schedule_info").html(inclassBuffer);
        }
        else{ */
            $(courseData).find('course').each(function(){
				
                id_text = $(this).find('id').text();
                // alert(id_text);
                if(id_text.indexOf(course_name)!=-1){
                    if(indexLoop == 0){
						appendTableRows="";
					appendTableRows+="<tr><th>Start Date</th><th>End Date</th><th>Duration</th><th>Class Type</th><th>Cost</th><th>&nbsp;</th></tr>";
				}
                    coursePrice = $(this).find('cost').text();
                    courseInstructor = $(this).find('instructor').text();
                    courseType = $(this).find('type').text();
                    courseStdate = $(this).find('start_date').text();
                    courseEndDate = $(this).find('end_date').text();
                    courseTimes = $(this).find('timings').text();
                    courseDuration = $(this).find('duration').text();
                    if(indexLoop %2 == 0){
                        appendTableRows+=" <tr class=\"even\">";
                    }
                    else {
                        appendTableRows+=" <tr class=\"odd\">";
                    }
                    appendTableRows+="<td>"+courseStdate+"</td>";
                    appendTableRows+="<td>"+courseEndDate+"</td>";
                    appendTableRows+="<td>"+courseDuration+"</td>";
					//appendTableRows+="<td align=\"center\"><img src=\"images/clock.png\" width=\"25\" onmouseover=\"Tip('"+courseTimes+"', BGCOLOR, '#CCCCCC')\" onmouseout=\"UnTip()\"/></td>";
                    appendTableRows+="<td>"+courseType+"</td>";
                    //appendTableRows+="<td>"+courseInstructor+"</td>";
                    appendTableRows+="<td>"+coursePrice+"</td>";
                    appendTableRows+="<td  ><a id=\""+id_text+"\" title=\"Register\" onClick=\"registerClass(this,'"+id_text+"')\" style=\"text-decoration:underline;cursor:hand;cursor:pointer;\" >More Info &amp; Register</a></td>";
                    appendTableRows+="</tr>";
                    
                    indexLoop++;
                }
            });
            //alert(appendTableRows);
            $("#schedule_info").html(appendTableRows);
        //}
        
    });
    
	//	$("#container").before("<div id=\"top-most-links\" ><ul><li><a href=\"http://upgradeitskill.wordpress.com/\" target=\"_blank\"><img src=\"images/blogger_16.png\" title=\"UpgradeITSkills Adobe Training Blog\"/>&nbsp;Blog</a></li><li><a href=\"http://www.linkedin.com/groups?gid=2634277&trk=myg_ugrp_ovr\" target=\"_blank\"><img src=\"images/linkedin_16.png\" title=\"UpgradeITSkills Adobe Training Linked In\"/>&nbsp;Linked-In</a></li><li><a href=\"https://twitter.com/UpgradeITSkills\" target=\"_blank\"><img src=\"images/twitter_16.png\" title=\"Follow UpgradeITSkills Adobe Training on Twitter\"/>&nbsp;Twitter</a></li><li><a href=\"faq_training.html\" ><img src=\"images/help.png\" title=\"UpgradeITSkills Adobe Training Frequently Asked Questions \"/>&nbsp;FAQ</a></li></ul></div>");
    // load the side bar, saving it in one place.
    $("#container #nav").load("topnav.html?uncache="+Math.random());

    $("#container #top").load("bannerbar.html?uncache="+Math.random());
    
    $(".sidebar .content").load("sidebar.html?uncache="+Math.random());

    $(".right-sidebar #right-sidebar-content").load("right_sidebar.html?uncache="+Math.random());

    $("#register_course").load("registercoursehidden.html");
//  alert(courseData);
	$("#footer").after("<div id=\"top-most-links\" ><ul><li><a href=\"http://upgradeitskill.wordpress.com/\" target=\"_blank\"><img src=\"images/blogger_16.png\" title=\"UpgradeITSkills Adobe Training Blog\"/>&nbsp;Blog</a></li><li><a href=\"http://www.linkedin.com/groups?gid=2634277&trk=myg_ugrp_ovr\" target=\"_blank\"><img src=\"images/linkedin_16.png\" title=\"UpgradeITSkills Adobe Training Linked In\"/>&nbsp;Join us-Linked-In</a></li><li><a href=\"https://twitter.com/UpgradeITSkills\" target=\"_blank\"><img src=\"images/twitter_16.png\" title=\"Follow UpgradeITSkills Adobe Training on Twitter\"/>&nbsp;Follow on Twitter</a></li><li><a href=\"faq_training.html\" ><img src=\"images/help.png\" title=\"UpgradeITSkills Adobe Training Frequently Asked Questions \"/>&nbsp;FAQ</a></li></ul></div>");
   
});

function registerClass(currentAnchor,id_Clicked){
      
    var id_text,courseName,
    coursePrice,
    courseInstructor,
    courseStdate,
    courseEndDate,
    courseTimes,
    courseType,
    courseDuration;
    //alert(currentAnchor).attr("id") ;
    //alert(courseData);

    $(courseData).find('course').each(function(){
        id_text = $(this).find('id').text();
        // alert(id_text + " = = "+ id_Clicked);
        if(id_Clicked == id_text){
            courseName = $(this).find('title').text();
            coursePrice = $(this).find('cost').text();
            courseInstructor = $(this).find('instructor').text();
            courseType = $(this).find('type').text();
            courseStdate = $(this).find('start_date').text();
            courseEndDate = $(this).find('end_date').text();
            courseTimes = $(this).find('timings').text();
            courseDuration = $(this).find('duration').text();
        }
    });

    $('#courseName').text(courseName);
    $('#coursePrice').text(coursePrice);
    $('#courseInstructor').text(courseInstructor);
    $('#courseType').text(courseType);
    $('#courseDates').text(courseStdate+" - " + courseEndDate);
    $('#courseTime').text(courseTimes);
    $('#courseDuration').text(courseDuration);


        
    //alert(currentAnchor.text);

    $(this).attr({
        href : "#TB_inline?height=540&width=675&inlineId=register_course"
    });
   
    tb_show(currentAnchor.text,$(this).attr("href"),false);
}

function showSchedules(course_name){

	var id_text,courseName,
    coursePrice,
    courseTitle,
    courseStdate,
    courseEndDate,
    courseType,
	courseURL,
    courseDuration;

        var appendTableRows= "Please call our Sales Representatives for getting more information about this course. Our Sales Rep are very knowledgable and they will help you decide the course that suits your needs and do not forget to ask about current offers.";	indexLoop = 0;

    $(courseData).find('course').each(function(){
		
        id_text = $(this).find('id').text();

		if(id_text.indexOf(course_name)!=-1){
			if(indexLoop == 0){
					appendTableRows="";
					appendTableRows+="<tr><th>Start Date</th><th>End Date</th><th>Duration</th><th>Class Type</th><th>Cost</th><th>&nbsp;</th></tr>";
				}
			coursePrice = $(this).find('cost').text();
			courseTitle = $(this).find('title').text();
			courseType = $(this).find('type').text();
			courseStdate = $(this).find('start_date').text();
			courseEndDate = $(this).find('end_date').text();
			courseDuration = $(this).find('duration').text();
			courseURL = $(this).find('href').text();

			if(indexLoop %2 == 0){
				appendTableRows+=" <tr class=\"even\">";
			}
			else {
				appendTableRows+=" <tr class=\"odd\">";
			}
			appendTableRows+="<td><a href=\"course_"+courseURL+"\">" + courseTitle + "</a></td>";
			appendTableRows+="<td>"+courseStdate+"</td>";
			appendTableRows+="<td>"+courseEndDate+"</td>";
			appendTableRows+="<td nowrap>"+courseDuration+"</td>";
			appendTableRows+="<td nowrap>"+courseType+"</td>";
			appendTableRows+="<td>"+coursePrice+"</td>";
			appendTableRows+="<td nowrap><a id=\""+id_text+"\" title=\"Register\" onClick=\"registerClass(this,'"+id_text+"')\" style=\"text-decoration:underline;cursor:hand;cursor:pointer;\" >More Info &amp; Register</a></td>";
			appendTableRows+="</tr>";
			
			indexLoop++;
		}
	
		$("#schedule_info").html(appendTableRows);
	});
}

/*
function launchPayPal(){
    window.open('https://www.paypal.com/cgi-bin/webscr?image%5Furl=http%3A%2F%2Fwww%2Emyflextrainer%2Ecom%2Fassets%2Fatcs%5Flogo%2Ejpg&cmd=%5Fcart&quantity%5F1=1&amount%5F1='+$('#coursePrice').text()+'&business=billing%40myflextrainer%2Ecom&item%5Fname%5F1='+$('#courseName').text()+'&test=Something&currency%5Fcode=USD&upload=1');
}
*/

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-12619346-1");
pageTracker._trackPageview();
} catch(err) {}   