/*************************************************************
* Page: specific_functions.js v 3.01 
* Description: Specific Javascript functions
* 
* Hospitality Recruitment - Online Strategies
* Copyright (C) 2005 Online Strategies, All rights reserved
* Email  info@hospitalityonline.co.uk
*  				
*************************************************************/

// Function to show the searching box when doing a basic or advanced search
function show_searching_div()
{
	// Check for DOM support
	if(document.getElementById && document.createTextNode)
	{
	// Lets set some variables
	var showdiv = document.getElementById('show');
	var searcher = document.getElementById('searching');
		if(searcher)
		{
			searcher.style.display = 'block';
			showdiv.className  = 'visi30';
		}
	}
}
/*****************************************************************************************/
var END_OF_INPUT = -1;
var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);

var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
    reverseBase64Chars[base64Chars[i]] = i;
}

var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function readBase64(){    
    if (!base64Str) return END_OF_INPUT;
    if (base64Count >= base64Str.length) return END_OF_INPUT;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}

function readReverseBase64(){   
    if (!base64Str) return END_OF_INPUT;
    while (true){      
        if (base64Count >= base64Str.length) return END_OF_INPUT;
        var nextCharacter = base64Str.charAt(base64Count);
        base64Count++;
        if (reverseBase64Chars[nextCharacter]){
            return reverseBase64Chars[nextCharacter];
        }
        if (nextCharacter == 'A') return 0;
    }
    return END_OF_INPUT;
}

function ntos(n){
    n=n.toString(16);
    if (n.length == 1) n="0"+n;
    n="%"+n;
    return unescape(n);
}

function decodeBase64(str){
    setBase64Str(str);
    var result = "";
    var inBuffer = new Array(4);
    var done = false;
    while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT
        && (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){
        inBuffer[2] = readReverseBase64();
        inBuffer[3] = readReverseBase64();
        result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4));
        if (inBuffer[2] != END_OF_INPUT){
            result +=  ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2));
            if (inBuffer[3] != END_OF_INPUT){
                result +=  ntos((((inBuffer[2] << 6)  & 0xff) | inBuffer[3]));
            } else {
                done = true;
            }
        } else {
            done = true;
        }
    }
    return result;
}
/*********************************************************************************************/

// Function to insert standard replies into the text area 
// textarea - the textarea that you want your std reply inserted into
// message - the message that you are going insert
// type - the type of message it is, for the alert
function insert_standard_reply(textarea, message, type)
{
	// Check for DOM support
	if(document.getElementById && document.createTextNode)
	{
		// Lets set some variables
		var txt = document.getElementById(textarea);
		// if the message field is blank, then tell them its blank, otherwise insert the text
		(message == '')?alert('you have no '+type+' letter set up'):txt.value = decodeBase64(message);
	}
}

//------------------------------------------------------------------
// Function to hide / show the new shortlist box when adding an applicant
// select_element - the element that you are triggering the function from.
function display_new_shortlist ( select_element )
{
	// Check for DOM support
	if ( document.getElementById && document.createTextNode )
	{
		// lets set some variables
		var sel = document.getElementById( select_element ); // find the select tag that we are firing the event from
		if (sel.selectedIndex == 1)
		{
			show_elements('lbl_1','lbl_2','shortlist_title','vacancy');
		}
		else
		{
			hide_elements('lbl_1','lbl_2','shortlist_title','vacancy'); // Check hidden rows and hide or show the inside divs of those
		}
	}
}

//------------------------------------------------------------------
// Function to hide / show the new shortlist box when adding an applicant
// select_element - the element that you are triggering the function from.
function display_new_archives ( select_element )
{
	// Check for DOM support
	if ( document.getElementById && document.createTextNode )
	{
		// lets set some variables
		var sel = document.getElementById( select_element ); // find the select tag that we are firing the event from
		if (sel.selectedIndex == 1)
		{
			show_elements('lbl_1','archive_title');
		}
		else
		{
			hide_elements('lbl_1','archive_title'); // Check hidden rows and hide or show the inside divs of those
		}
	}
}

//------------------------------------------------------------------
// Function to hide / show the new shortlist box when adding an applicant
// select_element - the element that you are triggering the function from.
function generate_stats ()
{
	// Check for DOM support
	if ( document.getElementById && document.createTextNode )
	{
		// lets set some variables
		var hide = document.getElementById( 'hidden_vacancies' );
		var show = document.getElementById( 'show_vacancies' );
		if (show && hide){ // make sure that the elements exsists
			hide.style.display = 'block';
			show.style.display = 'none';
		}
		else // if the elements for some reason DONT exsist, then return true,
			// and go to the stats page without the loader effect.
		{
			// if for some reason 
			return true;
		}
	}
}
//--------------------------------------------------------------------------------------------------------
// Function to show and hide content with or without an image and text
// paragraph = the paragraph that needs to be shown, hidden
// inner = the inner HTML that needs to be changed
function show_hide_homepage_divs(paragraph,inner,right,left,middle)
{
	// Check for DOM support
	if (document.getElementById && document.createTextNode)
	{
		// Lets set come variables
		var para 	= document.getElementById(paragraph);
		var inner 	= document.getElementById(inner);
		var rgt 	= document.getElementById(right);
		var lft 	= document.getElementById(left);
		var mdl 	= document.getElementById(middle);
		
		
		if(para.style.display == "none"){
			para.style.display = "block";
			inner.innerHTML = "Close information &laquo;";
			rgt.className = "br_right_lrg";
			lft.className = "br_left_lrg";
			mdl.className = "block_holder_lrg";
		}
		else{
			para.style.display = "none";
			inner.innerHTML = "More information &raquo;";
			rgt.className = "br_right";
			lft.className = "br_left";
			mdl.className = "block_holder";
		}
	}
}
// Function that checks the checkbox for the relevant product if you fill in the quantity first
// un - the unchecked box that needs to be checked
// qb - quantity box that is filled and checking against
function check_box(uc)
{
	if (document.getElementById && document.createTextNode)
	{
		var unchecked = document.getElementById(uc);	
		if (unchecked.checked == false){
			unchecked.checked = true;
		}
	}
	
}
// Function to focus the text box when checking the checkbox on purchase products page
// product = the text box we want to focus to
// checkboxi sthe checkbox we want to trigger the event from

