/* member functions */


function cropImage(){
	// alert("cropImage");
	if (document.getElementById('w').value != 0) {
	} else {
		alert("Please select a crop region then press 'Crop Image'.");
		return false;
	}
	var oOptions = {
		method: "POST",
		parameters: Form.serialize("crop_form"),
		asynchronous: true,
		onFailure: function (oXHR) {
			$('crop_feedback').update(oXHR.statusText);
		},
		onLoading: function (oXHR) {
			$('crop_feedback').update('Sending data ... <img align="middle" src="images/layout/loading.gif" title="Loading..." alt="Loading..." border="0" />');
		},							
		onSuccess: function(oXHR) {
			$('crop_feedback').update(oXHR.responseText);
		}				
	};		
	var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "member/member_functions_imagecrop.php", oOptions);
}


function submit_register_form(){
	var alerttext = "";

	// firstname
	var zeichen="/ ;:,<>";
	eingabe = document.getElementById("firstname_id").value;
	if (eingabe == ""){      
		alerttext += "\nFirstname missing."; 
    }
	laenge = eingabe.length;
	for(i=0; i<laenge; i++) {
	  	badchar = eingabe.charAt(i);
	  	if (zeichen.indexOf(badchar)>-1) {
			alerttext += "\nFirstname contains bad characters.";
		}
	}
	
	
	// email
	var zeichen="/ ;:,δόφ<>";
	eingabe = document.getElementById("email_id").value;
	if (eingabe == "" || eingabe == 'email'){      
		alerttext += "\nEmail missing."; 
    }
	laenge = eingabe.length;
	for(i=0; i<laenge; i++) {
	  	badchar = eingabe.charAt(i);
	  	if (zeichen.indexOf(badchar)>-1) {
			alerttext += "\nEmail contains bad characters.";
		}
	}   		
    var PosEt = document.getElementById("email_id").value.indexOf("@");
    var PosPt = document.getElementById("email_id").value.indexOf(".", PosEt);
    if ((document.getElementById("email_id").value == '') || (PosPt == -1) || (PosPt - PosEt < 2) || (document.getElementById("email_id").value.length - PosPt < 3) || (PosEt == -1) || (PosEt == 0) || (document.getElementById("email_id").value.indexOf("@", PosEt + 1) > PosEt)) {
		alerttext += "\nEmail is not valid.";	
	}
	if ((document.getElementById("email_id2").value == '') || (document.getElementById("email_id2").value != document.getElementById("email_id").value)) {
		alerttext += "\nConfirm your email.";	
	}
	
	
	var zeichen="/;:,<>";


	// password_id   
    if (document.getElementById("password_id").value == "" || document.getElementById("password_id").value == 'password'){      
		alerttext += "\nPassword missing."; 
    }
	eingabe = document.getElementById("password_id").value;
	laenge = eingabe.length;
	for (i=0; i<laenge; i++) {
	  	badchar = eingabe.charAt(i);
	  	if (zeichen.indexOf(badchar)>-1) {
			alerttext += "\nPassword contains bad characters.";
		}
	}
	if (laenge < 6 || laenge > 16) {
		alerttext += "\nPassword must be between 6 and 16 characters long.";
	}


	// lkz_id  
    if (document.getElementById("lkz_id").value == ""){      
		alerttext += "\nCountry missing."; 
    }


	// final check
	if (alerttext != "") {
		alerttext = "Error, please check:\n" + alerttext;
		alert(alerttext);
		return false;
	} else {
		// alerttext = "No errors :)";
		// alert(alerttext);
		document.forms.register_form.submit_name.disabled = true;			
		document.forms.register_form.submit_name.value = 'PLEASE WAIT ...';
		return true;
	}
}


/* backstage functions */


function submit_password_form(){
	var alerttext = "";


	// email
	var zeichen="/ ;:,δόφ<>";
	eingabe = document.getElementById("email_id").value;
	if (eingabe == "" || eingabe == 'email'){      
		alerttext += "\Email missing."; 
    }
	laenge = eingabe.length;
	for(i=0; i<laenge; i++) {
	  	badchar = eingabe.charAt(i);
	  	if (zeichen.indexOf(badchar)>-1) {
			alerttext += "\nEmail contains bad characters.";
		}
	}   		
    var PosEt = document.getElementById("email_id").value.indexOf("@");
    var PosPt = document.getElementById("email_id").value.indexOf(".", PosEt);
    if ((document.getElementById("email_id").value == '') || (PosPt == -1) || (PosPt - PosEt < 2) || (document.getElementById("email_id").value.length - PosPt < 3) || (PosEt == -1) || (PosEt == 0) || (document.getElementById("email_id").value.indexOf("@", PosEt + 1) > PosEt)) {
		alerttext += "\nEmail is not valid.";	
	}


	// final check
	if (alerttext != "") {
		alerttext = "Error, please check:\n" + alerttext;
		alert(alerttext);
		return false;
	} else {
		// alerttext = "No errors :)";
		// alert(alerttext);
		document.forms.password_form.submit_name.disabled = true;			
		document.forms.password_form.submit_name.value = 'PLEASE WAIT ...';
		return true;
	}
}


function updateBirthdayBS() {
	var dayValue = document.getElementById("birthday_day_id").value;
	var monthValue = document.getElementById("birthday_month_id").value;
	var yearValue = document.getElementById("birthday_year_id").value;
	document.getElementById("birthday_id").value = dayValue + "." + monthValue + "." + yearValue;
}


