// Functions to generate random guest quotes.  Quotes should be in numbered pairs in each sepertae function to work correctly		
		
var quoteno;

function randomQuoteText() {
	
var quoteText = new Array ();
quoteText[0] = "It was faultless, and if you see our other reviews we are staying at very high end 5* resorts in the world and very fussy.";
quoteText[1] = "The drawing room and the huge open fire was beautiful and we all felt rested and relaxed after our stay.";
quoteText[2] = "I'm speechless.  Comfortable wonderful hospitality, pure luxury.  Enjoyed beyond words.";
quoteText[3] = "Once again, a wonderful stay.  Cannot praise this place or wonderful hosts highly enough!";
quoteText[4] = "A very special & magical hotel. Our compliments to you both for making our stay perfect. See you next birthday.";
quoteText[5] = "Spotlessly clean, beautiful surroundings, lovely interior, comfortable room, excellent service, great food, fantastic!";
quoteText[6] = "Plas Dinas is gorgeous! Such a pleasant visit..";
quoteText[7] = "It's a must for any traveller that likes a little luxury !!";
quoteText[8] = "Everything was perfect from our warm welcome on arrival to our delicious last breakfast there.";
quoteText[9] = "The elegant yet cosy drawing room was the perfect place to relax with a cup of tea, and the best chocolate brownies in the world.";
quoteText[10] = "Amazing hospitality in a beautiful setting with a touch of luxury.";
quoteText[11] = "A warm welcome from hosts who go that extra mile to make your trip a memorable one.";
quoteText[12] = "Such care and attention to detail in everything they do.";
quoteText[13] = "The property grounds are beautiful and it's really nice to walk outside in the morning or the evening.";
quoteText[14] = "We have toured many stately homes, but this is the first time that we have actually stayed in one! ";
quoteText[15] = "Beautiful grounds, peace and quiet, plenty of parking space";
quoteText[16] = "Attention to the smallest of details is key here.";
quoteText[17] = "What a magical and special place Plas Dinas is and what wonderfully talented hosts!";
quoteText[18] = "The drawing room is large and extremely comfortable with a roaring log fire, so comfortable and relaxed, I took my shoes off and put my feet up!";
quoteText[19] = "Andy and Julian are excellent hosts.";
quoteText[20] = "This was a birthday surprise and though we only stayed the one night, our hosts Julian and Andy made this a treasured memory for us both.";
quoteText[21] = "What wonderfully talented hosts! so thank you Julian & Andy.. see you next Birthday!";
quoteText[22] = "Our hosts were perfect - Andy and Julian manage the daily affairs and guests' needs with seamless precision...";
quoteText[23] = "Andy and Julian work so hard to keep this hotel in top class condition which is amazing bearing in mind there is just the two of them.";
quoteText[24] = "Very kind of them to allow our little dog as well and thoughtful to leave a welcome pack for him which included doggy poop bags and biscuits!";
quoteText[25] = "Even our border collie had a present of dog treats waiting for her in our room.";
quoteText[26] = "Sammi wants to thank Andy & Julian for the extra rashes of bacon (woof).";


quoteno = Math.floor(27*Math.random())

 document.write('"' + quoteText[quoteno] + '"');

}

