﻿function XmlHttpRequestManager(url)
{
	this.progressControlId;
	this.progressDisableElementId;
	this.onCompletedHandler;
	this.onFailedHandler;
	this.datacontext;
	this.method = "GET";
	this.url = url;
	
	
	this.Send = function(){
		if(this.progressControlId != null)
			$get(this.progressControlId).style.display = '';
			
		ProceedRequestAsync(this.url, this.RequestCompleted, this.onFailedHandler, this);
	}
	
	this.RequestCompleted = function(sender, response)
	{
		if(sender.progressControlId != null)
			$get(sender.progressControlId).style.display = 'none';
		sender.onCompletedHandler(sender, response);
	}
	
	this.RequestFailed = function(sender, response)
	{
		if(sender.onFailedHandler != null)
		{
			sender.onFailedHandler(sender, response);
		}
	}
	
}

function $get(id)
{
	return document.getElementById(id);
}

function ProceedRequestAsync(page, onCompleteHandler, onFailedHandler, sender)
{
	var r = GetRequest();
	
	r.open("GET", page);
	
	r.onreadystatechange = function (){
		if(this.readyState == 4)
		{
			
			if(this.status == 200)
			{
				onCompleteHandler(sender, this.responseText);
			}else
			{
				onFailedHandler(sender, "Der gewünschte Prozess konnte nicht ausgeführt werden (Fehler: " + this.status + ")");
			}
		}
	};	
	r.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	r.setRequestHeader("Content-type","charset=utf-8")
	r.send(null);
	
}

function GetRequest(){
	var req = null;
	try{
		req = new XMLHttpRequest();
	}
	catch (ms){
		try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (nonms){
			try{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (failed){
				req = null;
			}
		}  
	}
	return req;
}

function IsValidEmail(email)
{
	var isValid = true;

	var array = email.split("@");
	if(array.length != 2)
	{
		isValid = false;
	}else if(array[1].split(".").length < 2){	
		isValid = false;
	}
	
	return isValid;
}