function submit_profile_form(){
	var alerttext = "";

	// firstname
	var zeichen="/ ;:,<>";
	eingabe = document.getElementById("firstname_id").value;
	if (eingabe == ""){      
		alerttext += "\nFirstname missing."; 
    }
	laenge = eingabe.length;
	for(i=0; i<laenge; i++) {
	  	badchar = eingabe.charAt(i);
	  	if (zeichen.indexOf(badchar)>-1) {
			alerttext += "\nFirstname contains bad characters.";
		}
	}
	
	// email
	var zeichen="/ ;:,δόφ<>";
	eingabe = document.getElementById("email_id").value;
	if (eingabe == "" || eingabe == 'email'){      
		alerttext += "\nEmail missing."; 
    }
	laenge = eingabe.length;
	for(i=0; i<laenge; i++) {
	  	badchar = eingabe.charAt(i);
	  	if (zeichen.indexOf(badchar)>-1) {
			alerttext += "\nEmail contains bad characters.";
		}
	}   		
    var PosEt = document.getElementById("email_id").value.indexOf("@");
    var PosPt = document.getElementById("email_id").value.indexOf(".", PosEt);
    if ((document.getElementById("email_id").value == '') || (PosPt == -1) || (PosPt - PosEt < 2) || (document.getElementById("email_id").value.length - PosPt < 3) || (PosEt == -1) || (PosEt == 0) || (document.getElementById("email_id").value.indexOf("@", PosEt + 1) > PosEt)) {
		alerttext += "\nEmail is not valid.";	
	}
		
	var zeichen="/;:,<>";

	// password_id   
    if (document.getElementById("password_id").value == "" || document.getElementById("password_id").value == 'password'){      
		alerttext += "\nPassword missing."; 
    }
	eingabe = document.getElementById("password_id").value;
	laenge = eingabe.length;
	for (i=0; i<laenge; i++) {
	  	badchar = eingabe.charAt(i);
	  	if (zeichen.indexOf(badchar)>-1) {
			alerttext += "\nPassword contains bad characters.";
		}
	}
	if (laenge < 6 || laenge > 16) {
		alerttext += "\nPassword must be between 6 and 16 characters long.";
	}
	
	// birthday_id
	/*
	eingabe = document.getElementById("birthday_id").value;
	laenge = eingabe.length;
    if (laenge > 0 && laenge < 10){    
		alerttext += "\nDate of Birth incorrect."; 
    }
	*/

	// lkz_id
    if (document.getElementById("lkz_id").value == ""){      
		alerttext += "\nCountry missing."; 
    }

	// final check
	if (alerttext != "") {
		alerttext = "Error, please check:\n" + alerttext;
		alert(alerttext);
		return false;
	} else {
		// alerttext = "No errors :)";
		// alert(alerttext);
		document.forms.profile_form.submit_name.disabled = true;			
		document.forms.profile_form.submit_name.value = 'PLEASE WAIT ...';
		return true;
	}
}


function updateUploadForm(form_id) {
	var gallery_title = document.getElementById(form_id).gallery_id[document.getElementById(form_id).gallery_id.selectedIndex].title;
	if (gallery_title == "live" || gallery_title == "bandandme") {
		document.getElementById('type_holder').style.display = "block";
	} else {
		document.getElementById('type_holder').style.display = "none";
	}
	document.getElementById(form_id).type.value = ""; // pulldown nullen
}
	

function uploadImage(form_id,messages,feedback_id){
	
	// desc nicht = "" und nicht zu lang, gallery-id, subgallery (type falls live-event)
	var gallery = document.getElementById(form_id).gallery_id;
	if (gallery.value.length == 0 || gallery.value == null) {
		alert("Please select to which gallery you want to upload your picture!");
		gallery.disabled=false;
		gallery.focus();
		return false; 
	}	
	
	var gallery_title = document.getElementById(form_id).gallery_id[document.getElementById(form_id).gallery_id.selectedIndex].title;
	if (gallery_title == "live" || gallery_title == "bandandme") {
		var type = document.getElementById(form_id).type;
		if (type.value.length == 0 || type.value == null) {
			alert("Please select to which Event/Concert-gallery you want to upload your picture!\n\nIf you don't know select 'Other'.");
			type.disabled=false;
			type.focus();
			return false; 
		}		
	}
	
	var comment = document.getElementById(form_id).text;
	if (comment.value.length == 0 || comment.value == null) {
		alert(messages["empty"]);
		comment.disabled=false;
		comment.focus();
		return false; 
	}
	if (comment.value.length > 255) {
		alert(messages["toolong"]);
		comment.disabled=false;
		comment.focus();
		return false;
	}
	
	document.getElementById(form_id).upload_submit.disabled = true;
	document.getElementById(form_id).upload_submit.value = 'PLEASE WAIT ...';
	document.getElementById(feedback_id).innerHTML = 'Sending data ... <img style="display:inline;" align="middle" src="images/layout/loading.gif" alt="Loading..." border="0" />';
	
	return true;
}


function getUploadFeedback(feedback_iframe_id,feedback_id) {	
	var i = document.getElementById(feedback_iframe_id);
	if (i.contentDocument) {
		var d = i.contentDocument;
	} else if (i.contentWindow) {
		var d = i.contentWindow.document;
	} else {
		var d = window.frames[id].document;
	}
	if (d.location.href == "about:blank") {
		return;
	} else {
		document.getElementById(feedback_id).innerHTML = d.body.innerHTML;
		if (d.body.innerHTML.indexOf("Error") == -1) {
			BUEffect('upload_form_div');
		}
	}
}
	
	
	
	
