 /* PAGELOCATOR */
		function PageLocator(propertyToUse, dividingCharacter) {
			this.propertyToUse = propertyToUse;
			this.defaultQS = null;
			this.dividingCharacter = dividingCharacter;
		}
		PageLocator.prototype.getLocation = function() {
			return eval(this.propertyToUse);
		}
		PageLocator.prototype.getHash = function() {
			var url = this.getLocation();
			if(url.indexOf(this.dividingCharacter)>-1) {
				var url_elements = url.split(this.dividingCharacter);
				return url_elements[url_elements.length-1];
			} else {
				return this.defaultQS;
			}
		}
		PageLocator.prototype.getHref = function() {
			var url = this.getLocation();
			var url_elements = url.split(this.dividingCharacter)
			return url_elements[0];
		}
		PageLocator.prototype.makeNewLocation = function(new_qs) {
			return this.getHref() + this.dividingCharacter + new_qs;
		}
	/* END PAGELOCATOR */
	
	
	/* AjaxIframesFixer */
		function AjaxIframesFixer(iframeid) {
			this.iframeid = iframeid;
			if (document.getElementById(iframeid)) {
				//this.fixLinks();
				
				this.locator =  new PageLocator("top.frames['"+this.iframeid+"'].document.location.href", "?"); //document.frames['"+this.iframeid+"']
				this.windowlocator = new PageLocator("window.location.href", "#");
				this.timer = new Timer(this);
				
				this.delayInit(); // required or IE doesn't fire
			}
		}
		AjaxIframesFixer.prototype.fixLinks = function (iframeid) {
			var links = document.getElementsByTagName("A");
			for(var i=0; i<links.length; i++) {
				var href = links[i].getAttribute("href");
				var hash = href.substr(href.indexOf("hash=")+5);
				links[i].setAttribute("href","javascript:document.getElementById('"+this.iframeid+"').setAttribute('src', 'mock-page.php?hash="+hash+"');");
			}
		}
		AjaxIframesFixer.prototype.delayInit = function(){
			this.timer.setTimeout("checkBookmark", 100, "");
		}
		AjaxIframesFixer.prototype.checkBookmark = function(){
			window.location = this.windowlocator.makeNewLocation(this.locator.getHash());
			this.checkWhetherChanged(0);
		}
		AjaxIframesFixer.prototype.checkWhetherChanged = function(location){
			if(this.locator.getHash() != location) {
    bb1ReloadBrandModelData();
    var hash_string = this.locator.getHash();
    var iframe_src = '/site/bb1_media/mockpage.html' + ((hash_string) ? '?'+hash_string : '');
    document.getElementById(this.iframeid).setAttribute('src', iframe_src);
				//window.location = this.windowlocator.makeNewLocation(this.locator.getHash());
			}
			this.timer.setTimeout("checkWhetherChanged", 200, this.locator.getHash());
		}
	/* END AjaxIframesFixer */
	
	
	/* AjaxUrlFixer */
		function AjaxUrlFixer() {
			//this.fixLinks();
			
			this.locator = new PageLocator("window.location.href", "#");
			this.timer = new Timer(this);
			this.checkWhetherChanged(0);
		}
		AjaxUrlFixer.prototype.fixLinks = function () {
			var links = document.getElementsByTagName("A");
			for(var i=0; i<links.length; i++) {
				var href = links[i].getAttribute("href");
				var hash = href.substr(href.indexOf("hash=")+5);
				links[i].setAttribute("href","#"+hash);
			}
		}
		AjaxUrlFixer.prototype.checkWhetherChanged = function(location){
			if(this.locator.getHash() != location) {
    //var ajaxnav = document.getElementById('ajaxnav'); //this.iframeid
    //if (ajaxnav) ajaxnav.setAttribute('src', '/site/bb1_media/mockpage.html?'+this.locator.getHash());
    bb1ReloadBrandModelData();
			}
			this.timer.setTimeout("checkWhetherChanged", 200, this.locator.getHash());
		}
	/* END AjaxUrlFixer */

function addHashParamToURL(url, param, value,replace) {
 if ( url == null )
  return null;
 if (url.length && url.charAt(url.length - 1) == '#')
  url = url.substring(0, url.length - 1);
 if ( isValEmpty( param ) )
  return url;
 if (replace == true)
  url = removeHashParamFromURL(url,param);
 return addNextHashParamPrefixToURL( url ) + param + "=" + emptyIfNull(value);
}


function addNextHashParamPrefixToURL(url) {
 return url + ( url.indexOf("#") == -1 ? "#" : "&" );
}

function removeHashParamFromURL(url, param) {
 var sep = "&";
 var startIndex = url.indexOf("&"+param+"=");
 if (startIndex == -1) { // || startIndex < url.indexOf("#")
  startIndex = url.indexOf("#"+param+"=")
  sep = "#";
 }
 if (startIndex != -1) {
  var endIndex = url.indexOf("&",startIndex+1);
  return url.substring(0,startIndex)+ (endIndex > 0 ? (sep == "#" ? "#"+url.substr(endIndex+1) : url.substr(endIndex)) : "");
 }
 return url;
}


function bb1GetParameter(param, doc) {
 if (typeof doc == "undefined" || doc == null)
  doc = document;
 var re = new RegExp(".*[?&#]"+param+"=([^&#]*)");
 var matches = re.exec(doc.location.href.toString()) ;
 return (matches != null && matches.length > 0) ? unescape(matches[1]) : null;
}
