// Homepage Registration Input

$(document).ready(function () {
      
   //set focus on registration
   $("#ctl00_cph1_txtRegistration").focus();

    if (! $("#ctl00_cph1_txtRegistration").val() == '') {
            $('#ctl00_cph1_txtRegistration').removeClass('idle');
            $('#ctl00_cph1_txtRegistration').addClass('active');
    }
      
    //test which class to apply on text changed event 
    $("#ctl00_cph1_txtRegistration").keyup(function (event) {
        if ($("#ctl00_cph1_txtRegistration").val() == '') {
            $('#ctl00_cph1_txtRegistration').addClass('idle');
            $('#ctl00_cph1_txtRegistration').removeClass('active');
        }
        else {
            $('#ctl00_cph1_txtRegistration').removeClass('idle');
            $('#ctl00_cph1_txtRegistration').addClass('active');
            
        }
    });

});

////strip out non alphanumeric characters

//$(document).ready(function() {
//	$('#ctl00_cph1_txtBranchLocator').bind("keydown keyup", function(e) {
//		if (this.value != null && this.value.length > 0)
//		{
//			if (this.value.length > 8) this.value = this.value.substring(0, 8);
//			this.value = this.value.replace(/[^a-zA-Z 0-9]+/g, '');		
//		}
//	});
//});

// Branch Locator Postcode Input

$(document).ready(function () {

    //valuation textbox
    $("#ctl00_cph1_txtBranchLocator").focus(function (event) {
        event.preventDefault();
        if ($("#ctl00_cph1_txtBranchLocator").val() == 'Enter postcode') {
            $('#ctl00_cph1_txtBranchLocator').toggleClass('txtPostcodeActive');
            $("#ctl00_cph1_txtBranchLocator").val('');
        }
        else {
            if ($("#ctl00_cph1_txtBranchLocator").val() == '') {
                $('#ctl00_cph1_txtBranchLocator').toggleClass('txtPostcodeIdle');
                $("#ctl00_cph1_txtBranchLocator").val('Enter postcode');
            }
        }
    });
    $("#ctl00_cph1_txtBranchLocator").blur(function (event) {
        event.preventDefault();
        if ($("#ctl00_cph1_txtBranchLocator").val() == '') {
            $('#ctl00_cph1_txtBranchLocator').toggleClass('txtPostcodeActive');
            $("#ctl00_cph1_txtBranchLocator").val('Enter postcode');
        }
    });
});

////strip out non alphanumeric characters

//$(document).ready(function() {
//	$('#ctl00_cph1_txtBranchLocator').bind("keydown keyup", function(e) {
//		if (this.value != null && this.value.length > 0)
//		{
//			if (this.value.length > 8) this.value = this.value.substring(0, 8);
//			this.value = this.value.replace(/[^a-zA-Z 0-9]+/g, '');		
//		}
//	});
//});



// Quick Valuation Registration Input

$(document).ready(function () {

    //valuation textbox
    $("#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall").focus(function (event) {
        event.preventDefault();
        if ($("#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall").val() == 'YOUR REG') {
            $('#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall').toggleClass('txtRegistrationActiveSmall');
            $("#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall").val('');
        }
        else {
            if ($("#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall").val() == '') {
                $('#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall').toggleClass('txtRegistrationIdleSmall');
                $("#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall").val('YOUR REG');
            }
        }
    });
    $("#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall").blur(function (event) {
        event.preventDefault();
        if ($("#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall").val() == '') {
            $('#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall').toggleClass('txtRegistrationActiveSmall');
            $("#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall").val('YOUR REG');
        }
    });
});

//strip out non alphanumeric characters

$(document).ready(function() {
	$('#ctl00_cph1_RightColumn1_QuickValuation1_txtRegistrationSmall').bind("keydown keyup", function(e) {
		if (this.value != null && this.value.length > 0)
		{
			if (this.value.length > 8) this.value = this.value.substring(0, 8);
			this.value = this.value.replace(/[^a-zA-Z 0-9]+/g, '');		
		}
	});
});



// Quick Branch Locator Postcode Input

