

//Shortcut Functions.
function closeError(){(new Dialog).hideMessage()}
function closeSuccess(){ myDialog.hide() }
//Show Slide Function
function showSlide(objectID,overlay,overlayColor,Height,Width){
	//-> CHANGE BY EVA 10/22/08
	//var pageName = '/slides/'+objectID+'.php';
	var pageName = objectID;
	var options={
				overlay:overlay,
				maskColor:overlayColor,
				height:Height,
				width:Width
				}
				//
				myDialog.getForm(pageName,options)
				
				
	}


var Dialog = new Class({
				Implements: Options,
				options: {
					overlay: true,
					maskColor: '#000000',
					backgroundColor: '#ffffff',
					width: 400,
					height: 'auto',
					onComplete: Class.empty,
					onStart: Class.empty,
					id:'dialog_content'
					
				},   
				initialize: function(newOptions){
					this.setOptions(newOptions)      
					this.defaults=this.options;    
				
				},
				
				
				
				
				getForm: function(url,options){
					this.setOptions(this.defaults)
					this.setOptions(options);
						this.request = new Request({
													method: 'get',
													url: url,
													onRequest: function(){},
													onComplete:function(a){
														var myForm=new Element('div',{id:'myForm'}).inject(document.body).set('html',a);
														this.root.show(myForm);
														var loader = new Element('span',{className:'ajax-loader'}).setStyle('visibility','hidden').inject(myForm);
														$('busyicon').setStyle('display','none');
														setTimeout(jqueryFormAjaxInit,100);
														$$('#myForm form').addEvent('submit',function(){
															$$('span.ajax-loader').setStyle('visibility','visible');
														});
														window.scrollTo(0,0);
														$$('#myForm a.popuplink').addEvent('click', function(){
															bindPopups(this);
															return false;
														});
									/*var myForm=new Element('form',
								{id:'myForm','method':'get','action':'/s/send.php'}).inject(document.body).set('html',a)
								
								
									
									
									
									this.root.show(myForm)
									
									
									$('myForm').addEvent('submit', function(e) {
																				
											//Cancel submit event
											new Event(e).stop();
											this.set('send', {
														 url: '/s/send.php', 
														 method: 'get',
														 onComplete:function(a,b){(new Dialog).message('myForm',a)}});

												this.send();
												
												
												
												
											});	*/
									
									
														
														}
					});
							this.request.root=this
							this.request.send();
					},
				
				get:	function(url,options){
					this.setOptions(this.defaults)
					this.setOptions(options);
					this.request = new Request({
													method: 'get',
													url: url,
													onRequest: function(){},
													onComplete:function(a){
													
														this.root.show(a)
														
														}
					});
							this.request.root=this
							this.request.send();
							
					
					
					
					},
				
				showElement:function(id,options){this.options=this.defaults;this.setOptions(options);this.show($(id))},
				showHTML:function(html,options){this.options=this.defaults;this.setOptions(options);this.show(html)},
				show: function(el) {
					
								
					switch ($type(el)) {
						case 'element':
								this.el = new Element('div',
														  {'class':this.options.className,'styles':{'padding':10,'width':this.options.width,'height':this.options.height}})
								el.inject(this.el)
							break;
						case 'string':
							this.el = new Element('div',
												  {'class':this.options.className,'styles':{'padding':10,'width':this.options.width,'height':this.options.height}}).set('html',el);
							
							break;
						default:
							return false;
							break;
					}
				
					//Clear previous instance
						if($('dialog_pop')){$('dialog_pop').dispose()}
						if($('pop_overlay')){$('pop_overlay').dispose()}
						if($('msgbox_content')){$('msgbox_content').dispose()}

					
					// create elements: mask, pop, message and close
					this.mask = new Element('div',{'id':'pop_overlay','styles':{
						'position':'absolute',
						'top':0,
						'left':0,
						'opacity':0,
						'height': (window.getHeight() > window.getScrollHeight())?window.getHeight():window.getScrollHeight(),
						'width':'100%',
						'background':this.options.maskColor,
						'z-index':9999
					}});
					
				
					this.pop = new Element('div',{ id:'dialog_pop','class':'dialog_pop','styles':{
						'position':'absolute',
						'visibility':'hidden',
						'opacity':0,	
						'width':this.options.width+"px",
						'left':this.options.width*-1, //Start outside
						'z-index':10000
					}});
					this.message = new Element('div',{'styles':{
						'margin':'0 auto'
					}});
					this.message.id='dialog_content';
					this.close = new Element('span',{'styles':{
						'display':'block',
						'text-align':'right',
						'color':'#ffffff',
						'padding':3,
						'cursor':'pointer'
					//-> CHANGE BY EVA 10/22/08
					//}}).set('text','close');
					}}).set('text','x');

					// add events to close the dialog box
					this.close.addEvent('click',this.hide.bind(this));
					this.mask.addEvent('click',this.hide.bind(this));
					// in case there are objects in our message,
					// we hide objects BEFORE we add the message to the dom
					$$('object','select').setStyle('visibility','hidden');

					// add elements to the DOM
					if (this.options.overlay){document.body.appendChild(this.mask)};
					document.body.appendChild(this.pop);
					this.close.inject(this.el,'inside')
					this.el.inject(this.message,'inside');
					this.message.inject(this.pop,'inside');
					this.message.setStyle('width',this.el.getCoordinates().width);

					
					
							//Align  top//center 
							
					if (this.options.top && this.options.left)
					{
							var top=this.options.top
							var left=this.options.left
					}
					else
					{
							//-> CHANGE BY EVA 10/22/08
							//var top=((window.getHeight()-this.pop.getCoordinates().height)/2) +window.getScrollTop();
							//var left=(window.getWidth()-this.options.width)/2
							var top=110; 
							var left=(((window.innerWidth)?window.innerWidth:document.body.clientWidth)/2)-273;
						
						}
					
					
					
					this.pop.setStyles({
						//'top': window.getScrollTop() - this.pop.getCoordinates().height,
						//top: top-30,
//						left:left-30
						top: top,
						left:left
						
					
					});

					// start the animation
					this.fade = new Fx.Tween(this.mask);
					this.slide = new Fx.Tween(this.pop);
					this.slide2 = new Fx.Tween(this.pop);
					this.slide3 = new Fx.Tween(this.pop);

				
					
				
					//-> CHANGE BY EVA 10/22/08
					//this.fade.start('opacity',0.8);
					this.fade.start('opacity',0.4);	
					this.slide.start('top',top);
					this.slide2.start('left',left);
					this.slide3.start('opacity',1);
			
				},
				update: function() {
					this.slide.start(window.getScrollTop()+30);
					var h = (window.getHeight() > window.getScrollHeight())?window.getHeight():window.getScrollHeight();
					this.mask.setStyle('height',h);
				},	
				hide: function() {
					$$('object','select').setStyle('visibility','visible');
					$clear(this.periodical);
					this.fade.start('opacity',0);
					this.slide.start('opacity',0).chain(function(){
						this.pop.dispose();
						this.mask.dispose();
						$$('body').setStyle('overflow','auto');
						this.hideMessage();
					}.bind(this));
				},
				hideMessage: function(){
					
					$$('.dialog_pop_content').removeClass('errorWin');
					if($('msgbox_content')==null){return};
					var el=$('msgbox_content')
					var fade = new Fx.Tween(el);
					fade.start('opacity',0);
					el.dispose()
					//Put back the overlay under.
					if($('pop_overlay')){
						$('pop_overlay').setStyle('z-index',10000)
						$('pop_overlay').removeEvents('click');
						$('pop_overlay').addEvent('click',function(){myDialog.hide();});
						}
					
					},
				message:	function(id,content,options){
					
						//Put back the overlay on top of form and remove the event.
						$('pop_overlay').setStyle('z-index',10001)
						$('pop_overlay').removeEvents('click');
						$('pop_overlay').addEvent('click',function(){myDialog.hideMessage();});
					
					
						$$('.dialog_pop_content').addClass('errorWin');
						
						
						
						var w=$(id).getCoordinates().width
						var h=$(id).getCoordinates().height 
						
						var t=$(id).getCoordinates().top
						var l=$(id).getCoordinates().left
					
						
						
						this.el = new Element('div',{id:'msgbox_content','class':'msgbox_content', 'opacity':0, 'styles':
															{'background-color':'#FFFFFF',
																'position':'absolute', 'z-index':10002,
																//-> CHANGE BY EVA 10/22/08
																//'top':t+20,'left':l+5,'width':w-10
																'top':t+4,'left':l+0,'width':w-20
															}
															}).set('html',content);
						this.fade = new Fx.Tween(this.el);
						document.body.appendChild(this.el)
						this.fade.start('opacity',1)
						
						//Success delete all 
						if($('pop_message_sucess')){
							$('pop_overlay').removeEvents('click');
							$('pop_overlay').addEvent('click',function(){myDialog.hide();});
							}
						
					
					
					}
			});






