/*-----------------------------------------------------*/
/*                                                     */
/* reduce the maxlength to 5 charcters,                */
/* if the user lives in germany                        */
/*                                                     */
/*-----------------------------------------------------*/

function set_maxlength(type) {
	max = document.createAttribute("maxlength");
	max.nodeValue = "5";
	document.getElementById("postcode").setAttributeNode(max);
	if(type == "change") {
		max_new = document.createAttribute("maxlength");
		max_new.nodeValue = "5";
		document.getElementById("new_postcode").setAttributeNode(max_new);
	}
}

function change_maxlength(postcode_id,country_id) {
	max = document.createAttribute("maxlength");
	max_new = document.createAttribute("maxlength");
	status = document.getElementById(country_id).value;
	if(postcode_id == "postcode") {
		if (status != "DEU") {
			max.nodeValue = "";
		} else {
			document.getElementById(postcode_id).value = "";
			max.nodeValue = "5";
		}
		document.getElementById(postcode_id).setAttributeNode(max);
	} else if(postcode_id == "new_postcode") {
		if (status != "DEU") {
			max_new.nodeValue = "";
		} else {
			document.getElementById(postcode_id).value = "";
			max_new.nodeValue = "5";
		}
		document.getElementById(postcode_id).setAttributeNode(max_new);
	}
}

/*-----------------------------------------------------*/
/*                                                     */
/* write some radiobuttons, that change the label and  */
/* value, depending on the fundraising rhythm          */
/*                                                     */
/*-----------------------------------------------------*/

function write_contribution_radiobuttons(value) {
	document.write("<div class=\"amount\">einen Betrag* von<br \/><\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_01\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"5\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_01\" for=\"contribution_01\">5 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_02\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"10\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_02\" for=\"contribution_02\">10 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_03\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"20\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_03\" for=\"contribution_03\">20 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"free_amount\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"0.0\" onclick=\"highlite_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\"" + (value==undefined ? "" : " checked=\"checked\"" ) + " \/>");
	document.write("<label id=\"free_amount_label\" for=\"free_amount\">anderer Betrag<\/label>");
	document.write("<\/div>");
	if (value==undefined) {
		value = "";
	}
	document.write("<div class=\"field\">");
	document.write("<input type=\"text\" id=\"contribution_04\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"" + value + "\" onfocus=\"set_focus_on_free_amount_field();\" onblur=\"release_focus_on_free_amount_field();\" style=\"border-style:solid;border-color:#999;background-color:#eee;\" \/>");
	document.write("<\/div>");
}

// r for reversed
function write_contribution_radiobuttons_r(value) {
	document.write("<div class=\"amount\">einen Betrag* von<br \/><\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_03\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"20\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_03\" for=\"contribution_03\">20 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_02\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"10\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_02\" for=\"contribution_02\">10 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_01\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"5\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_01\" for=\"contribution_01\">5 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"free_amount\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"0.0\" onclick=\"highlite_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\"" + (value==undefined ? "" : " checked=\"checked\"" ) + " \/>");
	document.write("<label id=\"free_amount_label\" for=\"free_amount\">anderer Betrag<\/label>");
	document.write("<\/div>");
	if (value==undefined) {
		value = "";
	}
	document.write("<div class=\"field\">");
	document.write("<input type=\"text\" id=\"contribution_04\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"" + value + "\" onfocus=\"set_focus_on_free_amount_field();\" onblur=\"release_focus_on_free_amount_field();\" style=\"border-style:solid;border-color:#999;background-color:#eee;\" \/>");
	document.write("<\/div>");
}


// e for einmalig, now reversed
function write_contribution_radiobuttons_e(value) {

	document.write("<div class=\"amount\">einen Betrag* von<br \/><\/div>");

	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_03\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"120\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_03\" for=\"contribution_03\">120 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_02\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"80\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_02\" for=\"contribution_02\">80 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"contribution_01\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"50\" onclick=\"clear_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\" \/>");
	document.write("<label id=\"contribution_label_01\" for=\"contribution_01\">50 Euro<\/label>");
	document.write("<\/div>");
	document.write("<div class=\"radio\">");
	document.write("<input type=\"radio\" id=\"free_amount\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"0.0\" onclick=\"highlite_field(\'contribution_04\');\" onkeypress=\"this.onclick\" class=\"radio\"" + (value==undefined ? "" : " checked=\"checked\"" ) + " \/>");
	document.write("<label id=\"free_amount_label\" for=\"free_amount\">anderer Betrag<\/label>");
	document.write("<\/div>");
	if (value==undefined) {
		value = "";
	}
	document.write("<div class=\"field\">");
	document.write("<input type=\"text\" id=\"contribution_04\" name=\"FE[tx_a21gpdforms_donations][contribution]\" value=\"" + value + "\" onfocus=\"set_focus_on_free_amount_field();\" onblur=\"release_focus_on_free_amount_field();\" style=\"border-style:solid;border-color:#999;background-color:#eee;\" \/>");
	document.write("<\/div>");

}


