// Useful prototypes
String.prototype.stripHtml=function(){return this.replace(/<(?:.|\s)*?>/g,"");};
String.prototype.stripSpaces=function(){var str=this.replace(/\t/g," ");return str.replace(/\s{2,}/g," ");};
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');};
String.prototype.parseQueryString=function(){ob=new Object();ar=this.split('&');for(var i=0;i<ar.length;i++){ob[ar[i].split('=')[0]]=ar[i].split('=')[1];}return ob;};
Array.prototype.contains=function(item,from){return this.indexOf(item,from)!=-1;}
Array.prototype.unique=function(){for(var i=1;i<this.length;i++){if(this[i][0]==this[i-1][0]){this.splice(i,1);}}};
Array.prototype.empty=function(){for(var i=0;i<=this.length;i++){this.shift();}};
Array.prototype.foreach=function(fn){for(var i=0,l=this.length;i<l;i++){fn.call(null,this[i],i);}};

// Include google analytics onload
var ga_key = "UA-6767939-1";
function load_ga(){var gaJsHost  = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");var s = document.createElement('script');s.src = gaJsHost + "google-analytics.com/ga.js";s.type = "text/javascript";document.getElementsByTagName("head")[0].appendChild(s);var i = 0;run_ga();
function run_ga(){if(typeof _gat == "object"){var pageTracker = _gat._getTracker(ga_key);pageTracker._initData();pageTracker._trackPageview();}else if(i < 20){i++;setTimeout(run_ga, 500);}};};
if(window.addEventListener){window.addEventListener("load", load_ga, false);}else if(window.attachEvent){window.attachEvent("onload", load_ga);} 

// addDOMLoadEvent
addDOMLoadEvent=(function(){var load_events=[],load_timer,script,done,exec,old_onload,init=function(){done=true;clearInterval(load_timer);while(exec=load_events.shift())
exec();if(script)script.onreadystatechange='';};return function(func){if(done)return func();if(!load_events[0]){if(document.addEventListener)
document.addEventListener("DOMContentLoaded",init,false);if(/WebKit/i.test(navigator.userAgent)){load_timer=setInterval(function(){if(/loaded|complete/.test(document.readyState))
init();},10);}
old_onload=window.onload;window.onload=function(){init();if(old_onload)old_onload();};}
load_events.push(func);}})();

// OnDomReady
addDOMLoadEvent(function(){
});

// Store locator
var locator = {
	doFocus: function(obj, foc) {
		switch(foc) {
			case true:
				if((/[0-9]{4}/.test(obj.value))) {
					obj.select();
				}
				else {
					obj.value = '';
				}
				break;
			case false:
				if(!(/[0-9]{4}/.test(obj.value))) {
					obj.value = 'Enter postcode';
				}
				break;
		}
	},
	doSubmit: function(obj) {
		if(/[0-9]{4}/.test(obj.elements['pcode'].value)) {
			window.location = CFG_BASEURL+'/stores/'+obj.elements['pcode'].value+'/';
		}
		return false;
	},
	showMap: function(url, str) {
		modalbox.Show(url, '7-Eleven ' + str, 600, 500);
		return false;
	}
};
