<!--
// Block right click on window
	if (window.Event) 
	document.captureEvents(Event.MOUSEUP); 
	function nocontextmenu()  
	{
	event.cancelBubble = true
	event.returnValue = false;
	return false;
	}
	function norightclick(e)	
	{
	if (window.Event)	
	{
	if (e.which == 2 || e.which == 3)
	return false;
	}
	else
	if (event.button == 2 || event.button == 3)
	{
	event.cancelBubble = true
	event.returnValue = false;
	return false;
	}	
	}
	document.oncontextmenu = nocontextmenu;		
	document.onmousedown = norightclick;		

// for Portal
// open new window
  function OpenNew(p1, p2)
  { 

	var filename = p2 ;
	var wintitle = p1 ;
	var width = '600';
//	var heigh = '550';
	var heigh = '600';
	var attr = 'toolbar=no,menubar=0,scrollbars=yes,status=0,resizable=no,top=0,left=0,screenX=0,screenY=0';

	var openwindow = newWin(wintitle, filename, width, heigh, attr);
  }

// end for portal


// TAB
function dotab(first,next){
if (first.getAttribute&&first.value.length==first.getAttribute("maxlength"))
next.focus();
}

var isIE = (document.all)? true:false;
var isNS = (document.layers)? true:false;
var isNS6 = (document.getElementById&&!document.all)? true:false;

function highlight(field) {
  field.focus();
  field.select();
}


function newWin(name, url, width, height, args) {
	var newWin = new Object();

	newWin.args = args;
	newWin.url = url;
	newWin.name = name;
	newWin.width = width;
	newWin.height = height;

	if (document.layers) {// browser is NN
		newWin.left = window.screenX + ((window.outerWidth - newWin.width) / 2);
		newWin.top = window.screenY + ((window.outerHeight - newWin.height) / 2);
		var attr = 'screenX=' + newWin.left + ',screenY=' + newWin.top + ',resizable=yes,width=' + newWin.width + ',height=' + newWin.height + ',' + newWin.args;
	}
	else {// browser is MSIE
		newWin.left = (screen.width - newWin.width) / 2;
		newWin.top = (screen.height - newWin.height) / 2;
		var attr = 'left=' + newWin.left + ',top=' + newWin.top + ',width=' + newWin.width + ',height=' + newWin.height + ',' + newWin.args;
	}

	newWin.win=window.open(newWin.url, newWin.name, attr);
	newWin.win.opener=self;
	newWin.win.focus();
}


//Email Validation
function isEmailAddr(emailId) {

//	var invalidChars = new String(" /:,;'&");
	var invalidChars = new String(" /:,;'&~!#$%^&*`");
	var invalidCharsSize = invalidChars.length;
	var atPos=-1;
	var periodPos=-1;


	for (var i=0; i < invalidCharsSize; i++)
	{
		var badchar = invalidChars.charAt(i);
		if (emailId.indexOf(badchar,0) != -1)
		{
			return false;
		}
	}
	atPos = emailId.indexOf("@");
	if (atPos == -1 || atPos == 0)
	{
		return false;
	}
	if (emailId.indexOf("@",atPos+1) != -1)
	{
		return false;
	}
	periodPos = emailId.indexOf(".",atPos);
	if(periodPos == -1)
	{
		return false;
	}
	if (emailId.indexOf(".@") != -1)
	{
		return false;
	}
	if (emailId.indexOf("@.") != -1)
	{
		return false;
	}
	if (emailId.indexOf("..") != -1)
	{
		return false;
	}

	return true;
}


function CheckEmail(email)
{
	if (email.value == "")
	{
		alert("Please enter a value for the \"email\" field.");
		email.focus();
		return false;
	}

	if (!isEmailAddr(email.value))
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com with no special character such as : , ; ' & ~ ! # $ % ^ & * ` ");
		email.focus();
		return false;
	}

	if (email.value.length < 3)
	{
		alert("Please enter at least 3 characters in the \"email\" field.");
		email.focus();
		return false;
	} 

	return true;
}

function ClearEmail(email)
{
	email.value = "";
}

function encodetext(form)
{
	form.message2.value = escape(form.message.value);
	form.message2.value = Replace(form.message2.value, "%0D%0A", "<br>");
//		text.value = unescape(text.value);
	return true;

}

function encodetext2(text1,text2)
{
	var temp
	temp = escape(text1.value);
	text2.value = Replace(temp, "%0D%0A", "<br>");
	text2.value = unescape(text2.value);
	return true;

}


function goback() {
	 history.go(-1);
}


// delete last digit from source number
function DelLastDigit(theForm){
	theForm.phone.value=String(theForm.phone.value).substring(0,theForm.phone.value.length-1);
}

