﻿/* Faber Academy */
// tipsy plugin
(function($) {$.fn.tipsy = function(options) {options = $.extend({}, $.fn.tipsy.defaults, options); return this.each(function() {var opts = $.fn.tipsy.elementOptions(this, options); $(this).hover(function() {$.data(this, 'cancel.tipsy', true); var tip = $.data(this, 'active.tipsy'); if (!tip) { tip = $('<div class="tipsy"><div class="tipsy-inner"/></div>'); tip.css({ position: 'absolute', zIndex: 100000 }); $.data(this, 'active.tipsy', tip); }if ($(this).attr('title') || typeof ($(this).attr('original-title')) != 'string') { $(this).attr('original-title', $(this).attr('title') || '').removeAttr('title'); }var title; if (typeof opts.title == 'string') { title = $(this).attr(opts.title == 'title' ? 'original-title' : opts.title); } else if (typeof opts.title == 'function') { title = opts.title.call(this); }tip.find('.tipsy-inner')[opts.html ? 'html' : 'text'](title || opts.fallback); var pos = $.extend({}, $(this).offset(), { width: this.offsetWidth, height: this.offsetHeight }); tip.get(0).className = 'tipsy'; tip.remove().css({ top: 0, left: 0, visibility: 'hidden', display: 'block' }).appendTo(document.body); var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight; var gravity = (typeof opts.gravity == 'function') ? opts.gravity.call(this) : opts.gravity; switch (gravity.charAt(0)) { case 'n': tip.css({ top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 }).addClass('tipsy-north'); break; case 's': tip.css({ top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 }).addClass('tipsy-south'); break; case 'e': tip.css({ top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth }).addClass('tipsy-east'); break; case 'w': tip.css({ top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }).addClass('tipsy-west'); break; }if (opts.fade) { tip.css({ opacity: 0, display: 'block', visibility: 'visible' }).animate({ opacity: 0.8 }); } else { tip.css({ visibility: 'visible' }); } }, function() { $.data(this, 'cancel.tipsy', false); var self = this; setTimeout(function() { if ($.data(this, 'cancel.tipsy')) return; var tip = $.data(self, 'active.tipsy'); if (opts.fade) { tip.stop().fadeOut(function() { $(this).remove(); }); } else { tip.remove(); } }, 100); });});}; $.fn.tipsy.elementOptions = function(ele, options) { return $.metadata ? $.extend({}, options, $(ele).metadata()) : options; }; $.fn.tipsy.defaults = { fade: false, fallback: '', gravity: 'n', html: false, title: 'title' }; $.fn.tipsy.autoNS = function() { return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n'; }; $.fn.tipsy.autoWE = function() { return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w'; };})(jQuery);
//
var opera = (navigator.appName.indexOf("Opera") != -1) ? true : false;
var firefox = navigator.userAgent.toLowerCase();
firefox = (firefox.indexOf("firefox") != -1) ? true : false;
var safari = navigator.userAgent.toLowerCase();
safari = ((safari.indexOf("safari") != -1) && (safari.indexOf("chrome") == -1)) ? true : false;
var chrome = navigator.userAgent.toLowerCase();
chrome = (chrome.indexOf('chrome') != -1) ? true : false;
var msie_only = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
var msie_old = false; // MSIE versions older than 7
var msie_80 = false; // MSIE version 8.0 or newer
var msie_70 = false; // MSIE version 7.0
var msie_60 = false; // only MSIE 6.0

if (msie_only) {
  fullVerStr = navigator.appVersion;
  verStr = fullVerStr.substring(fullVerStr.indexOf('MSIE') + 4, fullVerStr.length);
  verStr = verStr.substring(0, verStr.indexOf(';'));
  msie_old = (parseFloat(verStr) < 7.0) ? true : false;
  msie_80 = (parseFloat(verStr) >= 8.0) ? true : false;
  msie_70 = (parseFloat(verStr) == 7.0) ? true : false;
  msie_60 = (parseFloat(verStr) == 6.0) ? true : false;
}

