
function isDate()
{
	var newdate = new Date();      // 'var' makes them LOCAL
	var day    = newdate.getDay();
	var month  = newdate.getMonth();
	var weekday= newdate.getDate();
	var year   = newdate.getYear();
	
	if (year < 2000) year = year + 1900;
	
	var arday   = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var armonth = new Array("January ","February ","March ","April ","May ","June ","July ","August ","September ", "October ","November ","December ")
	var time = (arday[day] +",&nbsp;&nbsp;" + armonth[month] +" "+weekday + ", " + year);
	document.write(time);
}

function clearText(thefield) {
	if (thefield.defaultValue == thefield.value)
		thefield.value = "" 
} 

/****************************************************************************************
|                                                                                       |
|		This following are the scripts for popup javascript windows on the site.        |
|		openWin() is on https://redbackgw.docmagic.com/webservices/login/newuser.jsp    |
|		checkUSPhone (Phone, emptyOK[boolean: determines if it is required])            |
|                                                                                       |
****************************************************************************************/

// we need something dynamic... let's try this:
function dynPopUpWin(URL, windowName, width, height, miscParams) { 
	var dsiWin = null;
	if (dsiWin != null) dsiWin.close();
	dsiWin = window.open(URL,'dsiWin','width='+width+',height='+height+','+miscParams);
	dsiWin.focus();	
}			

// used by dmo to pop automated tutorials
function launchTutorial(tutorialName) {
	var tutorialLocation = '/support/tutorials/files/cam/main.jsp?tutorial=';
	if (tutorialName == 'planfilter') dynPopUpWin(tutorialLocation+'planfilter','Adding a New Loan Program','888','691','');
}

function printWin(URL)	{ receipt = window.open(URL,'receipt','width=530,height=340,scrollbars=yes'); }
function openWin(URL) 	{ helpWindow = window.open(URL,'helpWin','width=475,height=400,scrollbars=yes'); }
function popout(url) 	{ privacynotice = window.open(url,'privacynotice','width=520,height=430,scrollbars=yes,resizable=yes,menubar=no'); }

function loanmagicHelp(URL) {
	var loanmagicHelp = null;
	if (loanmagicHelp == null || loanmagicHelp.closed) 
		loanmagicHelp = window.open(URL,'loanmagicHelp','width=510,height=439,scrollbars=yes,resizable=yes'); 
	loanmagicHelp.focus();
}

function dmonnlineClosed(URL) {
	var dmonnlineClosed = null;
	if (dmonnlineClosed == null || dmonnlineClosed.closed) 
		dmonnlineClosed = window.open(URL,'dmonnlineClosed','width=475,height=500,scrollbars=no,resizable=no');  // left=300,top=100,
	dmonnlineClosed.focus();
}

function adminHelp(URL) {
	var adminHelp = null;
	if (adminHelp == null || adminHelp.closed) 
		adminHelp = window.open(URL,'adminHelp','width=475,height=500,scrollbars=yes,resizable=yes');  // left=300,top=100,
	adminHelp.focus();
}
function partnerHelp(URL) {
	var partnerHelp = null;
	if (partnerHelp == null || partnerHelp.closed) 
		partnerHelp = window.open(URL,'partnerHelp','width=450,height=400,resizable=yes');  // left=300,top=100,
	partnerHelp.focus();
}
function websheetsWin(URL) {
   newWindow = window.open(URL,'websheetsWin','width=850,height=750,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes'); 
   if (newWindow.opener == null) newWindow.opener = window;
   newWindow.opener.name = "opener";
}
function loanmagicSetup(URL) {
	var loanmagicSetup = null;
	if (loanmagicSetup == null || loanmagicSetup.closed) 
		loanmagicSetup = window.open(URL,'loanmagicSetup','width=745,height=514,scrollbars=no,resizable=no');  // width=665,height=593
	loanmagicSetup.focus();
}
function loanmagicPricing(URL) {
	var loanmagicPricing = null;
	if (loanmagicPricing == null || loanmagicPricing.closed) 
		loanmagicPricing = window.open(URL,'loanmagicPricing','width=539,height=382,scrollbars=no,resizable=no');  // width=665,height=593
	loanmagicPricing.focus();
}
function shopImage(IMG,x,y) {
	var shopImage = null;
	if (shopImage == null || shopImage.closed) 
		shopImage = window.open(IMG,'shopImage','width=' + x + ',height=' + y + ',scrollbars=no,resizable=no');
	shopImage.focus();
}

