﻿/* =============================================================================
General Functions
================================================================================
Used as genreal functions that can be used through the entire website
----------------------------------------------------------------------------- */

var _PopupWindow;

function $pop(ur, ht, wt, ad) //popup window
{
	if (ad) //auto-dimension
	{
		ht = screen.height;
		wt = screen.width;
	}
	_PopupWindow = window.open(ur,'','height='+ht+',width='+wt+',screenX=0,screenY=0,left=0,top=0,toolbar=1,status=1,scrollbars=1,resize=1,menubar=1,resizeable=1,location=1,directories=1');
}

function $epop(el, ht, wt, ad)
{
    if (el != '')
    {
        var e = $(el);
        if (e) 
        {
            e.addEvent('click', function(event) {
                event.stop();
                $pop(e.get('href'), ht, wt, ad);
            }); 
        }
    }
}

function $pops(ht, wt, ad)
{
    //fetch all hyperlinks within the element.
    $$('a').each(function(item, index) {
        item.addEvent('click', function(event) {
            event.stop();
            $pop(item.get('href'), ht, wt, ad);
        });  
    });
}

function $forms(ht, wt, ad)
{
    //fetch all forms within the element.
    $$('form').each(function(item, index) {
        item.addEvent('submit', function(event) {
            event.stop();
            $pop(item.get('action'), ht, wt, ad);
        });  
    });
}

function $dropdowns(ht, wt, ad)
{
    //fetch all dropdowns within the element.
    $$('select').each(function(item, index) {
        item.removeEvents('change');
        item.addEvent('change', function(event) {     
            if (item.options[item.selectedIndex].value != '') { 
                $pop(item.options[item.selectedIndex].value, ht, wt, ad); 
                return false; 
            }
            }); 
    });
}

function $popext(ht, wt, ad)
{
    //fetch all hyperlinks within the element.
    $$('a.popup').each(function(item, index) {
        item.set('title', item.get('title') + ' (opens in new window)');
        item.addEvent('click', function(event) {
            event.stop();
            $pop(item.get('href'), ht, wt, ad);
        });  
    });
    
    $$('a.popup750x650').each(function(item, index) {
        item.set('title', item.get('title') + ' (opens in new window)');
        item.addEvent('click', function(event) {
            event.stop();
            $pop(item.get('href'), 750, 650, false);
        });  
    });
}

function $epopext(el, ht, wt, ad)
{
    //fetch all hyperlinks within the element.
    var allAnchors = el.getElements('a.popup');
    
    allAnchors.each(function(item, index) {
        item.set('title', item.get('title') + ' (opens in new window)');
        item.addEvent('click', function(event) {
            event.stop();
            $pop(item.get('href'), ht, wt, ad);
        });  
    });
    
    allAnchors = el.getElements('a.popup750x650');
    
    allAnchors.each(function(item, index) {
        item.set('title', item.get('title') + ' (opens in new window)');
        item.addEvent('click', function(event) {
            event.stop();
            $pop(item.get('href'), 750, 650, false);
        });  
    });
}
var CWElement;
var CWLink;
function $cw(u, w, h, l, t, bg) //create window.
{
    if (!CWElement) { CWElement = new Element('div', {'id':'systemWindowPopup'});  CWElement.inject($(document.body)); } else { CWElement.fade('out'); }
    CWElement.setStyle('position', 'absolute');
    CWElement.setStyle('background-color', bg);
    CWElement.setStyle('width', w);
    CWElement.setStyle('height', h);
    CWElement.setStyle('left', l);
    CWElement.setStyle('top', t);
    CWLink = new Element('a');
    CWLink.set('href','javascript:$cw_exit();');
    CWElement.empty();
    CWLink.inject($(CWElement));
	CWLink.load(u).fade('in');
	CWElement.fade('in');
}

function $cw_exit()
{
    CWElement.fade('out');
}

function $prt() //print page
{
	if (window.print) { window.print(); }
}

function $dsb(btn) //disable a button on submit.
{
    var e = $(btn);
    //add the disable function to the event.
    if (e) {
        e.addEvent('click', function(event) {
            event.stop();
            e.fade(0.3); e.disabled = true; e.set('style', 'cursor: default;');
            //submit the form.
            $('aspnetForm').submit();
       });
    }
}

function $dsblist(ctrl, ctrlList) //disable controls by using another control.
{
    var e = $(ctrl); //being clicked.
    var disableArray = ctrlList.split(';'); //being disabled.
    //add the disable function to the event.
    if (e) {
        e.addEvent('click', function(event) {
              disableArray.each(function(item, index){
                var e2 = $(item);
                if (e2) {
                    if (e2.disabled == true)
                    { e2.fade('in'); e2.fade(1); e2.disabled = false; } else {
                      e2.fade('out'); e2.fade(0.3); e2.disabled = true; }
                }
                });
            });
    }
    if (e)
    {
        if (e.checked) { 
            disableArray.each(function(item, index){
                var e2 = $(item);
                    if (e2) {
                        e2.fade('out'); e2.fade(0.3); e2.disabled = true; 
                        }
            });
        }
    }
}

