//this function includes all necessary js files for the application  
 function include(file)  
 {  
   
   var script  = document.createElement('script');  
   script.src  = file;  
   script.type = 'text/javascript';  
   script.defer = true;  
   
   document.getElementsByTagName('head').item(0).appendChild(script);  
   
 }  
   
 /* include any js files here */  
//include('/fileadmin/js/php.default.min.js');  



function chkSubscriberForm(frmObj) {
	//check to see if the honey-pot inputs are empty
	if(!frmObj.name.value && !frmObj.email.value){
	//strip any html/script tags from the form fields
	bool_strip = checkBadHTML(frmObj);
	var txt_error = '';
	var ele_causeid = document.getElementById('tx-srfeuserregister-pi1-tx_stwextendfeusers_cause');
	//alert('starting JS validaton! id:'+ ele_causeid.value+' name:'+ele_causeid.name+' type:'+ele_causeid.type);
	// validate that the required tickboxes are ticked, as the registration module isn't doing it.
	if (document.getElementById('tx-srfeuserregister-pi1-tx_stwextendfeusers_readagreement').checked == false) {
		//alert("Please check the box indicating that you have read and agree to our terms and conditions");
		document.getElementById('tx-srfeuserregister-pi1-tx_stwextendfeusers_readagreement').focus();
		txt_error += '-Please check the box indicating that you have read and agree to our terms and conditions\n';
	}
	
	//check that a cause has been selected by the user before submitting the form
	if(frmObj['FE[fe_users][tx_stwextendfeusers_cause]'].value == ''){
		//they have not selected a cause
		txt_error += '-Please search for and select a charitable cause to support(empty).\n';
	}else if(!isInteger(parseInt(frmObj['FE[fe_users][tx_stwextendfeusers_cause]'].value))){
	   //they have entered a value but it is not an integer
	   txt_error += '-Please search for and select a charitable cause to support(non int).\n';   
	}else if(parseInt(frmObj['FE[fe_users][tx_stwextendfeusers_cause]'].value)<1){
	    //they have entered a value but it is less than 1
       txt_error += '-Please search for and select a charitable cause to support (0).\n';
	}
	
	if(txt_error || !bool_strip){
		alert(txt_error);
		return false;
	}else{
		return true;
	}
	}else{
	//return false so the form doesn't submit
	  //alert('name:'+frmObj.name.value+'\nemail:'+frmObj.email.value);
	  return false;
	}
    
	
}

/**
 * This checks to see if the passed value is a integer.
 * n  The value to be checked
 * return true or false
 */
function isInteger(n) {
    return (typeof n == 'number' && /^-?\d+$/.test(n+''));
}



function chkCauseAdminForm() {
	
	// validate that the required tickboxes are ticked, as the registration module isn't doing it.
	if (document.getElementById('tx-srfeuserregister-pi1-tx_stwextendfeusers_adminverifyt').checked == false) {
		alert("Please check the box indicating that have the authority to view and/or edit this profile");
		document.getElementById('tx-srfeuserregister-pi1-tx_stwextendfeusers_adminverify').focus();
		return false;
	}else{
		return true;
	}
}
function checkReferUnlisted(formObj) {
	//strip any html tags
	bool_strip = checkBadHTML(formObj)
	// validate that the required tickboxes are ticked, as the registration module isn't doing it.
  return bool_strip;
}



