/*
 * JTip
 * By Cody Lindley (http://www.codylindley.com)
 * Under an Attribution, Share Alike License
 * JTip is built on top of the very light weight jquery library.
 */

function JT_init(){
    $("a.jTip")
		   .click(function () { JT_show(this.href, this.id, this.name); return false; }, function () { $('#JT').remove() }, function () { return false; });
           //.click(function(){return false});	   
}

function JT_show(url,linkId,title){
	if(title == false)title="&nbsp;";
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var hasArea = w - getAbsoluteLeft(linkId);
	var clickElementy = getAbsoluteTop(linkId) - 3; //set y position
	
	var queryString = url.replace(/^[^\?]+\??/,'');
	var params = parseQuery( queryString );
	if(params['width'] === undefined){params['width'] = 250};
	if(params['link'] !== undefined){
	$('#' + linkId).bind('click',function(){window.location = params['link']});
	$('#' + linkId).css('cursor','pointer');
	}
	
	if(hasArea>((params['width']*1)+75)){
		$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_left'></div><div id='JT_close_left'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//right side
		var arrowOffset = getElementWidth(linkId) + 11;
		var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
	}else{
		$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_right' style='left:"+((params['width']*1)+1)+"px'></div><div id='JT_close_right'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//left side
		var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
	}
	
	$('#JT').css({left: clickElementx+"px", top: clickElementy+"px"});
	$('#JT').show();
	$('#JT_copy').load(url);

}

function getElementWidth(objectId) {
	x = document.getElementById(objectId);
	return x.offsetWidth;
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	return oTop
}

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function blockEvents(evt) {
              if(evt.target){
              evt.preventDefault();
              }else{
              evt.returnValue = false;
              }
}

function codeAddress(address) 
{
    geocoder.geocode({ 'address': address }, 
      function (results, status) 
      {
	if (status == google.maps.GeocoderStatus.OK) 
	{
	  map.setCenter(results[0].geometry.location);
	  var marker = new google.maps.Marker({
	      map: map,
	      position: results[0].geometry.location
	      });
	}
      });
}


var BizzyRateBadgeID=1000;

function showBizzyBadge(ob, srcob)

{

	ob.src = document.getElementById(srcob).src;

}

function createBizzyBadge(cn,co,s,bw,w)
{

	var brdt=new Date(); var ld="rating";

	if (s=="f") {ld="listing";}

	var brwidth=0; var brheight=0;

	if (w=="2") { brwidth=119; brheight=45;}

	else if (w=="3") { brwidth=131; brheight=55;}

	else { w="1"; brwidth=110; brheight=42;}

	var brurl="http://bizzy.co.uk/bizzyrate/badge.aspx?co="+co+"&s="+s+"&bw="+bw+"&w="+w+"&dt="+brdt.getDay()+brdt.getYear()+"-"+brdt.getMonth()+"-"+brdt.getDay();

	BizzyRateBadgeID++;



	//document.write('<a target="_blank" href="http://bizzy.co.uk/badge/c/'+cn+'/" title="Click to see our bizzy&reg; '+ld+'..."><img width="'+brwidth+'" height="'+brheight+'" id="bizzyRate'+BizzyRateBadgeID+'" style="padding:0px;border:0px;margin:0px;" alt="Click to see our bizzy&reg; '+ld+'..." border="0" src="'+brurl+'" onmouseout="showBizzyBadge(this,\'bizzyRate'+BizzyRateBadgeID+'Out\')" onmouseover="showBizzyBadge(this,\'bizzyRate'+BizzyRateBadgeID+'Over\')" /></a>');
	document.write('<a href="javascript:badgeclick();return false;" title="bizzy&reg; RATE indicates a Creditworthy Company"><img width="' + brwidth + '" height="' + brheight + '" id="bizzyRate' + BizzyRateBadgeID + '" style="padding:0px;border:0px;margin:0px;" border="0" src="' + brurl + '" onmouseout="showBizzyBadge(this,\'bizzyRate' + BizzyRateBadgeID + 'Out\')" onmouseover="showBizzyBadge(this,\'bizzyRate' + BizzyRateBadgeID + 'Over\')" /></a>');

	document.write('<img width="0" height="0" id="bizzyRate'+BizzyRateBadgeID+'Over" style="display:none;" src="'+brurl+'&ro=t" />');

	document.write('<img width="0" height="0" id="bizzyRate'+BizzyRateBadgeID+'Out" style="display:none;" src="'+brurl+'" />');

}

function badgeclick() {
    return false;
}

function createHomeBizzyBadgeNL(cn, co, s, bw, w, msg) {

    var brdt = new Date(); var ld = "rating";

    if (s == "f") { ld = "listing"; }

    var brwidth = 0; var brheight = 0;

    if (w == "2") { brwidth = 119; brheight = 45; }

    else if (w == "3") { brwidth = 131; brheight = 55; }

    else { w = "1"; brwidth = 110; brheight = 42; }

    var brurl = "http://bizzy.co.uk/bizzyrate/badge.aspx?nl=1&bi=y&co=" + co + "&s=" + s + "&bw=" + bw + "&w=" + w + "&msg=" + msg + "&dt=" + brdt.getYear() + "-" + brdt.getMonth() + "-" + brdt.getDay();

    BizzyRateBadgeID++;

    document.write('<a title="Login to view" id="bizzybadgelink' + BizzyRateBadgeID + '" rel="nofollow" href="javascript:showSignupPanel()"><img width="' + brwidth + '" height="' + brheight + '" id="bizzyRate' + BizzyRateBadgeID + '" style="padding:0px;border:0px;margin:0px;" border="0" src="' + brurl + '"  /></a>');
}

function createSampleBizzyBadge(cn, co, s, bw, w, divid) {

    var brdt = new Date(); var ld = "rating";

    if (s == "f") { ld = "listing"; }

    var brwidth = 0; var brheight = 0;

    if (w == "2") { brwidth = 119; brheight = 45; }

    else if (w == "3") { brwidth = 131; brheight = 55; }

    else { w = "1"; brwidth = 110; brheight = 42; }

    var brurl = "http://bizzy.co.uk/bizzyrate/badge.aspx?&bi=y&co=" + co + "&s=" + s + "&bw=" + bw + "&w=" + w + "&msg=&dt=" + brdt.getYear() + "-" + brdt.getMonth() + "-" + brdt.getDay();

    BizzyRateBadgeID++;

    document.getElementById(divid).innerHTML = '<img width="' + brwidth + '" height="' + brheight + '" id="bizzyRate' + BizzyRateBadgeID + '" style="padding:0px;border:0px;margin:0px;" border="0" src="' + brurl + '"  />';
}


function createHomeBizzyBadge(cn,co,s,bw,w,msg)

{

	var brdt=new Date(); var ld="rating";

	if (s=="f") {ld="listing";}

	var brwidth=0; var brheight=0;

	if (w=="2") { brwidth=119; brheight=45;}

	else if (w=="3") { brwidth=131; brheight=55;}

	else { w="1"; brwidth=110; brheight=42;}

	var brurl = "http://bizzy.co.uk/bizzyrate/badge.aspx?bi=y&co=" + co + "&s=" + s + "&bw=" + bw + "&w=" + w + "&msg=" + msg + "&dt=" + brdt.getYear() + "-" + brdt.getMonth() + "-" + brdt.getDay();

	BizzyRateBadgeID++;

	//document.write('<a id="bizzybadgelink' + BizzyRateBadgeID + '" class="jTip" rel="nofollow" target="_blank" href="/badge-info.aspx?co='+cn+"&msg="+escape(msg)+'" name="'+msg+'" onclick="javascript:document.location.href=\'/tools/website-badge/'+cn+'/\'"><img width="'+brwidth+'" height="'+brheight+'" id="bizzyRate'+BizzyRateBadgeID+'" style="padding:0px;border:0px;margin:0px;" border="0" src="'+brurl+'" onmouseout="showBizzyBadge(this,\'bizzyRate'+BizzyRateBadgeID+'Out\')" onmouseover="showBizzyBadge(this,\'bizzyRate'+BizzyRateBadgeID+'Over\')" /></a>');
	document.write('<a id="bizzybadgelink' + BizzyRateBadgeID + '" class="jTip" rel="nofollow" target="_blank" href="/badge-info.aspx?co=' + cn + "&msg=" + escape(msg) + '" name="' + msg + '" onclick="badgeclick()"><img width="' + brwidth + '" height="' + brheight + '" id="bizzyRate' + BizzyRateBadgeID + '" style="padding:0px;border:0px;margin:0px;" border="0" src="' + brurl + '" onmouseout="showBizzyBadge(this,\'bizzyRate' + BizzyRateBadgeID + 'Out\')" onmouseover="showBizzyBadge(this,\'bizzyRate' + BizzyRateBadgeID + 'Over\')" /></a>');

	document.write('<img width="0" height="0" id="bizzyRate'+BizzyRateBadgeID+'Over" style="display:none;" src="'+brurl+'&ro=t" />');

	document.write('<img width="0" height="0" id="bizzyRate'+BizzyRateBadgeID+'Out" style="display:none;" src="'+brurl+'" />');

}