/* =============================================================================
Slide Animation
================================================================================
Used for online student community compact.
----------------------------------------------------------------------------- */

//slide in and out timer.
var slide_rtl_timer;
var slide_counter = 1;

function osccompact(lines)
{
    $slide_rtl(lines);
}

function $slide_rtl(lines)
{
    var timer = 5000;
    $clear(slide_rtl_timer);
    
    var timeout = (function() {
        var entArray = lines.split('|');
        //perform random extract and change
        //var rnd = $random(0, entArray.length - 1);
        var entity = entArray[slide_counter];
        
        if ($('osccompact') || $('osccompact') == null) { return; }
        var widthChange = new Fx.Tween($('osccompact'));
            widthChange.set('tween', {duration: 'medium'});
            
        widthChange.start('margin-left', [114, 0]);
        (function() { $('osctext').set('html', entity); }).delay(100);
        widthChange.start('margin-left', [0, 114]);
        
        slide_counter++;
        if (slide_counter > entArray.length - 1) { slide_counter = 0; }
        
    });
    slide_rtl_timer = timeout.periodical(timer);
}


/* =============================================================================
Slide Animation
================================================================================
Used for Ten Great Reasons compact.
----------------------------------------------------------------------------- */

//slide in and out timer.
var slide_rtl_timer;
var slide_counter = 1;

function tgrcompact(lines)
{
    $slide_rtl(lines);
}

function $slide_rtl(lines)
{
    var timer = 5000;
    $clear(slide_rtl_timer);
    
    var timeout = (function() {
        var entArray = lines.split('|');
        //perform random extract and change
        //var rnd = $random(0, entArray.length - 1);
        var entity = entArray[slide_counter];
        
        if ($('tgrcompact') || $('tgrcompact') == null) { return; }
        var widthChange = new Fx.Tween($('tgrcompact'));
            widthChange.set('tween', {duration: 'medium'});
            
        widthChange.start('margin-left', [114, 0]);
        (function() { $('tgrtext').set('html', entity); }).delay(100);
        widthChange.start('margin-left', [0, 114]);
        
        slide_counter++;
        if (slide_counter > entArray.length - 1) { slide_counter = 0; }
        
    });
    slide_rtl_timer = timeout.periodical(timer);
}


/* =============================================================================
Rotation Animation
================================================================================
Used for featured course and what our students say.
----------------------------------------------------------------------------- */

function featcourse(cont, imglink, img, link)
{
    $rot_fc(cont, imglink, img, link);
}

function $rot_fc(cont, imglink, img, link)
{
    //entities data.
    //CourseName|CourseUrl|QualificationImage|QualificationDescription,
    //CourseName|CourseUrl|QualificationImage|QualificationDescription
    
    //timer.
    var timer = 6000;
    
    //determine if the entities exist.
    $clear(periodical);
    //find a random number according to the length.
    var refresh = (function() {
	    var entArray = entities.split(',');
        //perform random extract and change
        var rnd = $random(0, entArray.length - 1);
        var entity = entArray[rnd];
        var eArray = entity.split('|');
        
        //set the image.
        imglink.set('href', eArray[1]);
        img.set('src', eArray[2]);
        img.set('alt', eArray[3]);
        img.set('title', eArray[3]);
        
        //set the link.
        link.set('html', eArray[0]);
        link.set('href', eArray[1]);    
    });
    periodical = refresh.periodical(timer);
}


/* =============================================================================
Payment Process - Card Start Date and Issue Number
================================================================================
Used to show and hide the date and issue fields.
----------------------------------------------------------------------------- */

function $card_hasdates()
{
    var e = $('ctl00_cphMiddle_cboCardType');
    if (e) {
        //add intercept event to show or hide start and issue fields.
        e.addEvent('change', function(event) {
            switch(e.options[e.selectedIndex].value)
            {
                case 'Please Select':
                case 'MasterCard':
                case 'Visa':
                case 'Visa Debit':
                case 'Visa Electron':
                    //hide the start date list item.
                    $$('li.start_date_checker').each(function(item, index) {
                        item.fade('out').fade(0);
                        item.setStyle('display', 'none');
                    });
                    //hide the issue number list item.
                    $$('li.issue_number_checker').each(function(item, index) {
                        item.fade('out').fade(0);
                        item.setStyle('display', 'none');
                    });
                    break;
                case 'Maestro':
                case 'Solo':
                    //show the start date list item.
                    $$('li.start_date_checker').each(function(item, index) {
                        item.fade('in').fade(1);
                        item.setStyle('display', 'block');
                    });
                    //hide the issue number list item.
                    $$('li.issue_number_checker').each(function(item, index) {
                        item.fade('in').fade(1);
                        item.setStyle('display', 'block');
                    });
                    break;
            }
        });
        
        //check which option is currently selected.
        switch(e.options[e.selectedIndex].value)
        {
            case 'Please Select':
            case 'MasterCard':
            case 'Visa':
            case 'Visa Debit':
            case 'Visa Electron':
                //hide the start date list item.
                $$('li.start_date_checker').each(function(item, index) {
                    item.fade('out').fade(0);
                    item.setStyle('display', 'none');
                });
                //hide the issue number list item.
                $$('li.issue_number_checker').each(function(item, index) {
                    item.fade('out').fade(0);
                    item.setStyle('display', 'none');
                });
                break;
            case 'Maestro':
            case 'Solo':
                //show the start date list item.
                $$('li.start_date_checker').each(function(item, index) {
                    item.fade('in').fade(1);
                    item.setStyle('display', 'block');
                });
                //hide the issue number list item.
                $$('li.issue_number_checker').each(function(item, index) {
                    item.fade('in').fade(1);
                    item.setStyle('display', 'block');
                });
                break;
        }
    }
 
    return false;
}