function getCities(dd1)
{

	//clearSelect = document.getElementById('causecategory'); 
	//clearSelect.options.length = 1;  
	//clearSelect = document.getElementById('causes'); 
	//clearSelect.options.length = 1;  
	//clearSelect = document.getElementById('keywordentry'); 
	//clearSelect.value="";  
	//above code clears the third select box when re-clicking the first select box

  var idx = dd1.selectedIndex;
  var first = dd1[idx].text;
  var firstvalue = dd1[idx].value;
  var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
  var parelmts = par.elements;
  var prezsel = parelmts["causecity"];
  if (first != "choose a province")
  document.getElementById('loader').style.display="";
  {
 	Http.get({
		url: "fileadmin/include/stwcauses.php?province=" + firstvalue,
		callback: fillPrez,
		cache: Http.Cache.Get
	}, [prezsel]);
  }
  document.getElementById('loader').style.display="none";
  document.getElementById('cityselect').style.display="";

}
function resetCauseSelection() {
	clearSelect = document.getElementById('causeprovince'); 
	clearSelect.options[0].selected = true; 
	clearSelect = document.getElementById('causecity'); 
	clearSelect.options.length = 1; 	
	preloadCategories();
	//clearSelect = document.getElementById('causes'); 
	//clearSelect.options.length = 1;  
	clearSelect = document.getElementById('keywordentry'); 
	clearSelect.value="enter cause name";
	document.getElementById('cause-name').style.display="none";
}

function causesForProvinces(dd1) {
	 document.getElementById('loader').style.display="";
	//var idx = dd1.selectedIndex;
	// var first = dd1[idx].text;
	var firstvalue = dd1;
	var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
	var parelmts = par.elements;
	var prezsel = parelmts["causes"];
 	{
	Http3.get({
		url: "fileadmin/include/stwcauses.php?causesforprovince=" + firstvalue,
		callback: fillPrezCauses,
		cache: Http3.Cache.Get
	}, [prezsel]);	
  }
  document.getElementById("causes").style.display="inline";
}

function preload () {
	
	if (document.signup) {
		preloadCategories();
		if (document.getElementById("tx-srfeuserregister-pi1-email").value || document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value) {
			// if the cause has a value ie if we are on the start page, clicked register, then clicked "back to edit:
			//alert ("email: " + document.getElementById("tx-srfeuserregister-pi1-email").value);
			checkForCause();
		}
		
	
	//	loadDefaultCause();
		//document.getElementById('tx-srfeuserregister-pi1-gender')[0].checked=false;
		//lived removed to accomodate the removal of the option form fields (25-08-2011)
		//document.signup['FE[fe_users][gender]'][0].checked = false;
		//document.signup['FE[fe_users][gender]'][1].checked = false;
		//removed the line below because the field was removed from form - Peter
		//document.getElementById('tx-srfeuserregister-pi1-tx_stwextendfeusers_sharename').checked=true;		
		// determine whether or not to show the cause box
		
		
		// check for the custom cause URL segment
		wurl = new String (location);
		//alert(wurl);
		x = wurl.split("/");
		lastsegment = "";
		for (var i=0; i<x.length; i++) {
			lastsegment = x[i];
		}
		lastsegmentexists = 0;
		//check to see if the last segment has a length
		if (lastsegment.length > 0) {
			lastsegmentexists = 1;	
		}
		
		// check to see if the last segment has a ? in it (ie charitysupporters.com/causeid=14
		y = lastsegment.split("?")
		for (var j=0; j<y.length; j++) {
			
		}
		
		if (j > 1 ) {
			lastsegmentexists = 0;	//it might exist, but it has a ? in it, so we're not interested
		}
		// check to see if the last segment has a ? in it (ie charitysupporters.com/causeid=14
		y = lastsegment.split(".")
		for (var k=0; k<y.length; k++) {
			
		}
		//alert ("?s = " + j);
		if (k > 1 ) {
			lastsegmentexists = 0;	//it might exist, but it has a ? in it, so we're not interested
		}		
		
		if (lastsegmentexists == 1) {
		 // look up to which cause it belongs
		 //alert(lastsegment);
		}
		
			var queryString = new QueryString();
			queryString.read();
			var x =queryString.get('causeid');
			if(x == ''){
				x = queryString.get('stw_causes_pi1[cause]');
			}
			if ((x) || (lastsegmentexists == 1)) {
				
				document.getElementById('cause-name').style.display="";
			} else {
				document.getElementById('cause-name').style.display="none";		
			}
			// determine whether to show the cause selection fields (ie. did the person come to this page from a referral link)
			y = queryString.get('inlink');
			if ((y =="ru") ||(lastsegmentexists == 1)) {  //inline=ru means that its a referall that is unchangeable, the supporter can not change the selected cause		
				document.getElementById('causeselection').style.display="none"; //hide cause selection fields
				document.getElementById('hpcauseinfo').style.display="none"; // hide cause info checkboxes in the signup		
				document.getElementById('cause-name').style.display=""; //turn on selected cause
			}
		
	}
		//display the featured cause
		loadFeatured();
		document.getElementById('loader').style.display="none";
		
	return;
	
}
function loadFeatured () {
	
  var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
  var parelmts = par.elements;
  var prezsel = parelmts["featuredcause"];
  firstvalue = "findme";
  document.getElementById('loader').style.display="";
  Http.get({
	url: "fileadmin/include/stwcauses.php?featuredcause=" + firstvalue,
	callback: fillFeaturedCause,
	cache: Http.Cache.Get
  });
  loadPreselectedCause(firstvalue);
}

