
var timeSinceMouseOver = new Array();
var currentShowing = 0;
var hideTimeOutIsRunning = false;
var instantiatedBuyOptions = [];
var buyOptionsTemplate = null;
language.setPage('tokenshop-php');

function instantiateTemplates() {
	buyOptionsTemplate = $('#buyOptionTemplate').template();
}

function buyTickets(drawingId, noOfTickets){
    if (!tokenshop.isLoggedIn) {
        return;
    }
	var url = "/ajax/tokenshop.ajax.php";
	
	url = url + "?act=buyTicket&id=" + drawingId + "&tickets=" + noOfTickets;
	makeHttpRequest(url, "ticketsPurchased");
}

function ticketsPurchased(str) {
	
	var response = str.split(":");
	if (response[1] == 'succes') {
		var counter = document.getElementById('owned_tickets_' + response[2]);
		var ticketsOwned = parseInt(counter.innerHTML);
		ticketsOwned  += parseInt(response[3]);
		tokenshop.ticketsOwnedAr[response[2]] = ticketsOwned;
		
		counter.innerHTML = ticketsOwned;
		
		$('#subtractButton_' + response[2])
            .attr('src', tokenshop.root + '/images/tokenshop/button_subtract.png')
            .unbind('click')
            .bind('click', function () {
                returnTickets(response[2], 1);
            });
		
		
		/* set the number of tokens displayed in the header of the page */
		setTopTokens(-response[4]);
		updateButtons(response[2]);
		
	} else if (response[1] == 'error') {
		language.setPage('tokenshop-php');
		switch (response[2]) {
			case "insufficientTokens":
				alert(language.getText('F16'));
				break;
			case "outdated":
				alert(language.getText('F18'));
				break;
			default:
				alert(language.getText('F17'));
				break;
		}
	}
}

function updateButtons(id) {

    /* handle return buttons */
	if (tokenshop.ticketsOwnedAr[id] >= 1) {
			
		activateButton('return', id, 'Max');	
	
		if (tokenshop.ticketsOwnedAr[id] >= 10) {
				
			activateButton('return', id, 10);	
			
			if (tokenshop.ticketsOwnedAr[id] >= 100) {
				
				activateButton('return', id, 100);		
				
				if (tokenshop.ticketsOwnedAr[id] >= 1000) {
	
					activateButton('return', id, 1000);		
				
				} else {

					disableButton('return', id, 1000);	
		
				}						
			} else {

				disableButton('return', id, 100);	
				disableButton('return', id, 1000);	
				
			}
		} else {
			
			disableButton('return', id, 10);	
			disableButton('return', id, 100);	
			disableButton('return', id, 1000);	
		
		}
	} else {
		
		disableButton('return', id, 'Max');	
		disableButton('return', id, 10);	
		disableButton('return', id, 100);	
		disableButton('return', id, 1000);	
		
	}
	
	/* handle buy buttons */
	if (tokenshop.ticketPrices[id] * 1000 > tokenshop.tokens ) {
		
		disableButton('buy', id, 1000);
		
		if (tokenshop.ticketPrices[id]  * 100 > tokenshop.tokens ) {

			disableButton('buy', id, 100);
			
			if (tokenshop.ticketPrices[id]  * 10 > tokenshop.tokens ) {

				disableButton('buy', id, 10);
				
				if (tokenshop.ticketPrices[id] > tokenshop.tokens ) {

					disableButton('buy', id, 'Max');
			
				} else {

					activateButton('buy', id, 'Max');	
				
				}
			} else {
				
				activateButton('buy', id, 'Max');	
				activateButton('buy', id, 10);	
				
			}
		
		} else {
			
			activateButton('buy', id, 'Max');	
			activateButton('buy', id, 100);	
			activateButton('buy', id, 10);	
			
		}
	
	} else {
		
		activateButton('buy', id, 'Max');	
		activateButton('buy', id, 1000);	
		activateButton('buy', id, 100);	
		activateButton('buy', id, 10);	
		
	}
}

