
// Last updated: 14-07-2009 (Jnm)

var stockInfoTelephone = '0844 372 1010';
var strRowShow = 'block';
var noFB;
/** creates an extra stylesheet **/
function addstyles(){

	//** Build js rendered stylesheet that css validators fail on **
	var jstyle = document.getElementsByTagName("head")[0];
	var lk = document.createElement("link");
	jstyle.appendChild(lk);
	lk.setAttribute("rel", "stylesheet");
	lk.setAttribute("type", "text/css");
	lk.setAttribute("href", "/styles/js-vl.css");
}

// This is a painted-on function to prevent JS errors on IE8.x and co..

function down(obj)
	{
	}

// This function should be present on the "onload" area of the <body> tag on _all_ pages.

function loaded(){
	
	//alert('Page Loaded');
	buildFancyBoxTags();

	$('a.brandshopslink').click(function(e){
		e.preventDefault();
		target = e?e.target:window.event?window.event.srcElement:null;
		if(target) showBrandShops('show');
	});
	
	$("a.ajaxpopupinfo").fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'hideOnContentClick': false,
		'autoDimensions':true,
		'scrolling': 'yes',
		'titleShow': false,
		'onStart' : function(selectedArray, selectedIndex, selectedOptions){
			hrefaction = selectedArray[selectedIndex].href.replace("http://www.ellis-brigham.com/","");
			pageTracker._trackEvent('Fancy pop-ups', hrefaction);
		}
	});
	
	topmenuHightlight();
	
}

function setsearchterms(formid){

	if(formid == 'ebsearchbox'){
		searchterms = $("form#"+formid).children("input.searchkeywords").val();
		sref = 'header';
	}else if(formid == 'ebsearchfilter'){
		searchterms = $("form#"+formid).children("div").children("div").children("input.searchtext").val();
		sref = 'sfilter';
	}else{
		searchterms = $("form#"+formid).children("div").children("div").children("div").children("div").children("input.searchtext").val();
		sref = 'advanced';
	}
	
	if(searchterms == '')searchterms = 'none';
	
	searchurl = "http://www.ellis-brigham.com/search?search_text="+searchterms+"&search_ref="+sref;
	
	$("form#"+formid).attr("action",searchurl);
	
	return true;
}


// ----- auto-caption script (Jnm 2008) --------------------------------------

function cap(obj)
	{
	if (obj.accessKey)
		{
		obj.title=obj.innerText + " (shortcut = alt+" +obj.accessKey+ " then Enter)";
		}
	
	else
		{
		obj.title=obj.innerText;
		}
	}
	

	
// ----- inline help on menubar (Jnm 2008) --------------------------------------

function iCap(helpText)
	{
	document.getElementById('menuTopHelp').innerText=helpText;
	}
	
function capZap()
	{
	document.getElementById('menuTopHelp').innerText='';
	}
	


// ----- generic destination onclick (Jnm 2008) -------------------------------

function go(dest)
	{
	top.location=dest;
	}
	
function capZap()
	{
	document.getElementById('menuTopHelp').innerText='';
	}
	


// ----- Open left menu items and hide the rest -----

function hideTheKids()
	{
	document.getElementById('m01').className='';
	document.getElementById('m02').className='';
	document.getElementById('m03').className='';
	document.getElementById('m04').className='';
	document.getElementById('m05').className='';
	document.getElementById('m06').className='';
	document.getElementById('m07').className='';
	document.getElementById('m08').className='';
	document.getElementById('m09').className='';
	document.getElementById('m10').className='';
	document.getElementById('m11').className='';
	document.getElementById('m12').className='';
	document.getElementById('m13').className='';
	document.getElementById('m14').className='';
	document.getElementById('m15').className='';
	
	//document.getElementById('c01').className='hidden';
	//document.getElementById('c02').className='hidden';
	//document.getElementById('c03').className='hidden';
	//document.getElementById('c04').className='hidden';
	//document.getElementById('c05').className='hidden';
	//document.getElementById('c06').className='hidden';
	//document.getElementById('c07').className='hidden';
	//document.getElementById('c08').className='hidden';
	//document.getElementById('c09').className='hidden';
	//document.getElementById('c10').className='hidden';
	//document.getElementById('c11').className='hidden';
	//document.getElementById('c12').className='hidden';
	//document.getElementById('c13').className='hidden';
	//document.getElementById('c14').className='hidden';
	//document.getElementById('c15').className='hidden';
	}

