// JavaScript Document

/*IE 6 does not display transparent png images correctly, so subsitute a logo with a background = page background*/

function swapLogo(){
	document.logoimg.src="images/Logofffded.png";
}

function swapLogo1(){
	document.logoimg1.src="images/fmgfffded.png";
}

function swapLogo2(){
	document.logoimg2.src="images/logo-ambassador-fffded.png";
}

function swapLogo3(){
	document.logoimg3.src="images/bnbs_logo2012smfffded.png";
}
/*Animation function from Adobe and
Animation vs. Static Image Selector***********************************/

var newWindow;

function checkAnimationCookie()
{
	var value = cookieCheck('viewed');
	//alert(value);
	if (value=="recently")

	{
		document.getElementById("animation").style.visibility="hidden";
		//alert("an to hidden");
	}
	else
	{
		document.getElementById("animation").style.visibility="visible";
		//alert("an to visible");
		cookieSet("viewed","recently",7);
	}
}

//Adobe code
function playFlash()
{
		AC_FL_RunContent(
		'codebase', 	'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
		'width', '200',
		'height', '406',
		'src', 'images/PendantFormationRSm2',
		'quality', 'high',
		'pluginspage', 'http://www.adobe.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'false',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
		'id', 'PendantFormationRSm2',
		'bgcolor', '#fffded',
		'name', 'PendantFormationRSm2',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', 'images/PendantFormationRSm2',
		'salign', ''
		); //end AC code
}

function repeatFlash()
{
	  /*document.getElementById("animation").style.zIndex="99";												
	  */
	  cookieSet("viewed", "recently", -1);
	  window.location.href="index.php";
	  //document.getElementById("animation");
	  //playFlash();
}



/*Window open functions*/

/*Open a new window 75% of the height and width of the opener and 50px from both the bottom and right edges of the screen.*******************************/

function windowOpen(outlink)
{
	var x=window.screen.availWidth;
	var y=window.screen.availHeight;
		
	var w=window.innerWidth;
	if (isNaN(w))			//for IE 
	{
		w=.75*document.body.clientWidth;
	}
	else w=.75*w;
	
	var h=window.innerHeight;
	if (isNaN(h))			//for IE
	{
		h=.6*y;				//document.body.clientHeight not appropriate here - gives full document height	
	}
	else h=.75*h;
		
	var place;
	if (document.getElementById("home")) {var hor=0; var vert=0;}
	if (document.getElementById("sites")) {var hor=10; var vert=10;}
	if (document.getElementById("calendar")) {var hor=0; var vert=20;}

	newx=x-w-25-hor*5;
	newy=y-h-75-vert*5;
		
	if (newWindow)	newWindow.close();

newWindow=window.open(outlink, '','width='+ w + ',height=' + h + ',left=' + newx + ',top=' + newy + ',scrollbars=1,toolbar=1,menubar=1,resizable=1,location=1,status=1');
	
}


function hover(iLink)
{
	document.getElementById(iLink).style.borderColor='#ff252c';
}

function out(iLink)
{
	document.getElementById(iLink).style.borderColor='#fffded';
}


/*Functions for Form Validation*******************************************/

function limit3()
{
	var elements = document.formSS1;		
	//alert(document.formSS1.sStoneBead.length);
	var count=0;
	for (var i=0; i<elements.sStoneBead.length; i++)
	{
		if(elements.sStoneBead[i].checked == true)	count++;
	}
	//alert("Final count = " + count);
	if (count >3) 
		{
			alert("Please select any three but only three items.");
			for (var i=elements.sStoneBead.length-1; i>2; i--)
			{
				if(elements.sStoneBead[i].checked == true)
				{
					elements.sStoneBead[i].checked = false;
					count--;
					if (count>3) continue;
					else break;
				}
			}
		}
}

function validate()
{
	var elements = document.formSS1;		
	var alertString = "";
	
	if (!elements.fname.value.match (/[A-z]/)) alertString += "<br />...enter your first name";
	
	if (!elements.lname.value.match (/[A-z]/)) alertString += "<br />...enter your last name";
	
	
	if (!elements.emailAddress.value.match (/^\w+(\.\w+)*@[0-9A-z]+\.[A-z]{2,4}$/)) alertString += "<br />...enter a valid email address";
	
	if (elements.addToList[0].checked == false &&
		elements.addToList[1].checked == false)
	alertString+="<br />...indicate your email preference";
	
	for (var i=0; i<elements.wire.length; i++)
	{
		if (elements.wire[i].checked) break;
		else if (i==elements.wire.length-1) alertString+="<br />...select the type of wire for your necklace";
		else continue;
	}
	
	for (var i=0; i<elements.pendant.length; i++)
	{
		if (elements.pendant[i].checked) break;
		else if (i==elements.pendant.length-1) alertString+="<br />...choose a central stone";
		else continue;
	}
	
for (var i=0; i<elements.sStoneBead.length; i++)
	{	
		if(elements.sStoneBead[i].checked)	break;
		else if(i== elements.sStoneBead.length-1) alertString+="<br />...select at least one ornamental bead";
	}
	
	if (elements.clasp.value == "") alertString+="<br />...select a clasp";
	
	if (alertString != "")
	{
		window.location.href="#formalert";
		nudge=document.getElementById("formalert");
		nudge.innerHTML="Please"+alertString+".";
		return (false);
	}
	
	window.location.href="#formalert";
	nudge=document.getElementById("formalert");
	nudge.innerHTML="";
	return(true);
}

