// Pop-up window code...
/*-------------------------------------------------------------------------------------*\
 | Function: popUpWindow( string, string, integer, integer )
 |
 | Purpose: To encapsulate the code used to pop open a X x Y window into the middle
 |			of the user's screen.
 |
 | Props:	http://www.irt.org (Internet Related Technologies) for code examples
 |
 | Args:	strName - A string describing the intended name of the window.
 |			strURL - A string describing the URL you want loaded into the pop-up window.
 |			intHeight - An integer defining the length of Y. 
 |			intWidth - An integer defining the length of W.
 | NOTE!
 |			Use the following bounds (in pixels) for the defined resolutions:
 |
 |			640 x 480 -- (( 1 <= intHeight <= 400 ) and ( 1 <= intWidth <= 600 ))
 |			800 x 600 -- (( 1 <= intHeight <= 520 ) and ( 1 <= intWidth <= 760 ))
 |			1024 x 768 -- (( 1 <= intHeight <= 688 ) and ( 1 <= intWidth <= 984 ))
 |
 | Author:	Michael Stilson Jr.
\*-------------------------------------------------------------------------------------*/
function popUpWindow(strName,strURL,intHeight,intWidth)  
{
	var xMax=0;
	var yMax=0;
	var window_handle=0;

	if(document.all)
	{	// Then it's IE...
		xMax=screen.width;
		yMax=screen.height;
	}
	else
	{
		if(document.layers)
		{	// Then it's Netscape...
			xMax=window.outerWidth; 
			yMax=window.outerHeight;
		}
		else
		{	// Default to an 800x600 resolution...
			xMax=760; 
			yMax=520;
		}
	}
	// Calculate position to the center of the screen...
	var	xOffset=((xMax-intWidth)/2);
	var	yOffset=((yMax-intHeight)/2);

	if(window_handle)	window_handle.close();
		
	window_handle=window.open(strURL,strName,"height="+intHeight+",width="+intWidth+",screenX="+xOffset+",screenY="+yOffset+",alwaysRaised=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=no,top="+yOffset+",left="+xOffset);

	window_handle.focus();
}

// Login authentication scripts
/*-------------------------------------------------------------------------------------*\
 | Function: isEmail_RegExp( string )
 |
 | Purpose: To see if a email is valid.
 |
 | Props:	http://www.informit.com for a most excellent JavaScript reference
 |
 | Args:	strValue - A string describing an email address.
 |
 | Author:	Michael Stilson Jr.
\*-------------------------------------------------------------------------------------*/
function isEmail_RegExp( strValue )
{
	var objValidateSpecial = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var objValidateName = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

	return ( !objValidateSpecial.test(strValue) && objValidateName.test(strValue) );  
}

/*-------------------------------------------------------------------------------------*\
 | Function: isEmail_Manual( string )
 |
 | Purpose: To see if a email is valid.
 |
 | Props:	http://www.informit.com for a most excellent JavaScript reference
 |
 | Args:	strValue - A string describing an email address.
 |
 | Author:	Michael Stilson Jr.
\*-------------------------------------------------------------------------------------*/
function isEmail_Manual( strValue )
{
	return ( strValue.indexOf(".") > 2 ) && ( strValue.indexOf("@") > 0 ); 
}

/*-------------------------------------------------------------------------------------*\
 | Function: ValidateRegistration( object, object )
 |
 | Purpose: To validate the email entered by the user before submitting the form.
 |
 | Props:	http://www.informit.com for a most excellent JavaScript reference
 |
 | Args:	dfoForm - An object reference to the form to be focused.
 |		dioEmail - An object reference to the email field to verify.
 |
 | Author:	Michael Stilson Jr.
\*-------------------------------------------------------------------------------------*/
function ValidateRegistration(dfoForm,dioEmail)
{
	var EmptyEmail = false;
	var ValidEmail = false;
	var RegExpAvailable = false;
	var strEmail = dioEmail.value
	var strErrorMessages = "";

	if(window.RegExp)
	{
		var strChar = "a";
		var objRegExpression=new RegExp(strChar);
    
		if( objRegExpression.test(strChar)) RegExpAvailable=true;
	}

	EmptyEmail=strEmail=='';

	if(RegExpAvailable)
	{
		ValidEmail=isEmail_RegExp(strEmail)
	}
	else
	{
		ValidEmail=isEmail_Manual(strEmail)
	}
		
	if(EmptyEmail)
	{
		alert("Please enter your email address so that we may confirm your registration.");
	}
	
	if(((!ValidEmail)&&(!EmptyEmail)))
	{
		alert("Your email address appears to be invalid. \n\n\tYou typed: " + strEmail + "\n\nPlease make sure it is entered correctly and then resubmit.");
	}

	if(((!EmptyEmail)&&(ValidEmail)))
	{
		strErrorMessages = ValidateRequiredFields(dfoForm);

		if(strErrorMessages != "")
		{
			alert("Please fill in the following required fields:\n\n" + strErrorMessages + "\nThen click on \"Register\" again. Thank you.");
		}
		else
		{
			dfoForm.submit();
		}
	}
}

/*-------------------------------------------------------------------------------------*\
 | Function: ValidateRequiredFields( object )
 |
 | Purpose: To validate that all required fields have data.
 |
 | Props:	http://www.informit.com for a most excellent JavaScript reference
 |
 | Args:	dfoForm - An object reference to the form to be focused.
 |
 | Author:	Michael Stilson Jr.
\*-------------------------------------------------------------------------------------*/
function ValidateRequiredFields(dfoForm)
{
	var strErrorMessage = "";

	var arrFieldList = new Array("txtFirstName","txtLastName","txtCompany","txtPhone");
	var arrTitleList = new Array("First Name","Last Name","Company","Phone");

	for( var i = 0; i < arrFieldList.length; i++ )
	{
		if(dfoForm.elements[arrFieldList[i]].value == "")
		{
			strErrorMessage = strErrorMessage + "\to- " + arrTitleList[i] + "\n";
		}
	}

	return strErrorMessage;
}

// Misc Client-side processing functions

/*-------------------------------------------------------------------------------------*\
 | Function: SetFocusToFirstField( object )
 |
 | Purpose: To set the focus on the first field of the form when the page loads.
 |
 | Props:	http://www.informit.com for a most excellent JavaScript reference
 |
 | Args:	dfoForm - An object reference to the form to be focused.
 |
 | Author:	Scott Quibell, Michael Stilson Jr.
\*-------------------------------------------------------------------------------------*/
function SetFocusToFirstField(dfoForm)
{
	var intFieldIndex=0;
	
	// if we have a form...
	if(document.forms.length>0)
	{
		// find the first visible element in this form
		while(((intFieldIndex<dfoForm.elements.length)&&(dfoForm.elements[intFieldIndex].type=='hidden')))
		{
			intFieldIndex++;
		}
		// and now set focus to it if we found one...
		if(intFieldIndex<dfoForm.elements.length) dfoForm.elements[intFieldIndex].focus();
	}
}