if (self != top) { top.location.href = self.location;href; }

var base64		= {
 charmap		: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 encode			: function(str) {
  var ret		= "";
  var c, i, acc		= 0;
  var div		= 1;
  for(i=0,c=0;i<str.length;i++,c++) {
   acc			= acc*256 + str.charCodeAt(i);
   div			= div*4;
   ret			= ret + base64.charmap.charAt(parseInt(acc/div));
   acc			= acc % div;
   if(div==64) ret	= ret + base64.charmap.charAt(parseInt(acc)), acc = 0, div = 1,c++;
   if(c>=75) c=-1, ret	= ret + "\n";
  } if(i%3) {
   ret			= ret + base64.charmap.charAt(parseInt(acc*((i%3==1)?16:4)));
   ret			= ret + ((i%3)==1?"==":"=");
  } return ret;
 },
 decode			: function(str) {
  var ret		= "";
  var i, acc		= 0;
  var div		= 1;
  for(i=0;i<str.length;i++) {
   if(str.charAt(i)=="=" || str.charAt(i)=='\n') break;
   acc			= acc*64 + base64.charmap.indexOf(str.charAt(i));
   div			= (div==1?64:div/4);
   if(div!=64) {
    ret			= ret + String.fromCharCode(parseInt(acc/div));
    acc			= acc % div;
   }
  } return ret;
 }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function validateMemberForm()
{
	// check email
	if(document.getElementById('Email Address').value == document.getElementById('Verify Email').value)
	{
		// check password
		if(document.getElementById('Password').value == document.getElementById('Verify Password').value)
		{
			return true;
		}
		document.getElementById('Password').focus();
		alert('Passwords do not match.');
		return false;		
	}
	document.getElementById('Email Address').focus();
	alert('Email addresses do not match.');
	return false;
} 

function toggleDiv(divId)
{
	div = document.getElementById(divId);
	if(div.style.display == 'none')
	{
		div.style.display = 'block';
	}
	else
	{
		div.style.display = 'none';
	}
}

function defaultAutoFill(defaultValue, fieldId)
{
	if(empty(document.getElementById(fieldId).value)) { document.getElementById(fieldId).value = defaultValue; }
}

function defaultAutoEmpty(defaultValue, fieldId)
{
	if(document.getElementById(fieldId).value == defaultValue) { document.getElementById(fieldId).value = ''; }
}

function compareFields(divFieldOne, divFeildTwo, alertMessage)
{
	var fieldOne = document.getElementById(divFieldOne);
	var fieldTwo = document.getElementById(divFeildTwo);
	
	if(fieldOne.value == fieldTwo.value)
	{
		return true
	}
	else
	{
		document.getElementById(divFieldOne).value.focus();
		alert(alertMessage);
	}
	return false;	
}

function editForm(divId, method, action, primaryFieldName, otherFields, submitButton)
{
	g = document.getElementById(divId);
	fieldValue = g.innerHTML;
	
	if(fieldValue.indexOf("</form>") >= 1 || fieldValue.indexOf("</FORM>") >= 1) { return false; }
	if(fieldValue.indexOf("<script>") >= 1 || fieldValue.indexOf("<SCRIPT>") >= 1) { return false; }
	
	now      = new Date();
	randomId = now.getTime();
	hiddenFields = '';
	
	if(!method){ method = 'get'; }
	if(!submitButton) { submitButton = 'Save &raquo;'; }
	
	if(otherFields)
	{
		fields = new Array();
		fields = otherFields.split('|');

		for(i=0;i<=(fields.length-1);i++)
		{
			temp = new Array();
			temp = fields[i].split(',');
			hiddenFields += '<input type="hidden" name="' + temp[0] + '" value="' + temp[1] + '" />';
		}
	}
	
	makeForm  = '<form method="' + method + '" action="' + action + '" id="' + randomId + '" onsubmit="return false;">';
	makeForm += '<input type="text" name="' + primaryFieldName + '" id="' + randomId + '' + randomId + '" value="' + fieldValue + '" onblur="ajaxSubmit(document.getElementById(\'' + randomId + '\'), \'' + divId + '\');" />';
	makeForm += ' <a href="#" onclick="ajaxSubmit(document.getElementById(\'' + randomId + '\'), \'' + divId + '\'); return false;">' + submitButton + '</a>';
	makeForm += hiddenFields;
	makeForm += '</form>';
	
	g.innerHTML = makeForm;
	document.getElementById(randomId + '' + randomId).select();
}

function ajaxGET(divId, page)
{
	var xmlHttp;
	try
    {
    	// Firefox, Opera 8.0+, Safari
	    xmlHttp=new XMLHttpRequest();
    }
	catch (e)
    {
	    // Internet Explorer
	    try
	    {
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
        	{	
				alert("Your browser does not support AJAX!");
		        return false;
	        }
    	}
	}
	
    xmlHttp.onreadystatechange=function()
	{
    	if(xmlHttp.readyState==4)
		{
			document.getElementById(divId).innerHTML=xmlHttp.responseText;
			setAndExecute(divId, xmlHttp.responseText);
    	}
    }
	xmlHttp.open("GET",page,true);
    xmlHttp.send(null);
}

function ajaxSubmit(f, divId)
{
	if(!document.getElementById(divId))
	{ 
		alert('The requested ID `'+ divId +'`\ndoes not exist on this page.'); 
		return false; 
	}
	
	var formData = '', elem = '';
	for(var s=0; s<f.elements.length; s++)
	{
		elem = f.elements[s];
		if(formData != '')
		{
		formData += '&';
		}
		formData += elem.name+"="+elem.value;
	}
	
	document.getElementById(divId).innerHTML = '<span style="color: #cc0000;">Saving&hellip;</span>';
	
	if(window.XMLHttpRequest){ 	var xmlReq = new XMLHttpRequest();	} 
	else if(window.ActiveXObject) { var xmlReq = new ActiveXObject('Microsoft.XMLHTTP'); }
	
	xmlReq.onreadystatechange = function()
	{
		if(xmlReq.readyState == 4)	
		{ 
			document.getElementById(divId).innerHTML = xmlReq.responseText; 
			setAndExecute(divId, xmlReq.responseText);
		}
	}
	
	xmlReq.open(f.method, f.action, true);
	xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlReq.send(formData);
	return false;
}

function setAndExecute(divId, innerHTML) {
	/* http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=20&t=006435 */
   var div = document.getElementById(divId);
   div.innerHTML = innerHTML;
   var x = div.getElementsByTagName("script"); 
   for( var i=0; i < x.length; i++) {
     eval(x[i].text);
   }
}

function incrementField(fieldId, keyCode)
{
	f = document.getElementById(fieldId);
	
	fNum = parseInt(f.value);
	
	if(isNaN(fNum)) { fNum = 0; };
	
	if(keyCode == '38')
	{
		if(fNum == 18446744073709551615) { fNum == (fNum -1); /* MySQL bigInt unsigned max value */ }
		f.value = (fNum+1);
	}
	else if(keyCode == '40')
	{
		if(fNum == 0){ fNum = 1; }
		document.getElementById(fieldId).value = (fNum-1);	
	}
	else
	{
		return false;
	}
}

function popLayer(divId, fileName)
{
	if(!document.getElementById(divId)) { return false; }
		
	d = document.getElementById(divId);

	d.style.display    = 'block';
	d.style.background = '#ffffff';
	d.style.position   = 'absolute';
	d.style.left       = '40%';
	d.style.top        = '50%';
	d.style.marginTop  = '-125px';
	d.style.marginLeft = '-100px';
	d.style.width      = '350px';
	d.style.height     = '250px';	
	d.style.padding    = '20px;';
	d.style.border     = '1px solid #000000';
	d.style.overflow   = 'auto';
	
	ajaxGET(divId, '../g-core/page-permissions.ajax.php?f=' + fileName)
}

function classChange(ID2)
{
	for (i=0;i<document.getElementsByTagName("div").length; i++) 
	{
		if (document.getElementsByTagName("div").item(i).className == "close")
		{
			document.getElementsByTagName("div").item(i).style.display = "none";			
		}
		
		if (document.getElementsByTagName("div").item(i).className == "open")
		{
			document.getElementsByTagName("div").item(i).style.display = "block";
		}
	}
}

var closeAll = 'all';
function showFAQ(ID, ID2, ID3, closeAll)
{
	if(closeAll == 'all') { classChange(ID2); }
	
	for(i=0; i<=15; i++)
	{
		if(document.getElementById('faq' + i)){ document.getElementById('faq' + i).style.backgroundColor = '#FFFFFF'; }
	}
	
	// If there is no div, don't throw a JavaScript error
	if(!document.getElementById(ID)){ return false; }
	
	// Evaluate the current visibility status of the display box.
	if(document.getElementById(ID).style.display == 'none')
	{
		// The display box is not visible, so we want to display the box
		document.getElementById(ID).style.display='block';
		document.getElementById(ID2).style.backgroundColor = '#FFFFFF';
		document.getElementById(ID3).style.display='none';		
	}
	else
	{
		// The display box is visible, so we want to hide the display box
		document.getElementById(ID).style.display='none';
		document.getElementById(ID3).style.display='block';
	}
}

function closeFaq(divId, divId2)
{
	document.getElementById(divId).style.display='none';
	document.getElementById(divId2).style.display='block';	
}

function selectOption(divId, num)
{
	var selObj = document.getElementById(divId);
	selObj.selectedIndex = num;
}

function stripScript(string)
{
	var stripped = string.replace(/\s+/g," ");
	var stripped = stripped.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,"$1");	
	var stripped = stripped.replace(/<script[^>]*?>.*?<\/script>/ig,"");
	
	return stripped;
}

