$(function() {
    $('.info_div').click(function() {$(this).fadeOut('slow')});
    $('.help').hide();
    $('.togglehelp').show();
    $('.togglehelp').click(function(){
        $('.help').toggle();
    });

    $('.goBackConfirm').click(function() {
        if(confirm("Are you sure you want to navigate away from this page?")) {
          history.go(-1);
        }
        return false;
     });
    
  //onload toggle keywords box
  //toggleDesc('hdrKeywords');
  //toggleDesc('hdrPostcode');
    //shortlist
    //$('a[data-href]').each(function() { $(this).attr('href', $(this).attr('data-href'));   });
    $('a[data-href]').mouseover(function(){
        $(this).attr('href', $(this).attr('data-href'));
    }).mouseout(function(){
        //$(this).attr('href', '');
    });
  
  $('#toggleuserlinks').show();
  var userlinksstate = get_cookie("userlinksstate"); //up2date1.js //return null if not existis
  if(userlinksstate == null || userlinksstate == 'visible') {
  	$('.userlinks').show();
  	$('#toggleuserlinksParent').css({"background-color" : "#006D3C"});
  	$('#toggleuserlinks').html("<strong>Hide links</strong>");
  } else if(userlinksstate == 'hidden') {
  	$('.userlinks').hide();
  	$('#toggleuserlinksParent').css({"background-color" : "red"});
  	$('#toggleuserlinks').html("<strong>Show links</strong>");
  }
  
  $('#toggleuserlinks').click(function() {
  		userlinksstate = get_cookie("userlinksstate");
		if(userlinksstate == null || userlinksstate == 'visible') {
		  	$('#toggleuserlinksParent').css({"background-color" : "red"});
  			$(".userlinks").slideToggle('fast');
		  	set_cookie("userlinksstate", "hidden", 1);
		  	$('#toggleuserlinks').html("<strong>Show links</strong>");
		} else if(userlinksstate == 'hidden') {
		  	$(".userlinks").slideToggle('fast');
		  	$('#toggleuserlinksParent').css({"background-color" : "#006D3C"});
		  	set_cookie("userlinksstate", "visible", 1);
		  	$('#toggleuserlinks').html("<strong>Hide links</strong>");
		} 		
  	});
    
    $('.ajaxPreview').click(function(event) {
    	$('<div id="previewContainer"> </div>').appendTo('body');
		event.preventDefault();		
		//var stringId = $(this).attr("id");
		//var stringStatus = $(this).attr("status");
		//var serviceId = stringId.substring(2)
		var stringURL = $(this).attr("href");
		 
				
		$.ajax({
			method: "get"
			, url: stringURL //"preview_entry.php"
			, data: "blah=blah"
			, beforeSend: function(){
				//$("#loading").show("fast");
				} //show loading just when link is clicked
			, complete: function(){ 
				//$("#loading").hide("fast");
				}  //stop showing loading when the process is complete
			, success: function(html){ //so, if data is retrieved, store it in html
				//$("#locationResults").show("slow"); //animation
				//$("#previewContainer").html(html); //show the html inside .content div
				$("#previewContainer").append(html); //show the html inside .content div
				$("#previewContainer").dialog({					
					width: 600,
					modal: true,
					close: function(event, ui) {
						$("#previewContainer").remove();
						}
					});
				}
			 }); //close $.ajax(
			
   }); //close click(
    
   
}); //end doc ready
function dynamic_select(pid)  
{
    $.ajax({
        type: "GET"
        ,url: 'aactions.php'
        ,data: "act=optcat&pid="+pid
        ,dataType: "html"
        ,success: function(html){
            $("#svccat").html(html);     
        }
    });
    
}
/* this is just a simple reload; you can safely remove it; remember to remove it from the image too */
function reloadCaptcha()
{
	document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
}   	
    
function formatItem(row) { return row[1];	} 
function formatResult(row) { return row[0].replace(/(<.+?>)/gi, ''); }
  //Search box text
var term = {"hdrKeywords" : "Search keywords", "hdrPostcode": "Postcode/name", "jbe_email" : "Your email"};
function toggleDesc(el){
	if($("input#" + el + "").val() == ''){ 
		$("input#" + el + "").val(term[el]);
	} else if($("input#" + el + "").val() == term[el]){
		$("input#" + el + "").val('');
	}
}