var cono = "";
var vCartIDForCreditReport = 0;
var vBaseCreditReportPrice = 11.99;

function bizzysetupbuttons() {
    vCartIDForCreditReport = 0;
    $('#crbutton').show();
    $('#whatsinclcr').show();
    $('#viewsamplecrr').show();
    var docid = document.getElementById('cartitem_' + cono + '_01');
    if (docid != null) {
        if (docid.value != "") {
            vCartIDForCreditReport = document.getElementById('cartitem_' + cono + '_01').value;
            $('#crbutton').attr('disabled', 'disabled');
            $('#crbuttontext').html('CREDIT REPORT<br>in basket  <a title="Go to My Basket" style="color:white;text-decoration:underline" href="/cart/">View</a>');
        }
    }
    else {
        $('#crbutton').removeAttr('disabled');
        $('#crbuttontext').html('BUY CREDIT REPORT<br>Full report <span style=color:yellow;font-weight:bold>&pound; ' + vBaseCreditReportPrice + '</span></a>');
    }


    var docid = document.getElementById('cartitem_' + cono + '_02');
    if (docid != null) {
        if (docid.value != "") {
            $('#crbutton').attr('disabled', 'disabled');
            $('#crbuttontext').html('CREDIT REPORT<br>in basket  <a title="Go to My Basket" style="color:white;text-decoration:underline" href="/cart/">View</a>');
        }
    }

    var docid = document.getElementById('doclatestaccounts_id');
    if (docid != null) {
        if (docid.value != "") {

            if (document.getElementById('doclatestaccounts_pr').value == '0') {
                // No latest accounts available
                $('#accseperator').hide();
                $('#accbutton').hide();
                $('#accbuttontext').hide();
                $('#accinfobox').hide();
                $('#accwhatsincl').hide();
            }
            else {

		    var userIsAPLUSSubscriber = document.getElementById('userIsAPLUSSubscriber');
		    if (userIsAPLUSSubscriber == null) { userIsAPLUSSubscriber='False'; } else { userIsAPLUSSubscriber=userIsAPLUSSubscriber.value; }
		    //alert(userIsAPLUSSubscriber);

                $('#accbuttontext').html('<span style=font-size:12px;font-weight:bold>VALUE BUNDLE! <span style=color:yellow;font-weight:bold>&pound;' + (((userIsAPLUSSubscriber == 'True' ? 1:3))+parseFloat(document.getElementById('doclatestaccounts_pr').value)) + '</font></span><br><span style=font-size:10px>Credit Score+Latest Accounts</span>');
                $('#accinfobox').html('<b style=font-size:11px>Latest credit rating, monthly limit and filed Accounts to ' + document.getElementById('doclatestaccounts_dt').value + '</b>');
                $('#accinfobox').attr('title', 'Made up to ' + document.getElementById('doclatestaccounts_dt').value + ' ' + document.getElementById('doclatestaccounts_dc').value);

                $('#accseperator').show();
                $('#accbutton').show();
                $('#accbuttontext').show();
                $('#accinfobox').show();
                $('#accwhatsincl').show();

                var docid = document.getElementById('cartitem_' + cono + '_' + document.getElementById('doclatestaccounts_id').value);
                if (docid != null) {
                    if (docid.value != "") {
                        //alert('accs in basket!');

                        $('#accbutton').attr('disabled', 'disabled');
                        $('#accbuttontext').html('LATEST ACCOUNTS<br>in basket  <a title="Go to My Basket" style="color:white;text-decoration:underline" href="/cart/">View</a>');

                    }
                    else {
                        $('#accbutton').removeAttr('disabled');
                    }
                }
                else {
                    $('#accbutton').removeAttr('disabled');
                }
            }
        }
        else {
            // No latest accounts available
            $('#accseperator').hide();
            $('#accbutton').hide();
            $('#accbuttontext').hide();
            $('#accinfobox').hide();
            $('#accwhatsincl').hide();
        }
    }
    else {
        // No latest accounts available
        $('#accseperator').hide();
        $('#accbutton').hide();
        $('#accbuttontext').hide();
        $('#accinfobox').hide();
        $('#accwhatsincl').hide();
    }




    var docid = document.getElementById('doclatestreturn_id');
    if (docid != null) {
        if (docid.value != "") {

            if (document.getElementById('doclatestreturn_pr').value == '0') {
                // No latest return available
                $('#arseperator').hide();
                $('#arbutton').hide();
                $('#arbuttontext').hide();
                $('#arinfobox').hide();
                $('#arwhatsincl').hide();
            }
            else {

                $('#arbuttontext').html('BUY ANNUAL RETURN<br><span style=font-size:12px>Just &pound; ' + document.getElementById('doclatestreturn_pr').value + '</span>');
                $('#arinfobox').html('<b style=font-size:12px>Made up to ' + document.getElementById('doclatestreturn_dt').value + '</b>');
                $('#arinfobox').attr('title', 'Made up to ' + document.getElementById('doclatestreturn_dt').value + ' ' + document.getElementById('doclatestreturn_dc').value);

                $('#arseperator').show();
                $('#arbutton').show();
                $('#arbuttontext').show();
                $('#arinfobox').show();
                $('#arwhatsincl').show();


                var docid = document.getElementById('cartitem_' + cono + '_' + document.getElementById('doclatestreturn_id').value);
                if (docid != null) {
                    if (docid.value != "") {
                        //alert('return in basket!');

                        $('#arbutton').attr('disabled', 'disabled');
                        $('#arbuttontext').html('LATEST RETURN<br>in basket  <a title="Go to My Basket" style="color:white;text-decoration:underline" href="/cart/">View</a>');

                    }
                    else {
                        $('#arbutton').removeAttr('disabled');
                    }
                }
                else {
                    $('#arbutton').removeAttr('disabled');
                }
            }
        }
        else {
            // No latest return available
            $('#arseperator').hide();
            $('#arbutton').hide();
            $('#arbuttontext').hide();
            $('#arinfobox').hide();
            $('#arwhatsincl').hide();
        }
    }
    else {
        // No latest return available
        $('#arseperator').hide();
        $('#arbutton').hide();
        $('#arbuttontext').hide();
        $('#arinfobox').hide();
        $('#arwhatsincl').hide();
    }

    // Set the status of the Credit report button in the filing history tab and front summary listing
    if ($('#cartitem_' + cono + '_01').length) {
        $('#fileddoc-1btn').removeClass('filed-documents-buy-now-btn');
        $('#fileddoc-1btn').addClass('filed-documents-remove-btn');
        $('#fileddoc-1btn').attr('title', 'Remove from My Basket');
        $('#fileddoc-1btn2').removeClass('filed-documents-buy-now-btn');
        $('#fileddoc-1btn2').addClass('filed-documents-remove-btn');
        $('#fileddoc-1btn2').attr('title', 'Remove from My Basket');
        $('#fileddoc-1btntxt').html('REMOVE');
        $('#fileddoc-1btntxt').attr('title', 'Remove from My Basket');
        $('#fileddoc-1btntxt2').html('REMOVE');
        $('#fileddoc-1btntxt2').attr('title', 'Remove from My Basket');
    }
    else {
        $('#fileddoc-1btn').removeClass('filed-documents-remove-btn');
        $('#fileddoc-1btn').addClass('filed-documents-buy-now-btn');
        $('#fileddoc-1btn').attr('title', 'Add to My Basket');
        $('#fileddoc-1btn2').removeClass('filed-documents-remove-btn');
        $('#fileddoc-1btn2').addClass('filed-documents-buy-now-btn');
        $('#fileddoc-1btn2').attr('title', 'Add to My Basket');
        $('#fileddoc-1btntxt').html('BUY NOW');
        $('#fileddoc-1btntxt').attr('title', 'Add to My Basket');
        $('#fileddoc-1btntxt2').html('BUY NOW');
        $('#fileddoc-1btntxt2').attr('title', 'Add to My Basket');
    }

    // show state of filed documents
    var vDocCount = $('#doccount');
    if (vDocCount != null) {
        vDocCount=vDocCount.val();
        for (var x = 1; x <= vDocCount; x++) {
            var vDocID = $('#doc' + x + '_id');
            if (vDocID != null) {
                vDocID = vDocID.val();
                if ($('#cartitem_' + cono + '_' + vDocID).length) {
                    $('#fileddoc' + vDocID + 'btn').removeClass('filed-documents-buy-now-btn');
                    $('#fileddoc' + vDocID + 'btn').addClass('filed-documents-remove-btn');
                    $('#fileddoc' + vDocID + 'btn').attr('title', 'Remove from My Basket');
                    $('#fileddoc' + vDocID + 'btn2').removeClass('filed-documents-buy-now-btn');
                    $('#fileddoc' + vDocID + 'btn2').addClass('filed-documents-remove-btn');
                    $('#fileddoc' + vDocID + 'btn2').attr('title', 'Remove from My Basket');
                    $('#fileddoc' + vDocID + 'btntxt').html('REMOVE');
                    $('#fileddoc' + vDocID + 'btntxt').attr('title', 'Remove from My Basket');
                    $('#fileddoc' + vDocID + 'btntxt2').html('REMOVE');
                    $('#fileddoc' + vDocID + 'btntxt2').attr('title', 'Remove from My Basket');
                }
                else {
                    $('#fileddoc' + vDocID + 'btn').removeClass('filed-documents-remove-btn');
                    $('#fileddoc' + vDocID + 'btn').addClass('filed-documents-buy-now-btn');
                    $('#fileddoc' + vDocID + 'btn').attr('title', 'Add to My Basket');
                    $('#fileddoc' + vDocID + 'btn2').removeClass('filed-documents-remove-btn');
                    $('#fileddoc' + vDocID + 'btn2').addClass('filed-documents-buy-now-btn');
                    $('#fileddoc' + vDocID + 'btn2').attr('title', 'Add to My Basket');
                    $('#fileddoc' + vDocID + 'btntxt').html('BUY NOW');
                    $('#fileddoc' + vDocID + 'btntxt').attr('title', 'Add to My Basket');
                    $('#fileddoc' + vDocID + 'btntxt2').html('BUY NOW');
                    $('#fileddoc' + vDocID + 'btntxt2').attr('title', 'Add to My Basket');
                }
                $('#fileddoc' + vDocID + 'btn').show();
            }
        }

        if (vDocCount == 0) {
            // No latest accounts available
            $('#accseperator').hide();
            $('#accbutton').hide();
            $('#accbuttontext').hide();
            $('#accinfobox').hide();
            $('#accwhatsincl').hide();

            // No latest return available
            $('#arseperator').hide();
            $('#arbutton').hide();
            $('#arbuttontext').hide();
            $('#arinfobox').hide();
            $('#arwhatsincl').hide();

            // Hide credit report button
            $('#crbutton').hide();
            $('#whatsinclcr').hide();
            $('#viewsamplecrr').hide();
        }

    }
    


}

