/**************************************************************
FUNCTION INVENTORY FOR csws-istore-ajax.js
***************************************************************
1.  querySt(ji) :: Used to lookup querystring parameters in order to change search parameters and dropdown indexes.  ji is the string to search for.
2.  childImageTransition(id, opacStart, opacEnd, millisec) :: Used to face child image in and out between searches and next/previous buttons.  
3.  changeOpac(opacity, id) :: Used to change the opacity of an HTML element (used in childImageTransition)
4.  fadeImageIn(childImage) ::  This function is called from populateChildInfo.  When the child object is loaded from the Web Service, a dynamic image is created and loaded with the child image url from WebPics.  Once the image is fully loaded, the image is faded in.
5.  makeRequest(url) :: Builds the initial AJAX call based on the URL that's passed in and uses the request to call the createChildObj(httpRequest) function, which then creates the Child object.
6.  customDoProcessing(value) :: uses the "value" var  as an action to set new values to pass into the Web Service.  It then calls the buildRequestToWebService(wsReqObj) function to send a new request to Web Services and either create a new Child object or iterate through existing children in the arChildren[] array.
7.  initializeCSWS() :: used to call the Web service for the first time, based on global vars that are set through query string values.
8.  createChildObj(httpRequest) :: using the httpRequest object created in the makeRequest function, a child object is created and populated from the Web Service XML.  If the Web Service is being called for the first time, the country dropdown lists are also populated, based on the XML data returned.  If all was successful, the Child object is added to the arChildren[] array, and the populateChildInfo(newChildObj) function is then called to populate the HTML elements with the new Child object's data.
9.  populateChildInfo(newChildObj) :: this function renders the HTML elements of the page based on the Child object that is passed in.
10.  buyRouteServer() :: used in fixBuyRoute to fix any buyRoute issues so that the action to sponsor is always directed into the same environment where the child search is being performed.
11.  fixBuyRoute() ::  Fixes any buyRoute issues so that the action to sponsor is always directed into the same environment where the child search is being performed.
12.  changeIndexes() :: based on global vars, this function will change the indexes of the search dropdown menus.  Search dropdown menu values are then used to pass in any further CSWS calls instead of the querystring values.
13.  changeSearchType() :: on the initial load of the page, this function is used to change the index of the "CO" dropdown.  This functionality isn't included in changeIndexes, because changeIndexes() is run every time the "CO" dropdown value is changed.
14.  calcTime(city, offset) :: used to calculate the time that the error ocurred which caused the page to redirect to either the egift redirect or default istore sponsorship pages
15.  webSvcDownRedirect() :: if an error was thrown in another function, this function will be called to redirect to either the egift redirect or default istore sponsorship pages.
16.   changeTab(classname, id) :: used to alternate between the sponsorship info tabs of the istore look & feel design.
17.  validate(oFrm) :: used to validate the input of an alternate sponsorship amount in the istore look & feel design.
18.  newSponAmt(buyRoute) :: rewrites the buyroute of the Child object to be the value of the alternate sponsorship amount that has been entered in the istore look & feel design
19.   getInternetExplorerVersion() :: needed in order to correctly iterate through the XML object returned through the AJAX functionality within the createChildObj function.  IE8 uses functionality that is similar to FireFox and Chrome to get the XML object, but IE6 and 7 do not have this functionality and must convert import an HTML object into an HTML div tag, and then convert the div tag's inner HTML into an XML object.
20.  checkIEVersion() :: used to get the IE version and return true if the browser is IE8.
21.  loadCountryLists() :: this is an empty function that is left over from the old Flash version for compatability.
22.  age(bdate) :: used to determine the age of a child based on the Child object's 'born' date property. 
23.  loadDefaultContent :: a timer function that loads the AJAX CSWS calls only after determining first if the default content is the recipe.  Currently, this is the L&B design.
***************************************************************/
/**************************************************************
If the page will reside in istore, generate a different path to donation
***************************************************************/
path = "donate.worldvision.org";
//Setting to true right now since we're only using iStore for ajax version.  Later, we'll want to change this if
//we add functionality to use ajax in www.worldvision.org
isIstore = true;
if(window.location.href.indexOf("tprod.worldvision.org")!=-1){
	path="tprod.worldvision.org";
	isIstore = true;
}
if(window.location.href.indexOf("jade.worldvision.org")!=-1){
	path="jade.worldvision.org";
	isIstore = true;
}
if(window.location.href.indexOf("ambr.worldvision.org")!=-1){
	path="ambr.worldvision.org";
	isIstore = true;
}
if(window.location.href.indexOf("cyrus04.worldvision.org")!=-1){
	path="cyrus04.worldvision.org";
	isIstore = true;
}
else if(window.location.href.indexOf("othniel.wvus.org")!=-1){
	path="othniel.wvus.org"
	isIstore = true;
}
else if(window.location.href.indexOf("dprod.worldvision.org")!=-1){
	path="dprod.worldvision.org"
	isIstore = true;
}
else if(window.location.href.indexOf("prodproxy1.wvus.org")!=-1){
	path="prodproxy1.wvus.org"
	isIstore = true;
}
else if(window.location.href.indexOf("prodproxy2.wvus.org")!=-1){
	path="prodproxy2.wvus.org"
	isIstore = true;
}
else if(window.location.href.indexOf("prodproxy3.wvus.org")!=-1){
	path="prodproxy3.wvus.org"
	isIstore = true;
}
else if(window.location.href.indexOf("prodproxy4.wvus.org")!=-1){
	path="prodproxy4.wvus.org"
	isIstore = true;
}
else if(window.location.href.indexOf("donate.worldvision.org")!=-1){
	isIstore = true;
}
/**************************************************************
Base URL for Web Service calls
**************************************************************/
wsBaseURL = '';
if(isIstore){
	wsBaseURL= "xxwvChildWebService.jsp?"
}else{
	wsBaseURL= "/Worldvision/Spon-wsc.nsf/csws.xml?readform&"
}
/**************************************************************
Initiate the functions and global vars that will be loaded once the HTML elements are rendered
***************************************************************/
//We need to ensure first that the T&T campaign has been loaded or that T&T is disabled before we begin loading children.
//The default campaign contains a contentLoaded variable that is set.  So, we continually check to see if this variable is set
//And if it is, we can then load children. 
defaultContentLoaded =setInterval('loadDefaultContent()',1000);
var defaultTimeOut = 0
function loadDefaultContent(){	
	if (typeof contentLoaded!="undefined" && contentLoaded=="Default" || isMboxDisabled==true || defaultTimeOut >4){
		//Change the form index values to match the query string parameters using the changeIndexes function
		loadSearchType =setInterval('changeSearchType()',800);
		clearInterval(defaultContentLoaded)
		document.getElementById("hollow-template-container").style.display="block";
		initialCSWS =setInterval('initializeCSWS()',300);
		
		if(defaultTimeOut > 4){
			sendLPOS("timeout-default-content-loaded");
		}
	}else if(typeof contentLoaded!="undefined" && contentLoaded=="Slider"){
		document.getElementById("hollow-template-container").style.display="block";
	}
	if(typeof contentLoaded=="undefined" || (contentLoaded !="Default" && contentLoaded!="Slider") && defaultTimeOut < 6){
		defaultTimeOut++
	}
}
tryCount = 0;
arrayID = '';
wsReqObj = new Object();
var TimeToFade = 1000.0;
childImageIsLoaded=false;
arChildren = [];
/**************************************************************
Generate the variables that will be passed in the web service calls for search based on deeplink.
***************************************************************/
var campaign="";
var CG="";
var CA="";
var CBD="";
var CBM="";
var CO="";
var CST="";
var CL="";
var CP="";
var sponRes="";
var item = "";
if(querySt("campaign")){campaign=querySt("campaign")};
if(querySt("xxwvCampaign")){campaign=querySt("xxwvCampaign")};
if(querySt("CG")){CG=querySt("CG").toUpperCase()};
if(querySt("xxwvGender")){CG=querySt("xxwvGender").toUpperCase()};
if(querySt("CA")){CA=querySt("CA")};
if(querySt("xxwvAge")){CA=querySt("xxwvAge")};
if(querySt("CBD")){CBD=querySt("CBD")};
if(CBD.length==1){CBD="0" & CBD}
if(querySt("CBM")){CBM=querySt("CBM")};
if(CBM.length==1){CBM="0" & CBM}
if(querySt("xxwvBirthDate")){var arBirthDate=querySt("xxwvBirthDate").split("/")};
if(arBirthDate){
	CBM=arBirthDate[0];
	CBD=arBirthDate[1];
}
if(CBM!="" && CBD==""){CBD="01"}
if(CBD!="" && CBM==""){CBM="01"}
if(querySt("CO")){CO=querySt("CO")};
if(querySt("CST")){CO=querySt("CST")};
if(querySt("xxwvOrphan")){CO=querySt("xxwvOrphan")};
if(querySt("xxwvSearchType")){CO=querySt("xxwvSearchType")};
if(CO=="SPON"){CO="NONHOPE"};
if(querySt("CL")){CL=querySt("CL")};
if(querySt("xxwvLocation")){CL=querySt("xxwvLocation")};
if(querySt("CP")){CP=querySt("CP")};
if(querySt("xxwvProject")){CP=querySt("xxwvProject")};
if(querySt("sponRes")){sponRes=querySt("sponRes")};
if(querySt("xxwvRes")){sponRes=querySt("xxwvRes")};
if(querySt("item")){item=querySt("item")};
/**************************************************************
Create query string parser to grab qs params before default fields in form are populated
***************************************************************/
function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}
/**************************************************************
Send LPOS to SiteCatalyst
***************************************************************/
function sendLPOS(lpos){
   if(window.location.href.indexOf("donate.worldvision.org")!=-1){
	var account="wvdonatewvus,wvmastersuite";
   }else{
        var account="wvdonatewvusdev,wvrollupsuite";
   }
   s_objectID=lpos;
   var s=s_gi(account);
   s.linkTrackVars='prop32'; 
   arPageName = WVOM.pageName.split("|");
   var lposPageName = "";
   var indexOfNewIstore = "";
   for(var i=0;i<arPageName.length;i++){
     if(arPageName[i].indexOf("Giving_Center")!=-1){
       arPageName[i]="";
     }
     if(arPageName[i].indexOf("By_Category")!=-1){
       arPageName[i]="";
     }
     if(arPageName[i].indexOf("(New iStore)")!=-1){
       indexOfNewIstore = arPageName[i].indexOf("("); 
       arPageName[i]=arPageName[i].substring(0,indexOfNewIstore);
     }
     if(arPageName[i]!=""){
       lposPageName += arPageName[i] + "|";
     }
   }
   s.prop32=lposPageName.substring(lposPageName.length, lposPageName.length-50) + " :: " + lpos;
   s.tl(this,'o',lpos);
}
/**************************************************************
Functions for child image animation
***************************************************************/
function childImageTransition(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
function fadeImageIn(childImage){
	if(document.getElementById('childInfoPicture')){
		if(childImage.complete && childImageIsLoaded==false && document.getElementById('childInfoPicture').style.opacity == 0 ){
			clearInterval(checkImageLoaded);
			if(document.getElementById("childInfoPicture"))document.getElementById('childInfoPicture').style.visibility='visible';
			if(document.getElementById("childInfoPictureShadow"))document.getElementById('childInfoPictureShadow').style.visibility='visible';
			if(document.getElementById("childInfoPictureShadow"))document.getElementById('childInfoPictureShadow').style.opacity = 0;
			if(document.getElementById("childInfoPictureShadow"))document.getElementById('childInfoPictureShadow').style.filter = 'alpha(opacity=0)';
			if(document.getElementById("childInfoPicture"))document.getElementById('childInfoPicture').style.opacity = 0;
			if(document.getElementById("childInfoPicture"))document.getElementById('childInfoPicture').style.filter = 'alpha(opacity=0)';
			if(document.getElementById("childInfoPicture"))childImageTransition('childInfoPicture',0,100,500);
			if(document.getElementById("childInfoPictureShadow"))childImageTransition('childInfoPictureShadow',0,100,500);
			if(document.getElementById("imageURL"))document.getElementById("imageURL").src = childImage.src;
			childImageIsLoaded=true;
		}
	}	
} //end  fadeImageIn()
/********************************************************************
Functions used to generate the Web Service calls
********************************************************************/
function makeRequest(url) {
        var httpRequest;
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
            }
        }
        if (!httpRequest) {
            //alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() { createChildObj(httpRequest); };
        httpRequest.open('GET', url, true);
        httpRequest.send('');
}
function customDoProcessing(value){
	wsReqObj.actionReq = value;
	if (value=='previous'){
		//wsReqObj.childArray = arChildren[c-1].childArray;
		//wsReqObj.arrayLoc = arChildren[c-1].arrayLoc;
		populateChildInfo( arChildren[c-1])
	}else if (value=='next' && arChildren[c+1]!=undefined){
		populateChildInfo( arChildren[c+1])
	}else{	
		wsReqObj.childArray = arChildren[arChildren.length-1].childArray;
		wsReqObj.arrayLoc = arChildren[arChildren.length-1].arrayLoc;
		buildRequestToWebService(wsReqObj);
	}
}
function buildRequestToWebService(wsReqObj){
	unid_date = new Date();
   	unid = unid_date.getTime();
		wsReqObj.campaign=campaign;
		wsReqObj.gender = document.getElementById("CG").options[document.getElementById("CG").selectedIndex].value;
		if (wsReqObj.gender=="\"\"") wsReqObj.gender="";
		wsReqObj.age = (document.getElementById("CA").selectedIndex - 1).toString();
		if (wsReqObj.age=="-1") wsReqObj.age="";
	var valCBM = 	document.getElementById("CBM").options[document.getElementById("CBM").selectedIndex].text;
	var valCBD = document.getElementById("CBD").options[document.getElementById("CBD").selectedIndex].text
	if(valCBD!="dd" && valCBM=="mm"){
		wsReqObj.birthMonth = "01"
	}else{
		wsReqObj.birthMonth = valCBM;
	}
	if(valCBM!="mm" && valCBD=="dd"){
		wsReqObj.birthDay = "01";
	}else{
		wsReqObj.birthDay = valCBD;	
	}
	
	var CPSearch="";
	if(document.getElementById("CP")){
		if(document.getElementById("CP").checked==false){
			CPSearch="";
		}else{
			CPSearch=CP;
		}
	}
		wsReqObj.searchType = document.getElementById("searchType").options[document.getElementById("searchType").selectedIndex].value;
		if(wsReqObj.searchType == "ALL"){
			wsReqObj.childLocation = document.getElementById("dlgTypeAll").options[document.getElementById("dlgTypeAll").selectedIndex].value;
		}else if(wsReqObj.searchType=="NONHOPE"){
			wsReqObj.childLocation = document.getElementById("dlgTypeNon").options[document.getElementById("dlgTypeNon").selectedIndex].value;
		}else if(wsReqObj.searchType=="HOPE"){
			wsReqObj.childLocation = document.getElementById("dlgTypeHope").options[document.getElementById("dlgTypeHope").selectedIndex].value;
		}
		if(CPSearch==CP && CP!=""){
			wsReqObj.childLocation = "";
		}
		var childArray ="";
		var childArrayLoc ="";
		if(isIstore){
			childArray="&xxwvChildArray="+wsReqObj.childArray
			childArrayLoc="&xxwvArrayLoc=" + wsReqObj.arrayLoc
		}else{
			childArray="&kids="+wsReqObj.childArray
			childArrayLoc="&kidi="+ wsReqObj.arrayLoc
		}
		wsReqObj.childProject = CPSearch;
		wsReqObj.eventRes = sponRes;
		wsReqObj.eventResCampaign = campaign;
		//wsReqObj.xxwvChildArray = '';
		//wsReqObj.ArrayLoc = '0';  
		wsReqObj.unid = unid.toString();
		wsReqObj.securityToken='';
		wsReqObj.log = '';
		wsUrl=wsBaseURL
		+ "xxwvAction=search"
		+ "&xxwvOrphan=" + wsReqObj.searchType
		+ "&xxwvLocation=" + wsReqObj.childLocation
		+ "&xxwvProject=" + wsReqObj.childProject 
		+ "&xxwvCampaign=" + campaign
		+  childArray
		+  childArrayLoc
		+ "&xxwvEventRes=" + sponRes
		+ "&xxwvEvtResCampaign=" + campaign
		+ "&xxwvGender=" + wsReqObj.gender
		+ "&xxwvMonth=" + wsReqObj.birthMonth
		+ "&xxwvDay=" + wsReqObj.birthDay
		+ "&xxwvAge=" + wsReqObj.age
		+ "&unid=" + unid.toString()
		+ "&securityToken="
		+ "&log=";
		makeRequest(wsUrl)	
}
function initializeCSWS() {
	if(document.getElementById("dlgTypeAll") && document.getElementById("dlgTypeNon") && document.getElementById("dlgTypeHope")){
		clearInterval(initialCSWS);
		var unid_date = new Date();
		var unid = unid_date.getTime();
		if (item==""){
			wsUrl = wsBaseURL
			+ "xxwvAction=search"
			+ "&xxwvOrphan=" + CO
			+ "&xxwvLocation=" + CL
			+ "&xxwvProject=" + CP
			+ "&xxwvCampaign=" + campaign
			+ "&xxwvChildArray=" 
			+ "&xxwvArrayLoc=0"
			+ "&xxwvEventRes=" + sponRes
			+ "&xxwvEvtResCampaign=" + campaign
			+ "&xxwvGender=" + CG
			+ "&xxwvMonth=" + CBM
			+ "&xxwvDay=" + CBD
			+ "&xxwvAge=" + CA
			+ "&unid=" + unid.toString()
			+ "&securityToken="
			+ "&log=" ;
			makeRequest(wsUrl)
		}else{
			wsUrl = wsBaseURL
			+ "xxwvAction=next"
			+ "&xxwvChildArray=" + item
			makeRequest(wsUrl);
		}
	}
}
function sendSearchVars() {
	customDoProcessing("search");
}
function resetEventRes(frmReservation){
	wsReqObj.sponRes = frmReservation;
}
function nextButton() {
	customDoProcessing("next");
}
function previousButton() {
	customDoProcessing("previous");
}
function createChildObj(httpRequest){
       childObj = new Object();
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
//Just to check if it is a different navigator from internet explorer
if (typeof document.implementation !="undefined" && typeof document.implementation.createDocument!="undefined"){
     requestObj = httpRequest.responseXML;
//In case of internet explorer
} else if (typeof window.ActiveXObject != "undefined" && checkIEVersion() ==false){
//Create a xml tag in run time
     var testandoAppend = document.createElement('xml');
//Put the requester.responseText in the innerHTML of the xml tag
      testandoAppend.setAttribute('innerHTML',httpRequest.responseText);
//Set the xml tag's id to _formjAjaxRetornoXML
     testandoAppend.setAttribute('id','_formjAjaxRetornoXML');
//Add the created tag to the page context
     document.body.appendChild(testandoAppend);
//Just to check, put the xmlhttp.responseXML in the innerHTML of the tag
     document.getElementById('_formjAjaxRetornoXML').innerHTML = httpRequest.responseText;
//Now we can get the xml tag and put it on a var
     requestObj = document.getElementById('_formjAjaxRetornoXML');
//So we have a valid xml we can remove the xml tag         
     document.body.removeChild(document.getElementById('_formjAjaxRetornoXML'));
}else{
     requestObj = httpRequest.responseXML;
}
//childObjLoader =setInterval('loadChildObject(requestObj)',500);
loadChildObject(requestObj);
            } else {
	//webSvcDownRedirect(httpRequest.status);
            }
        }
}
function loadChildObject(requestObj){
if(requestObj && requestObj.hasChildNodes){
item = "";
if(document.getElementById("dlgTypeHope")){var dlgTypeHope = 		document.getElementById("dlgTypeHope");}
if(document.getElementById("dlgTypeAll")){var dlgTypeAll = document.getElementById("dlgTypeAll");}
if(document.getElementById("dlgTypeNon")){var dlgTypeNon = document.getElementById("dlgTypeNon");}
for(n = 0; n < requestObj.childNodes.length; n++){
	if (requestObj.childNodes[n].nodeName=="spon"){
		x = requestObj.childNodes[n];
	}
}
//if(typeof x=='undefined'){alert('test')};
	//Iterate through the child nodes to get the XML and add to the child object
	for (i = 0; i < x.childNodes.length;i++){
		if(x.childNodes[i].nodeName=='request'){
			//<request> element values
			for(k = 0; k < x.childNodes[i].childNodes.length; k++ ){
				if(x.childNodes[i].childNodes[k].nodeName=='gender' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.gender=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='project' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.project=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='birthdate' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.birthdate=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='birthMonth' && x.childNodes[i].childNodes[k].firstChild!=null){
				childObj.birthMonth=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='birthDay' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.birthDay=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='age' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.age=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='location' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.location=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='handicap' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.handicap=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='orphan' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.orphan=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='childArray' && x.childNodes[i].childNodes[k].firstChild!=null){
				childObj.childArray=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='arrayLoc' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.arrayLoc=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='searchType' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.searchType=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='org' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.org=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='language' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.language=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='campaign' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.campaign=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[k].nodeName=='eventRes' && x.childNodes[i].childNodes[k].firstChild!=null){
					childObj.eventRes=x.childNodes[i].childNodes[k].firstChild.nodeValue;
				}
			}
		}
		else if(x.childNodes[i].nodeName=='response'){
			//<response> element values
			for(l = 0; l < x.childNodes[i].childNodes.length; l++ ){
				if(x.childNodes[i].childNodes[l].nodeName=='item' && x.childNodes[i].childNodes[l].firstChild!=null ){
					childObj.item=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='errorMsg' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.errorMsg=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='buyRoute' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.buyRoute=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='formAction' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.formAction=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='section' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.section=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='childId' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.childId=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='childTitle' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.childTitle=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='firstName' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.firstName=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='country' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.country=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='project' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.project=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='imageURL' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.imageURL=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='price' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.price=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='preDonation' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.preDonation=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='instructions' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.instructions=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='born' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.born=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='grade' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.grade=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='subject' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.subject=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='health' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.health=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='play' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.play=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='gender' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.gender=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
				if(x.childNodes[i].childNodes[l].nodeName=='chores' && x.childNodes[i].childNodes[l].firstChild!=null){
					childObj.chores=x.childNodes[i].childNodes[l].firstChild.nodeValue;
				}
			}
		}
		else if(x.childNodes[i].nodeName=='locations'){
			//<location> element values for country dropdowns
			if (dlgTypeHope.length==0 || dlgTypeNon.length==0 || dlgTypeAll.length==0){
			for(m = 0; m < x.childNodes[i].childNodes.length; m++ ){
				if(x.childNodes[i].childNodes[m].nodeName=='hope' && x.childNodes[i].childNodes[m].firstChild!=null ){
countries = x.childNodes[i].childNodes[m].getElementsByTagName("location");
					for(n=0;n<=countries.length-1;n=n+1){
						country = countries[n];
						dlgTypeHope.options[dlgTypeHope.length] = new Option( country.getAttribute("display"),country.getAttribute("id"));
						//dlgTypeHope.options[n].style.paddingLeft="10px";
						if(country.getAttribute("level")=="0"){
							//
						}
						else if(country.getAttribute("level")=="1"){
dlgTypeHope.options[n].innerHTML = "&nbsp;" + dlgTypeHope.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="2"){
dlgTypeHope.options[n].innerHTML = "&nbsp;&nbsp;" + dlgTypeHope.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="3"){
dlgTypeHope.options[n].innerHTML = "&nbsp;&nbsp;&nbsp;" + dlgTypeHope.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="4"){
dlgTypeHope.options[n].innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;" + dlgTypeHope.options[n].innerHTML;
							//dlgTypeNon.options[n].style.paddingLeft="20px";
						}else{
							indent = "";
						}	
					}
				}
				if(x.childNodes[i].childNodes[m].nodeName=='nonHope' && x.childNodes[i].childNodes[m].firstChild!=null ){
countries = x.childNodes[i].childNodes[m].getElementsByTagName("location");
					for(n=0;n<=countries.length-1;n=n+1){
						country = countries[n];
dlgTypeNon.options[dlgTypeNon.length] = new Option( country.getAttribute("display"),country.getAttribute("id"));						
						//dlgTypeNon.options[n].style.paddingLeft="10px";
						if(country.getAttribute("level")=="0"){
							//
						}
						else if(country.getAttribute("level")=="1"){
dlgTypeNon.options[n].innerHTML = "&nbsp;" + dlgTypeNon.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="2"){
dlgTypeNon.options[n].innerHTML = "&nbsp;&nbsp;" + dlgTypeNon.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="3"){
dlgTypeNon.options[n].innerHTML = "&nbsp;&nbsp;&nbsp;" + dlgTypeNon.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="4"){
dlgTypeNon.options[n].innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;" + dlgTypeNon.options[n].innerHTML;
							//dlgTypeNon.options[n].style.paddingLeft="20px";
						}else{
							indent = "";
						}	
					}
				}
				if(x.childNodes[i].childNodes[m].nodeName=='all' && x.childNodes[i].childNodes[m].firstChild!=null ){
countries = x.childNodes[i].childNodes[m].getElementsByTagName("location");
					for(n=0;n<=countries.length-1;n=n+1){
						country = countries[n];
						dlgTypeAll.options[dlgTypeAll.length] = new Option( country.getAttribute("display"),country.getAttribute("id"));
						//dlgTypeAll.options[n].style.paddingLeft="10px";
						if(country.getAttribute("level")=="0"){
							//
						}
						else if(country.getAttribute("level")=="1"){
dlgTypeAll.options[n].innerHTML = "&nbsp;" + dlgTypeAll.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="2"){
dlgTypeAll.options[n].innerHTML = "&nbsp;&nbsp;" + dlgTypeAll.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="3"){
dlgTypeAll.options[n].innerHTML = "&nbsp;&nbsp;&nbsp;" + dlgTypeAll.options[n].innerHTML;
						}
						else if(country.getAttribute("level")=="4"){
dlgTypeAll.options[n].innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;" + dlgTypeAll.options[n].innerHTML;
							//dlgTypeNon.options[n].style.paddingLeft="20px";
						}else{
							indent = "";
						}	
					}
				}
				}
			loadIndexes =setInterval('changeIndexes()',600);
			}
		
		}
		}
	//Add the child object into the array and populate the HTML elements with the new child 	XML data.  If there was a status error, redirect the browser.
	arrayID = parseInt(childObj.arrayLoc)
	if(arChildren[arrayID]==null){ 
		arChildren.push(childObj);
		populateChildInfo(childObj);
	}
}else{
	tryCount += 1
	if(tryCount < 3){
		initialCSWS =setInterval('initializeCSWS(tryCount)',1000);
	}
	else{
		//webSvcDownRedirect('InvalidXML');
	}
}
}
/**************************************************************
The Web Service has returned child information, which we can now populate into the HTML
***************************************************************/
function populateChildInfo(newChildObj){
c = parseInt(newChildObj.arrayLoc);
	childInfoIsLoaded = false; 
	if(newChildObj.errorMsg){
		if(document.getElementById("childInfoContent_div")){
			if(typeof divH =="undefined"||divH==""){
				divH = document.getElementById("childInfoContent_div").style.height;
				divH = divH.substring(0,3);
				divH = parseFloat(divH);
				divH = divH + 35;
				divH = divH.toString() + "px";
				document.getElementById("childInfoContent_div").style.height = divH;
				document.getElementById("top_div").style.height = divH;
			}
		}
		document.getElementById("errorMsg").innerHTML = unescape("We apologize, we are unable to locate a child that matches your request, instead below please find a child similar to your original request.");
		document.getElementById("errorMsg").style.display="block";
	}else{
		document.getElementById("errorMsg").innerHTML = "";
		document.getElementById("errorMsg").style.display="none";
		if (typeof divH !="undefined" && divH!=""){
			divH = document.getElementById("childInfoContent_div").style.height;
			divH = divH.substring(0,3);
			divH = parseFloat(divH);
			divH = divH - 35;
			divH = divH.toString() + "px";
			document.getElementById("childInfoContent_div").style.height = divH;
			document.getElementById("top_div").style.height = divH;
			divH="";
		}
	}
	isHopeChild=false;
	if(newChildObj.preDonation){
		if(newChildObj.preDonation.indexOf("HopeChild")!=-1){
	   		isHopeChild=true;
		}else{
	  		 isHopeChild=false;
		}	
	}
	if(document.getElementById("sponsorshipChoice")){
					if(isHopeChild){
						document.getElementById("sponsorshipChoice").innerHTML = "a HopeChild";
						document.getElementById("sponsor-tab2content").innerHTML="A HopeChild is a child living in a community affected by AIDS. As a HopeChild sponsor, you are connected with one special child who will know your name, write to you, and feel your tender love and prayers. Your monthly sponsorship gift can help turn the tide of the HIV and AIDS pandemic! You can provide things such as:<ul><li>Clean Water</li><li>Nutritious Food</li><li>Health Care, including AIDS Prevention</li><li>Educational Opportunities</li><li>Spiritual Nurture</li><li>Care for Sick or Dying Parents</li><li>HIV and AIDS counseling</li></ul>";
					}
					else{
						document.getElementById("sponsorshipChoice").innerHTML = "";
						document.getElementById("sponsor-tab2content").innerHTML="As a child sponsor, you are connected with one special child who will know your name, write to you and feel your tender love and prayers. Your monthly sponsorship gift will provide a child with things such as: <ul><li>Clean Water</li><li>Nutritious Food</li><li>Health Care</li><li>Educational Opportunities</li><li>Spiritual Nurture</li></ul>";
					}
			}
		if(document.getElementById("aboutSponsorshipTitle")){
				if(isHopeChild){
					document.getElementById("aboutSponsorshipTitle").innerHTML = "About HopeChild Sponsorship";
				}
				else{
					document.getElementById("aboutSponsorshipTitle").innerHTML = "About Sponsorship";
				}
	}
childImageIsLoaded=false;
if(document.getElementById("childInfoPictureShadow"))document.getElementById('childInfoPictureShadow').style.opacity = 100;
		if(document.getElementById("childInfoPictureShadow"))document.getElementById('childInfoPictureShadow').style.filter = 'alpha(opacity=100)';
		if(document.getElementById("childInfoPicture"))document.getElementById('childInfoPicture').style.opacity =100;
		if(document.getElementById("childInfoPicture"))document.getElementById('childInfoPicture').style.filter = 'alpha(opacity=100)';
		if(document.getElementById("childInfoPicture"))childImageTransition('childInfoPicture',100,0,500);
		if(document.getElementById("childInfoPictureShadow"))childImageTransition('childInfoPictureShadow',100,0,500);
//Create the new child image and load the child object's url into it.	
childImage = new Image();
childImage.src =  newChildObj.imageURL;
if(document.getElementById('childInfoPicture')){
	if(childImageIsLoaded==false && document.getElementById('childInfoPicture').style.opacity ==100 ){
		checkImageLoaded = setInterval('fadeImageIn(childImage)',500);
	}
}
	if(document.getElementById("moreAboutTitle"))document.getElementById("moreAboutTitle").innerHTML = "More About " +newChildObj.firstName;
	if(document.getElementById("childTitle"))document.getElementById("childTitle").innerHTML = newChildObj.childTitle;
	if(document.getElementById("smallSponsorLink"))document.getElementById("smallSponsorLink").href = fixBuyRoute(newChildObj.buyRoute);
	if(document.getElementById("largeSponsorLink"))document.getElementById("largeSponsorLink").href = fixBuyRoute(newChildObj.buyRoute);
	if(document.getElementById("sponsorAmtForm"))document.getElementById("sponsorAmtForm").action = newSponAmt(newChildObj.buyRoute);
	//if(document.getElementById("imageURL"))document.getElementById("imageURL").src = newChildObj.imageURL;
	if(document.getElementById("childImageLink"))document.getElementById("childImageLink").href = fixBuyRoute(newChildObj.buyRoute);
	if(document.getElementById("Name"))document.getElementById("Name").innerHTML = newChildObj.firstName;
	if(document.getElementById("Gender"))document.getElementById("Gender").innerHTML = newChildObj.gender;
	if(document.getElementById("Born"))document.getElementById("Born").innerHTML = newChildObj.born;
	if(document.getElementById("Grade"))document.getElementById("Grade").innerHTML = newChildObj.grade;
	if(document.getElementById("Country"))document.getElementById("Country").innerHTML = newChildObj.country;
	if(document.getElementById("Health"))document.getElementById("Health").innerHTML = newChildObj.health;
	if(document.getElementById("Amt"))document.getElementById("Amt").innerHTML = newChildObj.price;
	if(document.getElementById("smallSponsorButton"))document.getElementById("smallSponsorButton").style.color="white";
	if(document.getElementById("smallSponsorButton"))document.getElementById("smallSponsorButton").innerHTML = "Sponsor " + newChildObj.firstName + " now";
	if(document.getElementById("sponsorChildTitle"))document.getElementById("sponsorChildTitle").innerHTML = "Sponsor " + newChildObj.firstName + " in " + newChildObj.country;
	if(document.getElementById("sponsorChildTitleLink"))document.getElementById("sponsorChildTitleLink").innerHTML = "<a id='sponsorChildTitleA' href='"+fixBuyRoute(newChildObj.buyRoute)+"'>Sponsor " + newChildObj.firstName + " in " + newChildObj.country + "</a>";
if(document.getElementById("sponsorChildTitleLink-FirstPerson"))document.getElementById("sponsorChildTitleLink-FirstPerson").innerHTML = "Hi!  My name is " + newChildObj.firstName;
	if(document.getElementById("largeSponsorshipButton"))document.getElementById("largeSponsorshipButton").innerHTML = "Sponsor<br>" + newChildObj.firstName + "<br>now";
if(document.getElementById("largeSponsorshipButton2"))document.getElementById("largeSponsorshipButton2").innerHTML = "Sponsor<br>" + newChildObj.firstName + "<br>now";
	
	if(isHopeChild){
		if(document.getElementById("AIDSAffectedLogo"))document.getElementById("AIDSAffectedLogo").style.display="block";
	}else{
		if(document.getElementById("AIDSAffectedLogo"))document.getElementById("AIDSAffectedLogo").style.display="none";
	}
	if (unescape(newChildObj.chores) == "Doesn'T Help - Too Young"){
			newChildObj.chores = "Too Young";
	}
//BEGIN CODE TO CHANGE PREDONATION IF HAITI (HEA MESSAGING)
	var gen = 'him';
		var gen2= 'his';
		if (newChildObj.gender == 'Girl') {
			gen = 'her';
			gen2 = 'her';
		}
		//TEMP For Haiti PreDonation
		if (newChildObj.country == 'Haiti') {
			newChildObj.preDonation = newChildObj.firstName + ' is a <a href=http://www.worldvision.org/worldvision/master.nsf/sponsorship_types?Open target=_blank>HopeChild</a> living in Haiti, a country recently devastated by a powerful 7.0-magnitude earthquake. When you sponsor a child like '+
			newChildObj.firstName + ', you help provide '+ gen +' with critical basics that will help '+ gen +' better cope with disasters like the recent earthquake &#8212 essentials such as food, clean water, healthcare, education, safe shelter, and more. '
			+ newChildObj.firstName + ' has been reserved for you to sponsor within the next five minutes. Just click the "Sponsor '+ newChildObj.firstName +'" button below to become '+ gen2 +' sponsor right now!';
		}
//END HAITI HEA MESSAGING
	if(document.getElementById("Chores"))document.getElementById("Chores").innerHTML = unescape(newChildObj.chores);
	if(document.getElementById("Subject"))document.getElementById("Subject").innerHTML = unescape(newChildObj.subject);
	if(document.getElementById("Play"))document.getElementById("Play").innerHTML = newChildObj.play;
	if(document.getElementById("childInfo"))document.getElementById("childInfo").innerHTML = newChildObj.preDonation;
	if(document.getElementById("childInfo-FirstPerson") && (isHopeChild==true))document.getElementById("childInfo-FirstPerson").innerHTML = "My name is " + newChildObj.firstName + ".  I live in " + newChildObj.country + ", in a community severely affected by the AIDS epidemic.  In communities like mine, the disease has created an entire generation of orphans and vulnerable children.  As my sponsor, you will be providing access to water, health, education, and opportunities for economic development.  You'll also be helping to save me and those in my community from the AIDS crisis.  Click the \"Sponsor Now\" button to become my sponsor.  I look forward to getting to know you."
if(document.getElementById("childInfo-FirstPerson") && (isHopeChild==false))document.getElementById("childInfo-FirstPerson").innerHTML = "My name is " + newChildObj.firstName + ".  I'm a " + age(newChildObj.born) + " year old from " + newChildObj.country + ".  Your support is critical to providing me with things like clean water, nutritious food, and an education.  As my sponsor, you will be ensuring that I have the opportunity to thrive, and grow up healthy; and that I will have the skills I need to provide for myself in the future.  Click the \"Sponsor Now\" button to become my sponsor.  I look forward to getting to know you."
if(document.getElementById("dynBodyLink1")){
	document.getElementById("dynBodyLink1").innerHTML = "<a href='" + fixBuyRoute(newChildObj.buyRoute) +"'>save " + newChildObj.firstName + "</a>";
}
if(document.getElementById("dynBodyLink2")){
	document.getElementById("dynBodyLink2").innerHTML = "<a href='" + fixBuyRoute(newChildObj.buyRoute) +"'>sponsor " + newChildObj.firstName + "</a>";
}
if(document.getElementById("dynBodyLink3")){
	document.getElementById("dynBodyLink3").innerHTML = "<a href='" + fixBuyRoute(newChildObj.buyRoute) +"'>Become a child sponsor through World Vision and sponsor " + newChildObj.firstName + " today</a>!";
}
	if(parseInt(newChildObj.arrayLoc)>0){
		if(document.getElementById("previousButton"))document.getElementById("previousButton").style.display="block";
		if(document.getElementById("previousLink"))document.getElementById("previousLink").style.display="block";
	}else{
		if(document.getElementById("previousButton"))document.getElementById("previousButton").style.display="none";
		if(document.getElementById("previousLink"))document.getElementById("previousLink").style.display="none";
	}
	if((!newChildObj.imageURL) || (newChildObj.imageURL=="")){
			//window.location.replace("xxwv2DoChildSearch.jsp");
			//webSvcDownRedirect('ImageNotLoaded');
	}
	
	/**************************************************************
	Disable right click on image
	***************************************************************/
	 var isNS = (navigator.appName == "Netscape") ? 1 : 0;
	  if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
	  function mischandler(){
	   return false;
	 }
	  function mousehandler(e){
	 	var myevent = (isNS) ? e : event;
	 	var eventbutton = (isNS) ? myevent.which : myevent.button;
	    if((eventbutton==2)||(eventbutton==3)) return false;
	 }
	 document.getElementById("imageURL").oncontextmenu = mischandler;
	 document.getElementById("imageURL").onmousedown = mousehandler;
 	 document.getElementById("imageURL").onmouseup = mousehandler;
	
	childInfoIsLoaded=true;
	
	//BEGIN Omniture SiteCatalyst Code Version H.14 
	if (isIstore){
		setHollowSiteCat();
	}
}
        
/***************************************************************
Fixes for BuyRoute
***************************************************************/
function buyRouteServer(){
	var server="donate.worldvision.org";
	if(window.location.href.indexOf("tprod.worldvision.org")!=-1){
		server="tprod.worldvision.org";
	}
	else if(window.location.href.indexOf("dprod.worldvision.org")!=-1){
		server="dprod.worldvision.org";
	}
	else {
		server="donate.worldvision.org";
	}
	return server;
}
function fixBuyRoute(buyRoute){
	//For now, just use relative paths - JM :
	//var server = buyRouteServer();
	//var arBuyRoute = buyRoute.split("/OA_HTML");
	//var restOfBuyRoute = arBuyRoute[1];
	//return "http://" + server + "/OA_HTML" + restOfBuyRoute;
	return buyRoute;
}
   
/**************************************************************
Change the selected index of the search fields based on deep link parameters
***************************************************************/
function changeIndexes(){
	if(document.getElementById("dlgTypeAll") && document.getElementById("dlgTypeHope") && document.getElementById("dlgTypeNon")){
		clearInterval(loadIndexes);
		for (i=0; i <= (document.getElementById("dlgTypeAll").options.length -1);i++)
			{
				if(document.getElementById("dlgTypeAll").options[i].value==CL){
					document.getElementById("dlgTypeAll").options[i].selected=true;
				}
			}
		for (i=0; i <= (document.getElementById("dlgTypeHope").options.length -1);i++)
			{
				if(document.getElementById("dlgTypeHope").options[i].value==CL){
					document.getElementById("dlgTypeHope").options[i].selected=true;
				}
			}
		for (i=0; i <= (document.getElementById("dlgTypeNon").options.length -1);i++)
			{
				if(document.getElementById("dlgTypeNon").options[i].value==CL){
					document.getElementById("dlgTypeNon").options[i].selected=true;
				}
			}
		if (CG=="M"){
			if(isIstore){
				document.getElementById("CG").selectedIndex=1;
			}else{
				document.getElementById("CG").selectedIndex=0;
			}
		}else if(CG=="F"){
			if(isIstore){
				document.getElementById("CG").selectedIndex=2;
			}else{
				document.getElementById("CG").selectedIndex=1;
			}
		}
		if (CA!=""){
			document.getElementById("CA").selectedIndex = parseInt(CA) + 1;
		}
		if (CBM!=""){
			document.getElementById("CBM").selectedIndex = CBM;
		}
		if (CBD!=""){
			document.getElementById("CBD").selectedIndex = CBD;
		}
		if (CP!=""){
			document.getElementById("Reserve_div").innerHTML = "<input type=\"checkbox\" name=\"xxwvProject\" id=\"CP\" CHECKED onclick=\"CPCheck(this)\" style=\"float:left;margin-right:8px;*margin-top:-3px\"><div style=\"font-size:12px\">Children in community " + CP + "</div>";
			document.getElementById("Reserve_div").style.display="block";
		}
		if(sponRes=="Y" && campaign!=""){
			if(document.getElementById("sponsorResMsg")){document.getElementById("sponsorResMsg").style.display="block"}
			document.getElementById("Reserve_div").innerHTML = "<input type=\"checkbox\" name=\"sponResCheck\" id=\"sponResCheck\" CHECKED onclick=\"setResPool(this)\" style=\"float:left;margin-right:8px;\"><div style=\"font-size:12px\">Children reserved for my event</div>";
			document.getElementById("Reserve_div").style.display="block";
		}
		/**************************************************************
		// display proper location drop-down based on spon type
		***************************************************************/
		myListType = document.getElementById("searchType").options[document.getElementById("searchType").selectedIndex].value;
		    if (myListType == "ALL")
		    { document.getElementById("dlgTypeAll").style.display = "block";
		      document.getElementById("dlgTypeNon").style.display = "none";
		      document.getElementById("dlgTypeHope").style.display = "none";
		    }
		    if (myListType == "NONHOPE")
		    { document.getElementById("dlgTypeAll").style.display = "none";
		      document.getElementById("dlgTypeNon").style.display = "block";
		      document.getElementById("dlgTypeHope").style.display = "none";
		    }
		    if (myListType == "HOPE")
		    { document.getElementById("dlgTypeAll").style.display = "none";
		      document.getElementById("dlgTypeNon").style.display = "none";
		      document.getElementById("dlgTypeHope").style.display = "block";
	    }
    }
}
function CPCheck(field){
	if (field.checked==true){
		if(CL!=""){
			changeIndexes();
		}else{
			document.getElementById("dlgTypeAll").selectedIndex = 0;
			document.getElementById("dlgTypeNon").selectedIndex = 0;
			document.getElementById("dlgTypeHope").selectedIndex = 0;
		}
	}else{
		
	}
}
function resetCP(){
	if(document.getElementById("CP"))document.getElementById("CP").checked=false;
}
function setResPool(field){
	if(field.checked==true){
		sponRes="Y";
	}else{
		sponRes="";
	}
}
function changeSearchType(){
	clearInterval(loadSearchType);
	myListType="ALL";
	//By default, SearchType will load the correct value from the query string, but should only do this on page load.
	if (CO!=""){
		if(CO.toUpperCase()=="ALL"){
			
			document.getElementById("searchType").selectedIndex = 0;
			
		}else if (CO.toUpperCase()=="HOPE"){
			
			document.getElementById("searchType").selectedIndex = 1;
			
		}else if (CO.toUpperCase()=="NONHOPE"){
			
			document.getElementById("searchType").selectedIndex = 2;
		}
	}
}
/*************************************************************************
Web Services Down Redirection functions
*************************************************************************/
function calcTime(city, offset) {
    // create Date object for current location
    d = new Date();
   
    // convert to msec
    // add local time zone offset
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
   
    // create new Date object for different city
    // using supplied offset
    nd = new Date(utc + (3600000*offset));
   
    // return time as a string
    time = nd.toLocaleString().split(" ");
    return(time[4] + time[5]);
}
function webSvcDownRedirect(errCode){
if(isIstore){
	if(typeof errCode=='undefinded'){
		errCode = ""
	}
}else{
	if(typeof errCode=='undefinded'){
		errCode = ""
	}
}
if(isIstore){
	var s=s_gi('wvworldvision,wvmastersuite'); s.tl(this,'o','istore Hollow Template :: time(' + calcTime('PST','-8') + ')err(' + errCode +')');
}else{
	var s=s_gi('wvworldvision,wvmastersuite'); s.tl(this,'o','|  |  |  | Online Donations - Child Sponsorship :: time(' + calcTime('PST','-8') + ')err(' + errCode +')');
}
           if (isIstore == false){ window.location.replace("http://donate.worldvision.org/OA_HTML/xxwv2DoChildSearch.jsp?lpos=time(" + calcTime('PST','-8') + ")err(" + errCode +")");
	}else{
    		document.redirectForm.redirectButton.click();
    	}
    }
/************************************************************
iStore Design Specific functions
************************************************************/
function changeTab(classname, id)
{
    var alltabs = document.getElementById("tabs");
    for (var i = 0; i < alltabs.childNodes.length; i++)
    {
        var tempId = alltabs.childNodes[i].id
        if (tempId != "" && tempId != null)
        {
            if (tempId.indexOf(id) > -1)
            {
                alltabs.childNodes[i].className = classname+"-tabon";
            }
            else
            {
                alltabs.childNodes[i].className = classname+"-taboff";
            }
        }
    }
    
    var alltabcontent = document.getElementById("tabcontent");
    for (var i = 0; i < alltabcontent.childNodes.length; i++)
    {
        var tempId = alltabcontent.childNodes[i].id
        if (tempId != "" && tempId != null)
        {
            if (tempId.indexOf(id) > -1)
            {
                alltabcontent.childNodes[i].style.display = "block";
            }
            else
            {
                alltabcontent.childNodes[i].style.display = "none";
            }
        }
    }
}
            
function validate(oFrm)
	{
              // determine if they have entered an oda
              if (oFrm.itemqty[1].checked)
              {
                var minGiftAmt = '35';
                if (isNaN(parseInt(minGiftAmt)))
                {// default it to 30
                   minGiftAmt = 30;
                }
                else
                {
                  minGiftAmt = parseInt(minGiftAmt);
                }
                var maxGiftAmt = '3500';
                if (isNaN(parseInt(maxGiftAmt)))
                {// default it to 3000
                  maxGiftAmt = 3000;
                }
                else
                {
                  maxGiftAmt = parseInt(maxGiftAmt);
                }
                var giftAmt=oFrm.xxwvotheramt.value;
                if ((giftAmt>=minGiftAmt && giftAmt<maxGiftAmt) && giftAmt.indexOf(".") == -1)
                {
                  oFrm.xxwvsponotheramt.value=oFrm.xxwvotheramt.value;
                  return true;
                }
                else if (giftAmt.indexOf(".")> -1)
                {
                  alert("Please only enter whole dollar amounts.");
                  oFrm.xxwvotheramt.focus();
                  return false;
                }
                else
                {
                  alert("Please enter a donation amount between " + minGiftAmt + " and " + maxGiftAmt);
                  oFrm.xxwvotheramt.focus();
                  return false;
                }
              }
              return true;
}
function newSponAmt(buyRoute){
                arLoc = buyRoute.split("/OA_HTML");
                arLoc[0] = buyRouteServer();
                page = arLoc[1].split("&");
                newLoc = arLoc[0] + "/OA_HTML" +page[0] ;
		arBuyRoute = buyRoute.split("&");
		if (arBuyRoute[3].indexOf("xxwvsponotheramt")!=-1){
                        arBuyRoute[0] = newLoc;
                        if(document.getElementById("itemqty1").checked!=true){
			arBuyRoute[3] = "xxwvsponotheramt=" + document.getElementById("xxwvotheramt").value;
		}else{
                        arBuyRoute[3] = "xxwvsponotheramt=" + document.getElementById("Amt").innerHTML;
		}
			var newBuyRoute = arBuyRoute.join("&");
			return "http://" + newBuyRoute
		}
}
/**********************************************************************
Browser sniffing functions to detect if the user is running IE8 or above (for WS calls)
***********************************************************************/
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
function checkIEVersion() {
    isIE8 = false;
    var ver = getInternetExplorerVersion();
    if (ver > -1) {
        if (ver >= 8.0)
            isIE8 = true;
        else
            isIE8 = false;
    }
    return isIE8;
}
function loadCountryLists(){}
function age(bDay){
 now = new Date()
 bD = bDay.split(' ');
var month = bD[0];
var numMonth;
var day = bD[1].substring(0,2);
switch(month)
{
case "Jan":
  numMonth = 1
  break;
case "Feb":
  numMonth = 2
  break;
case "Mar":
  numMonth = 3
  break;
case "Apr":
  numMonth = 4
  break;
case "May":
  numMonth = 5
  break;
case "Jun":
  numMonth = 6
  break;
case "Jul":
  numMonth = 7
  break;
case "Aug":
  numMonth = 8
  break;
case "Sep":
  numMonth = 9
  break;
case "Oct":
  numMonth = 10
  break;
case "Nov":
  numMonth = 11
  break;
case "Dec":
  numMonth = 12
  break;
default:
  numMonth = "0"
}
bD[0] = parseFloat(day);
bD[1] = numMonth;
bD[2] = parseFloat(bD[2]);
 if(bD.length==3){
   born = new Date();
   born.setFullYear(bD[2], bD[1]-1, bD[0]);
   years = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
   return(years)
 }
}
/**********************************************************************
Function for Flash movie to grab child first name and image URL
***********************************************************************/
function getChildInfoForSwf(){
	var imgSRC = arChildren[c].imageURL;
	var firstName = arChildren[c].firstName;
	swfChild = new Array();
	swfChild[0] = firstName;
	swfChild[1] = imgSRC ;
	return swfChild;
}