function ebtogg(childMenu,currentLink)
	{
	hideTheKids();
	document.getElementById(childMenu).className='visible';
	currentLink.className='current';
	}
	

	
// ----- Generic show hidden content function -----

function reveal(itemId)
	{
	document.getElementById(itemId).className='inline';
	}
	


// ----- Generic hide content function -----

function conceal(itemId)
	{
	document.getElementById(itemId).className='hidden';
	}
	
	
	
// ----- Generic lock a Form Field -----

function lock(theItem)
	{
	document.getElementById(theItem).className='locked';
	document.getElementById(theItem).disabled='disabled';
	document.getElementById(theItem).title='this form field is locked..';
	}	
	


// ----- Hide all panels -----

function zapPanels()
	{
	/*
	document.getElementById('panelShop').className='hidden';
	document.getElementById('panelNews').className='hidden';
	document.getElementById('panelStores').className='hidden';
	document.getElementById('panelHelp').className='hidden';
	document.getElementById('panelCommunity').className='hidden';
	document.getElementById('panelContact').className='hidden';
	document.getElementById('panelBasket').className='hidden';
	*/
	}

function closePanels()
	{
	setTimeout("zapPanels()", 2000);
	}
	

// ----- Jump to a Brand listing -----

function hopBrand(destBrand)
	{
	destBrand = destBrand.replace(/\+/g,"%2B");
	//top.location = '/cgi-bin/psProdSrch.cgi?mode=user&formCategory=All&formBrand='+destBrand;
	//top.location = '/cgi-bin/psShowCategory.cgi?brand='+destBrand;
	top.location = '/store/'+destBrand;
	}
	
// ----- Jump to a Category listing -----

function hopCategory(destCategory)
	{
	destCategory = destCategory.replace(/\+/g,"%2B");
	//top.location = '/cgi-bin/psProdSrch.cgi?mode=user&formCategory='+destCategory+'&formBrand=All';
	top.location = '/'+destCategory+'/store';
	}
	

	
// ----- Promotional messages -----

function ebPromo(currentPage)
	{
	top.location = '/';
	}
	
	

// ----- Blank form field reset -----

function resetPrompt(vessel)
	{
	if (vessel.value == '')
		{
		vessel.value = vessel.title;
		}
	else
		{
		}
	}
	
function zapPrompt(vessel)
	{
	if (vessel.value != vessel.title || vessel.value == '')
		{
		vessel.value = vessel.value;
		vessel.select();
		}
	else
		{
		vessel.value = '';
		}
	}
	
	
function newsthumb(id,itype){

	if(itype == "1")
	{
		document.getElementById(id).src = "/gfx/newsborderHi.gif";
	}
	else if(itype == "0")
	{
		document.getElementById(id).src = "/gfx/newsborder.gif";
	}

}


// ------ Credit Card Stuff (09-02-2009) Jnm

function cardBasic()
	{
	document.getElementById('vf').className='hidden';
	document.getElementById('issue').className='hidden';
	document.getElementById('amexDigits').className='hidden';
	}
	
function cardSolo()
	{
	document.getElementById('amexDigits').className='hidden';
	document.getElementById('vf').className='hidden';
	document.getElementById('issue').className='visibleTr';
	}
	
function cardMaestro()
	{
	document.getElementById('amexDigits').className='hidden';
	document.getElementById('vf').className='visibleTr';
	document.getElementById('issue').className='visibleTr';
	}
	
function cardAmex()
	{
	document.getElementById('vf').className='hidden';
	document.getElementById('issue').className='hidden';
	document.getElementById('amexDigits').className='visibleTr';
	}


/** New Drop Menu 2010 for IE6 **/

