function loadLocMap() {
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' " +
		"codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='600' height='540' " +
  	"id='world_usa_map' align='middle'>");
	document.write("<param name='allowScriptAccess' value='sameDomain' />");
  document.write("<param name='movie' value='world_map.swf' />");
  document.write("<param name='FlashVars' value='xmlfile1=world_map.xml&show_map=0'>");
  document.write("<param name='quality' value='high' />");
  document.write("<param name='wmode' value='transparent' />");
  document.write("<param name='bgcolor' value='#ffffff' />");
  document.write("<embed src='world_map.swf?xmlfile1=world_map.xml&show_map=0' quality='high' " +
  	"wmode='transparent' bgcolor='#ffffff' width='600' height='540' name='world_usa_map' " +
    "align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' " +
    "pluginspage='http://www.macromedia.com/go/getflashplayer/' />");
	document.write("</object>");
	//500x450
}


var sClickFlag = new String();
sClickFlag = "";

function set_text(div_name) {
	if (div_name=="main_back") {
		//clear top and bottom Country information when user clicks the back button
		document.getElementById("main_text").innerHTML=" ";
		//document.getElementById("main_instr").innerHTML=" ";
		document.getElementById("main_instr").style.display="none";
			sClickFlag = "";		
	} else {
		//display Country information
		sClickFlag = "main_text";
		document.getElementById("main_text").innerHTML=document.getElementById(div_name).innerHTML;
		//document.getElementById("btn" + div_name.replace("div","")).focus();
		document.getElementById("btnFocus").focus();
		window.scrollBy(0,80);
		document.getElementById("main_instr").style.display = "block";		
		
		txtMain = document.getElementById("main_text").getElementsByTagName("h3");
		var sCountry = txtMain[0].childNodes[0].nodeValue;
		
		txtInstr = document.getElementById("main_instr").getElementsByTagName("h2");
		txtInstr[0].childNodes[0].nodeValue = sCountry.substr(sCountry.indexOf("adopted")+8);
		
	}
}


function chkClick(sClick) {
	
	//alert(sClickFlag);

	switch (sClickFlag) {
		case "main_text" :
			sClickFlag = "";
			break;
		case "" :
			set_text("main_back");
			//sClickFlag = "";
			break;
	}
			/*
	switch (sClick) {
	case "down" :
		//alert(sClickFlag);
		break;
	case "up" :

		
		//if (sClickFlag!="main_text")
		//	set_text("main_back");		
		break;
	}
	*/
}


		
function showForm(btnId) {
	document.getElementById("btn"+btnId).style.display = "none";
	document.forms[0].style.display = "block";	
	window.scrollBy(0,300);
}



function writeForm(divId,sCountry) {
	var sRecipient = "sharingthedream@gov.bc.ca,rob.fiddler@gov.bc.ca";
	var sSubject = "School Adoption Form Submitted";
	var sRedirect = "http://www.sharingthedream.gov.bc.ca/adopt-a-country/formsubmitted.php";
	
	document.write("    <button id=\"btn" + divId + "\" onclick=\"showForm(\'" + divId + "\');\">Adopt this Country&hellip;</button>" +
    "<form name=\"frmAdoption\" method=\"post\" action=\"/cgi-bin/FormMail3-40c.pl\" enctype=\"multipart/form-data\" onSubmit=\"return chkForm();\">" +
      "<input type=\"hidden\" name=\"recipient\" value=\"" + sRecipient + "\" />" +
      "<input type=\"hidden\" name=\"Country\"	value=\"" + sCountry + "\" />" +
      "<input type=\"hidden\" name=\"subject\" value=\"" + sSubject + "\" />" +
      "<input type=\"hidden\" name=\"redirect\" value=\"" + sRedirect + "\" />" +
      "<input type=\"hidden\" name=\"required\" value=\"SchoolName,Address,City,PostalCode,DistrictName,DistrictNum,Email\" />    " +
      "<h4 style='margin-bottom: 0px;'>Enter your school's contact information:</h4>" +
			"<div style='margin-bottom: 10px;'>(registration limited to British Columbia schools):</div>" +
			"<div style='margin: 5px 10px 5px 10px; font-size: 0.9em;'>(<span class='required' style='font-size: 1em;'>*</span> = required field)</div>" +
      "<table summary=\"\">" +
        "<tr><td class=\"lcol\"><span class='required'>*</span>School Name:</td><td class=\"rcol\"><input type=\"text\" size=\"40\" maxlength=\"80\" name=\"SchoolName\" value=\"\" /></td></tr>" +
        "<tr><td class=\"lcol\"><span class='required'>*</span>Contact Name:</td><td class=\"rcol\"><input type=\"text\" size=\"40\" maxlength=\"80\" name=\"ContactName\" value=\"\" /></td></tr>" +
        "<tr><td><span class='required'>*</span>Address:</td><td><input type=\"text\" size=\"40\" maxlength=\"80\" name=\"Address\" value=\"\" /></td></tr>" +
        "<tr><td><span class='required'>*</span>City:</td><td><input type=\"text\" size=\"40\" maxlength=\"80\" name=\"City\" value=\"\" /></td></tr>" +
        "<tr><td><span class='required'>*</span>Postal Code:</td><td><input type=\"text\" size=\"40\" maxlength=\"7\" name=\"PostalCode\" value=\"\" /></td></tr>" +
        "<tr><td><span class='required'>*</span>District Name:</td><td><input type=\"text\" size=\"40\" maxlength=\"80\" name=\"DistrictName\" value=\"\" /></td></tr>" +
        "<tr><td><span class='required'>*</span>District #:</td><td><input type=\"text\" size=\"40\" maxlength=\"2\" name=\"DistrictNum\" value=\"\" /></td></tr>" +
        "<tr><td>&nbsp;&nbsp;Phone:</td><td><input type=\"text\" size=\"40\" maxlength=\"40\" name=\"Phone\" value=\"\" /></td></tr>" +
        "<tr><td>&nbsp;&nbsp;Fax:</td><td><input type=\"text\" size=\"40\" maxlength=\"40\" name=\"Fax\" value=\"\" /></td></tr>" +
        "<tr><td><span class='required'>*</span>E-mail:</td><td><input type=\"text\" size=\"40\" maxlength=\"80\" name=\"Email\" value=\"\" /></td></tr>" +
        "<tr><td>&nbsp;&nbsp;Website:</td><td><input type=\"text\" size=\"40\" maxlength=\"80\" name=\"Website\" value=\"\" /></td></tr>" +
      "</table>" +
			"<div style='margin: 5px 10px 10px 0px; font-size: 0.85em;'>Note: please click the submit button only once, as there may be a slight delay while your submission is being sent. Contact names are for internal use only and will be kept strictly confidential.</div>" +
      "<input class=\"submit\" type=\"submit\" value=\"Submit\" />" +
    "</form>");

}

