$(document).ready(function() {
	var olclicktocontinue = '<div id="ol_continue">click here to continue</div>';
// Block UI Styling.
$.blockUI.defaults = {
    // styles for the message when blocking; if you wish to disable
    // these and use an external stylesheet then do this in your code:
    // $.blockUI.defaults.css = {};
    css: {
        padding:        '20px 20px 20px 20px',
        margin:         0,
        width:          '30%',
        top:            '20%',
        left:           '35%',
        textAlign:      'center',
        color:          '#fff',
        backgroundColor:'#444',
        cursor:         'default',
        //'font-size': 'normal',        
        '-webkit-border-radius': '10px',
        '-moz-border-radius':    '10px'
    },
    overlayCSS:  {
        backgroundColor:'#fff',
        opacity:        '0.8'
    },
    baseZ: 1000,
    centerX: true,
    centerY: true,
    allowBodyStretch: true,
    constrainTabKey: true,
    fadeIn:  50,
    fadeOut:  300,
    timeout: 0,
    showOverlay: true,
    focusInput: true,
    applyPlatformOpacityRules: true,
    onUnblock: null,
    quirksmodeOffsetHack: 4
};

	function miniErrors(targetDiv, theMessage) {
			var targetWidth = '70%';
			var continueType = olclicktocontinue;
            var msgId = theMessage.error_code;
            var msg = theMessage.error;
            if(msg == undefined)
            {
                msg = theMessage;
            }
            if(msgId == 'ERROR_NOT_LOGGED_IN')
            {
                $(targetDiv).block({css: {color: '#f42c52', width:targetWidth },message:msg+'<div id="sessionTimeOut">click here to continue</div>'});
            }
            else
            {
    			if (targetDiv == 'div#register_box'){
			        continueType = clicktocontinue;		
			    }
			    $(targetDiv).block({css: {color: '#f42c52', width:targetWidth },message:msg+continueType});
            }
		}
	
	var SendSample = 'http://mpoll.me/RegisterUserBeta/REST/?&_forcenohttperror=true&output=jsoncallback&callback=?';
	function sampleRequest(formData, jqForm, options) {
                        $('form#sample_req').block({message:"<img src=\"imgs/loader_small.gif\" alt=\"loading...\" /><h4>Sending demo!<br/></h4>"});
        }
            
    function processSampleRequest(data) { //determines what to display when user is logging in.
                if (data.error){
                    $('form#sample_req').unblock();
                    $('form#sample_req').block({css: {color: '#f42c52'},message: data.error+olclicktocontinue});
                    return false;
                } else {
                    $('form#sample_req').unblock();
                    $('form#sample_req').block({css: {color: '#25c058'},message:"Check your mobile for our SMS!"+olclicktocontinue});
                }
            }

	var SampleRequestOptions = { 
                    url:  SendSample, //API URL
                	dataType:  'jsonp',
                    success:   processSampleRequest,
                    beforeSubmit:  sampleRequest
                }; 
                
	var sf = $('form#sample_req').validate({
                    submitHandler: function(form) {
                        $(form).ajaxSubmit(SampleRequestOptions);
                    }
                });
    $('div#ol_continue').live('click', function(){
		    $($(this).parent().parent()).unblock();
            Recaptcha.reload();
	})
	
	/**QTIPS**/
	$('#styling_marker').qtip({
               content: {text: 'You can create an MPoll using your logo and style, and any colours you choose.'},
               position: {
                  corner: {
                     tooltip: 'bottomLeft',
                     target: 'topRight'
                  }
               },
               show: { delay: 0 },
               hide: { delay: 0 },
               style: {
                  border: {
                     width: 1,
                     radius: 3
                  },
                  tip: true,
                  name: 'green'
               }
            });
	$('#title_marker').qtip({
               content: {text: 'Each MPoll has a customisable title, so your company can make use of multiple surveys.'},
               position: {
                  corner: {
                     tooltip: 'bottomLeft',
                     target: 'topRight'
                  }
               },
               show: { delay: 0 },
               hide: { delay: 0 },
               style: {
                  border: {
                     width: 1,
                     radius: 3
                  },
                  tip: true,
                  name: 'green'
               }
            });
	$('#content_marker').qtip({
               content: {text: 'Create any number of multiple-choice questions. Each answer is collected with a single click from the customer, making MPolls simple to use.'},
               position: {
                  corner: {
                     tooltip: 'bottomLeft',
                     target: 'topRight'
                  }
               },
               show: { delay: 0 },
               hide: { delay: 0 },
               style: {
                  border: {
                     width: 1,
                     radius: 3
                  },
                  tip: true,
                  name: 'green'
               }
            });    

	$('#phone_marker').qtip({
               content: {text: 'MPolls work on any type of mobile handset, not just smartphones. Polls are delivered by text message and customers respond with just a few clicks. It\'s that easy!'},
               position: {
                  corner: {
                     tooltip: 'bottomLeft',
                     target: 'topRight'
                  }
               },
               show: { delay: 0 },
               hide: { delay: 0 },
               style: {
                  border: {
                     width: 1,
                     radius: 3
                  },
                  tip: true,
                  name: 'green'
               }
            });                
});
