﻿/// <reference path="jqIntellisense/jquery141.js"/>
//Page Pos / Vehicle Type Setter
function LoadPopUnder(url) {
    window.open("http://referral.contracthireandleasing.com/popunder.aspx?url=" + url + "&referer=http%3a%2f%2f" + window.location.host, "Redirect", "height=600,width=800,resizable=1,scrollbars=1").blur();
    window.focus();
}
function LoadPopUp(url) {
	window.open("http://referral.contracthireandleasing.com/popunder.aspx?url=" + url + "&referer=http%3a%2f%2f" + window.location.host, "Redirect", "height=600,width=800,resizable=1,scrollbars=1");
}
function getScrollPos() { loadXMLDoc("", "set-values.aspx?pos=" + $(window).scrollTop() + "&date=" + new Date().getTime(), true); }
// General Functions
function CancelCheck(el) { if (el.checked) { el.checked = false; } else { el.checked = true; } }
function postform() { document.forms[0].action = ''; document.forms[0].submit(); }
function CheckSecurityCode(cID) {
    var xmlhttp = null; var jsonObject;
    var url = "/DealDataService.svc/CheckCAPTCHA";
    if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }
    else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    if (xmlhttp != null) { xmlhttp.open("POST", url, false); xmlhttp.setRequestHeader("Content-type", "application/json"); xmlhttp.send('{"code":"' + $("#" + cID + "txtCaptchaCode").val() + '"}'); if (xmlhttp.readyState == 4) { if (xmlhttp.status == 200) { jsonObject = eval('(' + xmlhttp.responseText + ')'); } } }
    if (jsonObject.d) { if (window.AddProfileJSON != undefined) { AddProfileJSON(); } return true; } else { alert('The security code you entered does not match.'); RegenerateCaptcha($("#" + cID + "imgCaptcha")); return false; }
}
function RegenerateCaptcha(el) { el.attr("src", "/captcha.aspx?noCache=" + new Date().getTime()); }
var xmlhttp;
$(document).ready(function () {
    var rows = document.getElementsByTagName('img');
    for (var i = 0, row; row = rows[i]; i++) {
        if (row.id.indexOf('IMG:') != -1) {
            var arrImg = row.id.split(":");
            row.src = $('#hidImageLocation').val().replace('$$', arrImg[6]) + '/' + $('#hidSiteId').val() + '/' + arrImg[1] + '/' + arrImg[2] + '/' + arrImg[3] + '/' + arrImg[4] + '/';
        }
    }
    var rows2 = document.getElementsByTagName('div');
    for (var i = 0, row; row = rows2[i]; i++) {
        if (row.id.indexOf('AD-') != -1) {
            var arrAd = row.id.split("-");
            LoadBanners(document.URL, arrAd[1], arrAd[2], navigator.userAgent, arrAd[3], arrAd[4], row.id);
        }
    }
    $(".fade1").hover(
        function () { $(this).find('.fade').stop(true, false).animate({ "opacity": "0" }, 400); },
        function () { $(this).find('.fade').stop(true, false).animate({ "opacity": "1" }, 400); });
    $(".expander").click(
        function () { var el = $(this); $(this).prev().animate({ "height": $(this).prev().find('div').outerHeight() + $(this).prev().find('p').outerHeight() + 35, "opacity": "1" }, 400); $(this).css('display', 'none'); $(this).next().css('display', 'block'); setTimeout(function () { el.prev().css("filter", "") }, 410); RecordStat($(this).attr("id").split("_")[2], 'deal', $(this).attr("id").split("_")[1], 'expansion'); });
    $(".collapse").click(
        function () { $(this).prev().prev().animate({ "height": 0, "opacity": "0" }, 400); $(this).css('display', 'none'); $(this).prev().css('display', 'block'); });
    SetLeftNav();
    SetHomeNews();
    MenuHover('cldHover', 'cldDiv');
    MenuHover('vldHover', 'vldDiv');
    MenuHover('gHover', 'gDiv');
//    CallWcfAjax('VehicleDataService.svc', 'SetLeaderboardBanner', '', 'SetBanner(jsonObject)');
});
function MenuHover(hover, display) {
    $('#' + hover).hover(function () { $('#' + display).css("display", "block") }, function () { $('#' + display).css("display", "none") });
}
function SetBanner(data) {
    $('#lbbanner').html(data.d);
    $(".sponsor-close").click(function() { $(".sponsor-slider-panel").slideToggle("slow"); $(this).toggleClass("active"); return false; });
    $(".sponsor-logo").click(function() { $(".sponsor-slider-panel").slideToggle("slow"); $(".sponsor-close").toggleClass("active"); return false; });
   }
