var helper = {
	addEvent: function(obj, type, fn, capture) {
		var r;

		if ( obj.addEventListener ) {
				obj.addEventListener(type, fn, capture);
				return true;
		} else if ( obj.attachEvent ) {
				r = obj.attachEvent('on' + type, fn);
				return r;
		} else {
				obj['on' + type] = fn;
		}
	},

	cssjs: function(action, obj, c1, c2) {

		switch ( action.toLowerCase() ) {
		case 'add':

			if ( !helper.cssjs('check', obj, c1) ) {
				obj.className += obj.className ? ' ' + c1 : c1;
			}
			break;

		case 'check':
			return new RegExp('(^|\\s)' + c1 + '(\\s|$)').test(obj.className);

		case 'remove':
			var rep = obj.className.match(' ' + c1) ? ' ' + c1 : c1;
			obj.className = obj.className.replace(rep, '');
			break;

		case 'swap':
			obj.className = !helper.cssjs('check', obj, c1) ? obj.className.replace(c2, c1) : obj.className.replace(c1, c2);
			break;
		}
	},

	debug: null,

	debugAdd: function(bug) {
		var item;

		if ( !helper.debug ) {
			helper.debugBegin();
		}

		item = document.createElement('li');
		item.innerHTML = bug;
		helper.debug.appendChild(item);
	},

	debugBegin: function() {

		if ( helper.debug ) {
			helper.debugEnd();
		}

		helper.debug = document.createElement('ul');
		helper.debug.setAttribute('id', helper.debugWindowId);
		document.body.insertBefore(helper.debug, document.body.firstChild);
	},

	debugEnd: function() {

		if ( helper.debug ) {
			helper.debug.parentNode.removeChild(helper.debug);
			helper.debug = null;
		}
	},

	debugWindowId: 'helper-debug'
};

function RemoveAccountAlert() {
    var strMessage="Are you sure you wish to remove your account? This will permanently delete all user information that relates to your account."
    if (confirm(strMessage)) 
        return true;
    else
        return false;
}

function CancelAlert(strActivity) 
{
    if (confirm("Are you sure you want to Cancel " + strActivity + "?")) //'You will lose all the unsaved data.Do you want to proceed?
            return true;
        else
            return false;
}

function DeleteAlert(strActivity) {
    if (confirm("Are you sure you want to Delete " + strActivity + "?")) //'You will lose all the unsaved data.Do you want to proceed?
        return true;
    else
        return false;
}


function SnoozeAlert(strActivity, completed, total) {
    alert("You have completed " + completed + " of " + total + " " + strActivity + " Questionnaire choices till " + DateNow() + " " + TimeNow());
}


function DateNow()
{
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    curr_month++;
    var curr_year = d.getFullYear();    
    return curr_month + "/" + curr_date + "/" + curr_year;
}

function TimeNow() {
    var a_p = "";
    var d = new Date();
    var curr_hour = d.getHours();
    if (curr_hour < 12) {
        a_p = "AM";
    }
    else {
        a_p = "PM";
    }
    if (curr_hour == 0) {
        curr_hour = 12;
    }
    if (curr_hour > 12) {
        curr_hour = curr_hour - 12;
    }

    var curr_min = d.getMinutes();

    curr_min = curr_min + "";

    if (curr_min.length == 1) {
        curr_min = "0" + curr_min;
    }

    return curr_hour + " : " + curr_min + " " + a_p;

}