/* =============================================================================
Request Information - Find Your Address
================================================================================
Used to show and hide the address finder.
----------------------------------------------------------------------------- */

function $ad_show()
{
    //show the address finder section.
    $('find_your_address').setStyle('display', 'block');
    $('find_your_address').fade('in').fade(1);
    $('hide_your_address').fade('out').fade(0);
    $('hide_your_address').setStyle('display', 'none');
    return false;
}

function $ad_hide()
{
    //hide the address finder section.
    $('find_your_address').fade('out').fade(0);
    $('find_your_address').setStyle('display', 'none');
    $('hide_your_address').setStyle('display', 'block');
    $('hide_your_address').fade('in').fade(1);
    return false;
}

/* =============================================================================
Videos - ASP Net Flash Javascript API
================================================================================
Used to control videos loaded on a web page.
----------------------------------------------------------------------------- */

function $vid(video, cssclass)
{
    var vid = ASPNetMedia.FlashVideo(video);   
    vid.OnFinish = function(object, position) { vid.SetPosition(0.5); }
    
    vid.OnPlay = function(object, position) {
        $$('div.' + cssclass).each(function(item, index) {
            if (video != item.get('id')) {
                var ovd = ASPNetMedia.FlashVideo(item.get('id'));
                if (ovd) { ovd.PauseMedia(); }
            }
        });
    }
}

/* =============================================================================
Social Bookmarks
================================================================================
Used to dynamically create the markup for a social bookmarks control
----------------------------------------------------------------------------- */

var titlePrefix = 'Home Learning College - ';

var SocialBookmarks = new Class({
	initialize: function() {
		this._BookmarkArray = new Array();
	},
	add: function(cs, ur, vl) { 
		//class, url, value
		this._BookmarkArray.extend(['<li class="'+cs+'"><a href="'+ur+'" onclick="$pop(this.href, 0, 0, true); return false;">'+vl+'</a></li>']);
	},
	tostring: function() {
		var html = '';
		html += '<ul>';

		this._BookmarkArray.each(function(item, index) {
			html += item;
		});

		html += '</ul>';
		return html;
	}
});

function SocialBookmarking(ur, tl, id)
{
    //add to domain to the url.
    var domain = '';
    if (location.protocol) { domain += location.protocol + '//'; }
    if (location.hostname) { domain += location.hostname; }
    if (location.port) { domain += ':' + location.port; }
    if (!ur.contains(domain)) { ur = domain + ur; }
        
	//encode the parameters.
	if (ur) { ur = encodeURIComponent(ur); }
	if (tl) { tl = encodeURIComponent(titlePrefix + tl); }

	//add social bookmarks.
	var sbs = new SocialBookmarks();
	//delicious.
	sbs.add('delicious', 'http://del.icio.us/post?url='+ur+'&title='+tl, 'Delicious');
	//digg.
	sbs.add('digg', 'http://digg.com/submit?phase=2&url='+ur+'&title='+tl, 'Digg');
	//facebook.
	sbs.add('facebook', 'http://www.facebook.com/sharer.php?u='+ur+'&t='+tl, 'Facebook');
	
	var html = '';
	html += '<p>Bookmark with: <a href="/SiteInformation/Social-Bookmarking-Links/">What&rsquo;s this?</a></p>';
	html += '<div class="social_links">';
	html += sbs.tostring();
	html += '</div>';
	html += '<div class="facility_links">';
	html += '<ul><li class="print_this_page"><a href="" onclick="$prt(); return false;">Print this page</a></li>';
	html += '<li class="email_this_page"><a href="/SiteInformation/Email-This-Page/?page='+id+'">Email this page</a></li></ul>';
	html += '</div>';
	
	return html;
}

//Featured Course Ajax

