    /*
     * Contact section
     */
          
	var Contact = 
    {    
    	FORM_CONTACT : 'form_contact',
                    
    	selectTable :
        {    
    		routeTopic : function()
    		{
    			var topics = $(Contact.FORM_CONTACT).getInputs('radio', 'topic'); 
            
    			topics.each
    			(
    				function(radio)
    				{
    					if(radio.checked)
    					{
    						switch(radio.value)
    						{
    							case '1' : 
    							{
    								Contact.contactForm.showGeneralInformation();
    								Contact.contactForm.goStep();
    								break;
    							}
    							case '3' : 
                                {
                                	location.replace(CONTACT_LOCATION_2);    
                                	break;
                                }
    							default : 
    							{
    								Contact.contactForm.showForm(radio.value);    
    								Contact.contactForm.goStep();
    							}
    						}
    						
    						return;
    					}
    				}
    			);            
    		}            
        },
    
        contactForm : 
        {
        	_formErrors			: null,
        	ERROR_CLASS			: 'error_field',
        	REQUIRED_CLASS		: 'required',
        	IFRAME_ID			: 'contact_us_iframe',
        	IFRAME_MARGIN_B		: 80,
        	IFRAME_DEFAULT_H	: 1400,
            
        	updateTopic : function(topicValue)
            {
        		$(Contact.FORM_CONTACT)['topic_selected'].value = topicValue;
            },
            
            goStep : function()
            {
            	$('contact_steps_1').style.display = 'none';
            	$('contact_steps_2').style.display = 'block';
            },
            
            autosizeIframe : function(scroll)
            {
        		if(scroll)
        		{
                	goTop();        			
        		}
        		
        		if(document.domain.split('lasikmd.com').length == 2)
        		{
        			document.domain             	= 'lasikmd.com';
        			var renderedDocumentHeight  	= $(Contact.contactForm.IFRAME_ID).contentWindow.document.body.scrollHeight;  
        			var iframeHeight             	= renderedDocumentHeight + Contact.contactForm.IFRAME_MARGIN_B + 'px';
        			
        			try
        			{
        				console.log('Iframe height :');
            			console.log(iframeHeight);
        			} catch(e){}
        			
        			if(document.domain.split('lasikmd.com').length == 2)
    				{
    					if(jQuery.browser.msie)
    					{
    						jQuery('#contact_us_iframe').contents().find('form').attr('autocomplete', 'off');      			        				
    						
    						try
    						{
    							console.log('Autocomplete contact off');
    						}
    						catch(e)
    						{
    								
    						}
    					}
    				}		        			        			
        			
        			$(Contact.contactForm.IFRAME_ID).setStyle({height : iframeHeight});
        			$('content_right_dynamic').setStyle({height : iframeHeight});                            
        		}
        		else
        		{
        			$('content_right_dynamic').setStyle({height : (Contact.contactForm.IFRAME_DEFAULT_H + Contact.contactForm.IFRAME_MARGIN_B) + 'px'});                            
        		}                
            },
            
            showGeneralInformation : function()
            {
            	var iframeSrc     = 'http://forms.lasikmd.com/PatientForm/?lang=' + ((LANG == 'fr') ? 2 : 1) + '&page=3&clinic=' + GUID + '&comp=DC877BC3-497D-DE11-A7CB-000C294BDB24';
                
            	newIframe = new Element('iframe', {frameborder : 0, scrolling : 'no', src : iframeSrc, id : Contact.contactForm.IFRAME_ID}).setStyle({id:'contact_us_iframe', height: Contact.contactForm.IFRAME_DEFAULT_H + 'px', width: '705px', border:'0px #FFF solid', overflow : 'hidden'});                            	
            	
            	newIframe.observe('load', Contact.contactForm.autosizeIframe.curry(true));                                                 
                      
            	new PeriodicalExecuter(Contact.contactForm.autosizeIframe.curry(false), 3); 
            	
				$('content_right_dynamic').setStyle('padding:0px');                
				$('contact_select').style.display = 'none';
				$('contact_select_general_information').insert(newIframe);
				$('contact_select_general_information').style.display = 'block';
            },
            
            showForm : function()
            {
            	$('contact_form').style.display             = 'block';
            	$('contact_select').style.display           = 'none';
            	$('content_right_dynamic').style.height     = 'auto';
                
            	Contact.contactForm._trackingGoogle(2);                
            },
            
            _trackingGoogle : function(showStep)
            {            
            	switch(showStep)
            	{
            		case 2 : 
            		{
            			var trackURL = '?ga_step=2';
            			break;
                    }                
            		default : 
            		{
            			return;    
            		}
            	}
                
            	completeURL = PAGE_TRACK_VIEW_PREFIX + trackURL;
            	pageTracker._trackPageview(completeURL);
            },
            
            submitForm : function()
            {
                Contact.contactForm._formErrors = Array();
                
                $$('#' + Contact.FORM_CONTACT + ' .' + Contact.contactForm.REQUIRED_CLASS).each
                (
                     Contact.contactForm._validateFields
                );                
            
                if($(Contact.FORM_CONTACT).email.value != $(Contact.FORM_CONTACT).email_confirm.value)
                {
                    Contact.contactForm._formErrors.push('email_confirm');    
                    $(Contact.FORM_CONTACT).email_confirm.addClassName(Contact.contactForm.ERROR_CLASS);
                }

                if($(Contact.FORM_CONTACT).email.value.split('@').length != 2 || $(Contact.FORM_CONTACT).email.value.split('.').length < 2)
                {
                    Contact.contactForm._formErrors.push('email_format');    
                    $(Contact.FORM_CONTACT).email.addClassName(Contact.contactForm.ERROR_CLASS);
                }                
            
                Contact.contactForm._submitForm();
            },
        
            _validateFields : function(elementForm)
            {
                var value = '';
                
                if(elementForm.hasClassName('input_form') || elementForm.hasClassName('captcha_form'))
                {
                    var value = elementForm.value;
                }
                else
                {
                    if(elementForm.hasClassName('select_form'))
                    {
                        var value = elementForm.options[elementForm.selectedIndex].innerHTML;    
                    
                        if(elementForm.selectedIndex == 0)
                        {
                            value = '';    
                        }
                    }
                    else
                    {
                        if(elementForm.hasClassName('textarea_form'))
                        {
                            var value = elementForm.value;
                        }
                    }
                }
                
                var suffix = ((Prototype.Browser.IE6) ? '_ie' : '');
                
                if(value == '')
                {
                    Contact.contactForm._formErrors.push(elementForm.name);
                    elementForm.addClassName(Contact.contactForm.ERROR_CLASS + suffix);    
                }
                else
                {
                    elementForm.removeClassName(Contact.contactForm.ERROR_CLASS + suffix);    
                }                            
            },
            
            _submitForm : function()
            {        
                if(Contact.contactForm._formErrors.length == 0)
                { 
                    $(Contact.FORM_CONTACT).request
                    (
                         {   
                            onComplete: function(transport)
                            {                                
                                if (transport.responseText == '')
                                {
                                    Contact.contactSent.showDiv();
                                }
                                else
                                {
                                    var errors = $A(transport.responseText.split(','));

                                    errors.each
                                    (
                                        function(error)
                                        {
                                            switch(error)
                                            {
                                                case 'captcha' : 
                                                {
                                                    $('recaptcha_response_field').addClassName(Contact.contactForm.ERROR_CLASS);
                                                    Recaptcha.reload();
                                                    break;
                                                }
                                                case 'mailer' : 
                                                {
                                                    alert('Mailer ERROR');
                                                }
                                            }
                                        }                                 
                                    );                                                                                                    
                                }
                            } 
                        }
                    )
                }
            },
                            
            phoneInput : function(phoneInput)
            {
                inputsPhone     = phoneInput.parentNode.getElementsByTagName('input');
                var checked     = false;
                var checkbox     = phoneInput.parentNode.parentNode.getElementsByTagName('input')[0];
                
                $A(inputsPhone).each
                (
                    function(inputPhone)
                    {                        
                        if(inputPhone.value != '')
                        {
                            checked = true;
                        }
                    }
                );                                    
            
                checkbox.checked = checked;
            }
        },
    
        contactSent : 
        {
            showDiv : function()
            {
                $('contact_sent').style.display 			= 'block';
                $('contact_form').style.display				= 'none';
                $('contact_select').style.display			= 'none';
                $('content_right_dynamic').style.height		= 'auto';
            }
        },
        
        events : 
        {
            loader : function()
            {                                            
                Contact.events.bind();
                
                $('recaptcha_response_field').addClassName(Contact.contactForm.REQUIRED_CLASS);            
                $('recaptcha_response_field').addClassName('captcha_form');                                
            
    			if(jQuery.browser.msie && parseInt(jQuery.browser.version) >= 9)
    			{
    				jQuery('#contact_form').attr('AUTOCOMPLETE', 'off');
    			}
    			
                $A($(Contact.FORM_CONTACT)['topic']).each
                (
                     function(element)
                    {
                        if(element.checked)
                        {
                            Contact.contactForm.updateTopic(element.value);
                        }
                    }
                );
            
            },
            
            bind : function()
            {            
                /* 
                 * Continue button
                */
                $('contact_continue_button').observe
                (
                    'click',
                    Contact.selectTable.routeTopic        
                );                        

                $('contact_submit').observe
                (
                    'click',
                    Contact.contactForm.submitForm        
                );                                    
            
                $$('.phone_input').each
                (
                     function(currentInput)
                    {
                        currentInput.observe
                        (
                            'keyup',
                            Contact.contactForm.phoneInput.curry(currentInput)        
                        );                                                
                    
                        Contact.contactForm.phoneInput(currentInput);
                    }                
                );
            }                    
        }
    };
    
    Event.observe
    (
        window, 
        'load', 
        Contact.events.loader
    );      