function randomQuoteSource() {
	
var quoteSource = new Array ();
quoteSource[0] = "Svante Bergstrom, Stockholm";
quoteSource[1] = "Eugenie Brooks, Bagshot";
quoteSource[2] = "Angie Salisbury, Wrexham";
quoteSource[3] = "Brigid & Jennifer Bowen, Cardiff";
quoteSource[4] = "Karin & Pete Evans, Midlands";
quoteSource[5] = "Jon & Tina, Cheshire";
quoteSource[6] = "Carolyn Blackburn, Phoenix Arizona";
quoteSource[7] = "Svante Bergstrom, Stockholm";
quoteSource[8] = "Maxine Sutton, Nottingham";
quoteSource[9] = "Maxine Sutton, Nottingham";
quoteSource[10] = "Becky Supria, Worcester";
quoteSource[11] = "Briged Bowen, Cardiff";
quoteSource[12] = "Briged Bowen, Cardiff";
quoteSource[13] = "Cristina Sanchez, Sheffield";
quoteSource[14] = "Jan and Dick Mitchell, Bristol ";
quoteSource[15] = "Jan and Dick Mitchell, Bristol ";
quoteSource[16] = "Karin & Pete Evans, Stafford ";
quoteSource[17] = "Karin & Pete Evans, Stafford";
quoteSource[18] = "Tim Haselwood, Macclesfield";
quoteSource[19] = "Mr & Mrs Hartwell, Manchester";
quoteSource[20] = "Karin & Pete Evans, Stafford ";
quoteSource[21] = "Karin & Pete Evans, Stafford ";
quoteSource[22] = "Ray Simmons, Trip Advisor";
quoteSource[23] = "Tim Haselwood, Macclesfield";
quoteSource[24] = "Karen Williams, Peterborough";
quoteSource[25] = "Karin & Pete Evans, Stafford";
quoteSource[26] = "Philip & Dominique Gee, Hyde";


 document.write('<p style="font:0.8em Arial,Helvetica,sans-serif; text-align: right; color:#ABB6BA;">' + quoteSource[quoteno]);

}

// Weddings Page Quotes

function randomQuoteTextWeddings() {
	
var quoteText = new Array ();
quoteText[0] = "Thank you both so very much for making our wedding day in Plas Dinas so special";
quoteText[1] = "Everything was just perfect, and Plas Dinas was a beautiful setting";
quoteText[2] = "We had a fantastic time, as did all of our guests.  You both obviously worked very hard for us so we're very grateful";
quoteText[3] = "Your organisational skills, excellent food & service, were faultless";
quoteText[4] = "The wedding went magnificently and your attention to detail was second to none";
quoteText[5] = "I could not have wished for a better wedding weekend - in fact it exceeded our expectations";
quoteText[6] = "Thank you for making our special day so memorable.  It was such a beautiful place for our civil ceremony and our guests are still talking about it";
quoteText[7] = "Thank you for making it possible for Ali & Les to have a magical wedding.  We will all treasure the memories forever";
quoteText[8] = "Your hard work and hospitality ensured it was the wedding of our dreams!";
quoteText[9] = "It is a stunning location, grounds were perfect for lots of fabulous photos.";
quoteText[10] = "It was the perfect location for a wedding and the whole weekend was everything our daughter and son in law wanted it to be. ";
quoteText[11] = "You were top class!";
quoteText[12] = "It was exactly as we hoped it would be - relaxed and seamless.";

quoteno = Math.floor(13*Math.random())

 document.write('"' + quoteText[quoteno] + '"');

}

function randomQuoteSourceWeddings() {
	
var quoteSource = new Array ();
quoteSource[0] = "Andrea & Steve";
quoteSource[1] = "Sarah & Sophie";
quoteSource[2] = "Patrick & Charlotte";
quoteSource[3] = "Alan & John";
quoteSource[4] = "Sheila & Dave";
quoteSource[5] = "James & Luke";
quoteSource[6] = "Gwilym & Stuart";
quoteSource[7] = "Tam & Mary";
quoteSource[8] = "The Connors Clan!";
quoteSource[9] = "Mr & Mrs Hartwell, Manchester";
quoteSource[10] = "Mr & Mrs Hartwell, Manchester";
quoteSource[11] = "Alan & Joyce ";
quoteSource[12] = "Andy & Mark";


 document.write('<p style="font:0.8em Arial,Helvetica,sans-serif;text-align:right;color:#ABB6BA;">' + quoteSource[quoteno]);
}


// Cottages Page Quotes