// clear source number
function ClearDigits(theForm){
	theForm.phone.value="";
}

function FormValidator(theForm) {

	if (theForm.message.value == "") {
//			alert("Please enter a value for the \"message\" field.");
		alert("Please enter a \"message\".");
		theForm.message.focus();
		return false;
	}

// get HTML message
	var temp
	temp = escape(theForm.message.value);
	theForm.message2.value = Replace(temp, "%0D%0A", "<br>");
	theForm.message2.value = unescape(theForm.message2.value);
	
	if (theForm.name.value == "") {
//			alert("Please enter a value for the \"name\" field.");
		alert("Please enter your \"name\".");
		theForm.name.focus();
		return false;
	}

	if ( (theForm.phone1.value == "") || (theForm.phone2.value == "") || (theForm.phone3.value == "") ){
		if (theForm.phone1.value == ""){
			theForm.phone1.focus();
//				alert("Please enter a value for the \"area code phone\" field.");
			alert("Please enter your \"area code\".");
			return false;
		}
		else {
			if (theForm.phone1.value.length < 3) {
//					alert("Please enter at least 3 digits in the \"area code phone\" field.");
				alert("Please enter your 3-digit \"area code\" of your phone number.");
				theForm.phone1.focus();
				return false;
			}
		}


		if (theForm.phone2.value == ""){
			theForm.phone2.focus();
//				alert("Please enter a value for the \"prefix phone\" field.");
			alert("Please enter your \"prefix\".");
			return false;
		}
		else {
			if (theForm.phone2.value.length < 3) {
//					alert("Please enter 3 digits in the \"prefix phone\" field.");
				alert("Please enter 3-digit \"prefix\" of your phone number.");
				theForm.phone2.focus();
				return false;
			}
		}
		if (theForm.phone3.value == ""){
			theForm.phone3.focus();
//				alert("Please enter a value for the \"subfix phone\" field.");
			alert("Please enter your \"suffix\".");
			return false;
		}
		else {
			if (theForm.phone3.value.length < 4) {
//					alert("Please enter at least 4 digits in the \"subfix phone\" field.");
				alert("Please enter 4-digit \"suffix\" of your phone number.");
				theForm.phone3.focus();
				return false;
			}
		}
		return false;
	}
/*
	if (theForm.phone1.value.length < 3) {
		alert("Please enter at least 3 digits in the \"phone area code\" field.");
		theForm.phone1.focus();
		return false;
	}

	if (theForm.phone2.value.length < 3) {
		alert("Please enter at least 3 digits in the \"prefix phone\" field.");
		theForm.phone2.focus();
		return false;
	}

	if (theForm.phone3.value.length < 4) {
		alert("Please enter at least 4 digits in the \"subfix phone\" field.");
		theForm.phone3.focus();
		return false;
	}
*/
	theForm.phone.value = theForm.phone1.value + theForm.phone2.value + theForm.phone3.value;
//		if ( !CheckPhoneNumber(theForm.phone,"your phone number") ){
//			return false;
//		}

	var  valid_phone = ( CheckPhoneNumber(theForm.phone,theForm.phone1,theForm.phone2,theForm.phone3,"your phone number") );
// ?  false:true;
//alert ("valid phone " + valid_phone);
	if (!valid_phone) {
		return valid_phone;
	}

	if (theForm.email.value == "") {
		alert("Please enter your \"email\".");
		theForm.email.focus();
		return false;
	}

	if (!isEmailAddr(theForm.email.value)) {
		alert("Please enter a complete email address in the form: yourname@yourdomain.com with no special character such as : , ; ' & ~ ! # $ % ^ & * ` ");
		theForm.email.focus();
		return false;
	}

	if (theForm.email.value.length < 3) {
//			alert("Please enter at least 3 characters in the \"email\" field.");
		alert("Please enter at least 3 characters in your \"email\".");
		theForm.email.focus();
		return false;
	}
	return true;
}

function printPage() {
	if (window.print) {
		setTimeout('window.print();', 200);
	} else {
		alert("Please choose the \"print\" option from the file menu in your browser");
	}
}