function setTopMenu(){

	//And Bottom Menu!

	topMenuItems = $("ul#topmenu > li");
	bottomMenuItems = $("ul#footermenu > li");
	ulWidthN=0;
	for(i=0;i<topMenuItems.length;i++)
	{
		menuItem = topMenuItems[i];
		
		menuItem.onmouseover = function(){dropMenu(this,'show');}
		menuItem.onmouseout = function(){dropMenu(this,'hide');}
		
		if(menuItem.getElementsByTagName("ul")[0]){

			thisUL = menuItem.getElementsByTagName("ul")[0];
			totalLI = $(thisUL).children("li");
			firstLIUL = $(totalLI[0]).children("ul");

			if($(firstLIUL).length > 0){
			
				colHeight = $(firstLIUL[0]).css('min-height');
				colHeight = colHeight.replace("px","");
				colHeight = parseInt(colHeight);
				$(totalLI).children("ul").css("height",colHeight);
			}
			
			ulWidth = countIEMenuWidth(totalLI);	
			$(thisUL).css("width",parseInt(ulWidth)-2);
			
			if($(thisUL).hasClass('rhs')){

			 	leftPos = 977-ulWidth;
			 	$(thisUL).css("left",leftPos);
			}
		}
	}
	
	for(b=0;b<bottomMenuItems.length;b++)
	{
		btMenuItem = bottomMenuItems[b];
		btMenuItem.onmouseover = function(){dropMenu(this,'show');}
		btMenuItem.onmouseout = function(){dropMenu(this,'hide');}
	}
}

function countIEMenuWidth(totalLI){

	ulWidthN=0;
	
	for(c=0;c<totalLI.length;c++)
	{
		colWidth = $(totalLI[c]).css('width');
		colWidth = colWidth.replace("px","");
		ulWidthN = ulWidthN+parseInt(colWidth);	
	}
	
	return ulWidthN;
}


function dropMenu(mItem,hoVis){
	
	checkSubMenu = mItem.childNodes;
	for(i=0;i<checkSubMenu.length;i++)
	{
		if(checkSubMenu[i].nodeName == "UL")
		{
			if(hoVis == "show"){varVis = "block";mItem.style.background = "#e95d0e url('/gfx/ogmenu-bg.gif') repeat-x left top";}
			else if(hoVis == "hide"){varVis = "none";mItem.style.background = '';}
			
			checkSubMenu[i].style.display = varVis;
		}
	}
}

/** New Drop Menu 2010 for IE6 - End **/


function topmenuHightlight(){

	thisPage = location.pathname;
	
	topList = $("ul#topmenu").children("li");
	
	$(topList).each(function(index){
	
		checkPage = '';
		if($(this).children("a").attr("href"))checkPage = $(this).children("a").attr("href");
		checkPage = checkPage.replace("http://www.ellis-brigham.com","");
		if(checkPage == thisPage)$(this).addClass("active");
	});
}

/** Homepage Products Rotate **/

var HomeProductSpeed = 5; 
var totalHomeRotateProducts;
var strtRotate;

function startProducts(){

	$("#homeproductcontrols").css("display","block");
	

	$('#stophomerotate').click(function(e){
		e.preventDefault();
		target = e?e.target:window.event?window.event.srcElement:null;
		if(target) StopProducts();
	});
	
	$('#starthomerotate').click(function(e){
		e.preventDefault();
		target = e?e.target:window.event?window.event.srcElement:null;
		if(target) NextProducts('auto','nxt');
	});
	
	rtProducts = document.getElementById("products").getElementsByTagName("div");
	totalHomeRotateProducts=0;
	
	for(i=0;i<rtProducts.length;i++)
	{
		thisCLASS = $(rtProducts[i]).attr("class");
		
		if(thisCLASS == "result")
		{
			thisID = "rp"+totalHomeRotateProducts;
			rtProducts[i].setAttribute("id",thisID);
			rtProducts[i].style.top = "-160px";
			totalHomeRotateProducts=totalHomeRotateProducts+1;
		}
	}
	
	document.getElementById("products").setAttribute("curproduct","0");
	
	if(totalHomeRotateProducts>1)
	{
		rotateAni = HomeProductSpeed*1000;
		rtProducts[0].style.top = "0px";
		strtRotate = setTimeout("rotateProducts(0,'auto','f')",rotateAni);
	}
}


