﻿/*
 * LETZTE AENDERUNGEN VON EVENTIM:
 *		2009-08-13 18:30	In der Funktion popupwindow() settings um den Parameter "name" erweitert, um individuelle
 *							Namen per Profile vergeben zu koennen (hans-peter.beck@eventim.de).
 *
 * Copyright 2008-2009 by CTS Eventim AG.
 */
/*
Popupwindow plugin for jQuery.
by: Tony Petruzzi
homepage: http://rip747.wordpress.com
plugin download: http://rip747.wordpress.com/2007/03/02/the-return-of-popupwindow-jquery-plugin/

*/

jQuery.fn.popupwindow = function(p)
{

	var profiles = p || {};

	return this.each(function(index){
		var settings, parameters, mysettings, b, a, winObj;
		
		// for overrideing the default settings
		mysettings = (jQuery(this).attr("rel") || "").split(",");

		
		settings = {
			height:600, // sets the height in pixels of the window.
			width:568, // sets the width in pixels of the window.
			toolbar:0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
			scrollbars:1, // 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)}.
			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			left:0, // left position when the window appears.
			top:0, // top position when the window appears.
			center:1, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
			createnew:1, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
			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)}.
			onUnload:null // function to call when the window is closed
		};

		// if mysettings length is 1 and not a value pair then assume it is a profile declaration
		// and see if the profile settings exists

		if(mysettings.length == 1 && mysettings[0].split(":").length == 1)
		{
			a = mysettings[0];
			// see if a profile has been defined
			if(typeof profiles[a] != "undefined")
			{
				settings = jQuery.extend(settings, profiles[a]);
			}
		}
		else
		{
			// overrides the settings with parameter passed in using the rel tag.
			for(var i=0; i < mysettings.length; i++)
			{
				b = mysettings[i].split(":");
				if(typeof settings[b[0]] != "undefined" && b.length == 2)
				{
					settings[b[0]] = b[1];
				}
			}
		}

		// center the window
		if (settings.center == 1)
		{
			settings.top = (screen.height-(settings.height + 110))/2;
			settings.left = (screen.width-settings.width)/2;
		}
		
		parameters = "location=" + settings.location + ",menubar=" + settings.menubar + ",height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
		
		jQuery(this).bind("click", function(){
			var name = settings.createnew ? "PopUpWindow" + index : "PopUpWindow";
			winObj = window.open(this.href, name, parameters);
			
			if (settings.onUnload) {
				// Incremental check for window status
				// Attaching directly to window.onunlaod event causes invoke when document within window is reloaded
				// (i.e. an inner refresh)
				unloadInterval = setInterval(function() {
					if (!winObj || winObj.closed) {
						clearInterval(unloadInterval);	
						settings.onUnload.call($(this));
					}
				},500);
			}
			
			winObj.focus();
			
			return false;
		});
	});

};

var profiles =
{
	general:
	{
		height:600,
		width:575,
		center:1,
		status:0,
		scrollbars:1
	},
	small:
	{
		height:400,
		width:575,
		center:1,
		status:0,
		scrollbars:1
	},	
	smallHeight:
	{
		height:175,
		width:575,
		center:1,
		status:0,
		scrollbars:1
	},	
	tellAFriend:
	{
		height:645,
		width:509
	},
	
	forgotPassword:
	{
		height:400,
		width:400
	},
	contactData:
	{
		height:400,
		width:400
	},

	window800:
	{
		height:800,
		width:800,
		status:1
	},

	helpContactWindow:
	{
		height:600,
		width:750,
		status:1
	},

	window600:
	{
		height:600,
		width:600,
		status:1
	},

	window500:
	{
		height:500,
		width:500,
		status:1
	},
	
	window400:
	{
		height:400,
		width:400,
		status:1
	},

	window200:
	{
		height:200,
		width:200,
		status:1,
		resizable:0
	},

	windowCenter:
	{
		height:300,
		width:400,
		center:1
	},
	
	windowNotNew:
	{
		height:300,
		width:400,
		center:1,
		createnew:0
	},
	
	fanReportConditions:
	{
		height:600,
		width:525,
		scrollbars:1
	},
	
	fanReportExample:
	{
		height:550,
		width:750,
		scrollbars:1
	},
	
	lotteryConditions:
	{
		height:450,
		width:500,
		scrollbars:1
	},
	
	tellAFriend :
	{
		
		height:660,
		width:600,
		center:1,
		scrollbars:1
	},
	
	onlineFeedbackStep1 :
	{
		
		height:240,
		width:600,
		center:1,
		scrollbars:1
	},
	
	window1024x600 :
	{
		
		height:600,
		width:1024,
		center:1
	},
	
	windowNoStatus : 
	{
		
		height:600,
		width:600,
		center:1,
		status:0,
		scrollbars:1
	},
	
	seatingChart : 
	{
		
		height:642,
		width:817,
		center:1,
		status:0,
		scrollbars:1,
		resizable:0,
		location:0,
		menubar:0,
		name:'Saalplan'
	},
	
	windowFWWCpw : 
	{
		
		height:250,
		width:638,
		center:1,
		status:0,
		scrollbars:1
	},

	windowFWWC1 : 
	{
		
		height:495,
		width:638,
		center:1,
		status:0,
		scrollbars:1
	},

	windowFWWC : 
	{
		
		height:550,
		width:750,
		center:1,
		status:0,
		scrollbars:1
	},
	
		window800 : 
	{
		
		height:600,
		width:850,
		center:1
	}
	
};


jQuery(function() {
				
	jQuery(".popupwindow").popupwindow(profiles);
});
