(function($){
	$.fn.popupWindow = function(instanceSettings){
		
			return this.each(function(){
		
				$(this).click(function(){
		
					$.fn.popupWindow.defaultSettings = {
						centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
						centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
						height:500, // sets the height in pixels of the window.
						left:0, // left position when the window appears.
						location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
						menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
						resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
						scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
						status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
						width:500, // sets the width in pixels of the window.
						windowName:null, // name of window set from the name attribute of the element that invokes the click
						windowURL:null, // url used for the popup
						top:0, // top position when the window appears.
						toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
					};
		
					settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});
		
					var windowFeatures =     
						'height=' + settings.height +
						',width=' + settings.width +
						',toolbar=' + settings.toolbar +
						',scrollbars=' + settings.scrollbars +
						',status=' + settings.status + 
						',resizable=' + settings.resizable +
						',location=' + settings.location +
						',menuBar=' + settings.menubar;

					settings.windowName = this.name || settings.windowName;
					settings.windowURL = this.href || settings.windowURL;
					var centeredY,centeredX;
			
					if(settings.centerBrowser){
						
						if ($.browser.msie) { //hacked together for IE browsers
							centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
							centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
						}else{
							centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
							centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
						}
						window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
					}else if(settings.centerScreen){
						centeredY = (screen.height - settings.height)/2;
						centeredX = (screen.width - settings.width)/2;
						window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
					}else{
						window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	
					}
					return false;
				});
			
			});	
		};
})(jQuery);function addslashes(str) {
	str = str.replace(/\\/g, '\\\\');
	str = str.replace(/\'/g, '\\\'');
	return str;
}

/**
 * @param string
 * @param int	0 = Keine Anführungszeichen umwandeln 
 *				1 = Nur einfache Anführungszeichen umwandeln 
 *				2 = Nur doppelte Anführungszeichen umwandeln (Standardeinstellung) 
 *				3 = Beide Arten (einfache und doppelte Anführungszeichen) umwandeln
 */
function htmlspecialchars(str, typ) {
	if (typeof str == 'undefined') {
		str = "";
	}
	if (typeof typ != 'number') {
		typ = 2;
	}
	typ = Math.max(0, Math.min(3, parseInt(typ)));
	var from = new Array(/&/g, /</g, />/g);
	var to = new Array('&amp;', '&lt;', '&gt;');
	if (typ == 1 || typ == 3) {
		from.push(/"'"/g);
		to.push('&#039;');
	}
	if (typ == 2 || typ == 3) {
		from.push(/'"'/g);
		to.push('&quot;');
	}
	for ( var i in from) {
		str = str.replace(from[i], to[i]);
	}
	return str;
}

if (typeof String.prototype.trim !== 'function') {
	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g, '');
	}
}