function rotateProducts(product,am,dir){

	totalProducts=totalHomeRotateProducts-1;
	
	if(am == "manual")
	{
		mProduct = parseInt(product);
		product = $("#products").attr("curproduct");
		
		i=parseInt(product);
		if(product > totalProducts)
		{
			i=0;
		}
		
		alert(i);

		n=mProduct;
		if(i >= totalProducts)
		{
			n=0;
		}

		na=n+1;
		if(n >= totalProducts)
		{
			na=0;
		}

		$("#rp"+n).animate({"top": "+=160px"}, "slow");
		$("#rp"+i).animate({"top": "+=160px"}, "slow");

		fID = "rp"+i;
		sID = "rp"+na;
		
		document.getElementById(fID).style.top = "-160px";
		document.getElementById(sID).style.top = "-160px";
	}
	else
	{	
		if(dir == 'f')
		{
			i=parseInt(product);
			if(product > totalProducts)
			{
				i=0;
			}

			n=i+1;
			if(i >= totalProducts)
			{
				n=0;
			}

			na=n+1;
			if(n >= totalProducts)
			{
				na=0;
			}

			$("#rp"+n).animate({"top": "+=160px"}, "slow");
			$("#rp"+i).animate({"top": "+=160px"}, "slow");

			fID = "rp"+i;
			sID = "rp"+na;

			document.getElementById(fID).style.top = "-160px";
			document.getElementById(sID).style.top = "-160px";
		}
		else if(dir == 'b')
		{
			i=parseInt(product);
			if(product < 0)
			{
				i=totalProducts;
			}

			n=i-1;
			if(i <= 0)
			{
				n=totalProducts;
			}

			na=n-1;
			if(n <= 0)
			{
				na=totalProducts;
			}

			$("#rp"+n).animate({"top": "-=160px"}, "slow");
			$("#rp"+i).animate({"top": "-=160px"}, "slow");

			fID = "rp"+i;
			sID = "rp"+na;

			document.getElementById(fID).style.top = "160px";
			document.getElementById(sID).style.top = "160px";
		}
	}
	
	$("#products").attr("curproduct",n);
	
	if(am == "auto")
	{
		rotateAni = HomeProductSpeed*1000;
		strtRotate = setTimeout("rotateProducts("+n+",'auto','f')",rotateAni);
	}
}

function NextProducts(mType,prNum){

	clearTimeout(strtRotate);
	
	if(prNum == 'nxt'){curProduct = $("#products").attr("curproduct");}
	else {curProduct = prNum;}
	
	for(i=0;i<totalHomeRotateProducts;i++)
	{
		if(i != curProduct)
		{
			cID = "rp"+i;
			document.getElementById(cID).style.top = "-160px";
		}
	}
	
	rotateProducts(curProduct,mType,'f');
}

function PreviousProducts(){

	clearTimeout(strtRotate);
	curProduct = $("#products").attr("curproduct");
	
	for(i=0;i<totalHomeRotateProducts;i++)
	{
		if(i != curProduct)
		{
			cID = "rp"+i;
			document.getElementById(cID).style.top = "160px";
		}
	}
	
	rotateProducts(curProduct,'manual','b');
}

function StopProducts(){

clearTimeout(strtRotate);

}


/** Homepage News  **/

function startNews(){


	//Build nav
	newsArticles = document.getElementById("tickgrid").getElementsByTagName("tr");
	navHeight = $("div#bulletin > #nav").outerHeight(true);
	
	navParent = document.getElementById("nav");
	navButtonHeight = Math.floor((navHeight/newsArticles.length)-5);
	navParent.setAttribute("article", "0");

	for(i=0;i<newsArticles.length;i++)
	{
		thisID = "navBT"+i;
		
		var newButton = document.createElement("a");
		navParent.appendChild(newButton);
		newButton.setAttribute("id", thisID);
		newButton.setAttribute("class", "button");
		newButton.setAttribute("article", i);
		
		thisTITLE = newsArticles[i].getElementsByTagName("a")[0].innerHTML;
		newButton.setAttribute("href", "#"+thisTITLE);
		
		document.getElementById(thisID).style.height = navButtonHeight+"px";
		
		$('#'+thisID).click(function(e){
			e.preventDefault();
			target = e?e.target:window.event?window.event.srcElement:null;
			if(target) gotoArticles(this);
		});
		
	}
}

