'+
arrow + title +
'
' + showHtml +'
'+
'
';
// state buttons may be in object or array, lets convert objects to arrays
if($.isArray(stateobj.buttons)){
buttons = stateobj.buttons;
}
else if($.isPlainObject(stateobj.buttons)){
for(k in stateobj.buttons){
if(stateobj.buttons.hasOwnProperty(k)){
buttons.push({ title: k, value: stateobj.buttons[k] });
}
}
}
// iterate over each button and create them
for(i=0, l=buttons.length; i' + v.title + '';
}
state += '
';
$state = $(state).css({display:'none'});
$state.on('impromptu:submit', stateobj.submit);
if(afterState !== undefined){
t.getState(afterState).after($state);
}
else{
$jqistates.append($state);
}
t.options.states[statename] = stateobj;
return $state;
},
/**
* removeState - Removes a state from the prompt
* @param state String - Name of the state
* @param newState String - Name of the state to transition to
* @return Boolean - returns true on success, false on failure
*/
removeState: function(state, newState) {
var t = this,
$state = t.getState(state),
rm = function(){ $state.remove(); };
if($state.length === 0){
return false;
}
// transition away from it before deleting
if($state.css('display') !== 'none'){
if(newState !== undefined && t.getState(newState).length > 0){
t.goToState(newState, false, rm);
}
else if($state.next().length > 0){
t.nextState(rm);
}
else if($state.prev().length > 0){
t.prevState(rm);
}
else{
t.close();
}
}
else{
$state.slideUp('slow', rm);
}
return true;
},
/**
* getApi - Get the api, so you can extract it from $.prompt stack
* @return jQuery - the prompt
*/
getApi: function() {
return this;
},
/**
* getBox - Get the box containing fade and prompt
* @return jQuery - the prompt
*/
getBox: function() {
return this.jqib;
},
/**
* getPrompt - Get the prompt
* @return jQuery - the prompt
*/
getPrompt: function() {
return this.jqi;
},
/**
* getState - Get the state by its name
* @param statename String - Name of the state
* @return jQuery - the state
*/
getState: function(statename) {
return this.jqi.find('[data-jqi-name="'+ statename +'"]');
},
/**
* getCurrentState - Get the current visible state
* @return jQuery - the current visible state
*/
getCurrentState: function() {
return this.getState(this.getCurrentStateName());
},
/**
* getCurrentStateName - Get the name of the current visible state/substate
* @return String - the current visible state's name
*/
getCurrentStateName: function() {
return this.currentStateName;
},
/**
* disableStateButtons - Disables the buttons in a state
* @param statename String - Name of the state containing buttons
* @param buttons Array - Array of button values to disable. By default all are disabled
* @param enable Boolean - True to enable the buttons instead of disabling (internally use only)
* @return Void
*/
disableStateButtons: function(statename, buttons, enable) {
var t = this;
if($.isArray(statename)){
buttons = statename;
statename = null;
}
t.getState(statename || t.getCurrentStateName()).find('.'+ t.options.prefix + 'button').each(function(i,btn){
if(buttons === undefined || $.inArray(btn.value, buttons) !== -1){
btn.disabled = !enable;
}
});
},
/**
* enableStateButtons - Enables the buttons in a state
* @param statename String - Name of the state containing buttons. Defaults to current state
* @param buttons Array - Array of button values to enable. By default all are enabled
* @return Void
*/
enableStateButtons: function(statename, buttons) {
this.disableStateButtons(statename, buttons, true);
},
/**
* position - Repositions the prompt (Used internally)
* @return void
*/
position: function(e){
var t = this,
restoreFx = $.fx.off,
$state = t.getCurrentState(),
stateObj = t.options.states[$state.data('jqi-name')],
pos = stateObj ? $.isFunction(stateObj.position) ? stateObj.position() : stateObj.position : undefined,
$window = $(window),
bodyHeight = document.body.scrollHeight, //$(document.body).outerHeight(true),
windowHeight = $(window).height(),
documentHeight = $(document).height(),
height = (bodyHeight > windowHeight) ? bodyHeight : windowHeight,
scrollTop = parseInt($window.scrollTop(),10),
top = scrollTop + (t.options.top.toString().indexOf('%') >= 0?
(windowHeight*(parseInt(t.options.top,10)/100)) : parseInt(t.options.top,10));
// when resizing the window turn off animation
if(e !== undefined && e.data.animate === false){
$.fx.off = true;
}
t.jqib.css({
position: "absolute",
height: height,
width: "100%",
top: 0,
left: 0,
right: 0,
bottom: 0
});
t.jqif.css({
position: "fixed",
height: height,
width: "100%",
top: 0,
left: 0,
right: 0,
bottom: 0
});
// tour positioning
if(pos && pos.container){
var offset = $(pos.container).offset(),
hasScrolled = false;
if($.isPlainObject(offset) && offset.top !== undefined){
top = (offset.top + pos.y) - (t.options.top.toString().indexOf('%') >= 0? (windowHeight*(parseInt(t.options.top,10)/100)) : parseInt(t.options.top,10));
t.jqi.css({
position: "absolute"
});
t.jqi.animate({
top: offset.top + pos.y,
left: offset.left + pos.x,
marginLeft: 0,
width: (pos.width !== undefined)? pos.width : null
}, function(){
// if it didn't scroll before, check that the bottom is within view. Since width
// is animated we must use the callback before we know the height
if(!hasScrolled && (offset.top + pos.y + t.jqi.outerHeight(true)) > (scrollTop + windowHeight)){
$('html,body').animate({ scrollTop: top }, 'slow', 'swing', function(){});
hasScrolled = true;
}
});
// scroll if the top is out of the viewing area
if(top < scrollTop || top > scrollTop + windowHeight){
$('html,body').animate({ scrollTop: top }, 'slow', 'swing', function(){});
hasScrolled = true;
}
}
}
// custom state width animation
else if(pos && pos.width){
t.jqi.css({
position: "absolute",
left: '50%'
});
t.jqi.animate({
top: pos.y || top,
left: pos.x || '50%',
marginLeft: ((pos.width/2)*-1),
width: pos.width
});
}
// standard prompt positioning
else{
t.jqi.css({
position: "absolute",
top: top,
left: '50%',//$window.width()/2,
marginLeft: ((t.jqi.outerWidth(false)/2)*-1)
});
}
// restore fx settings
if(e !== undefined && e.data.animate === false){
$.fx.off = restoreFx;
}
},
/**
* style - Restyles the prompt (Used internally)
* @return void
*/
style: function(){
var t = this;
t.jqif.css({
zIndex: t.options.zIndex,
display: "none",
opacity: t.options.opacity
});
t.jqi.css({
zIndex: t.options.zIndex+1,
display: "none"
});
t.jqib.css({
zIndex: t.options.zIndex
});
},
/**
* goToState - Goto the specified state
* @param state String - name of the state to transition to
* @param subState Boolean - true to be a sub state within the currently open state
* @param callback Function - called when the transition is complete
* @return jQuery - the newly active state
*/
goToState: function(state, subState, callback) {
var t = this,
$jqi = t.jqi,
jqiopts = t.options,
$state = t.getState(state),
stateobj = jqiopts.states[$state.data('jqi-name')],
promptstatechanginge = new $.Event('impromptu:statechanging'),
opts = t.options;
if(stateobj !== undefined){
if (typeof stateobj.html === 'function') {
var contentLaterFunc = stateobj.html;
$state.find('.' + opts.prefix +'message ').html(contentLaterFunc());
}
// subState can be ommitted
if(typeof subState === 'function'){
callback = subState;
subState = false;
}
t.jqib.trigger(promptstatechanginge, [t.getCurrentStateName(), state]);
if(!promptstatechanginge.isDefaultPrevented() && $state.length > 0){
t.jqi.find('.'+ opts.prefix +'parentstate').removeClass(opts.prefix +'parentstate');
if(subState){ // hide any open substates
// get rid of any substates
t.jqi.find('.'+ opts.prefix +'substate').not($state)
.slideUp(jqiopts.promptspeed)
.removeClass('.'+ opts.prefix +'substate')
.find('.'+ opts.prefix +'arrow').hide();
// add parent state class so it can be visible, but blocked
t.jqi.find('.'+ opts.prefix +'state:visible').addClass(opts.prefix +'parentstate');
// add substate class so we know it will be smaller
$state.addClass(opts.prefix +'substate');
}
else{ // hide any open states
t.jqi.find('.'+ opts.prefix +'state').not($state)
.slideUp(jqiopts.promptspeed)
.find('.'+ opts.prefix +'arrow').hide();
}
t.currentStateName = stateobj.name;
$state.slideDown(jqiopts.promptspeed,function(){
var $t = $(this);
t.enableStateButtons();
// if focus is a selector, find it, else its button index
if(typeof(stateobj.focus) === 'string'){
$t.find(stateobj.focus).eq(0).focus();
}
else{
$t.find('.'+ opts.prefix +'defaultbutton').focus();
}
$t.find('.'+ opts.prefix +'arrow').show(jqiopts.promptspeed);
if (typeof callback === 'function'){
t.jqib.on('impromptu:statechanged', callback);
}
t.jqib.trigger('impromptu:statechanged', [state]);
if (typeof callback === 'function'){
t.jqib.off('impromptu:statechanged', callback);
}
});
if(!subState){
t.position();
}
} // end isDefaultPrevented()
}// end stateobj !== undefined
return $state;
},
/**
* nextState - Transition to the next state
* @param callback Function - called when the transition is complete
* @return jQuery - the newly active state
*/
nextState: function(callback) {
var t = this,
$next = t.getCurrentState().next();
if($next.length > 0){
t.goToState( $next.data('jqi-name'), callback );
}
return $next;
},
/**
* prevState - Transition to the previous state
* @param callback Function - called when the transition is complete
* @return jQuery - the newly active state
*/
prevState: function(callback) {
var t = this,
$prev = t.getCurrentState().prev();
if($prev.length > 0){
t.goToState( $prev.data('jqi-name'), callback );
}
return $prev;
}
};
// ########################################################################
// $.prompt will manage a queue of Impromptu instances
// ########################################################################
/**
* $.prompt create a new Impromptu instance and push it on the stack of instances
* @param message String/Object - String of html or Object of states
* @param options Object - Options to set the prompt
* @return jQuery - the jQuery object of the prompt within the modal
*/
$.prompt = function(message, options){
var api = new Imp(message, options);
return api.jqi;
};
/**
* Copy over static methods
*/
$.each(Imp, function(k,v){
$.prompt[k] = v;
});
/**
* Create a proxy for accessing all instance methods. The close method pops from queue.
*/
$.each(Imp.prototype, function(k,v){
$.prompt[k] = function(){
var api = Imp.getLast(); // always use the last instance on the stack
if(api && typeof api[k] === "function"){
return api[k].apply(api, arguments);
}
};
});
// ########################################################################
// jQuery Plugin and public access
// ########################################################################
/**
* Enable using $('.selector').prompt({});
* This will grab the html within the prompt as the prompt message
*/
$.fn.prompt = function(options){
if(options === undefined){
options = {};
}
if(options.withDataAndEvents === undefined){
options.withDataAndEvents = false;
}
$.prompt($(this).clone(options.withDataAndEvents).html(),options);
};
/**
* Export it as Impromptu and $.prompt
* Can be used from here forth as new Impromptu(states, opts)
*/
window.Impromptu = Imp;
}));
var cont = function() {};
cont.init = function () {
jQuery('#divModelo').css('display', 'none');
jQuery('#divAno').css('display', 'none');
jQuery('#divVersao').css('display', 'none');
//jQuery('#divKm').css('display', 'none');
//jQuery('#dadosPessoais').css('display', 'none');
jQuery('#next').css('display', 'none');
jQuery('#previous').css('display', 'none');
}
cont.init();
cont.selMarca = function (codMarca) {
jQuery('#divModelo').css('display', 'none');
jQuery('#divAno').css('display', 'none');
jQuery('#divVersao').css('display', 'none');
//jQuery('#divKm').css('display', 'none');
//jQuery('#dadosPessoais').css('display', 'none');
if (codMarca != "selecione a marca") {
cfe.cfejs_cfe_up('divModelo', 'compro', 'divModelo', 'codMarca=' + codMarca, 0);
}
}
cont.selModelo = function (modelo) {
jQuery('#divAno').css('display', 'none');
jQuery('#divVersao').css('display', 'none');
//jQuery('#divKm').css('display', 'none');
//jQuery('#dadosPessoais').css('display', 'none');
if (modelo != "selecione o modelo") {
cfe.cfejs_cfe_up('divAno', 'compro', 'divAno', 'modelo=' + modelo, 0);
}
}
cont.selAno = function (ano) {
jQuery('#divVersao').css('display', 'none');
//jQuery('#divKm').css('display', 'none');
//jQuery('#dadosPessoais').css('display', 'none');
var modelo = jQuery('select#modelo').val();
if (ano != "selecione o ano") {
cfe.cfejs_cfe_up('divVersao', 'compro', 'divVersao', 'ano=' + ano + '&modelo=' + modelo, 0);
}
}
cont.selVersao = function (versao) {
if (versao != "none") {
//jQuery('#divKm').css('display', 'block');
//jQuery('#dadosPessoais').css('display', 'none');
cfe.prompt('O modelo do seu carro é