function popImage(imageName,imageTitle,x,y) {
	var fileName  = '/webservices/viewer/page.jsp';
	var NN = '/webservices/viewer/frame.jsp' + '?' + escape(imageName);
	var MSIE = '/webservices/viewer/page.jsp' + '?imgsrc=' + imageName + "&imgtitle=" + imageTitle;
	
	if (navigator.appName == 'Netscape')
	    myWindow = window.open(NN,'docmagicImage','width=' + x + ',height=' + y);
	else
	    myWindow = window.open(MSIE,'docmagicImage','width=' + x + ',height=' + y); // + ',scrollbars=yes'
}

function popAutoTutorial(fileName,fileTitle,x,y) {
	//var fileName  = '/support/tutorials/files/page.jsp';
	var fileType = fileName.substring(fileName.indexOf(".")+1, fileName.length);
	var NN = '/webservices/support/tutorials/files/'+fileType+'/frame.jsp' + '?' + escape(fileName);
	var MSIE = '/webservices/support/tutorials/files/'+fileType+'/page.jsp' + '?filesrc=' + fileName + "&filetitle=" + fileTitle;
	
	if (navigator.appName == 'Netscape')
	    flashWindow = window.open(NN,'AutomatedTutorial','width=' + x + ',height=' + y);
	else
	    flashWindow = window.open(MSIE,'AutomatedTutorial','width=' + x + ',height=' + y); //  + ',resizable=yes'
}

/****************************************************************************************/

// required to launch the loanmagic defaults applet
function popPreferences(host) {
	var LoanMagicAdmin;
	var IE4Only = false;
	if (navigator.appVersion.indexOf("4.0 (compatible; MSIE 4.01; Windows 95)") == 0)
		IE4Only = true;
	
	if (navigator.appName == 'Microsoft Internet Explorer') {
		if ((IE4Only) && (dmonlinelogin == null))
			LoanMagicAdmin = window.open( "about:blank","loanmagicWin","width=785,height=536","resizable=no,scrollbars=no,status=no"); //"width=739,height=538"
		else
			LoanMagicAdmin = window.open("http://"+host+"/webservices/ws/defaults.jsp","loanmagicWin","width=785,height=536","resizable=no,scrollbars=no,status=no");
		}
	else {
		LoanMagicAdmin = window.open("http://"+host+"/webservices/ws/defaults.jsp","loanmagicWin","toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,location=no")
	}
}

/****************************************************************************************/

// was clickSeva chat application (comments and variables to be used when https logging is available from clickseva)
// now gotoassist... pass user to our own webhelp page (ie, no more popup) - will get rid of this once the apps (dmo, dmw) are updated 
	
// 10/18/2006 DMO still will use the function call to open the webhelp page
	
function dmoWebHelp() {
	var webHelp = null;
	if (webHelp == null || webHelp.closed) 
		webHelp = window.open('/support/webhelp','webHelp');
	webHelp.focus();
}			

/****************************************************************************************/

//   Pass the current <SELECT> object and the name of the <SELECT> to DEFAULT from.
//	 Ex: 	 <select name="BeneOrgState" onFocus="SelectDefault(this, 'BeneState')">

function SelectDefault(obj, DfltSelect) {
	if (obj.selectedIndex == 0) {
		obj.selectedIndex = eval("obj.form." + DfltSelect + ".selectedIndex"); // ex: 'LendState'
	}
	return 1;
}

//   Pass the current 'INPUT TEXT' object and the name of the TEXT to DEFAULT from.
//	 Ex: <INPUT TYPE=TEXT NAME=BeneName VALUE="default" onFocus="Default(this,'LendName')">