function gotoArticles(obj){

	newsArticles = document.getElementById("tickgrid").getElementsByTagName("tr");

	articleHeight = 84;
	article = $(obj).attr("article");
	curArticle = $("div#bulletin > #nav").attr("article");
	
	xtHeight = $(newsArticles[article]).outerHeight(true);
	xtHeight = Math.round(xtHeight-articleHeight);
	if(xtHeight <= 0)
	{
		xtHeight = 0;
	}
		
	if(article > curArticle)
	{
		moveNews = article-curArticle;
		moveNews = Math.round((articleHeight*moveNews)-xtHeight);
		
		$('#homenews').animate({"top": "-="+moveNews+"px"}, "slow");
	}
	else if(curArticle > article)
	{
		moveNews = curArticle-article;
		moveNews = Math.round((articleHeight*moveNews)+xtHeight);
		
		$('#homenews').animate({"top": "+="+moveNews+"px"}, "slow");
	}
	
	$("div#bulletin > #nav").attr("article", article);
}



/** Show / Hide Brand Shop Menu **/

function checkBrandShops(){

	countColums = $('#brandbuttoncont > div');
	if(countColums.length<2){$('div.brandbuttoncont > h2').html("featured brands");}
}

function showBrandShops(sType){

	$('a.brandshopslink').unbind();
	
	countColums = $('#brandbuttoncont > div');
	slideWidth = ((countColums.length-1)*212)+5;
	sdwSlideWidth = slideWidth-5;
	slideWidthCss = parseInt(slideWidth)+5;
	
	if(countColums.length>1)
	{

		if(sType == 'show')
		{
			$('div#homefeatbrandcover').click(function(){

				showBrandShops('hide');
			});
			
			$('div#homefeatbrandsdw').css("width",slideWidthCss+"px");
			$('div#homefeatbrandsdw').show();
			$('div#homefeatbrandcover').fadeTo("fast","0.6");
			
			$('div#rightmenu').animate({width: '+='+slideWidth+'px'}, "slow");
			$('div#homefeatbrandsdw').animate({right: '+='+sdwSlideWidth+'px'}, "slow");
			
			$('#brandbuttoncont').css("padding-left","5px");
			$('a.brandshopslink').attr("href","#view-min");
			$('a.brandshopslink > span').html("view less");

			$('a.brandshopslink').click(function(e){
				e.preventDefault();
				target = e?e.target:window.event?window.event.srcElement:null;
				if(target) showBrandShops('hide');
			});
		}
		else if(sType == 'hide')
		{
			$('div#homefeatbrandcover').unbind();
			
			$('div#homefeatbrandsdw').hide();
			$('div#homefeatbrandsdw').css('right','0px');

			$('div#rightmenu').animate({width: '-='+slideWidth+'px'}, "slow");
			$('#brandbuttoncont').css("padding-left","0px");
			
			$('a.brandshopslink').attr("href","#view-all");
			$('a.brandshopslink > span').html("view more");
			$('div#homefeatbrandcover').fadeTo("fast","0",function(){$('div#homefeatbrandcover').hide();});
			
			$('a.brandshopslink').click(function(e){
				e.preventDefault();
				target = e?e.target:window.event?window.event.srcElement:null;
				if(target) showBrandShops('show');
			});
		}
	}
	/*
	else
	{
		//$('a.brandshopslink > span').html("");
		//$('a.brandshopslink').click(function(e){
		//	e.preventDefault();
		//});
		
		$('div.brandbuttoncont > h2').html("featured brands")
	}*/
}

