function locateObject(obj) {
	var myleft = 0;
	var mytop = 0;
	if (obj.id) {
		if (obj.offsetParent) {
			do {
				myleft += obj.offsetLeft;
				mytop += obj.offsetTop;
//				document.getElementById('sub-main-bottom').innerHTML += obj.id + ' - ';
			} while (obj = obj.offsetParent);
		}
	}
	return new Array(myleft,mytop);
}

function popErrorBox(id,error,withold) { // withold=true stops the balloon appearing

	if (id.length) {
		if (obj = document.getElementById(id)) {
			var pos = locateObject(obj);
			if (error) {
				if (!withold) {
					if (!(errbox = document.getElementById('errbox'))) { // create an errorbox if it doesn't exist
						var errbox = document.createElement('div');
						errbox.setAttribute('id','errbox');
						document.body.appendChild(errbox);
						errbox.onclick = function() { $(this).hide(); } ;
						errbox.style.position = 'absolute';
						errbox.style.width='220px';
						errbox.style.padding = '0px';
						errbox.style.zIndex = '1200';
						errbox.style.cursor = 'pointer';
						errbox.style.display = 'none';
						errbox.innerHTML = '<div style="padding: 10px 5px 10px 35px; background: transparent url(/images/errorbox.' + (MSIE6?'gif':'png') + ') 0% 0% no-repeat;" id="errboxmsg"></div>'
										 + '<div style="height: 10px; background: transparent url(/images/errorbox.' + (MSIE6?'gif':'png') + ') 0% 100% no-repeat;">&nbsp;</div>';
			
					}
					
					document.getElementById('errboxmsg').innerHTML = error;
	
					var left = parseInt(pos[0]) + parseInt(obj.offsetWidth);
					var top  = parseInt(pos[1]) - 10; 
					
					errbox.style.left = left + 'px';
					errbox.style.top = top + 'px';
	
					if (errbox.style.display == 'none') {
						errbox.style.display = 'block';			
					}
				}
		
				if (obj.parentNode.className.substr(0,5) == 'input') {
					f = obj.parentNode.className.split(' ');
					obj.parentNode.className = f[0] + ' ' + f[0] + '-error';
				} else {
					obj.style.border = '1px solid red';
				}
				
			} else {
				if (obj.parentNode.className.substr(0,5) == 'input') {
					f = obj.parentNode.className.split(' ');
					obj.parentNode.className = f[0];
				} else {
					obj.style.borderWidth = '0px';
				}
			}
			
		} else if (errbox = document.getElementById('errbox')) {
			errbox.style.display="none"; // invalid call? Hide error box just in case
		}
	} else if (errbox = document.getElementById('errbox')) {
		errbox.style.display="none"; // invalid call? Hide error box just in case
	}

}

function scanPopErrorBox(fields,errors,highlight) {

	if (!document.getElementById(highlight)) {
			highlight = '';
	}

	if (errbox = document.getElementById('errbox')) {
		errbox.style.display="none"; // zap error box in case the current one has changed to be valid
	}
	var c = fields.length;		
	for (i=0;i<c;i++) {
		if (!highlight && errors[i]) {
			highlight = fields[i];
		}
		withold = (highlight?(fields[i]==highlight?false:true):true);
		popErrorBox(fields[i],errors[i],withold);
	}
}

function processPhoneNum(id) {
	if (e = document.getElementById(id)) {
		e.value = e.value.replace(/[^0-9\.\(\)\+ ]+/g,'');
		return ( e.value.replace(/[^0-9]+/g,'').length < 6 ? true : false );
	} else {
		return false;
	}
}