var FCRR;
var FeaturedCourseRotatorTimer;
var FeaturedCourseElement;
var FeaturedCourseSite;
var FeaturedCourseType;
var FeaturedCourseIndex;
var FeaturedCourseCurrent;
var FCCRCount = 1;

function RotateFeaturedCourse(element, site, type, index, current)
{
    FCRR = new FeaturedCourseRotator(element, site, type, index, current);
    FCRR.makerequest();
    var refresh = (function() {
	    FCRR.rotate();     
    });
    periodical = refresh.periodical(6000);
}

var FeaturedCourseRotator = new Class({
    initialize: function(element, site, type, index, current) {
        FeaturedCourseSite = site;
        FeaturedCourseType = type;
        FeaturedCourseIndex = index;
        FeaturedCourseCurrent = current;
        FeaturedCourseElement = $(element);
    },
    loadajax: function() {
        var _AjaxLoaderHtml = '';
        FeaturedCourseElement.set('html', _AjaxLoaderHtml);
    },
    loadrequest: function() {
        var r;
        //r = new Request.Html({method: 'get', url: '/CMSGlobalFiles/FeaturedCourse.aspx', evalScripts: true});
        var r = new Request.HTML({url:'/SiteInformation/Ajax/FeaturedCourse/'});

        // Wire up the event handlers
	    //request.onComplete = LoadTabContentSuccess;
	    r.onSuccess = this.loadsuccess;
	    //request.onException = LoadTabContentFailure;
	    r.onFailure = this.loadfailure;
	    // Send the request
	    var valCurrent = '';
	    if (FeaturedCourseType == '2') { '&ci=' + FeaturedCourseCurrent; }
	    r.get('/SiteInformation/Ajax/FeaturedCourse/?sd=' + FeaturedCourseSite + '&ct=' + FeaturedCourseType + '&cv=' + FeaturedCourseIndex + valCurrent);
	    //alert('/CMSGlobalFiles/FeaturedCourse.aspx' + 'sd=' + this.Site + '&ct=' + this.Type + '&cv=' + this.Index + 'ci=' + this.Current);
	    //alert('sd=' + this.Site + '&ct=' + this.Type + '&cv=' + this.Index + 'ci=' + this.Current);
    },
    helloworld: function(html) {
        var divText;
	    divText = new Element('div', {'class': 'text'});
	    divText.adopt(html);
	    FeaturedCourseElement.set('html', '');
	    FeaturedCourseElement.adopt(divText);
    },
    loadsuccess: function(html) {
        var divText;
	    divText = new Element('div', {'class': 'text'});
	    divText.adopt(html);
	    FeaturedCourseElement.set('html', '');
	    FeaturedCourseElement.adopt(divText);
    },
    loadfailure: function() {
        //this.loadcontent('<p>Sorry, there was an error processing your request. Please try clicking the tab again.</p>');
    },
    makerequest: function() {
        this.loadajax();
        this.loadrequest();
    },
    rotate: function() {
        //alert('working');
        FCCRCount++;
        //alert('count;'+T5Count);
        var divs = FeaturedCourseElement.getElements('div.featured_course');
        divs.each(function(item, index) {
            if ((index+1) == FCCRCount)
            {
                item.setStyle('display', 'block');
            } else {
                item.setStyle('display', 'none');
            }
        });
        if (FCCRCount >= divs.length) { FCCRCount=0; }
    }
});

//Partner Logo Rotation

var PTLR;
var PTLRRotatorTimer;
var PTLRElement;
var PTLRCount = 1;

function RotatePartnerLogos(element)
{
    PTLR = new PTLRRotator(element);
    var refresh = (function() {
	    PTLR.rotate();     
    });
    var PTLRperiodical = refresh.periodical(8000);
}

var PTLRRotator = new Class({
    initialize: function(element) {
        PTLRElement = $(element);
    },
    rotate: function() {
        //alert('working');
        PTLRCount++;
        //alert('count;'+T5Count);
        var divs = PTLRElement.getElements('div.partner_logos');
        divs.each(function(item, index) {
            if ((index+1) != PTLRCount)
            {
                item.fade('out').fade(0); item.setStyle('display', 'none');
            }
        });
        divs.each(function(item, index) {
            if ((index+1) == PTLRCount)
            {
                item.setStyle('display', 'block'); item.fade('in').fade(1);
            }
        });
        if (PTLRCount >= divs.length) { PTLRCount=0; }
    }
});

//Banner Management Rotation

var BANNR;
var BANNRRotatorTimer;
var BANNRElement;
var BANNRCount = 1;

function RotateBanner(element)
{
    BANNR = new BannerRotator(element);
    var refresh = (function() {
	    BANNR.rotate();     
    });
    periodical = refresh.periodical(5000);
}

