﻿//find out if an element exists
//$(document).ready(function() {
//    if ($(".sharethelovethanks").length != 0) {

//        var currentpath = window.location.pathname;
//        var regex = /sharethelove$/
//        if (currentpath.match(regex)) {
//            if (pageTracker) {

//                pageTracker._trackEvent('14daysoflove', 'Submittal',currentpath);
//                //alert("pagetracker implemented");
//            }
//            //            } else {
//            //                alert("Cannot locate pagetracker");

//            //                
//            //            }
//            

//        }


//    }
//});


//Function applies the ajax search functionality to the textbox element as reference in first param.
//The container id selector specified will show the results.  The third parameter shows the function to call from the service 
function ApplyKeyUpFunctionFeatures(featurenametxtboxid,placerefelementid,containerresultsid,functionname) 
{


    unknownfeature(); 
  
    
   // alert(textboxelementid);

    //get the selector id for feature name textbox
    featurenametxtboxid = "#" + featurenametxtboxid;
    
    //get the selector id for hidden box for placeref
    placerefelementid = "#" + placerefelementid;

     

    //Add keyup function to features textbox
   // $(featurenametxtboxid).keyup(function(e) {

        //get current value of featuretextbox
        var curText = $(featurenametxtboxid).val();

        //get current valu eof placeref in hidden box
        // var PlaceRef = $(placerefelementid).val();
        var PlaceRef = $("input[title='hdplaceref']").val();
       
        //alert(curText + String.fromCharCode(e.keyCode));
        //$('#result').html("hello");
         //alert(PlaceRef);
        $.get("/_services/helper.ashx?function=" + functionname + "&featurename=" + curText + "&placeref=" + PlaceRef, function(result) {
            //var oResultData = eval('(' + result + ')');
            //  alert(result);

            $(containerresultsid).addClass("containerselection");
            $(containerresultsid).html(result.toString());

        });

     
   

   // }
  // )

}

function help() {
    alert('hit');

}

function ApplyKeyUpFunctionPlaces(placenametxtboxid,containerresultsid, functionname) {

    
    //amend the selector id
    placenametxtboxid = "#" + placenametxtboxid;
    
     $("input[title='hdplaceref']").val("");

     
    
    //Add keyup function
   // $(placenametxtboxid).keyup(function(e) {

        var curText = $(placenametxtboxid).val();
        
        //alert(curText + String.fromCharCode(e.keyCode));
        //$('#result').html("hello");
        // alert(curText);

        $.get("/_services/helper.ashx?function=" + functionname + "&placename=" + curText, function(result) {
            //var oResultData = eval('(' + result + ')');


            $(containerresultsid).addClass("containerselection");
            $(containerresultsid).html(result.toString());
            
            
            
        });

    //}
   //)

}

function ClearResults(results) {

    //alert(results);
    $(results).removeClass("containerselection");
    $(results).html("");
    

}


function SelectPlace(PlaceRef,PlaceName) {
    //alert(PlaceRef);
    
    
    $("input[title='hdplaceref']").val(PlaceRef.toString());
    
    $("input[rel='places']").val(unescape(PlaceName));
    
    
    //Close the containing box
    ClearResults("#placeresults");
        




}

function knownfeature() {

    //make required elements disappear
    $("#wrapperlblAddress").hide('slow');
    $("#wrapperlblBusinessDo").hide('slow');
    $("#wrappertxtAddress").hide('slow');
    $("#wrappertxtBusinessDo").hide('slow');


    //now make the recommendation box bigger in height
    //find recommendation box
    var recommendationbox = $("textarea.txtfullwidth");

    //now assign the different css class
    recommendationbox.removeClass("txtfullwidth");
    recommendationbox.addClass("txtfullwidthandheight");
    
    
    
    



}

function unknownfeature() {

    $("#wrapperlblAddress").show('slow');
    $("#wrapperlblBusinessDo").show('slow');
    $("#wrappertxtAddress").show('slow');
    $("#wrappertxtBusinessDo").show('slow');

    //now make the recommendation box bigger in height
    //find recommendation box
    var recommendationbox = $("textarea.txtfullwidthandheight");

    //now assign the different css class
    recommendationbox.removeClass("txtfullwidthandheight");
    recommendationbox.addClass("txtfullwidth");
    
    
   

}



function SelectFeature(FeatureRef, FeatureName,PlaceRef,PlaceName) {

    knownfeature();
   

    //alert(FeatureName);
    //alert(PlaceRef);
    //alert(FeatureRef);
    $("input[title='hdfeatureref']").val(FeatureRef.toString());
    
    $("input[title='hdplaceref']").val(PlaceRef.toString());
    //also set the placeref and placename from here.
    //we do this so that we know the placeref and placename recorded is coming from the feature.  This ensures there aren't any mistakes.
    if ($("input[rel='places']").val() != null || $("input[rel='places']").val() == '') {

        $("input[rel='places']").val(unescape(PlaceName))
        

    }
     
    

    //alert(FeatureName);
    $("input[rel='features']").val(unescape(FeatureName));

    //Close the containing box
    ClearResults("#featureresults");

   



}



function tellyourfriends(url) {
    var win = window.open(url, "tellyourfriend", "width=600,height=520;");
}