function bizzyca(btnid,docpos) {

    $(btnid).hide();
    if ($('#' + btnid).hasClass('filed-documents-remove-btn')) {
        bizzycrdoc($('#' + btnid).attr('docid'));
    }
    else {
        var docid = document.getElementById('doc' + docpos + '_id').value;
        var dc = document.getElementById('doc' + docpos + '_dc').value;
        var pr = document.getElementById('doc' + docpos + '_pr').value;
        var sU = "/bizzy.ashx?ctx=ca&cono=" + cono + "&docid=" + docid + "&price=" + pr + "&descr=" + escape(dc);
        $.ajax({
            type: "GET",
            timeout: 10000,
            url: sU,
            data: "",
            cache: false,
            success: function (html) {
                if (html !== '') {
                    getSH();
                }
            }
        });
    }
}


function bizzycala() {

    $('#accbutton').hide();

    var docid = document.getElementById('doclatestaccounts_id');
    if (docid != null) {
        if (docid.value != "") {

            docid = docid.value;
            var dc = document.getElementById('doclatestaccounts_dc').value;
            var pr = document.getElementById('doclatestaccounts_pr').value;
            var sU = "/bizzy.ashx?ctx=ca&cono=" + cono + "&docid=" + docid + "&price=" + pr + "&descr=" + escape(dc);
            $.ajax({
                type: "GET",
                timeout: 10000,
                url: sU,
                data: "",
                cache: false,
                success: function (html) {
                    if (html !== '') {
                        getSH();
                    }
                }
            });
        }
    }
}

function bizzycasb() {

    $('#accbutton').hide();

    var docid = document.getElementById('doclatestaccounts_id');
    var userIsAPLUSSubscriber = document.getElementById('userIsAPLUSSubscriber');
    if (userIsAPLUSSubscriber == null) { userIsAPLUSSubscriber='False'; } else { userIsAPLUSSubscriber=userIsAPLUSSubscriber.value; }
    
    if (docid != null) {
        if (docid.value != "") {

            docid = docid.value;
            var dc = document.getElementById('doclatestaccounts_dc').value;
            var pr = (userIsAPLUSSubscriber=='True' ? 1:3)+parseFloat(document.getElementById('doclatestaccounts_pr').value);
            var sU = "/bizzy.ashx?ctx=ca&cono=" + cono + "&docid=" + docid + "&price=" + pr + "&descr=" + escape("Bizzy Snapshot Credit Report plus LATEST "+dc);
            $.ajax({
                type: "GET",
                timeout: 10000,
                url: sU,
                data: "",
                cache: false,
                success: function (html) {
                    if (html !== '') {
                        getSH();
                    }
                }
            });
        }
    }
}


function bizzycalr() {

    $('#arbutton').hide();

    var docid = document.getElementById('doclatestreturn_id');
    if (docid != null) {
        if (docid.value != "") {

            docid = docid.value;
            var dc = document.getElementById('doclatestreturn_dc').value;
            var pr = document.getElementById('doclatestreturn_pr').value;
            var sU = "/bizzy.ashx?ctx=ca&cono=" + cono + "&docid=" + docid + "&price=" + pr + "&descr=" + escape(dc);
            $.ajax({
                type: "GET",
                timeout: 10000,
                url: sU,
                data: "",
                cache: false,
                success: function (html) {
                    if (html !== '') {
                        getSH();
                    }
                }
            });
        }
    }
}

function bizzycaeur(cty) {

    $('#crbutton').hide();

    var docid = -2;
    var dc = 'bizzy Comprehensive Report - '+cty;
    var pr = 19.95;
    var sU = "/bizzy.ashx?ctx=ca&cono=" + cono + "&docid=" + docid + "&price=" + pr + "&descr=" + escape(dc);
    $.ajax({
        type: "GET",
        timeout: 10000,
        url: sU,
        data: "",
        cache: false,
        success: function (html) {
            if (html !== '') {
                getSH();
            }
        }
    });
}

function bizzycrr() {

    $('#crbutton').hide();

    var docid = -1;
    var dc = 'bizzy Comprehensive Credit Report';
    var pr = 11.99;

    if (vCartIDForCreditReport > 0) {
        bizzycr(vCartIDForCreditReport);
    }
    else {
        var sU = "/bizzy.ashx?ctx=ca&cono=" + cono + "&docid=" + docid + "&price=" + pr + "&descr=" + escape(dc);
        $.ajax({
            type: "GET",
            timeout: 10000,
            url: sU,
            data: "",
            cache: false,
            success: function (html) {
                if (html !== '') {
                    getSH();
                }
            }
        });
    }
}

function bizzycrdoc(docid) {
    var sU = "/bizzy.ashx?ctx=cr&docid=" + docid;
    $.ajax({
        type: "GET",
        timeout: 10000,
        url: sU,
        data: "",
        cache: false,
        success: function (html) {
            if (html !== '') {
                getSH();
            }
        }
    });
}


function bizzycr(docid) {
    var sU = "/bizzy.ashx?ctx=cr&id=" + docid;
    $.ajax({
        type: "GET",
        timeout: 10000,
        url: sU,
        data: "",
        cache: false,
        success: function (html) {
            if (html !== '') {
                getSH();
            }
        }
    });
}


function getSH() {
    var sU = "/bizzy.ashx?ctx=gc&mi=y";
    $.ajax({
        type: "GET",
        timeout: 5000,
        url: sU,
        data: "",
        cache: false,
        success: function (html) {
            if (html !== '') {
                $("#minibasket").html(html);
                getMA();
                bizzysetupbuttons();
            }
        }
    });
}

function getMA() {
    var sU = "/bizzy.ashx?ctx=ma";
    $.ajax({
        type: "GET",
        timeout: 5000,
        url: sU,
        data: "",
        cache: false,
        success: function (html) {
            if (html !== '') {
                if (html.indexOf("My Account") > 0) {
                    $("#my-account-options").html(html);
                    $("#my-account-options").show();
                }
                else {
                	$("#my-account-options").html(html);
                    $("#my-account-options").hide();
                }
            }
        }
    });
}

function getFH(co) {
    var sU = "/bizzy.ashx?ctx=fh&q=" + co;
    $.ajax({
        type: "GET",
        timeout: 20000,
        url: sU,
        data: "",
        success: function (html) {
            if (html !== '') {
                var fhsplit = html.split('####');
                $("#docfilinghist").html(fhsplit[0]);
                if (parseInt(fhsplit[1]) > 0) {
                    var docsavail = parseInt(fhsplit[1]);
                    docsavail = docsavail + 1; //alows for the credit report
                    $("#docavailtab").addClass("tabred");
                    $("#docavailtab").html('<span class="tabcounter">' + docsavail + '</span> Documents Available');
                    $("#summaryfilinghistory").html(fhsplit[2]);
                    $("#summaryfilinghistoryrow").show();
                    $("#summarydoccount").html('Click to see all ' + docsavail + ' documents available...');
                }
                else {
                    $("#summaryfilinghistoryrow").hide();
                }
                bizzysetupbuttons();
            }
        }
    });
}


// Recently Viewed

function rvSetCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function rvGetCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function rvDeleteCookie(name) {
    rvSetCookie(name, "", -1);
}

function rvEndsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

function rvAddURL(t, u) {
    t = t.replace('"', '');

    if (rvEndsWith(u, "/")) {
        u = u.substring(0, u.length-1);
    }
    if (u.indexOf("#") > 0) {
        u = u.substring(0, u.indexOf("#"));
    }
    if (u.indexOf("?") > 0) {
        u = u.substring(0, u.indexOf("?"));
    }
    if (u.indexOf("/refresh") > 0) {
        u = u.substring(0, u.indexOf("/refresh"));
    }
    if (u.indexOf("/update") > 0) {
        u = u.substring(0, u.indexOf("/update"));
    }

    if (!rvURLExists(u)) {
        var vRVVal = rvGetCookie("bizzy_rv");
        if (vRVVal == null) {
            rvSetCookie("bizzy_rv", "0", 180);
            vRVVal = "0";
        }
        vRVCount = parseFloat(vRVVal);
        vRVCount = vRVCount + 1;

        rvSetCookie(("bizzy_rv_t_" + vRVCount), t, 180);
        rvSetCookie(("bizzy_rv_u_" + vRVCount), u, 180);

        rvSetCookie("bizzy_rv", vRVCount, 180);
    }
}

function rvClear() {
    var vRVVal = rvGetCookie("bizzy_rv");
    if (vRVVal == null) {
        rvSetCookie("bizzy_rv", "0", 180);
        vRVVal = "0";
    }
    vRVCount = parseFloat(vRVVal);
    for (var x = 1; x <= vRVCount; x++) {
        rvSetCookie(("bizzy_rv_t_" + x), "", 180);
        rvSetCookie(("bizzy_rv_u_" + x), "", 180);
        rvDeleteCookie(("bizzy_rv_t_" + x));
        rvDeleteCookie(("bizzy_rv_u_" + x));
    }
    rvSetCookie("bizzy_rv", "0", 180);
}

function rvURLExists(u) {
    var bRet = false;
    var vRVVal = rvGetCookie("bizzy_rv");
    if (vRVVal == null) {
        rvSetCookie("bizzy_rv", "0", 180);
        vRVVal = "0";
    }
    vRVCount = parseFloat(vRVVal);

    for (var x = 1; x <= vRVCount; x++) {
        if (u == rvGetCookie(("bizzy_rv_u_" + x)))
        {
            bRet=true;
            break;
        }
    }
    return bRet;
}

function rvGetCount() {
    var vRVVal = rvGetCookie("bizzy_rv");
    if (vRVVal == null) {
        rvSetCookie("bizzy_rv", "0", 180);
        vRVVal = "0";
    }
    vRVCount = parseFloat(vRVVal);
    return vRVCount;
}

function rvGetItemTitle(x) {
    return rvGetCookie("bizzy_rv_t_" + x);
}

function rvGetItemURL(x) {
    return rvGetCookie("bizzy_rv_u_" + x);
}


function rvGetList(ctr) {
    var sRet = "";
    var vRVVal = rvGetCookie("bizzy_rv");
    if (vRVVal == null) {
        rvSetCookie("bizzy_rv", "0", 180);
        vRVVal = "0";
    }
    vRVCount = parseFloat(vRVVal);
    var vShown = 0;
    for (var x = vRVCount; x >= (vRVCount - ctr + 1); x--) 
    {
        vRVTitle = rvGetCookie("bizzy_rv_t_" + x);
        if (vRVTitle != null) {
            if (vRVTitle != "") {

                if (vShown != 0) {
                    sRet = sRet + "<div class='basket-item-seperator'></div>";
                }
                vShown = vShown + 1;
                var RVURL = rvGetCookie("bizzy_rv_u_" + x);

                if (document.location.href == RVURL) {
                    sRet = sRet + "<span title='Current page: " + vRVTitle + "' class='rvtitlecurrent'>" + vRVTitle + "</span><br/>";
                }
                else {
                    sRet = sRet + "<a href='" + RVURL + "' title='" + vRVTitle + "' class='rvtitle'>" + vRVTitle + "</a><br/>";
                }
            }
        }
    }
    return sRet;
}

function rvGetHomeList(ctr) {
    var sRet = "";
    var vRVVal = rvGetCookie("bizzy_rv");
    if (vRVVal == null) {
        rvSetCookie("bizzy_rv", "0", 180);
        vRVVal = "0";
    }
    vRVCount = parseFloat(vRVVal);
    var vShown = 0;
    for (var x = vRVCount; x >= (vRVCount - ctr + 1); x--) {
        vRVTitle = rvGetCookie("bizzy_rv_t_" + x);
        if (vRVTitle != null) {
            if (vRVTitle != "") {

                vShown = vShown + 1;
                var RVURL = rvGetCookie("bizzy_rv_u_" + x);

                sRet = sRet + "<a href='" + RVURL + "' title='" + vRVTitle + "' class='rvtitle'>" + vRVTitle + "</a><br/>";
            }
        }
    }
    return sRet;
}

function rvPopulateList(divid) {
    if (rvGetCount() == 0) {
        $('#' + divid).html("Use the search feature to find companies of interest.");
    }
    else {
        var vRVMax = 10;
        var newrvlist = rvGetList(vRVMax);
        $('#' + divid).html(newrvlist);
    }
}

function rvPopulateHomeList(divid) {
    if (rvGetCount() == 0) {
        $('#' + divid).html("Use the search feature to find companies of interest.");
    }
    else {
        var vRVMax = 10;
        var newrvlist = rvGetHomeList(vRVMax);
        $('#' + divid).html(newrvlist);
    }
}

function rvClearList(divid) {
    rvClear();
    rvPopulateList(divid);
}

function switchToTab(tabid) {
    $('ul.tabs li').removeClass('active');
    $('ul.tabs. li#' + tabid).addClass('active');
    $(".tab_content").hide();
    var activeTab = $('ul.tabs. li#' + tabid).find("a").attr("href");
    scroll(0, 0);
    $(activeTab).fadeIn();
}


var lastrequest = null;
var typingTimer;                //timer identifier
var doneTypingInterval = 500;  //time in ms

function goSearch(frm) {
    var sterm = $('#q').val();
    frm.action = '/search/' + sterm.replace("&", "");
}
var vTryCount = 0;
//user is "finished typing," do something


function doneTyping() {
    vTryCount = 0;
    trySearchNow();
}

function trySearchNow() {
    vTryCount++;
    var sterm = $('#q').val();
    if (sterm.length >= 2) { // if there are more then 2 letters
        var data = sterm;
        // ajax call
        if (lastrequest != null) {
            try { lastrequest.abort(); } catch (err) { alert(err) }
        }
        $("#search-results-container").show();

        if (vTryCount <= 1)
        {            
            vTryCount=1;     
            $("#suggestloading").html("<img src='http://media.bizzy.co.uk/v3/images/loader.gif' border='0' title='Searching...' /> Searching...");
        }

        $("#suggestloading").show(); // showing loading image
        lastrequest = $.ajax({
            type: "GET",
            timeout: 10000,
            url: "/search-suggest.aspx?q=" + data.replace("&", ""),
            cache: false,
            data: "",
            error: function (xhr, ajaxOptions, thrownError) {
                if (vTryCount == 3) {
                    $("#suggestloading").html("No results found. <a href='javascript:doneTyping();' style='color:#000;font-weight:bold;text-decoration:underline;'>Try again</a>");
                    vTryCount = 0;
                }
                else {
                    if (vTryCount < 1) {
                        vTryCount = 1;
                    }
                    if (vTryCount > 1) {
                        $("#suggestloading").html("<img src='http://media.bizzy.co.uk/v3/images/loader.gif' border='0' title='Searching...' /> Searching, " + (vTryCount * 10) + " seconds...");
                    }
                    trySearchNow();
                }
            },
            success: function (html) { // this happen after we get result
                if (html !== '') {
                    if (lastrequest != null) {
                        try { lastrequest.abort(); } catch (err) { alert(err) }
                    }

                    vTryCount = 0;
                    $("#search-results-container").html(html);
                    $("#search-results-container").show();
                    $("#suggestloading").hide(); // hiding loading image
                }
            }
        });
    }
    else {
        if (sterm.length == 0) {
            vTryCount = 0;
            $("#search-results-container").hide(); // hiding form
            $("#content").show();
        }
        else {
            vTryCount=0;
            $("#search-results-container").show();
            $("#content").show();
        }
    }
}

function configSearch() {

        //on keyup, start the countdown
        $('#q').keyup(function () {
            typingTimer = setTimeout(doneTyping, doneTypingInterval);
        });
        //on keydown, clear the countdown 
        $('#q').keydown(function () {
            clearTimeout(typingTimer);
        });
}

