//image rollovers created by Dreamweaver

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//resize fix for netscape 4 created by Dreamweaver

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// pop-up window for photo gallery

function OpenNewWindow(WindowPicture,WindowLabel,WindowParameters)
	{
	NewWindow=window.open("","NewOne",WindowParameters);
	NewWindow.document.write ("<html><head><title>");
	NewWindow.document.write ("Martin 16 Photo Gallery");
	NewWindow.document.write ("</title>");
	NewWindow.document.write ("<link rel='stylesheet' href='/includes/m16.css' type='text/css'>");
	NewWindow.document.write ("</head>");
	NewWindow.document.write ("<body>");
	NewWindow.document.write ("<h3 align='center'>");
	NewWindow.document.write (WindowLabel);
	NewWindow.document.write ("</h3>");
	NewWindow.document.write ("<h5 align='center'>");
	NewWindow.document.write ("Click the image to close this window");
	NewWindow.document.write ("</h5>");
	NewWindow.document.write ("<p align='center'>");
	NewWindow.document.write ("<a href='JavaScript:this.close()'><img src=");
	NewWindow.document.write (WindowPicture);
	NewWindow.document.write ("></a></p>");
	NewWindow.document.write ("</body></html>");
	NewWindow.document.close();
	return false;
	}

// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// master function - check the form

function checkForm() {
    var why = "";
    why += checkEmail(document.form1.email.value);
   // why += checkPhone(document.form1.phone.value);
   // why += checkName(document.form1.name.value);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

// email - check for proper formatting

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}


// name - may not be blank

function checkName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your name.\n";
    } 
return error;
}       

function checkForm2(form1,setpass) {
    var why = "";
    why += checkEmail2(document.form1.email.value);
    why += checkName2(document.form1.firstname.value);
    why += checkName2b(document.form1.lastname.value);
    why += checkAddress(document.form1.address1.value);
    why += checkCity(document.form1.city.value);
    why += checkState(document.form1.province.value);
    why += checkZip(document.form1.postalcode.value);
    why += checkPassword(document.form1.password1.value , document.form1.password2.value , setpass);
    //why += checkEntry(document.form1.giveaway.value);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

// email - check for proper formatting

function checkEmail2 (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// name - may not be blank

function checkName2 (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your first name.\n";
    } 
return error;
}   

function checkName2b (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your last name.\n";
    } 
return error;
}   

function checkAddress (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your address.\n";
    } 
return error;
} 

function checkCity (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your city.\n";
    } 
return error;
} 

function checkState (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your state.\n";
    } 
return error;
} 

function checkZip (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your zip code.\n";
    } 
return error;
}  

function checkEntry (strng) {
var error = "";
if (strng == "") {
   error = "You didn't choose a giveaway to participate in.\n";
    } 
return error;
} 

function checkPassword ( pass1 , pass2 , setpass) {
var error = "";
if ( setpass == "checkpass" ) {
  if ( pass1 == "" && pass2 == "" ) {
    error = "You must set a password.\n";
	return error;
  }
  if ( pass1 != pass2 ) {
    error = "The two passwords must match.\n";
	return error;
  }
}
else if ( setpass == "" ) {
  if ( pass1 != "" || pass2 != "" ) {
    if ( pass1 != pass2 ) {
      error = "The two passwords must match.\n";
    }
  }
}
return error;
}