function changeAmpersand(string)
{
	var ampersand = string.replace(/&amp;/ig,"&");
	
	return ampersand;
}

function minCharLimit(fieldId, minLimit, message)
{
	if(document.getElementById(fieldId).value.length < minLimit)
	{
		alert(message);
		is_false = false;
		return is_false;
	}
	
	return true;
}

function remainingChars(divIdValue, divIdRemain, charLimit)
{
	field = document.getElementById(divIdValue);
	if(!field) { return false; }
	
	if(field.value.length > charLimit)
	{		
		alert("You've reached the character limit.");
		field.value = field.value.substr(0, charLimit);
	}
	
	document.getElementById(divIdRemain).innerHTML = (charLimit - field.value.length);	
}

function fillQuestion(questionId, question)
{
	document.getElementById('question_id').value = questionId;
	document.getElementById('Question').value = question;
}

function popLayer(divId, fileName)
{
	if(!document.getElementById(divId)) { return false; }
		
	d = document.getElementById(divId);

	d.style.display    = 'block';
	d.style.background = '#ffffff';
	d.style.position   = 'absolute';
	d.style.left       = '50%';
	d.style.top        = '50%';
	d.style.marginTop  = '-125px';
	d.style.marginLeft = '-225px';
	d.style.width      = '450px';
	d.style.height     = '250px';
	d.style.border     = '1px solid #000000';
	d.style.overflow   = 'auto';
	
	d.innerHTML = '<div style="padding: 8px;">Loading, please wait&hellip;</div>';
	ajaxGET(divId, '../g-core/page-permissions.ajax.php?f=' + fileName)
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
