 
var pos_x = 0;
var pos_y = 0;	
$(document).ready(function(){
	
	$('h4.clickme').click(function() {
	  $('div.slidedown').slideToggle('slow', function() {
		// Animation complete.
	  });
	});
	
	$('h4.clickme2').click(function() {
	  $('div.slidedown2').slideToggle('slow', function() {
		// Animation complete.
	  });
	});
	
	$('h4.clickme3').click(function() {
	  $('div.slidedown3').slideToggle('slow', function() {
		// Animation complete.
	  });
	});
  

	  // tipsy=
	$('img.tip').tipsy({gravity: 's'});
	
	$('.here').click(function(e){
		pos_x = e.pageX;
		pos_y = e.pageY;
	});
	$('a[rel*=facebox]').facebox(); 
	
	$('.forgotPW').click(function(){
		ColdFusion.Window.show('forgotPWWindow');
		return false;
	});		
	
	$('.forgotUsername').click(function(){
		ColdFusion.Window.show('forgotUsernameWindow');
		return false;
	});
	
	$('.forgotContributorPW').click(function(){
		ColdFusion.Window.show('forgotContributorPWWindow');
		return false;
	});		
	
	$('.forgotContributorUsername').click(function(){
		ColdFusion.Window.show('forgotContributorUsernameWindow');
		return false;
	});
	
	$('#genInfoAreYouThePatient').change(function(){
		if($(this).val()=='0'){
			$('#notPatientDetails').show();
			$('#patientEmailRequired').hide();	
			$('#patientEmailRequiredConfirm').hide();
			$('#patientAddressRequired').hide();	
			$('#patientCityRequired').hide();				
			$('#patientZipRequired').hide();	
			$('#patientPhoneRequired').hide();	
			$('#patientPhoneTypeRequired').hide();			
		}else{
			$('#notPatientDetails').hide();
			$('#patientEmailRequired').show();
			$('#patientEmailRequiredConfirm').show();
			$('#patientAddressRequired').show();
			$('#patientCityRequired').show();				
			$('#patientZipRequired').show();
			$('#patientPhoneRequired').show();	
			$('#patientPhoneTypeRequired').show();				
		}		
	});
	
	$('#genInfoTransplantPatient').change(function(){
		if($(this).val()=='1'){
			$('#transplantPatientDetails').show();
		}else{
			$('#transplantPatientDetails').hide();
		}		
	});
	
	$('#genInfoCatastrophicInjury').change(function(){
		if($(this).val()=='1'){
			$('#catastrophicInjuryDetails').show();
		}else{
			$('#catastrophicInjuryDetails').hide();
		}		
	});
	
	$('#wasPatientTransplantedGen').change(function(){
		if($(this).val()=='1'){
			$('#transplantDateDetailsGen').show();
		}else{
			$('#transplantDateDetailsGen').hide();
		}		
	});	
	
	$('#patientRelation').change(function(){
		if($(this).val()=='Other'){
			$('#patientRelationOther').show();
		}else{
			$('#patientRelationOther').hide();
		}					
		
		if($(this).val()=='Friend' || $(this).val()=='Other Relative' || $(this).val()=='Neighbor' || $(this).val()=='Other' ){
			$('#isNotFamily').show();
		}else{
			$('#isNotFamily').hide();
		}	
			
	});
	
	$('#spouseRelation').change(function(){
		if($(this).val()=='Other'){
			$('#spouseRelationOther').show();
		}else{
			$('#spouseRelationOther').hide();
		}		
	});	
	
	$('#howDidYouHear').change(function(){
		if($(this).val()=='Other'){
			$('#howDidYouHearOther').show();
		}else{
			$('#howDidYouHearOther').hide();
		}		
	});	
	
	$('#race').change(function(){
		if($(this).val()=='Other'){
			$('#raceOther').show();
		}else{
			$('#raceOther').hide();
		}		
	});	
	
	$('#contactRelation').change(function(){
		if($(this).val()=='Other'){
			$('#contactRelationOther').show();
		}else{
			$('#contactRelationOther').hide();
		}		
	});	
	
	$('#knownNeighborhood').change(function(){
		if($(this).val()=='Yes'){
			$('#knownNeighborhoodParty').show();
		}else{
			$('#knownNeighborhoodParty').hide();
		}		
	});	
	
	$('#socialClub').change(function(){
		if($(this).val()=='Yes'){
			$('#socialClubType').show();
		}else{
			$('#socialClubType').hide();
		}		
	});	
	
	$('#childrenInSchool').change(function(){
		if($(this).val()=='Yes'){
			$('#childrenInSchoolInvolved').show();
		}else{
			$('#childrenInSchoolInvolved').hide();
		}		
	});		
	
	$('#currentlyEmployed').change(function(){
		if($(this).val()=='1'){
			$('#currentlyEmployedYes').show();
			$('#currentlyEmployedNo').hide();
		}else if($(this).val()=='0'){
			$('#currentlyEmployedYes').hide();
			$('#currentlyEmployedNo').show();
		}		
	});		
	
	$('#hasMedicare').change(function(){
		if($(this).val()=='1'){
			$('#medicareDates').show();
		}else{
			$('#medicareDates').hide();
		}		
	});	
	
	$('#hasMedicaid').change(function(){
		if($(this).val()=='1'){
			$('#medicaidInfo').show();
		}else{
			$('#medicaidInfo').hide();
		}		
	});	
	
	$('#hasPrivateInsurance').change(function(){
		if($(this).val()=='1'){
			$('#privateInsuranceInfo').show();
		}else{
			$('#privateInsuranceInfo').hide();
		}		
	});	
	
	$('#hasCobraInsurance').change(function(){
		if($(this).val()=='1'){
			$('#cobraInsuranceInfo').show();
		}else{
			$('#cobraInsuranceInfo').hide();
		}		
	});	
	
	$('#toldSetMount').change(function(){
		if($(this).val()=='Yes'){
			$('#transplantDisplayAmount').show();
		}else{
			$('#transplantDisplayAmount').hide();
		}		
	});	
	
	$('#wasPatientTransplanted').change(function(){
		if($(this).val()=='1'){
			$('#transplantDateDetails').show();
		}else{
			$('#transplantDateDetails').hide();
		}		
	});	
	
	$('#professionalInstitution').change(function(){
		if($(this).val()=='Other'){
			$('#professionalInstitutionOther').show();
		}else{
			$('#professionalInstitutionOther').hide();
		}		
	});	
	
	$('#professionalInstitutionState').change(function(){
		if($(this).val()=='Other'){
			$('#professionalInstitutionStateOther').show();
		}else{
			$('#professionalInstitutionStateOther').hide();
		}		
	});		
	
	$('#selectDiagnosis').change(function(){
		if($(this).val()=='Other'){
			$('#otherDiagnosisDetails').show();
		}else{
			$('#otherDiagnosisDetails').hide();
		}		
	});	
	
	$('#patientOnWaitingList').change(function(){
		if($(this).val()=='1'){
			$('#waitingListDate').show();
		}else{
			$('#waitingListDate').hide();
		}		
	});	
	
	$('#patientTransplanted').change(function(){
		if($(this).val()=='1'){
			$('#transplantDateDetails').show();
		}else{
			$('#transplantDateDetails').hide();
		}		
	});	
	
	$('#donorIdentified').change(function(){
		if($(this).val()=='1'){
			$('#donorRelationship').show();
		}else{
			$('#donorRelationship').hide();
		}		
	});	
	
	$('#patientInstitution').change(function(){
		if($(this).val()=='1'){
			$('#otherPatientHospital').show();
		}else{
			$('#otherPatientHospital').hide();
		}		
	});	
	
	$('#patientTransInstitution').change(function(){
		if($(this).val()=='Other'){
			$('#otherPatientHospital').show();
		}else{
			$('#otherPatientHospital').hide();
		}		
	});		
	
	$('#equipNeeded').change(function(){
		if($(this).val()=='1'){
			$('#equipmentNeededDetails').show();
		}else{
			$('#equipmentNeededDetails').hide();
		}		
	});	
	
	contributeForm.init();
	patientUI.init();

	/*
$('.contentRight').append($('.ad234x60'));
	$('.contentLeft .ad234x60').remove();
	$('.ad234x60').css('margin-left', '-240px');
	if ($('.adminContent').height() < $('.contentLeft').height()) {
		var admargin = 388 - $('.adminContent').height();
		if (admargin > 0) {
			$('.ad234x60').css('margin-top', admargin);
		}
	}
*/

//JUSTIN - THIS IS WHAT WAS CAUSING THE LINKS NOT TO WORK ON THOSE PAGES, BUT ALLOWS FOR THE SUBNAV TO WORK IN IE7.
//THIS IS WHERE I GOT THIS... http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/comment-page-1/
$(function() {
if ($.browser.msie) {
	var zIndexNumber = 1000;
	$('div').each(function(){
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 1;
	});
}
});
	
	function addMega(){ 
	  $(this).addClass("hovering"); 
	  $(this).children("a").addClass("selected"); 
	}
	 
	function removeMega(){ 
	  $(this).removeClass("hovering"); 
	  $(this).children("a").removeClass("selected");
	 } 

	var megaConfig = {     
	     interval: 500, 
     	 sensitivity: 4, 
		 over: addMega, 
		 timeout: 500, 
		 out: removeMega 
	};

	$("li.mega").hoverIntent(megaConfig);

	var default_values = new Array();
	$("* .default").focus(function() {
		if (!default_values[this.id]) {
				default_values[this.id] = this.value;
		 }
		if (this.value == default_values[this.id]) {
			this.value = '';			
		}
		$(this).blur(function() {
			if (this.value == '') {				        
				    this.value = default_values[this.id];
		    }
		});
	});

});
	
