// ------[ Nurun Javascript Framework ]------------------------------------------------- //	
window.Nurun = window.Nurun || {};

Nurun = {
	// Nurun Javascript Framework;
	};

Nurun.HBX = {
	Debug : false,
	
	Config : {
		Server : "ehg-nuruninc.hitbox.com",
		Account : "DM550710DNEA62EN3",
		CommerceAccount : "975603177056"
		},

	PageName : null,
	ContentCategory : null,
	
	PageView : function(pageName,contentCategory) {
		this.PageName = Nurun.HBX.FormatString(pageName); 
		this.ContentCategory = Nurun.HBX.FormatString(contentCategory); 
		if(this.Debug) alert("Old PageName: " + pageName + "\nNew PageName: " + this.PageName + "\nOld ContentCategory: " + contentCategory + "\nNew ContentCategory: " + this.ContentCategory);
		},

	SearchKeywords : "",
	SearchCount : "0",
	
	SearchView : function(keywords,count) {
		if(keywords) this.SearchKeywords = Nurun.HBX.FormatString(keywords); 
		if(count) this.SearchCount = Nurun.HBX.FormatString(count);
		},

	FormatString : function(s) { // Remove invalid Char in a string.
		if(s) {
			s=s.toString();
			s=s.replace(/\s+/g,"+");
			s=s.replace(/[\À\à\Á\á\Â\â\Ä\ä ]/g,"a");
			s=s.replace(/[\É\é\È\è\Ê\ê\Ë\ë ]/g,"e");
			s=s.replace(/[\Î\î\Ï\ï ]/g,"i");
			s=s.replace(/[\Ô\ô\Ò\ò\Ô\ô\Ö\ö ]/g,"o");
			s=s.replace(/[\Œ\œ ]/g,"o");
			s=s.replace(/[\Ÿ\ÿ ]/g,"y");
			s=s.replace(/[\Ç\ç ]/g,"c");
			s=s.replace(/[\ù\ú\û\ü ]/g,"u");
			s=s.replace(/[^a-zA-Z0-9\/+()\.\-]/g,"+");		
			}
		return(s);
		},
		
	FormatPrice : function(i) { // Format to the HBX Price Format
		if(i) {
			i=i.toString().replace(/[^0-9\.]/g,"");	
			if(isNaN(i)) i = 0;
			else i = parseFloat(i);
			}
		return(i);
		}		
	};
		
Nurun.HBX.Products = {
	ViewFlag : 1,
	Name : ["PRODUCT"],
	Quantity : ["QUANTITY"],
	Price : ["PRICE"],
	Brand : ["BRAND"],
	Categories : ["CATEGORIES"],		
	Quantity : ["QUANTITY"],
	Sku : ["SKU"],
	Custom1 : ["CUSTOM+ONE"],
	Custom2 : ["CUSTOM+TWO"],
	Store : "STORE",
	
	View : function(name,sku,price,brand,categories,store) {
		this.ViewFlag = 1;
		this.Name.push(Nurun.HBX.FormatString(name)+"+("+Nurun.HBX.FormatString(sku)+")");
		this.Price.push(Nurun.HBX.FormatPrice(price));
		this.Sku.push(Nurun.HBX.FormatString(sku));
		this.Brand.push(Nurun.HBX.FormatString(brand));
		this.Categories.push(Nurun.HBX.FormatString(categories));
		if(store) this.Store = store;
		},

	Add : function(quantity,name,sku,price,brand,categories,store,custom1,custom2) {
		this.ViewFlag = 0;
		this.Quantity.push(quantity);
		this.Name.push(Nurun.HBX.FormatString(name)+"+("+Nurun.HBX.FormatString(sku)+")");
		this.Price.push(Nurun.HBX.FormatPrice(price));
		this.Sku.push(Nurun.HBX.FormatString(sku));
		this.Brand.push(Nurun.HBX.FormatString(brand));
		this.Categories.push(Nurun.HBX.FormatString(categories));
		this.Custom1.push(Nurun.HBX.FormatString(custom1));
		this.Custom2.push(Nurun.HBX.FormatString(custom2));
		if(store) this.Store = store;			
		},			
	
	Get : function(item) {
		obj = eval("this." + item);
		if(obj) {

			var items = obj.slice();
			if(items.length > 1) items.shift();
			str = items.join(",");
			if(Nurun.HBX.Debug) alert(str);
			return str;
			} 
		}
	
	}; // Product Object
	
Nurun.HBX.Order = {
	ShipType : "SHIP+TYPE",
	ShipCost : "SHIP+COST",
	ShipCity : "CITY",
	ShipState : "STATE",
	ShipZip : "ZIP",
	ShipCountry : "COUNTRY",
	OrderID : "ORDER+ID",
	PaymentType : "PAYMENT+TYPE",
	CustomerType : "CUSTOMER+TYPE",
	CustomerID : "",
	Promotion : "PROMOTION",
	Discount : "DISCOUNT",
	
	Shipping : function(type,cost) {
		if(type) this.ShipType = Nurun.HBX.FormatString(type);
		if(cost) this.ShipCost = Nurun.HBX.FormatPrice(cost);
		},
		
	ShippingInfo : function(city,state,zip,country) {
		if(city) this.ShipCity = Nurun.HBX.FormatString(city);
		if(state) this.ShipState = Nurun.HBX.FormatString(state);
		if(zip) this.ShipZip = Nurun.HBX.FormatString(zip);
		if(country) this.ShipCountry = Nurun.HBX.FormatString(country);
		},
		
	CheckOut : function(customerID,orderID,customerType,paymentType,promotion,discount) {
		if(customerID) this.CustomerID = Nurun.HBX.FormatString(customerID);
		if(orderID) this.OrderID = Nurun.HBX.FormatString(orderID);
		if(customerType) this.CustomerType = Nurun.HBX.FormatString(customerType);
		if(paymentType) this.PaymentType = Nurun.HBX.FormatString(paymentType);
		if(promotion) this.Promotion = Nurun.HBX.FormatString(promotion);
		if(discount) this.Discount = Nurun.HBX.FormatPrice(discount);
		}

	}; // Order Object
