var preloadspinner = new Image();
preloadspinner.src = "images/loading-img.gif";
var preloadqmark = new Image();
preloadqmark.src = "images/loading-q-small.gif";

		function getabstop( el )
		{
			elobj = document.getElementById( el );
			if ( !elobj )
				elobj = el;

			eltop = elobj.offsetTop;

			for ( ; ; )
			{
				elobj = elobj.offsetParent;
				if ( elobj )
				{
					eltop += elobj.offsetTop;
				}
				else
					return (eltop);
			}
		}

		function getabsleft( el )
		{
			elobj = document.getElementById( el );
			if ( !elobj )
				elobj = el;
			elleft = elobj.offsetLeft;

			for ( ; ; )
			{
				elobj = elobj.offsetParent;
				if ( elobj )
				{
					elleft += elobj.offsetLeft;
				}
				else
					return (elleft);
			}
		}


function isie()
{
	var ua = window.navigator.userAgent;
    var msie = ua.indexOf ( "MSIE " );

    if ( msie <= 0 )
    	return false;
    else
    	return true;
}

function swfwrite( name )
{
	document.write( "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"551\" height=\"250\" id=\"why_slider\" align=\"middle\">" );
	document.write( "<param name=\"allowScriptAccess\" value=\"sameDomain\" />" );
	document.write( "<param name=\"movie\" value=\"flash/" + name + ".swf\" />" );
	document.write( "<param name=\"menu\" value=\"false\" />" );
	document.write( "<param name=\"quality\" value=\"high\" />" );
	document.write( "<param name=\"bgcolor\" value=\"#b7c292\" />" );
	document.write( "<embed src=\"flash/" + name + ".swf\" menu=\"false\" quality=\"high\" bgcolor=\"#b7c292\" width=\"551\" height=\"250\" name=\"why_slider\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />" );
	document.write( "</object>" );
}

function pop( url, w, h )
{
 	t = ( screen.height / 2 ) - (h);
 	l = ( screen.width / 2 ) - (w/4);
	newwindow = window.open( url, 'pop', 'width=' + w + ',height=' + h + ',top=' + t + ',left=' + l );
	if ( window.focus )
	{
		newwindow.focus();
	}
	return false;
}

function faqon( num )
{
	qe = document.getElementById( 'q' + num );
	ae = document.getElementById( 'a' + num );

	if ( qe && ae )
	{
		if ( num == 1 )
			qe.className = "qmeatovertop";
		else
			qe.className = "qmeatover";

		ae.className = "ameatover";
	}
}

function faqoff( num )
{
	qe = document.getElementById( 'q' + num );
	ae = document.getElementById( 'a' + num );

	if ( qe && ae )
	{
		if ( num == 1 )
			qe.className = "qmeattop";
		else
			qe.className = "qmeat";

		ae.className = "ameat";
	}
}

function preloadImages()
{
	i02 = new Image(); i02.src = "images/why_off.gif";
	i03 = new Image(); i03.src = "images/why_over.gif";
	i01 = new Image(); i01.src = "images/why_on.gif";
	i05 = new Image(); i05.src = "images/which_off.gif";
	i06 = new Image(); i06.src = "images/which_over.gif";
	i04 = new Image(); i04.src = "images/which_on.gif";
	i08 = new Image(); i08.src = "images/purchasing_off.gif";
	i09 = new Image(); i09.src = "images/purchasing_over.gif";
	i07 = new Image(); i07.src = "images/purchasing_on.gif";
	i11 = new Image(); i11.src = "images/popular_off.gif";
	i12 = new Image(); i12.src = "images/popular_over.gif";
	i10 = new Image(); i10.src = "images/popular_on.gif";
	i14 = new Image(); i14.src = "images/gallery_off.gif";
	i15 = new Image(); i15.src = "images/gallery_over.gif";
	i13 = new Image(); i13.src = "images/gallery_on.gif";
	i17 = new Image(); i17.src = "images/info_off.gif";
	i18 = new Image(); i17.src = "images/info_over.gif";
	i16 = new Image(); i16.src = "images/info_on.gif";
}

