$(document).ready(function(){
		
	// js checkboxes
	$('.checkBoxList li a, .checkBoxList_new li a').click(function() {
		var checking = $(this).hasClass('checked');
		var checked = $(this).attr('href');
		var id = $(this).attr('rel');
		var postName = checked.replace('#', '')
		if (checking)
		{
			//true
			$(this).attr('class', '');
			$(checked + ' .checkBoxFormItems #input-' + id).remove();
		}
		else
		{
			// false
			$(this).attr('class', 'checked');
			$(checked + ' .checkBoxFormItems').append('<input id="input-' + id + '" type="hidden" name="' + postName + '[]" value="' + id + '" />');	
		}									 
	});
	
	// close all msg boxes after 6000ms 
	setInterval( "closeBoxs()", 6000 );
	
	// show form notes
	$('.do_notes .form-item').click(function () {
		$('.form-note').css('visibility','hidden');									  
		$(this).children('.form-note').css('visibility','visible');	
	});
	
	// form view slider
	$('.toolViewItem').click(function () {	   
		var form = $(this).attr('href');
		var id = $(this).attr('rel');
		$(".sliderView").hide();
		$('#sliderView-' + id).slideToggle("slow");
		$('#sliderEdit-' + id).hide("slow");
	});
	
	//add by roy
	$('.toolEditItem').click(function () {									   
		var form = $(this).attr('href');
		var id = $(this).attr('rel');
		$(".sliderView").hide();
		$('#sliderEdit-' + id).slideToggle("slow");
		$('#sliderView-' + id).hide("slow");
	});
		
	// form delete item.
	$('.toolDeleteItem').click(function () {
		var form = $(this).attr('href');
		var id = $(this).attr('rel');
		if(!confirm('Are you sure you want to delete?'))  
		{ 
			return false; 
		}
		$.ajax({
			 type: "POST",
			 url: "/ajax.php",
			 data: "formType=deleteItem&form=" + form + "&id=" + id,
			 success: function(html){
			$('.output').html(html);
			$('#item-' + id).remove();
			 }
		});
	});
	
		// form delete item.
	$('.toolRemoveShortlistItem').click(function () {
		var form = $(this).attr('href');
		var id = $(this).attr('rel');
		var originalContent = $('.output').html();
		if(!confirm('Are you sure you want to remove this shortlisted job?'))  
		{ 
			return false; 
		}
		$.ajax({
			 type: "POST",
			 url: "/ajax.php",
			 data: "formType=removeFromShortlist&form=" + form + "&id=" + id,
			 success: function(html){
		 	$('.preoutput').html(html);
			$('#item-' + id).remove();
			 }
		});
	});
	
	$(".defaultItem").hide();
	// edit form fields
	$('.editElement .editItem').click(function () {
		var current = $(this).attr('href');
		$(current + ' .textView').hide();
		$(current + ' .formView').show();
		$(".defaultItem").show();
		
		//add by roy
		$(current + ' .formView .form-item').show();
		$(current + ' .formView .form-buttons').show();
		
	});
	
	// view form fields
	$('.editElement .defaultItem').click(function () {
		var current = $(this).attr('href');
		$(current + ' .formView').hide();
		$(".defaultItem").hide();
		$(current + ' .textView').show();
	});
	
	// process forms
	$('.ajax').submit(function() { 
		$(".sitebar_results").hide();
		$('.default_results').hide();
		var form = $(this).attr('id');
		$('#' + form + ' .loader').show();
        $(this).ajaxSubmit( { target: form + ' .output', beforeSubmit: showRequest } ); 
		$('#' + form + ' .textView').remove();
        return false; 
    });
	
	$('.address_country select').click(function() {
		var option = $(this).attr('value');	
		$.ajax({
		  type: "POST",
		  url: "/ajax.php",
		  data: "formType=addressDetails&country=" + option,
		  success: function(html){
			$('.address_city').hide();
			$('.results_address').html(html);
		  }
		});					 
	});
	
	$('.site_colours li a').click(function() {
		$('.site_colours li a').removeClass("selected")
		var colour = $(this).attr('class');
		$('#site_colour').val(colour);
		$(this).attr('class', colour + ' selected');
	});
	
	//employer read more
	
	$(".employers_more_detail").css("display", "none");
	$(".employers_more").css("text-align","right");
	$(".employers_more").click(function(){
		$(this).next(".employers_more_detail").slideToggle("slow");							
	});
	
	//add by roy for tutorial overlay
	$("a.tutorial_links[rel]").overlay({ 
        // start exposing when overlay starts to load 
        onBeforeLoad: function() { 
             
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = this.getContent().find("div.wrap"); 
         
			// load only for the first time it is opened            
			wrap.load(this.getTrigger().attr("href"));     
			    
        },  
         
        // when overlay is closed take the expose instance and close it as well 
        onClose: function() { 
            $.expose.close(); 
			window.location.reload();
        } 
         
    }); 
	
	//add by roy for tests overlay
	$("a.presentation_link[rel]").overlay({ 
        // start exposing when overlay starts to load 
        onBeforeLoad: function() { 
             
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = this.getContent().find("div.content"); 
         
			// load only for the first time it is opened            
			wrap.load(this.getTrigger().attr("href"));     
			    
        },  
         
        // when overlay is closed take the expose instance and close it as well 
        onClose: function() { 
            $.expose.close();
			window.location.reload();
        } 
         
    }); 
	
	//add by roy for tests overlay
	$("a.cccc_links[rel]").overlay({ 
        // start exposing when overlay starts to load 
        onBeforeLoad: function() { 
             
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = this.getContent().find("div.ccc"); 
         
			// load only for the first time it is opened            
			wrap.load(this.getTrigger().attr("href"));     
			    
        },  
         
        // when overlay is closed take the expose instance and close it as well 
        onClose: function() { 
            $.expose.close(); 
        } 
         
    }); 
	
	$("a.what_we_do_link[rel]").overlay({ 
        // start exposing when overlay starts to load 
        onBeforeLoad: function() { 
             
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = this.getContent().find("div.what_we_do_content"); 
         
			// load only for the first time it is opened            
			wrap.load(this.getTrigger().attr("href"));     
			    
        },  
         
        // when overlay is closed take the expose instance and close it as well 
        onClose: function() { 
            $.expose.close(); 
        } 
         
    }); 
	
	//add by roy for tests overlay
	$("a.courses_link[rel]").overlay({ 
        // start exposing when overlay starts to load 
        onBeforeLoad: function() { 
             
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = this.getContent().find("div.content"); 
         
			// load only for the first time it is opened            
			wrap.load(this.getTrigger().attr("href"));     
			    
        },  
         
        // when overlay is closed take the expose instance and close it as well 
        onClose: function() { 
            $.expose.close(); 
			window.location.reload();
        } 
         
    }); 
	
	
	$("a.new_links[rel]").overlay({
        onBeforeLoad: function()
		{		
			this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = 	this.getContent().find("div.wrap");
			
			wrap.load(this.getTrigger().attr("href"));
         
		},
		
		onClose: function(){
			$.expose.close();
			}
	
	}); 	
	
	$("a.need[rel]").overlay({
        onBeforeLoad: function()
		{		
			this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = 	this.getContent().find("div.cc_course");
			
			wrap.load(this.getTrigger().attr("href"));
         
		},
		
		onClose: function(){
			$.expose.close();
			}
	
	}); 
	
	//employer page overlay
	$("a.post_it_link[rel],a.free_download_link[rel]").overlay({ 
        // start exposing when overlay starts to load 
        onBeforeLoad: function() { 
             
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = this.getContent().find("div.post_info"); 
         
			// load only for the first time it is opened            
			wrap.load(this.getTrigger().attr("href"));     
			    
        },  
         
        // when overlay is closed take the expose instance and close it as well 
        onClose: function() { 
            $.expose.close();
        } 
         
    }); 
	
	$("a.job_board_link[rel]").overlay({ 
         // start exposing when overlay starts to load 
        onBeforeLoad: function() { 
             
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = this.getContent().find("div.info"); 
         
			// load only for the first time it is opened            
			wrap.load(this.getTrigger().attr("href"));     
			    
        },  
         
        // when overlay is closed take the expose instance and close it as well 
        onClose: function() { 
            $.expose.close();
			window.location.reload();
        } 
         
    }); 
	
	$("a.testimonial_link[rel]").overlay({ 
         // start exposing when overlay starts to load 
        onBeforeLoad: function() { 
             
            // this line does the magic. it makes the background image sit on top of the mask 
            this.getBackgroundImage().expose({color: '#fff'});
			
			var wrap = this.getContent().find("div.t_info"); 
         
			// load only for the first time it is opened            
			wrap.load(this.getTrigger().attr("href"));     
			    
        },  
         
        // when overlay is closed take the expose instance and close it as well 
        onClose: function() { 
            $.expose.close();
			window.location.reload();
        } 
         
    }); 
	
	$("a.required").click(function(){
		alert("You need to have filled in more information within your profile and CV area. Please check you profile and populate all areas marked with a *.");
	});
	
	$("a.cv_required").click(function(){
		alert("You need to have filled in more information within your CV area. Please check you cv and populate all areas marked with a *.");
	});
	
	$("a.mycv_link").click(function(){
		alert("To apply for a job you need to either complete your online CV or upload a CV");
	});
	
});

// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    var queryString = $.param(formData); 
	var loader = '#' + options['target'].replace('.output', '.loader');
	var form = '#' + options['target'].replace('.output', '');
	var dhf = $(form).attr('class');
	$.ajax({
	  type: "POST",
	  url: "/ajax.php",
	  data: queryString,
	  success: function(html){
		$('#' + options['target']).html(html);
		// hide form if hide option isn't set
		if (dhf != "editElement noFormHide")
		{			
			$(form + ' .formView').show();			
		}
		$(loader).hide();
		
		// form view slider
		$('.toolViewItem').click(function () {
			var view_id = $(this).attr('rel');
			$(form + ' .output #sliderView-' + view_id).slideToggle("slow");
		});
		
		
		// form delete item.
		$('.toolDeleteItem').click(function () {
			var del_id = $(this).attr('rel');
			if(!confirm('Are you sure you want to delete?'))  
			{ 
				return false; 
			}
			$.ajax({
				 type: "POST",
				 url: "/ajax.php",
				 data: "formType=deleteItem&form=" + form + "&id=" + del_id,
				 success: function(html){
				$(form + ' #item-' + del_id).remove();
				 }
			});
		});
		
	  }
	});
    return true; 
}

// hide any msg boxes
function closeBoxs()
{
	$(".doBox").hide();
}

function reFresh() {
  location.reload(true)
}
