function viewitem(formname,fieldname,action,intId)
	{
		frm = eval('document.'+formname);
		frmobj = eval('document.'+formname+'.'+fieldname);
		frmobj.value=intId;
		if (frm.sortorder) {
			frm.sortorder.value = "";
		}
		action = "index.cfm?fuseaction="+action;
		frm.action=action;
		frm.submit();
		
	}
function chkLoginForm(frmName) {
	lf = eval('document.'+frmName);
	if (lf.username.value == "") {
		lf.username.focus();
		alert('Please enter a username');
		return false;
	}
	if (lf.password.value == "") {
		lf.password.focus();
		alert('Please enter a password');
		return false;
	}
	return true;
}

function sortorder(url,thissort,formname) {
	theform = eval('document.'+formname);
	theform.sortorder.value = thissort;
	theform.action = url;
	theform.submit();
}
function charcount(textbox,charbox) {
	charbox.value = textbox.value.length;
}

function select_image(theItem1,theItem, thetype) {
	isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
	isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
	if(isNav){
		thepage = "FileManager/index.cfm?fuseaction=uploadfile&theObj=document." + theItem + "&type=" + thetype + "&theObj1=" + theItem1;
	} else {
		thepage = "FileManager/index.cfm?fuseaction=uploadfile&theObj=" + theItem + "&type=" + thetype + "&theObj1=" + theItem1;
	}
	
	vWinCal = window.open(thepage,"sImage","status=no,toolbar=no,location=no,scrollbars=yes,resizable=no,top=200,left=200");

}
function clearfield(fieldname) {
	p = eval('document.'+fieldname);
	p.value = '';
}


function deleteitem(formname,fieldname,action,intId) {
		frm = eval('document.'+formname);
		frmobj = eval('document.'+formname+'.'+fieldname);
		frmobj.value=intId;
		if (frm.sortorder) {
			frm.sortorder.value = "";
		}
		action = "index.cfm?fuseaction="+action;
		frm.action=action;
		frm.submit();
	}

	
function moveitem(formname,fieldname,action,intId) {
	frm = eval('document.'+formname);
	frmobj = eval('document.'+formname+'.'+fieldname);
	frmobj.value=intId;
	frm.action = "index.cfm?fuseaction="+action;
	frm.submit();
}

function emailCheck (emailStr)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)")
	return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    alert("The email username doesn't seem to be valid.")
	    return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
						   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
						    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
			alert("The email address destination IP address is invalid!")
			return false
	    	}	
    	}
	    return true
		}

	// Domain is symbolic name
		var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The email address domain name doesn't seem to be valid.")
	    return false
		}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
    	domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
   		alert("The email address must end in a three-letter domain, or two letter country.")
   		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	    var errStr="The email address is missing a hostname!"
	    alert(errStr)
   		return false
	}
		// If we've gotten this far, everything's valid!
	return true;
}
function dateDiff(dteFirstDate,dteSecondDate)
	{
		date1 = new Date();
		date2 = new Date();
		diff  = new Date();
		date1temp = new Date(dteFirstDate);
		date1.setTime(date1temp.getTime());
		date2temp = new Date(dteSecondDate);
		date2.setTime(date2temp.getTime());
		// sets difference date to difference of first date and second date
		diff.setTime(date1.getTime() - date2.getTime());
		timediff = diff.getTime();		
		if (timediff > "0")
		{
			return false;
		}
		return true;
	}	
	
function URLBrowser(fieldName) {
	window.open('/admin_area/index.cfm?fuseaction=app.URLBrowser&fieldName='+fieldName,'URLBrowser');
}
function eventBrowser(fieldName,layerName) {
	window.open('/admin_area/index.cfm?fuseaction=events.calendar&eventBrowser=true&fieldName='+fieldName+'&layerName='+layerName,'eventBrowser');
}
function NPPage(formname,intPageNumStart,intCurrentPage,fuseaction)
	{
		f = eval('document.'+formname);
		f.action="index.cfm?fuseaction="+fuseaction;
		f.StartRow.value= intPageNumStart;
		f.PageNum.value=intCurrentPage;
		f.submit();
		
	}
 function pageThru(formname,fieldname,action,onpage,strStartRow)
	{
		var intCurrentPage = "";
		var intPageNumStart = "";
		var OnEachPage = "";			
		OnEachPage=onpage;
		frm = eval('document.'+formname);
		frmobj = eval('document.'+formname+'.'+fieldname);
		intCurrentPage = frmobj.value;			
		intPageNumStart = (((intCurrentPage - 1) * OnEachPage) + 1);
		frm.action=action;
		frm.StartRow.value= intPageNumStart;
		frm.PageNum.value=intCurrentPage;
		frm.submit();
	}
	
	
	//TRIM ----------------------------------------------------------------------------