function togglediv( divid, state, eloff, elon )
{
	e = document.getElementById( divid );
	if (e)
	{
		if (state=='on')
			e.className = 'vdiv';
		else
			e.className = 'idiv';
	}

	if ( eloff )
	{
		e=document.getElementById( eloff );
		if (e)
			e.style.display = 'none';
	}

	if ( elon )
	{
		e=document.getElementById( elon );
		if (e)
			e.style.display = 'block';
	}

}

function si( img, el )
{
	//size_blurb_to( 1, 20 );
	//size_blurb_to( 350, 20 );
	e = document.getElementById( "imagechunk" );
	if (e)
	{
		e.style.backgroundImage = "url(images/loading-img.gif)";
		e.style.backgroundRepeat = "no-repeat";
		e.style.backgroundPosition = "50% 50%";
		//e.style.backgroundPositionX = "50%";
		//e.style.backgroundPositionY = "50%";
		e.src = "images/1px.gif";
		//return;
		setTimeout( "document.getElementById( 'imagechunk' ).src = '" + img + "'", 10 );
		//setTimeout( "'e.src =' + img", 100 );
		if ( e.style.cursor != "pointer" )
			e.style.cursor = "pointer";
	}

	if ( el != undefined )
	{
		imgid = el.id;
		blurbid = imgid + "_blurb";
		e = document.getElementById(blurbid);
		if ( e )
		{
			blurbdiv = document.getElementById("blurb");
			blurbdiv.innerHTML = e.innerHTML;
			blurb_height = e.clientHeight;
			if ( isie() )
				blurb_height += 16;	// adjust ie by 16px for padding.
			size_blurb_to( blurb_height, 20 );
		}
		else
		{
			// if the blurb isn't there for the given photo yet, rollback
			// any open blurb.
			size_blurb_to( 1, 20 );
		}
	}
}

function leaving()
{
	pop('leaving.php',480,250);
	return true;
}

function galleryclass( link, classname )
{
	size_blurb_to( 1, 20 );

	octclass = "ivt";
	ovalclass = "ivt";
	rectclass = "ivt";
	interiorclass = "ivt";
	if ( classname == "octagon" ) { octclass = "vt"; }
	if ( classname == "oval" ) { ovalclass = "vt"; }
	if ( classname == "rect" ) { rectclass = "vt"; }
	if ( classname == "interiors" ) { interiorclass = "vt"; }

	e = document.getElementById( "octlink" ); if ( e ) { e.className = "iltinactive"; }
	e = document.getElementById( "ovallink" ); if ( e ) { e.className = "iltinactive"; }
	e = document.getElementById( "rectlink" ); if ( e ) { e.className = "iltinactive"; }
	e = document.getElementById( "intlink" ); if ( e ) { e.className = "iltinactive"; }
	link.className = "iltactive";

	e = document.getElementById( "octagonsblock" );	if ( e ) { e.className = octclass; }
	e = document.getElementById( "ovalsblock" ); if ( e ) { e.className = ovalclass; }
	e = document.getElementById( "rectsblock" ); if ( e ) { e.className = rectclass; }
	e = document.getElementById( "interiorsblock" ); if ( e ) { e.className = interiorclass; }

	return false;
}

function htgclass( link, classname )
{
	i1class = "ivt";
	i2class = "ivt";
	i3class = "ivt";

	if ( classname == "i1" ) { i1class = "vt"; }
	if ( classname == "i2" ) { i2class = "vt"; }
	if ( classname == "i3" ) { i3class = "vt"; }

	e = document.getElementById( "i1" ); if ( e ) { e.className = "iltinactive"; }
	e = document.getElementById( "i2" ); if ( e ) { e.className = "iltinactive"; }
	e = document.getElementById( "i3" ); if ( e ) { e.className = "iltinactive"; }
	link.className = "iltactive";

	e = document.getElementById( "htgi" );
	if ( e )
	{
		if ( classname == "i1" ) { e.src = "images/Adams4.jpg"; }
		if ( classname == "i2" ) { e.src = "images/adams3.jpg"; }
		if ( classname == "i3" ) { e.src = "images/adams1.jpg"; }
	}

	return false;
}

