﻿function SwitchWrapperClass (itemId, classToSwitchTo) {
	document.getElementById(itemId).className = classToSwitchTo;
}

function SwitchClass (ob, classToSwitchTo) {
	ob.className = classToSwitchTo;
}

function clearOutTextBox (ob, textToCheckFor) {
    if ( ob.value == textToCheckFor ) 
    {
        ob.value = '';
    }
}

function openWindow(winURL,winName,features) {
  window.open(winURL,winName,features);
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function resizeText(multiplier) {
    if (document.body.style.fontSize == "") 
    {
        document.body.style.fontSize = "1.0em";
    }
    document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
}

/* Requires Mootools */
function AddClass (ob, classToAdd) {
	ob.addClass(classToAdd);
}

/* Requires Mootools */
function RemoveClass (ob, classToRemove) {
	ob.removeClass(classToRemove);
}

function AddJobToBasket (jobId)
{
    //This code will send a data object via a GET request and alert the retrieved data.
    var jsonRequest = new Request.JSON({url: "/Handlers/AddJobToBasket.ashx", onComplete: function(response){
    
        var p = $('AddToBasketNotificationPanel').getElement('p');
        if ( response != null ) 
        {
            if ( response.Action == null )
            {
                p.set('html', 'The job <strong>' + response.JobTitle + '</strong> (Ref: <strong>' + response.Reference + '</strong>) was successfully added to your job basket');
            }
            else if ( response.Action == 'AlreadyInBasket' ) 
            {
                p.set('html', 'The selected job is already in your Job Basket!');
            }
            else if ( response.Action == 'Redirect' ) 
            {
                p.set('html', "To add jobs to your basket you must <strong><a href='/Candidates/Register/'>Login or Register with Us</a></strong>");
            }
            else
            {
                p.set('html', '! Sorry - something went wrong. The job could not be added to your Job Basket!');
            }
        }
        else 
        {
            p.set('html', '! Sorry - something went wrong. The job could not be added to your Job Basket!');
        }
        
        
        $('AddToBasketNotificationPanel').setStyle('display', 'block');
        $('AddToBasketNotificationPanel').set('opacity', 0.9);
        
        //Simply request the hide for the AddToBasketNotificationPanel with a delay so the user will actually see it before it goes...
        setTimeout("HideBasketNotificationPanel();", 2000);
        
    }}).get({'jid': jobId, 'timestamp': new Date().getTime()}); //Had to add timestamp to the params to prevent Internet Explorer caching the output of the ajax request!
}

function HideBasketNotificationPanel()
{
    var fadeOut = new Fx.Morph($('AddToBasketNotificationPanel'), {duration: 'long', transition: Fx.Transitions.Sine.easeOut, link: 'ignore'});
    //Only fade out if the panle is currently at the 0.9 opacity - otherwise it may have already been faded out by an earlier request in which case no need to go again!
    var currentOpacity = $('AddToBasketNotificationPanel').getStyle('opacity');
    if ( currentOpacity == 0.9 ) 
    {
        fadeOut.start({
            'opacity': [0.9, 0]
        });
    }
}

function addToFavourites(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}