function EAregFormCheckEB(highlight,submitted,formData)
{
	if ($('#tab_result').length > 0) 
	{
		tab_result = $('#tab_result').val();
		service_result = $('#service').val();
	}
	if ($('#tracking_registration').length > 0) 
	{
		tracking_registration = $('#tracking_registration').val();
	}
	else
	{
		tracking_registration = "/EnhancedAccess_registration_successful";
	}
	
	var regexp_pin = /^\d{6}$/;
	
	fields = new Array();
	
	fields[0] = 'firstName';
	fields[1] = 'lastName';
	fields[2] = 'company';
	fields[3] = 'phone';
	fields[4] = 'email';
	fields[5] = 'emailConfirm';
	fields[6] = 'password';
	fields[7] = 'password2';
	fields[8] = 'howHeard';
	fields[9] = 'preferred_pin';
	fields[10] = 'terms';
	fields[11] = 'howHeard-other';
	fields[12] = 'preferred_handset';
	
	var errors = new Array();
	errors[0] = ($('#firstName').val() == '' ? 'Please enter your first name' : '');
	errors[1] = ($('#lastName').val() == '' ? 'Please enter your surname' : '');
	errors[2] = ($('#company').val() == '' ? 'Please enter a company name': '');
	errors[3] = (processPhoneNum('phone') ? 'Please enter a contact phone number': '');
	errors[4] = (!regex.test($('#email').val()) ? 'This email address does not appear to be valid' : '');
	errors[5] = ($('#emailConfirm').val() != $('#email').val() ? 'Email addresses do not match' : '');
	errors[6] = ($('#password').val().length < 6 ? 'Your password must be at least 6 characters' : '');
	errors[6] = ($('#password').val().indexOf(',') >= 0 ? 'Your password may not contain a comma' : errors[6]);
	errors[7] = ($('#password').val() != $('#password2').val() ? 'Passwords do not match' : '');
	errors[8] = ($('#howHeard option:selected').val() == 0 ? 'Please tell us how you heard about Powwownow' : '');
	if (document.getElementById('howHeard').options.length == (document.getElementById('howHeard').selectedIndex+1)) {
			fields[11] = 'howHeard-other';
			errors[11] = ($('#howHeard-other').val() == '' ? 'Please tell us how you heard about Powwownow' : '');
	} else {
			errors[11] = '';
	}
	errors[9] = ($('#preferred_pin').val() != "" && !regexp_pin.test($('#preferred_pin').val()) ? 'Please specify a six digit PIN number' : '');
	errors[10] = ((document.getElementById('terms').type == 'checkbox' && document.getElementById('terms').checked === false) ? 'Please read our terms and conditions and mark the checkbox as you agree' : ''			);
	if (document.getElementById('howHeard').options.length == (document.getElementById('howHeard').selectedIndex+1)) 
		errors[11] = ($('#howHeard-other').val() == '' ? 'Please tell us how you heard about Powwownow' : '');
	else 
		errors[11] = '';
	errors[12] = ($('#preferred_handset option:selected').val() == 0 ? 'Please tell us which phone you have' : '');


	scanPopErrorBox(fields,errors,highlight); // actually runs the check

	reg_email = $('#email').val();
	
	if(errors.join('').length > 0)
	{
		if(visit == 0)
		{
			Google_tracker('/EnhancedAccess_registration_error');
			visit++;
		}
		for(var i = 0; i < fields.length; i++) {
			var el = document.getElementById(fields[i]);
			if (el) {
				el.onfocus = function() { EAregFormCheckEB(this.id); }
				el.onblur = EAregFormCheckEB;
			}
		}
		$('#busyindicator'+tab_result).hide();
		$('#voice-reg'+tab_result).show();
		return false;
	}
	else
	{
		popErrorBox(fields[0],errors[0]); // clear errorbox
		if (submitted) {
			$('#voice-reg'+tab_result).hide();
			$('#busyindicator'+tab_result).show();
			if ($('#voice-reg'+tab_result).blur) {
				$('#voice-reg'+tab_result).blur();
			}
		}
		$('#div_errors').hide();
		return true;
	}
}