function configSignUpLoginPanel() {
    $('#registeremailaddress').keyup(function (event) {
            var emailaddr = $('#registeremailaddress').val();
            emailaddr = cleanEmailAddress(emailaddr, '#registeremailaddress');
            if (event.keyCode == 13) {
                signUpSubmit();
            } else {
                validEmailAddress(emailaddr, (bDisplayRegisterIcons ? '#registeremailaddressicon' : ''));
                return true;
            }
        });

        $('#registername').keyup(function (event) {
            var registername = leftTrim(rightTrim($('#registername').val()));
            if (event.keyCode == 13) {
                signUpSubmit();
            } else {
                validFullName(registername, (bDisplayRegisterIcons ? '#registernameicon' : ''));
                return true;
            }
        });

        $('#loginemailaddress').keyup(function (event) {
            var emailaddr = $('#loginemailaddress').val();
            emailaddr = cleanEmailAddress(emailaddr, '#loginemailaddress');
            if (event.keyCode == 13) {
                loginSubmit();
            } else {
                if ((!bLoginPanelShowing) && (emailaddr.length > 0)) {
                    showLoginPanel();
                }
                validEmailAddress(emailaddr, (bDisplayLoginIcons ? '#loginemailaddressicon' : ''));
                return true;
            }
        });

        $('#loginpassword').keyup(function (event) {
            var loginpwd = $('#loginpassword').val();
            if (event.keyCode == 13) {
                loginSubmit();
            }
            else {
                validUserPassword(loginpwd, (bDisplayLoginIcons ? '#loginpasswordicon' : ''));
            }
        });
}

function submitSearch() {
    $("#search-form").submit();
}

function configLanguageSelector() {
    try {

            // Country selector dropdown
        $(".dropdown dt a").click(function (event) {
            event.stopImmediatePropagation();
                $(".dropdown dd ul").toggle();
            });

            $(".dropdown dd ul li a").click(function () {
                var text = $(this).html();
                $(".dropdown dt a").html(text);
                $(".dropdown dd ul").hide();
                $("#selectedcountrycode").val($(this).attr("val"));
                rvSetCookie("bizzy_cty", $(this).attr("val"), 180);

                    doneTyping();
            });

            $(document).bind('click', function (e) {
                var $clicked = $(e.target);
                if (!$clicked.parents().hasClass("dropdown"))
                    $(".dropdown dd ul").hide();
            });
        
    }
    catch (err) { }
}

$(document).ready(function () {
    configSearch();
    configSignUpLoginPanel();
    try { initializeMap(); } catch (err) { }
    configLanguageSelector();
    $(".tab_content").hide();
    $("ul.tabs li:first").addClass("active").show();
    $(".tab_content:first").show();
    $("ul.tabs li").click(function () {
        $("ul.tabs li").removeClass("active");
        $(this).addClass("active");
        $(".tab_content").hide();
        var activeTab = $(this).find("a").attr("href");
        $(activeTab).fadeIn();
        return false;
    });
});


/*
* SimpleModal 1.4.1 - jQuery Plugin
* http://www.ericmmartin.com/projects/simplemodal/
* Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
* Dual licensed under the MIT and GPL licenses
* Revision: $Id: jquery.simplemodal.js 261 2010-11-05 21:16:20Z emartin24 $
*/
(function (d) {
    var k = d.browser.msie && parseInt(d.browser.version) === 6 && typeof window.XMLHttpRequest !== "object", m = d.browser.msie && parseInt(d.browser.version) === 7, l = null, f = []; d.modal = function (a, b) { return d.modal.impl.init(a, b) }; d.modal.close = function () { d.modal.impl.close() }; d.modal.focus = function (a) { d.modal.impl.focus(a) }; d.modal.setContainerDimensions = function () { d.modal.impl.setContainerDimensions() }; d.modal.setPosition = function () { d.modal.impl.setPosition() }; d.modal.update = function (a, b) {
        d.modal.impl.update(a,
b)
    }; d.fn.modal = function (a) { return d.modal.impl.init(this, a) }; d.modal.defaults = { appendTo: "body", focus: true, opacity: 50, overlayId: "simplemodal-overlay", overlayCss: {}, containerId: "simplemodal-container", containerCss: {}, dataId: "simplemodal-data", dataCss: {}, minHeight: null, minWidth: null, maxHeight: null, maxWidth: null, autoResize: false, autoPosition: true, zIndex: 1E3, close: true, closeHTML: '<a class="modalCloseImg" title="Close"></a>', closeClass: "simplemodal-close", escClose: true, overlayClose: false, position: null,
        persist: false, modal: true, onOpen: null, onShow: null, onClose: null
    }; d.modal.impl = { d: {}, init: function (a, b) {
        var c = this; if (c.d.data) return false; l = d.browser.msie && !d.boxModel; c.o = d.extend({}, d.modal.defaults, b); c.zIndex = c.o.zIndex; c.occb = false; if (typeof a === "object") {
            a = a instanceof jQuery ? a : d(a); c.d.placeholder = false; if (a.parent().parent().size() > 0) {
                a.before(d("<span></span>").attr("id", "simplemodal-placeholder").css({ display: "none" })); c.d.placeholder = true; c.display = a.css("display"); if (!c.o.persist) c.d.orig =
a.clone(true)
            } 
        } else if (typeof a === "string" || typeof a === "number") a = d("<div></div>").html(a); else { alert("SimpleModal Error: Unsupported data type: " + typeof a); return c } c.create(a); c.open(); d.isFunction(c.o.onShow) && c.o.onShow.apply(c, [c.d]); return c
    }, create: function (a) {
        var b = this; f = b.getDimensions(); if (b.o.modal && k) b.d.iframe = d('<iframe src="javascript:false;"></iframe>').css(d.extend(b.o.iframeCss, { display: "none", opacity: 0, position: "fixed", height: f[0], width: f[1], zIndex: b.o.zIndex, top: 0, left: 0 })).appendTo(b.o.appendTo);
        b.d.overlay = d("<div></div>").attr("id", b.o.overlayId).addClass("simplemodal-overlay").css(d.extend(b.o.overlayCss, { display: "none", opacity: b.o.opacity / 100, height: b.o.modal ? f[0] : 0, width: b.o.modal ? f[1] : 0, position: "fixed", left: 0, top: 0, zIndex: b.o.zIndex + 1 })).appendTo(b.o.appendTo); b.d.container = d("<div></div>").attr("id", b.o.containerId).addClass("simplemodal-container").css(d.extend(b.o.containerCss, { display: "none", position: "fixed", zIndex: b.o.zIndex + 2 })).append(b.o.close && b.o.closeHTML ? d(b.o.closeHTML).addClass(b.o.closeClass) :
"").appendTo(b.o.appendTo); b.d.wrap = d("<div></div>").attr("tabIndex", -1).addClass("simplemodal-wrap").css({ height: "100%", outline: 0, width: "100%" }).appendTo(b.d.container); b.d.data = a.attr("id", a.attr("id") || b.o.dataId).addClass("simplemodal-data").css(d.extend(b.o.dataCss, { display: "none" })).appendTo("body"); b.setContainerDimensions(); b.d.data.appendTo(b.d.wrap); if (k || l) b.fixIE()
    }, bindEvents: function () {
        var a = this; d("." + a.o.closeClass).bind("click.simplemodal", function (b) { b.preventDefault(); a.close() });
        a.o.modal && a.o.close && a.o.overlayClose && a.d.overlay.bind("click.simplemodal", function (b) { b.preventDefault(); a.close() }); d(document).bind("keydown.simplemodal", function (b) { if (a.o.modal && b.keyCode === 9) a.watchTab(b); else if (a.o.close && a.o.escClose && b.keyCode === 27) { b.preventDefault(); a.close() } }); d(window).bind("resize.simplemodal", function () {
            f = a.getDimensions(); a.o.autoResize ? a.setContainerDimensions() : a.o.autoPosition && a.setPosition(); if (k || l) a.fixIE(); else if (a.o.modal) {
                a.d.iframe && a.d.iframe.css({ height: f[0],
                    width: f[1]
                }); a.d.overlay.css({ height: f[0], width: f[1] })
            } 
        })
    }, unbindEvents: function () { d("." + this.o.closeClass).unbind("click.simplemodal"); d(document).unbind("keydown.simplemodal"); d(window).unbind("resize.simplemodal"); this.d.overlay.unbind("click.simplemodal") }, fixIE: function () {
        var a = this, b = a.o.position; d.each([a.d.iframe || null, !a.o.modal ? null : a.d.overlay, a.d.container], function (c, h) {
            if (h) {
                var g = h[0].style; g.position = "absolute"; if (c < 2) {
                    g.removeExpression("height"); g.removeExpression("width"); g.setExpression("height",
'document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight + "px"'); g.setExpression("width", 'document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth + "px"')
                } else {
                    var e; if (b && b.constructor === Array) {
                        c = b[0] ? typeof b[0] === "number" ? b[0].toString() : b[0].replace(/px/, "") : h.css("top").replace(/px/, ""); c = c.indexOf("%") === -1 ? c + ' + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"' :
parseInt(c.replace(/%/, "")) + ' * ((document.documentElement.clientHeight || document.body.clientHeight) / 100) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"'; if (b[1]) { e = typeof b[1] === "number" ? b[1].toString() : b[1].replace(/px/, ""); e = e.indexOf("%") === -1 ? e + ' + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"' : parseInt(e.replace(/%/, "")) + ' * ((document.documentElement.clientWidth || document.body.clientWidth) / 100) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"' } 
                    } else {
                        c =
'(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"'; e = '(document.documentElement.clientWidth || document.body.clientWidth) / 2 - (this.offsetWidth / 2) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"'
                    } g.removeExpression("top"); g.removeExpression("left"); g.setExpression("top",
c); g.setExpression("left", e)
                } 
            } 
        })
    }, focus: function (a) { var b = this; a = a && d.inArray(a, ["first", "last"]) !== -1 ? a : "first"; var c = d(":input:enabled:visible:" + a, b.d.wrap); setTimeout(function () { c.length > 0 ? c.focus() : b.d.wrap.focus() }, 10) }, getDimensions: function () { var a = d(window); return [d.browser.opera && d.browser.version > "9.5" && d.fn.jquery < "1.3" || d.browser.opera && d.browser.version < "9.5" && d.fn.jquery > "1.2.6" ? a[0].innerHeight : a.height(), a.width()] }, getVal: function (a, b) {
        return a ? typeof a === "number" ? a : a === "auto" ? 0 :
a.indexOf("%") > 0 ? parseInt(a.replace(/%/, "")) / 100 * (b === "h" ? f[0] : f[1]) : parseInt(a.replace(/px/, "")) : null
    }, update: function (a, b) { var c = this; if (!c.d.data) return false; c.d.origHeight = c.getVal(a, "h"); c.d.origWidth = c.getVal(b, "w"); c.d.data.hide(); a && c.d.container.css("height", a); b && c.d.container.css("width", b); c.setContainerDimensions(); c.d.data.show(); c.o.focus && c.focus(); c.unbindEvents(); c.bindEvents() }, setContainerDimensions: function () {
        var a = this, b = k || m, c = a.d.origHeight ? a.d.origHeight : d.browser.opera ?
a.d.container.height() : a.getVal(b ? a.d.container[0].currentStyle.height : a.d.container.css("height"), "h"); b = a.d.origWidth ? a.d.origWidth : d.browser.opera ? a.d.container.width() : a.getVal(b ? a.d.container[0].currentStyle.width : a.d.container.css("width"), "w"); var h = a.d.data.outerHeight(true), g = a.d.data.outerWidth(true); a.d.origHeight = a.d.origHeight || c; a.d.origWidth = a.d.origWidth || b; var e = a.o.maxHeight ? a.getVal(a.o.maxHeight, "h") : null, i = a.o.maxWidth ? a.getVal(a.o.maxWidth, "w") : null; e = e && e < f[0] ? e : f[0]; i = i && i <
f[1] ? i : f[1]; var j = a.o.minHeight ? a.getVal(a.o.minHeight, "h") : "auto"; c = c ? a.o.autoResize && c > e ? e : c < j ? j : c : h ? h > e ? e : a.o.minHeight && j !== "auto" && h < j ? j : h : j; e = a.o.minWidth ? a.getVal(a.o.minWidth, "w") : "auto"; b = b ? a.o.autoResize && b > i ? i : b < e ? e : b : g ? g > i ? i : a.o.minWidth && e !== "auto" && g < e ? e : g : e; a.d.container.css({ height: c, width: b }); a.d.wrap.css({ overflow: h > c || g > b ? "auto" : "visible" }); a.o.autoPosition && a.setPosition()
    }, setPosition: function () {
        var a = this, b, c; b = f[0] / 2 - a.d.container.outerHeight(true) / 2; c = f[1] / 2 - a.d.container.outerWidth(true) /
2; if (a.o.position && Object.prototype.toString.call(a.o.position) === "[object Array]") { b = a.o.position[0] || b; c = a.o.position[1] || c } else { b = b; c = c } a.d.container.css({ left: c, top: b })
    }, watchTab: function (a) {
        var b = this; if (d(a.target).parents(".simplemodal-container").length > 0) {
            b.inputs = d(":input:enabled:visible:first, :input:enabled:visible:last", b.d.data[0]); if (!a.shiftKey && a.target === b.inputs[b.inputs.length - 1] || a.shiftKey && a.target === b.inputs[0] || b.inputs.length === 0) {
                a.preventDefault(); b.focus(a.shiftKey ? "last" :
"first")
            } 
        } else { a.preventDefault(); b.focus() } 
    }, open: function () { var a = this; a.d.iframe && a.d.iframe.show(); if (d.isFunction(a.o.onOpen)) a.o.onOpen.apply(a, [a.d]); else { a.d.overlay.show(); a.d.container.show(); a.d.data.show() } a.o.focus && a.focus(); a.bindEvents() }, close: function () {
        var a = this; if (!a.d.data) return false; a.unbindEvents(); if (d.isFunction(a.o.onClose) && !a.occb) { a.occb = true; a.o.onClose.apply(a, [a.d]) } else {
            if (a.d.placeholder) {
                var b = d("#simplemodal-placeholder"); if (a.o.persist) b.replaceWith(a.d.data.removeClass("simplemodal-data").css("display",
a.display)); else { a.d.data.hide().remove(); b.replaceWith(a.d.orig) } 
            } else a.d.data.hide().remove(); a.d.container.hide().remove(); a.d.overlay.hide(); a.d.iframe && a.d.iframe.hide().remove(); setTimeout(function () { a.d.overlay.remove(); a.d = {} }, 10)
        } 
    } 
    }
})(jQuery);