(function($) {
	$.fn.center = function() {
		this.css("position", "absolute");
		this.css("top", ($(window).height() - this.height()) / 2
				+ $(window).scrollTop() + "px");
		this.css("left", ($(window).width() - this.width()) / 2
				+ $(window).scrollLeft() + "px");
		return this;
	}
	
	$.fn.startHidingSubMenu = function() {
		clearTimeout($('.navigation-navigationMain').data('intervalId'));
		$('.navigation-navigationMain').data('currentSubMenu').parent().addClass('highlighted');
		$('.navigation-navigationMain').data('intervalId',setTimeout("$.fn.hideSubMenu()",1500));
					
	}
	$.fn.hideSubMenu = function() {
		clearTimeout($('.navigation-navigationMain').data('intervalId'));
		$('.navigation-navigationMain').data('currentSubMenu').parent().removeClass('highlighted');
		$('.navigation-navigationMain').data('currentSubMenu').hide();
	}

	$(function() {
		$('.navigation-navigationMain').data('intervalId',-1);
		$('.navigation-navigationMain').data('currentSubMenu',null);
		
		// IE missing label image click event bugfix
		if ($.browser.msie) {
			$('label img').live(
					'click',
					function() {
						$('#' + $(this).parents('label').attr('for')).click()
								.each(function() {
											var el = $(this);
											var elType = el.attr('type');
											if (elType == 'checkbox' || elType == 'radio') {
												el.attr('checked', true);
											}
										});
					});
		}

		// Popupize all popup links.
		$('a.popup, .popup a').popupWindow({
			height : 500,
			width : 423,
			centerBrowser : 1,
			scrollbars : 1
		});
		
		$('.boxes-logInLogOutBox input[name=username]').focus(function() {
			if($(this).val() == $(this)[0].defaultValue) {
				$(this).val("");
			}
		});
		$('.boxes-logInLogOutBox input[name=username]').blur(function() {
			if($(this).val() == "") {
				$(this).val($(this)[0].defaultValue);
			}
		});
		$('.boxes-logInLogOutBox .passwordShow').focus(function() {
			if($(this).val() == $(this)[0].defaultValue) {
				$('.boxes-logInLogOutBox .passwordShow').hide();
				$('.boxes-logInLogOutBox .password').show();
				$('.boxes-logInLogOutBox .password').focus();
			}
		});
		$('.boxes-logInLogOutBox input[name=password]').blur(function() {
			if($(this).val() == "") {
				$('.passwordShow').show();
				$('.password').hide();
			}
		});
		$('.boxes-logInLogOutBox .btnLogin').click(function() {
			$(this).parent().submit();
		});
	});
})(jQuery);

