// JavaScript Document
var homepageURLs = new Array();
homepageURLs[0] = "bcwomens-3dcart.3dcartstores.com/";
homepageURLs[1] = "bcwomens-3dcart.3dcartstores.com/index.html";
homepageURLs[2] = "bcwomens-3dcart.gssiwebs.com/";
homepageURLs[3] = "bcwomens-3dcart.gssiwebs.com/index.html";

var bannerImgs = new Array("assets/templates/custom1/images/banner.jpg","assets/templates/custom1/images/banner1.jpg","assets/templates/custom1/images/banner2.jpg", "assets/templates/custom1/images/banner3.jpg", "assets/templates/custom1/images/banner4.jpg", "assets/templates/custom1/images/banner5.jpg");

function isHomepage()
{
	var strHref = window.location.href;
	strHref = strHref.replace("https://", "").replace("http://","")
	
	for(var i = 0; i < homepageURLs.length; i++)
	{
		if(strHref == homepageURLs[i])
		{
			return true;
		}
	}
	return false;
}

function ischeckoutpage()
{
	var strHref = window.location.href;
	
	if(strHref.toLowerCase().indexOf("checkout.asp") > -1)
	{
		return true;
	}
	else if(strHref.toLowerCase().indexOf("checkout3.asp") > -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function loadBanner()
{
	var bannerEle = document.getElementById("topbanner");
	var contentEle = document.getElementById("content");
	var contentbodyEle = document.getElementById("content-body");
	var catEle = document.getElementById("category-fullline");
	var h1Ele = document.getElementsByTagName("h1");
	var catsValue;
	var catsArray;
	
	
	/****** load banners randomly for content pages and homepage ******/
	if (bannerEle != null && isHomepage())
	{
		bannerEle.style.backgroundImage = "url(" + bannerImgs[0] + ")";
	} 
	else if (bannerEle != null)
	{
		bannerEle.style.backgroundImage = "url(" + bannerImgs[Math.floor(Math.random()*bannerImgs.length)] + ")";
	}
	
	if(catEle != null)
	{
		catsValue = catEle.innerText || catEle.textContent;  //cross browsers
		catsArray = catsValue.split(">",2);
	}
	
	if(h1Ele[0] == null && catEle != null) // put headings for product listing page
	{
		var idx = catsValue.lastIndexOf(">");
		var lastCatName = catsValue.substr(idx+2);
		//alert(lastCatName);
		var h1EleNew = document.createElement('h1');
		h1EleNew.innerHTML = lastCatName;
		contentbodyEle.insertBefore(h1EleNew, contentbodyEle.childNodes[0]);
	}
	
	/******  load category image for each category ******/
	if(catEle != null && contentbodyEle != null)
	{
		if(ischeckoutpage())
		{
			contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-blank.gif)";
			contentbodyEle.style.backgroundRepeat = "no-repeat";
		}
		else
		{
			var catV = trim(catsArray[1].toLowerCase());
			if(catV.indexOf("baby clothing") > -1)
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-babycloth.jpg)";
			else if (catV.indexOf("baby keepsakes") > -1)
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-baby.jpg)";
			else if (catV.indexOf("blankets") > -1)
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-blanket.jpg)";
			else if (catV.indexOf("for mom") > -1)
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-mom.jpg)";
			else if (catV.indexOf("gift sets") > -1)
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-gift.jpg)";
			else if (catV.indexOf("toys, books and stuffies") > -1)
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-toy.jpg)";
			else if (catV.indexOf("flowers") > -1)
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-flower.jpg)";
			else if (catV.indexOf("my cart") > -1)
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-blank.gif)";
			else
				contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-books.jpg)";
			contentbodyEle.style.backgroundRepeat = "no-repeat";
		}
	}
	else
	{
		contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/cat-books.jpg)";
		contentbodyEle.style.backgroundRepeat = "no-repeat";
	}
}

/********  trim leading spaces *************/
function trim(s) 
{
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}