// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}


function set_tabs(TabValue)
{
  var vars = TabValue;
  // Postcode tab
  if(TabValue == 0){
	jQuery("#loc_postcode").addClass('current', 0);
	jQuery("#loc_london").removeClass('current', 0);
	jQuery("#loc_uk").removeClass('current', 0);
  }
  // UK tab
  if(TabValue == 1){
	jQuery("#loc_uk").addClass('current', 0);
	jQuery("#loc_postcode").removeClass('current', 0);
	jQuery("#loc_london").removeClass('current', 0);
  }
  // London
  if(TabValue == 2){
	jQuery("#loc_london").addClass('current', 0);
	jQuery("#loc_postcode").removeClass('current', 0);
	jQuery("#loc_uk").removeClass('current', 0);
  } 
} // end of function



function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++)
if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}}
function MM_swapImgRestore(){var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)x.src=x.oSrc;}
function MM_findObj(n,d){var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);if(!x&&d.getElementById)x=d.getElementById(n);return x;}
function MM_swapImage(){var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc)x.oSrc=x.src;x.src=a[i+2];}}
/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function IsThisBrowserIE6() {
    return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined))
}


// Delay Plugin for jQuery
// - http://www.evanbot.com
// - © 2008 Evan Byrne

jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	
	return this;
};

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


function validateSearchForm()
{
	
	xform=document.forms['search'];
	//alert( "the Length = " + jQuery('#postcode').val().length );
	//alert( "the Value = " + jQuery('#postcode').val() );
jQuery('#search').submit(function() {
	if(jQuery('#postcode').val().length == 0 ) {
		
		alert('Please enter a location or postcode');
		// red color
		jQuery('div#location_tabs input').css({'border':'4px solid #bf0000'});
		xform.postcode.focus();
		
		return false;
	}
	else {
		//returned to std blue color
		jQuery('div#location_tabs input').css({'border':'4px solid #50AFE1'});
		if (jQuery("#loc_london").is('.current')) {
			jQuery('#postcode').val('london');
		}
		else if (jQuery("#loc_uk").is('.current')) { 
			
			jQuery('#postcode').val('united kingdom');
		}
		return true;
	}

});



} 


function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	document.deal_form.deal_code.value = randomstring;
}




/* ------JQUERY	 PNGFIX-------*/
(function($){jQuery.fn.pngFix=function(settings){settings=jQuery.extend({blankgif:'blank.gif'},settings);var ie55=(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)==4&&navigator.appVersion.indexOf("MSIE 5.5")!=-1);var ie6=(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)==4&&navigator.appVersion.indexOf("MSIE 6.0")!=-1);if(jQuery.browser.msie&&(ie55||ie6)){jQuery(this).find("img[src$=.png]").each(function(){jQuery(this).attr('width',jQuery(this).width());jQuery(this).attr('height',jQuery(this).height());var prevStyle='';var strNewHTML='';var imgId=(jQuery(this).attr('id'))?'id="'+jQuery(this).attr('id')+'" ':'';var imgClass=(jQuery(this).attr('class'))?'class="'+jQuery(this).attr('class')+'" ':'';var imgTitle=(jQuery(this).attr('title'))?'title="'+jQuery(this).attr('title')+'" ':'';var imgAlt=(jQuery(this).attr('alt'))?'alt="'+jQuery(this).attr('alt')+'" ':'';var imgAlign=(jQuery(this).attr('align'))?'float:'+jQuery(this).attr('align')+';':'';var imgHand=(jQuery(this).parent().attr('href'))?'cursor:hand;':'';if(this.style.border){prevStyle+='border:'+this.style.border+';';this.style.border='';}
if(this.style.padding){prevStyle+='padding:'+this.style.padding+';';this.style.padding='';}
if(this.style.margin){prevStyle+='margin:'+this.style.margin+';';this.style.margin='';}
var imgStyle=(this.style.cssText);strNewHTML+='<span '+imgId+imgClass+imgTitle+imgAlt;strNewHTML+='style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;strNewHTML+='width:'+jQuery(this).width()+'px;'+'height:'+jQuery(this).height()+'px;';strNewHTML+='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader'+'(src=\''+jQuery(this).attr('src')+'\', sizingMethod=\'scale\');';strNewHTML+=imgStyle+'"></span>';if(prevStyle!=''){strNewHTML='<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:'+jQuery(this).width()+'px;'+'height:'+jQuery(this).height()+'px;'+'">'+strNewHTML+'</span>';}
jQuery(this).hide();jQuery(this).after(strNewHTML);});jQuery(this).find("*").each(function(){var bgIMG=jQuery(this).css('background-image');if(bgIMG.indexOf(".png")!=-1){var iebg=bgIMG.split('url("')[1].split('")')[0];jQuery(this).css('background-image','none');jQuery(this).get(0).runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+iebg+"',sizingMethod='scale')";}});jQuery(this).find("input[src$=.png]").each(function(){var bgIMG=jQuery(this).attr('src');jQuery(this).get(0).runtimeStyle.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader'+'(src=\''+bgIMG+'\', sizingMethod=\'scale\');';jQuery(this).attr('src',settings.blankgif)});}
return jQuery;};})(jQuery);