var contributeForm = {};
var patientUI = {};

patientUI.init = function(){
	var fields = ['detail_field','url_field','document_field'];
	for(i=0; i<fields.length; i++){
		$('#'+fields[i]).hide();
	}
	$('.fieldControl').change(function(){
		for(i=0; i<fields.length; i++){
			$('#'+fields[i]).hide();
		}		
    	$('#'+fields[$(this).val()]).show();
	});
}

contributeForm.init = function(){
	this.initHeaders();
	this.recurrance();	
	//this.recurrance2();
	this.contribute();
	this.honor();
}

contributeForm.initHeaders = function(){
	$('h4.toggleheader').wrap('<div class=\"toggle\">');
	$('.toggle:last').css('margin-top','50px');
	
	$('.toggle').mouseover(function(){
		$(this).addClass('hover');
	})
	$('.toggle').mouseout(function(){
		$(this).removeClass('hover');
	})	
	$('.toggle').click(function(){
		$(this).removeClass('hover');
		$(this).toggleClass('selected')
		$(this).next().toggle();
	})
	$('.toggle:last').addClass('selected')
}

contributeForm.recurrance = function(){
	//$('.recurringFields').hide();
	$('.contribType select').change(function(){
		//alert($(this).val())
		if($(this).val() == 1){
			$('.recurringFields').show();
		}else{
			$('.recurringFields').hide();
		}
	});
}