var BannerRotator = new Class({
    initialize: function(element) {
        BANNRElement = $(element);
    },
    rotate: function() {
        //alert('working');
        BANNRCount++;
        //alert('count;'+T5Count);
        var divs = BANNRElement.getElements('div.banner_rotate');
        divs.each(function(item, index) {
            if ((index+1) == BANNRCount)
            {
                item.setStyle('display', 'block');
            } else {
                item.setStyle('display', 'none');
            }
        });
        if (BANNRCount >= divs.length) { BANNRCount=0; }
    }
});

//Top Five Courses Ajax

var T5;
var T5Timer;
var T5Element;
var T5Site;
var T5Version;
var T5Count = 1;

function RotateTop5(element, site, version)
{
    T5 = new Top5Rotator(element, site, version);
    T5.makerequest();
    periodical = T5Refresh.periodical(5000);
}

var T5Refresh = (function() {
            T5.rotate();
        });

var Top5Rotator = new Class({
    initialize: function(element, site, version) {
        T5Site = site;
        T5Version = version;
        T5Element = $(element);
    },
    loadajax: function() {
        var _AjaxLoaderHtml = '';
        T5Element.set('html', _AjaxLoaderHtml);
    },
    loadrequest: function() {
        var r;
        //r = new Request.Html({method: 'get', url: '/CMSGlobalFiles/FeaturedCourse.aspx', evalScripts: true});
        var r = new Request.HTML({url:'/SiteInformation/Ajax/TopFiveCourses/'});

        // Wire up the event handlers
	    //request.onComplete = LoadTabContentSuccess;
	    r.onSuccess = this.loadsuccess;
	    //request.onException = LoadTabContentFailure;
	    r.onFailure = this.loadfailure;
	    // Send the request
	    r.get('/SiteInformation/Ajax/TopFiveCourses/?sd=' + T5Site + '&vr=' + T5Version);
	    //alert('/CMSGlobalFiles/FeaturedCourse.aspx' + 'sd=' + this.Site + '&ct=' + this.Type + '&cv=' + this.Index + 'ci=' + this.Current);
	    //alert('sd=' + this.Site + '&ct=' + this.Type + '&cv=' + this.Index + 'ci=' + this.Current);
    },
    helloworld: function(html) {
        var divText;
	    divText = new Element('div', {'class': 'text'});
	    divText.adopt(html);
	    T5Element.set('html', '');
	    T5Element.adopt(divText);
    },
    loadsuccess: function(html) {
        var divText;
	    divText = new Element('div', {'class': 'text'});
	    divText.adopt(html);
	    T5Element.set('html', '');
	    T5Element.adopt(divText);
    },
    loadfailure: function() {
        //this.loadcontent('<p>Sorry, there was an error processing your request. Please try clicking the tab again.</p>');
    },
    makerequest: function() {
        this.loadajax();
        this.loadrequest();
    },
    rotate: function() {
        T5Count++;       
        var divs = T5Element.getElements('div.top_five_course');
        divs.each(function(item, index) {
            if (index == (T5Count-1))
            {
                item.setStyle('display', 'block');
            } else {
                item.setStyle('display', 'none');
            }
        });
        //reset the timers.
        if (T5Count == (divs.length)) { $clear(periodical); periodical = T5Refresh.periodical(30000); } else 
                                          { $clear(periodical); periodical = T5Refresh.periodical(5000); }
        if (T5Count > (divs.length - 1)) { T5Count=0; }
    }
});





//Rotate Top Ten Partners Ajax

var T10P;
var T10PTimer;
var T10PElement;
var T10PSite;
var T10PVersion;
var T10PCount = 1;

function RotateTop10(element, site, version)
{
    T10P = new Top10Rotator(element, site, version);
    T10P.makerequest();
    periodical = T10PRefresh.periodical(5000);
}

var T10PRefresh = (function() {
            T10P.rotate();
        });