function EAregFormReceiveEB(responseText, statusText) {
	if (responseText.length > 50) {
		$("#enhanced-first-left").show();
		$("#enhancedreg").show();
		$('#tab'+tab_result+'-content').html(responseText);
		if(service_result != 2) //web-conferencing is separated
		{
			Google_tracker('/EA_total_registrations');
		}
		var timestamp = new Date().getTime();
		$("#google_conversion").html(EA_conversion_code);
		Google_tracker(tracking_registration);
				
	} else {
		resp = responseText.split(':');
		switch(resp[0]) {
			case '0':
				err = 'System error. It is not possible to register the user';
			break;
			case '-1':
				err = 'Session expired. Please try to register again. Thank you';
			break;
			case '-2':
				err = 'This email address has already been registered for a PIN. <a class="dotted" style="color:red;" href="http://www.powwownow.co.uk/Show-Pin-Reminder/">Click here</a> to request a PIN reminder';
			break;
			case '-3':
				popErrorBox('terms','Please read our terms and conditions and mark the checkbox as you agree');
				err = '';
			break;
			case '-4':
				err = 'System error. It is not possible to register the user';
			break;
			case '-5':
				err = 'System error. It is not possible to register the user';
			break;
			case '-6':
				popErrorBox('email','Sorry, this email does not appear to be valid',false);
				err = "";
			break;
			case '-7':
				popErrorBox('password','The password has to be at least 6 characters long');
				err = '';
			break;
			case '-8':
				err = 'Passwords mismatching';
			break;
			case '-9':
				popErrorBox('preferred_pin','Sorry, this PIN is taken.<br><br>Either choose another<br>(e.g. six digits from your phone number) or leave this box empty and we\'ll pick one for you');
				err = '';
			break;
			case '-10':
				err = 'System error. It is not possible to register the user';
			break;
			case '-11':
				err = 'That password does not match your existing Premium password.  If you need to reset it, please visit http://powwownow.co.uk/Showtime/powt.'.replace(/http[^ ]+powwownow.([^\/]+)\/[Ss]howtime\/powt/g,'<a href="http://www.powwownow.$1/Showtime/'+resp[1]+'" class="dotted">www.powwownow.$1/Showtime/'+resp[1]+'</a>');
			break;
			default:
				err = responseText;
			break;
		}
		if(visit == 0)
		{
			Google_tracker('/EnhancedAccess_registration_error');
			visit++;
		}
		$('#busyindicator'+tab_result).hide();
		$('#voice-reg'+tab_result).show();
		$('#div_errors').html(err);
		$('#div_errors').show();
	}
}

function OAregFormCheckEB(highlight,submitted)
{

	if ($('#tab_result').length > 0) {
		tab_result = $('#tab_result').val();
		service_result = $('#service').val();
	}
	var regexp_pin = /^\d{6}$/;
	
	fields = new Array();
	
	fields[0] = 'emailaddressbottom';
	fields[1] = 'agree-tick-img';
	
	var errors = new Array();
	errors[0] = (!regex.test($('#emailaddressbottom').val()) ? 'This email address does not appear to be valid' : '');
	errors[1] = (($('#agree-tick').val() != 2) ? 'Please read our terms and conditions and mark the checkbox as you agree' : '');

	scanPopErrorBox(fields,errors,highlight); // actually runs the check
	
	if(errors.join('').length > 0)
	{
		if(visit == 0)
		{
			Google_tracker('/OpenAccess_registration_error');
			visit++;
		}
		for(var i = 0; i < fields.length; i++) {
			var el = document.getElementById(fields[i]);
			if (el) {
				el.onfocus = function() { OAregFormCheckEB(this.id); }
				el.onblur = OAregFormCheckEB;
			}
		}
		document.getElementById('pin').style.background = 'transparent';
		return false;
	}
	else
	{
		popErrorBox(fields[0],errors[0]); // clear errorbox
		if (submitted) {
			$('#pin').html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
			document.getElementById('pin').style.background = 'transparent url(/images/common/btn-loader.gif) 50% 50% no-repeat';
		}
		return true;
	}
}

