var success = escape("http://www.livebabemmu.com/morgan/success.html");
var pin = escape("http://www.livebabemmu.com/morgan/pin.html");
var failure = escape("http://www.livebabemmu.com/morgan/failure.html");

function signUp() {

	var persona = 569;
	var address1 = document.getElementById('msnOne').value;
	var address2 = document.getElementById('msnTwo').value;
	var address = address1 + "@" + address2;
	var number = document.getElementById('txtCli').value;
	var check1 = document.getElementById('chkOver18').checked;
	var check2 = document.getElementById('chkTsCs').checked;

	if (getQueryString('cid') == "") {
	// if there is a cid key in the querystring, add it to the end of the urls
		var signUpURL = "http://mmuchatengine.co.uk/MMUHttpApi/signup.ashx?";
	} else {
		var signUpURL = "http://mmuchatengine.co.uk/MMUHttpApi/signup.ashx?mmuCustomerID=" + getQueryString('cid') + "&";
	}

	if(address1 == "" || address2 == "" || number == "" || /07\d{9}/.test(number) == false || check1 == false || check2 == false) {
		alert("Please fill in all fields properly and check the two boxes. Your mobile number should be in the format: 07534965478. ");
	} else {
		signUpURL = signUpURL + "mmuPersonaID="+persona+"&mmuCli="+number+"&mmuImAddress="+address+"&mmuSuccessUrl="+success+"&mmuPinUrl="+pin+"&mmuFailureUrl="+failure;
		window.location.href = signUpURL;
		//alert(signUpURL);
	}
}

function valPin() {

var address = document.getElementById('txtIm').value;
var number = document.getElementById('txtCli').value;
var pinNum = document.getElementById('txtPin').value;
	
	if (getQueryString('cid') == "") {
	// if there is a cid key in the querystring, add it to the end of the urls
		var pinURL = "http://mmuchatengine.co.uk/MMUHttpApi/pin.ashx?";
	} else {
		var pinURL = "http://mmuchatengine.co.uk/MMUHttpApi/pin.ashx?mmuCustomerID=" + getQueryString('cid') + "&";
	}
	
	pinURL = pinURL+"&mmuCli="+number+"&mmuImAddress="+address+"&mmuPin="+pinNum+"&mmuSuccessUrl="+success+"&mmuPinUrl="+pin+"&mmuFailureUrl="+failure;
	
	window.location.href = pinURL;

}

function getQueryString(key, default_)
{
  if (default_==null) default_="";
  
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  
  if(qs == null)
    return default_;
  else
    return qs[1];
}