// This file contains the JavaScript code for the Familiworks website
// Copyright 2006 Barbara Tripp - Tripp Web Solutions
// Some of these scripts are open source scripts obtained from others




<!-- The following are used in the anti-spam contact info functions all email addresses must be put in the following array; they are assigned ids in the pages to point them to the correct entry -->
var contactInfo = new Array();
var contactIndx = 0;
contactInfo[contactIndx] = new Array();
contactInfo[contactIndx][0] = "marla_elliott";         
contactInfo[contactIndx][1] = "Marla Elliott";         
contactInfo[contactIndx][2] = "marla";         
contactInfo[contactIndx][3] = "familiworks";          
contactInfo[contactIndx][4] = "com";  

// The following variables are used for showing the disclaimer info
// they are used in tips.php, disclaimer.php and the various tip pages



<!-- The following function is an anti-spam measure and was developed by Tripp Web Solutions.  The email address is displayed as an image on the page.  This function replaces the image with a mailto link -->
// the following formats email links 
function setEmail(id)
{
	var contactEmail = document.getElementById(id);
	// strip out generic part of email id
	var memId = id.substr(3);
	var foundEntry = 0;
	// look up email id in the array of member info
	var i;
	for (i=0; i<contactInfo.length; i++)
	{
		if (contactInfo[i][0] == memId)
		{
			foundEntry = 1;
			break;
		}
	}
	if (foundEntry == 1)
		{
			contactEmail.href = "mailto:" + contactInfo[i][2] + "@" + contactInfo[i][3] + "." + contactInfo[i][4];
		}
	else
		{
			alert ("Warning!  Missing email for this member.  Notify the webmaster");
		}
}


function setEmailAll(id)
{
	setEmail(id);
	var memEmail = document.getElementById(id);
	var emailText = memEmail.href.substr(7);
	if(document.all)
		{
    		memEmail.innerText = emailText;
		} 
		else
		{
			memEmail.textContent = emailText;
		}

}


//  The following is for the contact page
function validateContactForm()
{
	//alert ("in form validation function");
	var userEmail = document.frmcntct.email.value;
	var userName = document.frmcntct.realname.value;
	var userPhone = document.frmcntct.phone.value;
	//alert ("userEmail: " + userEmail);
	//alert ("userName: " + userName);
	//alert ("userPhone: " + userPhone);
	
	if (!validateName(userName,1,1)) 
		{
			//alert ("Error in userName");
			return false;
		}
	
	if (!validatePhone(userPhone, 1, 1))
		{
			//alert ("Error in userPhone");
			return false;
		}

	if (!validateEmail(userEmail,1,1)) 
		{
		  //alert('email address is invalid or was not entered');
			return false;
		}

	return true;

}

// validate user name
function validateName(name, man, db) 
{
//alert ("In validateName()");
	if (name == '' && man) {
   		if (db) alert('name is required');
   		return false;
		}

	var invalidChars = '\/\'\\";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) 
	{
   		if (name.indexOf(invalidChars.charAt(i),0) > -1) 
			{
      		if (db) alert('your name contains invalid characters');
      		return false;
   			}
	}

	for (i=0; i<name.length; i++) 
	{
   		if (name.charCodeAt(i)>127) 
		{
      		if (db) alert("name contains non ascii characters.");
      		return false;
  		 }
	}
	return true;
}

   
function validatePhone(userPhone, man, db)
{
	//alert ("In validatePhone()");
	if (userPhone == '' && man) {
   		if (db) alert('Phone Number is required');
   		return false;
		}
	var stripped = userPhone.replace(/[\(\)\.\-\ ]/g, '');
	
	//alert ("db is " + db);
	//alert ("stripped phone number is " + stripped);
	//alert ("parseInt(stripped) = " + parseInt(stripped));
	//alert ("isNaN(parseInt(stripped)) = " + isNaN(parseInt(stripped)));
	//strip out acceptable non-numeric characters\
	// The following line replaced 2/6/2008
	//if (isNaN(parseInt(stripped))) 
	if (isNaN(stripped)) 
	{
		if (db) 
		{
			alert("The phone number contains illegal characters.");
			return false;
		}
	}
	
	if ((stripped.length < 10)) 
	{
		if (db) alert("Your phone number is too short.  Please inlude your full phone number, including area code.");
		return false;
	}
	if ((stripped.length > 10)) 
	{
		if (db) alert("Your phone number is too long. It can be a max of 10 digits.  If you have an international number, please enter it in the question section.");
		return false;
	}
	//alert ("at end of phone validation, returning true");
	return true;
}
// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd
// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.
// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd
// You have permission to copy and use this javascript provided that
function validateEmail(addr, man, db) 
{
	 //alert ("In validateEmail()");
   if (addr == '' && man) {
   if (db) alert('email address is required');
   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
  	 if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      	if (db) alert('email address contains invalid characters');
      	return false;
   	}
	}
	for (i=0; i<addr.length; i++) {
   		if (addr.charCodeAt(i)>127) {
      		if (db) alert("email address contains non ascii characters.");
      		return false;
   		}
	}
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
  		 if (db) alert('email address must contain an @');
   		return false;
	}

	if (atPos == 0) {
   		if (db) alert('email address must not start with @');
   		return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
   		if (db) alert('email address must contain only one @');
   		return false;
	}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('email address must contain a period in the domain name');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('period must not immediately follow @ in email address');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('period must not immediately precede @ in email address');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('two periods must not be adjacent in email address');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('invalid primary domain in email address');
   return false;
}
//alert("We are at the end of email validations, returning a true value");
return true;
}
// end of contact page functions
// The following is for the tip pages
function tippage_checkreferrer()
{
	// note.  the document.referrer property only works on a live web server, not on local machine
	// check to see if the referrer's url is another page at familiworks.com
	// if it came from the trippweb familiworks demo page it's treated similarly
// in IE, the referrer may be empty if coming from the disclaimer window, which is a different window.  That's OK - if it came from the disclaimer window we're ok 
	// This will catch situations where you found the page by a search engine
	// In this case, we want to open the disclaimer window

// Note.  This routine is triggered in the body onload event of the tip page.  Events in the body tag, must reference the window not the document.  That's why we use the window.location object to get the href
// The following if statement is commented out for testing on local server.  Before uploading this to the 
// live web server uncomment it
if ((window.document.referrer != "") && (window.document.referrer.indexOf("www.familiworks.com/disclaimer.php") ==-1) &&  (window.document.referrer.indexOf("trippweb.com/demo/familiworks") == -1))
	{
//		alert("came from outside window.location.href  " + window.location.href);
		set_tiphref(window.location.href);
		open_disclaimerwindow(); 
	}
}
						
//
//-->
