
var MSLO_Lookups = {};

//PRIVATE OBJECTS
MSLO_Lookups._retailerIds = [1,2,3,4,5,6,7,8,9,10,999999];
MSLO_Lookups._retailerNames = ["Costco","FLOR","KMart","Lowes","Macy's","Michaels", "Walmart", "1-800-FLOWERS", "Home Depot", "PetSmart", "Other"];
MSLO_Lookups._typeDescriptions = ["All","Bedding/Bath", "Crafts", "Fine China", "Flowers", "Food", "Furniture", "Gargen/Outdoor", "Holiday/Special Occasions", "Homes", "Home Decor", "Kitchen/Dinnerware", "Lighting", "Mattresses", "Paint", "Photo Cards", "Rugs/Floor Tiles", "Wine", "Cleaning Supplies", "Pet Products"];
MSLO_Lookups._typeIds = ["ALL","B","C","I","F","O","U","G","S","H","D","K","L","M","P","T","R","W","A","E","2", "7"];
MSLO_Lookups._etailerOnlyProducts = [
		"W",
		"T"
	];
MSLO_Lookups._validRetailerProductCombo = [
		{retailer: 8, product: "F"},
		{retailer:  2, product: "R"},
		{retailer: 8, product: -1},
		{retailer: 2, product: -1},
		{retailer: 8, product: "G"}
	];
MSLO_Lookups._etailers = [
	//All
	[{name: "Martha Stewart for Kodak Gallery", url: "http://www.kodakgallery.com/marthastewart", pretty: "www.kodakgallery.com"},
	 {name: "Martha Stewart Crafts", url: "http://www.marthastewartcrafts.com", pretty: "www.marthastewartcrafts.com"},
	 {name: "WeddingChannel.com", url: "http://macys.weddingchannel.com/registry/catalog/Fine+China/ID/34070/pn/1/ni/9/brands/-1?cm_mmc=MarthaStewart-_-Dining_Wedgwood-_-StoreLocator-_--1", pretty: "macys.weddingchannel.com"},
	 {name: "Martha Stewart for 1-800-Flowers.com", url: "http://www.1800flowers.com/marthastewart", pretty: "www.1800flowers.com"},
	 {name: "Martha Stewart Floor Designs with FLOR", url: "http://www.flor.com/service/flor/shop_by_martha_stewart_floor_designs.html?id=8RuZFh9u&mv_arg=07&utm_source=martha&utm_medium=storelocator", pretty: "www.flor.com"}
	],
	//Bedding and Bath
	[],	
	//Crafts
	[{name: "Martha Stewart for Kodak Gallery", url: "http://www.kodakgallery.com/marthastewart", pretty: "www.kodakgallery.com"},
	 {name: "Martha Stewart Crafts", url: "http://www.marthastewartcrafts.com", pretty: "www.marthastewartcrafts.com"}
	],
	//Fine China
	[{name: "WeddingChannel.com", url: "http://macys.weddingchannel.com/registry/catalog/Fine+China/ID/34070/pn/1/ni/9/brands/-1?cm_mmc=MarthaStewart-_-Dining_Wedgwood-_-StoreLocator-_--1", pretty: "macys.weddingchannel.com"}],
	//Flowers
	[{name: "Martha Stewart for 1-800-Flowers.com", url: "http://www.1800flowers.com/marthastewart", pretty: "www.1800flowers.com"}],
	//Food
	[],
	//Furniture
	[],
	//Garden Outdoor
	[{name: "Martha Stewart for 1-800-Flowers.com", url: "http://www.1800flowers.com/marthastewart", pretty: "www.1800flowers.com"}],
	//Holidays Special Occasions
	[{name: "Martha Stewart for Kodak Gallery", url: "http://www.kodakgallery.com/MarthaStewartOverview.jsp?UV=452442098826_451759317208", pretty: "www.kodakgallery.com"},
	 {name: "Martha Stewart Crafts", url: "http://www.marthastewartcrafts.com", pretty: "www.marthastewartcrafts.com"}
	],
	//Homes
	[],
	//Home Decor
	[],
	//Kitchen
	[],
	//Lighting
	[],
	//Mattresses
	[],
	//Paint
	[],
	//Photo Cards
	[{name: "Martha Stewart for Kodak Gallery", url: "http://www.kodakgallery.com/MarthaStewartOverview.jsp?UV=452442098826_451759317208", pretty: "www.kodakgallery.com"}],
	//Rugs and Floors
	[
	{name: "Martha Stewart Floor Designs with FLOR", url: "http://www.flor.com/service/flor/shop_by_martha_stewart_floor_designs.html?id=8RuZFh9u&mv_arg=07&utm_source=martha&utm_medium=storelocator", pretty: "www.flor.com"},
	{name: "Rugs Direct", url: "http://www.rugs-direct.com/rugsdirectory/home_page.aspx?N=125+4294740967", pretty: "www.rugsdirect.com.com"},
	{name: "RugsUSA.com", url: "http://www.rugsusa.com/rugsusa/control/keywordsearch;jsessionid=08C0D9DE77D719A6B70B808269B8FDE0.ajp13-jvm1?SEARCH_STRING=Martha%20Stewart", pretty: "www.rugsusa.com"},
	{name: "Grandin Road", url: "http://www.grandinroad.com", pretty: "www.grandinroad.com"},
	{name: "Home Decorators ", url: "http://www.homedecorators.com/Rugs/", pretty: "www.homedecorators.com"}],
	//Wine
	[],
	//FLOR
	[{name: "Martha Stewart Floor Designs with FLOR", url: "http://www.flor.com/service/flor/shop_by_martha_stewart_floor_designs.html?id=8RuZFh9u&mv_arg=07&utm_source=martha&utm_medium=storelocator", pretty: "www.flor.com"}],
	//1800FLOWERS
	[{name: "Martha Stewart for 1-800-Flowers.com", url: "http://www.1800flowers.com/marthastewart", pretty: "www.1800flowers.com"}]
	
];