function randomQuoteTextCottages() {
	
var quoteText = new Array ();
quoteText[0] = "A truly fantastic stay!  The Lodge was everything we had hoped it would be.  The open fires were a particular favourite...";
quoteText[1] = "Lovely Lodge, great place to be at Christmas.  Had a lovely relaxing week.";
quoteText[2] = "Beautiful, well equipped lodge.  A real find.  We too will be back.";
quoteText[3] = "Another visit at the lodge so you are definitely doing something right!  Still there is plenty to see and do as the area is so fantastic!";
quoteText[4] = "Great centre for exploring North Wales.";
quoteText[5] = "Great lodge - everything seems to be thought of! ";
quoteText[6] = "Lovely!  We think that you would have to go a very long way to find better.";
quoteText[7] = "Fantastic!  Very clean, well equipped.  Simply a home from home.  We want to come again.";
quoteText[8] = "An enjoyable week!  Great weather, comfortable house and nearness to many tourist attractions all added to our memories.  Thanks!!";
quoteText[9] = "Excellent accommodation, lots to do in area.  Plas Newydd - spectacular, ditto castles, mini railway to Beddgellert good fun too.";
quoteText[10] = "Lovely house, was great to come back to after long days out!";
quoteText[11] = "This house is awesome, had a fantastic time and will be back for more.  Thanks very much.x";

quoteno = Math.floor(12*Math.random())

 document.write('"' + quoteText[quoteno] + '"');

}

function randomQuoteSourceCottages() {
	
var quoteSource = new Array ();
quoteSource[0] = "Lewis & Su, Edinburgh";
quoteSource[1] = "Spike, Rozz & kids, Cheshire";
quoteSource[2] = "Sandra & Marilyn, Barnet";
quoteSource[3] = "Dave, Alison, Isabella & Oscar, Leicester";
quoteSource[4] = "Andy & Ruth Webb, Pembrokeshire";
quoteSource[5] = "Anne-Helene, Ronald & Emile, The Netherlands";
quoteSource[6] = "Pat & Pete, Derby";
quoteSource[7] = "Ivan, Donald & Raymundo, Cambridge";
quoteSource[8] = "Davies family, Cardiff";
quoteSource[9] = "Andrew, Carole, Michael & Alex, Hitchin";
quoteSource[10] = "Debs & Adam, London";
quoteSource[11] = "Sam, Nev & Carl, Wrexham";


 document.write('<p style="font:0.8em Arial,Helvetica,sans-serif;text-align:right;color:#ABB6BA;">' + quoteSource[quoteno]);

}


// Location Page Quotes

function randomQuoteTextLocation() {
	
var quoteText = new Array ();
quoteText[0] = "Location is brilliant and there are many places to visit not far from the hotel.";
quoteText[1] = "A good location for touring Snowdonia.";
quoteText[2] = "After dinner, we watched the most glorious sunset as we sipped champagne and drank our coffee overlooking the Menai Straights.";
quoteText[3] = "The views from the property (both inside and out) are lovely, and the grounds are very pretty, especially up on The Mount.";
quoteText[4] = "...very privately situated, located out in the country but close enough to the town of Caernarfon and makes a good base from which to explore...";
quoteText[5] = "The country house is very special, and is located in the perfect, quiet setting - set in many quiet acres with spectacular views...";
quoteText[6] = "The location could not be improved upon if you were searching for that special, peaceful or romantic break...";
quoteText[7] = "We visited the Sygun copper mines, Welsh Zoo, Llandudno, Colwyn Bay, Portmeirion, Caernarfon Castle...all within 20-30 minutes of Plas Dinas.";

quoteno = Math.floor(8*Math.random())

 document.write('"' + quoteText[quoteno] + '"');

}

function randomQuoteSourceLocation() {
	
var quoteSource = new Array ();
quoteSource[0] = "Cristina Sanchez, Sheffield";
quoteSource[1] = "Jan and Dick Mitchell, Bristol ";
quoteSource[2] = "Karin & Pete Evans, Stafford";
quoteSource[3] = "Nicholas Hunter, Manchester";
quoteSource[4] = "Nicholas Hunter, Manchester";
quoteSource[5] = "Ray Simmons, Trip Advisor";
quoteSource[6] = "Ray Simmons, Trip Advisor";
quoteSource[7] = "Ray Simmons, Trip Advisor";

 document.write('<p style="font:0.8em Arial,Helvetica,sans-serif;text-align:right;color:#ABB6BA;">' + quoteSource[quoteno]);

}


