///////////////////////////////////////////////////////////////////
//// 
//// website utilities - njscuba.net / A.R. Galiano ( argaliano@optonline.com )
////
///////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////
//// embed flash slideshow using xhtml object standard
//// width = pixels
//// height = pixels
//// where = name of standard images directory
//// which = name of slideshow file


///////////////////////////////////////////////////////////////////
//// simple form validator

/*

USAGE:

This validator mis-uses the css class attribute to specify validation requirements.
The class attribute is both "safe" to use in WordPress, and easily accessible in JS.

Sample syntax:

--------------------------------------------------------

<form id="form-id" ... >
<input type="text"     class="valid-required" ... />
<input type="text"     class="valid-email" ... />
<input type="text"     class="valid-phone" ... />
<input type="textarea" class="valid-required" ... ></textarea>
<input type="select"   class="valid-required" ... >
<input type="submit"   onclick="validate('form-id')"... />
</form>

------------------------------------------------------------

The "classes" trigger validation as follows:

valid-required: non-null text value or selection
valid-email:    valid email address
valid-phone:    text min length 10 characters

If none of these classes is specified for a field, the validator simply skips it. These names
will hopefully not collide with any real css classes that may be in use.

The validate function has the form id as a parameter, allowing multiple forms on a page. This is a simple
text string. The function knows nothing about the fields, nor does it need to. All set-up is done in the
html, no programming is required. Error messages are generic, the user is guided with color highlighting.

*/

function validate( frm )
{
emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i ; //// by Michael Cooper

theform = document.forms[frm] ;

if ( typeof theform  == "undefined" )
  {  
  alert( "Error - form not found" ) ;
  return false ;
  }

for( i=0 ; i<theform.length ; i++ )
  {
  thefield = theform.elements[i] ;
  ////alert( thefield.type ) ;

  if ( thefield.type == "text" && thefield.className == "valid-required" && thefield.value.length < 1 )
    {
    thefield.focus();
    thefield.style.background = "yellow" ;
    alert( "Please enter a value" ) ;
    return false ;
    } else { thefield.style.background = "white" ; }

  if ( thefield.type == "text" && thefield.className == "valid-phone" && thefield.value.length < 10 )
    {
    thefield.focus();
    thefield.style.background = "yellow" ;
    alert( "Please enter a valid phone number" ) ;
    return false ;
    } else { thefield.style.background = "white" ; }

  if ( thefield.type == "text" && thefield.className == "valid-email" && ! emailfilter.test(thefield.value) )
    {
    thefield.focus();
    thefield.style.background = "yellow" ;
    alert( "Please enter a valid email address" ) ;
    return false ;
    } else { thefield.style.background = "white" ; }

  if( thefield.type == "textarea" && thefield.className == "valid-required" && thefield.value.length < 1 )
    {
    thefield.focus();
    thefield.style.background = "yellow" ;
    alert( "Please enter a value" ) ;
    return false;
    } else { thefield.style.background = "white" ; }

  if( thefield.type == "select-one" && thefield.className == "valid-required" && thefield.selectedIndex == 0 )
    {
    thefield.focus();
    thefield.style.background = "yellow" ;
    alert( "Please make a selection" ) ;
    return false;
    } else { thefield.style.background = "white" ; }

  if( thefield.type == "radio" && thefield.className == "valid-required" )
    {
    //// tricky, maybe someday
    }

  }

return true ;
}

function popUpSWF( url, Width, Height, arg1, arg2 )
{
tools = "resizable=no,toolbar=no,location=no,directories=no,status=no,scroll=no,scrollbars=no,menubar=no,width="+Width+",height="+Height+",left=50,top=50";
url = url + "?bandwidth=" + arg1 + "&video=" + arg2 ;
newWindow = window.open( url, 'newWin', tools );
newWindow.focus();
return false;
}