var bDisplayRegisterIcons = false;
var bDisplayLoginIcons = false;
var bLoginPanelShowing = false;
var bForgottenPasswordMode = false;

function showlayer(layer) {
    var myLayer = document.getElementById(layer);
    if (myLayer.style.display == "none" || myLayer.style.display == "") {
        myLayer.style.display = "block";
    } else {
        myLayer.style.display = "none";
    }
}

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function isValidTelNumber(telephone) {
    telephone = telephone.replace(" ", "");
    telephone = telephone.replace("-", "");
    telephone = telephone.replace("#", "");
    telephone = telephone.replace(".", "");
    telephone = telephone.replace("+", "");
    telephone = telephone.replace("/", "");
    telephone = telephone.replace("\\", "");
    telephone = telephone.replace("*", "");
    if (telephone.length < 11) return false;
    return /^[0-9 ()]*$/.test(telephone);
}

function validTelNumber(telephone, sIconDivID) {
    if (telephone.length > 0) {
        if (isValidTelNumber(telephone)) {
            if (sIconDivID.length > 0) {
                $(sIconDivID).attr("src", "http://media.bizzy.co.uk/v3/images/accept.png");
                $(sIconDivID).attr("title", "Accepted");
                $(sIconDivID).css("display", "inline");
            } else { $(sIconDivID).css("display", "none"); }
            return true;
        }
        else {
            if (sIconDivID.length > 0) {
                $(sIconDivID).attr("src", "http://media.bizzy.co.uk/v3/images/error_small.png");
                $(sIconDivID).attr("title", "Problem");
                $(sIconDivID).css("display", "inline");
            } else { $(sIconDivID).css("display", "none"); }
            return false;
        }
    }
    else {
        return false;
    }
}
var offerTimer;
function showOfferPanelSoon() {
	offerTimer = setTimeout(showOfferPanelNow(), 2000);
}

function showOfferPanelNow() {
	if (offerTimer != null)
	{
	 clearTimeout(offerTimer);
	}
	var vOfferShownCount=parseInt("0"+rvGetCookie("bizzy_offer_shown"));
	vOfferShownCount=vOfferShownCount+1;
	
	if (vOfferShownCount == 1)
	{
		rvSetCookie("bizzy_offer_shown", vOfferShownCount, 180);
		$('#sign-up-panel').hide();
		$('#login-panel').hide();
		$('#offer-panel').show();
		$('#offerregisterlink').show();
		$('#basic-modal-content').modal();
		$('#simplemodal-container').height("460");
		$('#offer-panel-title').css("background-image", "url(http://media.bizzy.co.uk/v3/images/tabs-background.png)");
	}
	else if (vOfferShownCount > 10)
	{
		rvSetCookie("bizzy_offer_shown", 0, 180);
	}
	else
	{
		rvSetCookie("bizzy_offer_shown", vOfferShownCount, 180);
	}
}

function showOfferPanel() {
	var vOfferShownCount=parseInt("0"+rvGetCookie("bizzy_offer_shown"));
	vOfferShownCount=vOfferShownCount+1;
	
	rvSetCookie("bizzy_offer_shown", vOfferShownCount, 180);
	$('#sign-up-panel').hide();
	$('#offerregisterlink').hide();
	$('#login-panel').hide();
	$('#offer-panel').show();
	$('#basic-modal-content').modal();
	$('#simplemodal-container').height("460");
	$('#offer-panel-title').css("background-image", "url(http://media.bizzy.co.uk/v3/images/tabs-background.png)");
}

