function delit(name,url) {
 ask=window.confirm("Are you sure you want to DELETE "+name+"? This action cannot be undone!");
 if(ask==true){
  window.location=url;
 }
}

function hide (name) {	
	Effect.BlindUp(document.getElementById(name));	
	return false;
}

function show (name) {	
	Effect.BlindDown(document.getElementById(name));
	return false;	
}

function xmsshow (name) {	
	Effect.BlindDown(document.getElementById(name));
	return false;	
}

function doAction (id,name,frompage,modaction) {
	
	var modactions = modaction.split("_");
	var page = modactions[0];
	var type = modactions[1];
	
	var actionUrl = 'xms-action.html?id='+id+'&p='+page+'&action='+ type;
	
if(type!='' && page!='') { /* only redirect if we have something to work with */
	
 if(type=='delete') { /* confirm deletes */
	 
  	ask=window.confirm("Are you sure you want to DELETE "+name+"? This action cannot be undone!");
		 
		 if(ask==true) {
		  top.window.location=actionUrl;
		 }
		 
  } else {
		 top.window.location=actionUrl;
  }
	 
}
	
}

function doSingleAction (id,name,page,type) {
	
	var actionUrl = 'xms-action.html?id='+id+'&p='+page+'&action='+ type;
	
if(type!='' && page!='') { /* only redirect if we have something to work with */
	
 if(type=='delete') { /* confirm deletes */
	 
  	ask=window.confirm("Are you sure you want to DELETE "+name+"? This action cannot be undone!");
		 
		 if(ask==true) {
		  top.window.location=actionUrl;
		 }
		 
  } else {
		 top.window.location=actionUrl;
  }
	 
}
	
}

function doFunction (page,type,func) {
	
if(func!='Any') { /* skip any */
	if(page!='' && type!='' && func!='') { /* only redirect if we have something to work with */
		 top.window.location= 'xms-function.html?page='+page+'&type='+type+'&func='+ func;
	} else {
		window.confirm("There was a problem with that function!");
	}
}
	
}

function doSubFunction (page,type,func,subid) {
	
if(func!='Any') { /* skip any */
	if(page!='' && type!='' && func!='' && subid!='') { /* only redirect if we have something to work with */
		 top.window.location= 'xms-function.html?page='+page+'&type='+type+'&func='+ func+'&subid='+ subid;
	} else {
		window.confirm("There was a problem with that sub-function!");
	}
}
	
}

function doRedirect (page) {
	if(page!='') { /* only redirect if we have something to work with */
		 top.window.location=page;
	} else {
		window.confirm("There was a problem with that link!");
	}
}

function checkAll(theForm, cName, check) {
    for (i=0,n=theForm.elements.length;i<n;i++)
        if (theForm.elements[i].className.indexOf(cName) !=-1)
            theForm.elements[i].checked = check;
}

function doMultiAction (action,formo) {	

	document.getElementById('doaction').value = action;
	
	if(action=='delete') { /* confirm deletes */
	  	ask=window.confirm("Are you sure you want to DELETE the checked items? This action cannot be undone!");
			 if(ask==true) {
			/*	testask=window.confirm("You clicked yes"); */
			  document.getElementById('multiactionform').submit();
		 	}
	  } else if(action=='archive') {
		ask=window.confirm("Are you sure you want to Archive the checked items?");
			 if(ask==true) {
			  document.getElementById('multiactionform').submit();
			 }	
      } else if(action=='export') {
	    document.getElementById('multiactionform').submit();
		/*var w = window.open('about:blank','Export_Window','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=500, top=20, left=100');
		formo.target = 'Export_Window';
		return true;*/
	  } else if(action=='print') {
	    document.getElementById('multiactionform').submit();
		/*var w = window.open('about:blank','Print_Window','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=500, top=20, left=100');
		formo.target = 'Print_Window';
		return true;*/
	  } else if(action!='') {
			document.getElementById('multiactionform').submit();
	  } else {
			top.window.location='xms-dashboard.html?xe=';
	  }	 
		
}

/* phone autotabbing */
var phone_field_length=0;
function TabNext(obj,event,len,next_field) {
	if (event == "down") {
		phone_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
				}
		}
	}
}

/* AJAX ops */

var isWorking = false;

