function showBanner()
{
theBanner = document.getElementById("Banner")
if (theBanner != null)
	{
	theBanner.style.display = "inline";
	}
}

function hideBanner()
{
theBanner = document.getElementById("Banner")
if (theBanner != null)
	{
	theBanner.style.display = "none";
	}
}
	

function showButtons()
{
	thebackbutton = document.getElementById("backButton")
	thelrbuttons_left = document.getElementById("lrbuttons_left")
	thelrbuttons_right = document.getElementById("lrbuttons_right")
	if(browser.isMac && browser.isIE)
		{
			thebackbutton.style.display = "none";
		}
	else
		{
		thebackbutton.style.display = "none";
		}
	thelrbuttons_left.style.display = "inline";
	thelrbuttons_right.style.display = "inline";
}

function hideButtons()
{
	thebackbutton = document.getElementById("backButton")
	thelrbuttons_left = document.getElementById("lrbuttons_left")
	thelrbuttons_right = document.getElementById("lrbuttons_right")
	thebackbutton.style.display = "none";
	thelrbuttons_left.style.display = "none";
	thelrbuttons_right.style.display = "none";
}

function hideIframe()
	{
	if (browser.isIE)
		{
		document.all.datamain.style.display = "none" //remove iframe
		//note.. IE mac doesnt pick this up on history backs!
		}
	else
		{
		datamain.style.display = "none"
		}
	}

function showIframe() //hide 3 sub-frames for ie mac
{
	if (browser.isIE)
		{
		document.all.datamain.style.display = "inline"
		if (document.all.otherUseIF) //if subframes
			{
			document.all.otherUseIF.style.display = "none"
			document.all.finishIF.style.display = "none"
			document.all.colourIF.style.display = "none"
			}
		}
	else
		{
		datamain.style.display = "inline"
		}
}

function goBack()
	{
	
	if(browser.isMac && browser.isIE)
		{
		return;  //IE mac cant handle anything
		}
	
	datamain = document.getElementById("datamain")

	if(oldLinkID != undefined)
		{
		if (oldLinkID != "" )
				{
				theOldPanel = document.getElementById(oldLinkID)
				theOldPanel.style.display="none";
				}			
		}
	if ((datamain != undefined) && (datamain != null))
		{
		//"the frame exists so.. check src."
		
		var myLoc
		var myObjRef
		if (browser.isSafari)
			{
			history.go(-1)
			return;
			}
		if (browser.isGecko)
			{
			myLoc = this.location.href
			myObjRef = datamain.contentWindow.history
			}
		if (browser.isIE)
			{
			myLoc = this.location.href
			myObjRef = datamain.window.history
			}
			
		resetlastCat()
		myObjRef.back()
		}
	}

function changeCatColour(imgID)
	{
		if(browser.isMac && browser.isIE)
			{
			return;
			}
		if(typeof(imgID) == "undefined" || imgID == null) //
			{
			return;
			}
		theImage = document.getElementById(imgID)
		theImage.src = "images/" + imgID + "_on.gif"
	}

function resetlastCat()
	{
		if(browser.isMac && browser.isIE)
			{
			return;
			}
		if( typeof(lastImgID) != "undefined" && lastImgID != null) // 
			{
			theImage = document.getElementById(lastImgID)
			theImage.src = "images/" + lastImgID + "_off.gif"
			}
	}

var lastImgID			
var shifted = false;
var oldLinkID = ""