function ne( id, msg )
{
	e = document.getElementById( id );
	if ( e )
	{
		if ( e.value == "" )
		{
			if ( msg == 1 )
			{
				s = "By entering your e-mail address here, you'll be able to keep track of your favorite gazebos as you browse. If you return to our website at a later time, you'll have a history of what you've looked at, including any of your custom-designed gazebos.\r\n\r\n";
				s = s + "If you've never been here before, entering your e-mail address will create an account for you. No personal information is associated with this account, so it's 100% safe and easy to use.";
				alert( s );
				e.focus();
			}

			if ( msg == 2 )
			{
				s = "Enter your e-mail address below to receive the Countryside Gazebos monthly newsletter. You'll stay up-to-date with our latest deals and special offers, and you'll also receive tips from our team of gazebo experts on maintaining the beauty of your gazebo for years of complete enjoyment.\r\n\r\n";
				s = s + "We will never share your e-mail address with anyone, and you can opt-out of our monthly newsletter at any time.";

				alert( s );
				e.focus();
			}

			if ( msg == 3 )
			{
				s = "Want to suggest Countryside Gazebos to a friend?  Enter their e-mail address below, and we'll send them an e-mail inviting them to visit us online.";
				alert( s );
				e.focus();
			}

			e.focus();
			return false;
		}
		else
		{
			if ( vemail(e.value) == false )
			{
				alert( "You must provide a valid e-mail address." );
				e.focus();
				return false;
			}
			else
			{
				return true;
			}
		}

	}
}

function vmi()
{
	e1 = document.getElementById( "custname" );
	e2 = document.getElementById( "custemail" );
	e3 = document.getElementById( "custphone" );
	e4 = document.getElementById( "custaltphone" );
	e5 = document.getElementById( "contactmethod" );
	if ( e1 && e2 && e3 && e4 && e5 )
	{
		custname = e1.value;
		custemail = e2.value;
		custphone = e3.value;
		custaltphone = e4.value;
		contactmethod = e5.value;

		if ( custname == "" )
		{
			alert( "Please enter your name." );
			e1.focus();
			return false;
		}

		if ( contactmethod == "By e-mail" && custemail == "" )
		{
			alert( "You selected e-mail as your preferred method of contact, but you didn't provide an e-mail address.  Please enter your e-mail address." );
			e2.focus();
			return false;
		}

		if ( contactmethod == "By phone" && custphone == "" && custaltphone == "" )
		{
			alert( "You selected phone as your preferred method of contact, but you didn't provide a phone number.  Please enter your phone number." );
			e3.focus();
			return false;
		}

		if ( contactmethod == "No preference" && custemail == "" && custphone == "" && custaltphone == "" )
		{
			alert( "You must provide either an e-mail address or a phone number, or we will be unable to contact you." );
			e2.focus();
			return false;
		}

		if ( custemail != "" )
		{
			if ( vemail( custemail ) == false )
			{
				alert( "You must provide a valid e-mail address, or we will be unable to contact you." );
				e2.focus();
				return false;
			}

		}

	}

	return true;
}

function vemail( addr )
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (filter.test(addr))
		return true;
	 else
	 	return false;
}

function dupebilling()
{
	n1 = document.getElementById( "custbillingname" );
	a11 = document.getElementById( "custbillingaddr1" );
	a21 = document.getElementById( "custbillingaddr2" );
	c1 = document.getElementById( "custbillingcity" );
	s1 = document.getElementById( "custbillingstate" );
	z1 = document.getElementById( "custbillingzip" );

	n2 = document.getElementById( "custshippingname" );
	a12 = document.getElementById( "custshippingaddr1" );
	a22 = document.getElementById( "custshippingaddr2" );
	c2 = document.getElementById( "custshippingcity" );
	s2 = document.getElementById( "custshippingstate" );
	z2 = document.getElementById( "custshippingzip" );

	if ( n1 && a11 && a21 && c1 && s1 && z1 )
	{
		if ( n2 && a12 && a22 && c2 && s2 && z2 )
		{
			n2.value = n1.value;
			a12.value = a11.value;
			a22.value = a21.value;
			c2.value = c1.value;
			s2.value = s1.value;
			z2.value = z1.value;
		}
	}

	return false;
}

