// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique =
  function() {
    var a = [];
    var l = this.length;
    for(var i=0; i<l; i++) {
      for(var j=i+1; j<l; j++) {
        // If this[i] is found later in the array
        if (this[i] === this[j])
          j = ++i;
      }
      a.push(this[i]);
    }
    return a;
  };

// Array.shuffle( deep ) - Randomly interchange elements
Array.prototype.shuffle = function( b ) {
 var i = this.length, j, t;
 while( i ) {
  j = Math.floor( ( i-- ) * Math.random() );
  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 }
 return this;
};

function parseRegion(string){
	
	var lastIndex = string.lastIndexOf("_") + 1;
	return string.substring(lastIndex,string.length);
	
}

function formatTag(string,propid,brand,type,region){

	//string out the IM=
	var lastIndex = string.lastIndexOf("&IM=");
	if(lastIndex>-1){
		string = string.substring(0,lastIndex);
	}
	
	var lastIndexMark = string.lastIndexOf("?");
	
	if(lastIndexMark>-1){
		string += "&IM=LP_GOVT_"+propid+"_";
	}else{
		string += "?IM=LP_GOVT_"+propid+"_";
	}
	
	if(type!=''){
		string += type+"_";
	}
	
	string += brand+"_"+region;
	
	return string;

}

String.prototype.convertBrandURL = function(){

	var brandRef = new Array();
	
	brandRef["SI"] = "sheraton";
	brandRef["AL"] = "alofthotels";
	brandRef["EL"] = "element";
	brandRef["4P"] = "fourpoints";
	brandRef["MD"] = "lemeridien";
	brandRef["LC"] = "luxury";
	brandRef["SR"] = "stregis";
	brandRef["WH"] = "whotels";
	brandRef["WI"] = "westin";
	brandRef["GX"] = "gx";
	
	return brandRef[this];

}

String.prototype.convertBrand = function(){

	var brandRef = new Array();
	
	brandRef["SI"] = "Sheraton";
	brandRef["AL"] = "aloft Hotels";
	brandRef["EL"] = "Element";
	brandRef["4P"] = "Four Points by Sheraton";
	brandRef["MD"] = "Le Méridien";
	brandRef["LC"] = "Luxury Collection";
	brandRef["SR"] = "St. Regis";
	brandRef["WH"] = "W Hotels";
	brandRef["WI"] = "Westin";
	brandRef["GX"] = "Historic Hotels";
	
	return brandRef[this];

}