contributeForm.recurrance2 = function(){
	var radiovalue=$(".contribType2 input:radio:checked").val(); 
	//$('.contribType2 checked').change(function(){
		//alert(radiovalue);
		if(radiovalue == 1){
			$('.recurringFields').show();
		}
		else{
			$('.recurringFields').hide();
		}
	//});
}

contributeForm.contribute = function(){
	//$('.ntafContribForm').hide();
	//$('.patientContribForm').hide();
	
	$('.patientContribForm .find').click(function(){
		var urlString = '/contribute/patient_results.cfm';
		urlString += '?first=' + $('#contribFirstNameValue').val();
		urlString += '&last=' + $('#contribLastNameValue').val();
		urlString += '&type=' + $('#contribTypeValue').val();
		
		//ColdFusion.navigate(urlString,'patientResults');
	})
	//$('.patientContribForm').show();
	//$('.toggle:last').addClass('selected');
}

contributeForm.honor = function(){
	//$('.honorForm').hide();
	//$('.honorForm .mail').hide();
	//$('.honorForm .email').hide();
	
	$('.contribNotify').change(function(){
		if($(this).val() == 1){
			$(this).parent().parent().next().show();
		}else{
			$(this).parent().parent().next().hide();
		}
	});
	
	$('.notification').change(function(){
		if($(this).val() == 1){
			$(this).parent().parent().next().show();
			$(this).parent().parent().next().next().hide();
		}else{
			$(this).parent().parent().next().hide();
			$(this).parent().parent().next().next().show();			
		}		
	});
	
}

function contribChange(obj){
	var tmp = $(obj);
		if($(tmp).val() == 1){
			$('.patientRecurringFields').show();
		}else{
			$('.patientRecurringFields').hide();
		}
}


function photoForm(photoId,galleryId){
		if(photoId != 0){
			var url = '/patients/photo-form.cfm?photo_id='+photoId+'&id=' + galleryId;
			ColdFusion.navigate(url,'pForm');
		}
		if($('#aphotoFormMultiple').attr('display','block')){
			$('#aphotoFormMultiple').slideUp();
		}
		$('#aphotoForm').slideToggle();
		sIFR.replace(rockwell, {
		  selector: '.rockwelltitle',
		  fitExactly:true,
			css: [
			  '.sIFR-root { font-size:16px; color:#0a91e3; font-weight: bold; text-transform: uppercase;}',
			  'a{ font-size:16px; color:#0a91e3; font-weight: bold; text-decoration:none;}',
			  'a:hover{ font-size:16px; color:#BD0016; font-weight: bold; text-decoration:none;}'
			  ],
		  wmode: 'transparent'
		});
		return false; 	
}

function photoFormMultiple(galleryId){
		if($('#aphotoForm').attr('display','block')){
			$('#aphotoForm').slideUp();
		}	
		$('#aphotoFormMultiple').slideToggle();
		sIFR.replace(rockwell, {
		  selector: '.rockwelltitle',
		  fitExactly:true,
			css: [
			  '.sIFR-root { font-size:16px; color:#0a91e3; font-weight: bold; text-transform: uppercase;}',
			  'a{ font-size:16px; color:#0a91e3; font-weight: bold; text-decoration:none;}',
			  'a:hover{ font-size:16px; color:#BD0016; font-weight: bold; text-decoration:none;}'
			  ],
		  wmode: 'transparent'
		});
		return false; 	 	
}

function loadGalleryImage2(id,photoid){
		jQuery.facebox({ajax: '/includes/gallery-images-full.cfm?id='+id+'&photoid='+photoid});
		return false;
  }
  
function loadGallery2(gallery){
	  jQuery.facebox({ajax: '/includes/gallery-images.cfm?id='+gallery});
  }
  
$(document).ready(function() { // FF needs keypress, IE needs keydown
            $('select').keypress(function(event) 
               { return cancelBackspace(event) });
            $('select').keydown(function(event) 
               { return cancelBackspace(event) });
        }); // ready

        function cancelBackspace(event) {
            if (event.keyCode == 8) {
                return false;
            }
        }