// Rooms Page Quotes

function randomQuoteTextRooms() {
	
var quoteText = new Array ();
quoteText[0] = "In all the hotel is a fantastic place to stay with glorious views from each window.";
quoteText[1] = "Our beautiful bedroom had a big comfy bed with a billowing white duvet and plump pillows.";
quoteText[2] = "The shower room was equipped with plentiful fluffy white towels and divine Molton Brown toiletries which were restocked when needed.";
quoteText[3] = "Our room 'The Princess Margaret Suite' was stunning. The attention to detail was brilliant and I loved the little luxurious touches. ";
quoteText[4] = "The bed was too comfortable and the bathroom with the plasma TV is a great added extra. ";
quoteText[5] = "After being taken to our Lady Armstrong suite we were even more impressed! The room was immaculate and stunningly decorated.";
quoteText[6] = "...beautifully decorated and furnished - really comfortable and lovely touches...including the chocolates, fresh fruit and flowers...";
quoteText[7] = "We stayed at the Lady Armstrong-Jones room which is fantastic.";
quoteText[8] = "Very comfortable bed in Lady Armstrong room. It's a great place to stay with lots of interesting memorabilia and period decor.";
quoteText[9] = "The rooms were well furnished and beds sumptuously comfortable. We stayed in the 'South' room which was very spacious and comfortable.";
quoteText[10] = "One of the best nights sleep ever comfortable bed and very peaceful.";
quoteText[11] = "We stayed in the Princess Margaret suite, a large, comfortable room with a four-poster bed and a superb modern bathroom.";
quoteText[12] = "The flatscreen TV on the wall next to the freestanding bathtub is pure, indulgent decadence...";
quoteText[13] = "We resided in the Lady Armstrong Suite and it was lush.";
quoteText[14] = "We stayed in 'South' which was a very large, comfortable room with a super king bed with the added touch of fresh milk...for us tea drinkers.";


quoteno = Math.floor(15*Math.random())

 document.write('"' + quoteText[quoteno] + '"');

}

function randomQuoteSourceRooms() {
	
var quoteSource = new Array ();
quoteSource[0] = "Eugenie Brooks, Bagshot";
quoteSource[1] = "Maxine Sutton, Nottingham";
quoteSource[2] = "Maxine Sutton, Nottingham";
quoteSource[3] = "Becky Supria, Worcester";
quoteSource[4] = "Becky Supria, Worcester";
quoteSource[5] = "Mark Williams, Luton";
quoteSource[6] = "Karen Williams, Peterborough";
quoteSource[7] = "Cristina Sanchez, Sheffield";
quoteSource[8] = "Mr & Mrs Hartwell, Manchester";
quoteSource[9] = "Mrs Sapphire, Manchester";
quoteSource[10] = "Benjamin Williams, Lydney";
quoteSource[11] = "Nicholas Hunter, Manchester";
quoteSource[12] = "Nicholas Hunter, Manchester";
quoteSource[13] = "Philip & Dominique Gee, Hyde";
quoteSource[14] = "Tim Haselwood, Macclesfield";

 document.write('<p style="font:0.8em Arial,Helvetica,sans-serif;text-align:right;color:#ABB6BA;">' + quoteSource[quoteno]);

}


// Food Page Quotes

