var totalImages = 16; // Total images used

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);

ns3up = (browserName == "Netscape" && browserVer >= 3);
ie4up = (browserName.indexOf("Microsoft") >= 0 && browserVer >= 4);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
  	x.src=x.oSrc;
}

function swopPhoto(imgName, imgIdx, imgPage) {
	
	if (ns3up || ie4up) 
		imgOn = ("" + imgName);
		
	document.mainpic.src = "images/gallery/"+imgOn;
}


function showPic(imgName) 
{
	if (ns3up || ie4up) 
		imgOn = ("images/topnav/" + imgName);
		
	document.mainpic.src = imgOn;
}

if(document.images)
{
	mFX = new Array(totalImages);
	for(i = 0; i < mFX.length; i++)
	{
		mFX[i] = new Image();
	}
	
	//url = 'http://www106.your-server.de/runfor/website/';
	url = 'http://www.runforthechildren.co.uk/';
	//url = 'http://mammoth-server/FIREROOM/RUN-FOR-THE-CHILDREN/';
	
	mFX[0].src = url+"/images/topnav/home.jpg";
	mFX[1].src = url+"/images/topnav/home-over.jpg";

	mFX[2].src = url+"/images/topnav/news.jpg";
	mFX[3].src = url+"/images/topnav/news-over.jpg";
	
	mFX[4].src = url+"/images/topnav/entry-rules.jpg";
	mFX[5].src = url+"/images/topnav/entry-rules-over.jpg";
	
	mFX[6].src = url+"/images/topnav/preparation.jpg";
	mFX[7].src = url+"/images/topnav/preparation-over.jpg";
	
	mFX[8].src = url+"/images/topnav/volunteer-now.jpg";
	mFX[9].src = url+"/images/topnav/volunteer-now-over.jpg";
	
	mFX[10].src = url+"/images/topnav/our-sponsors.jpg";
	mFX[11].src = url+"/images/topnav/our-sponsors-over.jpg";
	
	mFX[12].src = url+"/images/topnav/about.jpg";
	mFX[13].src = url+"/images/topnav/about-us-over.jpg";
	
	mFX[14].src = url+"/images/topnav/gallery.jpg";
	mFX[15].src = url+"/images/topnav/gallery-over.jpg";
	
}

function imgFX(img, num)
{
	if(document.images)
	{
		document.images[img].src = mFX[num].src;
	}
}

function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function openPopup() 
{
	window.open("display-popup.php", "pop", "resizable=0,HEIGHT=790,WIDTH=830");
}

function validateContact()
{
	fv = new formValidator();
	
	if (fv.isEmpty("company_name"))
		fv.raiseError("Please specify your company name.");
		
	if (!fv.isSelected("country"))
		fv.raiseError("Please select your country.");	
		
	if (fv.isEmpty("contact_person"))
		fv.raiseError("Please specify your contact person.");
	
	if (fv.isEmpty("email"))
		fv.raiseError("Please specify an email address.");
	else
	{
		if (!fv.isEmailAddress("email"))
			fv.raiseError("Please specify a valid email address.");
	}
	
	if (fv.isEmpty("telephone_number"))
		fv.raiseError("Please specify your phone number.");
		
	if (fv.isEmpty("code"))
		fv.raiseError("Please specify the code being used for spam prevention.");		
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
		return true;
}

function validatePartner()
{
	fv = new formValidator();
	
	if (fv.isEmpty("company_name"))
		fv.raiseError("Please specify your company name.");
		
	if (!fv.isSelected("country"))
		fv.raiseError("Please select your country.");	
		
	if (fv.isEmpty("contact_person"))
		fv.raiseError("Please specify your contact person.");
	
	if (fv.isEmpty("email"))
		fv.raiseError("Please specify an email address.");
	else
	{
		if (!fv.isEmailAddress("email"))
			fv.raiseError("Please specify a valid email address.");
	}
	
	if (fv.isEmpty("telephone_number"))
		fv.raiseError("Please specify your phone number.");
		
	if (fv.isEmpty("code"))
		fv.raiseError("Please specify the code being used for spam prevention.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
		return true;
}

function validateTrial()
{
	fv = new formValidator();
	
	if (fv.isEmpty("company_name"))
		fv.raiseError("Please specify your company name.");
		
	if (!fv.isSelected("country"))
		fv.raiseError("Please select your country.");	
		
	if (fv.isEmpty("contact_person"))
		fv.raiseError("Please specify your contact person.");
	
	if (fv.isEmpty("email"))
		fv.raiseError("Please specify an email address.");
	else
	{
		if (!fv.isEmailAddress("email"))
			fv.raiseError("Please specify a valid email address.");
	}
	
	if (fv.isEmpty("telephone_number"))
		fv.raiseError("Please specify your phone number.");
		
	if (fv.isEmpty("code"))
		fv.raiseError("Please specify the code being used for spam prevention.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
		return true;
}

function validateEntryStep2()
{
	fv = new formValidator();
	
	numAdults = new Number(fv.findObj("na").value);
	numChildren = new Number(fv.findObj("nc").value);
	
	for (i=1;i<=numAdults;i++)
	{
		adultAgeField = "adult_age_"+i;
		adultNameField = "adult_name_"+i;
		adultAddressField = "adult_address_"+i;
		adultEmailField = "adult_email_"+i;
		
		if (fv.findObj(adultNameField))
		{
			if (fv.isEmpty(adultNameField))
				fv.raiseError("Please specify the name of Adult #" + i);
		}
		
		if (fv.findObj(adultAgeField))
		{
			if (fv.isEmpty(adultAgeField))
				fv.raiseError("Please specify the age of Adult #" + i);
		}
		
		if (fv.findObj(adultAddressField))
		{
			if (fv.isEmpty(adultAddressField))
				fv.raiseError("Please specify the address for Adult #" + i);
		}		
	}
	
	for (i=1;i<=numChildren;i++)
	{
		childAgeField = "child_age_"+i;
		childNameField = "child_name_"+i;
		childAddressField = "child_address_"+i;
		childEmailField = "child_email_"+i;

		if (fv.findObj(childNameField))
		{
			if (fv.isEmpty(childNameField))
				fv.raiseError("Please specify the name of Child #" + i);
		}
		
		if (fv.findObj(childAgeField))
		{
			if (fv.isEmpty(childAgeField))
				fv.raiseError("Please specify the age of Child #" + i);
		}
		
		if (numAdults == 0)
		{
			if (fv.findObj(childAddressField))
			{
				if (fv.isEmpty(childAddressField))
					fv.raiseError("Please specify the address of Child #" + i);
			}
		}
	}
	
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
		return true;

}

function validateEntryStep1()
{
	fv = new formValidator();
	
	if (fv.findObj("num_adults").value == "0" && fv.findObj("num_children").value == "0")
		fv.raiseError("At least 1 adult or child must be specified in order to enter a race.");
		
	if (!fv.isChecked("terms"))
	  fv.raiseError("You cannot enter online without reading and agreeing to the Terms and Conditions.");
	
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
		return true;
}

function validateFunRun()
{
	fv = new formValidator();
	
	if (!fv.isSelected("funrun"))
		fv.raiseError("Please specify a fun run.");
	
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
		return true;
}