/*--------------LIGHTBOX---------------*/
var Lightbox={lightboxType:null,lightboxCurrentContentID:null,showBoxString:function(content,boxWidth,boxHeight){this.setLightboxDimensions(boxWidth,boxHeight);this.lightboxType='string';var contents=$('boxContents');contents.innerHTML=content;this.showBox();return false;},showBoxImage:function(href){this.lightboxType='image';var contents=$('boxContents');var objImage=document.createElement("img");objImage.setAttribute('id','lightboxImage');contents.appendChild(objImage);imgPreload=new Image();imgPreload.onload=function(){objImage.src=href;Lightbox.showBox();}
imgPreload.src=href;return false;},showBoxByID:function(id,boxWidth,boxHeight){this.lightboxType='id';this.lightboxCurrentContentID=id;this.setLightboxDimensions(boxWidth,boxHeight);var element=$(id);var contents=$('boxContents');contents.appendChild(element);Element.show(id);this.showBox();return false;},showBoxByAJAX:function(href,boxWidth,boxHeight){this.lightboxType='ajax';this.setLightboxDimensions(boxWidth,boxHeight);var contents=$('boxContents');var myAjax=new Ajax.Updater(contents,href,{method:'get'});this.showBox();return false;},setLightboxDimensions:function(width,height){var windowSize=this.getPageDimensions();if(width){if(width<windowSize[0]){$('box').style.width=width+'px';}else{$('box').style.width=(windowSize[0]-50)+'px';}}
if(height){if(height<windowSize[1]){$('box').style.height=height+'px';}else{$('box').style.height=(windowSize[1]-50)+'px';}}},showBox:function(){Element.show('overlay');this.center('box');return false;},hideBox:function(){var contents=$('boxContents');if(this.lightboxType=='id'){var body=document.getElementsByTagName("body").item(0);Element.hide(this.lightboxCurrentContentID);body.appendChild($(this.lightboxCurrentContentID));}
contents.innerHTML='';$('box').style.width=null;$('box').style.height=null;Element.hide('box');Element.hide('overlay');return false;},getPageDimensions:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=document.body.scrollWidth;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){windowWidth=self.innerWidth;windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=windowWidth;}else{pageWidth=xScroll;}
arrayPageSize=new Array(windowWidth,windowHeight,pageWidth,pageHeight)
return arrayPageSize;},center:function(element){try{element=document.getElementById(element);}catch(e){return;}
var windowSize=this.getPageDimensions();var window_width=windowSize[0];var window_height=windowSize[1];$('overlay').style.height=windowSize[3]+'px';element.style.position='absolute';element.style.zIndex=99;var scrollY=0;if(document.documentElement&&document.documentElement.scrollTop){scrollY=document.documentElement.scrollTop;}else if(document.body&&document.body.scrollTop){scrollY=document.body.scrollTop;}else if(window.pageYOffset){scrollY=window.pageYOffset;}else if(window.scrollY){scrollY=window.scrollY;}
var elementDimensions=Element.getDimensions(element);var setX=(window_width-elementDimensions.width)/2;var setY=(window_height-elementDimensions.height)/2+scrollY;setX=(setX<0)?0:setX;setY=(setY<0)?0:setY;element.style.left=setX+"px";element.style.top=setY+"px";Element.show(element);},init:function(){var lightboxtext='<div id="overlay" style="display:none"></div>';lightboxtext+='<div id="box" style="display:none">';lightboxtext+='<img id="close" src="/images/close-lb.gif" onClick="close_lb(false);" alt="Close" title="Close this window" />';lightboxtext+='<div id="boxContents"></div>';lightboxtext+='</div>';var body=document.getElementsByTagName("body").item(0);new Insertion.Bottom(body,lightboxtext);}}
