function setToDefault(ID,defaultVal) { /* If no value then this will set it back to the default color */
	if (!document.getElementById(ID).value) { 
		if (defaultVal && defaultVal.length) {
			setTo = defaultVal;
		} else {
			setTo = document.getElementById(ID).defaultValue;
		}
		document.getElementById(ID).value = setTo;
		document.getElementById(ID).style.color = 'silver';
	}
}
function clearDefault(ID,defaultVal) { /* User clicked in the box, if current value equals default then clear it */
	if (defaultVal && defaultVal.length) {
		checkOn = defaultVal;
	} else {
		checkOn = document.getElementById(ID).defaultValue;
	}
	if (document.getElementById(ID).value == checkOn) { 
		document.getElementById(ID).value = '';
		document.getElementById(ID).style.color = 'black'; 
	}
}
function flashMessage() { 
	setTimeout("setMessageColor('#CCFF99')", 1000); setTimeout("setMessageColor('#D9FFB3')", 2000); 
}
function setMessageColor(color) { 
	document.getElementById('messageContent').style.backgroundColor = color; 
}
function setMessage(message) { document.getElementById('messageContent').innerHTML = message; setMessageColor('#CCFF00'); flashMessage(); }
function hide(divID) {	document.getElementById(divID).style.display = 'none'; }
function show(divID) { 	document.getElementById(divID).style.display = ''; }
function swapShowHide(divID) { 	if (document.getElementById(divID).style.display == 'none') { show(divID); } else { hide(divID); } }
function saveSupport() {
	var url = '/index.cfm?event=feedback.support'; 
 	if (!document.getElementById('supportHelpWith').value) {
		alert('Please select what you would like help with');
		return;
	}
	var send = 'supportText='+escape(document.getElementById('supportText').value) + '&email=' + document.getElementById('supportEmail').value + '&supportHelpWith=' + escape(document.getElementById('supportHelpWith').value) + '&machiiInfo=' + escape(document.getElementById('machiiInfo').value);
	document.getElementById('supportDiv').innerHTML = "<br>Saving...";
	postForm(url,send);
}
function postForm(url,sendStr) {
    if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } else {	alert('save not authorized'); }
	if (req) {
		req.onreadystatechange = processFeedback;
		req.open('POST', url);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(sendStr);
	} else { alert('No req') }
}
function processFeedback() 	{
    if (req.readyState == 4) {
        if (req.status == 200) {
			document.getElementById('supportDiv').innerHTML = req.responseText;
        } else {
            alert('There was a problem retrieving data:\n' + req.statusText);
        }
    }
}
var loggedOutNotifier = function () {
	alert('Your session has timed out.  Please either:\n\n- click on logout in the top right corner and start again.\n\n- or if you are in the middle of a task: 1) open a new window or tab 2) go to interfolio.com 3) log in 4) close new window or tab and return to this window/tab.');
}

function trimAll(sString){
	while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
	while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
}

function validateEmail(str){
	var isvalid = true;
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){isvalid=false;}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){isvalid=false;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){isvalid=false;}
	if (str.indexOf(at,(lat+1))!=-1){isvalid=false;}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){isvalid=false;}
	if (str.indexOf(dot,(lat+2))==-1){isvalid=false;}
	if (str.indexOf(" ")!=-1){isvalid=false;}
	return isvalid;
}
	