function Default(obj, From) {
	if (obj.value == "") {
		obj.value = eval("obj.form." + From + ".value"); // IE and NS handle this way
	}
	return 1;
}

// Just add this to your <INPUT...> tag:     onChange="UpCase(this)"  (LowCase would work too)
function UpCase( obj ) {
  obj.value=obj.value.toUpperCase();
}

function checkZip( obj ) {
	zip = obj.value;					// This is the STRING value (NOT the object...)
  if ((zip.length != 5) && (zip.length != 0) && (zip.length != 10)) {
	  alert("Zip Code must be 5 or 10 characters");
		obj.focus();
		obj.select();	// SELECT the old value ?
		return(false);	// This doesn't really matter?
	}			
	bCharsPresent = false;
	for (i = 0; i < zip.length; i++) {
		if ((zip.charAt(i) >= "A") && (zip.charAt(i) <= "Z")) {	bCharsPresent = true; }
		if ((zip.charAt(i) >= "a") && (zip.charAt(i) <= "z")) {	bCharsPresent = true; }
	}
	if ( bCharsPresent ) {
	  	alert("Zip code must be all numbers");
	  	obj.focus();
	  	obj.select();
	  	return (false);
	}
	return (true);
}

function CheckNum( obj ) {
	if (isNaN( obj.value )) {
		alert("Invalid numeric value");
	  obj.focus();
		obj.select();
		return (false);
	}
}

function ValidEmail(field) { // Validate form with field named email by ValidEmail(form)
  //var field = form.email;
  var str = field.value;
  if (window.RegExp) {
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(str) && reg2.test(str)) { return true; }
    field.focus();
    field.select();
	alert("Invalid email. Ex. example@docmagic.com.");
    return false;
  } else {
    if(str.indexOf("@") >= 0)
      return true;
    field.focus();
    field.select();
	alert("Invalid email. Ex. example@docmagic.com.");
    return false;
  }
}

/****************************************************************************************
|                                                                                       |
|		This following is the script for validating and reformatting phone numbers      |
|		http://developer.netscape.com/docs/examples/javascript/formval/overview.html    |
|                                                                                       |
****************************************************************************************/

var digits = "0123456789";
var digitsInUSPhoneNumber = 10;
var defaultEmptyOK = false
var iUSPhone = "This field must be a 10 digit U.S. phone number. Please reenter it now."
var phoneNumberDelimiters = "()- ";
var validUSPhoneChars = digits + phoneNumberDelimiters;

function isEmpty(s) {   
	return ((s == null) || (s.length == 0))
}

function stripCharsInBag (s, bag) {   
	var j = 0;
    var returnString = "";
	
	if (s.charAt(0) == "1")
		j = 1;

    for (i = j; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function isDigit (c) {   
	return ((c >= "0") && (c <= "9"))
}

function isInteger (s) {   
	var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

function reformat (s) {   
	var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function isUSPhoneNumber (s) {   
	//s = trimString(s);
	if (isEmpty(s)) 
       	if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
    	else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

function setFocus (theField) {   
	theField.focus();
    theField.select();
    //alert(s)
    //return false
}

function reformatUSPhone (USPhone){   
	return (reformat (USPhone, "(", 3, ")", 3, "-", 4))
}

function checkUSPhone (theField, emptyOK){   
	if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) {
          //return warnInvalid (theField, iUSPhone);
		  setFocus(theField);
		  return false;
	   } else {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}

// same function as above... but NEW version. we want to use this in the form, at the time of making the change, instead of at the time of onsubmit
// TODO: remove instances of the function called above
function validatePhone (theField, emptyOK)
{   if (validatePhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) {
	      alert(iUSPhone);
          return warnInvalid (theField, iUSPhone);
	   } else {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}

// Notify user that contents of field theField are invalid.
function warnInvalid (theField, s) {   
	theFieldID = theField.id;
	// this is a workaround for FF's bug in which focus and select DO NOT WORK
	setTimeout("document.getElementById(theFieldID).focus();",1);
	setTimeout("document.getElementById(theFieldID).select();",1);
    return false;
}

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}




