//---------Redirection URLs-----------------------
//Change these to correct URL for the girl
var success = escape("http://www.livebabemmu.com/anna/success.html");
var pin = escape("http://www.livebabemmu.com/anna/pin.html");
var failure = escape("http://www.livebabemmu.com/anna/failure.html");
//-------------------------------------------------

//Stored value of IM Type
var imvalue = document.getElementById("selected-im-type").value;

//Show correct IM input boxes and text
function imSelection() {
	
	var imselect = document.getElementById('im-select-dropdown').value;
	
	//DEBUG
	//alert(imselect);
	
	$('.im-details').fadeOut(function() 
									  
	{ 
	if(imselect == -1) {
		$('.im-select-text').text("");
	}
	if(imselect == 0) {
		$('.im-select-text').text("MSN");
		$('.im-details').fadeIn();
		imvalue = 0;
	}
	if(imselect == 1) {
		$('.im-select-text').text("AIM");
		$('.im-details').fadeIn();
		imvalue = 1;
	}
	if(imselect == 2) {
		$('.im-select-text').text("Yahoo");
		$('.im-details').fadeIn();
		imvalue = 2;
	}
	if(imselect == 3) {
		$('.im-select-text').text("Google Talk");
		$('.im-details').fadeIn();
		imvalue = 3;
	}
									  
	
	});
	
}


function signUp(APaymentType) { 

	var persona = 188;
	var imtype = imvalue;
	var region = 2;
	var address = document.getElementById('msnOne').value;
	//var address2 = document.getElementById('msnTwo').value;
	//var address = address1 + "@" + address2;
	var emailregex = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var number = document.getElementById('txtCli').value;
	var check1 = document.getElementById('chkOver18').checked;
	var check2 = document.getElementById('chkTsCs').checked;
	var CCsource = "Unknown";
	var CCurl = "http://payment.mmuchatengine.co.uk/";
	var CCregion = 8;

	if (APaymentType == "1") {
		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(address == "" || 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 {
			$('#pleaseWait').html("Please wait...we are sending you your PIN");
			$('#pleaseWait').fadeIn();
			$('#step1').block({ message: null });
			$('#step2').block({ message: null });
			signUpURL = signUpURL+"&mmuPersonaID="+persona+"&mmuIMType="+imtype+"&mmuRegion="+region+"&mmuCli="+number+"&mmuImAddress="+address+"&mmuSuccessUrl="+success+"&mmuPinUrl="+pin+"&mmuFailureUrl="+failure;
			window.location.href = signUpURL;
			
			//DEBUG
			//alert(signUpURL);
		}
	} else if (APaymentType == "2") {
		$('#pleaseWait').html("Please wait...we are redirecting you to our secure credit card payment page");
		$('#pleaseWait').fadeIn();
		$('#step1').block({ message: null });
		$('#step2').block({ message: null });
        //Redirect and our work is done.
       var signUpURL = CCurl+"?userIM="+address+"&imType=0&region="+CCregion+"&personaID="+persona+"&source="+CCsource+"&mmuSuccessUrl="+success+"&mmuPinUrl="+pin+"&mmuFailureUrl="+failure;
		window.location.href = signUpURL;
		
		//DEBUG
		//alert(signUpURL);
    }}

function valPin() {

	var address = document.getElementById('txtIm').value;
	var number = document.getElementById('txtCli').value;
	var pinNum = document.getElementById('txtPin').value;
	var pinimtype = document.getElementById('im-type').value;
	var emailregex = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	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');
	}

	if(address == "" || number == "" || /07\d{9}/.test(number) == false || pinNum == "") {
			alert("Please fill in all fields properly. Your mobile number should be in the format: 07534965478. Your PIN should be 4 digits long. ");
		} else {
	$('#pleaseWait').html("Please wait...I am adding you as one of my contacts");
	$('#pleaseWait').fadeIn();
	$('#regForm').block ({message: null});
	pinURL = pinURL+"&mmuCli="+number+"&mmuImAddress="+address+"&mmuIMType="+pinimtype+"&mmuPin="+pinNum+"&mmuSuccessUrl="+success+"&mmuPinUrl="+pin+"&mmuFailureUrl="+failure;
	window.location.href = pinURL;
	
		}
	//DEBUG
	//alert(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];
}

function pinPage() {

	var address = document.getElementById("msnOne").value;
	
	var signUpURL = "pin.html?"+"mmuImAddress="+address+"&mmuIMType="+imvalue;
	
	window.location.href = signUpURL;

}

function stepTwo() {
	var address = document.getElementById("msnOne").value;
	var emailregex = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(address == "") {
	alert('Please fill in your email address');
	document.getElementById("msnOne").value = "";
	document.getElementById("chkOver18").checked = false;
	}else{
	$('#step2').unblock();	
	}
}

function showTerms() {
	$('#terms').fadeIn("slow");	
	//$('#step1').block({ message: null });
	//$('#step2').block({ message: null });
}
function hideTerms() {
	$('#terms').fadeOut("slow");
	//$('#step1').unblock();
	//$('#step2').unblock();
}

$(document).ready(function() {
	$('#step2').block({ message: null });
	
	$('img[title]').qtip({style: {name: 'light'}, position: {corner: {target: 'topMiddle',tooltip: 'bottomMiddle'}}});
	
		$("#btnSMS").mouseover(function() {
            $("#btnSMS").attr('src', 'images/smsBtnOver.png');
        });
        $("#btnSMS").mouseout(function() {
            $("#btnSMS").attr('src', 'images/smsBtn.png');
		});
        $("#btnSendPin").mouseover(function() {
            $("#btnSendPin").attr('src', 'images/sendPinBtnOver.png');
        });
        $("#btnSendPin").mouseout(function() {
            $("#btnSendPin").attr('src', 'images/sendPinBtn.png');
        });
        $("#btnCC").mouseover(function() {
            $("#btnCC").attr('src', 'images/ccBtnOver.png');
        });
        $("#btnCC").mouseout(function() {
            $("#btnCC").attr('src', 'images/ccBtn.png');
        });
		$("#talktomeBtn").mouseover(function() {
            $("#talktomeBtn").attr('src', 'images/talktomeBtnOver.jpg');
        });
        $("#talktomeBtn").mouseout(function() {
            $("#talktomeBtn").attr('src', 'images/talktomeBtn.jpg');
        });
    });