function goURL(url, imgID, buttons)
	{
	if(browser.isMac && browser.isIE)
		{
		//should just work with IE Mac.
		}
	else
		{
		datamain = document.getElementById("datamain")
		if(typeof(oldLinkID) != "undefined")
			{
			if (oldLinkID != "" )
				{
				theOldPanel = document.getElementById(oldLinkID)
				theOldPanel.style.display="none";
				}
			}
		}	
	
	if (browser.isGecko || browser.isSafari)
		{
		var productDisplay
		productDisplay = document.getElementById("productDisplay")
		if (productDisplay != undefined && productDisplay != null)
			{
			productDisplay.style.display="none";
			}
		}
	
	if (browser.isIE)
		{
		document.all.datamain.style.display = "inline" //IE needs to be told explicity this to access styles on IFrames.
		}
	else	//might need to edit for other browsers
		{
		datamain.style.display = "inline"
		}
	// ENABLE /DISABLE COLOURED BUTTONS ON CATNAV
	resetlastCat()
	if (imgID != null || imgID != 0)
		{
		changeCatColour(imgID)
		}		
	lastImgID = imgID
	
	// SHOW / HIDE IF SCROLL / BACK BUTTON
	thebackbutton = document.getElementById("backButton")
	thelrbuttons_left = document.getElementById("lrbuttons_left")
	thelrbuttons_right = document.getElementById("lrbuttons_right")
	
	if (buttons == 1)
		{
			thelrbuttons_left.style.display = "inline";
			thelrbuttons_right.style.display = "inline";
			if (browser.isMac && browser.isIE && !shifted)
				{
				thelrbuttons_left.style.top = 48 //thelrbuttons.style.top - 20
				thelrbuttons_left.style.left = 580
				thelrbuttons_right.style.top = 48 //thelrbuttons.style.top - 20
				thelrbuttons_right.style.left = 580
				shifted = true
				thebackbutton.style.display = "none"; //IE mac cant handle history backs.
				}
			else
				{
				thebackbutton.style.display = "none";
				}
		}
	else
		{
			thebackbutton.style.display = "none";
			thelrbuttons_left.style.display = "none";
			thelrbuttons_right.style.display = "none";
		}
		// FINALLY RELOCATE
	
	if (browser.isIE)
		{
		datamain.location = url;
		}
		else
		{
		datamain.src = url ;
		}
	}


function scrQuickSmall(way)
	{
	if (way == "right")
		{
		op = ""
		}
	else
		{
		op = "-"
		}

	var milliseconds = 50
	var arrSpeed = new Array()
	var sum=0;

	arrSpeed[0] = 1
	arrSpeed[1] = 2
	arrSpeed[2] = 6
	arrSpeed[3] = 14
	arrSpeed[4] = 34
	arrSpeed[5] = 34
	arrSpeed[6] = 14
	arrSpeed[7] = 6
	arrSpeed[8] = 2
	arrSpeed[9] = 1

	for (i=0;i<10;i++)
		{
		sum = sum + arrSpeed[i]
		
		setTimeout("scrollSwank(" + arrSpeed[i] + ")", milliseconds)
		milliseconds = milliseconds + 50
		}
	}



function changeImage(theid, divType)
	{
	
	theid= divType + "Main" + theid
	theElem = document.getElementById(theid)
				
	theParent = theElem.parentNode 
	var childCount 
	
	if (browser.isGecko)
		{
		elemArray = theParent.childNodes
		childCount = elemArray.length
		}
	else
		{
		elemArray = theParent.children
		childCount = elemArray.length
		}
			
	for (i=0;i<childCount;i++)  //wipe out all  
		{
			if (browser.isIE && browser.isMac) //IE MAC HACK
			{
			elemArray[i].style.display ="none"
			}
			else
			{
				if (elemArray[i].id != undefined)  // mozilla returns more array elements 
				{
				elemArray[i].style.display ="none"
				}
			}
		}
	theElem.style.display = "inline";
	}


function swapToDetailTab(tabElemID)
	{
	theDetailsArea = document.getElementById("detailsArea")
	thePricingArea = document.getElementById("pricingArea")
	theCollectionArea = document.getElementById("collectionArea")

	scr1 = document.getElementById("divScroll1")
	ctr1 = document.getElementById("divControl1")

	scr2 = document.getElementById("divScroll2")
	ctr2 = document.getElementById("divControl2")

	scr3 = document.getElementById("divScroll3")
	ctr3 = document.getElementById("divControl3")

	theDetailsArea.style.visibility="hidden"
	scr1.style.visibility="hidden"
	ctr1.style.visibility="hidden"
	
	thePricingArea.style.visibility="hidden"
	scr2.style.visibility="hidden"
	ctr2.style.visibility="hidden"
	
	theCollectionArea.style.visibility="hidden"
	scr3.style.visibility="hidden"
	ctr3.style.visibility="hidden"
	
	switch(tabElemID)
		{
		case "pricingArea":
			{
			identifier = "2"
			break;
			}
		case "collectionArea":
			{
			identifier = "3"
			break;
			}
		default:
			{
			identifier = "1"
			}
		}

	showTab = document.getElementById(tabElemID)
	showTab.style.visibility="visible"
	
	myScrObj = document.getElementById("divScroll" + identifier)
	myScrObj.style.visibility="visible"
	myCtlObj = document.getElementById("divControl" + identifier)
	myCtlObj.style.visibility="visible"
	}
	
