/* POPUP */

// Display a popup in a new window
function popup(page, width, height) {
	window.open(page,'popup','width='+width+',height='+height+',left=100,top=100,toolbar=false,scrollbars=1');
}

/* CHECK FORM FUNCTIONS */

// Check userid / email-address
function checkBeforeSend() {

	var user_email = document.getElementById('user_email');
	var email_form = document.getElementById('email_form');

	if( user_email.value != "" ) {
		if( isValidEmail( user_email.value ) ) {		
			// email-address is valid
			//send the confirmtion mail (ex sogehts) sendMail(publisher_id, user_email)
			sendMail(0,userid.value);
			email_form.action = email_form.action.replace( "---CUSTOMIDENT---", user_email.value + "__email=" + user_email.value );
			return true;
		} else {
			// email-address is NOT valid
			alert ('Bitte Email-Adresse eintragen');
			user_email.style.border = "1px solid #990000";
			user_email.select();
			user_email.focus();
			return false;
		}
	} else {
		alert ('Bitte Email-Adresse eintragen');
		user_email.style.border = "1px solid #990000";
		user_email.select();
		user_email.focus();
		return false;
	}
}

// Check if the email is valid
function isValidEmail (email) {
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

// Prepare the request for the so geths email
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
        xmlhttp = false;
        }
      }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp = false;
      }
    }
  return xmlhttp;
}

// Send the so gehts email as soon the user click on the button
function sendMail(publisher_id, email) {
	var http = getHTTPObject();
	var url = 'http://client.eol.de/Export/mailingNetbankConfirmation/'+publisher_id+'/'+email;
	http.open("GET", url, true);
	http.send(null);
}