function fillFeaturedCause(xmlreply, prezelmt) {
		if (xmlreply.status == Http.Status.OK)
	  {
		    $response = xmlreply.responseText;
			$elements = $response.split("~");
			var causeid = $elements[0];	
			var causename = $elements[1];

			document.getElementById("featuredcause").innerHTML= "<a onclick=\"vHWin=window.open('/index.php?id=103&cause=" + causeid + "','FEopenLink','scrollbars=1,width=600,height=600');vHWin.focus();return false;\" target=\"FEopenLink\" href='index.php?id=103&cause=" + causeid + "'>" + causename + "</a>";
			/*
			* removed feb. 18, 2010 because we want them to select a cause
			*
			*if (document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value < 1) {
			*	document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value = causeid;	
			*}
			*/
			
	  }   else  {
		//alert("Cannot handle the AJAX call.");
	  }
	  
}

function loadPreselectedCause(featured) {
	//alert(featured);
	//alert(lastsegment);
	var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
  	var parelmts = par.elements;	
  
  
		var queryString = new QueryString();
		queryString.read();
		var firstvalue = queryString.get('causeid');
		//check value
		if(firstvalue == ''){
			firstvalue = queryString.get('stw_causes_pi1[causeid]');
		}
	//alert("causeid: "+firstvalue);
	//TODO remove lastsegmentexists and test
	if ((firstvalue > 0) || (lastsegmentexists == 1)){
		if (firstvalue > 0) {
			causeid = firstvalue;
		} else {
			causeid = -1;
		}
		document.getElementById('cause-name').style.display="";
	} else if (document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value) {
		causeid = document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value;
		if (document.getElementById("tx-srfeuserregister-pi1-email").value) {
			document.getElementById('cause-name').style.display="";
		}
	} else {
		causeid = featured;
	}
		
	if (causeid > 0){
		//alert('causeid:'+causeid);
		// its an actual cause id
		Http4.get({
			url: "fileadmin/include/stwcauses.php?preselected=" + causeid,
			callback: fillPreselected,
			cache: Http4.Cache.Get
		});
	} else {
		//alert("last else lastsegment: "+lastsegment);
		Http4.get({
		// its a text segment
			url: "fileadmin/include/stwcauses.php?preselectedT=" + lastsegment,
			callback: fillPreselected,
			cache: Http4.Cache.Get
		});
		
	}
	
}