var Top10Rotator = new Class({
    initialize: function(element, site, version) {
        T10PSite = site;
        T10PVersion = version;
        T10PElement = $(element);
    },
    loadajax: function() {
        var _AjaxLoaderHtml = '';
        T10PElement.set('html', _AjaxLoaderHtml);
    },
    loadrequest: function() {
        var r;
        //r = new Request.Html({method: 'get', url: '/CMSGlobalFiles/FeaturedCourse.aspx', evalScripts: true});
        var r = new Request.HTML({url:'/SiteInformation/Ajax/TopTenPartners/'});

        // Wire up the event handlers
	    //request.onComplete = LoadTabContentSuccess;
	    r.onSuccess = this.loadsuccess;
	    //request.onException = LoadTabContentFailure;
	    r.onFailure = this.loadfailure;
	    // Send the request
	    r.get('/SiteInformation/Ajax/TopTenPartners/?sd=' + T10PSite + '&vr=' + T10PVersion);
	    //alert('/CMSGlobalFiles/FeaturedCourse.aspx' + 'sd=' + this.Site + '&ct=' + this.Type + '&cv=' + this.Index + 'ci=' + this.Current);
	    //alert('sd=' + this.Site + '&ct=' + this.Type + '&cv=' + this.Index + 'ci=' + this.Current);
    },
    helloworld: function(html) {
        var divText;
	    divText = new Element('div', {'class': 'text'});
	    divText.adopt(html);
	    T10PElement.set('html', '');
	    T10PElement.adopt(divText);
    },
    loadsuccess: function(html) {
        var divText;
	    divText = new Element('div', {'class': 'text'});
	    divText.adopt(html);
	    T10PElement.set('html', '');
	    T10PElement.adopt(divText);
    },
    loadfailure: function() {
        //this.loadcontent('<p>Sorry, there was an error processing your request. Please try clicking the tab again.</p>');
    },
    makerequest: function() {
        this.loadajax();
        this.loadrequest();
    },
    rotate: function() {
        T10PCount++;       
        var divs = T10PElement.getElements('div.top_ten_partner');
        divs.each(function(item, index) {
            if (index == (T10PCount-1))
            {
                item.setStyle('display', 'block');
            } else {
                item.setStyle('display', 'none');
            }
        });
        //reset the timers.
        if (T10PCount == (divs.length)) { $clear(periodical); periodical = T10PRefresh.periodical(30000); } else 
                                          { $clear(periodical); periodical = T10PRefresh.periodical(5000); }
        if (T10PCount > (divs.length - 1)) { T10PCount=0; }
    }
});







//Gender Course Ajax

var GCRR;
var GenderCourseRotatorTimer;
var GenderCourseElement;
var GenderCourseCourse;
var GenderCourseCourseArea;
var GenderCourseGender;
var GenderCount = 1;

function RotateGenderCourse(element, course, coursearea, gender)
{
    GCRR = new GenderCourseRotator(element, course, coursearea, gender);
    GCRR.makerequest();
    var refresh = (function() {
	    GCRR.rotate();     
    });
    periodical = refresh.periodical(6000);
}

var GenderCourseRotator = new Class({
    initialize: function(element, course, coursearea, gender) {
        GenderCourseCourse = course;
        GenderCourseCourseArea = coursearea;
        GenderCourseGender = gender;
        GenderCourseElement = $(element);
    },
    loadajax: function() {
        var _AjaxLoaderHtml = '';
        GenderCourseElement.set('html', _AjaxLoaderHtml);
    },
    loadrequest: function() {
        var r;
        //r = new Request.Html({method: 'get', url: '/CMSGlobalFiles/FeaturedCourse.aspx', evalScripts: true});
        var r = new Request.HTML({url:'/SiteInformation/Ajax/GenderCourses/'});

        // Wire up the event handlers
	    //request.onComplete = LoadTabContentSuccess;
	    r.onSuccess = this.loadsuccess;
	    //request.onException = LoadTabContentFailure;
	    r.onFailure = this.loadfailure;
	    // Send the request
	    r.get('/SiteInformation/Ajax/GenderCourses/?cr=' + GenderCourseCourse + '&ca=' + GenderCourseCourseArea + '&gn=' + GenderCourseGender);
	    //alert('/CMSGlobalFiles/FeaturedCourse.aspx' + 'sd=' + this.Site + '&ct=' + this.Type + '&cv=' + this.Index + 'ci=' + this.Current);
	    //alert('sd=' + this.Site + '&ct=' + this.Type + '&cv=' + this.Index + 'ci=' + this.Current);
    },
    helloworld: function(html) {
        var divText;
	    divText = new Element('div', {'class': 'text'});
	    divText.adopt(html);
	    GenderCourseElement.set('html', '');
	    GenderCourseElement.adopt(divText);
    },
    loadsuccess: function(html) {
        var divText;
	    divText = new Element('div', {'class': 'text'});
	    divText.adopt(html);
	    GenderCourseElement.set('html', '');
	    GenderCourseElement.adopt(divText);
    },
    loadfailure: function() {
        //this.loadcontent('<p>Sorry, there was an error processing your request. Please try clicking the tab again.</p>');
    },
    makerequest: function() {
        this.loadajax();
        this.loadrequest();
    },
    rotate: function() {
        //alert('working');
        GenderCount++;
        //alert('count;'+T5Count);
        var divs = GenderCourseElement.getElements('div.gender_rotate');
        divs.each(function(item, index) {
            if ((index+1) == GenderCount)
            {
                item.setStyle('display', 'block');
            } else {
                item.setStyle('display', 'none');
            }
        });
        if (GenderCount >= divs.length) { GenderCount=0; }
    }
});

//Selection Text for Request Information Course List.
var _SelectedCoursesArray = new Array();
var _SelectedGroupArray = new Array();

function AddCourseToSelection(course, group)
{
    //declaration of local variables.
    var item = course + '|' + group;
    
    //add or remove the item from the array.
    if (_SelectedCoursesArray.contains(item))
    {      
        _SelectedCoursesArray.erase(item);
    } 
    else 
    {             
        _SelectedCoursesArray.include(item);
    }
}