function activateButton(buyOrReturn, id, number) {
	
	var prefix = buyOrReturn == 'buy' ? 'buy' : 'return';
	var color = buyOrReturn == 'buy' ? 'green' : 'red';
	
	$('#' + prefix + number + 'Button_' + id)
		.removeClass('s12_grey')
		.addClass('s12_' + color)
		.unbind('click')
		.attr('href', 'javascript:doNothing();');

	if (buyOrReturn == 'buy') {
		$('#' + prefix + number + 'Button_' + id)
			.bind('click', function () {
				buyTickets(id, number);
			});
	} else {
		$('#' + prefix + number + 'Button_' + id)
			.bind('click', function () {
				returnTickets(id, number);
			});
	}
		
}

function disableButton(buyOrReturn, id, number) {
	
	var prefix = buyOrReturn == 'buy' ? 'buy' : 'return';
	var color = buyOrReturn == 'buy' ? 'green' : 'red';
	
	$('#' + prefix + number + 'Button_' + id)
		.removeClass('s12_' + color)
		.addClass('s12_grey')
		.unbind('click')
		.bind('click', function () {
			doNothing();
		})
		.attr('href', 'javascript:doNothing();');
}


function setTopTokens(tokensInput){
	var topTokensCounter = document.getElementById('top_tokens');
	if (tokenshop.tokens == null) {
		tokenshop.tokens = parseInt(topTokensCounter.innerHTML.replace(/\./g , ''));
	}
	tokenshop.tokens += parseInt(tokensInput);
	topTokensCounter.innerHTML = addDots(tokenshop.tokens);
	
}
function addDots(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

function returnTickets(drawingId, noOfTickets){
	
	var url = "/ajax/tokenshop.ajax.php";
	
	url = url + "?act=returnTicket&id=" + drawingId + "&tickets=" + noOfTickets;
	makeHttpRequest(url, "ticketsReturned");	
}
function ticketsReturned(str) {
	var response = str.split(":");
	if (response[1] == 'succes') {
		var counter = document.getElementById('owned_tickets_' + response[2]);
		var ticketsOwned = parseInt(counter.innerHTML);
		ticketsOwned  -= parseInt(response[3]);
		tokenshop.ticketsOwnedAr[response[2]] = ticketsOwned;
		counter.innerHTML = ticketsOwned;
		
		if (ticketsOwned <= 0) {
			$('#subtractButton_' + response[2])
                .attr('src', tokenshop.root + '/images/tokenshop/button_subtractGrey.png')
                .unbind('click');
		}
		
		setTopTokens(response[4]);
		updateButtons(response[2]);
		
	} else if (response[1] == 'error') {
		language.setPage('tokenshop-php');
		switch (response[2]) {
			case "insufficientTickets":
				alert(language.getText('F23'));
				break;
			case "outdated":
				alert(language.getText('F18'));
				break;
			default:
				alert(language.getText('F16'));
				break;
		}
	}
}

var hoveredItem = 0;

function hoverBuyTickets(id) {
	
	if ($.inArray(id, instantiatedBuyOptions) == -1 && tokenshop.isLoggedIn){
		$('#buyOptionsContainerDiv_' + id).html($.tmpl(buyOptionsTemplate, {drawingId : id, tokenPrice : $('#drawingTokenPrice_' + id).val()}));
		instantiatedBuyOptions.push(id);
	}
	
    hoveredItem = id;
    setTimeout('stillHovering(' + id + ')',200);
}

function stillHovering(id) {
    if (hoveredItem == id) {
       updateButtons(id);
       hoveredBuyTickets(id);
    }
}


function hoveredBuyTickets(id) {

    if (tokenshop.tokens == null) {
		tokenshop.tokens = parseInt(topTokensCounter.innerHTML.replace(/\./g , ''));
	}
    if(document.getElementById('buy_options_' + id).style.display == 'none') {
        $('#buy_options_' + id).fadeIn(400);
    }
	timeSinceMouseOver[id] = -1;
	if (!hideTimeOutIsRunning) {
		hideBuyTickets();
	}
	if (currentShowing != 0 && currentShowing != id) {
		$('#buy_options_' + currentShowing).hide();
	}
	currentShowing = id;
}

function hideBuyTickets() {
	
	hideTimeOutIsRunning = true;
	for(var i in timeSinceMouseOver) {
		
		if (timeSinceMouseOver[i] > 0) {
			$('#buy_options_' + i).hide();
			delete timeSinceMouseOver[i];
		}
		if (timeSinceMouseOver[i] != -1) {
			timeSinceMouseOver[i] += 1;
		}
	}
	if(timeSinceMouseOver.length > 0) {
		setTimeout('hideBuyTickets()',500);
	} else {
		hideTimeOutIsRunning = false;
	}
}
function stopTimer(id) {
    hoveredItem = id;
	timeSinceMouseOver[id] = -1;
}
function startTimer(id) {
    hoveredItem = 0;
	timeSinceMouseOver[id] = 0;
}

function calculate(id, tokenprice, numberOfTokens){
	
	if (numberOfTokens == 'MAX') {
		if (tokenshop.tokens == null) {
			tokenshop.tokens = parseInt(topTokensCounter.innerHTML.replace(/\./g , ''));
		}
		numberOfTokens = Math.floor(tokenshop.tokens / tokenprice);
	}
	
	$('#calc_' + id).text(addDots(tokenprice + ' x ' + numberOfTokens + ' = ' + (tokenprice * numberOfTokens)) + ' ' + language.getText('F11', 'tokenshop-php'));
	
}

function countdownReachedZero(){

    var nextDrawingContainer = $('#nextDrawings').find('div.itemContainer:first');

    $('#rwDrawing').css('top', '169px');
    $('#rwWinner').css('top', '0px');
    

    $('#rwImg').attr('src', $('#ndImg').attr('src'));
    $('#rwTitle').text($('#ndTitle').text());
    $('#rwModel').text($('#ndModel').text());
    $('#rwPrice').text($('#ndPrice').text());

    var oldDrawingId = tokenshop.nextDrawingId;
    tokenshop.nextDrawingId = nextDrawingContainer.find('input#drawingId').val();
    $('#ndImg').attr('src', nextDrawingContainer.find('div.ts_item_img img:first-child').attr('src'));
    $('#ndTitle').text(nextDrawingContainer.find('div.ts_item_headline:first').text());
    $('#ndModel').text(nextDrawingContainer.find('div.ts_item_model:first').text() + '. ' + nextDrawingContainer.find('div.ts_item_price:first').text());
    $('#ndPrice').text(nextDrawingContainer.find('div.ts_item_tokenprice:first').text());
    $('#ndBuyOptions').html(nextDrawingContainer.find('div.ts_item_buyOptions').html());
    $('#tokenshopWrapper .ts_nd_tickets:first div.ts_focus_item_buyOptions_container').attr('id', 'buy_options_' + tokenshop.nextDrawingId);
    $('#tokenshopWrapper .ts_nd_owned_tickets:first').attr('id',nextDrawingContainer.find('div.ts_item_ownedtickets:first').attr('id')).text(nextDrawingContainer.find('div.ts_item_ownedtickets:first').text());

    var subtractButton = $('#subtractButton_' + oldDrawingId);
    if (parseInt($('#tokenshopWrapper .ts_nd_owned_tickets:first').text()) > 0) {
        subtractButton
            .attr('src', tokenshop.root + '/images/tokenshop/button_subtract.png')
            .unbind('click')
            .bind('click', function () {
              	returnTickets(tokenshop.nextDrawingId, 1);
            });
    } else {
        subtractButton
            .attr('src',tokenshop.root + '/images/tokenshop/button_subtractGrey.png')
            .unbind('click');
    }
    subtractButton.attr('id', 'subtractButton_' + tokenshop.nextDrawingId);
    $('#nd_specs_link').unbind('click').bind('click', function(){showDetails(tokenshop.nextDrawingId);});


    $('#rwWinner').animate({top: '-=169px'}, 3000);
    $('#rwDrawing').animate({top: '-=169px'}, 3000);

    var timeForNextDrawing = parseInt(nextDrawingContainer.find('input#drawingUnixTime').val());
    nextDrawingContainer.remove();

    var date = new Date();
    var seconds = timeForNextDrawing - Math.round(date.getTime() / 1000);
    
    if (seconds > 86400) {
        $('#CD1days').show();
        $('#CD1ts').show();
    }
    countdownHandler.start('CD1', "http://www.komogvind.dk/images/tokenshop/countdown_digits/largegold/", seconds, true, timeForNextDrawing, undefined, countdownReachedZero);
    setTimeout('checkForWinner(' + oldDrawingId + ')', 90000);
}
function checkForWinner(drawingId) {

    var url = "/ajax/tokenshop.ajax.php";

	url = url + "?act=checkDrawing&id=" + drawingId;
	makeHttpRequest(url, "checkedForWinner");

}
function checkedForWinner(response) {

    var responseAr = response.split(":");
    if (responseAr[1] == 'noWinner') {
    	setTimeout('checkForWinner(' + responseAr[2] + ')', 30000);
    } else {
    	var winner = eval("(" + response + ")");
        winnerFound(winner);
    }

}
function winnerFound(winner) {
	
	$('#rwWinProdImg').attr('src', winner.productImage);
	$('#rwWinProdTitle').text(winner.productName);
	$('#rwWinTime').text(winner.drawingTime);
	var newProfileLink = $('#rwWinUsername').attr('href');
	newProfileLink = newProfileLink.substr(0, newProfileLink.lastIndexOf('=') + 1) + winner.winnerUserid;
	$('#rwWinUsername').html(winner.winnerUsername).attr('href',newProfileLink);
	$('#rwWinUserImg').attr('src', winner.winnerUserImage);
	$('#rwWinUserinfo').text(winner.ageAndRegion);


    $('#rwDrawing').css('top', '0px');
    $('#rwWinner').css('top', '169px');
    $('#rwWinner').show();
    $('#rwWinner').animate({top: '-=169px'}, 3000);
    $('#rwDrawing').animate({top: '-=169px'}, 3000);
}

function showDetails(id) {
	var url = "/ajax/tokenshop.ajax.php";
	url = url + "?act=getDetails&id=" + id;

	makeHttpRequest(url, "detailsRecieved");	
}
function hideDetails() {
	$.unblockUI();
}
function detailsRecieved(response) {
	$.blockUI(
		{
			message:response,
			css:{
				backgroundColor:'transparent',
				border:'none',
				opacity:1,
				width:520,
                zIndex:999999999999,
                cursor: 'default'
                

			}
		}
	);
	$('.blockOverlay').click($.unblockUI);
    $('.blockOverlay').css('z-index',99999999).css('background-color', '#FFFFFF').css('cursor','default');

}

function checkAccount() {
	var ac = jQuery.trim($('#account').val());

	var acTemp = '';
	
	for (i=0; i < ac.length; i++) {
		if (!isNaN(ac[i]) && ac[i] != ' ') {
			acTemp += ac[i];
		}
	}
	ac = acTemp;
	
	if (ac.length <= 4) {
		return;
	}
	
	if (ac[4] != '-') {
		ac = ac.substring(0,4) + '-' + ac.substring(4);
	}
	
	$('#account').val(ac);
}

function doNothing(){

}

function sortCat(){
	var id = $('#catId').val(); 
	if (id == '') {
		window.location.replace('index.php');
	} else {
		window.location.replace('?catId=' + id);
	}
	
}


var facebookPromptShown = false;
function showFacebookPrompt() {
	if (!facebookPromptShown) {
		var content = $('#facebookPromptContainer').html();
		$('#facebookPromptContainer').html('');
		
		$.blockUI(
				{
					message:content,
					css:{
						backgroundColor:'transparent',
						border:'none',
						opacity:1,
						width:616,
		                zIndex:999999999999,
		                cursor: 'default'
		                
	
					}
				}
			);
		$('.blockOverlay').click($.unblockUI);
	    $('.blockOverlay').css('z-index',99999999).css('background-color', '#FFFFFF').css('cursor','default');
	    $('#ThemedBox1').draggable();
	    facebookPromptShown = true;
	}
}

var facebookPrompt = {

	promptContainer : null,
	iUsername : null,
	username : null,
	usernameIsValidated : false,
	iPassword : null,
	password : null,
	passwordIsValidated : false,
	iEmail : null,
	email : null,
	emailIsValidated : false,
	gender : null,
	disclaimer : null,
	ajaxUrl : '/ajax/tokenshop.ajax.php',
	gUserId : null,

	fbLanguage : null,
	
	initialize : function () {

		var thePrompt = this;

		thePrompt.promptContainer = $('#facebookPromptContainer');
		thePrompt.username = $('#fbpUsername');
		thePrompt.password = $('#fbpPassword');
		thePrompt.email = $('#fbpEmail');
		thePrompt.gender = $('#fbpGender');
		thePrompt.gUserId = $('#uid').val();
		thePrompt.disclaimer = $('#fbpDisclaimer');
		thePrompt.fbLanguage = jQuery.extend(true, {}, language);
		thePrompt.fbLanguage.setPage('tokenshop-php');

		/* attach eventhandlers */
		thePrompt.username.focus(function(){thePrompt.focusUsername();}).blur(function(){thePrompt.validateUsername();}).keydown(function(){thePrompt.changeUsername();});
		thePrompt.password.focus(function(){thePrompt.focusPassword();}).blur(function(){thePrompt.validatePassword();}).keydown(function(){thePrompt.changePassword();});;
		thePrompt.email.focus(function(){thePrompt.focusEmail();}).blur(function(){thePrompt.validateEmail();}).keydown(function(){thePrompt.changeEmail();});;
		
				
	},
	focusUsername : function () {
		
	},
	changeUsername : function () {
		$('#fbpUsernameValidator').hide();
		var thePrompt = this;
		thePrompt.usernameIsValidated = false;
	},
	validateUsername : function () {

		var thePrompt = this;
		var username = thePrompt.username.val();//.trim();

		if (thePrompt.iUsername == username) {
			return;
		}

		thePrompt.iUsername = username;
		 
		if (username.length < 5) {
			var valImg = $('#fbpUsernameValidator').find('img');
			valImg.attr('src', '/images/icons24/cancel.png').attr('title',thePrompt.fbLanguage.getText('F81'));
			$('#fbpUsernameValidator').fadeIn();
			return;
		} 
		
		$.get(thePrompt.ajaxUrl, {'act':'checkUsername', 'username':username}, function (response) {thePrompt.usernameValidated(response);});
	},
	usernameValidated : function (response) {
		var thePrompt = this;
		var valImg = $('#fbpUsernameValidator').find('img');
		if (response == 'OK') {	
			valImg.attr('src', '/images/icons24/check.png').attr('title',thePrompt.fbLanguage.getText('F85'));
			thePrompt.usernameIsValidated = true;
		} else {
			valImg.attr('src', '/images/icons24/cancel.png');
			switch(response) {
				case 'notAvailable':
					valImg.attr('title',thePrompt.fbLanguage.getText('F82'));
					break;
				case 'illegalChars':
					valImg.attr('title',thePrompt.fbLanguage.getText('F83'));
					break;
				case 'error':
				default:
					valImg.attr('title',thePrompt.fbLanguage.getText('F84'));
					break;
			}
		}	
		$('#fbpUsernameValidator').fadeIn();
	},
	focusPassword : function () {
							
	},
	changePassword : function () {
		$('#fbpPasswordValidator').hide();
		var thePrompt = this;
		thePrompt.passwordIsValidated = false;
	},
	validatePassword : function () {

		var thePrompt = this;
		var password = thePrompt.password.val();//.trim();

		if (thePrompt.iPassword == password) {
			return;
		}

		thePrompt.iPassword = password;
		 
		if (password.length < 5) {
			var valImg = $('#fbpPasswordValidator').find('img');
			valImg.attr('src', '/images/icons24/cancel.png').attr('title',thePrompt.fbLanguage.getText('F86'));
			$('#fbpPasswordValidator').fadeIn();
			return;
		}

		$.get(thePrompt.ajaxUrl, {'act':'checkPassword', 'password':password}, function (response) {thePrompt.passwordValidated(response);});
	},
	passwordValidated : function (response) {
		var thePrompt = this;
		var valImg = $('#fbpPasswordValidator').find('img');
		
		if (response == 'OK') {	
			valImg.attr('src', '/images/icons24/check.png').attr('title',thePrompt.fbLanguage.getText('F88'));
			thePrompt.passwordIsValidated = true;
		} else {
			valImg.attr('src', '/images/icons24/cancel.png').attr('title',thePrompt.fbLanguage.getText('F87'));
		}	
		$('#fbpPasswordValidator').fadeIn();
	},
	focusEmail : function () {
							
	},
	changeEmail : function () {
		$('#fbpEmailValidator').hide();
		var thePrompt = this;
		thePrompt.emailIsValidated = false;
	},
	validateEmail : function () {
		var thePrompt = this;
		var email = thePrompt.email.val();//.trim();

		if (thePrompt.iEmail == email) {
			return;
		}

		thePrompt.iEmail = email;
		
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		
		if (!filter.test(email)) {
			var valImg = $('#fbpEmailValidator').find('img');
			valImg.attr('src', '/images/icons24/cancel.png').attr('title',thePrompt.fbLanguage.getText('F89'));
			$('#fbpEmailValidator').fadeIn();
			return;
		}

		$.get(thePrompt.ajaxUrl, {'act':'checkEmail', 'email':email}, function (response) {thePrompt.emailValidated(response);});
	},
	emailValidated : function (response) {
		var thePrompt = this;
		var valImg = $('#fbpEmailValidator').find('img');
		if (response == 'OK') {	
			valImg.attr('src', '/images/icons24/check.png').attr('title',thePrompt.fbLanguage.getText('F90'));
			
			thePrompt.emailIsValidated = true;
		} else if (response.indexOf('emailExists') != -1) {
			
			var emailUser = response.split(':');
			if (emailUser[1] == thePrompt.gUserId) {
				valImg.attr('src', '/images/icons24/check.png').attr('title',thePrompt.fbLanguage.getText('F90'));
				thePrompt.emailIsValidated = true;
			} else {
				valImg.attr('src', '/images/icons24/cancel.png').attr('title',thePrompt.fbLanguage.getText('F91'));
			}
		} else {
			valImg.attr('src', '/images/icons24/cancel.png').attr('title',thePrompt.fbLanguage.getText('F89'));
		}	
		$('#fbpEmailValidator').fadeIn();
	}, 
	submitForm : function () {
		
		var thePrompt = this;
		var errors = new Array();
		
		if (!thePrompt.usernameIsValidated) {
			errors.push(thePrompt.fbLanguage.getText('F84')); 
		}

		if (!thePrompt.passwordIsValidated) {
			errors.push(thePrompt.fbLanguage.getText('F87'));
		}
		
		if (!thePrompt.emailIsValidated ) {
			errors.push(thePrompt.fbLanguage.getText('F89'));
		} 

		if (thePrompt.gender.val() == '0') {
			errors.push(thePrompt.fbLanguage.getText('F92'));
		}

		if (!thePrompt.disclaimer.is(':checked')) {
			errors.push(thePrompt.fbLanguage.getText('F93'));
		}

		if (errors.length > 0) {

			var errorStr = thePrompt.fbLanguage.getText('F94') + '\n';

			for (i = 0; i < errors.length; i++) {
				errorStr += '\t- ' + errors[i] + '\n';
			}

			alert(errorStr);
			return;
		}

		var formdata = {
			act : 'createUser',
			userid : $('#uid').val(),
			username : thePrompt.username.val(),
			password : thePrompt.password.val(),
			email : thePrompt.email.val(),
			gender : thePrompt.gender.val(),
			disclaimer : thePrompt.disclaimer.is(':checked')				
		};
		thePrompt.deactivateForm();
		$.post(thePrompt.ajaxUrl, formdata, function (response) {thePrompt.formSubmitResponseRecieved(response);});
	},
	activateForm : function () {
		$('#signupBoxContainer').find('input').attr('disabled', '');
	},
	deactivateForm : function () {
		$('#signupBoxContainer').find('input').attr('disabled', 'disabled');
	},
	formSubmitResponseRecieved : function (response) {
		var thePrompt = this;
		if (response == 'OK') {
			$('#signupBoxContainer').find('div.thecontent').hide().html(
					'<div class="welcome"><span class="wHeader">' + 
					thePrompt.fbLanguage.getText('F96') + 
					'</span>' + 
					thePrompt.fbLanguage.getText('F97') + 
					'</div><div class="button">' +
					tokenshop.fbLoginButton +
					'</div>'
			).fadeIn();
					
		} else if (response == 'notAGuest') {
			alert(thePrompt.fbLanguage.getText('F99'));
			$('.blockOverlay').click();
		} else {
			alert(thePrompt.fbLanguage.getText('F95'));
			thePrompt.activateForm();
		}
	},
	login : function () {
		var thePrompt = this;
		$('#username').val(thePrompt.username.val());
		$('#password').val(thePrompt.password.val());
		javascript:document.loginformRight.submit();
	}
};