function ExternalOpenInNew() {
	if (!document.getElementsByTagName)
		return;
	var anchors = document.getElementsByTagName("a");
	for ( var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href")
				&& anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}
window.onload = ExternalOpenInNew;
(function($) {
	$.widget('ui.SpanButtonSubmitLoading',{
		_create: function() {
		},
		_init: function() {
			var that = this;
			this.element.after('<span class="ajaxLoading"></span>');
			this.element.click(function(){
				that.element.hide();
				that.element.parent().children('.ajaxLoading').css('display', 'block');
			});
		}
	});
	
	$(function() {
		$('form span.button').SpanButtonSubmitLoading();
		$('form input#submit').SpanButtonSubmitLoading();
		$('form input.submit').SpanButtonSubmitLoading();
	});
	
})(jQuery);(function($) {
	$.widget('ui.DpDialog', {
		overlayEl: $('<div class="ui-DpDialogOverlay"></div>'),
		dialogEl: $('<div class="layout-window ui-DpDialog"><div class="head"><div class="title"><span><span></span></span></div></div><div class="body ui-DpDialogBody"></div><div class="clr"></div></div>'),
		options:  {
			title: '',
			body: '',
			width: 600,
			height: 0
		},
		_init: function() {
			var that = this;
		
			this.overlayEl.css('background-color', '#DDD');
			this.overlayEl.css('opacity', '0.9');
			this.overlayEl.css('position', 'absolute');
			this.overlayEl.css('top', '0');
			this.overlayEl.css('left', '0');
			this.overlayEl.css('height', $(document).height());
			this.overlayEl.css('width', '100%');
			this.overlayEl.css('display', 'none');
			this.overlayEl.css('z-index', '100000');
			this.element.append(that.overlayEl);

			this.dialogEl.css('position', 'absolute');
			this.dialogEl.css('display', 'none');
			this.dialogEl.css('z-index', '100001');
			this.dialogEl.find('.title > span > span').empty().append(this.options.title);
			this.dialogEl.find('.body').empty().append(this.options.body);
			this.element.append(that.dialogEl);
			this.dialogEl.width(this.options.width);
			if (this.options.height) {
				this.dialogEl.height(this.options.height);
			}
			
			this.element.append(this.overlayEl.fadeIn('fast', function(){
				that.element.append(that.dialogEl.center().fadeIn('slow'));
			}));
		},
		close: function() {
			var that = this;
			this.dialogEl.fadeOut(	'fast',
									function(){
										that.overlayEl.fadeOut(	'fast',
																function(){
																	that.overlayEl.remove();
																	that.dialogEl.remove();
																});
									});
		}
	});
	$.DpDialog = {
		open: function(titleEl, contentEl){
			$('body').DpDialog({
				title: titleEl,
				body: contentEl
			});
		},
		close: function(title, contentHtml){
			$('body').DpDialog('close');
		}
	};
})(jQuery);$().ready(function() {
	$('.currentCountryBox').click(function() {
		$('.differentCountryLightbox').fadeOut();
		$('.overlay').fadeOut();
	});
});(function($) {
	$('.teaser-landingGallery .profile').each(function() {
		$(this).click(function() {
			$(".teaser-registration .colContainer").effect("shake", { times: 3 }, 100);
		});
	});
})(jQuery);$().ready(
		function() {
			
			// toggling change mail box
			$('#mailChangeShow').click(function() {
				$('#mailChangeBox').slideToggle(300);
			});

			var pageNo = 2;
			// click on 'mehr..'
			$('.moreProfiles').click(function() {
				$('.parnterSuggestionsLoading').show();
				$('.partnerSuggestions').hide();
				url = 'ajax/user/getPartnerSuggestions/page/' + pageNo;
				pageNo++;
				$.ajax({
					url : url,
					contentType: "text/html; charset=utf-8",
					type: 'POST',
					success : function(respond) {
						if(respond['return'] == 'OK') {
							$('.partnerSuggestions').html(respond['htmlResult']);
							$('.parnterSuggestionsLoading').hide();
							$('.partnerSuggestions').fadeIn();
						} else {
							$.fn.partnerSuggestionsErrorOccurred();
						}				
					},
					error : function() {
						$.fn.partnerSuggestionsErrorOccurred();
					}
				});
							
			});
			
			$.fn.partnerSuggestionsErrorOccurred = function() {
				$('.parnterSuggestionsLoading').hide();
				$('.partnerSuggestions').fadeIn();
			}
			
			// re-sending the confirmation email
			var maximumRequests = 5;
			var requestCounter = 0;
			$('#sendActivationMail').click(function() {
				$('#sendActivationMailBox').slideDown(300);
				$('#sentMailError').hide();
				$('#validationinfo_nothingtochange').hide();
				$('#sentMailSuccess').hide();
				requestCounter++;
				if (requestCounter > maximumRequests) {
					$('#sendActivationMailBox').slideUp(300);
					$('#sendActivationMailContainer').hide();
					$('#sentMailSuccess').hide();
				} else {
					// send email confirmation request
					var url = 'ajax/user/resendActivationEmail';
					$.ajax({
						url : url,
						type: 'POST',
						data : 'email=' + $('#currentEmail').attr("value") + "&customerId=" 
										+ $('#customerId').attr("value") + "&login=" + $('#username').attr("value") + "&Zend=1",
						success : function($respond) {
							if($respond['return'] == "OK") {
								$('#sentMailSuccess').fadeIn();
								$('#sendActivationMailBox').hide();
							} else {
								requestCounter--;
								$.fn.resendEmailErrorOccurred();
							}
						},
						error : function() {
							requestCounter--;
							$.fn.resendEmailErrorOccurred();
						}
					});
				}
			});
			
			$.fn.resendEmailErrorOccurred = function() {
				$('#sentMailError').fadeIn();
				$('#sendActivationMailBox').hide();
			}
			
			// change the confirmation email
			$('#butChangeEmail').click(function() {
				var newEmail = $('#newEmail').attr('value');
				var currentEmail = $('#currentEmail').attr("value");
				$(this).hide();
				$('.divInfo').each(function() {
					$(this).fadeOut();
				});
				
				var isValid = $.fn.validateEmailInput(newEmail,currentEmail);
				if(!isValid) {
					$(this).show();
					return false;
				}
				$('#validationLoader').show();
				
				var url = 'ajax/user/changeRegistrationEmail';
				$.ajax({
					url : url,
					type: 'POST',
					data : 'email=' + $('#currentEmail').attr("value") + "&customerId=" 
									+ $('#customerId').attr("value") + "&login=" + $('#username').attr("value") 
									+ "&newEmail=" + newEmail,
					success : function(respond) {
						$.fn.validateChangeEmailRespond(respond,newEmail);
					},
					error : function() {
						$.fn.changeEmailErrorOccurred();
					}
				});				
			});
			// change email respond
			$.fn.validateChangeEmailRespond = function(respond,newEmail) {
				$('#validationLoader').hide();
				if(respond['return'] == "OK") {
					$('#validationLoader').hide();
					$('#validationinfo_success').fadeIn();
					$('#currentEmail').attr("value",newEmail);
				} else if(respond['return'] == "ERROR") {					
					if(typeof respond['errors'] != 'undefined') {
						$('#validationinfo_errors').html(respond['errors'].join(',<br />'));
						$('#validationinfo_errors').fadeIn();
						$('#butChangeEmail').show();
						$('#validationLoader').hide();
					}
					else {
						$.fn.changeEmailErrorOccurred();
					}
				}
			}
			// undefined error changing the email
			$.fn.changeEmailErrorOccurred = function() {
				$('#butChangeEmail').show();
				$('#validationLoader').hide();
				$('#validationinfo_error').fadeIn();
			}
			
			$.fn.validateEmailInput = function(newEmail, currentEmail) {
				newEmail = $.trim(newEmail);
				currentEmail = $.trim(currentEmail);
				// empty email
				if(newEmail == "") {
					$('#validationinfo_no_email').fadeIn();
					return false;
				}
				// nothing to change
				if(newEmail == currentEmail) {
					$('#validationinfo_nothingtochange').fadeIn();
					return false;
				}
				// validate format
				var validEmailFormat = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(! validEmailFormat.test(newEmail)) {
					$('#validationinfo_invalid_email').fadeIn();
					return false;
				}
				return true;
			}
			
			// button Continue
			$('.continueButtonHolder').click(function() {
				$('.overlayContent').fadeOut();
				$('.overlay').fadeOut();
			});	
			
			$('.activationRenewShow').click(function() {
				$('.activationRenewBox').fadeIn();
			});	
			
			// button: Close Short Profile Lightbox
			$('.closeProfileFormButton').click(function() {
				$('.overlayProfileContent').fadeOut();
				$('.overlay').fadeOut();				
			})
			
			$('#submit').click(function() {
				$(this).hide();
				$('#closeProfileFormButton').hide();
				$('.submit_button_loader').show();
			});
			
			// autocomplete
			$('#myCity').autocomplete
			({
				source: function(request, response) {
					$.ajax({
						url: 'ajax/profileindex/searchcity/',
						data: {
							term: request.term
						},
						type: 'POST',
						dataType: 'json',
						success: function(data) {
							response(data.result);
						}
					});
				},
				minLength: 3
			});
			
		});
$().ready(function() {
	$('.teaser-registration .registerShortRegistrationStep2 > form > span > span > span > input').click(function() {
		$(this).parent().parent().parent().hide();
		$('.submit_button_loader').show();
	});
	
	$('#gender').change(function () {
		if($(this).val() == 'MALE') {
			$('#searchingGender').val('FEMALE');
		}
		if($(this).val() == 'FEMALE') {
			$('#searchingGender').val('MALE');
		}
	});

	
});
$().ready(function() {	
	$('#changeMail').click(function() {
		if(! $('#changeEmailContainer').is(':visible')) {
			$('#changeEmailContainer').append($('#messageBoxChange').html());
		}
		$('#changeEmailContainer').show();
	});
});