function swapToGalleryTab(tabElemID)
	{
	theColourArea = document.getElementById("colourArea")
	theFinishArea = document.getElementById("finishArea")
	theUsesArea = document.getElementById("usesArea")

	theColourArea.style.display="none"
	theFinishArea.style.display="none"
	theUsesArea.style.display="none"

	showTab = document.getElementById(tabElemID)
	showTab.style.display="inline"
	}

function swapImage(el,mouseEvent)
	{
		var filename = el.src ;
		if (mouseEvent == 'onmouseover') filename = filename.replace("_off","_over");
		else{filename= filename.replace("_over","_off");
	}
		el.src = filename;
	}

function goRight()
{
	if (browser.isGecko)
		{
		datamain = document.getElementById("datamain")
		datamain = datamain.contentWindow
		}	
	datamain.scrQuick("right")
}

function goRightFirst()
{
	if (browser.isGecko)
		{
		datamain = document.getElementById("datamain")
		datamain = datamain.contentWindow
		}	
	datamain.scrQuickFirst("right")
}

function goLeft()
{
	if (browser.isGecko)
	{
		datamain = document.getElementById("datamain")
		datamain = datamain.contentWindow
	}
	datamain.scrQuick("left")
}

function slideRight()
	{
	if (browser.isSafari) 
		{ //use old method because safari suffers the 'smear' effect at least on G4 powerbooks
		goRight()
		return;
		}
	if (browser.isGecko)
		{
		datamain = document.getElementById("datamain")
		datamain = datamain.contentWindow
		}	
	datamain.slide("")
	}

function slideLeft()
	{
	if (browser.isSafari)
		{
		goLeft()
		return;
		}
	if (browser.isGecko)
		{
		datamain = document.getElementById("datamain")
		datamain = datamain.contentWindow
		}
	datamain.slide("-")
	}


var isBasket = false;

var theSlideTimer 

function slide(op)
{
	var way
	var distance = 5
	var milliseconds = 50
	var strComeAgain
	
	if (op == undefined)
		{
		op = ""
		}
	
	way = op + distance		
	way = parseFloat(way)
	window.scrollBy(way,0)
	
	strComeAgain = "slide('" + op + "')"
	theSlideTimer = setTimeout(strComeAgain, milliseconds)
}


function stopSlide()
{

if (browser.isGecko)
	{
	datamain = document.getElementById("datamain")
	datamain = datamain.contentWindow
	}
	datamain.stopSlideInternal()
}

function stopSlideInternal()
	{
	clearTimeout(theSlideTimer)
	}

function scrQuick(way)
{
	if (way == "right")
		{
		op = ""
		}
	else
		{
		op = "-"
		}

	var milliseconds = 50
	var arrSpeed = new Array()
	var arrVert = new Array()
	var sum=0;
	var sum2=0;

	arrSpeed[0] = 0
	arrSpeed[1] = 1
	arrSpeed[2] = 2
	arrSpeed[3] = 3
	arrSpeed[4] = 7
	arrSpeed[5] = 10
	arrSpeed[6] = 20
	arrSpeed[7] = 42
	arrSpeed[8] = 42
	arrSpeed[9] = 20
	arrSpeed[10] = 10
	arrSpeed[11] = 7
	arrSpeed[12] = 3
	arrSpeed[13] = 2
	arrSpeed[14] = 1
	arrSpeed[15] = 0

	for (i=0;i<16;i++)
	{
	sum = sum + arrSpeed[i]
	sum2 = sum2 + arrVert[i]

	myLoc = window.location.href
	isBasket = (myLoc.indexOf("asket") > 0)
		if (isBasket)
			{
			setTimeout("scrollSwank(" + arrVert[i] + ")", milliseconds)
			//alert()
			}
		else
			{
			setTimeout("scrollSwank(" + arrSpeed[i] + ")", milliseconds)
			}		
	milliseconds = milliseconds + 50
	
	if(browser.isSafari)
		{
		parent.hideButtons()
		setTimeout("parent.showButtons()", 800)
		}
	}
	//Exit Loop
}