function nocc()
{
	c1 = document.getElementById( "cc1" );
	c2 = document.getElementById( "cc2" );
	c3 = document.getElementById( "cc3" );
	if ( c1 && c2 && c3 )
	{
		c1.className = "idiv";
		c2.className = "idiv";
		c3.className = "idiv";
	}
}

function onecc()
{
	c1 = document.getElementById( "cc1" );
	c2 = document.getElementById( "cc2" );
	c3 = document.getElementById( "cc3" );
	if ( c1 && c2 && c3 )
	{
		c1.className = "vdiv";
		c2.className = "idiv";
		c3.className = "idiv";
	}
}

function multcc()
{
	c1 = document.getElementById( "cc1" );
	c2 = document.getElementById( "cc2" );
	c3 = document.getElementById( "cc3" );
	if ( c1 && c2 && c3 )
	{
		c1.className = "vdiv";
		c2.className = "vdiv";
		c3.className = "idiv";
	}
}

function thirdcc(b)
{
	c3 = document.getElementById( "cc3" );
	if ( c3 )
	{
		if (b)
			c3.className = "vdiv";
		else
			c3.className = "idiv";
	}
}

function vof()
{
	cn = document.getElementById( "custname" );
	ce = document.getElementById( "custemail" );
	cp = document.getElementById( "custphone" );
	cap = document.getElementById( "custaltphone" );
	if ( cn && ce && cp && cap )
	{
		if ( cn.value == "" ) { alert( "Please enter your name." ); cn.focus(); return false; }
		if ( ce.value == "" ) { alert( "Please enter your e-mail address.  We will be sending a confirmation of your order to you via e-mail." ); ce.focus(); return false; }
		if ( vemail( ce.value ) == false ) { alert( "You must provide a valid e-mail address. We will be sending a confirmation of your order to you via e-mail." ); ce.focus(); return false; }
        if ( cp.value == "" && cap.value == "" ) { alert( "Please provide at least one phone number where we can reach you." ); cp.focus(); return false; }
	}

	n1 = document.getElementById( "custbillingname" );
	a11 = document.getElementById( "custbillingaddr1" );
	a21 = document.getElementById( "custbillingaddr2" );
	c1 = document.getElementById( "custbillingcity" );
	s1 = document.getElementById( "custbillingstate" );
	z1 = document.getElementById( "custbillingzip" );
	if ( n1 && a11 && a21 && c1 && s1 && z1 )
	{
		if ( n1.value == "" || a11.value == "" || c1.value == "" || s1.value == "---" || z1.value == "" )
		{
			alert( "Your billing address is incomplete.  Please provide all of the requested information." );
			return false;
		}
	}

	n2 = document.getElementById( "custshippingname" );
	a12 = document.getElementById( "custshippingaddr1" );
	a22 = document.getElementById( "custshippingaddr2" );
	c2 = document.getElementById( "custshippingcity" );
	s2 = document.getElementById( "custshippingstate" );
	z2 = document.getElementById( "custshippingzip" );
	if ( n2 && a12 && a22 && c2 && s2 && z2 )
	{
		if ( n2.value == "" || a12.value == "" || c2.value == "" || s2.value == "---" || z2.value == "" )
		{
			alert( "Your shipping address is incomplete.  Please provide all of the requested information." );
			return false;
		}
	}

	pm1 = document.getElementById( "paymentmethod1" );
	pm2 = document.getElementById( "paymentmethod2" );
	pm3 = document.getElementById( "paymentmethod3" );
	pm4 = document.getElementById( "paymentmethod4" );
	pm5 = document.getElementById( "paymentmethod5" );
	if ( pm1 && pm2 && pm3 && pm4 && pm5 )
	{
		if ( pm1.checked == false && pm2.checked == false && pm3.checked == false && pm4.checked == false && pm5.checked == false )
		{
			alert( "You must select a payment method from one of the available options." );
			return false;
		}
		else
		{
			if ( pm1.checked ) { method = "1CC"; }
			if ( pm2.checked ) { method = "MCC"; }
			if ( pm3.checked ) { method = "CHK"; }
			if ( pm4.checked ) { method = "FIN"; }
			if ( pm5.checked ) { method = "OTH"; }

			//alert( method );
			//return false;

			if (method=="MCC")
			{
				c3 = document.getElementById( "cc3" );
				if ( c3.className == "vdiv" )
				{
					cc3type = document.getElementById( "cc3type" );
					cc3name = document.getElementById( "cc3name" );
					cc3num = document.getElementById( "cc3num" );
					cc3expmonth = document.getElementById( "cc3month" );
					cc3expyear = document.getElementById( "cc3year" );
					cc3cvv = document.getElementById( "cc3cvv" );

					if ( cc3type && cc3name && cc3num && cc3expmonth && cc3expyear && cc3cvv )
					{
						if ( cc3type.value == "---" || cc3name.value == "" || cc3num.value == "" || cc3expmonth.value == "---" || cc3expyear.value == "---" )
						{
							alert( "The information you've provided for credit card #3 is incomplete.  Please provide all of the requested information." );
							return false;
						}
					}
				}

				c2 = document.getElementById( "cc2" );
				if ( c2.className == "vdiv" )
				{
					cc2type = document.getElementById( "cc2type" );
					cc2name = document.getElementById( "cc2name" );
					cc2num = document.getElementById( "cc2num" );
					cc2expmonth = document.getElementById( "cc2month" );
					cc2expyear = document.getElementById( "cc2year" );
					cc2cvv = document.getElementById( "cc2cvv" );

					if ( cc2type && cc2name && cc2num && cc2expmonth && cc2expyear && cc2cvv )
					{
						if ( cc2type.value == "---" || cc2name.value == "" || cc2num.value == "" || cc2expmonth.value == "---" || cc2expyear.value == "---" )
						{
							alert( "The information you've provided for credit card #2 is incomplete.  Please provide all of the requested information." );
							return false;
						}
					}
				}
			}

			if (method=="MCC" || method=="1CC")
			{
				c1 = document.getElementById( "cc1" );
				if ( c1.className == "vdiv" )
				{
					cc1type = document.getElementById( "cc1type" );
					cc1name = document.getElementById( "cc1name" );
					cc1num = document.getElementById( "cc1num" );
					cc1expmonth = document.getElementById( "cc1month" );
					cc1expyear = document.getElementById( "cc1year" );
					cc1cvv = document.getElementById( "cc1cvv" );

					if ( cc1type && cc1name && cc1num && cc1expmonth && cc1expyear && cc1cvv )
					{
						if ( cc1type.value == "---" || cc1name.value == "" || cc1num.value == "" || cc1expmonth.value == "---" || cc1expyear.value == "---" )
						{
							alert( "The information you've provided for credit card #1 is incomplete.  Please provide all of the requested information." );
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}

function togglesug()
{
	e = document.getElementById( "sugdetails" );
	if ( e )
	{
		if ( e.className == "idiv" )
		{
			e.className = "vdiv";
			e2 = document.getElementById( "tellemail" );
			if ( e2 )
			{
				e2.focus();
			}
		}
		else
			e.className = "idiv";
	}
}

function ensurepop()
{
	//alert( this.parent.name );
	if ( this.parent.name != "pop" )
	{
		this.location = "index.php";
	}
}

function setandfadeingallerylabel( label )
{
	e = document.getElementById( "gldiv" );
	if ( e )
	{
		e.style.opacity = 0.75;
		e.style.MozOpacity = 0.75;
		e.style.filter = 'alpha(opacity=75)';
	}
}

function fadeoutgallerylabel()
{
	e = document.getElementById( "gldiv" );
	if ( e )
	{
		e.style.opacity = 0.0;
		e.style.MozOpacity = 0.0;
		e.style.filter = 'alpha(opacity=0)';
	}
}