function focus_text_box(product, checkbox)
{
	// Check for DOM support
	if(document.getElementById && document.createTextNode)
	{
		// Lets set some variables
		var prd = document.getElementById(product);
		var chk = document.getElementById(checkbox);
			if(chk.checked) // if the checkbox is checked / triggered and checked, then focus the text box
			{
				prd.focus();
			}
	}
}

//--------------------------------------------------------------------------------------------------------
// Function to show and hide content with or without an image and text
// paragraph = the paragraph that needs to be shown, hidden
// inner = the inner HTML that needs to be changed
function swap_tabs(which)
{
	// Check for DOM support
	if (document.getElementById && document.createTextNode)
	{
		// Lets set come variables
		var job_cont = document.getElementById('jobseeker');
		var emp_cont = document.getElementById('employer');
		var job_lnk = document.getElementById('job_tab');
		var emp_lnk = document.getElementById('emp_tab');
		//var lnk = document.getElementById('register').getElementsByTagName('a')[0];
		
		if (which == "job")
		{
			job_cont.style.display = "block"
			emp_cont.style.display = "none"
			job_lnk.className = "active"
			emp_lnk.className = "inactive"
			//lnk.href = "/jobseekers_registration/";
			//lnk.getElementsByTagName('span')[0].innerHTML = "Jobseeker";
			
		}
		else{
			job_cont.style.display = "none"
			emp_cont.style.display = "block"
			job_lnk.className = "inactive"
			emp_lnk.className = "active"
			//lnk.href = "/employers_registration/";
			//lnk.getElementsByTagName('span')[0].innerHTML = "Employer";
		}
		
	}
}

//--------------------------------------------------------------------------------------------------------
// Function to change the "See" to "Hide" for the products
function see_show_products(which,elem){
	// Check for DOM support
	if (document.getElementById && document.createTextNode)
	{
		var span = document.getElementById(which).getElementsByTagName('span')[0];
		var div  = document.getElementById(elem);
		if (span.innerHTML == '+ See')
		{
			span.innerHTML = '- Hide';
			div.style.display = 'block';
		}
		else{
			span.innerHTML = '+ See';
			div.style.display = 'none';
		}
	}
}


//--------------------------------------------------------------------------------------------------------
// Function to place the users CV online, or igore it
// url = the place that the page must get taken to, to activate the CV
function confirm_cv(url)
{
	// Check for DOM support
	if (document.getElementById && document.createTextNode)
	{
		// Lets set come variables
		var confirmer 	= confirm('Do you want to move this CV into our searchable database?\nRemember, you can take it out at any time.');
		
		if(confirmer){
			location.href = url;
		}
		else{
			location.href = '/cv_control_panel/';
		}
	}
}

//--------------------------------------------------------------------------------------------------------
// Function to place the users CV online, or igore it
// url = the place that the page must get taken to, to activate the CV
function cotw_show(element,text)
{
	// Check for DOM support
	if (document.getElementById && document.createTextNode)
	{
		// Lets set come variables
		var elem = document.getElementById(element);
		
		(elem.className == "no_logo")?elem.className = "logo_hover":elem.className = "no_logo";
		elem.innerHTML = text
	}
}

//--------------------------------------------------------------------------------------------------------
// Function to place the users CV online, or igore it
// url = the place that the page must get taken to, to activate the CV
function swap_application_boxes(show,hide,hide_val)
{
	// Check for DOM support
	if (document.getElementById && document.createTextNode)
	{
		// Lets set come variables
		var show_elem = document.getElementById(show);
		var hide_elem = document.getElementById(hide);
		var hidden = document.getElementById('logged_in');

		show_elem.style.display = "block";
		hide_elem.style.display = "none";
		hidden.value = hide_val;
	}
}

//--------------------------------------------------------------------------------------------------------
// Function to place the users CV online, or igore it
// url = the place that the page must get taken to, to activate the CV
function swap_application_boxes(show,hide,hide_val)
{
	// Check for DOM support
	if (document.getElementById && document.createTextNode)
	{
		// Lets set come variables
		var show_elem = document.getElementById(show);
		var hide_elem = document.getElementById(hide);
		var hidden = document.getElementById('logged_in');

		show_elem.style.display = "block";
		hide_elem.style.display = "none";
		hidden.value = hide_val;
	}
}

function contact_email_swap(selectbox,label,textbox) {
	// Check for DOM support
	if (document.getElementById && document.createTextNode)
	{
		// Lets set come variables
		var selected  = document.getElementById(selectbox);
		var maxi      = (selected.getElementsByTagName('option').length -1);
		var show_elem = document.getElementById(label);
		var hide_elem = document.getElementById(textbox);

		//alert (maxi);

		if (selected.selectedIndex < maxi) {
			show_elem.style.display = "none";
			hide_elem.style.display = "none";
		}
		else{
			show_elem.style.display = "block";
			hide_elem.style.display = "block";
		}
	}
}





