//document.write("[scripts.js loaded]");
/*
function popUp(page, w, h)
{
	// a jimbo script
	// has nothing enabled
	window.open(page,"title1","menubar=no,personalBar=no,scrollbars=no,titlebar=no,toolbar=no,directories=no,location=no,resizable=no,status=no,top="+((screen.height-h)/2)+",left="+((screen.width-w)/2)+",width="+w+",height="+h+""); 
}

function popUp3(page, w, h)
{
	// a jimbo script
	// has scrollbars enabled
	window.open(page,"title2","menubar=no,personalBar=no,scrollbars=yes,titlebar=no,toolbar=no,directories=no,location=no,resizable=yes,status=no,top="+((screen.height-h)/2)+",left="+((screen.width-w)/2)+",width="+w+",height="+h+""); 
}

function popUp8(page, w, h)
{
	// a jimbo script
	// resizeable
	window.open(page,"title2","menubar=no,personalBar=no,scrollbars=yes,titlebar=no,toolbar=no,directories=no,location=no,resizable=yes,status=no,top="+((screen.height-h)/2)+",left="+((screen.width-w)/2)+",width="+w+",height="+h+""); 
}
*/

// for the newsletter subscriptions
function expandText(divID, agentID) 
{
	document.getElementById(divID+'-'+agentID).className='show';
	document.getElementById('details-btnS-'+agentID).className = 'hide';
	document.getElementById('details-btnH-'+agentID).className = 'show';
	document.getElementById(divID+'-'+agentID+'-1').className='hide';
}

function collapseText(divID, agentID) 
{
	document.getElementById(divID+'-'+agentID).className='hide';
	document.getElementById('details-btnS-'+agentID).className = 'show';
	document.getElementById('details-btnH-'+agentID).className = 'hide';
	document.getElementById(divID+'-'+agentID+'-1').className='show';
}

// /admin/member_fees.cfm
function calculateColumn(col)
{
	var fees = document.frm_fees.elements[col + '_1'].value;
	var monthly = fees/12;
	var newFees = fees - monthly;
	
	for (var i=2; i<=12; i++)
	{
		var rFees = roundNumber(newFees,2);
		document.frm_fees.elements[col+'_'+i].value = rFees;
		document.frm_fees.elements[col+'_display_'+i].value = rFees;
		newFees = newFees - monthly;
	}
}

function calculateColumnLB(col)
{
	var fees = document.frm_fees.elements[col + '_1'].value;
	var endFees = document.frm_fees.elements[col + '_12'].value;
	var monthly = (fees - endFees)/11;
	var newFees = fees - monthly;
	
	for (var i=2; i<=12; i++)
	{
		var rFees = roundNumber(newFees,2);
		document.frm_fees.elements[col+'_'+i].value = rFees;
		document.frm_fees.elements[col+'_display_'+i].value = rFees;
		newFees = newFees - monthly;
	}
}

function copyColumn(col)
{
	var fees = document.frm_fees.elements[col + '_1'].value;
	//var monthly = fees/12;
	//var newFees = fees - monthly;
	
	for (var i=2; i<=12; i++)
	{
		//var rFees = roundNumber(newFees,2);
		document.frm_fees.elements[col+'_'+i].value = fees;
		document.frm_fees.elements[col+'_display_'+i].value = fees;
		//newFees = newFees - monthly;
	}
}

function roundNumber(num, dec) 
{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
// end member_fees

// 301 redirects
function showError(theReferer)
{
	$(document).ready(function(){
	//tb_show("","/include/error-display.cfm?theReferer="+theReferer+"&height=250&width=600&modal=true");
	tb_show("","/include/301.cfm?height=350&width=600&modal=true");
	});
}

/*
function getLatLong()
	{
		//alert(document.frm.lstCity.value);
		
	$(document).ready(function(){
	tb_show("get lat&long","http://geocoder.us/demo.cgi?address=" + document.frm.address.value + ", " + document.frm.lstCity.value + "&keepThis=true&TB_iframe=true&width=1000&height=600");
	});
	}
*/
/*
function getLatLong2(theAddress, theCityState)
	{
		var spacer = "+";
		var nodot = " ";
		var theStreet = theAddress.replace(/ /g, "+").replace(/\./g, "");
		var theCity = theCityState.substring(0,theCityState.indexOf(',')).replace(/ /g, "+").replace(/\./g, "");
		var theState = theCityState.replace(theCity, "").replace(/ /g, "").replace(/\,/g, "");
		
		//alert(theStreet + "\n" + theCity + "\n" + theState);
		//alert(theStreet + "\n" + theCity + "\n" + theState);
		
		//document.ll_frm.street.value = theStreet;
		//document.ll_frm.city.value = theCity;
		///document.ll_frm.state.value = theState;
		//document.ll_frm.submit();
		
		$(document).ready(function(){
		tb_show("retreiving latitude & longitude...","getLatLong.cfm?street=" + theStreet + "&city=" + theCity + "&state=" + theState + "&CloseWindow=true&keepThis=true&TB_iframe=true&width=300&height=200");
		});
	}
*/
function getLatLong3(theAddress, theCityState)
{
	var spacer = "+";
	var nodot = " ";
	var theStreet = theAddress.replace(/ /g, "+").replace(/\./g, "");
	var theCity = theCityState.substring(0,theCityState.indexOf(',')).replace(/ /g, "+").replace(/\./g, "");
	var theState = theCityState.replace(theCity, "").replace(/ /g, "").replace(/\,/g, "");
	//alert(theStreet + "\n" + theCity + "\n" + theState);

	document.frm.latitude.value = "";
	document.frm.longitude.value = "";



	if (typeof XMLHttpRequest != "undefined") {
       req = new XMLHttpRequest();
   } else if (window.ActiveXObject) {
       req = new ActiveXObject("Microsoft.XMLHTTP");
   }
   
	var url = "xml_getLatLong.cfm?address=" + theStreet + "&city=" + theCity + "&state=" + theState;
	//alert(url);
	
	req.onreadystatechange = function() 
	{
		if (this.readyState == 4 && this.status == 200) {
			// got response
			//alert("got response");
			//alert(this.getResponseHeader("Content-Type").toString());
			var cType =	this.getResponseHeader("Content-Type");
			if (cType == 'text/xml') {
				// XML response
				var xmlDoc = req.responseXML;
				var theLat = xmlDoc.getElementsByTagName("latitude")[0].firstChild.nodeValue;
				var theLong = xmlDoc.getElementsByTagName("longitude")[0].firstChild.nodeValue;
			} else if (cType.indexOf('text/') != -1) {
				// plain text response
				var xmlData = req.responseText.toString().split(",");
				var theLat = xmlData[0];
				var theLong = xmlData[1];
			} else {
			alert('unknown content type');
			}			
			
			document.frm.latitude.value = theLat;
			document.frm.longitude.value = theLong;
			}
		//else
			//alert("Error code " + req.status);
	} 

	req.open("GET", url, true);
	req.send(null);
	//alert("sending request");
}

