$(document).ready(function(){


$("#senderC").validate({
errorClass: "bwError", validClass: "BWsuccess",
errorContainer: "#messageBox1, #messageBox2",
errorLabelContainer: "#messageBox1 ul",
wrapper: "li", debug:true,

submitHandler: function(form) {
company = document.senderC.company.value;
contact2 = document.senderC.contactName.value;
for (var i=0; i<document.senderC.contact.length; i++)  {
if (document.senderC.contact[i].checked)  {
var radio = document.senderC.contact[i].value}
} 
email2 = document.senderC.emailfnd.value;
telno = document.senderC.telephone.value;
fax = document.senderC.fax.value;
addr = document.senderC.address.value;
city = document.senderC.city.value;
state = document.senderC.state[document.senderC.state.selectedIndex].value;
zipcode = document.senderC.zip.value;
related = document.senderC.related[document.senderC.related.selectedIndex].value;
message = document.senderC.message.value;

msg ='\nThe following is the results ECMC Foundation Contact Us form.\n\n\nTopic Selection: '+related+'\nRadio Selection:'+radio+'\nContact:'+contact2+'\nCompany:'+company+'\nAddress: \n'+addr+'\n'+city+' '+state+' '+zipcode+'\nPhone Number:'+telno+'\nFax Number:'+fax+'\nEmail address:'+email2+'\nMessage: '+message;
document.sender2.onsuccess.value = window.location.href;
document.sender2.onfailure.value = "http://"+window.location.hostname+"/details/error.html";
document.sender2.message.value = msg;
$("#downloadLink").html("<p>Thank you for your comments/questions. A member of our staff will get back to you soon.</p>");
centerPopup();  
loadPopup(); 
}
});



});






$(document).ready(function(){
    jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Enter a valid phone number");

 
$("#senderS").validate({
errorClass: "bwError", validClass: "BWsuccess",
errorContainer: "#messageBox1, #messageBox2",
errorLabelContainer: "#messageBox1 ul",
wrapper: "li", debug:true,

rules: {
    telephone: {required: true, phoneUS: true},
    email: {required: true, email: true}
  },

submitHandler: function(form) {

name = document.senderS.name.value;
address = document.senderS.address.value;
city = document.senderS.city.value;
organization = document.senderS.organization.value;
phone = document.senderS.phone.value;
email = document.senderS.email.value;
bestPhone = document.senderS.bestPhone.value;
bestEmail = document.senderS.bestEmail.value;
bestDay = document.senderS.bestDay.value;
bestTime = document.senderS.bestTime.value;
preferred = document.senderS.preferred.value;
alternate = document.senderS.alternate.value;
alternate2 = document.senderS.alternate2.value;
content5 = document.senderS.content5.value;

topic = document.senderS.topic[document.senderS.topic.selectedIndex].value;


other = document.senderS.other.value;
audience = document.senderS.audience.value;
media = document.senderS.media.value;
directions = document.senderS.directions.value;

msg = '\n\nContact Info:' +name+', '+address+', '+city+'\n\nOrganization: '+organization+'\n\nPhone: '+phone+'\n\nEmail: '+email+ 
'\n\nBest Bet: '+bestPhone+' '+bestEmail+' '+bestDay+' '+bestTime+ 
'\n\nPreferred: '+preferred+' '+alternate+' '+alternate2+
'\n\nContent: '+content5+
'\n\nTopic: '+topic+
'\n\nOther: '+other+ 
'\n\nAudience: '+audience+
'\n\nMedia: '+media+
'\n\nDirections: '+directions;

document.sender2.onsuccess.value = window.location.href;
document.sender2.onfailure.value = "http://"+window.location.hostname+"/details/error.html";
document.sender2.message.value = msg;
sendMailTo = checked();
document.sender2.location.value = sendMailTo;
document.sender2.action = "/servletMailer/sendmailservlet";
$("#downloadLink").html("<p>Thank you for requesting a speaker. A member of our staff will get back to you soon.</p>");
centerPopup();  
loadPopup(); 
}
});


function parseSearchString()
{var pairs=unescape(location.search.substring(1).replace(/\+/g," ")).split('&');
	for (var i=0;i<pairs.length;i++){
		var pair = pairs[i].split('=');
		this[pair[0]]=pair[1];
	}
}



function checked() {
var len = document.senderS.location.length;
var elementValue = new Array();	
var a = 0;
for (i=0; i<len; i++){
if (document.senderS.location[i].checked==true) {
elementValue[a]= document.senderS.location[i].value;
a=a+1;
}}
return elementValue;
}

function radioGet()
{for (var i=0; i < document.senderS.salutation.length; i++){
   if (document.senderS.salutation[i].checked){var rad_val = document.senderS.salutation[i].value;
      } 
   }return rad_val;
}


});