function GroupCoursesForSelection()
{
    //declaration of local variables.
    var newCoursesSelected = new Array();
    
    //group all courses avaiable.
    _SelectedGroupArray.each(function(item, index) {
    
        //declaration of local variables.
        var groupname = item.split('|')[0];
        var grouptotal = item.split('|')[1];
              
        //determine if the courses should be grouped into one.
        var groupedItems = _SelectedCoursesArray.filter(function(item, index){
            return item.contains(groupname);
        });
        if (groupedItems.length == grouptotal)
        {
            newCoursesSelected.include('All ' + groupname + '|' + groupname);
        } else {
            //add all the courses belonging to the group.
            newCoursesSelected.combine(groupedItems);
        }
      
    });
    return newCoursesSelected;
}

function AddSelectedCourse(course, group, addtolist)
{
    //add the course and group to the selection array.
    if (addtolist) { AddCourseToSelection(course, group); }
    
    //group the courses and output a selection string.
    var _SelectedCourses = GroupCoursesForSelection();
    var e = $('selected_courses');
    if (e) 
    { 
        if (_SelectedCourses.length > 0) 
        {
            //determine the plural of the amount of courses selected.
            var plural;
            if (_SelectedCourses.length == 1) {
                if (_SelectedCourses.some(function(item, index) { return item.contains('All'); }))
                { plural = 'courses'; } else { plural = 'course'; }
            } else {
                plural = 'courses';
            }
            
            //iterate and collect all selected courses.
            var text = '';
            _SelectedCourses.each(function(item, index) {
                if (index == _SelectedCourses.length - 1) {
                    text += item.split('|')[0]; } else { text += item.split('|')[0] + ', '; 
                }
            });
            e.set('html', 'You have selected <b>' + text + '</b> ' + plural + ".");
        } else { e.set('html',' '); }
    }
}

function OffersClick(currentCheck)
{
    var spans = $(document.body).getElements('span.course');
    //alert(currentCheck + ' ' + spans.length);
    spans.each(function(item, index) {
        if (item.get('id') != currentCheck) 
        { 
            //alert(item.getElements('input').length);
            item.getElements('input').each(function(item2, index2) {
                if (item2.checked) { item2.checked = false; }
            });
        }
    });
}

function OffersSubmit(campaign)
{
    var active;
    var spans = $(document.body).getElements('span.course');
    //alert(currentCheck + ' ' + spans.length);
    spans.each(function(item, index) {
        active = item.get('id');
        active = active.replace('course_', '');
        //alert(item.getElements('input').length);
        item.getElements('input').each(function(item2, index2) {
                if (item2.checked) { location.href = '/Redirect/?cp=' + campaign + '&pg=' + active; return false; }
        });
    });
}

/* =============================================================================
Price Dialog
================================================================================
Create a new dynamically loading price dialog window.
----------------------------------------------------------------------------- */
var PriceDialogBackground;
var PriceDialogWindow;

function PriceDialog(element, height, width, course, campaign, pifonly, tabId)
{
    //determine if the link is valid.
    //var link = $(element).getElement('a');
    if (element) {
        element.addEvent('click', function (event) {
            //event.stop();
            //event.stopPropagation();
            //hide the associated tab.
            $$('"#' + tabId + '"')[0].fade('out');
            var size = $(document.body).getSize();
            //create new dialog background element.
            if (!PriceDialogBackground) {
                PriceDialogBackground = new Element('div', {'id': 'price_dialog_bg'});
                PriceDialogBackground.setStyles({ height: (size.y + 500) });
                PriceDialogBackground.inject($(document.body)); //add the background to the document.
            }
            //determine the positioning - auto center.
            var left, top;
            //if (Browser.Engine.trident == true) { left = 200; top = 200; } else {
            left = ((size.x / 2) - (width / 2));
            top = ((size.y / 2) - (height / 2));
            
            //create new dialog window element.
            if (!PriceDialogWindow) { 
                PriceDialogWindow = new Element('div', {'id':'price_dialog_win'});
                PriceDialogWindow.inject($(document.body)); //add the window to the document.
            }
            //set the position attributes to the window.
            PriceDialogWindow.setStyles({ width: width, height: height, left: left, top: top });
            PriceDialogWindow.load('/SiteInformation/Ajax/PriceDialog/?cr=' + course + '&cm=' + campaign + '&pf=' 
            + pifonly).fade('in');
        });
    }
}

function ClosePriceDialog()
{
    //destroy the created elements.
    if (PriceDialogWindow) { PriceDialogWindow.fade('out').destroy(); PriceDialogWindow = null; }
    if (PriceDialogBackground) { PriceDialogBackground.destroy(); PriceDialogBackground = null;}
    //load the first tab.
    LoadTab(1);
}