function randomQuoteTextFood() {
	
var quoteText = new Array ();
quoteText[0] = "I even went to their butchers shop to purchase the same sausages they use as I enjoyed them so much.";
quoteText[1] = "The food was amazing and I recommend the full Welsh breakfast! (Best sausages I have ever tasted).";
quoteText[2] = "I ate wonderful poached eggs - best I've had for ages - and my mother was v impressed by the mini marmite.";
quoteText[3] = "Food is excellent.  A great breakfast served in a lovely dining room.";
quoteText[4] = "We breakfasted on the lightest of scrambled eggs and smoked salmon and reluctantly had to pack for our journey home.";
quoteText[5] = "The scrambled egg & smoked salmon on muffin for breakfast was divine.";
quoteText[6] = "Full Welsh cooked breakfast will set you up for the day to walk up Snowdon then back for an excellent three course meal in the evening superb...";
quoteText[7] = "The scrambled eggs and smoked salmon were particularly scrumptious.";
quoteText[8] = "Julian's breakfasts are very good, all local produce and well cooked.";
quoteText[9] = "The range of fruits and full Welsh breakfast were great! The scrambled egg & salmon was most impressive - a real winner!";
quoteText[10] = "The breakfast in the morning was delicious.";
quoteText[11] = "Julian's breakfast can't be faulted with local produce. We found that having eaten breakfast we didn't need to eat until dinner in the evening!";
quoteText[12] = "The dinner menu is fantastic and all served with the best attention to detail in both presentation and delivery.";
quoteText[13] = "We ate in the restaurant on one night of our stay and both had Anglesey pate and lamb shank which were excellent.";
quoteText[14] = "I had the Baileys Creme Brulee (well who could resist?) while my husband chose apple crumble, both excellent deserts.";
quoteText[15] = "We ate out one night but the food that Andy cooked was nicer. Considering they weren't trained chefs, they really were very good indeed.";
quoteText[16] = "The quality, standard and service of the food was excellent.";
quoteText[17] = "The Cuisine was spectacular with an 'out of this world' fish pie that was to die for.";
quoteText[18] = "Andy/Julian are fantastic chefs and the food was to die for, we loved it so much that we booked a table for our second night...";
quoteText[19] = "Andy's food is wonderful, well prepared and tasty, and the menu changes each day.";


quoteno = Math.floor(20*Math.random())

 document.write('"' + quoteText[quoteno] + '"');

}

function randomQuoteSourceFood() {
	
var quoteSource = new Array ();
quoteSource[0] = "Eugenie Brooks, Bagshot";
quoteSource[1] = "Mark Williams, Luton";
quoteSource[2] = "Briged Bowen, Cardiff";
quoteSource[3] = "Karen Williams, Peterborough";
quoteSource[4] = "Karin & Pete Evans, Stafford";
quoteSource[5] = "Mrs Sapphire, Manchester";
quoteSource[6] = "Benjamin Williams, Lydney";
quoteSource[7] = "Trip Advisor review";
quoteSource[8] = "Nicholas Hunter, Manchester";
quoteSource[9] = "Ray Simmons, Trip Advisor";
quoteSource[10] = "Chris Elkin, Talke";
quoteSource[11] = "Tim Haselwood, Macclesfield";
quoteSource[12] = "Eugenie Brooks, Bagshot";
quoteSource[13] = "Maxine Sutton, Nottingham";
quoteSource[14] = "Maxine Sutton, Nottingham";
quoteSource[15] = "Mrs Sapphire, Manchester";
quoteSource[16] = "Jean Jones, Swansea";
quoteSource[17] = "Karin & Pete Evans, Stafford";
quoteSource[18] = "Philip & Dominique Gee, Hyde";
quoteSource[19] = "Tim Haselwood, Macclesfield";


 document.write('<p style="font:0.8em Arial,Helvetica,sans-serif;text-align:right;color:#ABB6BA;">' + quoteSource[quoteno]);

}


// Validate newsletter email address in Left Col

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{

	with (thisform)
	{
	if (validate_email(fields_email,"Please enter a valid email address")==false)
  		{fields_email.focus();return false}
	}
	
}


/* 
 * Used to detect Flash or iPhone/iPad and direct user to the correct Virtual Tour page
 */

function selectTour()
{	 
      
	  if (swfobject.hasFlashPlayerVersion("9.0.0")) {
          window.location = '/tours/index.html';
                            
          } else 
             
		// check for CSS3 3D transformations and WebGL
		if (ggHasHtml5Css3D() || ggHasWebGL()) {
			    
             window.location = '/tours/itour.html';
			                            
          } else {  
		  
		    document.write('This content requires HTML5/CSS3, WebGL, or Adobe Flash Player Version 9 or higher.');
                  }
}
               



