function getCookie(cookieName)
{
	var re = new RegExp(cookieName + "=([^;]+)");
	var value = re.exec(document.cookie);

	return (value != null) ? unescape(value[1]) : null;
}

function setCookie(cookieName, cookieValue, nMinutes)
{
	var today = new Date();
	var expire = new Date();

	if (!nMinutes)
		nMinutes = 60*24*7;

	expire.setTime(today.getTime() + 60000 * nMinutes);

	document.cookie = cookieName + "=" + escape(cookieValue) + "; domain=" + location.hostname.replace('www', '') + "; expires=" + expire.toGMTString();
}

function window_openCentered(p_url, p_name, p_parameters, p_width, p_height)
{
	return window.open(p_url, p_name, p_parameters + ',' + "top=" + Math.floor((screen.height - p_height) / 2) + ",left=" + Math.floor((screen.width - p_width) / 2) + ",height=" + p_height + ",width=" + p_width);
}

function isAlphaNumeric(p_strText)
{
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -_";

	for (i = 0;  i < p_strText.length;  i++)
	{
		if (checkOK.indexOf(p_strText.charAt(i)) == -1) return false;
	}
		return (true);
}

function IsValidEmail(p_strEmail)
{
	var regexp = /^\S+\@[a-zA-Z0-9\.-]+\.[a-zA-Z0-9]{2,4}$/;
	return regexp.test(p_strEmail);
}

function IsValidDate(strDate)
{
	var temp = /^((0?[1-9])|([1][0-2]))\/(([0]?[1-9])|([1-2][0-9])|([3][0-1]))\/[1-2][0-9][0-9][0-9]$/;
	return temp.test(strDate);
}

function formatDate(p_dateString)
{
	a_dateParts = p_dateString.split('-');
	return (a_dateParts[1]) + '/' + (a_dateParts[2]) + '/' + a_dateParts[0];
}

function is_integer(p_int)
{
	var regexp = /^\d+$/;
	return regexp.test(p_int);
}

function setMembershipForm(frm) {
	if (frm.item_number[0].checked) {
		// 1 year.
		frm.item_name.value="1 YEAR BASIC MEMBERSHIP";
		frm.amount.value="$25.00";
	} else {
		// 1 month
		frm.item_name.value="1 MONTH BASIC MEMBERSHIP";
		frm.amount.value="$5.00";
	}
	//alert(frm.item_name.value);
	//alert(frm.amount.value);
	return true;
}

function lockButtons (whichform) {
	//alert ('hi');
	ua = new String(navigator.userAgent);
	if (ua.match(/IE/g)) {
		for (i=1; i<whichform.elements.length; i++) {
			if ((whichform.elements[i].type == 'submit') || (whichform.elements[i].type == 'button')) {
				whichform.elements[i].disabled = true;
			}
		}
	}
	// whichform.submit();
	// use this function for onsubmit, not onclick, k?
}

function validateAgreementCode(frm, code) {
	if (frm.AGREEMENT_CODE.value == '') {
		alert('Please enter your Agreement Code, then click \'Accept\' to accept these Terms of Use.');
		frm.AGREEMENT_CODE.focus();
		return false;
	}
	if (frm.AGREEMENT_CODE.value != code) {
		alert('Your Agreement Code does not match. Please enter your Agreement Code, then click \'Accept\' to accept these Terms of Use. Remember, the Agreement Code is CaSe SeNsItIve.');
		frm.AGREEMENT_CODE.focus();
		return false;
	}
	//lockButtons(frm);
	return true;
}

var g_strDisplay = '';
function treeShowHide(p_intLevel)
{
	for (var i = 1; i < 10; i++)
	{
		var objDiv = document.getElementById('ownedby' + p_intLevel + '_' + i);
		var strDisplay = '';

		if (g_strDisplay.indexOf('minus') > -1) strDisplay = 'none';

		if (objDiv)
		{
			objDiv.style.display = strDisplay;

			if (strDisplay == 'none') treeShowHide(objDiv.name);

			if (strDisplay == '')
			{
				//alert(document.getElementById('img_' + p_intLevel));
				document.getElementById('img_' + p_intLevel).src = '/images/tree_minus.jpg';
			}
			else
			{
				//alert(document.getElementById('img_' + p_intLevel));
				document.getElementById('img_' + p_intLevel).src = '/images/tree_plus.jpg';
			}
		}
	}

	return false;
}

function isCheckedRadio(my_name) {
	var radio_choice = false;
	for (counter = 0; counter < my_name.length; counter++) {
		if (my_name[counter].checked) radio_choice = true; 
		
	}
	return radio_choice;
}

/* thx firefox for now supporting this
String.prototype.trim = function()
{
	return this.replace(/^\s*|\s*$/g,"");
}*/

function trim(p_text)
{
	return p_text.replace(/^\s*|\s*$/g,"");
}

function set_opacity(p_obj, p_val)
{
	p_obj.style.filter = 'alpha(opacity=' + p_val + ')';
	p_obj.style.opacity = '.' + p_val;

	if (p_obj.style.MozOpacity)
	{
		p_obj.style.MozOpacity = ((p_val == 100) ? 100 : '.' + p_val);
	}
}

function toggle(p_element_id)
{
	document.getElementById(p_element_id).style.display = ((document.getElementById(p_element_id).style.display == 'none') ? '' : 'none');
}
