var init = false;
//var saveDraft = false;
var validate = true;
var formChanged = false;
var changeSection = false;
var formSaved = false;
var autosaveFlag = 'n';
var targetMenu;
var saveButton = false;
var firstSave = false;
var loock
var cancelUnlock = false;
function initList()
{
$('.saved').each(function(){
var list = this;
$(list).parent().find('a[id*=list]').click(function(){
if ($(list).css('display') == 'none'){
$(this).parent().addClass('active');
$(list).slideDown();
} else {
$(this).parent().removeClass('active');
$(list).slideUp();
}
});
});
var id_hash = window.location.hash;
if (id_hash){
$('a#list_'+id_hash.split('#').join('')).click();
}
$('.percent').each(function(){
var value = $(this).text();
$(this).progressBar(value, {
width: 120,
barImage: {
1: 'images/progress/progressbg_red.gif',
30: 'images/progress/progressbg_yellow.gif',
70: 'images/progress/progressbg_green.gif'
},
boxImage: 'images/progress/progressbar.gif'
});
})
}
/*function setSaveDraft()
{
saveDraft = true;
}*/
/*function redirectFrame()
{
//alert('redirect');
window.parent.location.href=window.location.href;
}*/
/**
* Fix change event for radio and checkbox in ie
*/
function ieEventFix()
{
if ($.browser.msie){
$("input[type=radio], input[type=checkbox]").click(function(){
this.blur();
this.focus();
})
}
}
function unloadEvent()
{
Qs_Form.onUnlockQuestionnaire($('form'), function(){
self.close();
});
}
function initIndex(initForm)
{
ieEventFix();
window.onbeforeunload = function(e) {
showQuestionnaireStatus();
e = e || window.event;
var message = "Please make sure to use \"Back\" link or \"Finish\" button to finish \n"
+ "editing current questionnaire correctly and leave this page, otherwise \n"
+ "questionnaire will be locked for a short amount of time to avoid mid-air collisions";
// For IE and Firefox
if (formChanged && e) {
e.returnValue = message;
return message;
}
if (!cancelUnlock){
unloadEvent();
}
}
$('#coda-slider-1').codaSlider({
dynamicArrows: false
});
$('#coda-nav-1').prepend('
Progress
');
targetMenu = jQuery('a.xtrig', jQuery('#navigation'));
var targetNav = jQuery('a.xtrig', jQuery('.panel_inside_nav'));
var targetCodaNav = jQuery('a', jQuery('#coda-nav-1'));
var id_hash = window.location.hash;
targetCodaNav.attr('href', '#');
targetNav.each( function(){
$(this).attr({id: 'nav' + $(this).attr('href').split('#').join('_')});
$(this).attr('href', '#')
})
targetNav.click(function() {
var id_menu = $(this).attr('id').substring(4, $(this).attr('id').length);
if (validate){
Qs_Form.validateSection(parseInt($('#navigation').find('.active').attr('id').replace('menu_', ''))-1, '#menu_' + id_menu, targetMenu);
}
return false;
});
targetMenu.click(function() {
if (validate){
Qs_Form.validateSection(parseInt($('#navigation').find('.active').attr('id').replace('menu_', ''))-1, this, targetMenu);
}
return false;
});
targetCodaNav.click(function() {
var id_menu = $(this).parent('li').attr('class').substring(3, $(this).parent('li').attr('class').length);
if (validate){
Qs_Form.validateSection(parseInt($('#navigation').find('.active').attr('id').replace('menu_', ''))-1, '#menu_' + id_menu, targetMenu);
}
return false;
});
$('#menu_' + id_hash.split('#').join('')).toggleClass('active');
if (id_hash == '') {
$('#menu_1').toggleClass('active');
}
$('.nav_finish').unbind('click').click(
function (){
Qs_Form.onSubmit(document.index_form);
return false;
}
);
jQuery.extend(Qs_Form, FormExtend);
if (initForm){
Qs_Form.init('index-form', Qs_Form.options);
}
$('input, textarea, select').change(function(){
if (formChanged != true && !init){
formChanged = true;
changeSection = true;
showQuestionnaireStatus();
}
});
showQuestionnaireStatus();
initLableClick();
fixPhoneElement();
}
function fixPhoneElement()
{
Qs_Form_Element_PhoneFix.parenFormatReal = Qs_Form_Element_Phone.formatReal;
$.extend(Qs_Form_Element_Phone, Qs_Form_Element_PhoneFix);
}
/**
* Fix change event for phone element
*/
var Qs_Form_Element_PhoneFix = {
parenFormatReal: null,
formatReal: function ()
{
if (this.parenFormatReal) {
this.parenFormatReal();
$(this.element).change();
}
}
}
function onBlurElements()
{
$('input, textarea, select').blur();
}
function initLableClick()
{
$("div[id*='-element']").children('.optional, .required').css('cursor', 'pointer').click(function(){
$(this).parent().find("[name*='field_']:first").putCursorAtEnd();
});
}
function setFormSaved()
{
formSaved = true;
}
function lockQuestionnaire()
{
if ($('#action').val() == 'update'){
lockQuestionnaireRequest(true);
setInterval(function(){
lockQuestionnaireRequest();
}, 300000);
}
}
function lockQuestionnaireRequest(firstLock)
{
var options = {
url: $('#index-form').attr('action'),
type: 'POST',
dataType: 'json',
data: {
action: 'lockQuestionnaire',
id: $('#id').val(),
firstLock: (firstLock?firstLock:false)
},
success: function (data) {
if (!data.success){
cancelUnlock = true;
//window.parent.location.href = BASE_URL;
}
}
}
$.ajax(options);
}
function verifyQuestionnairesLock(questionnairesId)
{
verifyQuestionnairesRequest(questionnairesId);
setInterval(function(){
verifyQuestionnairesRequest(questionnairesId);
}, 100000);
}
function verifyQuestionnairesRequest(questionnairesId)
{
var options = {
url: $('#index_form').attr('action'),
type: 'POST',
dataType: 'json',
data: {
action: 'verifyQuestionnairesLock',
'questionnaires[]': questionnairesId
},
success: function (data)
{
if (data){
for (var key in data){
var link = $('#' + key + '_percent').parent().children('a:first');
var delLink = $('#' + key + '_percent').parent().children('a:last');
var printLink = $('#' + key + '_print');
if (data[key] == true){
link.click(function(){
return false;
});
if (!link.next('.locked').size()){
link.after(' This questionnaire is locked, because it\'s editing by another user now.');
}
delLink.hide();
printLink.hide();
} else {
link.unbind('click').next('.locked').remove();
delLink.show();
printLink.show();
}
}
}
}
}
$.ajax(options);
}
function showQuestionnaireStatus()
{
var status = '';
if (autosaveFlag == false && formChanged && !formSaved){
status = ' Questionnaire is not yet saved';
} else if (!formSaved){
status = ' Questionnaire is not complete';
} else if (formSaved && formChanged){
status = ' Questionnaire has been modified'
} else if (!formChanged && formSaved && !firstSave){
status = '';
} else if (formSaved){
status = ' Questionnaire has been saved';
$('.nav_finish').css('display', '');
} else {
status = ' N/A';
}
$('.questionnaire_status').remove();
if (status == ''){
return false;
}
var activeSection = parseInt($('#navigation').find('a.active').attr('id').replace('menu_', '')) - 1;
var statusHtml = '