function showLoginPanel() {
    if (rvGetCookie("bizzylastem") != null) {
        if ($("#loginemailaddress").val() == "") {
            $("#loginemailaddress").val(rvGetCookie("bizzylastem"));
        }
    }
    bLoginPanelShowing = true;
    bDisplayLoginIcons = false;
    bLoginPanelShowing = false;
    $('#sign-up-panel').hide();
    $('#login-panel').show();
    $('#offer-panel').hide();
    $('#rpxmframe').attr('src', 'http://bizzyinfo.rpxnow.com/openid/embed?token_url=http%3A%2F%2Fbizzy.co.uk%2Frpx.aspx');
    $('#basic-modal-content').modal();
    $('#simplemodal-container').height("460");
    $('#login-panel-title').css("background-image", "url(http://media.bizzy.co.uk/v3/images/tabs-background.png)");
}

function showSignupPanel() {
    bLoginPanelShowing = false;
    bDisplayLoginIcons = false;
    bLoginPanelShowing = false;

    $('#sign-up-panel').show();
    $('#login-panel').show();
    $('#offer-panel').hide();
    $('#rpxmframe').attr('src', 'http://bizzyinfo.rpxnow.com/openid/embed?token_url=http%3A%2F%2Fbizzy.co.uk%2Frpx.aspx');
    $('#basic-modal-content').modal();
    $('#simplemodal-container').height("665");
    $('#login-panel-title').css("background-image", "none");
    $('#login-panel-title').css("background-color", "#666");
}

$('.modalbasic').click(function (e) {
    showSignupPanel()
    return false;
});

function leftTrim(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    return sString;
}

function rightTrim(sString) {
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}

function emptyCart() {
    var sU = "/bizzy.ashx?ctx=resetcart";
        $.ajax({
            type: "GET",
            timeout: 20000,
            url: sU,
            cache: false,
            data: "",
            success: function (html) {
                document.location.href = document.location.href;
            } 
        });
}

function signUpSubmit() {
    bDisplayRegisterIcons = true;
    $("#registernameicon").attr("src", "http://media.bizzy.co.uk/v3/images/error_small.png");
    $("#registernameicon").attr("title", "Problem");
    $("#registernameicon").css("display", "inline");

    $("#registeremailaddressicon").attr("src", "http://media.bizzy.co.uk/v3/images/error_small.png");
    $("#registeremailaddressicon").attr("title", "Problem");
    $("#registeremailaddressicon").css("display", "inline");

    var regname = $('#registername').val();
    var regemailaddr = $('#registeremailaddress').val();
    regemailaddr = cleanEmailAddress(regemailaddr, '#registeremailaddress');

    var bFullNameOK = validFullName(regname, "#registernameicon");
    var bEmailAddressOK = validEmailAddress(regemailaddr, '#registeremailaddressicon');

    if (!bFullNameOK) { $("#registername").focus(); }
    else {
        if (!bEmailAddressOK) { $("#registeremailaddress").focus(); }
    }

    if ((bEmailAddressOK) && (bFullNameOK)) {
        var sU = "/bizzy.ashx?ctx=rgu&fn=" + regname + "&ea=" + regemailaddr + "&ty=USER";
        $.ajax({
            type: "GET",
            timeout: 20000,
            url: sU,
            cache: false,
            data: "",
            success: function (html) {
                if (html !== '') {

                    if (html != '<ERROR>TAKEN</ERROR>') {

                        $("#registeremailaddressicon").hide();
                        $("#registernameicon").hide();

                        $("#registername").attr("disabled", "true");
                        $("#registeremailaddress").attr("disabled", "true");

                        $("#signupbutton").hide();
                        $("#signupthanks").show();
                        $("#signupthanks").html("<span style='color:green;position:relative;top:10px;'><img src='http://media.bizzy.co.uk/v3/images/mail.png' border='0'/> <b>Thank you.</b> Please check your email to complete sign up.</span>");
                        setTimeout("closeModalWindow()", 7500);
                    }
                    else {
                        $("#signuperror").show();
                        $("#signuperror").html("<span style='color:red;position:relative;'><img src='http://media.bizzy.co.uk/v3/images/error_small.png' border='0'/> This email address is already registered. Please login below.</span>");
                        $("#loginemailaddress").val($("#registeremailaddress").val());
                        $("#loginpassword").focus();
                        setTimeout("hideSignupError()", 5000);
                    }
                }
            }
        });
    }
}

function closeModalWindow() {
    $.modal.close();
}

function hideSignupError() {
    $("#signuperror").hide();
}

function hideLoginError() {
    $("#loginerror").hide();
}

function loginSubmit() {
    bDisplayLoginIcons = true;
    $("#loginemailaddressicon").attr("src", "http://media.bizzy.co.uk/v3/images/error_small.png");
    $("#loginemailaddressicon").attr("title", "Problem");
    $("#loginemailaddressicon").css("display", "inline");

    if (!bForgottenPasswordMode) {
        $("#loginpasswordicon").attr("src", "http://media.bizzy.co.uk/v3/images/error_small.png");
        $("#loginpasswordicon").attr("title", "Problem");
        $("#loginpasswordicon").css("display", "inline");
    }
    else {
        $("#loginpasswordicon").css("display", "none");
    }

    var loginemailaddr = $('#loginemailaddress').val();
    var loginpassword = $('#loginpassword').val();
    loginemailaddr = cleanEmailAddress(loginemailaddr, '#loginemailaddress');

    var bEmailAddressOK = validEmailAddress(loginemailaddr, '#loginemailaddressicon');
    var bPasswordOK = false;
    if (!bForgottenPasswordMode) {
        bPasswordOK = validUserPassword(loginpassword, '#loginpasswordicon');
    }

    if (!bEmailAddressOK) 
    {
        $("#loginemailaddress").focus(); 
    }
    else 
    {
        if ((!bForgottenPasswordMode) && (!bPasswordOK))
        {
            $("#loginpassword").focus(); 
        }
    }

    if (!bForgottenPasswordMode) {
        // Login mode
        if ((bEmailAddressOK) && (bPasswordOK)) {
            var sU = "/bizzy.ashx?ctx=login";
            var hn = window.location.hostname;
            if (hn == 'bizzy.co.uk') {
                //sU = "https://secure.bizzy.co.uk/bizzy.ashx?ctx=login";
            }
            $.ajax({
                type: "POST",
                timeout: 20000,
                url: sU,
                data: ("em=" + loginemailaddr + "&pw=" + loginpassword),
                cache: false,
                success: function (html) {
                    if (html !== '') {
                        if ((html != '<ERROR>NOTFOUND</ERROR>') && (html != '<ERROR>PWDINVALID</ERROR>')) {
                            // Close panel and refresh
                            rvSetCookie("bizzylastem", loginemailaddr, 180);
                            closeModalWindow();
                            if (document.location.href.indexOf("/login") > 0) {
                                document.location.href = "/";
                            }
                            else {
                                document.location.href = document.location.href;
                            }
                        }
                        else if (html == '<ERROR>PWDINVALID</ERROR>') {
                            $("#loginerror").show();
                            $("#loginerror").html("<span style='color:red;position:relative;'><img src='http://media.bizzy.co.uk/v3/images/error_small.png' border='0'/> The password was incorrect.</span>");
                            $("#loginpassword").focus();
                            setTimeout("hideLoginError()", 5000);
                        }
                        else {
                            $("#loginerror").show();
                            $("#loginerror").html("<span style='color:red;position:relative;'><img src='http://media.bizzy.co.uk/v3/images/error_small.png' border='0'/> This email address is not registered.</span>");
                            $("#loginemailaddress").focus();
                            setTimeout("hideLoginError()", 5000);
                        }
                    }
                }
            });
        }
    }
    else {
        // Forgotten Password
        if (bEmailAddressOK) {
            var sU = "/bizzy.ashx?ctx=resetp";
            $.ajax({
                type: "GET",
                timeout: 20000,
                url: sU,
                data: ("em=" + loginemailaddr),
                cache: false,
                success: function (html) {
                    if (html !== '') {
                        if (html != '<ERROR>NOTFOUND</ERROR>') {
                            // Show message and switch back to Login
                            rvSetCookie("bizzylastem", loginemailaddr, 180);
                            showLogin();
                            $("#loginerror").show();
                            $("#loginerror").html("<span style='color:green;position:relative;'><img src='http://media.bizzy.co.uk/v3/images/mail.png' border='0'/> Your new password has been emailed to you.</span>");
                            $("#loginemailaddress").focus();
                            setTimeout("hideLoginError()", 5000);
                        }
                        else {
                            $("#loginerror").show();
                            $("#loginerror").html("<span style='color:red;position:relative;'><img src='http://media.bizzy.co.uk/v3/images/error_small.png' border='0'/> This email address is not registered.</span>");
                            $("#loginemailaddress").focus();
                            setTimeout("hideLoginError()", 5000);
                        }
                    }
                }
            });
        }
    }
}

function cleanEmailAddress(sEmail, sDivID) {
    if (sEmail.indexOf(" ") >= 0) {
        sEmail = sEmail.replace(" ", "");
        $(sDivID).val(sEmail);
    }
    return sEmail;
}