document.writeln('<style type="text/css">\n/*<![CDATA[*/\n');
if (msie_old) {
  document.writeln('.Radio {left:-4px;}\n');
  document.writeln('.Radio input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.CheckBox {left:-3px;}\n');
  document.writeln('.RbHorizontalList td {padding-bottom:0px;}\n');
  document.writeln('.RbHorizontalList label {left:-7px;}\n');
  document.writeln('.RbVerticalList {left:-5px;}\n');
  document.writeln('.RbVerticalList label {top:-2px; margin-right:0px;}\n');
  document.writeln('.RbVerticalList input {}\n');
  document.writeln('.CbVerticalList {position:relative; left:-4px; top:-2px;}\n');
  document.writeln('.CbVerticalList input {position:relative;}\n');
  document.writeln('.CbVerticalList label {position:relative; top:-2px;}\n');
  document.writeln('.AccessCBList label {top:-2px; left:-2px; margin-right:12px;}\n');
  document.writeln('hr {margin-top:0px; margin-bottom:0px;}\n');
  document.writeln('.NewsAndFeaturesList .Item .BL {bottom:-2px;}\n');
  document.writeln('.NewsAndFeaturesList .Item .BR {bottom:-2px;}\n');
  document.writeln('.TypeOfCourses {margin-top:-27px;}\n');
  document.writeln('.FormWrap {overflow:hidden}\n');
  document.writeln('.StudentMenu .Border {display:none}\n');
  document.writeln('.PageBanner {padding-right:23px !important}\n');
  document.writeln('.ImageHolder .BL, .ImageHolder .BR {bottom:-3px !important}\n');
  document.writeln('.CMSBox .CorneredBoxPad .TR {position:absolute; top:0px; right:-1px;}\n');
  document.writeln('.CMSBox .CorneredBoxPad .BL {position:absolute; bottom:-1px; left:0px;}\n');
  document.writeln('.CMSBox .CorneredBoxPad .BR {position:absolute; bottom:-1px; right:-1px;}\n');

}
if (msie_70) {
  document.writeln('.Radio {left:-4px;}\n');
  document.writeln('.Radio input {top:0px; margin-top:0px; margin-right:0px; margin-bottom:0px;}\n');
  document.writeln('.CheckBox {left:-3px;}\n');
  document.writeln('.RbHorizontalList td {padding-bottom:0px;}\n');
  document.writeln('.RbHorizontalList input {left:0px;}\n');
  document.writeln('.RbVerticalList {left:-5px;}\n');
  document.writeln('.RbVerticalList input {position:relative; top:2px}\n');
  document.writeln('.RbVerticalList label {margin-right:0px;}\n');
  document.writeln('.CbVerticalList {position:relative; left:-3px;}\n');
  document.writeln('.CbVerticalList input {position:relative; top:2px}\n');
  document.writeln('.CbVerticalList label {position:relative; left:-2px;}\n');
  document.writeln('.AccessCBList label {top:-2px; margin-left:0px;}\n');
  document.writeln('.AccessCBList input {position:relative; left:-3px; margin-right:0px;}\n');
  document.writeln('.FormField .FileUploadW1 {border-right:solid 1px #ddd; height:1.8em;}\n');
  document.writeln('.TermsCheckboxAndLink {margin-left:11px; padding-left:10px; text-indent:-23px;}\n');
  document.writeln('#LocationDetail .DetailPageTop .Left .BL {bottom:3px; left:0;}\n');
  document.writeln('#LocationDetail .DetailPageTop .Left .BR {bottom:3px; right:0;}\n');
}
if (msie_80) {
  document.writeln('.Radio {left:0px;}\n');
  document.writeln('.Radio input {top:2px; margin-top:0px; margin-right:5px;}\n');
  document.writeln('.RbVerticalList {}\n');
  document.writeln('.RbVerticalList input {position:relative; margin-bottom:6px; top:4px}\n');
  document.writeln('.RbVerticalList label {top:1px;}\n');
  document.writeln('.CbVerticalList {}\n');
  document.writeln('.CbVerticalList input {position:relative; top:3px}\n');
  document.writeln('.AccessCBList label {top:-2px;}\n');
  document.writeln('.FormField .DropDownW2 {padding-bottom:1px; height:1.9em; padding-right:0px;}\n');
  document.writeln('.FormField .FileUploadW1 {border-right:solid 1px #ddd; height:1.8em;}\n');
}
if (opera) {
  document.writeln('.Radio {left:0px;}\n');
  document.writeln('.Radio input {margin-bottom:0px; margin-right:5px;}\n');
  document.writeln('.Radio label {position:relative; top:2px;}\n');
  document.writeln('.CheckBox input {top:0px;}\n');
  document.writeln('.RbHorizontalList input {margin-right:4px;}\n');
  document.writeln('.RbHorizontalList label {}\n');
  document.writeln('.RbVerticalList {}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:2px;}\n');
  document.writeln('.CbVerticalList {left:-1px;}\n');
  document.writeln('.CbVerticalList input {margin-top:2px; margin-bottom:3px;}\n');
  document.writeln('.AccessCBList label {}\n');
  document.writeln('.FormField .FileUploadW1 {height:1.8em;}\n');
}