function Trim(inString) {
  var retVal = "";
  var start = 0;
  while ((start < inString.length) && (inString.charAt(start) == ' ')) {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
    --end;
  }
  
  if(start <= end){
    retVal = inString.substring(start, end);
  }
  
  return retVal;
}//Trim()

//ISEMAILADDR -----------------------------------------------------------------------
function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}//isEmailAddr()

//ISVALIDZIP ------------------------------------------------------------------------
function isValidZip(strZip) {
var valid = "0123456789-";
var hyphencount = 0;

if (strZip.length!=5 && strZip.length!=10) {
  return false;
}
for (var i=0; i < strZip.length; i++) {
  temp = "" + strZip.substring(i, i+1);
  if (temp == "-") hyphencount++;
  if (valid.indexOf(temp) == "-1") {
    return false;
  }
  if ((hyphencount > 1) || ((strZip.length==10) && ""+strZip.charAt(5)!="-")) {
    return false;
  }
}
return true;
}//isValidZip()

//ISNUMERIC ---------------------------------------------------------------------------
function IsNumeric(strString)
{
  var strValidChars = "0123456789";
  var strChar;
  var blnResult = true;
  
  //test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
  {
    strChar = strString.charAt(i);
    if (strValidChars.indexOf(strChar) == -1)
    {
      blnResult = false;
    }
  }
  return blnResult;
}//IsNumeric 

//ISVALIDPHONE--------------------------------------------------------------------------
function IsValidPhone(areacode,prefix,suffix){
  var phone = areacode.toString() + prefix.toString() + suffix.toString()
  return ((phone.length == 10) && IsNumeric(areacode) && IsNumeric(prefix) && IsNumeric(suffix))
}//IsValidPhone 

function createXMLHttpRequest() {
	var xmlhttp=false;
	var agt = navigator.userAgent.toLowerCase();
	if (agt.indexOf('msie')!= -1 && document.all) {
		var control = (agt.indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
		try {
			//alert('ok b4');
			xmlhttp = new ActiveXObject(control);
			//alert('ok after');
		} catch (e) {
			//alert('no activex');
		}
	} else {
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		} else {
			//alert('no activex here either!');
		}	
	}
	return xmlhttp;
}

function getScreenSize() {
	var agt = navigator.userAgent.toLowerCase();
	myWidth = 0;
	myHeight = 0;
	if (agt.indexOf('msie') != -1) {
		myWidth = document.body.offsetWidth;
		myHeight = document.body.offsetHeight;
	} else {
		if(window.innerWidth) {
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if(document.body.clientWidth) {
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
	}
	return myWidth + ',' + myHeight;	
}

function getCurrentScreen() {
	var agt = navigator.userAgent.toLowerCase();
	myWidth = 0;
	myOffLeft = 0;
	myHeight = 0;
	myOffTop = 0;
	if (agt.indexOf('msie') != -1) {
		myWidth = document.body.offsetWidth;
		myOffLeft = document.body.scrollLeft;
		myHeight = document.body.offsetHeight;
		myOffTop = document.body.scrollTop;
	} else {
		if(window.innerWidth) {
			myWidth = window.innerWidth;
			myOffLeft = window.pageXOffset;
			myHeight = window.innerHeight;
			myOffTop = window.pageYOffset;
		} else if(document.body.clientWidth) {
			myWidth = document.body.clientWidth;
			myOffLeft = document.body.scrollLeft;
			myHeight = document.body.clientHeight;
			myOffTop = document.body.scrollTop;
		}
	}
	return myWidth + ',' + myOffLeft + ',' + myHeight + ',' + myOffTop;	
}

function ajaxloadingscreen(msg) {
	if (document.getElementById('ajaxloading') && document.getElementById('loadingtext')) {
		//prop = document.getElementById('ajaxproperties');
		wh = getCurrentScreen().split(",");
		w = wh[0];
		w2 = wh[1];
		h = wh[2];
		h2 = wh[3];
		myx = (parseInt(w) / 2 ) - 150;
		if (parseInt(h2) > parseInt(h)) {
			myy = parseInt(h2) + 100;
		} else {
			myy = (parseInt(h) - 100);
		}
		//prop.innerHTML = 'w: '+w+' h: '+h+' myx: '+myx+' myy: '+myy;
		document.getElementById('loadingtext').innerHTML = msg;
		document.getElementById('ajaxloading').style.pixelLeft = 0;
		document.getElementById('ajaxloading').style.left = 0;
		document.getElementById('ajaxloading').style.pixelTop = 0;
		document.getElementById('ajaxloading').style.top = 0;
		document.getElementById('ajaxloading').style.visibility='';
	}
}
function closeajaxloadingscreen() {
	if (document.getElementById('ajaxloading')) {
		document.getElementById('ajaxloading').style.visibility='hidden';
	}
}