function OAregFormReceiveEB(responseText, statusText) {
	responseText = responseText.split('-');

	$('#pin').css('background','transparent');
	if (responseText[0].length > 1) {
		$("#tabs-middle-btn-open").show();
		$('#pin').html(responseText[0]);
		$("#openAccess-btn1").attr("src",$("#openAccess-btn1").attr("src").replace(/btn-1-on.gif/,'btn-1.gif'));
		$("#openAccess-btn2").attr("src",$("#openAccess-btn2").attr("src").replace(/btn-2.gif/,'btn-2-on.gif'));
		
		if (responseText[1] == '0') {
			var timestamp = new Date().getTime();
			$("#google_conversion").html(OA_conversion_code);
			Google_tracker('/OpenAccess_registration_successful');
		}

	} else {

		switch(responseText[1]) {
			case '2':
				popErrorBox('emailaddressbottom','Sorry, this email does not appear to be valid',false);
				err = '';
			break;
			case '3':
				popErrorBox('agree-tick-img','Please read our terms and conditions and mark the checkbox as you agree');
				err = '';
			break;
			case '4':
				err = 'System error. It is not possible to register the user';
			break;
			default:
				err = responseText;
			break;
		}
		if(visit == 0)
		{
			Google_tracker('/OpenAccess_registration_error');
			visit++;
		}
		$('#pin-error').show();
		$('#pin-error').html(err);
	}
}

function tellafriendFormCheckEB(highlight,submitted)
{
	fields = new Array();
	
	fields[0] = 'yourname';
	fields[1] = 'youremailaddress';
	fields[2] = 'friendsname';
	fields[3] = 'friendsemailaddress';
	
	var errors = new Array();
	errors[0] = ($('#yourname').val() == '' ? 'Please enter your name' : '');
	errors[1] = (!regex.test($('#youremailaddress').val()) ? 'This email address does not appear to be valid' : '');
	errors[2] = ($('#friendsname').val() == '' ? 'Tell another friend' : '');
	errors[3] = (!regex.test($('#friendsemailaddress').val()) ? 'This email address does not appear to be valid' : '');

	scanPopErrorBox(fields,errors,highlight); // actually runs the check

	if(errors.join('').length > 0)
	{
		if(visit == 0)
		{
			Google_tracker('/TellAFriend_request_error');
			visit++;
		}
		for(var i = 0; i < fields.length; i++) {
			var el = document.getElementById(fields[i]);
			if (el) {
				el.onfocus = function() { tellafriendFormCheckEB(this.id); }
				el.onblur = tellafriendFormCheckEB;
			}
		}
		$('#busyindicatorfr').hide();
		return false;
	}
	else
	{
		popErrorBox(fields[0],errors[0]); // clear errorbox
		if (submitted) {
			$('#busyindicatorfr').show();
		}
		return true;
	}
}

function tellafriendFormReceiveEB(responseText, statusText) {
	if(responseText == 1)
	{
		$('#tellfriend-form').hide();
		$('#tellfriend-thankyou').show();
		Google_tracker('/TellaFriend_request_successful');
	}
	else if(responseText == -1)
	{
		popErrorBox('youremailaddress','This email address does not appear to be valid',false);
	}
	else if(responseText == -2)
	{
		popErrorBox('friendsemailaddress','This email address does not appear to be valid',false);
	}
	else if(responseText == -3)
	{
		popErrorBox('youremailaddress','This email address is not yet registered. Please <a href="/Registration-Enhanced/" class="dotted" style="color:red;">register</a> to receive a valid PIN',false);
	}
	else
	{
		var res = 'Sorry your message cannot be delivered. Please try again later';
		$('#tellfriend-error').show();
		$('#tellfriend-error').html(res);
		if(visit == 0)
		{
			Google_tracker('/TellaFriend_request_error');
			visit++;
		}
	}
}

function resetTellAFriendForm() {
		$('#tellfriend-thankyou').hide();
		$('#tellfriend-form').show();
		$('#friendsname').val('');
		$('#friendsemailaddress').val('');
}