function validEmailAddress(emailaddr, sIconDivID) {
    if (emailaddr.length > 0) {
        if (isValidEmailAddress(emailaddr)) {
            if (sIconDivID.length > 0) {
                $(sIconDivID).attr("src", "http://media.bizzy.co.uk/v3/images/accept.png");
                $(sIconDivID).attr("title", "Accepted");
                $(sIconDivID).css("display", "inline");
            } else { $(sIconDivID).css("display", "none"); }
            return true;
        }
        else {
            if (sIconDivID.length > 0) {
                $(sIconDivID).attr("src", "http://media.bizzy.co.uk/v3/images/error_small.png");
                $(sIconDivID).attr("title", "Problem");
                $(sIconDivID).css("display", "inline");
            } else { $(sIconDivID).css("display", "none"); }
            return false;
        }
    }
    else {
        return false;
    }
}

function validFullName(fullnme, sIconDivID) {
    if (fullnme.length > 0) {
        if (fullnme.indexOf(" ") > 2) {
            if (sIconDivID.length > 0) {
                $(sIconDivID).attr("src", "http://media.bizzy.co.uk/v3/images/accept.png");
                $(sIconDivID).attr("title", "Accepted");
                $(sIconDivID).css("display", "inline");
            } else { $(sIconDivID).css("display", "none"); }
            return true;
        }
        else {
            if (sIconDivID.length > 0) {
                $(sIconDivID).attr("src", "http://media.bizzy.co.uk/v3/images/error_small.png");
                $(sIconDivID).attr("title", "Problem");
                $(sIconDivID).css("display", "inline");
            } else { $(sIconDivID).css("display", "none"); }
            return false;
        }
    }
    else {
        return false;
    }
}

function validUserPassword(usrpwd, sIconDivID) {
    if (usrpwd.length > 0) {
        $("#loginpasswordicon").css("display", "none");
    }
    else {
        if (sIconDivID.length > 0) {
            $("#loginpasswordicon").attr("src", "http://media.bizzy.co.uk/v3/images/error_small.png");
            $("#loginpasswordicon").attr("title", "Problem");
            $("#loginpasswordicon").css("display", "inline");
        }
    }
    return (usrpwd.length > 0);
}

function showResetPassword()
{
    bForgottenPasswordMode = true;
    $("#forgottenpasswordquestion").css("display", "none");
    $("#forgottenpasswordbutton").css("display", "block");
    $("#loginbutton").css("display", "none");

    $("#loginpasswordlabel").css("display", "none");
    $("#loginpassword").css("display", "none");
    $("#loginpasswordicon").css("display", "none");
    $("#loginemailaddressicon").css("display", "none");

    $("#loginquestion").css("display", "inline");
    $("#login-panel-title").html('<span class="tabs-title-content">Forgotten Password</span>');
    $("#loginemailaddress").focus();
}

function showLogin()
{
    bForgottenPasswordMode = false;
    $("#forgottenpasswordquestion").css("display", "inline");
    $("#forgottenpasswordbutton").css("display", "none");
    $("#loginbutton").css("display", "block");
    $("#loginquestion").css("display", "none");

    $("#loginpasswordlabel").css("display", "inline");
    $("#loginpassword").css("display", "inline");
    $("#loginpasswordicon").css("display", "none");
    $("#loginemailaddressicon").css("display", "none");

    $("#login-panel-title").html('<span class="tabs-title-content">Login</span>');
    if (rvGetCookie("bizzylastem") != null) {
        if ($("#loginemailaddress").val() == "") {
            $("#loginemailaddress").val(rvGetCookie("bizzylastem"));
        }
    }

    $("#loginemailaddress").focus();
}



function MonitorCo(cono, uuid) {
    var sU = "/bizzy.ashx?ctx=mon&co=" + cono + "&uid=" + uuid;
    $.ajax({
        type: "GET",
        timeout: 10000,
        url: sU,
        data: "",
        cache: false
    });
}

function UnMonitorCo(cono, uuid) {
    var sU = "/bizzy.ashx?ctx=unmon&co=" + cono + "&uid=" + uuid;
    $.ajax({
        type: "GET",
        timeout: 10000,
        url: sU,
        data: "",
        cache: false
    });
}

function BPDemoExpired(sSignupLink)
{
		$("#offer-btn").hide(); 
		$("#countdown-demo").html("<span style='color:#CC0033;font-weight:bold;'>Offer Expired</span>"); 
		$("#countdown-demo-home").html(""); 
		$("#countdown-demo-home-info").html("");
		$("#bizzy-plus-demo-link").html("<span style='padding: 2px; border: 1px solid #FFFFFF; border-radius: 6px; -moz-border-radius: 6px;color:#CC0033;background-color:#fff;font-weight:bold;'>bizzy PLUS DEMO - EXPIRED</span>");
		$("#bizzy-plus-demo-link").attr("href", sSignupLink);
		$("#bizzy-plus-badge-link").attr("href", sSignupLink);
}

function BPNoDemoLink()
{
		$("#offer-btn").hide(); 
		$("#countdown-demo-home").html(""); 
		$("#countdown-demo-home-info").html("");
		$("#bizzy-plus-demo-link").hide();
}

function BPNoDemoTopLink()
{
		$("#countdown-demo-home").html(""); 
		$("#countdown-demo-home-info").html("");
		$("#bizzy-plus-demo-link").hide();
}




/*---------------
* jQuery iToggle Plugin by Engage Interactive
* Examples and documentation at: http://labs.engageinteractive.co.uk/itoggle/
* Copyright (c) 2009 Engage Interactive
* Version: 1.0 (10-JUN-2009)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires: jQuery v1.3 or later
---------------*/

(function ($) {
    $.fn.iToggle = function (options) {

        clickEnabled = true;

        var defaults = {
            type: 'checkbox',
            keepLabel: true,
            easing: false,
            speed: 200,
            onClick: function () { },
            onClickOn: function () { },
            onClickOff: function () { },
            onSlide: function () { },
            onSlideOn: function () { },
            onSlideOff: function () { }
        },
		settings = $.extend({}, defaults, options);

        this.each(function () {
            var $this = $(this);
            if ($this.attr('tagName') == 'INPUT') {
                var id = $this.attr('id');
                label(settings.keepLabel, id);
                $this.addClass('iT_checkbox').before('<label class="itoggle" for="' + id + '"><span></span></label>');
                if ($this.attr('checked')) {
                    $this.prev('label').addClass('iTon');
                } else {
                    $this.prev('label').addClass('iToff');
                }
            } else {
                $this.children('input:' + settings.type).each(function () {
                    var id = $(this).attr('id');
                    label(settings.keepLabel, id);
                    $(this).addClass('iT_checkbox').before('<label class="itoggle" for="' + id + '"><span></span></label>');
                    if ($(this).attr('checked')) {
                        $(this).prev('label').addClass('iTon');
                    } else {
                        $(this).prev('label').addClass('iToff');
                    }
                    if (settings.type == 'radio') {
                        $(this).prev('label').addClass('iT_radio');
                    }
                });
            }
        });

        function label(e, id) {
            if (e == true) {
                if (settings.type == 'radio') {
                    $('label[for=' + id + ']').addClass('ilabel_radio');
                } else {
                    $('label[for=' + id + ']').addClass('ilabel');
                }
            } else {
                $('label[for=' + id + ']').remove();
            }
        }

        $('label.itoggle').click(function () {
            if (clickEnabled == true) {
                clickEnabled = false;
                if ($(this).hasClass('iT_radio')) {
                    if ($(this).hasClass('iTon')) {
                        clickEnabled = true;
                    } else {
                        slide($(this), true);
                    }
                } else {
                    slide($(this));
                }
            }
            return false;
        });
        $('label.ilabel').click(function () {
            if (clickEnabled == true) {
                clickEnabled = false;
                slide($(this).next('label.itoggle'));
            }
            return false;
        });

        function slide($object, radio) {
            settings.onClick.call($object); //Generic click callback for click at any state
            h = $object.innerHeight();
            t = $object.attr('for');
            if ($object.hasClass('iTon')) {
                settings.onClickOff.call($object); //Click that turns the toggle to off position
                $object.animate({ backgroundPosition: '100% -' + h + 'px' }, settings.speed, settings.easing, function () {
                    $object.removeClass('iTon').addClass('iToff');
                    clickEnabled = true;
                    settings.onSlide.call(this); //Generic callback after the slide has finnished
                    settings.onSlideOff.call(this); //Callback after the slide turns the toggle off
                });
                $('input#' + t).removeAttr('checked');
            } else {
                settings.onClickOn.call($object);
                $object.animate({ backgroundPosition: '0% -' + h + 'px' }, settings.speed, settings.easing, function () {
                    $object.removeClass('iToff').addClass('iTon');
                    clickEnabled = true;
                    settings.onSlide.call(this); //Generic callback after the slide has finnished
                    settings.onSlideOn.call(this); //Callback after the slide turns the toggle on
                });
                $('input#' + t).attr('checked', 'checked');
            }
            if (radio == true) {
                name = $('#' + t).attr('name');
                slide($object.siblings('label[for]'));
            }
        }

    };
})(jQuery);

