// Put your application scripts here

function validatedFormAjaxSend(){
    //~ console.log('creo oggetto formcheck');
    new FormCheck('form_where',{
        submit: false,
        display : {
            scrollToFirst : true
        },
        onValidateSuccess: function(){
            //~ console.log('Validato!');
            var req = new Request.HTML({
                method: 'post',
                url: 'send_mail',
                evalResponse: false,
                onRequest: function() {
                    $('page2').setStyle('cursor','wait');
                    $('form_where_status').set('html','<h4>invio in corso...</h4>');
                },
                onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
                    $('form_where_status').set('html', '<h4>Mail inviata! Grazie per averci contattati</h4>');
                    $('page2').setStyle('cursor','default');
                },
                onFailure: function(xhr){
                    //console.log('DP');
                }
            }).post($('form_where'))
        }
        
    });
    
    // thacode
    $('name').addEvent('focus', function(){
        if($('name').value =='> Nome Completo') $('name').value = '';
    });
    $('mail').addEvent('focus', function(){
        if($('mail').value =='> Indirizzo Mail') $('mail').value = '';
    });
}


function validatedFormBookingAjaxSend(){
    new FormCheck('form_booking_data',{
        submit: false,
        display : {
            scrollToFirst : true
        },
        onValidateSuccess: function(){
            //~ console.log('Validato!');
            var req = new Request.HTML({
                method: 'post',
                url: 'send_booking',
                evalResponse: false,
                onRequest: function() {
                    $('page2').setStyle('cursor','wait');
                    $('form_booking_status').set('html','<h4>invio in corso...</h4>');
                },
                onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
                    $('form_booking_status').set('html', '<h4>Mail inviata! Grazie per averci contattati</h4>');
                    $('page2').setStyle('cursor','default');
                },
                onFailure: function(xhr){
                    //console.log('DP');
                }
            }).post($('form_booking_data'))
        }
        
    });
    
    // thacode
    $('form_booking_body').addEvent('focus', function(){
        if($('form_booking_body').value =='Specificare, gentilmente, la tipologia di camera desiderata') $('form_booking_body').value = '';
    });
}


function googleMapInitialize(){
    l=46.548056;
    ll=12.451181;
    link='http://maps.google.com/maps?f=d&source=s_d&saddr=46.548056,12.451181&daddr=&hl=it&geocode=&mra=mi&mrsp=0&sz=17&sll=46.548056,12.451181&sspn=0.004264,0.009892&ie=UTF8&t=k&ll=46.548056,12.451181&spn=0.004737,0.006437&z=16'

    if (GBrowserIsCompatible()){
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(l,ll), 13);
        map.setUIToDefault();
        map.setMapType(G_HYBRID_MAP);
        var point = new GLatLng(l,ll);

        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml('<a target="_blank" href="'+link+'">Segui le indicazioni per raggiungerci</a>');
    }
}