function WalletReqFormCheckEB(highlight,submitted)
{
	fields = new Array();
	
	fields[0] = 'building';
	fields[1] = 'town';
	fields[2] = 'postal_code';
	
	var errors = new Array();
	errors[0] = ($('#building').val() == '' ? 'Please enter your street address' : '');
	errors[1] = ($('#town').val() == '' ? 'Please enter your town' : '');
	errors[2] = ($('#postal_code').val() == '' ? 'Please enter your post code' : '');

	scanPopErrorBox(fields,errors,highlight); // actually runs the check

	if(errors.join('').length > 0)
	{
		if(visit == 0)
		{
			Google_tracker('/WalletCard_request_error');
			visit++;
		}
		for(var i = 0; i < fields.length; i++) {
			var el = document.getElementById(fields[i]);
			if (el) {
				el.onfocus = function() { WalletReqFormCheckEB(this.id); }
				el.onblur = WalletReqFormCheckEB;
			}
		}
		$('#busyindicatorwal').hide();
		return false;
	}
	else
	{
		popErrorBox(fields[0],errors[0]); // clear errorbox
		if (submitted) {
			$('#busyindicatorwal').show();
		}
		return true;
	}

}

var landingpage = 0;
function WalletCardReceiveEB(responseText, statusText)
{
	switch(responseText) {
		case -1:
			var res = '<p>Sorry, you can only request a Wallet Card a maximum of 3 times</p><br/>';
			if(visit == 0)
			{
				Google_tracker('/WalletCard_request_error');
				visit++;
			}
		break;

		case -2:
			var res = '<p>System error. It is not possible to request your Wallet Card at this time. Please contact us</p><br/>';
			if(visit == 0)
			{
				Google_tracker('/WalletCard_request_error');
				visit++;
			}
		break;
		
		default:		
			var res = '<p>Thank you for your request. Your wallet card will be delivered within the next eight working days</p>';
			Google_tracker('/WalletCard_request_successful');
		break;
	
	}
	if (landingpage != 1) {
		res += '<p><a href="%link%4%link%"><img src="/images/btn-arrow-left_off.gif" alt=\'Back\' style="margin-top:5px;" align="absmiddle" /></a> <a href="%link%4%link%" class="dotted">Back</a></p>';
	}
	$('#busyindicatorwal').hide();
	$('#wallet-card-right').hide();
	$('#wallet-card-left').attr('style','width:870px');
	$('#wallet-card-div').html(res);
}

function PinRemindCheckEB(highlight,submitted)
{

	fields = new Array();
	
	fields[0] = 'emailaddresstop';
	fields[1] = 'sms';
	
	var errors = new Array();

	errors[0] = (!regex.test($('#emailaddresstop').val()) ? 'This email address does not appear to be valid' : '');
	$('#sms').val($('#sms').val().replace(/[^0-9+]+/g,''));

	scanPopErrorBox(fields,errors,highlight); // actually runs the check

	if(errors.join('').length > 0)
	{
		if(visit == 0)
		{
			Google_tracker('/PinRemind_request_error');
			visit++;
		}
		for(var i = 0; i < fields.length; i++) {
			var el = document.getElementById(fields[i]);
			if (el) {
				el.onfocus = function() { PinRemindCheckEB(this.id); }
				el.onblur = PinRemindCheckEB;
			}
		}
		return false;
	}
	else
	{
		popErrorBox(fields[0],errors[0]); // clear errorbox
		return true;
	}
}

function PinRemindReceiveEB(responseText, statusText)
{
	if(responseText == -2)
	{
		$("#pinreminder-error").html('This email address does not appear to be valid');
		$("#pinreminder-error").fadeIn(250);
		if(visit == 0)
		{
			Google_tracker('/PIN_Reminder_request_error');
			visit++;
		}
	}
	else if(responseText == -3)
	{
		$("#pinreminder-error").html("System error, please try later");
		$("#pinreminder-error").fadeIn(250);
		if(visit == 0)
		{
			Google_tracker('/PIN_Reminder_request_error');
			visit++;
		}
	}
	else if(responseText == -4)
	{
		$("#pinreminder-error").html("Please enter a valid phone number");
		$("#pinreminder-error").fadeIn(250);
		if(visit == 0)
		{
			Google_tracker('/PIN_Reminder_request_error');
			visit++;
		}
	}
	else if(responseText == 0 || responseText == -1)
	{
		$("#pinreminder-error").html('This email address is not yet registered. Please <a href="/Registration-Enhanced/" class="dotted" style="color:red;">register</a> to receive a valid PIN');
		$("#pinreminder-error").fadeIn(250);
		if(visit == 0)
		{
			Google_tracker('/PIN_Reminder_request_error');
			visit++;
		}
	}
	else
	{
		$("#pinreminder-thankyou").fadeIn(250);
		$("#pinreminder-form").hide();
		Google_tracker('/PinReminder_request_successful');
	}
}

