// JavaScript Document

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_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_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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function createNavbar() {
	
	var navbarHtml = '';
	
	
	navbarHtml += "<a href='index.html'><img src='images/bn-home.gif' alt='Home' name='home' width='74' height='22' border='0' id='home' onmouseover=MM_swapImage('home','','images/bn-home-o.gif',1) onmouseout=MM_swapImgRestore() /></a>"+
	"<a href='2-about.html'><img src='images/bn-about.gif' alt='About Dan' name='about' width='114' height='22' border='0' id='about' onmouseover=MM_swapImage('about','','images/bn-about-o.gif',1) onmouseout=MM_swapImgRestore() /></a>"+
	"<a href='3-issues.html'><img src='images/bn-ontheissues.gif' alt='On the Issues' name='issues' width='142' height='22' border='0' id='issues' onmouseover=MM_swapImage('issues','','images/bn-ontheissues-o.gif',1) onmouseout=MM_swapImgRestore() /></a>"+
	"<a href='4-volunteer.html'><img src='images/bn-volunteer.gif' alt='Volunteer' name='volunteer' width='113' height='22' border='0' id='volunteer' onmouseover=MM_swapImage('volunteer','','images/bn-volunteer-o.gif',1) onmouseout=MM_swapImgRestore() /></a>"+
	"<a href='5-news.html'><img src='images/bn-news.gif' alt='News' name='news' width='74' height='22' border='0' id='news' onmouseover=MM_swapImage('news','','images/bn-news-o.gif',1) onmouseout=MM_swapImgRestore() /></a>"+
	"<a href='6-contact.html'><img src='images/bn-contact.gif' alt='Contact' name='contact' width='92' height='22' border='0' id='contact' onmouseover=MM_swapImage('contact','','images/bn-contact-o.gif',1) onmouseout=MM_swapImgRestore() /></a>";
	// "<a href='7-blog.html'><img src='images/bn-blog.gif' alt='Blog' name='blog' width='77' height='22' border='0' id='blog' onmouseover=MM_swapImage('blog','','images/bn-blog-o.gif',1) onmouseout=MM_swapImgRestore() /></a>";
		
	
	document.getElementById('topNav').innerHTML = navbarHtml;
}


function activateHomeButton() {
document.home.src = "images/bn-home-x.gif";	
}

function activateAboutButton() {
document.about.src = "images/bn-about-x.gif";	
}

function activateIssuesButton() {
document.issues.src = "images/bn-ontheissues-x.gif";	
}

function activateVolunteerButton() {
document.volunteer.src = "images/bn-volunteer-x.gif";	
}


function activateNewsButton() {
document.news.src = "images/bn-news-x.gif";	
}

function activateContactButton() {
document.contact.src = "images/bn-contact-x.gif";	
}

function activateBlogButton() {
document.blog.src = "images/bn-blog-x.gif";	
}


function createFooter() {
	
	var footerHtml = '';
	
	
	footerHtml += "<img src='images/footer-logo.gif' alt='' width='50' height='37' align='absmiddle' style='padding-right:20px;' /> Copyright &copy; 2010 Debicella For Congress  |  <a href='1a-privacy.html'>Privacy Policy</a> |  <a href='1b-sitemap.html'>Site Map</a> |  <a href='#' onclick=MM_openBrWindow('https://debicella.blue-swarm.com/donate/','contribute','location=yes,status=yes,scrollbars=yes,top=0,left=0,resizable=yes,width=900,height=600')>Contribute Now</a> | Paid for by Debicella For Congress, Ginny Harger, Treasurer";
		
	
	document.getElementById('footer').innerHTML = footerHtml;
}


function createEmailForm() {
	
	var emailFormHtml = '';
	
	
	emailFormHtml += "<form name='frm' method='post' action='/cgi-bin/formmail/formtest.pl' onsubmit='return validate(frm)'><p><input name='emailAddress' value='Email Address' type='text' class='emailTextbox' /></p><p><input name='zipCode' value='Zip Code' type='text' class='zipTextbox' />  <a href='javascript:document.frm.submit()'><img src='images/bn-signup.gif' alt='Sign Up' width='78' height='20' border='0' align='absmiddle' /></a><input type=hidden name='redirect' value='http://www.debicella.com/1-thank-you.html'></p></form>";
		
	
	document.getElementById('emailForm').innerHTML = emailFormHtml;
}

function validate(frm) {
		var inputFields = new Array("emailAddress", "zipCode");
		var counter;
		var name;
		var msg = "Please complete the following fields:\n";
		var badFields = "";
		for (counter = 0; counter < inputFields.length; counter++) {
			name = inputFields[counter];
			if (frm.elements[name].value.length == 0) {
				if (name == "formmail_mail_email") {
					badFields = badFields + "  -  \n";
				} else {
					badFields = badFields + "  - " + name + "\n";
				}
			}
		}
		if (badFields.length != 0) {
			alert(msg + badFields);
			return false;
		}
		if (frm.formmail_mail_email.value.length > 0) {
			return emailCheck(frm.formmail_mail_email.value);
		} else {
			return true;
		}
	}

	function emailCheck(emailStr) {
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray=emailStr.match(emailPat);

		if (matchArray==null) {
			alert("Email address seems incorrect (check @ and .'s)");
			return false;
		}

		var user=matchArray[1];
		var domain=matchArray[2];

		if (user.match(userPat)==null) {
    			alert("The username doesn't seem to be valid.");
			return false;
		}

		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
	  		for (var i=1;i<=4;i++) {
			    if (IPArray[i]>255) {
		        	alert("Destination IP address is invalid!");
				return false;
	 	   		}
    			}
    			return true;
		}

		var domainArray=domain.match(domainPat);
		if (domainArray==null) {
			alert("The domain name doesn't seem to be valid.");
    			return false;
		}

		var atomPat=new RegExp(atom,"g");
		var domArr=domain.match(atomPat);
		var len=domArr.length;
		if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		   alert("The address must end in a three-letter domain, or two letter country.");
   			return false;
		}

		if (len<2) {
   			var errStr="This address is missing a hostname!";
			alert(errStr);
   		return false;
		}

 		return true;
	}
	
	function volunteerForm() {
		 var error_string = "";
    // check the first name field
    if (window.document.volunteerFrm.firstName.value == "")
    {
        error_string += "You must type in your first name\n";
    }
	
	    // check the last name field
	    if (window.document.volunteerFrm.lastName.value == "")
    {
        error_string += "You must type in your last name\n";
    }
	
	    // check the address field
	    if (window.document.volunteerFrm.address.value == "")
    {
        error_string += "You must type in your address\n";
    }

    // check the city field
	    if (window.document.volunteerFrm.city.value == "")
    {
        error_string += "You must type in your city\n";
    }

	    // check the zip field
	    if (window.document.volunteerFrm.zipCode.value == "")
    {
        error_string += "You must type in your zip code\n";
    }
    // check the email field
	    if (window.document.volunteerFrm.emailAddress.value == "")
    {
        error_string += "You must type in your email address\n";
    }

    // check the phone field
	    if (window.document.volunteerFrm.phone.value == "")
    {
        error_string += "You must type in your phone number\n";
    }
	
 if (error_string == "")
    {
	   return true;
	   
    } else {
        error_string = error_string;
        alert(error_string);
        return false;
    } 
}
	
	
