/***********************************************
**
**   File Version:	1.0.2
**   File Date:		2011-02-09
**
***********************************************/


/***********************************************
**
**      Name:	jQuery Tipsy
**   Version:	1.0.0
**      Date:	2011-11-17
**
***********************************************/

	$(function() {

		$('.jqTipsy').tipsy({gravity: $.fn.tipsy.autoNS, fade: true});

	});


/***********************************************
**
**      Name:	jQuery Search AutoComplete
**   Version:	1.0.0
**      Date:	2011-10-25
**
***********************************************/

	$(function() {
		$( "#slkw" ).autocomplete({
			source: "/includes/ajax/search-area.asp?at=1|2|3",
			minLength: 3,
			select: function( event, ui ) {
			    if (ui.item) {
				window.location.href = ui.item.url;
			    }
			}
		})
		.data( "autocomplete" )._renderItem = function( ul, item ) {
			var sItemText = ""

			sItemText = sItemText + "<a><strong>" + item.label + "</strong><br/>" + item.type 
			    if (item.parent != '') {
				sItemText = sItemText + " in " + item.parent
			    }
			sItemText = sItemText + "</a>"

			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( sItemText )
				.appendTo( ul );
		};

	});

/***********************************************
**
**      Name:	jQuery Ajax Link
**   Version:	1.0.0
**      Date:	2011-10-25
**
***********************************************/

	$(function() {
		$('a.ajax').live("click", function(e){
			e.preventDefault();

			var strReason = "";
			var bContinue = true

			var linkURL = $(this).attr('href');
			var linkTyp = $(this).attr('rel');
			var linkPar = $(this).parent().attr('id');

			if (linkTyp == "2") {
				strReason = prompt('Reason for rejection:');
				if (strReason == null) { bContinue = false; return false; }
			} else if (linkTyp == "3") {
				window.location = linkURL;
				bContinue = false;
				return false;
			} else if (linkTyp == "4") {
				bContinue = confirm('Are you sure you want to perform that action?\nWe cannot revert the change if you continue.\n\nProceed with caution.');
			}
		

			if (bContinue) {
				// send requests
				$.post(linkURL, {ajax: "1", reason: strReason}, function(response) {

					//alert(linkPar + ' - ' + response);

					$('#'+linkPar).fadeOut();
					setTimeout("updateHTML('#"+linkPar+"', '"+escape(response)+"', 1)", 400);
				} );
			}
		});
	});


	function updateHTML(oElement, sHTML, bFade) {
		$(oElement).html(unescape(sHTML));
		if (bFade) { $(oElement).fadeIn(); }
	}

/***********************************************
**
**      Name:	jQuery Rate Content
**   Version:	1.0.0
**      Date:	2011-11-17
**
***********************************************/

	$(function() {
		$('a.jqRate').live("click", function(e){
			e.preventDefault();

			var linkURL = $(this).attr('href');
			var linkRel = $(this).attr('rel');

			
			if (linkRel != '') {

			    // send requests
			    $.post(linkURL, {ajax: "1"}, function(response) {

				if ( response == '' ) {

					$("#"+ linkRel).fadeOut();
					setTimeout("updateHTML('#"+ linkRel +"', 0, 1)", 400);

				} else if ( !isNaN(response) ) {

					$("#"+ linkRel).fadeOut();
					setTimeout("updateHTML('#"+ linkRel +"', "+ response +", 1)", 400);

				} else {

					alert(response);

				}
			    });
			}
		});
	});

	function is_numeric(input){
		return typeof(input)=='number';
	}

/***********************************************
**
**      Name:	Delete Table Row
**   Version:	1.0.0
**      Date:	2012-02-15
**
***********************************************/

	$(document).ready(function(){
	    $('a.delRow').live("click", function(e){
		e.preventDefault();

		var linkURL = $(this).attr('href');
		var linkPar = $(this).parent("td").parent("tr").attr('id');

		// send requests
		$.post(linkURL, {ajax: "1"}, function(response) {
			$('#'+linkPar).slideUp();
		});
	    });
	});

/***********************************************
**
**      Name:	jQuery Share Box
**   Version:	1.0.0
**      Date:	2012-02-09
**
***********************************************/

	$(document).ready(function(){
	    $(".shareHolder").hover(function() {
		$(".shareBox").animate({opacity: "show", top: "16px"}, "slow");
	    }, function() {
		$(".shareBox").animate({opacity: "hide", top: "26px"}, "fast");
	    });
	});

/***********************************************
**
**      Name:	Check Terms of Service Agreement
**   Version:	1.0.0
**      Date:	2011-09-29
**
***********************************************/

	function CheckTOS() {

	    if (document.getElementById('tos').checked == true) {
		document.getElementById('Submit').disabled=false;
	    } else {
		document.getElementById('Submit').disabled=true;
	    }
	}


/*******************************************************
**
**      Name:	Popup Window Function
**   Version:	1.0.0
**      Date:	2011-09-30
**
*******************************************************/

	function PopupWin(link,wName,wFeat) {
  		window.open(link,wName,wFeat);
	}


/*******************************************************
**
**      Name:	New Window Function (target=blank)
**   Version:	1.0.0
**      Date:	2011-09-30
**
*******************************************************/

	function ExtSite(link) {
		var theURL = link.href

  		window.open(theURL);
		return false;
	}


/*******************************************************
**
**      Name:	Check for white space form fields
**   Version:	1.1.0
**      Date:	2011-09-30
**
*******************************************************/
		function isSpace1(strTemp) 
		{
			if (strTemp == ' ')
				return false;
			else 
			{
				for (count=1; count < strTemp.length; count++)
				{
					if (strTemp.charAt(count) != ' ')
					return false;
				}
				return true;
			}
		}

	function isSpace(strTemp) {
	    if (strTemp == ' ') {
		return false;
	    } else {
		for (count=1; count < strTemp.length; count++) {
		    if (strTemp.charAt(count) != ' ') { return false; }
		}
		return true;
	    }
	}


/*******************************************************
**
**	Image Maps
**
*******************************************************/

	function newImage(arg) {
		if (document.images) {
			rslt = new Image();
			rslt.src = arg;
			return rslt;
		}
	}

	function changeImages() {
		if (document.images && (preloadFlag == true)) {
			for (var i=0; i<changeImages.arguments.length; i+=2) {
				document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
			}
		}
	}

/*******************************************************
**
**	Legacy Code
**
*******************************************************/

	function openWin(theURL,winName,features) {
  		window.open(theURL,winName,features);
	}

	function DescriptionCharCount(frmName) {
		frmName.count.value = frmName.message.value.length;
	}

	function pageselect(strPage,strPageType) {
			if (strPage == '') {
				alert('Please select a ' + strPageType + ' from the list.')
			} else {
				parent.location = strPage
			}
	}

	function changecolor(tblCell,strColor) {

		tblCell.style.background = strColor;

	}


	function AdvertOut(AdvertID) {

		return false;

		window.open('http://ads.mycountry.co.uk/out/?id=' + AdvertID)
	}



	function SendEmail(AdvertID) {

		// window.location = 'send_email.asp?id=' + AdvertID

		alert('Coming Soon');
	}


	function ViewWebsite(AdvertID) {

		window.open('http://www.hazel-grove.co.uk/business/out.asp?id=' + AdvertID)
	}


	function ViewMap(AdvertID, PostCode) {

		window.open('http://maps.google.com/?q=' + PostCode)
	}