function fillPreselected(xmlreply, prezelmt) {

		if (xmlreply.status == Http4.Status.OK)
	  {
		    $response = xmlreply.responseText;
		    //alert("response: "+$response);
			if ($response.length) {
				$elements = $response.split("~");
				
				var causeid = $elements[0];				
				var causename = $elements[1];
			
			
				if (document.getElementById("tx-srfeuserregister-pi1-email").value) {
					document.getElementById('cause-name').style.display="";
				}
				document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value = causeid;
				document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_causename").value = causename;
				document.getElementById("cause-name").innerHTML = "<p><span style='color:#000000;'>Your selected Cause is:</span>  <br />" + causename + "<br /><br /><span style='float:right;'><a href='#'  onclick='showResults()'>Back</a></span><span><a href='#' onclick='resetCauseSelection()'>Alternate Search</a></span></p>";
		//document.getElementById('causes').style.display="none";
		//document.getElementById("cause-name").style.display="none";
			} else {
				// looks like a bad custom url was entered, so turn back on the cause selection fields
				document.getElementById('causeselection').style.display=""; //hide cause selection fields
				document.getElementById('hpcauseinfo').style.display=""; // hide cause info checkboxes in the signup		
				document.getElementById('cause-name').style.display="none"; //turn on selected cause
			}
			
	  }   else  {
		alert("Cannot handle the AJAX call.");
	  }
}

function preloadCategories()
{

  var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
  var parelmts = par.elements;
  var prezsel = parelmts["causecategory"];
  firstvalue = "all";
	  document.getElementById('loader').style.display="";
 	Http3.get({
		url: "fileadmin/include/stwcauses.php?city=" + firstvalue,
		callback: fillPrezCats,
		cache: Http3.Cache.Get
	}, [prezsel]);


}

function checkForCause () {
	//alert(document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value)
	if (document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value) {
		
			cause = document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value
		 	Http2.get({
				url: "fileadmin/include/stwcauses.php?causevalue=" + cause,
				callback: fillCauseName,
				cache: Http2.Cache.Get
			});	
	}
}



function fillCauseName (xmlreply) 
{

  if (xmlreply.status == Http2.Status.OK)
  {
    var prezresponse = xmlreply.responseText;
  	document.getElementById("cause-name").innerHTML = "<p><span style='color:#000000;'>Your selected Cause is:</span>  <br />" + prezresponse + "</p>";
  }
  else
  {
    //alert("Cannot handle the AJAX call." + xmlreply.status);
  }
  //document.getElementById('loader').style.display="none";
}

function getCategories(dd1)
{
  var idx = dd1.selectedIndex;
  var first = dd1[idx].text;
  var firstvalue = dd1[idx].value;
  var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
  var parelmts = par.elements;
  var prezsel = parelmts["causecategory"];
  if (first != "choose a city")
  {
	  document.getElementById('loader').style.display="";
 	Http.get({
		url: "fileadmin/include/stwcauses.php?city=" + firstvalue,
		callback: fillPrezCats,
		cache: Http.Cache.Get
	}, [prezsel]);
  }
  //document.getElementById("causes").style.display="inline";
}

function getCauses(dd1,dd2) {

	var idx = dd1.selectedIndex;
	var third = dd1[idx].text;
	var thirdvalue = dd1[idx].value;
	var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
  	var parelmts = par.elements;
	var prezsel = parelmts["causes"];
	

	
	if (dd2 != 'choose a city') {
		var andCity = "&city=" + dd2;
	} else {
		var andCity = "&city=all";
	}
  		
	 if (third != "choose a category")
  {
	  	document.getElementById('loader').style.display="";
 	Http.get({
		url: "fileadmin/include/stwcauses.php?category=" + thirdvalue + andCity,
		callback: fillPrezCauses,
		cache: Http.Cache.Get
	}, [prezsel]);
  }
  //document.getElementById("causes").style.display="inline";
}

function setCause(causeid) {
	//var idx = cause.selectedIndex;
	//var selectedCause = cause[idx].text;
	//var selectedCauseId = cause[idx].value;

	var selectedCauseId = causeid;

	var causenamediv = "title" + causeid;
	var selectedCause = document.getElementById(causenamediv).innerHTML;


	if (selectedCause != "Select A Cause") {
		document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value = selectedCauseId;
		document.getElementById("cause-name").innerHTML = "<p><span style='color:#000000'>Your selected Cause is: </span> <br />" + selectedCause + "<br /><br /><span style='float:right;'><a href='#'  onclick='showResults()'>Back</a></span><span><a href='#' onclick='resetCauseSelection()'>Alternate Search</a></span></p>";
		document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_causename").value = selectedCause;
//		document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_causename").value;
		document.getElementById('causes').style.display="none";
		document.getElementById("cause-name").style.display="";
	}
        document.getElementById("causepop").style.display="none";
}

