//	Did they come in through the French URL?

var bFromEng = false;

//	Did they come from the English page?  If so, se bFromEng to TRUE so we know
//	not to flip them back to the French page.
if (window.location.href.indexOf("from_eng") > -1) {
	bFromEng = true;
 }

if (!bFromEng) {
	if (window.location.href.indexOf("beaux-arts") > -1) {
		goToFrench();
	}

	//	Detect if using French browser
	if (navigator.userLanguage) {
		if (navigator.userLanguage.indexOf("fr") > -1) {
			goToFrench();
		}
	} else if (navigator.language) {
		if(navigator.language.indexOf("fr") > -1) {
			goToFrench();
		}
	}
}

function goToFrench() {
	window.location.href = "home_f.jsp";
}


var profileLayers = new Array('set1', 'set2', 'set3');
var numProfiles = profileLayers.length;

var iCounter = 0;


function changeProfiles(iNum) {
	if (document.getElementById) {
		
		// Set all of the DIV to display = none
		for (var a = 0; a < numProfiles; a++) {
			var tempDivName = profileLayers[a];
			document.getElementById(tempDivName).className = "noShow";
		}			

		// Now, turn on the active DIV
		
		// Increase or decrease the count
		iCounter += iNum;
		
		// Get the reminder, which will be 0, 1 or 2
		iActiveDiv = Math.abs(iCounter % numProfiles);
		
		// Grab that DIV name from the array
		var tempDivName = profileLayers[iActiveDiv];
		
		// Set the DIV to display = block
		document.getElementById(tempDivName).className = "show";
	}
}

// preLoad

var preLoad = new Array;

preLoad[0] = new Image();
preLoad[0].src = "imagesHome/main_image_56.jpg";
preLoad[0].alt = "Marc-Aurčle Fortin - Detail - Landscape, Hochelaga, c. 1931";

preLoad[1] = new Image();
preLoad[1].src = "imagesHome/main_image_57.jpg";
preLoad[1].alt = "Geoffrey James - Detail - Venice, 1971 ";

preLoad[2] = new Image();
preLoad[2].src = "imagesHome/main_image_58.jpg";
preLoad[2].alt = "Claude Monet - Detail - A Stormy Sea, c. 1884 ";

preLoad[3] = new Image();
preLoad[3].src = "imagesHome/main_image_59.jpg";
preLoad[3].alt = "William Kurelek - Detail - Manitoba Party, 1964 ";

preLoad[4] = new Image();
preLoad[4].src = "imagesHome/main_image_60.jpg";
preLoad[4].alt = "Paraskeva Clark - Detail - Petroushka, 1937 ";


var preLoadLink = new Array();
preLoadLink[0] = "search/artwork_e.jsp?mkey=7431";
preLoadLink[1] = "search/artwork_e.jsp?mkey=86433";
preLoadLink[2] = "search/artwork_e.jsp?mkey=2109";
preLoadLink[3] = "search/artwork_e.jsp?mkey=6743";
preLoadLink[4] = "search/artwork_e.jsp?mkey=14957";

function randomFlashImage() {
	if (document.images && document.getElementById) {
		// Randomly determine which image and link we are using
		var x = preLoad.length;
		var n = Math.floor(Math.random() * x);
	
		// Change the image
		var imgString = preLoad[n].src;
		document.getElementById('mainImage').src = imgString;
		
		var altString = preLoad[n].alt;
		document.getElementById('mainImage').alt = altString;
		
		// Now, changing the link is a bit more complicated
		var theDiv = document.getElementById('topContent');
		
		var iTopContentSubs = theDiv.childNodes.length;
		
		for (var a = 0; a < iTopContentSubs; a++) {
			if (theDiv.childNodes[a].tagName.toUpperCase() == "A") {
				theDiv.childNodes[a].href = preLoadLink[n];
				break;
			}
		}
	}
}



// form validation stuff
var notValidChars = "'&?*^%$#@|\/+=-[]}{};:<>, ";

function validate_alpha(entered,alertbox)
{
validateFlag=true;
for (j=0; j<entered.value.length; j++)
	{
    toCheck=entered.value.charAt(j);
	if (notValidChars.indexOf(toCheck)>=0)
		validateFlag=false;
	} 
if (!validateFlag)
	alert(alertbox);
return validateFlag;
}

function trim(strVariable)
{

if (strVariable==null)
	return "";
var len=strVariable.length;
if (len==0)
	return "";
	
// first part:  trims blanks to the right
var index=len-1;
while ((index>0) && (strVariable.charAt(index)==" ")) index--;
strVariable=strVariable.substring(0,index+1);

// second part:  trims leading blanks

len=strVariable.length;
index=0;
while ((index<len) && (strVariable.charAt(index)==" ")) index++;
strVariable=strVariable.substring(index,len);
return strVariable;
}

function emptyvalidation(entered, alertbox)
{
with (entered)
	{
    value=trim(value);
	if (value==null || value=="")
		{	
		if (alertbox!="") 
			{
			alert(alertbox);
			} 
		return false;
		}
	else 
		{
		return true;
		}
	}
}

var bCheckMandatory=true;

function validateFields()
{
var ok=true;
if (bCheckMandatory==true)
	{
	ok= emptyvalidation(document.dropdownmenu.username,'You must enter a username in the space provided')
	if (ok)
		if (document.dropdownmenu.username.value.length<4)
		{
		alert ("Your username must be at least 4 characters long...");
		ok=false;
		}
	if (ok)
		ok= emptyvalidation(document.dropdownmenu.password,'You must enter a password in the space provided.')
	if (ok)
		if (document.dropdownmenu.password.value.length<5)
		{
		alert ("Your password must be at least 5  characters long...");
		ok=false;
		}
	}
	if (ok)
		ok=validate_alpha(document.dropdownmenu.username,"Error: Invalid characters in User name...(Please use only letters and numbers)");
	if (ok)
		ok=validate_alpha(document.dropdownmenu.password,"Error: Invalid characters in password...(Please use only letters and numbers)");
return ok;
}
 
function sendRegister()
{
bCheckMandatory=false;
document.dropdownmenu.register.value="register";
document.dropdownmenu.submit();
return true;
} 