$(document).ready(function () {

    //valuation textbox
    $("#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator").focus(function (event) {
        event.preventDefault();
        if ($("#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator").val() == 'Enter postcode') {
            $('#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator').toggleClass('txtPostcodeActiveSmall');
            $("#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator").val('');
        }
        else {
            if ($("#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator").val() == '') {
                $('#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator').toggleClass('txtPostcodeIdleSmall');
                $("#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator").val('Enter postcode');
            }
        }
    });
    $("#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator").blur(function (event) {
        event.preventDefault();
        if ($("#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator").val() == '') {
            $('#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator').toggleClass('txtPostcodeActiveSmall');
            $("#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator").val('Enter postcode');
        }
    });
});

//strip out non alphanumeric characters

$(document).ready(function() {
	$('#ctl00_cph1_RightColumn1_BranchLocator1_txtBranchLocator').bind("keydown keyup", function(e) {
		if (this.value != null && this.value.length > 0)
		{
			if (this.value.length > 8) this.value = this.value.substring(0, 8);
			this.value = this.value.replace(/[^a-zA-Z 0-9]+/g, '');		
		}
	});
});



/* Functions for the 'more' link dropdown */ 
$(function () {
    $(this).find('#morePopup').hide();
});

$(function () {
    $("#v3NavHeaderLink3").bind('mouseover', function () {
        $('#morePopup').fadeIn('fast');
    });

    $("#morePopup").bind('mouseleave', function () {
        //$('#morePopup').hide();
        $('#morePopup').fadeOut('fast');
    });
});


/* More Services */
$(function () {
    $(this).find('#moreServices').hide();
});

$(function () {
    $("#ctl00_hypMoreServices").bind('mouseover', function () {
        $('#moreServices').fadeIn('fast');
        $('#morePopup').fadeOut('fast');
    });

    $("#moreServices").bind('mouseleave', function () {
        //$('#morePopup').hide();
        $('#moreServices').fadeOut('fast');
    });
});


//////JQuery Message Box \\\\\\

//jQuery Tool Tips Show
function showToolTipTouchScreen(control, tooltip, align, vert)
{
    hideAllToolTips();
    
    $("#"+tooltip).css("visibility", "visible"); 
    $("#"+tooltip).css("display", "block"); 
    
    var pos   = $("#"+control.id).position();
    var width = $("#"+control.id).width();
    var height = $("#"+tooltip).height();
    //alert(height);
    
	if (align == 'right')
	{
		$("#" + tooltip).css("margin-left", -30);
	}
	else 
	{
		$("#" + tooltip).css("margin-left", 410);
	}
	
	if (vert == 'flip') {
	     $("#"+tooltip).css("top", pos.top - height+34);
	}
	else {
	    $("#"+tooltip).css("top", pos.top - 9);  
	}
    
    $("#"+tooltip).delay(5000).fadeOut(2000); 
    
}

//jQuery Tool Tips Show
function showToolTip(control, tooltip, align, vert)
{
    hideAllToolTips();
    
    $("#"+tooltip).css("visibility", "visible"); 
    var pos   = $("#"+control.id).position();
    var width = $("#"+control.id).width();
    var height = $("#"+tooltip).height();

	if (align == 'right')
	{
		$("#" + tooltip).css("margin-left", -30);
	}
	else 
	{
		$("#" + tooltip).css("margin-left", 410);
	}
	
	if (vert == 'flip') {
	     $("#"+tooltip).css("top", pos.top - height+34);
	}
	else {
	    $("#"+tooltip).css("top", pos.top - 9);  
	}

	
}
//jQuery Tool Tips Hide
function hideToolTip(control, tooltip)
{
    $("#"+tooltip).css("visibility", "hidden"); 
}
//jQuery to Hide All Tool Tips
function hideAllToolTips()
{
    $("div[type='tt']").css("visibility", "hidden");
}
 
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var currentPopup = '';