//Prepare default page popup options
	var popOptions={
			width:270,	 //Number only   
			height:'auto', // number or 'auto'
			//-> CHANGE BY EVA 10/22/08
			'maskColor':'#000000',
			'className':'dialog_pop_content'
			}
	// Create a instance of the popup
	var myDialog = new Dialog(popOptions);


function jqueryFormAjaxInit(){
	try {
		if (typeof _wpcf7 == 'undefined' || _wpcf7 === null)
			_wpcf7 = {};
	
		_wpcf7 = jQuery.extend({ cached: 0 }, _wpcf7);
	
		jQuery('div.wpcf7 > form').ajaxForm({
			beforeSubmit: function(formData, jqForm, options) {
				jqForm.wpcf7ClearResponseOutput();
				jqForm.find('img.ajax-loader').css({ visibility: 'visible' });
				return true;
			},
			beforeSerialize: function(jqForm, options) {
				jqForm.find('.wpcf7-use-title-as-watermark.watermark').each(function(i, n) {
					jQuery(n).val('');
				});
				return true;
			},
			data: { '_wpcf7_is_ajax_call': 1 },
			dataType: 'json',
			success: function(data) {
				var ro = jQuery(data.into).find('div.wpcf7-response-output');
				jQuery(data.into).wpcf7ClearResponseOutput();
	
				if (data.invalids) {
					jQuery.each(data.invalids, function(i, n) {
						jQuery(data.into).find(n.into).wpcf7NotValidTip(n.message);
					});
					ro.addClass('wpcf7-validation-errors');
				}
	
				if (data.captcha)
					jQuery(data.into).wpcf7RefillCaptcha(data.captcha);
	
				if (data.quiz)
					jQuery(data.into).wpcf7RefillQuiz(data.quiz);
	
				if (1 == data.spam)
					ro.addClass('wpcf7-spam-blocked');
	
				if (1 == data.mailSent) {
					jQuery(data.into).find('form').resetForm().clearForm();
					ro.addClass('wpcf7-mail-sent-ok');
	
					if (data.onSentOk)
						jQuery.each(data.onSentOk, function(i, n) { eval(n) });
				} else {
					ro.addClass('wpcf7-mail-sent-ng');
				}
	
				if (data.onSubmit)
					jQuery.each(data.onSubmit, function(i, n) { eval(n) });
	
				jQuery(data.into).find('.wpcf7-use-title-as-watermark.watermark').each(function(i, n) {
					jQuery(n).val(jQuery(n).attr('title'));
				});
	
				ro.append(data.message).slideDown('fast');
			}
		});
	
		jQuery('div.wpcf7 > form').each(function(i, n) {
			if (_wpcf7.cached)
				jQuery(n).wpcf7OnloadRefill();
	
			jQuery(n).wpcf7ToggleSubmit();
	
			jQuery(n).find('.wpcf7-acceptance').click(function() {
				jQuery(n).wpcf7ToggleSubmit();
			});
	
			jQuery(n).find('.wpcf7-exclusive-checkbox').each(function(i, n) {
				jQuery(n).find('input:checkbox').click(function() {
					jQuery(n).find('input:checkbox').not(this).removeAttr('checked');
				});
			});
	
			jQuery(n).find('.wpcf7-use-title-as-watermark').each(function(i, n) {
				var input = jQuery(n);
				input.val(input.attr('title'));
				input.addClass('watermark');
	
				input.focus(function() {
					if (jQuery(this).hasClass('watermark'))
						jQuery(this).val('').removeClass('watermark');
				});
	
				input.blur(function() {
					if ('' == jQuery(this).val())
						jQuery(this).val(jQuery(this).attr('title')).addClass('watermark');
				});
			});
		});
	
	} catch (e) {
	}
}

		