function ResetNewsSearch() {
	CallWcfAjax('VehicleDataService.svc', 'ResetNewsSearch', '', 'SetBanner(jsonObject)');
}
function loadXMLDoc(jsFunction, url) {
    xmlhttp = null;
    if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }
    else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    if (xmlhttp != null) {
    	xmlhttp.open("GET", url, true);
    	xmlhttp.send(null);
    	xmlhttp.onreadystatechange = function X() {
    		if (xmlhttp.readyState == 4) {
    			if (xmlhttp.status == 200) {
    				var sValue = xmlhttp.responseText;
    				eval(jsFunction);
    			}
    		}
    	}
    }
    else { alert("Your browser does not support XMLHTTP."); }
}
function CallWcfAjax(serviceName, functionName, functionParams, jsFunction) {
    var xmlhttp = null;
    var url = "/" + serviceName + "/" + functionName
    if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }
    else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    if (xmlhttp != null) {
        xmlhttp.open("POST", url, true);
        xmlhttp.setRequestHeader("Content-type", "application/json");
        xmlhttp.send(functionParams);
        xmlhttp.onreadystatechange = function X() {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    var jsonObject = eval('(' + xmlhttp.responseText + ')');
                    eval(jsFunction);
                }
            }
        }
    }
    else { alert("Your browser does not support XMLHTTP."); }
}
function GetMakeData(el ,ddl) {
    if (ddl != "") { $("select[id$=" + ddl + "] > option").remove(); $('#' + ddl).append($('<option></option>').val("").html("Loading ...")); }
    CallWcfAjax('VehicleDataService.svc', 'GetAvailableManufacturers', '{"vehType":"' + el.val() + '"}', 'PopulateModelDropdown(jsonObject, \'' + ddl + '\', \'' + el.val() + '\')');
}
function GetModelData(el, ddl, vehType) {
	$('#' + ddl).attr('disabled', 'disabled');
	if (ddl != "") { $("select[id$=" + ddl + "] > option").remove(); $('#' + ddl).append($('<option></option>').val("").html("Loading ...")); }
    CallWcfAjax('VehicleDataService.svc', 'GetAvailableRanges', '{"manufacturer":"' + el.val() + '", "vehType":"' + vehType + '"}', 'PopulateModelDropdown(jsonObject, \'' + ddl + '\', \'' + vehType + '\')');
}
function GetCompModelData(el, ddl, profileGUID) {
    if (ddl != "") { $("select[id$=" + ddl + "] > option").remove(); $('#' + ddl).append($('<option></option>').val("").html("Loading ...")); }
    CallWcfAjax('VehicleDataService.svc', 'GetProfileRanges', '{"manufacturer":"' + el.val() + '", "profileGUID":"' + profileGUID + '"}', 'PopulateModelDropdown(jsonObject, \'' + ddl + '\', \'' + profileGUID + '\')');
}
function PopulateModelDropdown(data, ddl, vehType) {
    $("select[id$=" + ddl + "] > option").remove();
    $('#' + ddl).append($('<option></option>').val("").html("Search " + ((ddl == 'ddlMake') ? "Make" : "Model")));
    for (var i = 0; i < data.d.length; i++) {
        $('#' + ddl).append($('<option></option>').val(data.d[i].URLName).html(data.d[i].Name));
    }
    if ($('#' + ddl.replace('ddl', 'hid')).val() != null) $('#' + ddl).val($('#' + ddl.replace('ddl', 'hid')).val());
    if ($('#' + $('#hidCompClientID').val() + ddl.replace('ddl', 'hid')).val() != null) $('#' + ddl).val($('#' + $('#hidCompClientID').val() + ddl.replace('ddl', 'hid')).val());
    if (($('#hidMake').val() != "") && (ddl == 'ddlMake')) {
    	GetModelData($('#ddlMake'), 'ddlModel', vehType);
    }
    $('#' + ddl).removeAttr('disabled');
}
function CheckIsNumbers(el, checkPoint) { var regex = new RegExp(/[^0-9]/g); if (regex.test(el.value.substring(el.value.length - 1, el.value.length))) { if (el.value.substring(el.value.length - 1, el.value.length) != ".") { el.value = el.value.replace(regex, ""); alert('Sorry, only numbers allowed!'); } else { el.value = el.value.substring(0, el.value.length - 1); if (checkPoint) { $(el).next().focus(); } } } }
function AddThousandComma(el) { var regex = new RegExp(",", "g"); el.val(el.val().replace(regex, "")); var decimalValue = ''; if (el.val().indexOf(".") != -1) { el.val(el.val().replace(".", "")); decimalValue = el.val().substring(el.val().length - 2, el.val().length); el.val(el.val().substring(0, el.value.length - 2)); } var elValue = el.val(); var finalValue = ''; if (el.val().length > 3) { for (var i = 1; i <= parseInt((el.val().length - 1) / 3); i++) { var choppedValue = elValue.substring(elValue.length - 3, elValue.length); elValue = elValue.substring(0, elValue.length - 3); finalValue = ',' + choppedValue + finalValue; } } if (decimalValue != '') { if (decimalValue.length == 1) { el.val() = elValue + finalValue + ".0" + decimalValue; } else { el.val(elValue + finalValue + "." + decimalValue); } } else { el.val(elValue + finalValue); } }
function AddLeadingZero(val) { if (val < 10) { return "0" + val; } else { return val; } }
function AddCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
function CloseToolTip(el) { el.css('display', 'none'); }
//Search Tabs
function CompanyCat(el, type) {
    el.children(':first').attr('checked', 'checked');
    el.parent().addClass('active');
    (type == 'main' ? el.parent().next().removeClass('active') : el.parent().prev().removeClass('active'));
    $('#divMainDealer').css('display', (type == 'main' ? 'block' : 'none'));
    $('#lblPostcode').css('display', (type == 'main' ? 'none' : 'block'));
}
function ShowSearch(searchType, tab) {
    $("#searchVehicle").css('display', 'none');
    $("#aVehicle").removeAttr("class");
    $("#searchCompany").css('display', 'none');
    $("#aCompany").removeAttr("class");
    $("#popularSearch").css('display', 'none');
    $("#aPopular").removeAttr("class");
    $('#' + searchType).css('display', 'block');
    $('#' + tab).addClass("search-active");
    CallWcfAjax('VehicleDataService.svc', 'SetCurrentSearchTab', '{"tab":"' + searchType + '"}', '');
}
function IsValidPostcode(p) {
    if (p != "") return true; else { alert("Please enter a postcode."); return false; }
}
//Company
function GetDirections(el, from) { window.open('http://maps.google.com/maps?daddr=' + from + '&saddr=' + encodeURIComponent(el.val().toLowerCase())); }
function ShowFeedback(show) {
    $('#feedbackdialog').css('display', (show ? 'block' : 'none'));
    $('#feedbackBK').css('display', (show ? 'block' : 'none'));
}
//News
function SetHomeNews() {
    $(".nexpander").click(
        function() {
            var el = $(this).next(), height = el.outerHeight() - 8;
            var elp = $(this).parent().parent().find(".exopen");
            $(this).css("display", "none");
            elp.animate({ "height": 0, "opacity": "0" }, 400).removeClass("exopen");
            elp.prev().css("display", "block");
            el.css("height", 0).css("display", "block").animate({ "height": height, "opacity": "1" }, 400).addClass("exopen");
            setTimeout(function() { el.css("filter", ""); elp.css("display", "none").css("height", "auto"); }, 410);
        });
}
//Left Nav
function SetLeftNav() {
    $(".lexpander").click(
        function() {
            var el = $(this).next().next();
            el.css("display", "block").css("height", "auto");
            var height = el.outerHeight();
            el.css("display", "none");
            $(this).css("display", "none");
            $(this).next().css("display", "block");
            el.css("height", 0).css("display", "block").animate({ "height": height - 17, "opacity": "1" }, 400);
            setTimeout(function() { el.css("filter", "") }, 410);
        });
    $(".lcollapse").click(
        function() {
            var el = $(this).next();
            $(this).css("display", "none");
            $(this).prev().css("display", "block");
            el.animate({ "height": 0, "opacity": "0" }, 400);
            setTimeout(function() { el.css("display", "none"); }, 400);
        });
}
//Stats
function RecordStat(dealId, sourceType, profileGUID, eventType) { loadXMLDoc("", "record-stats.aspx?dealId=" + dealId + "&sourceType=" + sourceType + "&profileGUID=" + profileGUID + "&eventType=" + eventType); }
function ClickPop(dealId, sourceType, profileGUID) { RecordStat(dealId, sourceType, profileGUID, 'click'); RecordStat(dealId, sourceType, profileGUID, 'popunder'); }
function SetMostPopularTab(el1, el2, el) { $('#liDay').removeClass("active"); $('#liWeek').removeClass("active"); $('#liMonth').removeClass("active"); $('#divMostPopularDay').css("display", "none"); $('#divMostPopularWeek').css("display", "none"); $('#divMostPopularMonth').css("display", "none"); $('#ulOtherPopularDay').css("display", "none"); $('#ulOtherPopularWeek').css("display", "none"); $('#ulOtherPopularMonth').css("display", "none"); el1.css("display", "block"); el2.css("display", "block"); el.addClass("active"); }
//Deal Search
function GetBodyStyleImage(ddl, vType) {
    $('#pIMG').prev().attr('src', 'http://images.rgdcdn.co.uk/' + $("#hidSiteId").val() + '/' + vType + '/' + ddl.val().split("|")[0] + '/120/80/');
}