function change_euro_radiobuttons_values() {
	var el = document.getElementById("contributionrythm");
	if (el && el.nodeName.toLowerCase()=='select') {
		var rhythm = el.value;
		switch(rhythm) {
			case "2":
			document.getElementById("contribution_label_01").innerHTML = "5 Euro";
			document.getElementById("contribution_label_02").innerHTML = "10 Euro";
			document.getElementById("contribution_label_03").innerHTML = "20 Euro";
			document.getElementById("contribution_01").value = "5";
			document.getElementById("contribution_02").value = "10";
			document.getElementById("contribution_03").value = "20";
			break;
			case "3":
			document.getElementById("contribution_label_01").innerHTML = "15 Euro";
			document.getElementById("contribution_label_02").innerHTML = "30 Euro";
			document.getElementById("contribution_label_03").innerHTML = "60 Euro";
			document.getElementById("contribution_01").value = "15";
			document.getElementById("contribution_02").value = "30";
			document.getElementById("contribution_03").value = "60";
			break;
			case "4":
			document.getElementById("contribution_label_01").innerHTML = "30 Euro";
			document.getElementById("contribution_label_02").innerHTML = "50 Euro";
			document.getElementById("contribution_label_03").innerHTML = "100 Euro";
			document.getElementById("contribution_01").value = "30";
			document.getElementById("contribution_02").value = "50";
			document.getElementById("contribution_03").value = "100";
			break;
			case "5":
			document.getElementById("contribution_label_01").innerHTML = "50 Euro";
			document.getElementById("contribution_label_02").innerHTML = "80 Euro";
			document.getElementById("contribution_label_03").innerHTML = "120 Euro";
			document.getElementById("contribution_01").value = "50";
			document.getElementById("contribution_02").value = "80";
			document.getElementById("contribution_03").value = "120";
			break;
			default:
			case "1":
			document.getElementById("contribution_label_01").innerHTML = "50 Euro";
			document.getElementById("contribution_label_02").innerHTML = "80 Euro";
			document.getElementById("contribution_label_03").innerHTML = "120 Euro";
			document.getElementById("contribution_01").value = "50";
			document.getElementById("contribution_02").value = "80";
			document.getElementById("contribution_03").value = "120";
			break;
		}
	}
}

function clear_field(field) {
	document.getElementById(field).disabled = "disabled";
	document.getElementById(field).style.borderStyle = "solid";
	document.getElementById(field).style.borderColor = "#999";
	document.getElementById(field).style.backgroundColor = "#eee";
	if (field!='contribution_04') document.getElementById(field).value = "";
}

function highlite_field(field) {
	if (field=='contribution_04') {
		document.getElementById(field).disabled = "";
		document.getElementById(field).style.borderStyle = "inset";
		document.getElementById(field).style.borderColor = "black";
		document.getElementById(field).style.backgroundColor = "#ff944c";
		if (document.getElementById(field).value=='') {
			document.getElementById(field).value = 'Bitte hier Eurobetrag eingeben.';
		}
	}
// 	document.getElementById(field).select();
// 	document.getElementById(field).focus();
}

function set_focus_on_free_amount_field() {
	highlite_field('contribution_04');
	if (document.getElementById('contribution_04').value=='Bitte hier Eurobetrag eingeben.') document.getElementById('contribution_04').value = '';
	document.getElementById("free_amount").checked=true;
}
function release_focus_on_free_amount_field() {
	var field = document.getElementById('contribution_04');
	if (field.value=='') document.getElementById('contribution_04').value = 'Bitte hier Eurobetrag eingeben.';
}

function set_focus_on_confirmationyear() {
	field = 'confirmationyear';
	if (!document.getElementById(field).value) {
		document.getElementById(field).disabled = "";
		document.getElementById(field).style.borderStyle = "inset";
		document.getElementById(field).style.borderColor = "black";
		document.getElementById(field).style.backgroundColor = "#ff944c";
	}
	document.getElementById('confirmation_05').checked=true;
}

function process_confirmationyear(enable) {
	if (enable) {
		document.getElementById("confirmationyear").disabled = "";
		document.getElementById("confirmationyear").style.borderStyle = "inset";
		document.getElementById("confirmationyear").style.borderColor = "black";
		document.getElementById("confirmationyear").style.backgroundColor = "#ff944c";
		document.getElementById("confirmationyear").focus();
	} else {
		clear_field('confirmationyear');
	}
}

function change_incentives() {
	if(document.getElementById("incentive_fieldset")) {
		var status = document.getElementById("contributionrythm").value;
		if (status == 1 && incentives_are_allways_on!=true) {
			document.getElementById("incentive_fieldset").style.display = "none";
		} else {
			document.getElementById("incentive_fieldset").style.display = "block";
		}
		change_euro_radiobuttons_values();
	} else if(document.getElementById("incentive_label")) {
		var status = document.getElementById("contributionrythm").value;
		if (status == 1 && incentives_are_allways_on!=true) {
			document.getElementById("incentive_label").style.color = "#666";
			document.getElementById("incentive_label").innerHTML = "Geschenke stehen nur regelm&auml;&szig;igen F&ouml;rderern zur Verf&uuml;gung.";
			document.getElementById("incentive_label").style.width = "100%";
			document.getElementById("incentive").style.visibility = "hidden";
		} else {
			document.getElementById("incentive_label").style.color = "black";
			document.getElementById("incentive_label").innerHTML = "Geschenkwunsch";
			document.getElementById("incentive_label").style.width = "10em";
			document.getElementById("incentive").style.visibility = "visible";
		}
		change_euro_radiobuttons_values();
	}
}

var incentives_are_allways_on = false;

