
//======================================================================
//======================================================================
//
// jsutil.js - Javascript Utility Subroutines
//
//    IsBlankStr()       - returns true if a string is composed only
//                         of whitespace characters.
//
//    CheckForm()        - validates required fields for the Dream Registry
//                         form.
//
//======================================================================
//======================================================================

        
//create a special window and load the curency express redirect page
function displayPopupWindow(displayURL) 
{
	var w;
    w=window.open(displayURL, 'DreamRegFrame', 'height=590,width=445,scrollbars=no,menubar=no,toolbar=no,resizable=no,status=no,screenX=80,screenY=10');
	w.focus();
}
        
function closePopupWindow() 
{
    var callingWin = window.opener;
    window.close();
    callingWin.focus();
}

        
//==================================================
// Return true if the string contains only white-
// space (space, tab, newline).  Return false
// otherwise.
//
// Input: String
//==================================================
//
function IsBlankStr(Str) {
	for (var i=0; i < Str.length; ++i) {
		var c = Str.charAt(i);
		if (c != ' ' && c != '\t' && c != '\n')
			return false;
	}
	return true;
}

        
//==================================================
// Return true if the string is a valid date of
// the form mm/dd/yy or mm/dd/yyyy.  Return false
// otherwise.
//
// Input: String
//==================================================
//
function IsValidDate(Str) {

	var d = new Date(Str);

	if (isNaN(d.getTime()))
		return false;

	return true;
}

//==================================================
// Validate required fields in the Dream Registry form.
//
// Input: Dream Registry form
//==================================================
//
function CheckForm(form) {

	if (IsBlankStr(form.Name.value)) {
		alert("Please enter your name.");
		form.Name.focus();
		return false;
	}
	if (IsBlankStr(form.Email.value)) {
		alert("Please enter your email address (this will not be published).");
		form.Email.focus();
		return false;
	}
	if (form.Email.value.indexOf("@")==-1 || form.Email.value.indexOf(".")==-1) {
		alert("Please enter a valid email address.")
		form.Email.focus();
		return false;
	}
	if (!IsValidDate(form.Date.value)) {
		alert("Please enter a valid date (mm/dd/yy or mm/dd/yyyy).");
		form.Date.focus();
		return false;
	}
	if (IsBlankStr(form.Info.value)) {
		alert("Please enter your Dream information.");
		form.Info.focus();
		return false;
	}

	return true;
}