//PUBLIC METHODS

MSLO_Lookups.isEtailerOnlyProduct = function (product){

	if(MSLO_Lookups.getIndexOf(MSLO_Lookups._etailerOnlyProducts,product) >= 0)
		return true;
	else
		return false;
}

MSLO_Lookups.parseURL = function (data){
    e=/^(((http(s?))|(ftp))\:\/\/)?((www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk))((\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+)))*$/;
    	
    	    if (data.match(e)) {
    	        return {protocol: RegExp.$1,
    	                host:RegExp.$6
    	        }
    	    }
    	    else {
    	        return {protocol:"", host:""};
	    }

}

MSLO_Lookups.getAllEtailers = function(){

	return MSLO_Lookups._etailers[0];
}

MSLO_Lookups.getNumberOfEtailers = function (){

	return MSLO_Lookups._etailers[0].length;
}

MSLO_Lookups.isValidCombination = function (retailerId, productId){
	//return true if the etailer set for retailerId and productId are the same
	
	if(retailerId == -1)	//if retailer is all then return true
		return true;
	for(i=0; i< MSLO_Lookups._validRetailerProductCombo.length; i++){
		combo = MSLO_Lookups._validRetailerProductCombo;
		if(combo[i].retailer == retailerId && combo[i].product == productId){
			return true;
		}
	}
	return false;

}
MSLO_Lookups.getNextEtailer = function (begin, typeId){
	
	var index = MSLO_Lookups.getIndexOf(MSLO_Lookups._typeIds, typeId);
	if (begin < MSLO_Lookups.getNumberOfEtailersForProductOrRetailer(typeId)){
		return MSLO_Lookups._etailers[index][begin];
	}
	else{
		return null;
	}
}

MSLO_Lookups.getNumberOfEtailersForProductOrRetailer = function(typeId){

	var index = MSLO_Lookups.getIndexOf(MSLO_Lookups._typeIds, typeId);
	if(index == -1) return -1;
	return MSLO_Lookups._etailers[index].length;
}


MSLO_Lookups.getTypeId = function(typeDescription){
	var index = MSLO_Lookups.getIndexOf(MSLO_Lookups._typeDescriptions, typeDescription);
	if (index == -1) return -1;
	return MSLO_Lookups._typeIds[index];
}

MSLO_Lookups.getTypeDescription = function(typeId){
	var index = MSLO_Lookups.getIndexOf(MSLO_Lookups._typeIds, typeId);
	if (index == -1) return -1;
	return MSLO_Lookups._typeDescriptions[index];
}

MSLO_Lookups.getRetailerName = function (retId){
	var index = MSLO_Lookups.getIndexOf(MSLO_Lookups._retailerIds, retId);
	if(index == -1) return -1;
	return MSLO_Lookups._retailerNames[index];
}
//
//PRIVATE FUNCTIONS
//
MSLO_Lookups.getIndexOf = function(list, item) {
	if (list.indexOf) {
		return list.indexOf(item);
	}
	for (var i = 0; i<list.length; i++) {
		if (list[i] == item)
			return i;
	}
	return -1;
}