function resetPinRemindForm() {
		$("#pinreminder-thankyou").hide();
		$("#pinreminder-form").fadeIn(250);
}

function contactUsFormCheckEB(highlight,submitted)
{
	fields = new Array();
	
	fields[0] = 'firstName';
	fields[1] = 'lastName';
	fields[2] = 'company';
	fields[3] = 'phone';
	fields[4] = 'email';
	fields[5] = 'emailConfirm';
	
	var errors = new Array();
	errors[0] = ($('#firstName').val() == '' ? 'Please enter your first name' : '');
	errors[1] = ($('#lastName').val() == '' ? 'Please enter your surname' : '');
	errors[2] = ($('#company').val() == '' ? 'Please enter a company name' : '');
	errors[3] = (processPhoneNum('phone') ? 'Please enter a contact phone number' : '');
	errors[4] = (!regex.test($('#email').val()) ? 'This email address does not appear to be valid' : '');
	errors[5] = ($('#emailConfirm').val() != $('#email').val() ? 'Email addresses do not match' : '');

	scanPopErrorBox(fields,errors,highlight); // actually runs the check

	if(errors.join('').length > 0)
	{
		if(visit == 0)
		{
			Google_tracker('/ContactUs_request_error');
			visit++;
		}
		for(var i = 0; i < fields.length; i++) {
			var el = document.getElementById(fields[i]);
			if (el) {
				el.onfocus = function() { contactUsFormCheckEB(this.id); }
				el.onblur = contactUsFormCheckEB;
			}
		}
		$('#busyindicator').hide();
		return false;
	}
	else
	{
		popErrorBox(fields[0],errors[0]); // clear errorbox
		if (submitted) {
			$('#busyindicator').show();
		}
		return true;
	}
}

function contactUsReceiveEB(responseText, statusText)
{
	if(responseText == 0)
	{
		var res = "<h2>Sorry your message cannot be delivered. Please try again later</h2>";
		if(visit == 0)
		{
			Google_tracker('/ContactUs_request_error');
			visit++;
		}
	}
	else
	{
		var res = "<h2>Thank you for your email</h2>";
		Google_tracker('/ContactUs_request_successful');
	}
	$('#contact-us-form').html(res);
}