if (firefox) {
  document.writeln('.RbHorizontalList label {}\n');
  document.writeln('.RbVerticalList {left:-1px;}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {position:relative; top:-3px; margin-left:6px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {position:relative; top:-3px; margin-left:6px;}\n');
  document.writeln('.AccessCBList label {top:-2px;}\n');
  document.writeln('.FormField .EditBoxW1 {width:260px}\n');
  document.writeln('.FormField .EditBoxW2 {}\n');
  document.writeln('.FormField .DropDownW2 {padding-right:0px;}\n');
}
if (safari) {
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {top:-3px; margin-left:7px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {position:relative; margin-left:7px; top:-2px; }\n');
  document.writeln('.AccessCBList label {top:-2px;}\n');
  document.writeln('.SearchHolder .SearchBox .EditBoxMargin {margin-top:3px;}\n');
  document.writeln('.FormWrap .FormCol .FormBox .TextInput {padding-top:4px; padding-bottom:4px;}\n');
  document.writeln('.FormWrap .FormCol .FormBox .DropDown {line-height:36px;}\n');
}
if (chrome) {
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {top:-3px; margin-left:5px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {position:relative; top:-2px; margin-left:7px;}\n');
  document.writeln('.AccessCBList label {top:-3px;}\n');
  document.writeln('.FormField .DropDownW2 {padding-right:0px;}\n');
  document.writeln('.FormWrap .FormCol .FormBox .TextInput {padding-top:4px; padding-bottom:4px;}\n');
}
document.writeln('.ValidationComplianceTag {display:none;}\n');
document.writeln('/*]]>*/\n</style>\n');

/* Character limits */
function checkLength(element, info, max_length) {
  var actual_length = element.value.length;
  var characters_left = max_length - actual_length;
  if (characters_left < 0) characters_left = 0;
  if (actual_length == 0) {
    document.getElementById(info).innerHTML = "Maximum text length is " + max_length + " characters.";
  }
  if ((actual_length > 0) && (actual_length <= max_length)) {
    document.getElementById(info).innerHTML = "You may enter " + characters_left + " more characters.";
  }
  if (actual_length > max_length) {
    element.value = element.value.substr(0, max_length);
    document.getElementById(info).innerHTML = "You may enter " + characters_left + " more characters.";
  }
}

//textarea_container - id
function initLengthInfo(textarea_container, info_id, max_length) {
  if (document.getElementById(textarea_container)) {
    element_ref = document.getElementById(textarea_container).getElementsByTagName("textarea")[0];
    checkLength(element_ref, info_id, max_length);
  }
}

//Limits length of text in textarea "element" (dom reference), finds correct .LengthInfo to write length information, counts characters
function checkLength2(element, max_length) {
  var actual_length = element.value.length;
  var characters_left = max_length - actual_length;
  if (characters_left < 0) characters_left = 0;

  if (actual_length == 0) {
    $(element).parent().nextAll("div.LengthInfo").html("Maximum text length is " + max_length + " characters.");
  }
  if ((actual_length > 0) && (actual_length <= max_length)) {
    $(element).parent().nextAll("div.LengthInfo").html("You may enter " + characters_left + " more characters.");
  }
  if (actual_length > max_length) {
    element.value = element.value.substr(0, max_length);
    $(element).parent().nextAll("div.LengthInfo").html("You may enter " + characters_left + " more characters.");
  }
}

//Inits all textareas on the page which are placed inside a container of given class name
function initLengthInfo2(textarea_container_class, max_length) {
  $("div." + textarea_container_class + " textarea").each(function(){
    checkLength2(this, max_length);
  })
}

//Returns value stored in cookie with given id, or -1 if cookie didn't exist (or is expired), multi value cookies safe.
function toCookie(cookie_id, value) {
  var exp = new Date();
  exp.setTime(exp.getTime() + (1000 * 60 * 60)); //1000 * 60 * 60 * 24 * 365
  var cookie_name = "Faber_" + cookie_id + "=" + value;
  var cookie_expires = "expires=" + exp.toGMTString();
  document.cookie = cookie_name + ";" + cookie_expires + "; path=/";
}

//Returns value stored in cookie with given id, or -1 if cookie didn't exist (or is expired), multi value cookies resistant.
function fromCookie(cookie_id) {
  var labelName = "Faber_" + cookie_id;
  var labelLen = labelName.length;
  var cookieData = document.cookie;
  var cLen = cookieData.length;
  var i = 0;
  var cEnd;
  while (i < cLen) {
    var j = i + labelLen;
    if (cookieData.substring(i, j) == labelName) {
      cEnd = cookieData.indexOf(";", j);
      if (cEnd == -1) {
        cEnd = cookieData.length;
      }
      return unescape(cookieData.substring(j + 1, cEnd));
    }
    i++;
  }
  return "-1";
}

//initial example value in a form field; disappears on focus, appears back on blur if is empty
function clearField(field_to_clear, initial_value) {
  if (initial_value == field_to_clear.value) field_to_clear.value = "";
}
function fillField(field_to_clear, initial_value) {
  if (field_to_clear.value == "") {
    field_to_clear.value = initial_value;
  };
}

function clearFieldPassword(field_to_clear, initial_value) {
  if (initial_value == field_to_clear.value) field_to_clear.value = "";
  field_to_clear.style.direction = 'ltr';
}

// a standard popup window; random number to always open new window and bring it to front
function openPopup(url) {
  var win_handle = window.open(url, 'PopUpWindow' + Math.floor(Math.random()*10000), 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=1010,height=640,top=50,left=100');
  win_handle.focus();
}
    
function getYear(id) {
  if (document.getElementById(id)) {
    var d = new Date();
    document.getElementById(id).innerHTML = d.getFullYear()
  }
}

//Open pop up window for terms and conditions, privacy policy; random number to always open new window and bring it to front
function openTerms(url, name) {
  var win = window.open(url, name + Math.floor(Math.random()*10000), "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,width=625,height=600");
  win.focus();
}

//Divide admin global nav tabs into 1, 2 or 3 rows;
function updateNavigation() {
  var max_number_of_tabs_in_single_row = 11; //11
  var number_of_tabs = $(".GlobalNavInner span.Active, .GlobalNavInner span.Inactive").length;
  if (number_of_tabs <= max_number_of_tabs_in_single_row) { //make one row
    $(".GlobalNavInner").wrapInner("<div class=\"TheRow\"></div>");
  } else {
    var html_begining = '<div class="TheRow">';
    var html_middle_to_replace = 'fdsa';
    var html_middle = '</div><div class="TheRow">';
    var html_end = '</div>';
    var inner_content = '';
    var divider_pos = number_of_tabs / (max_number_of_tabs_in_single_row - 1);
    var number_of_rows = Math.ceil(divider_pos);
    var divide_after = Math.floor(number_of_tabs / number_of_rows) - 1; //-1 because eq is 0 based

    if (number_of_rows == 2) { //make two rows
      $(".GlobalNavInner span.Between").eq(divide_after - 1).after(html_middle_to_replace);
      inner_content = $(".GlobalNavInner").html();
      inner_content = html_begining + inner_content.replace(html_middle_to_replace, html_middle) + html_end;
      $(".GlobalNavInner").html(inner_content);
    }

    if (number_of_rows > 2) { //make three rows
      $(".GlobalNavInner span.Between").eq(divide_after - 1).after(html_middle_to_replace);
      $(".GlobalNavInner span.Between").eq(divide_after * 2).after(html_middle_to_replace);
      inner_content = $(".GlobalNavInner").html();
      inner_content = inner_content.replace(html_middle_to_replace, html_middle)
      inner_content = html_begining + inner_content.replace(html_middle_to_replace, html_middle) + html_end;
      $(".GlobalNavInner").html(inner_content);
    }
  }
  $(".GlobalNavInner").css('display', 'block');
}

/* WYSIWYG editor ------------------------------- */
function loadWysiwyg(html_source_id, editor_parent_id, editor_width, editor_height) {
  var ports = '';
  if (window.location.port == '') {ports = '';} else {ports = ':' + window.location.port;}
  var dynamic_url = window.location.protocol + "//" + document.domain + ports;
  var hidden_field_id = document.getElementById(html_source_id).getElementsByTagName('input')[0].id;
  var html_code = "";
  html_code += '<object type="application/x-xstandard" id="' + editor_parent_id + '_editor" width="' + editor_width + '" height="' + editor_height + '">';
  html_code += '<param name="Value" value="' + htmlEncode(document.getElementById(hidden_field_id).value) + '" />';
  html_code += '<param name="ImageLibraryURL" value="' + dynamic_url + '/xstandard/imagelibrary.aspx" />';
  html_code += '<param name="AttachmentLibraryURL" value="' + dynamic_url + '/xstandard/attachmentlibrary.aspx" />';
  html_code += '<param name="LinkLibraryURL" value="' + dynamic_url + '/xstandard/linklibrary.aspx" />';
  html_code += '<param name="Styles" value="' + dynamic_url + '/xstandard/editor-styles.xml" />';
  html_code += '<param name="License" value="' + dynamic_url + '/xstandard/license.txt" />';
  html_code += '<param name="CSS" value="' + dynamic_url + '/xstandard/general.css" />';
  html_code += '<param name="ProxySetting" value="auto-detect" />';
  html_code += '<param name="EnableTimestamp" value="no" />';
  html_code += '<param name="EnablePasteMarkup" value="no" />';
  html_code += '<param name="BackgroundColor" value="#f9f9f9" />';
  html_code += '<param name="BorderColor" value="#ccc" />';
  html_code += '<param name="Lang" value="en" />';
  html_code += '<param name="Dir" value="ltr" />';
  html_code += '<param name="ClassImageFloatLeft"  value="LeftImage" />';
  html_code += '<param name="ClassImageFloatRight" value="RightImage" />';
  html_code += '<param name="ToolbarWysiwyg" value="strong, em, underline, strikethrough, align-left, align-center, align-right, ordered-list, unordered-list, draw-layout-table, draw-data-table, separator, image, hyperlink, attachment, source, preview" />';
  html_code += '<param name="ToolbarPreview" value="wysiwyg, source, preview, screen-reader" />';
  html_code += '<param name="ToolbarSource" value="indent, whitespace, word-wrap, validate,, wysiwyg, source, preview" />';
  html_code += '<param name="Base" value="' + dynamic_url + '/DynamicMedia/cms-uploaded/" />';
  html_code += '<p style="margin-bottom:0px;">Your HTML editor plug-in is not installed. Please download and install it using links below. More info on the help page.<br /><a href="/xstandard/x-pro-win.exe" style=\"text-decoration:underline;\">PC version</a>&nbsp;-&nbsp;<a href="/xstandard/x-pro-mac.dmg" style=\"text-decoration:underline;\">Mac version</a><p>'; //code for all browsers but Opera (v11.50) (it is displaying useless missing plugin box)
  html_code += '</object>';
  document.getElementById(editor_parent_id).innerHTML = html_code;
}

function saveWysiwyg(hidden_field_inside_id, editor_parent_id) {
  if (document.getElementById(hidden_field_inside_id) && document.getElementById(editor_parent_id + '_editor')) {
    if (typeof document.getElementById(editor_parent_id + '_editor').value == "undefined") {
      document.getElementById(hidden_field_inside_id).getElementsByTagName('input')[0].value = "";
    } else {
      document.getElementById(hidden_field_inside_id).getElementsByTagName('input')[0].value = document.getElementById(editor_parent_id + '_editor').value;
    }
  }
}

function htmlEncode(s) {
  var str = new String(s);
  str = str.replace(/&/g, "&amp;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/>/g, "&gt;");
  str = str.replace(/"/g, "&quot;");
  return str;
}

// cms flash content
function CreateMedia() {

  if ($('.VideoContent')) {
    for (var i = 0; i < $('.VideoContent').length; i++) {
      var video_holder = $('.VideoContent:eq(' + i + ')')
      video_holder.attr('id', 'VideoHolder' + i);
      var flash_video = video_holder.find('a').attr('href');
      //var flash_title = video_holder.find('img').attr('title');
      var flash_poster = video_holder.find('img').attr('src');
      swfobject.embedSWF("/StaticMedia/Flash/faber_player.swf", "VideoHolder" + i, "350", "220", "9.0.00", "", { title1: '', video1: flash_video, poster1: flash_poster }, { allowscriptaccess: "always", allowfullscreen: "true" }, {});
    };
  };  

  if ($('.AudioContent')) {
    for (var i = 0; i < $('.AudioContent').length; i++) {
      var audio_holder = $('.AudioContent:eq(' + i + ')')
      audio_holder.attr('id', 'AudioHolder' + i);
      var audio_file = audio_holder.find('a').attr('href');

      swfobject.embedSWF("/StaticMedia/Flash/player_mp3_maxi.swf", "AudioHolder" + i, "200", "18", "9.0.00", "", { mp3: audio_file, width: '200', height: '18', volume: '150', showstop: '1', showvolume: '1', buttonovercolor: '474747', bgcolor1: '3F5C85', bgcolor2: '577db0', sliderovercolor: '474747', volumewidth: '35', volumeheight: '10', sliderwidth: '7', loadingcolor: 'ffffff' }, { allowscriptaccess: "always", wmode: "transparent", allowfullscreen: "true" }, {});
    };
  };
};

function getParam(query_string, param_name) {
  query_string = query_string.toLowerCase();
  param_name = param_name.toLowerCase();
  
  var pos=query_string.indexOf("&"+param_name+"=");
  if (pos == -1) {
    pos=query_string.indexOf("?"+param_name+"=");
  }

  var cam="";

  if (pos >= 0) {
    query_string=query_string.substring(pos + param_name.length + 2)
    var end = query_string.indexOf("&")
    if (end == -1) {
      end = query_string.length
    }
    cam=query_string.substring(0, end)
  }
  return( unescape(cam.replace(/\+/g, " ")))
}

function dd(obj) {
  var msg = "";
  for (var i in obj) {
    msg += i + ": " + obj[i] + "\n";
  }
  return ('<pre style="font-size:15px;">\n' + msg + '</pre>');
}


function getParam(query_string, param_name) {
  query_string = query_string.toLowerCase();
  param_name = param_name.toLowerCase();
  
  var pos=query_string.indexOf("&"+param_name+"=");
  if (pos == -1) {
    pos=query_string.indexOf("?"+param_name+"=");
  }

  var cam="";

  if (pos >= 0) {
    query_string=query_string.substring(pos + param_name.length + 2)
    var end = query_string.indexOf("&")
    if (end == -1) {
      end = query_string.length
    }
    cam=query_string.substring(0, end)
  }
  return( unescape(cam.replace(/\+/g, " ")))
}

function clickButtonOnEnter(evt, button_class) {
  var href_string = $('.' + button_class).eq(0).attr('href');
  var keyCode = evt.keyCode;
//  alert (keyCode + ' ' + href_string);

  if(keyCode == 13) {
    eval(href_string.substring(11, href_string.length));
    return false;
  }
  return true;
}

// document ready
$(document).ready(function() {

  if (msie_70 || msie_old) $("table").attr('cellspacing', '0');
  
  getYear("CurrentYear");

  $('div.CMSBox .CorneredBox, div.CMSBox .CorneredBoxPad').append('<div class="TL"></div><div class="TR"></div><div class="BL"></div><div class="BR"></div>');

  //Social buttons
  $('.fblike').append('<iframe src="http://www.facebook.com/plugins/like.php?app_id=198511010212991&href=' + window.location.href + '&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>')
  $('.tweet').append('<a href="http://twitter.com/share?related=@FaberAcademy" class="twitter-share-button" data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>')

  //Form fields on focus highlight - selects, textareas, textboxes
  $("select.WithFocusHighlight, textarea.WithFocusHighlight, input.WithFocusHighlight").focus(function() {
    $(this).closest(".FormBox").addClass("FormBoxFocusHighlighted");
  });
  $("select.WithFocusHighlight, textarea.WithFocusHighlight, input.WithFocusHighlight").blur(function() {
    $(this).closest(".FormBox").removeClass("FormBoxFocusHighlighted");
  });

  //Highlight on focus - single checkbox/radiobutton
  $("span.WithFocusHighlight > input").focus(function() {
    $(this).closest(".FormBox").addClass("FormBoxFocusHighlighted");
  });
  $("span.WithFocusHighlight > input").click(function() { //added onclick because of safari
    $(this).focus();
  });
  $("span.WithFocusHighlight > input").blur(function() {
    $(this).closest(".FormBox").removeClass("FormBoxFocusHighlighted");
  });

  //Highlight on focus - radiobutton/checkbox lists
  $("table.WithFocusHighlight").find("input").focus(function() {
    $(this).closest(".FormBox").addClass("FormBoxFocusHighlighted");
  });
  $("table.WithFocusHighlight").find("input").click(function() { //added onclick because of safari
    $(this).focus();
  });
  $("table.WithFocusHighlight").find("input").blur(function() {
    $(this).closest(".FormBox").removeClass("FormBoxFocusHighlighted");
  });

  //form fields validation highlight - parent box
  $(".WithFocusHighlight").closest(".FormBox").find(".ValidationInfo").each(function() {
    $(this).closest(".FormBox").addClass("FormBoxValidationHighlighted");
  });

  //form fields validation highlight - each field except for radio and checkbox
  $(".WithFocusHighlight").closest(".FormBox").find(".ValidationInfo").each(function() {
    if ($(this).closest(".InnerFormBox").length == 1) {
      $(this).closest(".InnerFormBox").find("input[type!='radio'][type!='checkbox']").addClass("InputFieldValidationHighlighted");
      $(this).closest(".InnerFormBox").find("select").addClass("InputFieldValidationHighlighted");
      $(this).closest(".InnerFormBox").find("textarea").addClass("InputFieldValidationHighlighted");
    } else {
      $(this).closest(".FormBox").find("input[type!='radio'][type!='checkbox']").addClass("InputFieldValidationHighlighted");
      $(this).closest(".FormBox").find("select").addClass("InputFieldValidationHighlighted");
      $(this).closest(".FormBox").find("textarea").addClass("InputFieldValidationHighlighted");
    }
  });

  // make debug code visible on localhost and obs server
  if ((document.URL.indexOf("localhost") != -1) || (document.URL.indexOf("avamae.co.uk") != -1)) {
    $("div.Debug").css('display', 'block');
  }

  /* FormBox InfoBox */
  $('.FormBox .TextInput, .FormBox .DropDown, #LoginLayer .Input').focus(function() {
    $(this).parents('.FormBox').children('.InfoBox').show()
    $(this).addClass('focus')
  }).blur(function() {
    $(this).parents('.FormBox').children('.InfoBox').hide()
    $(this).removeClass('focus')
  })

  /* Login Layer */
  if (!msie_70 && !msie_old) {
    $('.NavLoginJS').bind('click', function() {
      $('#LoginLayer').fadeToggle()
      $(this).toggleClass('OpenLayer')
      return false
    })
    $('#LoginLayer .Close').bind('click', function() {
      $(this).parent().hide()
      $('.NavLoginJS').toggleClass('OpenLayer')
      return false
    })
  }

  if ($('#dialog').length > 0) {
    // Dialog
    $('#dialog').dialog({
      autoOpen: false,
      width: 390,
      position: 'center',
      resizable: false,
      buttons: {
        "Ok": function() {
          $(this).dialog("close")
        },
        "Reset": function() {
          switchToDefaultContrast()
          switchToDefaultTextSize()
          $('#contrastDefault, #font1').attr('checked', 'checked')
        }
      },
      title: 'Accessibility Settings',
      dialogClass: 'AccessDiv'
    })

    // Dialog Link
    $('#dialog_link').click(function() {
      $('#dialog').dialog('open')
      $('#dialog').find("input").eq(0).blur()
      return false
    })
  }
  
  //for application document upload
  if ($('.StyledFileUpload').length > 0 ){
    $('.StyledFileUpload').filestyle({
      inputClass: 'TextInput',
      inputWidth: 370,
      inputHeight: 43,
      buttonHeight: 43,
      buttonWidth: 77,
      buttonBgColor: '#476b9b',
      buttonBgPosition: 'right center'
    })
  }
 
  //for Session details course work upload  
//  if ($('.StyledFileUpload2').length > 0 ){
//    $('.StyledFileUpload2').filestyle({
//      inputClass: 'TextInput',
//      inputWidth: 100,
//      inputHeight: 43,
//      buttonHeight: 43,
//      buttonWidth: 177,
//      buttonBgColor: '#476b9b',
//      buttonBgPosition: 'right center'
//    })
//  }
//  
  // tipsy
  $('.ReadyReview').tipsy({ gravity: 's' });

  
  if (msie_old) {
    $('table').attr('cellspacing', '0');
  }
  
 $(document).pngFix(); 
});  //ready



