
$(document).ready(function(){

$("#docForm").attr("method", "post");
$("#docForm").attr("action", "rare_bird_documentation.php");

var f = document.forms[0];
var d = document;

$("#add_favs").html("<a href='#' id='addBookmark' title='Add this page to your favorites'>Bookmark this page</a>");
$("#add_favs").css("display", "block");

$(":button").click(function(){
if(confirm("Are you sure you want to clear this form? Doing so" +"\n" + "will completely erase your entries. If you do want to" + "\n" + "erase your entries, click OK. If you don't, click Cancel."))
{
for(i=0;i<f.elements.length-2;i++)
{
f.elements[i].checked=false;
f.elements[i].value="";
}
}

else
{
return false;
}

});

$("a#top").click(function(){
$(document).scroll(0,0);
});

$("a#addBookmark").click(function(){
var bookmark_url="http://theorniphile.info/rare_bird_documentation/index.html";
var text_description="Illinois Rare Bird Documentation Form";
if ($.browser.msie)
{
window.external.AddFavorite(bookmark_url,text_description);
}

else
{
alert("For PC users, press the Control (Ctrl), Shift, and \"D\" keys on your keyboard to bookmark this site. For Mac users, press the Command (Apple) key and the \"D\" key on your keyboard." + "\n\n" + "- IOS Webmaster");
}

});

$(":submit").click(function(){

reg_exp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/
//regular expression to test if the entered e-mail address is valid

for(i=0;i<f.elements.length-3;i++)
{
if(f.elements[i].value.search(/http/i) > -1)
{
alert("No URLs please.")
f.elements[i].focus();
f.elements[i].value="";
return false;
}
}

if(f.elements[0].checked == false && f.elements[1].checked == false && f.elements[2].checked == false && f.elements[3].checked == false && f.elements[4].checked == false && f.elements[5].checked == false && f.elements[6].checked == false && f.elements[7].checked == false && d.getElementById("other").value == "") 
{
alert("You didn't indicate why you are documenting this sighting (question #1).");
f.elements[0].focus();
return false;
}

if(d.getElementById("species").value.length < 4)
{
alert("You didn't say what species you're documenting (question #2).");
d.getElementById("species").focus();
return false;
}

if(d.getElementById("number").value.length < 1)
{
alert("You didn't indicate how many birds there were (question #3).");
d.getElementById("number").focus();
return false;
}

if(d.getElementById("age_sex_plumage").value.length  < 4)
{
alert("You didn't say what age, sex, or plumage this bird is (question #4).");
d.getElementById("age_sex_plumage").focus();
return false;
}

if(d.getElementById("date").value.length < 4)
{
alert("You didn't include a date for this sighting (question #5).");
d.getElementById("date").focus();
return false;
}

if(d.getElementById("location").value.length < 4)
{
alert("You didn't give a location for this sighting (question #6).");
d.getElementById("location").focus();
return false;
}

if(d.getElementById("observers").value.length < 4)
{
alert("You didn't say who the observers were (question #7).");
d.getElementById("observers").focus();
return false;
}

if(d.getElementById("your_name").value.length < 8)
{
alert("You didn't include your name (question #8).");
d.getElementById("your_name").focus();
return false;
}

if(d.getElementById("mailing_address").value.length < 8)
{
alert("You didn't include your mailing address (question #9).");
d.getElementById("mailing_address").focus();
return false;
}

if(!reg_exp.test(d.getElementById("email_address").value))
{
alert("Not a valid e-mail address (question #10).");
d.getElementById("email_address").focus();
return false;
}

if(d.getElementById("others_agreeing").value.length < 4)
{
alert("You didn't indicate who agreed with the identification (question #11).");
d.getElementById("others_agreeing").focus();
return false;
}

if(d.getElementById("others_not_agreeing").value.length < 4)
{
alert("You didn't say who didn't agree with the identification (question #12).");
d.getElementById("others_not_agreeing").focus();
return false;
}

if(d.getElementById("description").value.length < 8)
{
alert("You didn't include a description (question #13).");
d.getElementById("description").focus();
return false;
}

if(d.getElementById("behavior").value.length < 8)
{
alert("You didn't include a description of the behaviour (question #14).");
d.getElementById("behavior").focus();
return false;
}

if(d.getElementById("vocalizations").value.length < 4)
{
alert("You didn't include a description of the vocalization, if heard (question #15).");
d.getElementById("vocalizations").focus();
return false;
}

if(d.getElementById("habitat").value.length < 8)
{
alert("You didn't include a description of the habitat (question #16).");
d.getElementById("habitat").focus();
return false;
}

if(d.getElementById("optical_equipment").value.length < 8)
{
alert("You didn't say what kind of optical equipment was used (question #17).");
d.getElementById("optical_equipment").focus();
return false;
}

if(d.getElementById("distance").value.length < 4)
{
alert("You didn't give a distance for this sighting (question #18).");
d.getElementById("distance").focus();
return false;
}

if(d.getElementById("time_of_observation").value.length < 4)
{
alert("You didn't give a time for this sighting (question #19).");
d.getElementById("time_of_observation").focus();
return false;
}

if(d.getElementById("total_time_of_observation").value.length < 4)
{
alert("You didn't give a total time of observation (question #20).");
d.getElementById("total_time_of_observation").focus();
return false;
}

if(d.getElementById("weather_conditions").value.length < 4)
{
alert("You didn't describe the weather for this sighting (question #21).");
d.getElementById("weather_conditions").focus();
return false;
}

if(d.getElementById("experience").value.length < 4)
{
alert("You didn't indicate what your experience is with " + "\n" + "this species and similar species (question #22).");
d.getElementById("experience").focus();
return false;
}

if(d.getElementById("similar_species").value.length < 8)
{
alert("You didn't eliminate similar species (question #23).");
d.getElementById("similar_species").focus();
return false;
}

if(!f.photos[0].checked  && !f.photos[1].checked)
//make sure a checkbox is checked
{
alert("You didn't say if photos were taken (question #24).");
f.photos[0].focus();
return false;
}

if(f.photos[0].checked  && d.getElementById("photographer").value.length < 4)
//make sure that if the "yes" checkbox is checked a name is also given
{
alert("You said photos were taken but " + "\n" + "you didn't say by whom (question #25).");
d.getElementById("photographer").focus();
return false;
}

if(d.getElementById("books_advice").value.length < 4)
{
alert("You didn't say what books were consulted or " + "\n"  +  "what advice was received, if any (question #26).");
d.getElementById("books_advice").focus();
return false;
}

if(d.getElementById("field_notes").value.length < 4)
{
alert("You didn't say how long after the sighting field notes were recorded (question #27).");
d.getElementById("field_notes").focus();
return false;
}

if(d.getElementById("duration").value.length < 4)
{
alert("You didn't say how long after the sighting this form was completed (question #28).");
d.getElementById("duration").focus();
return false;
}

});

$("#info1").mouseover(function(){
$("#tip_blurb1").css("visibility", "visible");
$("#tip_blurb1").html("Your e-mail address won't be sold or given to anyone. IOS takes internet privacy very seriously.");
});

$("#info1").mouseout(function(){
$("#tip_blurb1").css("visibility", "hidden");
});

$("#info2").mouseover(function(){
$("#tip_blurb2").css("visibility", "visible");
$("#tip_blurb2").html("If the answer to question 24 is yes, please indicate who the photographer is.");
});

$("#info2").mouseout(function(){
$("#tip_blurb2").css("visibility", "hidden");
});

$(".txt_inputs :input, .txt_input").focus(function(){
$(this).css("background", "#f0f8ff");
});

$(".txt_inputs :input, .txt_input").blur(function(){
$(this).css("background", "#ffffff");
});

});