function setCauseOpener(causeid) {
	//var idx = cause.selectedIndex;
	//var selectedCause = cause[idx].text;
	//var selectedCauseId = cause[idx].value;
       
	var selectedCauseId = causeid;
	
	var causenamediv = "title" + causeid;
	var selectedCause = document.getElementById(causenamediv).innerHTML;

	
	if (selectedCause != "Select A Cause") {
		document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value = selectedCauseId;
		document.getElementById("cause-name").innerHTML = "<p><span style='color:#000000'>Your selected Cause is: </span> <br />" + selectedCause + "<br /><br /><span style='float:right;'><a href='#'  onclick='showResults()'>Back</a></span><span><a href='#' onclick='resetCauseSelection()'>Alternate Search</a></span></p>";
		document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_causename").value = selectedCause;
//		document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_causename").value;
		document.getElementById('causes').style.display="none";
		document.getElementById("cause-name").style.display="";
	}

        if (chkObject(true, 'causepop')) {
            window.opener.document.getElementById("causepop").style.display="none";
        }
}
function showResults() {
		document.getElementById('causes').style.display="";
}
function getKeyword() {

        //hide causepop box
        keyword = document.getElementById("causepop").style.display = 'none';
	//var keyword = dd1;
	keyword = document.getElementById("keywordentry").value
	province = document.getElementById("causeprovince").value
	category = document.getElementById("causecategory").value
	city = document.getElementById("causecity").value
	
	checkcombo = 0;
	// check to see if we have some options selected
	
	refineme = "For quicker results, refine search by ";  // by keyword or category or province";
	refinemeterms = "";

	if ((keyword != "") && (keyword != "enter cause name")) {
		checkcombo += 1;
	} else {
		refinemeterms = "keyword";
	}
	if ((category != "choose a category") && (category !="")) {
		checkcombo += 1;
	} else {
		if (refinemeterms.length > 0) refinemeterms += " or ";
		refinemeterms += "category";
	}	
	if ((province != "choose a province") && (province !="")) {
		checkcombo += 1;
	} else	{
		if (refinemeterms.length > 0) refinemeterms += " or ";
		refinemeterms += "province";
	}

	//alert(province + ", city=" + city + ",category=" + category + ",keyword=" + keyword+ ", combo=" + checkcombo);
		
	if (checkcombo < 2 ) {
		//alert(refineme + refinemeterms);	
	}
	
		
		//var keyword = dd1[idx].text;
		
		if ((keyword == "") || (keyword == "enter cause name")) {
			keyword = 'none';
		}
		
	
		query = "";
		if (province != "choose a province") {
			query = "&province=" + province;
		}
		if (category  != "choose a category") {
			query += "&category=" + category;	
		}
		if (city  != "choose a city") {
			query += "&city=" + city;	
		}
	
		if (checkcombo > 0) {
			
			document.getElementById('loader').style.display="";
	
			var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
			var parelmts = par.elements;
			var prezsel = parelmts["causes"];	

	//alert ("fileadmin/include/stwcauses.php?keyword=" +keyword + query);
			Http.get({
				url: "fileadmin/include/stwcauses.php?keyword=" + keyword + query,
				callback: fillPrezCauses,
				cache: Http.Cache.Get
			}, [prezsel]);
	
	
			document.getElementById("causes").style.display="";
		}
}
/**
 * This method is called from the refer a cause and be cause admin search form.
 * It searches the causes table using the entered keywords
 * 
 * dd1 String The keywords entered by the visitor
 * 
 */
