function MM_jumpMenu(targ,selObj,restore)
{ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() 
{ 
  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_findObj(n, d) 
{ 
  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); return x;
}

function MM_swapImage() 
{ 
  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 FindCenter(width, height) 
{ 
       var str = "height=" + height + ",innerHeight=" + height; 
       str += ",width=" + width + ",innerWidth=" + width; 
       if (window.screen) { 				
	
               var ah = screen.availHeight - 30; 
               var aw = screen.availWidth - 10; 

               var xc = (aw - width) / 2; 
               var yc = (ah - height) / 2; 

               str += ",left=" + xc + ",screenX=" + xc; 
               str += ",top=" + yc + ",screenY=" + yc; 
       } 
       return str; 
} 

function PopupEmailThis() 
{
	w1=window.open ('/emailthis.php','popupEmailThis', FindCenter(450,380) + ',resizable=yes,scrollbars=yes,toolbar=no,location=no');     
	w1.focus();
}

function PopupPrintThis() 
{
	var LoadPageURL = document.getElementById('fullpath').value;
	if (document.getElementById('query_string') != undefined)
		LoadPageURL += document.getElementById('query_string').value;
	LoadPageURL += "&prt=1";
	w1=window.open (LoadPageURL,'popupPrintThis', FindCenter(700,550) + ',resizable=yes,scrollbars=yes,toolbar=no,location=no');     
	w1.focus();
}

function IsValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}	

function IsValidAlphaNum(str)
{
	var regexPattern = /^[0-9a-zA-Z\s]+$/m;
    	return regexPattern.test(str);
}

function IsValidNum(str)
{
	var regexPattern = /^[0-9]+$/m;
    	return regexPattern.test(str);
}

function RegisterEmailTextBoxFocus()
{
	var Email = document.getElementById('Email');
	if (Email != null)
	{
		if (Email.value == 'Enter your email here...')
		{
			Email.value = '';
		}
	}
}
function RegisterEmailTextBoxBlur()
{
	var Email = document.getElementById('Email');
	if (Email != null)
	{
		if (Email.value == '')
		{
			Email.value = 'Enter your email here...';
		}
	}
}

String.prototype.trim = function() 
{
	return this.replace(/^\s+|\s+$/g,"");
}
function ValidateAdminProfileForm($pagemode)
{
	AdminUserManagement_SetFormAction($pagemode);
	var errorList = "";
	errorList = errorList + ValidateControl("FirstName", true, "ascii", "First Name");
	errorList = errorList + ValidateControl("LastName", true, "ascii", "Last Name");
	errorList = errorList + ValidateControl("Address", false, "ascii", "Address");
	errorList = errorList + ValidateControl("Address2", false, "ascii", "Address2");
	errorList = errorList + ValidateControl("City", false, "ascii", "City");
	errorList = errorList + ValidateControl("Zip", true, "numeric", "Zip");
	errorList = errorList + ValidateControl("Email", true, "email address", "Email");
	errorList = errorList + ValidateControl("Password", true, "ascii", "Password");
	errorList = errorList + ValidateControl("Captcha", true, "captcha", "captcha");
	if (errorList != "")
	{
		alert(errorList);
	}
	else
	{
		document.userform.submit();
	}
}
function ValidateProfileForm()
{
	var errorList = "";
	errorList = errorList + ValidateControl("FirstName", true, "ascii", "First Name");
	errorList = errorList + ValidateControl("LastName", true, "ascii", "Last Name");
	errorList = errorList + ValidateControl("Address", false, "ascii", "Address");
	errorList = errorList + ValidateControl("Address2", false, "ascii", "Address2");
	errorList = errorList + ValidateControl("City", false, "ascii", "City");
	errorList = errorList + ValidateControl("Zip", true, "numeric", "Zip");
	errorList = errorList + ValidateControl("Email", true, "email address", "Email");
	errorList = errorList + ValidateControl("Password", true, "ascii", "Password");
	errorList = errorList + ValidateControl("Captcha", true, "captcha", "captcha");
	if (errorList != "")
	{
		alert(errorList);
	}
	else
	{
		document.ProfileForm.submit();
	}
}

function ValidateControl(elementID, required, dataType, friendlyName)
{
	var element = document.getElementById(elementID);
	if (element != null)
	{
		var value = element.value.trim();
		if (value == "")
		{
			if (required == true)
			{
				if (dataType == "captcha")
				{
					return "Please enter the text as it appears in the image above the Submit button into the text box below it.\n";
				} 
				else 
				{
					return friendlyName + " is required.\n";
				}
			}
		}
		else
		{
			var result = true;
			switch (dataType)
			{
				case "alpha numeric":
				    	result = IsValidAlphaNum(value);
				break;
				case "numeric":
    					result = IsValidNum(value);
				break;
				case "email address":
					result = IsValidEmail(value);
				break;
				case "ascii":
					// Accept anything
				break;
				case "captcha":
					// Accept anything
				break;
			}
			if (result == false)
			{
				return "Invalid " + friendlyName + " - must be a valid " + dataType + " value\n";
			}
		}
	}
	return "";
}
function AdminUserManagement_SetFormAction(action)
{
	var element = document.getElementById("formaction");
	if (element != null)
	{
		element.value = action;
	}
}
function SetCSVExportQueryValue(query)
{
	var element = document.getElementById("csvquery");
	if (element != null)
	{
		element.value = query;
	}
	document.exportform.submit();
}
function AdminUserManagement_ConfirmDelete()
{
	var answer = confirm("Are you sure you want to delete the selected user?");
	if (answer)
	{
		AdminUserManagement_SetFormAction("SaveDelete");
		document.adminform.submit();
	}
}
function UserManagement_ConfirmDelete()
{
	var answer = confirm("Are you sure you want to delete the selected user?");
	if (answer)
	{
		AdminUserManagement_SetFormAction("SaveDelete");
		document.userform.submit();
	}
}