function checkPageUrlFB(){

	var thisPage = location.pathname;
	checkPage = thisPage.substring(0,18);

	buildFB = true;
	if(checkPage == "/cgi-bin/psProdDet"){buildFB = false;}
	if(checkPage == "/cgi-bin/psProdSrc"){buildFB = false;}
	if(checkPage == "/index.html"){buildFB = false;}
	if(checkPage == "/"){buildFB = false;}
	if(noFB){if(noFB==true){buildFB = false;}}
	return buildFB;
}

function buildFancyBoxTags(runFunc){

	thisPage = checkPageUrlFB();
	
	if(thisPage == true){

		sTags = document.getElementsByTagName("script");
		cTag=0;
		for(i=0;i<sTags.length;i++)
		{
			thisSrc = $(sTags[i]).attr("src");

			if(thisSrc == "/js/engine.js")
			{
				cTag++;
				wTag=i;
			}

			if(thisSrc == "/js/fancybox/jquery.fancybox-1.3.1.js")
			{
				cTag++;
			}
		}

		if(cTag == 1){

			$(sTags[wTag]).after('<script type="text/javascript" src="/js/fancybox/jquery.mousewheel-3.0.2.pack.js"></script><script type="text/javascript" src="/js/fancybox/jquery.fancybox-1.3.1.js"></script>');	

			shopByBrand();
			//startSignUp();
		}
	}else{
	
		shopByBrand();
		//startSignUp();
	}
}

function startSignUp(){

	$("a#inline").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'hideOnContentClick': false,
		'autoDimensions':false,
		'width': 204,
		'height':92
	});
}


function shopByBrand(){

	//$("#shopbranddrop").append('<a href="#viewShopByBrand" id="shopbybrandlinkf" class="inline">Shop by Brand</a>');
	//$("#shopbybrandlink").after('<div id="viewShopByBrand"></div>');
	$("#shopbranddrop").after('<div id="viewShopByBrand"></div>');

	buildShopByBrand();
}

function buildShopByBrand(){

	options = $("#shopbranddrop > select > option");
	brandHeight = Math.round((options.length*19)+20);
	
	$("#viewShopByBrand").append('<a href="/All/store">View All Brands</a>');
	singleLink = $("#viewShopByBrand > a");
	
	shopbybrandlinkAl=1;
	for(i=1;i<options.length;i++)
	{
		thisVal = $(options[i]).val();
		if(thisVal != '')$("#viewShopByBrand").append('<a href="/store/'+thisVal+'">'+thisVal+'</a>');
		
		shopbybrandlinkAl++;
	}
	
	if(shopbybrandlinkAl == options.length-1 || singleLink.length == 1){	
		$("a#shopbybrandlink").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'hideOnContentClick': false,
			'autoDimensions':false,
			'width':220,
			'height':brandHeight
		});
		
		$("a#shopbybrandlinkf").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'hideOnContentClick': false,
			'autoDimensions':false,
			'width':220,
			'height':brandHeight
		});
	}
}

function startProdPhotos(){

	$("a[rel='lightbox[products]']").fancybox({
		'autoScale':false,
		'titlePosition'	: 'inside'
		});
}

function startFilterValues(){

	radios = $("#searchfilter input[type=radio]");

	for(r=0;r<radios.length;r++)
	{

		filterName = $(radios[r]).attr("name");
		filterValue = $(radios[r]).attr("value");
		filterLabel = filterName+'_'+filterValue;

		if(radios[r].checked == true){

			//if(filterName != 'noMaxPrice'){

				$("label[for='"+filterLabel+"']").css("background-image","url('/gfx/icons/sfCheckOn.gif')");

			//}else{

				//$("label[for='"+filterLabel+"']").css("background-image","");
			//}
		}
	}
}

function switchFilterValue(obj){

	filterVals = $(obj).attr("for").split("_");
	fieldName = filterVals[0];
	fieldValue = filterVals[1];

	if(fieldName == 'noMaxPrice'){

		if($("input[name=noMaxPrice]").attr("checked")){

			$(obj).css("background-image","");
			$(".maxpricefield").fadeTo(10,1);
			$(".ui-slider-range").fadeTo(10,1);
			$(".ui-slider-handle").fadeTo(10,1);
			$("input[name=noMaxPrice]").attr("checked","");

		}else{

			$(obj).css("background-image","url('/gfx/icons/sfCheckOn.gif')");
			$(".maxpricefield").fadeTo(10,0.2);
			$(".ui-slider-range").fadeTo(10,0.2);
			$(".ui-slider-handle").fadeTo(10,0.2);
			$("input[name=noMaxPrice]").attr("checked","checked");
		}

	}else{

		labelClass = $(obj).attr("class");
		$("label."+labelClass).css("background-image","");
		$(obj).css("background-image","url('/gfx/icons/sfCheckOn.gif')");
	}
}