function ClearKeywords(el, image) { if (el.css("background-image").indexOf("/images/" + image) != -1) { el.css("background-image", ""); } }
function KeywordExample(el, image) { if (el.val() == "") { el.css("background-image", "url(/images/" + image + ")"); } }
// Email
function SubscribeEmail(man, ran) {
    $("#divSending").css("display", "block");
    CallWcfAjax('VehicleDataService.svc', 'SubscribeEmail', '{"email":"' + $('#txtEmailSub').val() + '", "manufacturer":"' + man + '", "range":"' + ran + '"}', 'SubscribeReturn(jsonObject)');
}
function SubscribeReturn(data) {
    alert(data.d);
    $("#txtEmailSub").val(""); $("#divSending").css("display", "none");
    if (data.d == "Request successfully sent.") { $("#divSent").css("display", "block"); }
}
function validate_text(f, a) { var b; var t; switch (a) { case 1: b = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_- "; break; case 2: b = "0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ_-+£%@,()&/\/:#[]{}* "; break; case 3: b = "0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ_-+@:/!#$%&'*=?^`{|}~"; break; case 4: b = "0123456789 "; break; case 5: b = "0123456789"; break; case 6: b = "0123456789."; break; default: b = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; break } var i = 0; for (i = 0; i < f.value.length; i++) { t = "" + f.value.substring(i, i + 1); var c = ascii_value(t); if (c == 13) { f.value = f.value.substring(0, i) + ' ' + f.value.substring(i + 2); t = "" + f.value.substring(i, i + 1) } try { if (b.toUpperCase().indexOf(t.toUpperCase()) == "-1") { if (f.value.toUpperCase().indexOf(t.toUpperCase()) == "0") { if (f.value.length == f.value.toUpperCase().indexOf(t.toUpperCase()) + 1) { f.value = "" } else { var d = f.value; while (d.toUpperCase().indexOf(t.toUpperCase()) != -1) { d = d.replace(t, ""); i = i - 1 } f.value = d } } else { if (f.value.indexOf(t) == (f.value.length - 1)) { var d = f.value; while (d.toUpperCase().indexOf(t.toUpperCase()) != -1) { d = d.replace(t, ""); i = i - 1 } f.value = d } else { var d = f.value; while (d.toUpperCase().indexOf(t.toUpperCase()) != -1) { d = d.replace(t, ""); i = i - 1 } f.value = d } } } } catch (e) { } } }
function VarifyEmail(cid) {
    var from = $("#" + cid + "txtFrom").val(), cc = $("#" + cid + "txtCC").val(), fname = $("#" + cid + "txtFirstName").val(), sname = $("#" + cid + "txtSurname").val(), phone = $("#" + cid + "txtPhone").val(), enquiry = $("#" + cid + "txtEnquiry").val();
    if (cc == "Send To A Friend") cc = ""; if (cc == "Send To A Friend") cc = "";
    if (fname.length == 0) { alert('Please enter your name.'); return false; }
    if (sname.length == 0) { alert('Please enter your name.'); return false; }
    if (!IsEmail(from)) return false;
    if (cc != "") { if (!IsEmail(cc)) return false; }
    if (phone.length == 0) { alert('Please enter your phone number.'); return false; }
    if (enquiry.length == 0) { alert('Please enter text into Enquiry box.'); return false; }
    return true;
}
function VarifyCallBack() {
    var fname = $("#txtFirstName").val(), sname = $("#txtSurname").val(), phone = $("#txtPhone").val(), callAt = $("#txtCallBackAt").val();
    if (fname.length == 0) { alert('Please enter your first name.'); return false; }
    if (sname.length == 0) { alert('Please enter your surname.'); return false; }
    if (phone.length == 0) { alert('Please enter your phone number.'); return false; }
    if (callAt.length == 0) { alert('Please enter when you would like to be called back.'); return false; }
    return true;
}
function VarifyFeedback(cid) {
    var valid = true, name = $("#" + cid + "txtName").val(), location = $("#" + cid + "txtLocation").val(), feedback = $("#" + cid + "txtFeedback").val();
    if (name == "" || name == "Your Name") { alert("Please enter your name"); valid = false; }
    if (location == "" || location == "Your Location") { alert("Please enter your location"); valid = false; }
    if (feedback == "" || feedback == "Your Feedback") { alert("Please enter your feedback"); valid = false; }
    return valid;
}
function CheckProgress(id) {
	loadXMLDoc('UpdateProgress(sValue, \'' + id + '\')', "set-values.aspx?progress=" + id + "&date=" + new Date().getTime(), true);
}
function UpdateProgress(sValue, id) {
	$('#' + id).html(sValue);
	setTimeout("CheckProgress('" + id + "')", 1000);
}
function EmptyTxt(el) {
    if (el.val() == "Postcode") el.val("");
    else if (el.val() == "") el.val("Postcode");
}
function ValidateAdForm() {
	if ($('#ddlTitle').val() == '') { alert('Please select your title.'); return false; }
	if ($('#txtName').val() == '') { alert('Please enter your name.'); return false; }
	if (!ContainsHTML($('#txtName').val())) return false;
	if ($('#txtJobTitle').val() == '') { alert('Please enter your job title.'); return false; }
	if (!ContainsHTML($('#txtJobTitle').val())) return false;
	if ($('#txtCompany').val() == '') { alert('Please enter the company you work for.'); return false; }
	if (!ContainsHTML($('#txtCompany').val())) return false;
	if ($('#txtAddress1').val() == '') { alert('Please enter the first line of your address.'); return false; }
	if (!ContainsHTML($('#txtAddress1').val())) return false;
	if (!ContainsHTML($('#txtAddress2').val())) return false;
	if ($('#txtTown').val() == '') { alert('Please enter your town'); return false; }
	if (!ContainsHTML($('#txtTown').val())) return false;
	if ($('#txtCounty').val() == '') { alert('Please enter your county'); return false; }
	if (!ContainsHTML($('#txtCounty').val())) return false;
    if ($('#txtPostcode').val() == '') { alert('Please enter your postcode'); return false; }
    if (!IsPostcode($('#txtPostcode').val())) { return false; }
    if ($('#txtPhone').val() == '') { alert('Please enter your phone number'); return false; }
    if (isNaN($('#txtPhone').val().replace(/\s/g, '')) || $('#txtPhone').val().replace(/\s/g, '').substr(0, 2) == '07') { alert('Please enter a valid landline phone number'); return false; }
    if (!ContainsHTML($('#txtFax').val())) return false;
	if ($('#txtEmail').val() == '') { alert('Please enter your email address'); return false; }
	if (!IsEmail($('#txtEmail').val())) { return false; }
	if (!ContainsHTML($('#txtWebsite').val())) return false;
	if (!ContainsHTML($('#txtFindUs').val())) return false;
    if ($('#txtHelp').val() == '') { alert('Please enter how we can help.'); return false; }
    if (!ContainsHTML($('#txtHelp').val())) return false;
    return true;
}
function IsPostcode(p) {
    var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i;
    if (!(postcodeRegEx.test(p))) { alert("Please enter a valid postcode."); }
    return postcodeRegEx.test(p);
}
function IsEmail(email) {
    var emailRegEx = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
    if ((email.length < 6) || !(emailRegEx.test(email))) { alert('Please enter a valid email address.'); return false; } else return true;
}
function ContainsHTML(string) {
	var htmlRegEx = /<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/;
	if (string.match(htmlRegEx) != null) { alert('The text cannot contain any HTML.'); return false; } else return true;
}
function GetNearestGroupProfile(groupGUID, dealId) {
	$("#divLoading").css("display", "block");
	CallWcfAjax('ProfileDataService.svc', 'GetNearestGroupProfile', '{"groupGUID":"' + groupGUID + '", "postcode":"' + $("#txtPostcode").val() + '", "dealId":' + dealId + '}', 'ShowNearestProfile(jsonObject)');
	return false;
}
function ShowNearestProfile(data) {
	if (data.d[4] == "") {
		$("#nearest").removeClass("enter-postcode").addClass("deal-phone-panel").html(data.d[0]);
		$("#pnlMoreLinks").css("display", "block").html($("#pnlMoreLinks").html().replace(/\$cu\$/g, data.d[1]).replace(/\$cn\$/g, data.d[2]));
		$("input[id*='txtTo']").each(function () { $(this).val(data.d[2]) });
		$(".compLogo").each(function () { $(this).html(data.d[3]) });
		var height = $("#pnlMoreLinks").outerHeight();
		$("#pnlMoreLinks").css("height", "0px").animate({ "height": height, "opacity": "1" }, 400);
		$("#hidProfileName").val(data.d[2]);
		$("#pLogo").attr("src", data.d[5]); $("#pLogo").attr("alt", data.d[2]); $("#cName").html(data.d[2]);
	}
	else alert(data.d[4]);
	$("#divLoading").css("display", "none");
}
function VScrollPos(el, dir, max) {
    var cSPos = $('#' + el).scrollLeft();
    var nSPos = (((cSPos + 537) > max) ? max : cSPos + 537);
    if (dir == 'l') nSPos = (((cSPos - 537) < 0) ? 0 : cSPos - 537);
    $('#' + el).animate({ scrollLeft: nSPos }, 400);
}
function TabDisplay(tab, div, tabs, divs, active) {
    $('#' + tab).addClass(active);
    $('#' + div).css("display", "block");
    for (var i = 0; i < tabs.length; i++) {
        $('#' + tabs[i]).removeClass(active);
        $('#' + divs[i]).css("display", "none");
    }
}