function getLookupKeyword(dd1) {
	// Used for lookup on refer a cause page
	var keyword = dd1;
	
	if ((keyword != "enter cause name") && (keyword != "")) {
		document.getElementById('loader').style.display="";
		//var keyword = dd1[idx].text;

		var par = document.forms['tx-srfeuserregister-pi1-fe_users_form'];
		var parelmts = par.elements;
		var prezsel = parelmts["causes"];	

		Http.get({
			url: "fileadmin/include/stwcauses.php?keyword=" + keyword,
			callback: fillPrezCats,
			cache: Http.Cache.Get
		}, [prezsel]);

  document.getElementById("causes").style.display="";
  document.getElementById("causenotfound").style.display="";
  	}
}


function fillPrez(xmlreply, prezelmt)

{
  if (xmlreply.status == Http.Status.OK)
  {
    var prezresponse = xmlreply.responseText;
    var prezar = prezresponse.split("|");
    prezelmt.length = 1;
    prezelmt.length = prezar.length;
    for (o=1; o < prezar.length; o++)
    {
      prezelmt[o].text = prezar[o];
	  prezelmt[o].value = prezar[o];
    }
  }
  else
  {
   // alert("Cannot handle the AJAX call.");
  }
  
  		
}

/**
 * This method will take the xml response from the PHP script and fill in the
 * Select box with the return causes as options.
 * xmlreply XML response from the PHP script
 * prezelmt 
 */
function fillPrezCats(xmlreply, prezelmt)
// used for populating the categories on the home page, and the causes on the add/edit your cause pages
{
  if (xmlreply.status == Http.Status.OK)
  {
    var prezresponse = xmlreply.responseText;
    var prezar = prezresponse.split("|");
	//alert (prezresponse);
	//alert (prezar);
	//alert (prezar.length);
    prezelmt.length = 1;
    prezelmt.length = prezar.length;
	//alert (prezar.length);
	if (prezar.length>1) {
		if (document.getElementById("nocauses")) document.getElementById("nocauses").style.display= "none";
		for (o=1; o < prezar.length; o++)
			{
				var cause = prezar[o].split("~");	
			 // prezelmt[o].text = prezar[o];
			  //prezelmt[o].value = prezar[o+1];
			  prezelmt[o].title = cause[2];
			  prezelmt[o].text = cause[1];
			  prezelmt[o].value = cause[0];
		
			}
	} else {
		document.getElementById("causes").style.display= "none";
		document.getElementById("nocauses").style.display= "";
	}
	
	//
  }
  else
  {
   // alert("Cannot handle the AJAX call.");
  }
  document.getElementById('loader').style.display="none";
}