function myPWNFormCheckEB(highlight,submitted)
{
	fields = new Array();
	
	fields[0] = 'first_name';
	fields[1] = 'last_name';
	fields[2] = 'organisation';
	fields[3] = 'business_phone';
	fields[4] = 'pass1';
	fields[5] = 'pass2';
	fields[6] = 'home_phone';
	fields[7] = 'fax_number';
	fields[8] = 'mobile_phone'; // NB the loop below before you add any fields
	
	var errors = new Array();
	errors[0] = ($('#' + fields[0]).val() == '' ? 'Please enter your first name' : '');
	errors[1] = ($('#' + fields[1]).val() == '' ? 'Please enter your surname' : '');
	errors[2] = ($('#' + fields[2]).val() == '' ? 'Please enter a company name' : '');
	errors[3] = (processPhoneNum(fields[3]) ? 'Please enter a contact phone number' : '');
	errors[4] = '';
	errors[5] = '';
	if ($('#' + fields[4]).val() != '') {
		errors[4] = ($('#' + fields[4]).val().indexOf(',') >= 0 ? 'Your password may not contain a comma' : '');
		errors[4] = ($('#' + fields[4]).val().length < 6 ? 'Your password must be at least 6 characters' : errors[4]);
		errors[5] = ($('#' + fields[4]).val() != $('#' + fields[5]).val() ? 'Passwords do not match' : '');
	}
	
	for (i=errors.length;i<fields.length;i++) { // loop through the three optional phone numbers (which is why they're last)
		errors[i] = ($('#' + fields[i]).val() != '' ? (processPhoneNum(fields[i]) ? 'Please enter a valid phone number' : '') : '');
	}
	
	scanPopErrorBox(fields,errors,highlight); // actually runs the check

	if(errors.join('').length > 0)
	{
		if(visit == 0)
		{
			Google_tracker('/ContactUs_request_error');
			visit++;
		}
		for(var i = 0; i < fields.length; i++) {
			var el = document.getElementById(fields[i]);
			if (el) {
				el.onfocus = function() { myPWNFormCheckEB(this.id); }
				el.onblur = myPWNFormCheckEB;
			}
		}
		$('#busyindicator').hide();
		return false;
	}
	else
	{
		popErrorBox(fields[0],errors[0]); // clear errorbox
		if (submitted) {
			$('#busyindicator').show();
		}
		return true;
	}
}

function myPWNReceiveEB(responseText, statusText)
{
	$('#busyindicator').hide();
	if ((responseText == '1')||(responseText == '2'))
	{
		alert('Your details have been successfully updated' + (responseText==2?"\n\nUnfortunately your password was not updated on YuuGuu. Please try again later before using Web Sharing.":''));
		Google_tracker('/MyPowwownow_details_updated');
		$('#pass1').val('');
		$('#pass2').val('');
	} else if (responseText == '-99') {
		alert('Sorry, your session has expired. Please log in again');
		document.location.replace('/');
	} else {
		switch(responseText) {
			case '-1': 
				popErrorBox('first_name','Please enter your first name',false);
				break;
			case '-2': 
				popErrorBox('last_name','Please enter your surname',false);
				break;
			case '-3': 
				popErrorBox('business_phone','Please enter a business contact number',false);
				break;
			case '-4': 
				popErrorBox('organisation','Please enter a company name',false);
				break;
			case '-5': 
				popErrorBox('pass2','Passwords do not match',false);
				break;
			case '-6': 
				popErrorBox('pass1','Your password may not contain a comma',false);
				break;
			case '-7': 
				popErrorBox('pass1','Your password must be at least 6 characters',false);
				break;
			default:
				alert('Sorry, an error occurred. Please try later');
				break;
		}
	}
}

var LOGIN = false;

function downloadShowtimeEB(highlight,submitted)
{
	if (LOGIN) {
		return true;
	} else {
		fields = new Array();
		
		fields[0] = 'dlemail';
		fields[1] = 'dlpass';
		
		var errors = new Array();
		errors[0] = (!regex.test($('#dlemail').val()) ? 'This email address does not appear to be valid' : '');
		errors[1] = ($('#dlpass').val() == '' ? 'Please enter your password' : '');
	
		scanPopErrorBox(fields,errors,highlight); // actually runs the check
	
		if(errors.join('').length > 0)
		{
			if(visit == 0)
			{
				Google_tracker('/Download_Showtime_request_error');
				visit++;
			}
			for(var i = 0; i < fields.length; i++) {
				var el = document.getElementById(fields[i]);
				if (el) {
					el.onfocus = function() { downloadShowtimeEB(this.id); }
					el.onblur = downloadShowtimeEB;
				}
			}
			return false;
		}
		else
		{
			popErrorBox(fields[0],errors[0]); // clear errorbox
			if (submitted) {
				$('#downloadreqbtn').hide();
				$('#busyindicator4').show();
				$('#div_errors3').hide();
			}
			return true;
		}
	}
}