$(document).ready(function(){
   
$("#senderA").validate({
errorClass: "bwError", validClass: "BWsuccess",
errorContainer: "#messageBox1, #messageBox2",
errorLabelContainer: "#messageBox1 ul",
wrapper: "li", debug:true,


submitHandler: function(form) { 
var name = document.senderA.name.value;
var address = document.senderA.address.value;
var city = document.senderA.city.value;
var organization = document.senderA.organization.value;
var phone = document.senderA.phone.value;
var grade = document.senderA.grade.value;
var email = document.senderA.email.value;

var bestPhone = document.senderA.bestPhone.value;
var bestEmail = document.senderA.bestEmail.value;
var bestDay = document.senderA.bestDay.value;
var bestTime = document.senderA.bestTime.value;

var preferred = document.senderA.preferred.value;
var alternate = document.senderA.alternate.value;
var alternate2 = document.senderA.alternate2.value;

var topic = document.senderA.topic[document.senderA.topic.selectedIndex].value;

var msg = '\n\nContact Info:' +name+', '+address+', '+city+'\n\nOrganization: '+organization+'\n\nPhone: '+phone+'\n\nEmail: '+email+ '\n\nBest Bet: '+bestPhone+' '+bestEmail+' '+bestDay+' '+bestTime+ '\n\nPreferred: '+preferred+' '+alternate+' '+alternate2+'\n\nTopic: '+topic;

document.sender2.message.value = msg;
document.sender2.onsuccess.value = window.location.href;
document.sender2.onfailure.value = "http://"+window.location.hostname+"/details/error.html";
sendMailTo = checked();
document.sender2.location.value = sendMailTo;
document.sender2.action = "/servletMailer/sendmailservlet";
$("#downloadLink").html("<p>Thank you for requesting an adviser. A member of our staff will get back to you soon.</p>");

centerPopup();  
loadPopup(); 
}
});

function radioGet()
{for (var i=0; i < document.senderA.salutation.length; i++){
   if (document.senderA.salutation[i].checked)
      {var rad_val = document.senderA.salutation[i].value;
      }
   }return rad_val;
}

function checked() {
var len = document.senderA.location.length;
var elementValue = new Array();	
var a = 0;
for (i=0; i<len; i++){
if (document.senderA.location[i].checked==true) {
elementValue[a]= document.senderA.location[i].value;
a=a+1;
}}
return elementValue;
}



});





 $(document).ready(function(){
    jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Enter a valid phone number");

 

$("#sender").validate({
errorClass: "bwError", validClass: "BWsuccess",
errorContainer: "#messageBox1, #messageBox2",
errorLabelContainer: "#messageBox1 ul",
wrapper: "li", debug:true,

rules: {
    telephone: {required: true, phoneUS: true},
    email: {required: true, email: true}
  },

 
submitHandler: function(form) { 

var school = document.sender.school.value;
var contact = document.sender.contact.value;
var title = document.sender.title.value;
var addr = document.sender.address.value;
var city = document.sender.city.value;
var state = document.sender.state[document.sender.state.selectedIndex].value;
var zipcode = document.sender.zip.value;
var telno = document.sender.telephone.value;
var email = document.sender.email.value;
var download = $("input[name='download']:checked").val();
var msg ='\nThe following is the results of the Foundation Download form.\n\n\nSchool/Organization:'+school+ '\nName: '+contact+'\nTitle:'+title+'\nAddress: \n'+addr+'\n'+city+' '+state+' '+zipcode+'\nPhone Number:'+telno+'\nEmail address:'+email+'\nDownloads: '+download;
document.sender2.onsuccess.value = window.location.href;
document.sender2.message.value = msg;
document.sender2.subject.value = download + " was Downloaded";
myLinks(download);
}

});

$("#senderNews").validate({
errorClass: "bwError", validClass: "BWsuccess",
errorContainer: "#messageBox1, #messageBox2",
errorLabelContainer: "#messageBox1 ul",
wrapper: "li", debug:true,

rules: {
    telephone: {required: true, phoneUS: true},
    email: {required: true, email: true}
  },

 
submitHandler: function(form) { 
var download = "None";
var email = document.senderNews.email.value;
var msg ='\nPlease add '+email+' to the Foundation news mailing list';
document.sender2.onsuccess.value = window.location.href;
document.sender2.onfailure.value = "http://"+window.location.hostname+"/details/error.html";
document.sender2.message.value = msg;
myLinks(download);
}

});


function mySubmit() {alert("My Submit");
$("#sender").ajax({
      type: "POST",
      url: "/servletMailer/sendmailservlet",
      data: msg,
      success: function() {alert("success");
       	myLinks(download);}
        });
    }
    
function SubmitForm(){
	document.sender2.action = "/servletMailer/sendmailservlet";
	document.sender2.submit();

} 

function myLinks(download){
var howTo = "<p><em>Click below to start your download.</em></p>";

if (download == "PERSIST" || download.match("PERSIST") == "PERSIST"){
$("#downloadLink").html(howTo+"<a href='/idc/groups/ucm_ecmc/@ecmc_web/documents/native/foundation_download_persist.zip'>PERSIST download<a/>");
}

if (download == "Believing" || download.match("Believing") == "Believing"){
$("#downloadLink").html(howTo+"<a href='/idc/groups/ucm_ecmc/@ecmc_web/documents/native/download_believingthecollegedr.zip'>Believing the College Dream download<a/>");
}

if (download == "Realizing" || download.match("Realizing") == "Realizing"){
$("#downloadLink").html(howTo+"<a href='/idc/groups/ucm_ecmc/@ecmc_web/documents/native/realizingthecollegedream.zip'>Realizing the College Dream download<a/>");
}

if (download == "All" || download.match("All") == "All"){
$("#downloadLink").html(howTo+"<a href='/idc/groups/ucm_ecmc/@ecmc_web/documents/native/allfoundationcurriculum.zip'>Download All<a/>");
}

centerPopup();  
loadPopup();  
  }

  }); 
  
  
  
 

  
function showRequest(formData, jqForm, options) { 
    var queryString = $.param(formData); 
    alert('About to submit: \n\n' + queryString); 
    return true; 
} 
 
function showResponse(responseText, statusText)  { 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
} 