function RedirectToBasket()
{
    //declaration of local variables.
    var course = '0'; var uniquecode = '';
    var courseopt = $$('select.first')[0];
    var paymentopt = $$('select.second')[0];
    //retrieve the course id.
    if (courseHash && courseHash.getLength() == 1) 
    { 
        //only one course.
        course = courseHash.getKeys()[0];
        if (paymentopt) { uniquecode = paymentopt.options[paymentopt.selectedIndex].value; }
    } else {
        if (courseopt) { course = courseopt.options[courseopt.selectedIndex].value; }
        if (paymentopt) { uniquecode = paymentopt.options[paymentopt.selectedIndex].value; }
    }
    //display error if no course or unique code is available.
    if (!course || course == '0' || course == 'PS' || !uniquecode || uniquecode == '' || uniquecode == 'PS') { alert('Please select a course and payment option.');
    return false; }
    var url = '/SiteInformation/Basket/Add/?id=' + course + '&uc=' + uniquecode;
    location.href = url;
}

function ManagePrices()
{
    var paymentopt = $$('select.second')[0];
    //manage the prices if the hash and dropdown exists.
    if (courseHash && paymentopt)
    {
        if (courseHash.getLength() == 1) 
        {
            //single course.
            var content = courseHash.getValues()[0].split('|');
            //alert(content + ' ' + content.length);
            paymentopt.options.length = 0; //clears the dropdown.
            for(var i = 0; i <= content.length - 1; i++)
            {
                //split the values even further.
                var option = content[i].split('=');
                //paymentopt.set('html', con.replace('|','')); 
                var opt = document.createElement("option");
                //paymentopt.options.add(new Element('option', {'text': option[0], 'value': option[1]}));  
                paymentopt.options.add(opt);
                opt.text = option[0];
                opt.value = option[1];
            }
        }
        else 
        {
            //multiple courses.
            var courseopt = $$('select.first')[0];
            if (courseopt) 
            {
                courseopt.addEvent('change', function(e) {
                    var val = courseopt.options[courseopt.selectedIndex].value;
                    //clear the cells if the selected value is blank.
                    $$('td.third')[0].set('html', '');
                    $$('td.fourth')[0].set('html', '');
                    $$('td.fifth')[0].set('html', '');
                    $$('td.last')[0].set('html', '');
                    $$('span.aprmsg').set('html','');
                    if (!val || val == '' || val == 'PS')
                    {
                        paymentopt.options.length = 0; //clears the dropdown.
                        var opt = document.createElement("option");
                        paymentopt.options.add(opt); opt.text = 'Please select';
                    } else 
                    {
                        //fill the second dropdown with payment options.
                        var con = courseHash.get(val);
                        if (!con || con == '') { 
                            paymentopt.options.length = 0; //clears the dropdown.
                            var opt = document.createElement("option");
                            paymentopt.options.add(opt); opt.text = 'Please select';                                             
                        } else {
                            var content = con.split('|');
                            //alert(content + ' ' + content.length);
                            paymentopt.options.length = 0; //clears the dropdown.
                            for(var i = 0; i <= content.length - 1; i++)
                            {
                                //split the values even further.
                                var option = content[i].split('=');
                                //paymentopt.set('html', con.replace('|','')); 
                                var opt = document.createElement("option");
                                //paymentopt.options.add(new Element('option', {'text': option[0], 'value': option[1]}));  
                                paymentopt.options.add(opt);
                                opt.text = option[0];
                                opt.value = option[1];
                            }
                        }
                    }
                });
            }
        }
    }
    //set the prices change.
    if (priceHash && paymentopt)
    {
        //add event to populate the prices.
        paymentopt.addEvent('change', function(e) {
            var val = paymentopt.options[paymentopt.selectedIndex].value;
            if (!val || val == '' || val == 'PS')
            {
                //clear the cells if the selected value is blank.
                $$('td.third')[0].set('html', '');
                $$('td.fourth')[0].set('html', '');
                $$('td.fifth')[0].set('html', '');
                $$('td.last')[0].set('html', '');
                $$('span.aprmsg').set('html','');
            } else 
            {
                //populate the cells if the selected value.
                var prices = priceHash.get(val).split('|');
                if (prices.length == 5)
                {
                    //set the prices.
                    $$('td.third')[0].set('html', prices[0]);
                    $$('td.fourth')[0].set('html', prices[1]);
                    $$('td.fifth')[0].set('html', prices[3]);
                    $$('td.last')[0].set('html', prices[4]);
                    if (prices[3] != '')
                    {
                        //pay by instalments - apr message.
                         $$('span.aprmsg').set('html','1 deposit of ' + prices[0] + ' and 12 monthly Instalments of ' + prices[1] + 
                                                      ' Course Price ' + prices[2] + ' plus Charge for Credit ' + prices[3] +
                                                      ' = Total Price ' + prices[4] + '<br><span class="apr"> 9.9% Typical APR</span>');
                    } 
                    else { $$('span.aprmsg').set('html',''); }
                }
            }
        });
    }
}