function Toggle(strDiv)
{
	objDiv = document.getElementById(strDiv);
	
	if(objDiv.style.display == 'none')
	{
		objDiv.style.display = 'inline';
	}
	else
	{
		objDiv.style.display = 'none';
	}
}


function isLoggedIn()
{	
	if(document.cookie)
	{
		arrCookie  = document.cookie.split(";");
		arrCookie2 = new Array();
		for(i in arrCookie)
		{
			//var strKey = 
			arrCookie2[arrCookie[i].split("=")[0].replace(/ /g,"")]=arrCookie[i].split("=")[1];
		}
	}
	if(arrCookie2['Customer'])
	{
		return true;
	}
	return false;
}


function checkValidForm(formobj){

	formname = formobj.getAttribute('name');
	reqFields = new Array();
	showErrorMssg = false;
	showErrorStyle = false;

	if(formname == 'newsletter'){

		reqFields[0] = 'name';
		reqFields[1] = 'email';
		showErrorMssg = false;
		showErrorStyle = true;
	}
	
	
	if(reqFields.length > 0)
	{
		chkDetails = new Array();
		chkDetails['num'] = 0;
		chkDetails['mssg'] = 'Please fill in all required fields.<br /><br />';
		var efilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i


		for(i=0;i<reqFields.length;i++)
		{
			fieldname = reqFields[i];
			fieldlabel = reqFields[i].replace(/-/g," ");

			if(fieldname == "email")
			{
				tcfemail = document.forms[formname].elements[fieldname].value;
				if(efilter.test(tcfemail))
				{
					chkDetails['num'] = chkDetails['num']+1;
					if(showErrorStyle == true)document.forms[formname].elements[fieldname].style.border = "";
				}
				else
				{
					chkDetails['mssg'] += "- Please enter a valid Email Address\<br />";
					if(showErrorStyle == true)document.forms[formname].elements[fieldname].style.border = "1px solid red";
				}
			}
			else if(fieldname == "phone" || fieldname == "budget")
			{
				tcfphone = document.forms[formname].elements[fieldname].value; cfphone = tcfphone.replace(/ /gi,"");
				if(isNaN(cfphone) || cfphone == "")
				{
					chkDetails['mssg'] += "- Please enter a valid Number<br />";
					if(showErrorStyle == true)document.forms[formname].elements[fieldname].style.border = "1px solid red";
				}
				else
				{
					chkDetails['num'] = chkDetails['num']+1;
					if(showErrorStyle == true)document.forms[formname].elements[fieldname].style.border = "";
				}

			}
			else
			{
				if(document.forms[formname].elements[fieldname].length > 1)
				{
					var gSv;
					for (var g=0; g < document.forms[formname].elements[fieldname].length; g++)
					{
						if (document.forms[formname].elements[fieldname][g].checked)
						{
							chkDetails['num'] = chkDetails['num']+1;
							gSv = "1";
							if(showErrorStyle == true)document.forms[formname].elements[fieldname].style.border = "";
						}
					}

					if(gSv != "1")
					{
						fieldlabelU = fieldlabel.charAt(0).toUpperCase() + fieldlabel.slice(1);
						chkDetails['mssg'] += "- "+fieldlabelU+"<br />";
						if(showErrorStyle == true)document.forms[formname].elements[fieldname].style.border = "1px solid red";
					}
				}
				else
				{
					tcfthisfield = document.forms[formname].elements[fieldname].value; cfthisfield = tcfthisfield.replace(/ /gi,"");
					
					if(fieldname == 'name' && cfthisfield == 'Name')cfthisfield='';

					if(cfthisfield != "")
					{
						chkDetails['num'] = chkDetails['num']+1;
						if(showErrorStyle == true)document.forms[formname].elements[fieldname].style.border = "";
					}
					else
					{
						fieldlabelU = fieldlabel.charAt(0).toUpperCase() + fieldlabel.slice(1);
						chkDetails['mssg'] += "- "+fieldlabelU+"<br />";
						if(showErrorStyle == true)document.forms[formname].elements[fieldname].style.border = "1px solid red";
					}
				}
			}

		}

		if(chkDetails['num'] == reqFields.length)
		{
			return true;
		}
		else
		{

			if(showErrorMssg == true){
				
				if (self.pageYOffset)
				{
					var scrolling = self.pageYOffset;
				}
				else
				{
					var scrolling = document.documentElement.scrollTop;
				}

				var errPos = scrolling+130;
				errorid = "cterrorpop";

				if(!document.getElementById(errorid))
				{
					var errBody = document.getElementsByTagName("body")[0];
					var errDiv = document.createElement("div");
					errBody.appendChild(errDiv);
					errDiv.setAttribute("id", errorid);
				}

				chkDetails['mssg'] += '<span id="errConf" onclick="hideErr()">OK</div>';

				document.getElementById(errorid).innerHTML = chkDetails['mssg'];

				document.getElementById(errorid).style.opacity = "0";
				document.getElementById(errorid).style.filter = "alpha(opacity=0)";

				document.getElementById(errorid).style.display = "block";

				errDivMarginV = document.getElementById(errorid).offsetHeight;
				errDivMargin = Math.round(errDivMarginV/2);
				document.getElementById(errorid).style.marginTop = "-"+errDivMargin+"px";

				document.getElementById(errorid).style.opacity = "1";
				document.getElementById(errorid).style.filter = "alpha(opacity=100)";
			}
			

			if(formname == 'newsletter'){
				alert('Please enter your name and email address');
			}


			return false;
		}
	}
}