/* 
 * Cross-browser event handling - used by ClearDefaultText
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}


/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 */

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}


/*
 * Used to toggle helicopter info div between visible and hidden
 */
              
function toggle(a,id){
	var div=document.getElementById(id);
		if(div.style.display=='none'){
		div.style.display='block';
		a.innerHTML='HIDE';
		}
			else{
				div.style.display='none';
				a.innerHTML='SHOW';
				}
					}
					
//  FONT-SIZE CHANGER FUNCTIONS					
//  dw_event.js version date Oct 2009
//  basic event handling file from dyn-web.com

var dw_Event = {
  
    add: function(obj, etype, fp, cap) {
        cap = cap || false;
        if (obj.addEventListener) obj.addEventListener(etype, fp, cap);
        else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);
    }, 

    remove: function(obj, etype, fp, cap) {
        cap = cap || false;
        if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);
        else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);
    }, 
    
    DOMit: function(e) { 
        e = e? e: window.event; // e IS passed when using attachEvent though ...
        if (!e.target) e.target = e.srcElement;
        if (!e.preventDefault) e.preventDefault = function () { e.returnValue = false; return false; }
        if (!e.stopPropagation) e.stopPropagation = function () { e.cancelBubble = true; }
        return e;
    },
    
    getTarget: function(e) {
        e = dw_Event.DOMit(e); var tgt = e.target; 
        if (tgt.nodeType != 1) tgt = tgt.parentNode; // safari...
        return tgt;
    }
    
}

/*********************************************************************************
  dw_cookies.js - cookie functions for dyn-web.com
  version date: Nov 2009
**********************************************************************************/

