// 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";
}

/*Animation function from Adobe and
Animation vs. Static Image Selector***********************************/

var newWindow;

function checkAnimationCookie()
{
	var value = cookieCheck('viewed');window
	//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.html";
}



/*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');
	
}


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

function out(iLink)
{
	document.getElementById(iLink).style.borderColor='rgb(139,124,21)';
}


/*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";
}