window.addEvent('domready', function() {
	if ($('navigation').getElement('form')) {
		// only apply when available
		loginFormEffect();
	}
});

/**
 * Login Form spesific functions
 */
function loginFormEffect() {
	// Empty the input on focus
	// and set back to default value on left empty
	var username = $('navigation').getElement('form > input[type=text]');
	username.addEvent('focus', function() {
		if (this.getProperty('value') == this.getProperty('rel')) {
			this.setProperty('value', '');
		}
	})
	.addEvent('blur', function() {
		if (this.getProperty('value') == '') {
			this.setProperty('value', this.getProperty('rel'));
		}
	});
	
	// password input effect
	var passwordInput = 'url(' + baseUrl +  '/images/resources/login-password-bg.png)';
	var password = $('navigation').getElement('form > input[type=password]');
	password.style.backgroundImage = passwordInput;
	password.addEvent('focus', function() {
		this.style.backgroundImage = 'none';
	})
	.addEvent('blur', function() {
		if (this.value == '') {
			password.style.backgroundImage = passwordInput;
		}
	});
	
	// Red arrow button on the form
	$('navigation').getElement('li[class=login] > a')
	.addEvent('click', function(e) {
		e.stop(); // stop current event
		$('navigation').getElement('form').submit(); // execute form
	});
	
}

function getNextProfile(){
	var result = false;
	//if baseUrl not found stop the process
	if(!baseUrl){
		//Prevents the default submit event from loading a new page.
		e.stop();
		alert("baseUrl not found");
		return;
	}
	
	var pageNumber = $('pageNumber').value;
		
	var myRequest = new Request(
			{
				url :baseUrl + '/next-profile',
				method :'get',
				onSuccess : function(responseText, responseXML) {

					$('pageNumber').value = ++pageNumber;
					
					$('thumbnails').innerHTML = responseText;
				}
			});

	//Send the request.
	myRequest.send('pageNumber=' + pageNumber);
}

/**
 * get 1 user Profile, if userId exists use it, if not get random profile 
 * @param userId
 * @return
 */
function getOneProfile(userId){
	var result = false;
	//if baseUrl not found stop the process
	if(!baseUrl){
		//Prevents the default submit event from loading a new page.
		alert("baseUrl not found");
		return;
	}
	var requestParameter = '';
	if(userId){
		requestParameter = '&userId=' + userId;
	}

		
	var myRequest = new Request(
			{
				url :baseUrl + '/one-profile',
				method :'get',
				onSuccess : function(responseText, responseXML) {
					$('profile').innerHTML = responseText;
				}
			});

	//Send the request.
	myRequest.send(requestParameter);
}

/**
 * get 1 user Profile from static pages INFOS,FAQ,PRESSE 
 * need to activate the selected user and forward to index page
 * @param userId
 * @return
 */
function getOneProfileFromStatic(userId){
	var result = false;
	//if baseUrl not found stop the process
	if(!baseUrl){
		//Prevents the default submit event from loading a new page.
		alert("baseUrl not found");
		return;
	}
	
	if(userId){
		requestParameter = '?userId=' + userId;
	}
	
	window.location.href = baseUrl + '/index' + requestParameter;
		
}

/**
 * open window for profile PDF
 * 
 */
function printPdf(){
	var requestParameter = '?displayedUserId=' + $('displayedUserId').value ;
	window.open(baseUrl + '/print' + requestParameter ,'mywindow','width=800,height=600');
}

/**
 * open terms of service PDF
 * @return
 */
function openTermsPdf(){
	window.open(baseUrl + '/pdf','mywindow','width=800,height=600');
}




	
