function copyToRelationship() {
	$('birth_first_name1').value = $('birth_first_name').value;
	$('birth_middle_names1').value = $('birth_middle_names').value;
	$('birth_last_name1').value = $('birth_last_name').value;
	$('current_first_name1').value = $('current_first_name').value;
	$('current_middle_names1').value = $('current_middle_names').value;
	$('current_last_name1').value = $('current_last_name').value;
	
	$('birth_date1[month]').value = $('birth_date[month]').value;
	$('birth_date1[day]').value = $('birth_date[day]').value;
	$('birth_date1[year]').value = $('birth_date[year]').value;
}

function hider()
    {
      if (document.getElementById('relationshipdiv').style.visibility != "hidden") {
        document.getElementById('relationshipdiv').style.visibility = "hidden";
      }
      else {
        document.getElementById('relationshipdiv').style.visibility = "visible";
      }

    }

function toggleDisplay(id, showType){
	if(!showType) {
		showType = 'block';
	}
	
	var obj = $(id);
	if( (obj.style.display == 'none') || ( (obj.style.display == '') && (obj.offsetWidth == 0) ) ) {
		obj.style.display = showType;
	} else {
		obj.style.display = 'none';
	}
}
 
 
function toggleBonusDisplay() {

	copyToRelationship();	

	toggleDisplay('birthNameCompatibility');	
	toggleDisplay('birthNameCompatibilityMessage');
	toggleDisplay('currentNameCompatibility');	
	toggleDisplay('currentNameCompatibilityMessage');
	toggleDisplay('birthDateCompatibility');	
	toggleDisplay('birthDateCompatibilityMessage');
	
}

function initialToggle(relStatus) {

	toggleDisplay('birthNameCompatibility');
	toggleDisplay('currentNameCompatibility');
	toggleDisplay('birthDateCompatibility');

	if(relStatus) {
		$('optionalnumerology_compatibility_reading').checked = true;
		toggleBonusDisplay();
	}
	
}

function submitFreebieAstrologySuccess(transport) {
    		
	if(transport.responseJSON) {
    	
    	if(transport.responseJSON.result) {
    		
    		var visitor = transport.responseJSON.visitor;
    		var aweber = transport.responseJSON.aweber;
    		    		
    		// We have success, fill up the custom rows and submit the form 
    		$('custom rowid').value = visitor.id;
    		$('custom coupon').value = visitor.id + '-' + visitor.coupon;
    		
    		$('custom lifepath').value = aweber.lifepath;
    		$('custom expression').value = aweber.expression;
    		$('custom soulurge').value = aweber.soulurge;
    		$('custom monthname').value = aweber.monthname;
    		$('custom ordday').value = aweber.ordday;
    		$('custom sunsign').value = aweber.sunsign;
    		
    		$('meta_required').value += ',custom rowid,custom coupon';
    		
    		$('freebie_astrology').action = 'http://www.aweber.com/scripts/addlead.pl';
    		$('freebie_astrology').submit();
    		
    	} else {
    		
    		// form validation failed
    		var errorMsg = '<h1>Please Correct these Errors</h1><hr /><ul>';
    		
    		var myErrors = transport.responseJSON.errors;
    		
			for(key in myErrors) {
				errorObj = myErrors[key];
				
				for(errorCode in errorObj) {
					var elName = ucwords(key.replace(/_/g, ' '));
					errorMsg += "<li>" + elName + '<br /><span style="color: #888;">' + errorObj[errorCode] + "</span></li>";
				}
				
			}
			
			errorMsg += '</ul><p style="text-align: center;"><a href="javascript:TINY.box.hide()">close</a></p>';

			// Hello word :)
			TINY.box.show(errorMsg,0,0,0,1);

		}
    } else {
    	var content = transport.responseText;
    	content += '<p style="text-align: center;"><a href="javascript:TINY.box.hide()">close</a></p>';
    	
    	TINY.box.show(transport.responseText,0,0,0,1);
    }
}

function submitFreebieAstrologyFailure() {
	alert('Oops, please refresh the page and try again in a few moments.');
}

function submitFreebieAstrology() {
		
	// Copy AWeber Form Variables to Hidden Freebie Form
	$('current_first_name').value = $F('name');
	$('current_last_name').value = $F('custom lastname');
	$('birth_full_name').value = $F('custom birthname');
	$('birth_country').value = $F('custom country');
	$('birth_city').value = $F('custom city');
	$('birth_date[month]').value = $F('custom month');
	$('birth_date[day]').value = $F('custom day');
	$('birth_date[year]').value = $F('custom year');
	$('email').value = $F('from');
	
    //remember to put a word separator between elements of the camelcase action name, per the ZF manual:
    var myAjax = new Ajax.Request(baseUrl + '/freebie/process/freebie/astrology',
    	 {
    		method: 'post', 
    		parameters: $('freebie_astrology').serialize(true),
    		onSuccess: submitFreebieAstrologySuccess,
    		onFailure: submitFreebieAstrologyFailure
    	});
   
    return false;
}

