// JavaScript Document
function trim(n) {
	// Remove leading spaces and carriage returns
	while ((n.substring(0, 1) == ' ') || (n.substring(0, 1) == '\n') || (n.substring(0, 1) == '\r'))
	{
		n = n.substring(1, n.length);
	}

	// Remove trailing spaces and carriage returns
	while ((n.substring(n.length-1, n.length) == ' ') || (n.substring(n.length-1, n.length) == '\n') || (n.substring(n.length-1, n.length) == '\r'))
	{
		n = n.substring(0, n.length-1);
	}
	return n;
}
function isNumeric(n) {
	return !isNaN(parseInt(n));
}
function isEmail(email) {
    var regExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return regExp.test(email);
}
function isZipCode(zip) {
   var regExp = /^\d{5}([\-]\d{4})?$/;
   return (regExp.test(zip));
}
function isSSN(ssn) {
	strng = trim(ssn);
	var validate = true;
	var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
	var numDashes = ssn.split('-').length - 1;
	if (matchArr == null || numDashes == 1) {
		validate = false;
	} else {
		if (parseInt(matchArr[1], 10) == 0) {
			validate = false;
		} else {
			validate = true;
		}
	}
	return validate;
}
function isNonZeroSSN(ssn) {
	var regExp = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([\-]?)(\d{2})\2(\d{4})$/;
	if (!regExp.test(ssn)) { return false; }
	var temp = ssn;
	if (ssn.indexOf("-") != -1) { temp = (ssn.split("-")).join(""); }
	if (ssn.indexOf(" ") != -1) { temp = (ssn.split(" ")).join(""); }
	if (temp.substring(0, 3) == "000") { return false; }
	if (temp.substring(3, 5) == "00") { return false; }
	if (temp.substring(5, 9) == "0000") { return false; }
	return true; 
}
function isDate(date) {
	var regExp = /^(((0?[1-9]|1[012])\/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])\/(29|30)|(0?[13578]|1[02])\/31)\/(19|[2-9]\d)\d{2}|0?2\/29\/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$/;
	return (regExp.test(date));
}
function changeDate(formElement, val, calElement) {
	eval("document."+formElement).value = val;
	callDatePicker(calElement, formElement);
	if (document.getElementById("hideme") && formElement == "form1.mbr_expire"){
		document.getElementById("hideme").style.display = "block";
	}
}
function callDatePicker(calElement, formElement) {
	if (document.getElementById(calElement).innerHTML == "&nbsp;"){
		datepicker = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='170' height='190'><param name='movie' value='http://draco001/flash/date_picker.swf?passForm=" + formElement + "&passDate=" + eval("document."+formElement).value + "&passCal=" + calElement + "'>"
        datepicker = datepicker + "<param name='quality' value='high'><embed src='http://draco001/flash/date_picker.swf?passForm=" + formElement + "&passDate=" + eval("document."+formElement).value + "&passCal=" + calElement + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='170' height='190'></embed></object>"
		document.getElementById(calElement).innerHTML = datepicker;
	} else {
		document.getElementById(calElement).innerHTML = "&nbsp;";
	}
}
function openSmartField(formName, IDfieldName, NamefieldName, depValue, smartSQL, depLabel, database) {
	if (depValue.length > 0) {
		smSQL = smartSQL + depValue;
		//alert(smSQL);
		if(document.getElementById("smartForm" + IDfieldName).innerHTML == "&nbsp;"){
			smpicker = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='117' height='102'><param name='movie' value='flash/smart_picker.swf?fn="+formName+"&id="+IDfieldName+"&nm="+NamefieldName+"&sql="+smSQL+"&dat="+database+"' />"
			smpicker = smpicker + "<param name='quality' value='high' /><embed src='flash/smart_picker.swf?fn="+formName+"&id="+IDfieldName+"&nm="+NamefieldName+"&sql="+smSQL+"&dat="+database+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='117' height='102'></embed></object>"
			document.getElementById("smartForm" + IDfieldName).innerHTML = smpicker;
		} else {
			document.getElementById("smartForm" + IDfieldName).innerHTML = "&nbsp;";
		}
	} else {
		alert('Please select a ' + depLabel + ' first.');
	}
}
function setSmartForm(formName, nameElement, idElement, data, label) {
	eval("document."+formName+"."+nameElement).value = label;
	eval("document."+formName+"."+idElement).value = data;
	document.getElementById("smartForm"+idElement).innerHTML = "&nbsp;";
}