var dw_Cookie = {

    set: function(name, value, days, path, domain, secure) {
        var date, expires;
        if (typeof days == "number") {
            date = new Date();
            date.setTime( date.getTime() + (days*24*60*60*1000) );
            expires = date.toGMTString();
        }
        document.cookie = name + "=" + encodeURI(value) +
            ((expires) ? "; expires=" + expires : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
    },
    
    get: function(name) {
        var c, cookies = document.cookie.split( /;\s/g );
        for (var i=0; cookies[i]; i++) {
            c = cookies[i];
            if ( c.indexOf(name + '=') === 0 ) {
                return decodeURI( c.slice(name.length + 1, c.length) );
            }
        }
        return null;
    },
    
    del: function(name, path, domain) {
        if ( dw_Cookie.get(name) ) {
            document.cookie = name + "=" +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    }
}

/*************************************************************************
  This code is from Dynamic Web Coding at dyn-web.com
  Copyright 2004-10 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/business/terms.php
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

/*  dw_sizerdx.js version date: April 2010
    requires dw_cookies.js (Nov 2009 version) and dw_event.js 
*/

var dw_fontSizerDX = {
    sizeUnit: "em",
    defaultSize: 0.8,
    maxSize: 1.6,
    minSize: 0.6,
    sizerDivId: 'sizer', // div id for sizer controls
    queryName: "dw_fsz", // name to check query string for when passing size in URL
    cookieLifetime: 180, // how long to keep cookie
    
    adjustList: [],  // set method populates

    setDefaults: function(unit, dflt, mn, mx, sels) {
        this.sizeUnit = unit; this.defaultSize = dflt;
        this.maxSize = mx;    this.minSize = mn;
        if (sels) this.set(dflt, mn, mx, sels);
    },

    set: function (dflt, mn, mx, sels) { 
        var ln = this.adjustList.length;        
        for (var i=0; sels[i]; i++) {
            this.adjustList[ln+i] = [];
            this.adjustList[ln+i]["sel"]  = sels[i];
            this.adjustList[ln+i]["dflt"] = dflt;
            this.adjustList[ln+i]["min"]   = mn || this.minSize;
            this.adjustList[ln+i]["max"]   = mx || this.maxSize;
            // hold ratio of this selector's default size to this.defaultSize for calcs in adjust fn 
            this.adjustList[ln+i]["ratio"] = this.adjustList[ln+i]["dflt"] / this.defaultSize;
        }
    },

    addHandlers: function () {
        var sizerEl = document.getElementById( dw_fontSizerDX.sizerDivId );
        if ( !dw_fontSizerDX.sizeIncrement ) { dw_fontSizerDX.getSizeIncrement(); }
        var links = sizerEl.getElementsByTagName('a');
        for (var i=0; links[i]; i++) {
            if ( dw_Util.hasClass( links[i], 'increase') ) {
                links[i].onclick = function () { dw_fontSizerDX.adjust( dw_fontSizerDX.sizeIncrement ); return false }
            } else if ( dw_Util.hasClass( links[i], 'decrease') ) {
                links[i].onclick = function () { dw_fontSizerDX.adjust( -dw_fontSizerDX.sizeIncrement ); return false }
            } else if ( dw_Util.hasClass( links[i], 'reset')  ) {
                links[i].onclick = function () { dw_fontSizerDX.reset(); return false }
            }
        }
        if (sizerEl) sizerEl.style.display = "block";
    },

    getSizeIncrement: function () {
        var val = 2;
        switch ( dw_fontSizerDX.sizeUnit ) {
            case 'px' : val = 2; break;
            case 'em' : val = .2; break;
            case '%' : val = 10; break;
        }
        dw_fontSizerDX.sizeIncrement = val;
    },
    
    init: function() {
        if ( !document.getElementById || !document.getElementsByTagName || !document.createElement ) return;
        var _this = dw_fontSizerDX;
        if ( !_this.doControlsSetup ) {
            _this.addHandlers();
        } else {
            _this.setupControls();
        }
        var size;
        // check query string and cookie for fontSize
        // check size (in case default unit changed or size passed in url out of range)
        size = dw_Util.getValueFromQueryString( _this.queryName );
        if ( isNaN( parseFloat(size) ) || size > _this.maxSize || size < _this.minSize ) {
            size = dw_Cookie.get("fontSize");
            if ( isNaN( parseFloat(size) ) || size > _this.maxSize || size < _this.minSize ) {
                size = _this.defaultSize;
            }
        } 
        // if neither set nor setDefaults populates adjustList, apply sizes to body and td's
        if (_this.adjustList.length == 0) _this.set(  _this.defaultSize, _this.minSize, _this.maxSize, ['body', 'td'] ); 
        _this.curSize = _this.defaultSize;  // create curSize property to use in calculations 
        if ( size != _this.defaultSize ) _this.adjust( size - _this.defaultSize );
    },

    adjust: function(n) {
        if ( !this.curSize ) return; 
        var alist, size, list, i, j;
        // check against max/minSize
        if ( n > 0 ) {
            if ( this.curSize + n > this.maxSize ) n = this.maxSize - this.curSize;
        } else if ( n < 0 ) {
            if ( this.curSize + n < this.minSize ) n = this.minSize - this.curSize;
        }
        if ( n == 0 ) return;
        this.curSize += n;
        // loop through adjustList, calculating size, checking max/min
        alist = this.adjustList;
        for (i=0; alist[i]; i++) {
            size = this.curSize * alist[i]['ratio']; // maintain proportion 
            size = Math.max(alist[i]['min'], size); size = Math.min(alist[i]['max'], size);
            list = dw_Util.getElementsBySelector( alist[i]['sel'] );
            for (j=0; list[j]; j++) { list[j].style.fontSize = size + this.sizeUnit; }
        }
        dw_Cookie.set( "fontSize", this.curSize, this.cookieLifetime, "/" );
    },

    reset: function() {
        if ( !this.curSize ) return; 
        var alist = this.adjustList, list, i, j;
        for (i=0; alist[i]; i++) {
            list = dw_Util.getElementsBySelector( alist[i]['sel'] );
            for (j=0; list[j]; j++) { 
                // Reset adjustList elements to their default sizes
                //list[j].style.fontSize = alist[i]['dflt'] + this.sizeUnit;
                list[j].style.fontSize = '';  // restores original font size (unless set inline!)
            } 
        }
        this.curSize = this.defaultSize;
        dw_Cookie.del("fontSize", "/");
    }

};

/////////////////////////////////////////////////////////////////////
//  
var dw_Util; 
if (!dw_Util) dw_Util = {};

// removes space characters from start and end of string
dw_Util.trimString = function (str) {
    var re = /^\s+|\s+$/g;
    return str.replace(re, "");
}

// removes extra space characters
dw_Util.normalizeString = function (str) {
    var re = /\s\s+/g;
    return dw_Util.trimString(str).replace(re, " ");
}

dw_Util.hasClass = function (el, cl) {
    var re = new RegExp("\\b" + cl + "\\b", "i");
    if ( re.test( el.className ) ) {
        return true;
    }
    return false;
}

// what className attached to what element type in what container element (default: document)
dw_Util.getElementsByClassName = function (sClass, sTag, oCont) {
    var result = [], list, i;
    var re = new RegExp("\\b" + sClass + "\\b", "i");
    oCont = oCont? oCont: document;
    if ( document.getElementsByTagName ) {
        if ( !sTag || sTag == "*" ) { // for ie5
            list = oCont.all? oCont.all: oCont.getElementsByTagName("*");
        } else {
            list = oCont.getElementsByTagName(sTag);
        }
        for (i=0; list[i]; i++) 
            if ( re.test( list[i].className ) ) result.push( list[i] );
    }
    return result;
}

// resource: simon.incutio.com/archive/2003/03/25/getElementsBySelector
dw_Util.getElementsBySelector = function (selector) {
    if (!document.getElementsByTagName) return [];
    var nodeList = [document], tokens, bits, list, col, els, i, j, k;
    selector = dw_Util.normalizeString(selector);
    tokens = selector.split(' ');
    for (i=0; tokens[i]; i++) {
        if ( tokens[i].indexOf('#') != -1 ) {  // id
            bits = tokens[i].split('#'); 
            var el = document.getElementById( bits[1] );
            if (!el) return []; 
            if ( bits[0] ) {  // check tag
                if ( el.tagName.toLowerCase() != bits[0].toLowerCase() ) return [];
            }
            for (j=0; nodeList[j]; j++) {  // check containment
                if ( nodeList[j] == document || dw_Util.contained(el, nodeList[j]) ) 
                    nodeList = [el];
                else return [];
            }
        } else if ( tokens[i].indexOf('.') != -1 ) {  // class
            bits = tokens[i].split('.'); col = [];
            for (j=0; nodeList[j]; j++) {
                els = dw_Util.getElementsByClassName( bits[1], bits[0], nodeList[j] );
                for (k=0; els[k]; k++) { col[col.length] = els[k]; }
            }
            nodeList = [];
            for (j=0; col[j]; j++) { nodeList.push(col[j]); }
        } else {  // element 
            els = []; 
            for (j = 0; nodeList[j]; j++) {
                list = nodeList[j].getElementsByTagName(tokens[i]);
                for (k = 0; list[k]; k++) { els.push(list[k]); }
            }
            nodeList = els;
        }
    }
    return nodeList;
}

// obj: link or window.location
dw_Util.getValueFromQueryString = function (name, obj) {
    obj = obj? obj: window.location; 
    if (obj.search && obj.search.indexOf(name != -1) ) {
        var pairs = obj.search.slice(1).split("&"); // name/value pairs
        var set;
        for (var i=0; pairs[i]; i++) {
            set = pairs[i].split("="); // Check each pair for match on name 
            if ( set[0] == name && set[1] ) {
                return set[1];
            }
        }
    }
    return '';
}

// returns true of oNode is contained by oCont (container)
dw_Util.contained = function (oNode, oCont) {
    if (!oNode) return null; // in case alt-tab away while hovering (prevent error)
    while ( (oNode = oNode.parentNode) ) if ( oNode == oCont ) return true;
    return false;
}