function downloadShowtimeReceiveEB(responseText, statusText)
{
	$('#busyindicator4').hide();
	$('#downloadreqbtn').show();

	var err = '';

	if (responseText == '-1') {
		
		popErrorBox('dlpass','Sorry, those details were not recognised',false);
		if(visit == 0)
		{
			Google_tracker('/Showtime_download_request_error');
			visit++;
		}
		err = ' ';
		
	} else if (responseText == '-2') {
		
		err = 'Sorry, your email address already exists as a Yuuguu user.  You can download Yuuguu again directly from their site at <a href="http://yuuguu.com/download" target="_blank">yuuguu.com/download</a>.  Alternatively, please <a href="/Show-Time/Get-Started/" class="dotted">register here</a> with a new email address.';
		
	} else if (responseText == '-3') {
		
		err = 'Sorry, a system error means you cannot download Showtime right now. Customer Services have been notified and will be in touch when the issue has been resolved. If you need to connect urgently please OFFICE_NUMBER';
		if(visit == 0)
		{
			Google_tracker('/Showtime_download_yuuguu_error');
			visit++;
		}
		
	}

	if(err != '') {
		
		$('#div_errors3').html(err);
		$('#div_errors3').show();
		
	} else {
		
		$('#downloadform').hide();
		
		$('.dllink').attr('href',responseText);
		if (responseText == '/downloads/Yuuguu.app.zip') {
			$('#yuuguudlicon').attr('src','/images/yuuguuicon-mac.gif');
		} else {
			$('#yuuguudlicon').attr('src','/images/yuuguuicon-pc.gif');
		}
		$('#downloadsuccess').show();
		
		Google_tracker('/Showtime_download_request_successful');
		setTimeout("document.location.href='" + responseText +"';",1000);
		
	}
}

recstati = new Array('Playing','Error','Finished','Ready','Paused','%%842%%');

function myPWNRecFormCheck(highlight,submitted,id)
{
	fields = new Array();
	
	fields[0] = 'publish_' + id;
	fields[1] = 'password_' + id;
	
	var errors = new Array();
	if ($('#publish_set_'+id).attr('checked')) {
		var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
		if (!re.test($('#publish_' + id).val())) {
			errors[0] = 'Please enter a valid date in dd/mm/yyyy format.';
		}			
	} else {
		$('#publish_' + id).val('');
	}
	
	if ($('#password_set_'+id).attr('checked')) {
		if ($('#password_' + id).val().length < 6) {
			errors[1] = 'Your password must be at least 6 characters';
		}
	} else {
		$('#password_' + id).val('');
	}

	scanPopErrorBox(fields,errors,highlight); // actually runs the check

	if(errors.join('').length > 0)
	{
		if(visit == 0)
		{
			Google_tracker('/TellAFriend_request_error');
			visit++;
		}
		for(var i = 0; i < fields.length; i++) {
			var el = document.getElementById(fields[i]);
			if (el) {
				el.onfocus = function() { myPWNRecFormCheck(this.id,false,id); }
				el.onblur = function() { myPWNRecFormCheck(false,false,id); }
			}
		}
		$('#busyindicatorrec_'+id).hide();
		return false;
	}
	else
	{
		popErrorBox(fields[0],errors[0]); // clear errorbox
		if (submitted) {
			$('#busyindicatorrec_'+id).show();
		}
		return true;
	}
}

function myPWNRecReceive(responseText, statusText) {
	resp = responseText.split("||");
	$('#busyindicatorrec_'+resp[2]).hide();
	if(resp[1] == 1)
	{
		$('#recording_' + resp[2]).html(resp[0]);
		selectclick(resp[2]);
	}
	else if(resp[1] == '-1')
	{
		popErrorBox('publish_'+resp[2],'Please enter a valid date in dd/mm/yyyy format.',false);
	}
	else if(resp[1] == '-2')
	{
		popErrorBox('publish_' + resp[2],'Please enter a date in the future, or untick the box to unpublish.',false);
	}
	else if(resp[1] == '-3')
	{
		popErrorBox('publish_' + resp[2],'Please enter a password of at least six characters, or untick the box.',false);
	}
	else
	{
		alert('System error, please try later');
	}
}

