$(function() {
    $('.info_div').click(function() {$(this).fadeOut('slow')});
	/*
    $('<span class="exit">X</span>').appendTo('div#alertbox');
	$('div#alertbox').fadeIn(800).fadeOut('slow').fadeIn(800).fadeOut('slow').fadeIn();
	$('span.exit').click(function() {
		$(this).parent('div#alertbox').slideUp('slow');
	});

	$('<span class="exit">X</span>').appendTo('div.hideable');
	$('span.exit').click(function() {
		$(this).parent().slideUp('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');
  writePhpTACookie();
  
  
  $('#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" : "#6CC020"});
  	$('#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" : "#6CC020"});
		  	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

/* 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('');
	}
}  

function writePhpTACookie() {
	date=new Date;
	date.setMonth(date.getMonth()+1);
	var name = "phpTA_resolution";
	var value = screen.width +"x"+ screen.height;
	var domain = "amsdev.co.uk";
	var path= "/";
	document.cookie=name+"="+escape(value)+"; expires="+date.toGMTString()+"; path="+path+"; domain="+domain;
	
	date=new Date;
	date.setMonth(date.getMonth()+1);
	var name = "phpTrafficA_style";
	var value = "green";
	var domain = "amsdev.co.uk";
	var path= "/";
	document.cookie=name+"="+escape(value)+"; expires="+date.toGMTString()+"; path="+path+"; domain="+domain;
}
//window.onload=writePhpTACookie;
