// JavaScript Document

$(document).ready(function(){
//Start JQuery Code

	
	//Outside Links
	$("a.target").click(function(){
		window.open($(this).attr("href"));
		return false;
	});	
	
	//Email Window
	$('a.contactlink').click(function() { 
		emailDisplay();
   	});
	
	$('a#closewindow').click(function() {
		emailHide();
		return false;		
   	});		

	
	//Insight Submission - Added 2/25/09	
	$("a#closeinsight").click(function () {
		$("#thankyou").css("display", "none");
		//jn start
		document.getElementById('globalemailsignup').reset();
		//jn end
		return false;
	});		


//add jn
 /*    	$(".webinarclick").click(function(){
		urchinTracker('nonprofitlandingpage/webinar');
		
	});	
	
		$("#rsssubscribeclick").click(function(){
		urchinTracker('nonprofitlandingpage/rsssubscribe');
		
	});	
	*/	
		$("#insightemailsignupclick").click(function(){
		urchinTracker('nonprofitlandingpage/insightemailsignup');
		
	});	

//end jn add


//----------------------------------
//contact form

$("#NPLandingForm").validate({	
     submitHandler: function(form) { 
	//alert('hi');
	// $.showStatusDialog('Contact Us','Please wait while your information is being submitted...');	
	 $("#NPLandingForm").ajaxSubmit( { url:'../icmlanding/processlanding_new.cfm', type: 'post', success: evaluateContactUsResponse } ); 	
	 emailHide();
     document.getElementById('NPLandingForm').reset();

	 return false;
   },	
    rules: { 	  
	  first_name: "required",
	  last_name: "required",
	  company: "required",
	  email: {
		required: true,
		email: true
	  },
	  phone: "required",
	  concerns: {
		maxlength: 500		  
	  }
	  
    },
	messages: {
	  first_name: "First name is required.",
	  last_name: "Last name is required.",  	
	  company: "An organization name is required",
	  email: 'A valid email address is required.',	  
	  phone: 'A telephone number is required.',
	  concerns: 'Concerns text has a maximum length of 500 characters.'	
	}, 
	errorPlacement: function(error, element) {			 
	  error.insertBefore(element);	
	}	
  }); 



//email form

$("#globalemailsignup").validate({	
     submitHandler: function(form) { 
	//alert('hi');
	// $.showStatusDialog('Contact Us','Please wait while your information is being submitted...');	
	 $("#globalemailsignup").ajaxSubmit( { url:'../icmlanding/processlanding.cfm', type: 'post', success: evaluateContactUsResponse } ); 	
		//modify jn start
		//$("#thankyou").css("display", "block");
		//modify jn end
	
 //  	});
	 return false;
   },	
    rules: { 	  
	   signupemail: {
		required: true,
		email: true
	  }
	  
    },
	messages: {
	   	
	  signupemail: 'A valid email address is required.'	  
	  			
	}, 
	errorPlacement: function(error, element) {			 
	  error.insertBefore(element);	
	}	
  }); 
//----------------------------------



	//Footnotes
	$("span.footnotes").hover(
		function(){
			ids = $(this).attr("id");
			$("span." + ids).addClass("shownotes");
		},
		function(){
			ids = $(this).attr("id");
			$("span." + ids).removeClass("shownotes");	
		}
	);	

	//ICM Process Image - Added 3/23/09
	$('a#thumbnail').click(function() {
		$('a#enlarged').addClass("shownotes");
		return false;		
   	});	

	$('a#enlarged').click(function() {
		$('a#enlarged').removeClass("shownotes");
		return false;
   	});		

//End JQuery Code
});

//Contact Form Display
function emailDisplay(){
	$('body').append('<span class="overlay"></span>');
	
   	var cover = 600;
	var cover = $('body').height();
	
	$('span.overlay').css('height', cover + 'px');
	$('div#contact').addClass("showcontact");	
};

//Contact Form Hide
function emailHide() {
	$('div#contact').removeClass("showcontact");
	$('span.overlay').remove();
	$('div.error').remove();
	$('label.error').remove();
};

function evaluateContactUsResponse(str) {
 var response = $.trim(str);
//document.write(response);
if(response.indexOf('Success') != -1) {$("#thankyou").css("display", "block");}


if(response.indexOf('Success') == -1 && response.indexOf('Success2') == -1) {
alert('Your submission failed.  Please contact Justin Bruton at jbruton@merkleinc.com')};

/*var msg = "<h4> + Your submission failed.  Please contact Merkle. + </h4>";	   
   $("div.sideitem#thankyou").innerHTML=msg;
   $("#thankyou").css("display", "block");*/
//window.location="http://cdhnfsite.wms.cdgsolutions.com/wmspage.cfm?parm1=112"; 
}