function ToggleNickName(SaveDetails)
{
	if(SaveDetails == 'No')
	{
		HideBlock('saveNewCardName');
	}
	else
	{
		ShowBlock('saveNewCardName');
	}
}


function HideBlock(strElement)
{
	ToggleStyleHideOption2(strElement, '', 'none');
}



function ShowBlock(strElement)
{
	if(navigator.userAgent.indexOf('Opera') != -1 || navigator.userAgent.indexOf('Firefox') != -1)
	{
		strShow = 'table-row';
	}
	else
	{
		strShow = 'block';
	}
	ToggleStyleHideOption2(strElement, '', strShow);
}


/*
        This function is very similar to the ToggleStyleHide function except that it is supposed to be attached to a radio group

        On being called it hides all elements who are prefixed with strElement, but enables those whose name are prefixed with strElement.strSuffix
*/
function ToggleStyleHideOption2(strElement, strSuffix, strSet)
{

	var arrRow = document.getElementsByTagName('tr');

	var strEnable  = strElement + strSuffix;

	for(var intLoop=0; intLoop < arrRow.length; intLoop++)
	{
		var objRow = arrRow.item(intLoop);
		var strID  = objRow.getAttribute('id');
		if(strID)
		{
			if(strID.substring(0, strElement.length) == strElement)
			{
				document.getElementById(strID).style.display = strSet;
			}
		}
	}
}



function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      eval(func);
    }
  }
}


function Checkout()
{
	if(!isLoggedIn() && (document.forms['basket'].user_email.value == '' || document.forms['basket'].user_password.value == ''))
	{
		alert("Please either register as a customer, login, or enter your registered email address and password in order to proceed to the checkout");
		return false;
	}
	
	document.forms['basket'].action='/checkout';
	document.forms['basket'].submit();
	return true;
	
}



//FaceBook Invalid APP ID Text Removal
function checkFaceBookErrTxt(){

	if(document.getElementById("fb-root")){

		divChild = document.getElementById("fb-root").getElementsByTagName("div");
		if(divChild.length>0){

			document.getElementById("fb-root").getElementsByTagName("div")[0].style.left = "-10000px";
		}
	}
}