function clearAlerts()
{
	nudge.innerHTML="";
	window.location.href="#formalert";
}

/**********Pop-up******************/

/*Declare global variables available to all functions*/

var a, b, l, t, inc, obj1, obj2, hwratio, maxheight, minheight, minwidth, growing, shrinking, direction, popped;

/*Get the top-left location of the smaller image and apply to the larger*/
/*All images must have a 3px border on all sides*/

function grow(smimg,lgimg,hdirection,vdirection)
{
	
	if (popped==1) {shrink();return;
		/*obj2.style.visibility="hidden";
		obj1.style.zIndex=2;
		obj2.style.zIndex=1;
		obj2.style.left=0+"px";	
		obj2.style.height = maxheight+"px";
		obj2.style.width = maxwidth+"px";
		maxheight=obj2.offsetHeight;
		*/}
	obj1 = document.getElementById(smimg);
	if(growing||shrinking)return;
	obj2 = document.getElementById(lgimg);
	maxheight=obj2.offsetHeight-6;//because offsetHeight includes the border
	maxwidth=obj2.offsetWidth-6;
	minheight=obj1.offsetHeight-6;
	minwidth=obj1.offsetWidth-6;
	obj2.style.height = minheight+"px";
	obj2.style.width = minwidth+"px";
	l = obj1.offsetLeft;
	obj2.style.left = l +"px";
	switch (vdirection)
	{
		case 'up':
		b=1;
		break;
		case 'down':
		b=0;
		break;
	}
	if (b) {
		t = obj1.offsetTop;
		obj2.style.top = t + "px";
	}
	switch (hdirection)
	{
		case 'left':
		a=1;
		break;
		case 'center':
		a=0.5;
		break;
		case 'right':
		a=0;
		break;
	}
	hwratio = (minwidth)/(minheight);
	/*obj1.style.zIndex=1;
	obj2.style.zIndex=3;*/
	obj2.style.visibility="visible";
	inc=0;
	growing=setInterval("increment()",10);
}

function shrink()
{
	if(growing||shrinking)return;
	inc=0;
	shrinking=setInterval("decrement()",10);
}

function increment()
{

	inc+=((maxheight-minheight)/20);
	obj2.style.height = minheight+inc +"px";
	obj2.style.width = (minheight+inc)*hwratio + "px";
	if (b) obj2.style.top = (t - inc) + "px";
	obj2.style.left = (l - a*(inc*hwratio)) + "px";	
	if (obj2.offsetHeight>=maxheight) 
	{
		clearInterval(growing);
		obj2.style.height = maxheight + "px";
		obj2.style.width = maxwidth + "px";
		if (b) obj2.style.top = (t-maxheight+minheight) + "px";
		l=obj2.offsetLeft;
		growing=shrinking=0;
		popped=1;
	}
}

function decrement()
{
	inc-=((maxheight-minheight)/20);
	obj2.style.height = maxheight+inc +"px";
	obj2.style.width = (maxheight+inc)*hwratio + "px";
	if (b) obj2.style.top = (t - maxheight + minheight - inc) + "px";
	obj2.style.left = (l -a*(inc*hwratio)) + "px";	
	if (obj2.offsetHeight<=minheight)
	{
		obj2.style.visibility="hidden";
		/*obj1.style.zIndex=2;
		obj2.style.zIndex=1;*/
		obj2.style.left=(l) +"px";	
		obj2.style.height = maxheight+"px";
		obj2.style.width = maxwidth+"px";
		if (b) obj2.style.top = (t - maxheight + minheight) + "px";
		maxheight=obj2.offsetHeight;
		clearInterval(shrinking);
		shrinking=0;
		popped=0;
	}
}

/* fall show reference to Sonoran Desert*/

function fallshow()
{
var source = document.referrer;
var name = /upcomingclasses.php$/;
if (source.search(name)!=-1)
   {
	   loadCentralImage(3);
   }

}

