
var MSLO_Lookups = {};

//PRIVATE OBJECTS
MSLO_Lookups._retailerIds = [1,2,3,4,5,6,7,8,999999];
MSLO_Lookups._retailerNames = ["Costco","FLOR","KMart","Lowes","Macy's","Michaels", "Walmart", "1-800-FLOWERS","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"];
MSLO_Lookups._typeIds = ["ALL","B","C","I","F","O","U","G","S","H","D","K","L","M","P","T","R","W", "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"},
	 {name: "Martha Stewart Crafts", url: "http://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"},
	 {name: "Martha Stewart for 1-800-Flowers.com", url: "http://www.1800flowers.com/marthastewart"},
	 {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"}
	],
	//Bedding and Bath
	[],	
	//Crafts
	[{name: "Martha Stewart for Kodak Gallery", url: "http://www.kodakgallery.com/marthastewart"},
	 {name: "Martha Stewart Crafts", url: "http://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"}],
	//Flowers
	[{name: "Martha Stewart for 1-800-Flowers.com", url: "http://www.1800flowers.com/marthastewart"}],
	//Food
	[],
	//Furniture
	[],
	//Garden Outdoor
	[{name: "Martha Stewart for 1-800-Flowers.com", url: "http://www.1800flowers.com/marthastewart"}],
	//Holidays Special Occasions
	[{name: "Martha Stewart for Kodak Gallery", url: "http://www.kodakgallery.com/MarthaStewartOverview.jsp?UV=452442098826_451759317208"},
	 {name: "Martha Stewart Crafts", url: "http://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"}],
	//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"}],
	//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"}],
	//1800FLOWERS
	[{name: "Martha Stewart for 1-800-Flowers.com", url: "http://www.1800flowers.com/marthastewart"}]
	
];


//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;
}