function fillPrezCauses(xmlreply)
// used for populating the causes on the home page
{
  if (xmlreply.status == Http.Status.OK)
  {
    var prezresponse = xmlreply.responseText;
    var prezar = prezresponse.split("|");

	causelist = document.getElementById("causes");
	causeinfo = document.getElementById("causepop");
	
	if (prezar.length>1) {
		if (document.getElementById("nocauses")) document.getElementById("nocauses").style.display= "none";
		var listhtml = [];
		var infohtml = [];		
		for (o=1; o < prezar.length; o++)
			{
			 var cause = prezar[o].split("~");	
			 // prezelmt[o].text = prezar[o];
			  //prezelmt[o].value = prezar[o+1];
			 description = cause[2];
			 title = cause[1];
			 causeid = cause[0];
			 website = cause[3];
			 logo = cause[4];
			 
			 stitle = escape(title);
//                         top = m(event).value;
			  
			 listhtml.push('<li class="causeitem"');
			// html.push('<li title="' + cause[2] + '"');
			 listhtml.push('id="' + causeid + '"');
                         //setTop(this.offsetTop, m(event)); 
 			 //listhtml.push(' onmouseover="setTop(getPageEventCoords(event)); showCausePopup(' + causeid + '); this.style.textDecoration=\'underline\'; this.style.color=\'#0082B5\';"');
			 listhtml.push(' onmouseover="setTop(getPageEventCoords(event)); this.style.cursor=\'pointer\'; this.style.textDecoration=\'underline\'; this.style.color=\'#0082B5\';"');
                         //hideCausePopup(' + causeid + '); 
 			 listhtml.push(' onmouseout="this.style.textDecoration=\'none\'; this.style.color=\'#000000\';"');
			 //listhtml.push(' onclick="setCause(' + causeid + ');"');
                         listhtml.push(' onclick="vHWin = window.open(\'/index.php?id=103&cause=' + causeid + '\',\'FEopenLink\',\'scrollbars=1,width=600,height=600\'); vHWin.focus(); return false;"');
			 listhtml.push('>' + title  );	
			 
			 infohtml.push('<div id="info' + causeid + '" style="display:none;">');
			 if (logo) {
				infohtml.push('<img src="http://www.charitysupporters.com/uploads/tx_stwcauses/' + logo +'" width="100px">');
				infohtml.push('<BR />');
			}
			 infohtml.push('<strong><span id="title' + causeid + '" style="cursor:pointer;" onclick="vHWin = window.open(\'http://www.charitysupporters.com/index.php?id=103&cause=' + causeid + '\',\'FEopenLink\',\'scrollbars=1,width=600,height=600\'); vHWin.focus(); return false;">' + title + '</span></strong>');
 			 infohtml.push('<BR />');
			 infohtml.push(description);
 			 infohtml.push('<BR />');			 
			 infohtml.push('<a href="' + website + '" target="_blank">' + website + '</a>');
			 // add logo
			 // add link
			 infohtml.push('</div>');



			}
			causelist.innerHTML = listhtml.join('');
			causeinfo.innerHTML = infohtml.join('');
	} else {
		document.getElementById("causes").style.display= "none";
		document.getElementById("nocauses").style.display= "";
	}
	
	//
  }
  else
  {
   // alert("Cannot handle the AJAX call.");
  }
  document.getElementById('loader').style.display="none";
}

function getit(xmlreply){
	if (xmlreply.status == Http.Status.OK)
	  {
		document.getElementById("causes").innerHTML= xmlreply.responseText;
	  }  
	  else
	  {
		//alert("Cannot handle the AJAX call.");
	  }
}


	function clearSearchWord() {
			if ((document.getElementById('keywordentry').value == "enter cause name") || (document.getElementById('keywordentry').value == "Enter Cause Name") ) {
				document.getElementById('keywordentry').value = ""
			}
	}
	
function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}

document.onkeypress = stopRKey; 

/*	function clearSearchWord() {
			document.getElementById('keywordentry').value = ""
	}
	*/
	
	
/* Cause Signup Functions */

function assignCause() {
	causeid = document.getElementById('causes').value
	window.location = '/index.php?id=107&causeid=' + causeid;

}
/**
 * This method is called from the cause search from on the refer a cause page. 
 * It uses the ID from the selected item to pre-register the new user with
 * the selected cause.
 */
function returnRegister(frmObject) {
	causeid = frmObject.value;
	//alert("id="+causeid);
	window.location = '/register/index.php?&causeid=' + causeid;
}
function resetForm() {
	document.getElementById('causes').style.display="none";
	preloadCategories();
	//clearSelect = document.getElementById('causes'); 
	//clearSelect.options.length = 1;  
	//clearSelect = document.getElementById('keywordentry'); 
	//clearSelect.value="";  	
	document.getElementById('cause-name').style.display="none"
}