//Jquery popups
$(document).ready(function () {
    //LOADING POPUP
    //Click the button event!
    $("#ctl00_cph1_rblV5_1").click(function () {
        //centering with css
        centerPopup('#divV5Warning');
        //load popup
        loadPopup('#divV5Warning');
    });

    $("#ctl00_cph1_VehicleDetails_rblMOT_1").click(function () {
        //centering with css
        centerPopup('#divMOTWarning');
        //load popup
        loadPopup('#divMOTWarning');
    });

    $("#ctl00_cph1_VehicleDetails_rblMechanical_3").click(function () {
        //centering with css
        centerPopup('#divNonRunnerWarning');
        //load popup
        loadPopup('#divNonRunnerWarning');
    });



    //CLOSING POPUP
    //Click the x event!
    $("#closePlate").click(function () { disablePopup(); });
    $("#closeV5").click(function () { disablePopup(); });
    $("#closeMOT").click(function () { disablePopup(); });
    $("#closeNoneRunner").click(function () { disablePopup(); });

    //Click out event!
    $("#backgroundPopup").click(function () { disablePopup(); });
    //Press Escape event!
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
});


//loading popup with jQuery magic!
function loadPopup(popupID) {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#backgroundPopup").css({ "opacity": "0.7" });
        $("#backgroundPopup").fadeIn("fast");
        $(popupID).fadeIn("fast");
        popupStatus = 1;
        currentPopup = popupID;
    }
}
//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $(currentPopup).fadeOut("slow");
        popupStatus = 0;
    }
}
//centering popup
function centerPopup(popupID) {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(popupID).height();
    var popupWidth = $(popupID).width();
    //centering
    $(popupID).css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6
    $("#backgroundPopup").css({ "height": windowHeight });
}


// homepage readmore

$(document).ready(function(){
$('#homepageContent').hide();
$('#hide').hide();
   $("#show").click(function(event){
     $('#homepageContent').slideDown();
     $('#show').hide();
     $('#hide').show();     
     $('html, body').animate({scrollTop: $(document).height()}, 'slow'); 
     event.preventDefault();          
   });
   $("#hide").click(function(event){
     $('#homepageContent').slideUp();
     $('#show').show();
     $('#hide').hide();
     $("html, body").animate({ scrollTop: 0 }, "slow");     
     event.preventDefault();
     
   }); 
 });
 
 function OpenWindow(url)
{
    window.open(url, '', 'height=600, left=50px, menubar=0, resizable=1, scrollbars=0, status=0, top=50px, width=800, scrollbars=1');
}

function DisableDefaultOptionalExtras(Control, Index)
{
		var x = document.getElementById(Control + '_' + Index);
		x.disabled = true;
}

var qsParm = new Array();
function qs()
{
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsParm[key] = val;
}
}
}

qsParm['affiliate'] = null;
qsParm['ID'] = null;
qsParm['VehicleAreaID'] = null;
qsParm['PARTEX'] = null;
qs();


//bookmark.js
    /***********************************************
    * Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    /* Modified to support Opera */
    function bookmarksite(title,url){
    if (window.sidebar) // firefox
	    window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
	    var elem = document.createElement('a');
	    elem.setAttribute('href',url);
	    elem.setAttribute('title',title);
	    elem.setAttribute('rel','sidebar');
	    elem.click();
    } 
    else if(document.all)// ie
	    window.external.AddFavorite(url, title);
    }
    
    
function redirTimer(reg) {
    wait = "15000";
    url = "http://www.webuyanycar.com/valuemycar.aspx?reg=" + reg;
    self.setTimeout("self.location.href = url;",wait);
}

function fixupClickTale(){
    $(":text, select, textarea").each(function() {
    $(this).addClass("ClickTaleSensitive");
    });
}


//////////Cookie Warning\\\\\\\\\\\
function closeCookiePopup(ocls,oControl){
    var oCloseBtn = oControl.parentNode;// document.getElementById('ctl00_cph1_VehicleConfirmation_divCookieWarning');
    oCloseBtn.style.display = 'none';  
}