function scrQuickFirst(way)
{
	if (way == "right")
		{
		op = ""
		}
	else
		{
		op = "-"
		}

	var milliseconds = 50
	var arrSpeed = new Array()
	var arrVert = new Array()
	var sum=0;
	var sum2=0;

	arrSpeed[0] = 340

	for (i=0;i<16;i++)
	{
	sum = sum + arrSpeed[i]
	sum2 = sum2 + arrVert[i]

	myLoc = window.location.href
	isBasket = (myLoc.indexOf("asket") > 0)
		if (isBasket)
			{
			setTimeout("scrollSwank(" + arrVert[i] + ")", milliseconds)
			//alert()
			}
		else
			{
			setTimeout("scrollSwank(" + arrSpeed[i] + ")", milliseconds)
			}		
	milliseconds = milliseconds + 50
	
	if(browser.isSafari)
		{
		parent.hideButtons()
		setTimeout("parent.showButtons()", 800)
		}
	}
	//Exit Loop
}

function scrollSwank(ammount)
{
if (op == "-")
	{
	neg = "-" + ammount
	if (isBasket)
		{
		window.scrollBy(0,parseFloat(neg))
		}
	else
		{
		window.scrollBy(parseFloat(neg),0)
		}
	}
else
	{
	if (isBasket)
		{
		window.scrollBy(0,ammount)	
		}
	else
		{
		window.scrollBy(ammount,0)	
		}
	}
}



function bookmarkUs(oLink){
	oLink.style.behavior='url(#default#homepage)';
	oLink.setHomePage(document.location);
	return false;
}


function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


function dropCookies()
{

var now = new Date();
var then = new Date();
fixDate(now);
then.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //Add 1 year
favPage = window.location
setCookie("mfPage", favPage, then)  //set the page cookski
setCookie("mfActivity", now.getTime(), then)
}


function checkCookies()
{
var timeAgo = getCookie("mfActivity")
var now = new Date();
var then = new Date();
fixDate(now);
then.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //Add 1 year

twentyMins = 1200000
difference = now.getTime() - timeAgo

if ((timeAgo == null) || (timeAgo == undefined)) // no homepage set
	{
	return;  // no redirect nec.
	}

if (difference > twentyMins) // if twenty mins has expired
	{
	setCookie("mfActivity", now.getTime(), then)
	window.location = getCookie("mfPage")	
	}	
else
	{
	setCookie("mfActivity", now.getTime(), then)
	}	
}

function spawnSTFWindow(URL)
{
	var URL = document.location;
	var sFeatures = "directories=no,height=320px,width=420px,location=no,menubar=no,resizable=no,status=no,toobar=no"
	window.open("sendtoafriendPanel.asp?url=" + document.location, "sendToFriend", sFeatures)
}


function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}

// values are URL, Name of popup (can be anything), width, height, scrollbars? 1 = yes, 0 = no, resizable? 1 = yes, 0 = no)
function popup(URL,PageName,w,h,scrollable,resizable){
	if (URL == "") return false;
	if (PageName == "") PageName = "popup window";
	w = 300;
	h = 300;
	scrollable = 1;
	resizable = 1;
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = ("height="+h+",width="+w+",top="+TopPosition+",left="+LeftPosition+",scrollbars="+scrollable+",resizable="+resizable);
	myWindow = window.open(URL,PageName,settings);
	myWindow.window.focus();
}

function popUp(pPage)  
{
	popupwin = window.open(pPage,'Reserve','resizable=no,scrollbars=yes,width=360,height=500');
}

function popLarge(pPage)  
{
	popupwin = window.open(pPage,'bigWin','resizable=yes,scrollbars=yes,width=800,height=600');
}

function popupMe(desID){
	PageName=""
	URL = "displayDesigner.asp?DesignerID=" + desID
	if (PageName == "") PageName = "popup window";
	w = 500;
	h = 500;
	scrollable = 1;
	resizable = 1;
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = ("height="+h+",width="+w+",top="+TopPosition+",left="+LeftPosition+",scrollbars="+scrollable+",resizable="+resizable);
	myWindow2 = window.open(URL,"",settings);
	myWindow2.window.focus();
}

function isValidEmail(emailAddress) 
{
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return re.test(emailAddress);
}
