/*

        Bild und Text Modal
        Autor: Carsten Meyer
        HMMH AG 2010

        Usage: new AjaxModal('demo.jpg','<b>Impact</b>').show();

*/

var helpLayerTimeout = '';

var lightBoxSiPa = new Class({

           initialize: function(text,options){
           
                    this.text = text;

										this.options = options;

                    this.center = new Element('div',{
                    
                            id: 'modalForeground',
                            styles:{
                            
                                 'position':'absolute',
                                 'z-index':1010,
                                 'width': '100%',
                                 'top': $(document.body).getScroll().y + 20 + 'px',
								 'height': $(document.body).getSize().y + 'px',
																 'left': '0px'
                            }
                    
                    });

                    this.div = new Element('div',{
                        styles: {
                          'background-color':'#ffffff',
                          'margin': '0px auto',
                          'opacity':0
                        }
                    });

                    this.close = new Element('a',{

                        html: 'Fenster schlie&szlig;en',
                        href: 'javascript:void(0)',
                        styles:{

                              'position': 'absolute',
                              'right': '20px',
                              'top': '10px'

                        }

                    });

					this.content = new Element('div',{'class':'lightboxSiPa'});
          
           },
           show: function(){

						this.content.set('html',this.text);
                        this.div.setStyles({
                          
                              'height': this.options.height + 'px', // wieder einkommentiert.Die Höhe 320 auskommentiert.
							  // 'height': '320px',
                              'width': this.options.width + 'px',
                              'position': 'relative',
							  'overflow': 'hidden'

                          });
													
													if(this.options.closeButton) {
														this.close.inject(this.div);
														this.close.set('class','modalclose');
														this.content.setStyle('margin-top','45px');
													}

                          this.div.grab(this.content);
                          this.div.inject(this.center);
                          this.center.inject($(document.body));
                          
                          this.div.fade('in');
                          this.center.pin();

													if(this.options.closeButton) {
														this.close.addEvent('click',function(){

																	 $('modalOverlay').fade('out');
																	 this.div.get('tween', {property: 'opacity', duration: 'long',onComplete:function(){

																				this.center.destroy();
																				$('modalOverlay').destroy();

																	 }.bind(this)}).start(1,0);


														}.bind(this));
													}
                          this.modalShow({
                    
                              modalStyle:{
                                'background-color':'#000000',
                                'opacity':0.3,
                                'position':'absolute',
                                'z-index':1000
                              }
                            });
														
										this.initEvents();
                          
           },

					 connectRadioButtons : function (event) {

						 $('paket1pc').checked = $('lsip1').checked;
						 $('paket3pc').checked = $('lsip3').checked;

							if( $('paket1pc').checked  || $('paket3pc').checked ) {
								$('lbWithSip').onclick = function() {
									$('tarife').submit();
								};
								$('lbWithNoSip').onclick = function(){return false;};
								$('lbWithNoSip').addClassName('noFunc');
								$('lbWithSip').removeClassName('noFunc');

							} else {
								$('lbWithSip').onclick = function(){return false;};
								$('lbWithNoSip').onclick = function() {
									$('tarife').submit();
								};
								$('lbWithSip').addClassName('noFunc');
								$('lbWithNoSip').removeClassName('noFunc');
							}
					 },

					 initEvents : function() {

						var _self = this;

							$('lbWithNoSip').onclick = function() {
								checkFormFieldsAndSend();
							};


						 $(document.body).getElements('div.lightboxSiPa input').each(function(obj,nr){
							obj.addEvent('click', function (event) {
									var checker = false;
									if (event.target.id == 'lsip1') {
										 $('paket1pc').checked = true;
										 $('paket3pc').checked = false;
									}
									else {
										if (event.target.id == 'lsip3') {
											$('paket1pc').checked = false;
											$('paket3pc').checked = true;
										}
										else {
											$('paket1pc').checked = false;
											$('paket3pc').checked = false;
										}
									}

									if( $('paket1pc').checked  || $('paket3pc').checked ) {
										$('lbWithSip').onclick = function() {
											checkFormFieldsAndSend();
										};
										$('lbWithNoSip').onclick = function(){return false;};
										$('lbWithNoSip').addClass('noFunc');
										$('lbWithSip').removeClass('noFunc');

									} else {

										$('lbWithSip').onclick = function(){return false;};
										$('lbWithNoSip').onclick = function() {
											checkFormFieldsAndSend();
										};
										$('lbWithSip').addClass('noFunc');
										$('lbWithNoSip').removeClass('noFunc');
									}

								});
						 });
					 }

}).implement(new Modalizer);

/*
* Positioniert die Hilfetexte anhand der Event-Position
*/
function showHelp(elm, divId) {

 var positionFixId = divId + "Master";
 document.getElementById(divId).style.display='block';
 var x = document.getElementById(positionFixId).offsetLeft + 15;
 var y = document.getElementById(positionFixId).offsetTop - 50;
 document.getElementById(divId).style.left = x + "px";
 document.getElementById(divId).style.top = y + "px";

}

function showHelpCancelTimeout(divId) {
 window.clearTimeout(helpLayerTimeout);
}

function closeDivAfterTimeout(divId) {

	try {
	 document.getElementById(divId).style.display='none';
	}
	catch(e) {}
	
	return false;
}

function closeHelp(divId) {
 var methodStr = "closeDivAfterTimeout('"+divId+"')";

 helpLayerTimeout = window.setTimeout(methodStr, 200);
}

/*
 *  uebearbeitet die Formularfelder onSubmit des Formulars
 */
function checkFormFieldsAndSend () {


	/* aus den Formular Values den Preis entfernen und nur die ID für die OB uebertragen*/
	var formFields = $('tarife').getElements('input[type=checkbox],input[type=radio],select');

	formFields.each(function(obj,nr) {

		try {
			var valueParts = obj.get('value').split('|');
			obj.set('value',valueParts[1]);
		}
		catch(e) {}

	});

	/* ggfs Bandbreitenerweiterung in formularfeld DSL uebertragen*/
	try {
			if ($('tarife').getElement('[name=dsldummy]:checked').get('value') > 0) {
				$('tarife').getElement('[name=dsl]').set('value',$('tarife').getElement('[name=dsldummy]:checked').get('value'));
			}
	} catch(e) {}


	$('tarife').submit();

 }