// branch profile FAQ //
    $(document).ready(function() {
        // Hide the toggle divs
        $('div.toggleTarget').hide();
        // Watch for clicks on the "toggleLinks" link. 
        $('span.toggleHeading a').click(function() {
            // Get id of clicked link and use it to construct of target div
            $targetId = $(this).attr("id") + "target";
            // When clicked, toggle the target div. 
            $('div#' + $targetId).toggle();
            // Toggle the link text to display either 'show' or 'hide' message
        //	toggleLinkTxt(this);
        //	toggleLinkBg(this);
            return false;
        });
    });


    //Vehicle Confirmation - highlight differences
    function highlightScript(count, rptId) {

        //highlight colour
        var highlightColour = '#fdb913';

        //declare our array variables
        var RegistrationArray = new Array();
        var ManufacturerArray = new Array();
        var ModelArray = new Array();
        var DerivativeArray = new Array();
        var BodyTypeArray = new Array();
        var FuelTypeArray = new Array();
        var FuelDeliveryArray = new Array();
        var YearArray = new Array();
        var ColourArray = new Array();
        var TransmissionArray = new Array();
        var DriveTrainArray = new Array();
        var EngineArray = new Array();
        var FirstRegisteredArray = new Array();


        //Registration field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdRegistration').html(), RegistrationArray) == -1) {
                RegistrationArray.push($('#' + rptId + '_ctl0' + i + '_tdRegistration').html());
            }
        }
        //if statement
        if (RegistrationArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trRegistration').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Manufacturer field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdManufacturer').html(), ManufacturerArray) == -1) {
                ManufacturerArray.push($('#' + rptId + '_ctl0' + i + '_tdManufacturer').html());
            }
        }
        //if statement
        if (ManufacturerArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trManufacturer').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Model field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdModel').html(), ModelArray) == -1) {
                ModelArray.push($('#' + rptId + '_ctl0' + i + '_tdModel').html());
            }
        }
        //if statement
        if (ModelArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trModel').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Model year field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdModelYear').html(), YearArray) == -1) {
                YearArray.push($('#' + rptId + '_ctl0' + i + '_tdModelYear').html());
            }
        }
        //if statement
        if (YearArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trModelYear').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Derivative field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdDerivative').html(), DerivativeArray) == -1) {
                DerivativeArray.push($('#' + rptId + '_ctl0' + i + '_tdDerivative').html());
            }
        }
        //if statement
        if (DerivativeArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trDerivative').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }

        //Body Type field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdBodyType').html(), BodyTypeArray) == -1) {
                BodyTypeArray.push($('#' + rptId + '_ctl0' + i + '_tdBodyType').html());
            }
        }
        //if statement
        if (BodyTypeArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trBodyType').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Fuel Type field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdFuelType').html(), FuelTypeArray) == -1) {
                FuelTypeArray.push($('#' + rptId + '_ctl0' + i + '_tdFuelType').html());
            }
        }
        //if statement
        if (FuelTypeArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trFuelType').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Fuel Delivery field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdFuelDelivery').html(), FuelDeliveryArray) == -1) {
                FuelDeliveryArray.push($('#' + rptId + '_ctl0' + i + '_tdFuelDelivery').html());
            }
        }
        //if statement
        if (FuelDeliveryArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trFuelDelivery').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Colour field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdColour').html(), ColourArray) == -1) {
                ColourArray.push($('#' + rptId + '_ctl0' + i + '_tdColour').html());
            }
        }
        //if statement
        if (ColourArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trColour').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Transmission field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdTransmission').html(), TransmissionArray) == -1) {
                TransmissionArray.push($('#' + rptId + '_ctl0' + i + '_tdTransmission').html());
            }
        }
        //if statement
        if (TransmissionArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trTransmission').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Drive Train field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdDriveTrain').html(), DriveTrainArray) == -1) {
                DriveTrainArray.push($('#' + rptId + '_ctl0' + i + '_tdDriveTrain').html());
            }
        }
        //if statement
        if (DriveTrainArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trDriveTrain').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //Engine Size field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdEngineSize').html(), EngineArray) == -1) {
                EngineArray.push($('#' + rptId + '_ctl0' + i + '_tdEngineSize').html());
            }
        }
        //if statement
        if (EngineArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trEngineSize').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }


        //First Registered field
        //add each item to the array
        for (i = 0; i <= count; i++) {
            //test that item is not in the array before we add it
            if (jQuery.inArray($('#' + rptId + '_ctl0' + i + '_tdFirstRegistered').html(), FirstRegisteredArray) == -1) {
                FirstRegisteredArray.push($('#' + rptId + '_ctl0' + i + '_tdFirstRegistered').html());
            }
        }
        //if statement
        if (FirstRegisteredArray.length > 1) {
            //set highlight
            for (i = 0; i <= count; i++) {
                $('#' + rptId + '_ctl0' + i + '_trFirstRegistered').css("background", highlightColour);
            }
            $('#highlightKey').css("display", "block");
        }
    }