function checkUserEmail() {

	var http = getHTTPObject(); // We create the HTTP Object

	if (!isWorking && http) {

		var element = document.getElementById('checkemail');
		element.innerHTML = '';
		var emailValue = document.getElementById("email").value;
		http.open("GET", "users/ajax/checkuseremail.php?param=" + escape(emailValue), true);
		http.onreadystatechange = function() {
			if (http.readyState == 4 && http.status == 200) {
				if (http.responseText.indexOf('invalid') == -1) {
					results = http.responseText.split(",");
						if(results[0].length < 6) {
							element.innerHTML = '';
						} else {
							if(results[1].length > 70) {
							// it has a validation error
							element.innerHTML = '<div id="ajaxerror">Check your entry again. <br> Your email is not formatted properly</div>';
							} else {
							// existing email address, throw error
							element.innerHTML = '<div id="ajaxerror">That email address is assigned an account:<br> <a href="signin.html">Sign In / Help</a></div>';
							}	
						}
					isWorking = false;
				}
			}

		}
		isWorking = true;
		http.send(null);

	}

}	

function checkPages() {

	var http = getHTTPObject(); // We create the HTTP Object

	if (!isWorking && http) {

		var element = document.getElementById('pageslink');
		element.innerHTML = '';
		var dataValue = document.getElementById("pages_name").value;
		http.open("GET", "users/ajax/checkpages.php?param=" + escape(dataValue), true);
		http.onreadystatechange = function() {
			if (http.readyState == 4 && http.status == 200) {
				if (http.responseText.indexOf('invalid') == -1) {
					results = http.responseText.split(",");
						if(results[0].length > 6) {
							element.innerHTML = '<div id="ajaxerror">That page already exists!</div>';
						} else {
							element.innerHTML = '';
						}
					isWorking = false;
				}
			}

		}
		isWorking = true;
		http.send(null);

	}

}	

/*
function checkUserAddr() {

	var http = getHTTPObject(); // We create the HTTP Object

	if (!isWorking && http) {

		var element = document.getElementById('checkaddr');
		element.innerHTML = '<span class="main">Checking ...</span>'; 
		
		var streetnumberValue = document.getElementById("ap_streetnum").value;
		var streetnameValue = document.getElementById("ap_streetname").value;
		var streettypeValue = document.getElementById("ap_streettype").value;
		var streetdirectionValue = document.getElementById("ap_streetdir").value;
		var streetunitnumberValue = document.getElementById("ap_streetunit").value;
		var cityValue = document.getElementById("ap_city").value;
		var stateValue = document.getElementById("ap_state").value;
		var zipValue = document.getElementById("ap_zip").value;

		http.open("GET", "checkaddr.php?ap_streetnum=" + escape(streetnumberValue) + "&ap_streetname=" + escape(streetnameValue) + "&ap_streettype=" + escape(streettypeValue) + "&ap_streetdir=" + escape(streetdirectionValue) + "&ap_streetunit=" + escape(streetunitnumberValue) + "&ap_city=" + escape(cityValue) + "&ap_state=" + escape(stateValue) + "&ap_zip=" + escape(zipValue), true);
		http.onreadystatechange = function() {
			if (http.readyState == 4 && http.status == 200) {
				if (http.responseText.indexOf('invalid') == -1) {
					results = http.responseText.split("^");
					var firstItem = trim(results[0]);
						if(firstItem == "no") {
							element.innerHTML = '<div id="okout" class="Tip4"><strong>Address OK!</strong></div>'; //'<div id="okout" class="Tip4" style="position:relative; top:-13; z-index:1">Address OK!</div> - '+firstItem;
						} else {
							// it returned an email address, throw error
							element.innerHTML = '<div id="errorout" class="error">A property with that address already exists in the system. <br>Please check your entries again then<br> <a href="#" onclick="javascript:checkUserAddr();" class="Link">click here to re-check</a>.</div>'; //+firstItem;
						}
					isWorking = false;
				}
			}

		}
		isWorking = true;
		http.send(null);

	}

}
*/

function getHTTPObject() {

  var xmlhttp;

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

	try {

	  xmlhttp = new XMLHttpRequest();

	} catch (e) {

	  xmlhttp = false;

	}

  }

  return xmlhttp;

}

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

/* dynamic calendars */
function getDateText(date, d) {
  var inf = dateInfo[date.print("%Y%m%d")];
  if (!inf) {
    return d + "<div class='inf'>&nbsp;</div>";
  } else {
    return d + "<div class='inf'>" + inf + "</div>";
  }
}

function dateChanged(calendar) {
  // Beware that this function is called even if the end-user only
  // changed the month/year.  In order to determine if a date was
  // clicked you can use the dateClicked property of the calendar:
  if (calendar.dateClicked) {
    // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
    var y = calendar.date.getFullYear();
    var m = calendar.date.getMonth()+1;     // integer, 0..11
    var d = calendar.date.getDate();      // integer, 1..31
    // redirect... /xms-events-list.html?year=2007&month=10&day=19
    window.location = "/xms-events-week.html?year=" + y + "&month=" + m + "&day=" + d;
  }
}

function hideStatus () {
	Element.hide('status');	
	return false;
}

function hideError (name) {	
	Element.hide('error');
	return false;	
}