/*
--------------------------------------------------------------------------------
Function
--------
Replace( sExpression, sFind, sReplaceWith, iStart, iCount )

Have you looked at JavaScript's RegExp documentation and thought, "Huh?!?" I 
have. That's why I wrote this JavaScript version of VBScript's Replace function.
Please let me know if you found this useful. Comments and questions are welcome.

Author: Greg Paye, http://www.paye.org/greg/, gregpaye@hotmail.com
--------------------------------------------------------------------------------
Purpose
-------
Find a substring within a string, and replace it with another substring. Returns 
string with substitutions made. 
--------------------------------------------------------------------------------
Arguments
---------
sExpression	- Required. String expression containing substring to replace. 
sFind		- Required. Substring being searched for.
sReplaceWith	- Required. Replacement substring.
iStart		- Optional. Position within expression where substring search 
				is to begin. 0 is default. 
iCount		- Optional. Number of substring substitutions to perform. If 
				omitted, the default value is -1, which means make 
				all possible substitutions. This can only be 
				specified if the start parameter is specified.
--------------------------------------------------------------------------------
Usage
-----
Replace( "Hello, World", "World", "Everybody" )		returns "Hello, Everybody"
Replace( "ABC_ABC_ABC_ABC", "ABC", "XYZ", 4 )		returns "ABC_XYZ_XYZ_XYZ"
Replace( "ABC_ABC_ABC_ABC", "ABC", "XYZ", 0, 1 )	returns "XYZ_ABC_ABC_ABC"
Replace( "ABC_ABC_ABC_ABC", "ABC", "XYZ", 8, 1 )	returns "ABC_ABC_XYZ_ABC"
--------------------------------------------------------------------------------
Error Conditions
----------------
If the expression string, find substring, or replace substring are null, then 
null will be returned. If find substring is equal to the replace substring, then 
the expression will be returned unchanged. If the length of expression string or 
find substring are 0, then the expression will be returned. If the start position 
specified is greater than the length of the expression, then the expression 
will be returned.
--------------------------------------------------------------------------------	
*/
function Replace( sExpression, sFind, sReplaceWith, iStart, iCount ) {
	
	var iLengthExp 		= 0;
	var iRemoveLength 	= 0;
 	var iStartPosition 	= 0;
	var iSubstringLength 	= 0;
	var iLoop		= 0;
	var sFirstPart 		= "";
	var sThirdPart 		= "";
	var sStartSubstring 	= "";
	var sReturnValue 	= "";

	// check for nulls in required parameters	
	if (( sExpression == null ) || ( sFind == null ) || ( sReplaceWith == null )) {
		return null;
	};

	if ( sFind == sReplaceWith ) { return sExpression; }		// prevent nasty recursion later
	if (( iStart == null ) || ( iStart < 0 )) { iStart = 0; };	// parameter check, default to 0
	if (( iCount == null ) || ( iCount < 1 )) { iCount = -1; }; 	// parameter check, default to -1

	iLengthExp 	= sExpression.length;	// check length of expression
	iRemoveLength 	= sFind.length;		// check length of sFind

	// check if sExpression or sFind are empty/blank
	if (( iLengthExp < 1 ) || ( iRemoveLength < 1 )) {	
		return sExpression;			
	};

	if ( iStart > iLengthExp ) { return sExpression; };	// sanity check start vs. expression length

	if ( iStart > 0 ) {	// do this if the user specified a place to start the replacement(s)

		// extract substring left of the start position
		sLeftOfStart 	= sExpression.substring( 0, iStart );
		
		// replace sExpression with the substring to the right of the iStart specified
		sRightOfStart	= sExpression.substring( iStart, iLengthExp);	
		sExpression	= sRightOfStart;	
	};

	iStartPosition 	= sExpression.indexOf( sFind );	// check to see if sFind is in sExpression 
	
	while( iStartPosition != -1 ) {		// do this while sFind is found within sExpression

		// sExpression's length will probably change in this loop
		iLengthExp = sExpression.length;		
		
		// based on the new iStartPosition, determine where 
		// we will get sExtract from sExpression
		iSubstringLength = iStartPosition + iRemoveLength;

		// get everything to the left of the substring being removed
		sFirstPart = sExpression.substring( 0, iStartPosition );
		
		// get everything to the right of the substring being removed
		sThirdPart = sExpression.substring( iSubstringLength, iLengthExp );

		// reform sExpression with the left substring, the replacement 
		// substring, and the right substring
		sExpression = sFirstPart + sReplaceWith + sThirdPart;

		// check to see if there is another instance of the sFind 
		// substring left in sExpression
		iStartPosition = sThirdPart.indexOf( sFind );

		// if substring still remains in the string, move the cursor up
		// to prevent any nasty recursion
		if ( iStartPosition > -1 ) {
			iStartPosition = sFirstPart.length + sReplaceWith.length + iStartPosition;
		};
		
		iLoop++;	

		// if the user specified a count, only do as many replacements as specified
		if (( iCount > -1 ) && ( iLoop == iCount )) { iStartPosition = -1; };

	};		// end while( iStartPosition != -1 )
	
	// if user specified start point, put the substring from before the start point back 
	// with the substring that had the replacement(s) performed on it
	if ( iStart > 0 ) { 					
		sExpression = sLeftOfStart + sExpression;
	};
	sReturnValue = sExpression;

	return sReturnValue;

// end Replace()
}

//-->

