// JavaScript Document
// Modified leadform field validation script
// Based on verify-original.js 
// 'Time' form field activated 10/31/2007
// 'lead_status' hidden field activated 01/10/2008
// show/hide added on form page
// conditonalized verification of fields added 01/25/2008
// rookie conditional questions & supporting functionality added 02/13/2008
// completely rewritten & converted to getElementById("") method 02/13/2008
// modal box version - Cause_group switched to dropdown - 02/28/2008

// declare Global auction variable

var auction=0;

function verify(returl) {

var themessage = "You are required to complete the following fields:\n";
var month=document.getElementById("month").value;
var year=document.getElementById("year").value; //getElementById("")
var date=month + "/01/"  + year;
var SFdate=0;
var haveRunLoop=0;
var uRunLoop=0;
var causeLoop=0;

if (document.getElementById("first_name").value=="") {
themessage = themessage + " - First Name\n";
}
if (document.getElementById("last_name").value=="") {
themessage = themessage + " - Last Name\n";
}
if (document.getElementById("company").value=="") {
themessage = themessage + " - Organization\n";
}
if (document.getElementById("email").value=="") {
themessage = themessage + " - Email\n";
}
if (document.getElementById("phone").value=="") {
themessage = themessage + " - Phone\n";
}
if (document.getElementById("hear").value=="") {
themessage = themessage + " - How did you hear about us?\n";
}
if (document.getElementById("time").value=="Time") {
themessage = themessage + " - Time\n";
}
if (document.getElementById("state").value=="") {
themessage = themessage + " - State\n";
}
if (document.getElementById("cause_group").value=="cause") {
themessage = themessage + " - Cause group?\n";
}
if (document.getElementById("interest").value=="Interest") {
themessage = themessage + " - Interest?\n";
}

//validation for HAVE RUN radio buttons requires a loop thru the array - this makes it a required field

for (var i=1; document.getElementById('auction'+i); i++) {
     if (document.getElementById('auction'+i).checked) 
        {haveRunLoop = i; break;}
}

if (haveRunLoop==0) {
     themessage = themessage + " - Has your Org run auctions before?\n";
}

//validation for CAUSE GROUP radio buttons requires a loop thru the array - this makes it a required field // 

//for (var j=1; document.getElementById('cause'+j); j++) {
//     if (document.getElementById('cause'+j).checked) 
//	 	{causeLoop = j; break;}
//}

//if (causeLoop==0) {
//     themessage = themessage + " - Cause group?\n";
//}

//conditional validation if YES is selected for 'Have you run an auction" question
//the auctionYes function sets the value of the Global auction variable

if (auction=="Yes") {
	if (document.getElementById("amt_raised").value=="n_a") {
	themessage = themessage + " - Amount Raised?\n";
	}
	if (document.getElementById("month").value=="Month") {
	themessage = themessage + " - Month?\n";
	}
	if (document.getElementById("year").value=="Year") {
	themessage = themessage + " - Year?\n";
	}
	if (document.getElementById("cc_processor").value=="n_a") {
	themessage = themessage + " - Credit Card Processor?\n";
	}
}

//conditional validation if NO is selected for 'Have you run an auction" question
//the auctionNo function sets the value of the Global auction variable

if (auction=="No") { 
//  Radio button version below - needs to be rewritten for getElementById("") method
// ---------------------------------------------

//	for (var i=0; i<document.leadform.elements['00N700000026tmi'].length; i++) {
//     	if (document.leadform.elements['00N700000026tmi'][i].checked == true) {
//       		uRunLoop++;
//        	break;
//    	}
//	}
//	if (uRunLoop==0) {
// 	    themessage = themessage + " - Have YOU run auctions before?\n";
//	}
// ---------------------------------------------
	if (document.getElementById("uauction").value=="n_a") {
		themessage = themessage + " - Have YOU run auctions before?\n";
	}
	if (document.getElementById("email_list").value=="n_a") {
		themessage = themessage + " - Email list?\n";
	}
}

//this places the value of the 'date' variable into the appropriate field to be sent to salesforce (date=month + "/01/"  + year;)
// the value of 'date' is then passed to Ringlead via a hidden input

if (date=='Month/01/Year') {
	SFdate=null;
	}
else {
	SFdate=date;
	}

document.getElementById("form_date").value=SFdate;

//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields:\n") {
// CREATE COOKIE FIRST
LC_createCookie('cmLearningCenter', 'LC_download_OK', '182');
// SET RETURN URL VALUE
document.getElementById("retURL").value = returl + "?id=" + document.getElementById("first_name").value + "_" + document.getElementById("last_name").value;
//DEBUG only alert
//alert ("cookie creation succeeded. sending form to Ringlead."); 
// SUBMIT THE FORM
document.getElementById("leadform").submit();
}
else {
	alert (themessage);
	return false;
   }
}

//show/hide and variable functions

    function showPath(id) {
        document.getElementById(id).style.display='block';
    }
	
    function hidePath(id) {
       document.getElementById(id).style.display='none';
    }
	
	function auctionYes() {
		auction="Yes";
	}
	
	function auctionNo() {
		auction="No";
	}

// select reset functions

function auctionYesReset() {
		document.getElementById("uauction").options.selectedIndex=0;
  		document.getElementById("email_list").options.selectedIndex=0;
}

function auctionNoReset() {
	 	document.getElementById("amt_raised").options.selectedIndex=0;
		document.getElementById("month").options.selectedIndex=0;
		document.getElementById("year").options.selectedIndex=0;
}