function loadXML(file) {
	
	var xmldom = null;
	var XMLdoc = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLDOM") : new Object();


  try {
	  xmldom = new ActiveXObject("Microsoft.XMLHTTP");	
  }catch (e) {	
	  xmldom = new XMLHttpRequest();
  }	
	

	xmldom.onreadystatechange = function(){   
			if (xmldom.readyState == 4 && xmldom.status == 200){	
			if (window.ActiveXObject){			
				XMLdoc.loadXML(xmldom.responseText);
			 } else {			
				XMLdoc = xmldom.responseXML;	
			 }
		 }	 	 
		 
			result1 = XMLdoc.getElementsByTagName('photo');
			
			for (j=0; j < result1.length; j++){
			temp = new Array(2);	
			temp[0] = "<img src=\""  + result1[j].getElementsByTagName('path')[0].childNodes[0].nodeValue + "\">";	
			temp[1] = result1[j].getElementsByTagName('description')[0].childNodes[0].nodeValue;
			globalPicArray[j] = temp;    
			}	 
		 
	 }	
	
	xmldom.open("GET", file);
	xmldom.send(null);	
	
//	var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
//	xmlDoc.async="false";
//	xmlDoc.load(file);
}







//--==Form Validation==--

			//Sample Execution
			function chkForm() {//Main form validation function
				var err = new Boolean();
				noErrors = true;
				
				
				var aFlds = new Array("SchoolName","ContactName","Address","City","PostalCode","DistrictName","DistrictNum","Email");
				
				for (i in aFlds) {
					if (isDirtyText("forms[0]",aFlds[i])==false) {
						noErrors = false;
						break;
					}
				}
				
				if (noErrors==true && isEmail("forms[0]","Email")==false)
					noErrors = false;
				
				return noErrors;				
			}
			
			function isDirtyText(frm,fld) {//Check for null entry in a text field
				var oFld=eval("document." + frm + "."+fld);
  			var err=false;
				if (oFld.value=="" || oFld.value==null) {
					err=true;
				}
				// Return error message if field value is null
  			if (err==true) {
  				alert("Required field is empty!");
  				oFld.select();
					return false;
  			}
			}
			
			function isEmail(frm,fld) {//E-Mail validation script
				var email=eval("document." + frm + "."+fld);
				
  			var err=false;
				var iEmail=email.value.length;
				var aEmail=new Array(iEmail);
				
				//Populate array - each character in string is one value
				for (i=0;i<=iEmail;i++)
				  {
					aEmail[i]=email.value.charAt(i);
					}
					
				//Check string for illegal characters
				for (i=0;i<=iEmail;i++)
				  {//allows: -, _, ., @, 0-9, A-Z, a-z
					if ((aEmail[i].charCodeAt(0)!=45 && aEmail[i].charCodeAt(0)!=95) && (aEmail[i].charCodeAt(0)!=46 && aEmail[i].charCodeAt(0)!=64) && (aEmail[i].charCodeAt(0)<48  || (aEmail[i].charCodeAt(0)>57 && aEmail[i].charCodeAt(0)<65) || (aEmail[i].charCodeAt(0)>90 && aEmail[i].charCodeAt(0)<97) || aEmail[i].charCodeAt(0)>122))
						err=true;
					}
				
				//Ensure period has been entered in the proper place
  			if (email.value.indexOf("@")<0)
  				err=true;
  			else
  			  {
          if (email.value.lastIndexOf(".")<email.value.indexOf("@"))
            err=true;
  				}
        if (email.value.lastIndexOf(".")>=iEmail-2)
          err=true;	
				
				//Ensure no spaces exist				
				if (email.value.indexOf(" ")>=0)
				  err=true;
				
				// Return error message if e-mail address is invalid
  			if (err==true)
  			  {
  				alert("Invalid e-mail address!");
  				email.select();
					return false;
  				}
				}