function selectFeatured(name, id) {
	// called from featured cause popup on home/signup page
	//alert("selectFeatured: name:"+name+" id: "+id);
	opener.document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_cause").value = id;
        opener.document.getElementById("tx-srfeuserregister-pi1-tx_stwextendfeusers_causename").value = name;
	opener.document.getElementById("cause-name").innerHTML = "<p><span style='color:#000000'>Your selected Cause is: </span> <br />" + name + "<br /><br /><span style='float:right;'><a href='#'  onclick='showResults()'>Back</a></span><span><a href='#' onclick='resetCauseSelection()'>Alternate Search</a></span></p>";
	opener.document.getElementById('causes').style.display="none";
	opener.document.getElementById("cause-name").style.display="";

        opener.document.getElementById("causepop").style.display="none";
	
	self.close();
}

function setTop(top) {

        //offsettop = document.getElementById(cause).offsetTop;
        //top = (offsettop - Math.floor((offsettop-675)/250) * 250)
        document.getElementById('causepop').style.top = top + "px";
}

function showCausePopup(cause, top) {

        hideAllCause();
	document.getElementById('causepop').style.display="";
	document.getElementById('info' + cause).style.display="";
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	 		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			if (ieversion<=6) document.getElementById('tx-srfeuserregister-pi1-zone').style.display="none";
				//hide the provinces dropdown lest it show through the cause info popup
	}
}
function hideCausePopup(cause) {
	document.getElementById('causepop').style.display="none";
	document.getElementById('info' + cause).style.display="none";	
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	 	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ieversion<=6) document.getElementById('tx-srfeuserregister-pi1-zone').style.display="";
	}	
}

function hideAllCause() {
    var divbox=document.getElementById("causepop")
    var subdivs=divbox.getElementsByTagName("div")

    for ( index=0; index< subdivs.length; index++) {
	subdivs[index].style.display = 'none';
    }
}

function getPageEventCoords_old(evt) {
    var coords = {
        left:0,
        top:0
    };
    if (evt.pageX) {
        coords.left = evt.pageX;
        coords.top = evt.pageY;
    } else if (evt.clientX) {
        coords.left =
        evt.clientX + document.body.scrollLeft - document.body.clientLeft;
        coords.top =
        evt.clientY + document.body.scrollTop - document.body.clientTop;
        // include html element space, if applicable
        if (document.body.parentElement && document.body.parentElement.clientLeft) {
            var bodParent = document.body.parentElement;
            coords.left += bodParent.scrollLeft - bodParent.clientLeft;
            coords.top += bodParent.scrollTop - bodParent.clientTop;
        }
    }
    isIE8 = isIE && check(/msie 8/)
    if(isIE8) {
        //alert(coords.top);
    }

//alert(coords.top);
return coords.top;
}

function getPageEventCoords(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
        return evt.clientY + (document.documentElement.scrollTop ?
            document.documentElement.scrollTop :
            document.body.scrollTop);
    else return null;
}

var idSeed = 0,
ua = navigator.userAgent.toLowerCase(),
check = function(r){
    return r.test(ua);
},
isStrict = document.compatMode == "CSS1Compat",
isOpera = check(/opera/),
isChrome = check(/chrome/),
isWebKit = check(/webkit/),
isSafari = !isChrome && check(/safari/),
isSafari3 = isSafari && check(/version\/3/),
isSafari4 = isSafari && check(/version\/4/),
isIE = !isOpera && check(/msie/),
isIE7 = isIE && check(/msie 7/),
isIE8 = isIE && check(/msie 8/),
isIE6 = isIE && !isIE7 && !isIE8,
isGecko = !isWebKit && check(/gecko/),
isGecko3 = isGecko && check(/rv:1\.9/),
isBorderBox = isIE && !isStrict,
isWindows = check(/windows|win32/),
isMac = check(/macintosh|mac os x/),
isAir = check(/adobeair/),
isLinux = check(/linux/),
isSecure = /^https/i.test(window.location.protocol);

function chkObject(inParent,theVal) {
    if(inParent){
        if (window.opener.document.getElementById(theVal) != null) {
            return true;
        } else {
            return false;
        }
    }else{
        if (document.getElementById(theVal) != null) {
            return true;
        } else {
            return false;
        }
    }
}