function submitFreebieNatalChartSuccess(transport) {
	
	if(transport.responseJSON) {
    	
    	if(transport.responseJSON.result) {
    		
    		var visitor = transport.responseJSON.visitor;
    		var aweber = transport.responseJSON.aweber;
    		    		
    		// We have success, fill up the custom rows and submit the form 
    		$('custom rowid').value = visitor.id;
    		$('custom coupon').value = visitor.id + '-' + visitor.coupon;
    		
    		$('custom lifepath').value = aweber.lifepath;
    		$('custom expression').value = aweber.expression;
    		$('custom soulurge').value = aweber.soulurge;
    		$('custom monthname').value = aweber.monthname;
    		$('custom ordday').value = aweber.ordday;
    		$('custom sunsign').value = aweber.sunsign;
    		
    		$('meta_required').value += ',custom rowid,custom coupon';
    		
    		$('freebie_natal_chart').action = 'http://www.aweber.com/scripts/addlead.pl';
    		$('freebie_natal_chart').submit();
    		
    	} else {
    		
    		// form validation failed
    		var errorMsg = '<h1>Please Correct the following errors</h1><hr /><ul>';
    		
    		var myErrors = transport.responseJSON.errors;
    		
			for(key in myErrors) {
				errorObj = myErrors[key];
				
				for(errorCode in errorObj) {
					var elName = ucwords(key.replace(/_/g, ' '));
					errorMsg += "<li>" + elName + '<br /><span style="color: #888;">' + errorObj[errorCode] + "</span></li>";
				}
				
			}
			
			errorMsg += '<p style="text-align: center;"><a href="javascript:TINY.box.hide()">close</a></p>';

			// Hello word :)
			TINY.box.show(errorMsg,0,0,0,1);

		}
    } else {
    	var content = transport.responseText;
    	content += '<p style="text-align: center;"><a href="javascript:TINY.box.hide()">close</a></p>';
    	
    	TINY.box.show(transport.responseText,0,0,0,1);
    }
}

function submitFreebieNatalChartFailure() {
	alert('Oops, please refresh the page and try again in a few moments.');
}

function submitFreebieNatalChart() {
		
	// Copy AWeber Form Variables to Hidden Freebie Form
	$('current_first_name').value = $F('name');
	$('email').value = $F('from');
	
	
    //remember to put a word separator between elements of the camelcase action name, per the ZF manual:
    var myAjax = new Ajax.Request(baseUrl + '/freebie/process/natal-chart',
    	 {
    		method: 'post', 
    		parameters: $('freebie_natal_chart').serialize(true),
    		onSuccess: submitFreebieNatalChartSuccess,
    		onFailure: submitFreebieNatalChartFailure
    	});
   
    return false;
}

function submitFreebieNatalChartSampleSuccess(transport) {
	
	if(transport.responseJSON) {
    	
    	if(transport.responseJSON.result) {
    		$('freebie_natal_chart_sample').submit();
    		
    	} else {
    		
    		// form validation failed
    		var errorMsg = '<h1>Please Correct the following errors</h1><hr /><ul>';
    		
    		var myErrors = transport.responseJSON.errors;
    		
			for(key in myErrors) {
				errorObj = myErrors[key];
				
				for(errorCode in errorObj) {
					var elName = ucwords(key.replace(/_/g, ' '));
					if(key == 'acs_location_id')
						elName = "City of Birth";
					errorMsg += "<li>" + elName + '<br /><span style="color: #888;">' + errorObj[errorCode] + "</span></li>";
				}
				
			}
			
			errorMsg += '<p style="text-align: center;"><a href="javascript:TINY.box.hide()">close</a></p>';

			// Hello word :)
			TINY.box.show(errorMsg,0,0,0,1);

		}
    } else {
    	var content = transport.responseText;
    	content += '<p style="text-align: center;"><a href="javascript:TINY.box.hide()">close</a></p>';
    	
    	TINY.box.show(transport.responseText,0,0,0,1);
    }
}

function submitFreebieNatalChartSampleFailure() {
	alert('Oops, please refresh the page and try again in a few moments.');
}

function submitFreebieNatalChartSample() {
	
    var myAjax = new Ajax.Request(baseUrl + '/freebie/sample-process/natal-chart',
    	 {
    		method: 'post', 
    		parameters: $('freebie_natal_chart_sample').serialize(true),
    		onSuccess: submitFreebieNatalChartSampleSuccess,
    		onFailure: submitFreebieNatalChartSampleFailure
    	});

    return false;
}

function MM_preloadImages() {}

function ucwords( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Waldo Malqui Silva
    // +   bugfixed by: Onno Marsman
    // *     example 1: ucwords('kevin van zonneveld');
    // *     returns 1: 'Kevin Van Zonneveld'
    // *     example 2: ucwords('HELLO WORLD');
    // *     returns 2: 'HELLO WORLD'
 
    return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase( ); } );
}


