﻿function initUI(fDom) {
	if (fDom == undefined || fDom == '') {
		fDom = '';
	} else {
		fDom = fDom + ' ';
	}

	updateButtons(fDom);

	jQuery(fDom+'.input-select').each(function () {
		fVal = jQuery(this).attr('selected');
		if (fVal != '') {
			jQuery(this).val(fVal);
		}
	});

	jQuery(fDom + '.input-radio').each(function () {
		fVal = jQuery(this).attr('selected');
		fValue = jQuery(this).attr('value');

		if (fVal != undefined) {
			if (fVal.toUpperCase() == fValue.toUpperCase()) {
				jQuery(this).attr('checked', 'true');
			} else {
				jQuery(this).attr('checked', 'false');
			}
		}
	});

	jQuery(fDom + '.input-time').each(function () {
		jQuery(this).css({
			'width': 90,
			'text-align': 'right'
		});
		jQuery(this).timeEntry();
		jQuery(this).removeClass('input-time');
	});

	jQuery(fDom + '.input-phone').mask('(999) 999-9999', {placeholder: ' '});

	jQuery(fDom + '.champ-header').addClass('ui-toolbar ui-widget-header ui-helper-clearfix ui-corner-all').css('padding', '5px').removeClass('champ-header');
	jQuery(fDom + '.input-date').datepicker({
		'onSelect': function () {
			$(this).trigger('change');
		}
	});

	ui(fDom);


	jQuery(fDom+'img').each(function () {
		fSrc = jQuery(this).attr('src');
		if (fSrc == '') {
			jQuery(this).attr('src', '/net/images/spacer.gif');
		}
	});

	initHelper();
	initColorInputs(fDom);

	initAccordions(fDom);
	initTabs(fDom);

	jQuery(fDom + '#name').select();
	try {
		top.disableLoader();
	} catch (e) {
	}

}

jQuery(function () {
    if (window.autoUI == undefined) {
        initUI('');

        try {
            pageInit();
        } catch (e) {
        }

        try {
            init();
        } catch (e) {
        }

        try {
            initUploader();
        } catch (e) {
        }

        fSPID = request("SPID")
        if (fSPID == undefined) {
            fSPID = 'nospid';
        }
        fID = request("LINKID")
        if (fID == undefined) {
            fID = 0;
        }

        if (document.getElementById('appInitDescription-' + fSPID + fID)) {
            fFunc = eval(jQuery('#appInitDescription-' + fSPID + fID).html());
            fFunc(fID, fSPID);
        }

        fBoxCNT = 0
        tryInits();



        try {
            top.disableLoader();
        } catch (e) {
        }


        setupErrorHandler();
    }
});

function tryInits() {
	try {
		initWebPage();
	} catch (e) {
	}

	try {
		initCK();
	} catch (e) {
	}

	try {
		//initUploaders();
	} catch (e) {
	}
}

function updateButtons(fDom) {
	if (fDom == undefined) {
		fDom = '';
	} else {
		fDom = fDom + ' ';
	}

	jQuery(fDom+'input:submit:not(\'.input-plain\'), '+fDom+'input:button:not(\'.input-plain\')').each(function () {
		if (!jQuery(this).hasClass('disable-ui')) {
			jQuery(this).button();
		}
	});

	jQuery(fDom + 'input:submit:not(\'.input-plain\'), '+fDom+'input:button:not(\'.input-plain\')').css('font-size', '12px');

	fInputs = fDom + 'input:text:not(\'.input-plain\'), ' + fDom + 'textarea:not(\'.input-plain\'), ' + fDom + 'select:not(\'.input-plain\'), ' + fDom + 'input:password:not(\'.input-plain\')';
	jQuery(fInputs).addClass('input border shadow');
	jQuery(fDom+'textarea').addClass('input-textarea');
	jQuery(fDom + '.inputDate').datepicker({
		'onSelect': function () {
			jQuery(this).trigger('onchange');
		}
	});

	fButtonTypes = 'To,New,Save,Delete,Create,Edit,Open,Close,Settings,View,Restore,Sync,Mail,Reset,Picture,Upload,Sign In,More,Search,Find,Match,List,Categorize,Back,Completed,Post,Help,Download,Write,Reply,Archive,Attach';
	fButtonIcons = 'contact,circle-plus,circle-check,circle-minus,circle-plus,gear,pencil,circle-close,gear,circle-zoomin,arrowreturnthick-1-w,transferthick-e-w,mail-closed,arrowreturnthick-1-w,person,circle-arrow-n,locked,circle-arrow-s,search,search,star,carat-2-n-s,bookmark,circle-arrow-w,circle-check,pin-s,help,arrowthickstop-1-s,pencil,arrowreturnthick-1-w,clock,tag';

	fButtonTypes = fButtonTypes.split(',');
	fButtonIcons = fButtonIcons.split(',');
	fDefaultIcon = 'circle-arrow-e';

	jQuery(fDom + 'button:not(\'.input-plain\')').each(function () {
		transformButton(this);
	});

	jQuery(fDom + '.buttonset').buttonset();
	//jQuery(fDom + '.buttonset button, '+fDom+'.buttonset input').removeClass('shadow');
}

function transformButton(fObj) {
	fButtonTypes = 'To,New,Save,Delete,Create,Edit,Open,Close,Settings,View,Restore,Sync,Mail,Reset,Picture,Upload,Sign In,More,Search,Find,Match,List,Categorize,Back,Completed,Post,Help,Download,Write,Reply,Archive,Attach';
	fButtonIcons = 'contact,circle-plus,circle-check,circle-minus,circle-plus,gear,pencil,circle-close,gear,circle-zoomin,arrowreturnthick-1-w,transferthick-e-w,mail-closed,arrowreturnthick-1-w,person,circle-arrow-n,locked,circle-arrow-s,search,search,star,carat-2-n-s,bookmark,circle-arrow-w,circle-check,pin-s,help,arrowthickstop-1-s,pencil,arrowreturnthick-1-w,clock,tag';

	fButtonTypes = fButtonTypes.split(',');
	fButtonIcons = fButtonIcons.split(',');
	fDefaultIcon = 'circle-arrow-e';

	fVal = jQuery(fObj).html();
	fVal = fVal.toUpperCase();
	fIcon = fDefaultIcon;
	for (i = 0; i < fButtonTypes.length; i++) {
		fThisType = fButtonTypes[i].toUpperCase();
		fPos = fVal.indexOf(fThisType);
		if (fPos > -1) {
			fIcon = fButtonIcons[i];
		}
	}

	jQuery(fObj).button({
		icons: {
			primary: 'ui-icon-' + fIcon
		}
	});

	//jQuery(fObj).addClass('shadow');
}

function btnTempLabel(fBtnID, fLabel) {
	fOrigLabel = jQuery(fBtnID).button('option', 'label');
	setBtnLabel(fBtnID, fLabel);

	setTimeout('setBtnLabel("' + fBtnID + '", "' + fOrigLabel + '")', 500);
}

function setBtnLabel(fBtnID, fLabel) {
	jQuery(fBtnID).button('option', 'label', fLabel);
}

function getAttr(fObj, fAttr, fDefault) {
	fData = fObj.attr(fAttr);
	if (fData == undefined || fData == '') {
		fData = fDefault;
	}

	if (fData == 'true' || fData == 'yes') {
		fData = true;
	}

	if (fData == 'false' || fData == 'no') {
		fData = false;
	}

	return fData;
}

window.initAccordions = function(fDom) {
	if (fDom == undefined || fDom == '') {
		fDom = '';
	} else {
		fDom = fDom + ' ';
	}

	jQuery(fDom+'.accordion').each(function () {
		jQuery(this).accordion({
			header: "h3",
			autoHeight: getAttr(jQuery(this), 'autoheight', false),
			fillSpace: getAttr(jQuery(this), 'fillspace', false),
			collapsible: getAttr(jQuery(this), 'collapsible', true),
			animated: "bounceslide",
			icons: {
				'header': 'ui-icon-circle-arrow-e',
				'headerSelected': 'ui-icon-circle-arrow-s'
			}
		});

		jQuery(this).removeClass('accordion');
	});
}


function initTabs(fDom) {
	if (fDom == undefined) {
		fDom = '';
	}

	fDom = fDom + ' .tabs';

	fDefaultConfig = {
		'collapsible': false,
		'cache': true,
		'spinner': '&nbsp;<img src="/net/images/loading-blue.gif" />&nbsp;',
		'load': function (event, ui) {
			jQuery(event.target).find('li.ui-state-active > a > span').html('');
			try {
				tabLoadCallback(event, ui);
			} catch (e) {
			}
		},
		'show': function (event, ui) {
			try {
				tabSelectCallback(event, ui);
			} catch (e) {
			}
		}

	};

	jQuery(fDom).tabs(fDefaultConfig);
}

function genericUploadHandler(fResponse) {
	fArray = fResponse.split('|');
	fField = fArray[0];
	fIsSrc = fArray[1];
	fData = fArray[2];
	
	if (fIsSrc == '0') {
		jQuery('#'+fField).html(fData);
	} else {
		jQuery('#'+fField).attr('src', fData);
	}

	return true;
}

function replace(origString, inChar, outChar) {
	var newString = origString.split(inChar);
	newString = newString.join(outChar);
	return newString;
}

function replaceLast(origString, inChar, outChar) {
	newString = '';
	var fArray = origString.split(inChar);
	for (i=0; i<fArray.length; i++) {
		newString += fArray[i]
		if (i<fArray.length-2) {
			newString += inChar;
		}
	}
	return newString;
}

function getRandomNumber(fMax) {
	return Math.floor(Math.random()*(fMax+1))
}

function initHTMLEditors() {
	jQuery('.input-html').each(function(i) {
		fID = jQuery(this).attr('id');
		jQuery('#'+fID).ckeditor(
			function() {
				CKFinder.SetupCKEditor(this);
			}
		);
	});
}

function initHelper() {
	fHelper = jQuery('#helper').detach();
	fHelper.appendTo('body');
	
	jQuery('#helper').dialog({
		autoOpen: false,
		title: 'Help &amp; Tips',
		width: 700,
		buttons: {
			"Ok": function() { 
				jQuery(this).dialog("close"); 
			}
		}
	});
	
	fHelper = jQuery('#helperEditor').detach();
	fHelper.appendTo('body');

	jQuery('#helperEditor').dialog({
		autoOpen: false,
		title: 'Helper Editor',
		width: 700,
		buttons: {
			"Cancel": function() { 
				jQuery(this).dialog("close"); 
			},
			"Save Changes": function() {
				helperUpdate();
			}
		}
	});
	
}

function openHelper() {
	jQuery('#helper').dialog('open');
}

function helperUpdate() {
	fArray = jQuery('#helperEditorForm').serializeArray();
	$.post(window.link+'&spid=helper.update', fArray, function(data) {
		if (data == 'OK') {
			jQuery('#helperEditor').dialog('close');
		} else {
			alert('Error Updating:\n'+data);
		}
	});
}

function editHelper() {
	jQuery('#helperEditor').dialog('open');
}

function initColorInputs(fDom) {
	if (fDom == undefined || fDom == '') {
		fDom = '';
	} else {
		fDom = fDom + ' ';
	}

	jQuery('.input-color').each(function() {
		fVal = jQuery(this).val();
		fVal = fVal.toLowerCase();
		jQuery(this).val(fVal);
		
		jQuery(this).ColorPicker({
			'color': fVal,
			'onChange': function() {
				jQuery(this).css({
					'background-color': jQuery(this).val()
				})
			}
		});
	});
}

function isIOS() {
	fStatus = false;
	if ($.browser.webkit) {
		fIpad = navigator.userAgent.indexOf('iPad');
		fIphone = navigator.userAgent.indexOf('iPhone');
		if (fIpad > -1 || fIphone > -1) {
			fStatus = true;
		}
	}
	
	return fStatus;
}

function handleIncompatibleIE() {
	jQuery('body').append('<div id="warningIncompatibleBrowser"><h1>Wow, your browser is really old!</h1><div>You are using a browser version that may cause this web page to crash or produce unexpected results.</div><div>Please consider <a href="http://www.microsoft.com/ie" target="_blank">upgrading it</a> or using <a href="http://www.firefox.com" target="_blank">Firefox</a> or <a href="http://www.apple.com/safari" target="_blank">Safari</a>.</div><div><br><input type="button" onclick="jQuery(\'#warningIncompatibleBrowser\').fadeOut(300)" value="Close"></div>');
	jQuery('#warningIncompatibleBrowser').fadeIn(300);
}

function request(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    fResult = 1;

    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            fResult = ft[1];
        }
    }

    return fResult;
}

function ui(fDom) {
	if (fDom == undefined || fDom == '') {
		fDom = '';
	} else {
		fDom = fDom + ' ';
	}

	jQuery(fDom + '.itembox').each(function (i) {
		fBoxCNT = i + 100;
		fName = jQuery(this).attr('name');
		fID = 'itembox_' + fBoxCNT;
		jQuery(this).attr('id', fID);
		boxify(fID, fName);
		fBoxCNT++;
		jQuery(this).removeClass('itembox');
	});

	jQuery(fDom + '.ajax-button').each(function () {
        transformButton(this);
        jQuery(this).removeClass('ajax-button');
    });

       jQuery(fDom + '.ajax-input').each(function () {
        jQuery(this).addClass('border');
        jQuery(this).addClass('shadow');
        jQuery(this).css({
            'padding': '5px'
        });
        jQuery(this).removeClass('ajax-input');
    });

       jQuery(fDom + '.ajax-textarea').each(function () {
        jQuery(this).addClass('border');
        jQuery(this).addClass('shadow');
        jQuery(this).css({
            'padding': '5px'
        });
        jQuery(this).removeClass('ajax-textarea');
    });

       jQuery(fDom + '.ajax-select').each(function () {
        jQuery(this).addClass('border');
        jQuery(this).addClass('shadow');
        jQuery(this).css({
            'padding': '5px',
            'width': 'auto'
        });
        jQuery(this).removeClass('ajax-select');
       });

	try {
		initDataTables(fDom);
	} catch (exception) {
		//
	}
}

function viewJSON(json) {
    for (var key in json) {
        if (json.hasOwnProperty(key)) {
            console.log(key + " -> " + json[key]);
        }
    }
}
function jsTrace(fFunction, fURL, fID, fText) {
	fMsg = 'Function: '+fFunction+'\nURL: '+fURL+'\nID: '+fID+'\nText: '+fText;
   	alert(fMsg);
}

function stringExists(fData, fString) {
	fThisData = fData.toUpperCase();
	fThisString = fString.toUpperCase();

	fPos = fThisData.indexOf(fThisString);
	if (fPos > -1) {
		return true;
	} else {
		return false;
	}
}

function setupErrorHandler() {
/*
	jQuery(document).ajaxError(function (event, jqxhr, settings, exception) {
		$.post('/net/remote/error/?action=notify', {
			'BODY': '<h1>jQuery Ajax Error in Script</h1>Page: ' + location.href + '<br>Ajax URL: '+settings.url + '<br>STATUS: ' + event.status + '<br>xhr RESPONSE: '+jqxhr.responseText
		}, function (data) {
		});
		return true;
	});
*/
}

function boxify(fDomID, fTitle, fStyleID, fWidth, fHeight, fBGColor) {
	fObj = $('#' + fDomID);
	if (fWidth == undefined) {
		fWidth = fObj.parent().offsetWidth;
		if (fWidth == '' || fWidth == undefined) {
			fWidth = fObj.parent().width();
		}
	}
	fWidth = fWidth - 15;
	fInnerWidth = fWidth - 10;
	fHeight = fObj.height() + 20;

	if (fTitle == undefined) {
		fTitle = fObj.attr('name');
	}

	fData = '<div id="boxify-' + fDomID + '" class="ui-dialog ui-widget ui-widget-content ui-corner-all" style="position: static; width: ' + fWidth + 'px; margin-top: 5px; margin-bottom: 5px; margin-left: 5px; margin-right: 5px"><div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" style="min-height: 20px"><span id="ui-dialog-title-dialog" class="ui-dialog-title">' + fTitle + '</span></div><div style="height: auto; width: ' + fInnerWidth + 'px; " class="ui-dialog-content ui-widget-content"></div></div>';
	$(fData).insertBefore(fObj);
	fDialogObj = $('#boxify-' + fDomID);
	fDialogObj.find('.ui-dialog-content').append(fObj);

	if (fTitle == '') {
		/*
		fDialogObj.find('.ui-dialog-titlebar').css({
			'visibility': 'hidden',
			'height': 1
		});
		*/
		fDialogObj.find('.ui-dialog-titlebar').remove();
	}
}

function tracerAction(fAction) {
	switch (fAction) {
		case 'activate':
			window.tracerStatus = true;
			$('body').append('<div id="tracerbox" style="position: fixed; width: 300px; height: 300px; border: 1px solid #cccccc; padding: 7px; top: 5px; left: 5px; overflow: auto; background-color: #FFFFFF; "></div>');
			break;
	}
}

function trace(fMsg) {
	try {
		console.log(fMsg);
	} catch (e) {
	}
}

function ie() {
	fObj = IEVersion();
	return fObj['DocMode'];
}


function IEVersion(){
	var _n=navigator,_w=window,_d=document;
	var version="NA";
	var na=_n.userAgent;
	var ieDocMode="NA";
	var ie8BrowserMode="NA";
	// Look for msie and make sure its not opera in disguise
	if(/msie/i.test(na) && (!_w.opera)){
		// also check for spoofers by checking known IE objects
		if(_w.attachEvent && _w.ActiveXObject){		
			// Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7
			version = (na.match( /.+ie\s([\d.]+)/i ) || [])[1];
			// Its IE 8 pretending to be IE 7 or in compat mode		
			if(parseInt(version)==7){				
				// documentMode is only supported in IE 8 so we know if its here its really IE 8
				if(_d.documentMode){
					version = 8; //reset? change if you need to
					// IE in Compat mode will mention Trident in the useragent
					if(/trident\/\d/i.test(na)){
						ie8BrowserMode = "Compat Mode";
					// if it doesn't then its running in IE 7 mode
					}else{
						ie8BrowserMode = "IE 7 Mode";
					}
				}
			}else if(parseInt(version)==8){
				// IE 8 will always have documentMode available
				if(_d.documentMode){ ie8BrowserMode = "IE 8 Mode";}
			}
			// If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions			
			ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode=="CSS1Compat") ? 7 : 5;//default to quirks mode IE5				   			
		}
	}
				 
	return {
		"UserAgent" : na,
		"Version" : version,
		"BrowserMode" : ie8BrowserMode,
		"DocMode": ieDocMode
	}
}

function sChanges(fFormID, fURL) {
    $('#processor').show();
    fArray = $('#' + fFormID).serializeArray();
    $.post(fURL, fArray, function (data) {
        $('#processor').hide();
    });

}

/* Time Entry - jquery.timeentry.min.js */
/* http://keith-wood.name/timeEntry.html
Time entry for jQuery v1.4.8.
Written by Keith Wood (kbwood{at}iinet.com.au) June 2007.
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 
Please attribute the author if you use it. */
(function ($) { function TimeEntry() { this._disabledInputs = []; this.regional = []; this.regional[''] = { show24Hours: false, separator: ':', ampmPrefix: '', ampmNames: ['AM', 'PM'], spinnerTexts: ['Now', 'Previous field', 'Next field', 'Increment', 'Decrement'] }; this._defaults = { appendText: '', showSeconds: false, timeSteps: [1, 1, 1], initialField: 0, useMouseWheel: true, defaultTime: null, minTime: null, maxTime: null, spinnerImage: 'spinnerDefault.png', spinnerSize: [20, 20, 8], spinnerBigImage: '', spinnerBigSize: [40, 40, 16], spinnerIncDecOnly: false, spinnerRepeat: [500, 250], beforeShow: null, beforeSetTime: null }; $.extend(this._defaults, this.regional['']) } var m = 'timeEntry'; $.extend(TimeEntry.prototype, { markerClassName: 'hasTimeEntry', setDefaults: function (a) { extendRemove(this._defaults, a || {}); return this }, _connectTimeEntry: function (b, c) { var d = $(b); if (d.hasClass(this.markerClassName)) { return } var e = {}; e.options = $.extend({}, c); e._selectedHour = 0; e._selectedMinute = 0; e._selectedSecond = 0; e._field = 0; e.input = $(b); $.data(b, m, e); var f = this._get(e, 'spinnerImage'); var g = this._get(e, 'spinnerText'); var h = this._get(e, 'spinnerSize'); var i = this._get(e, 'appendText'); var j = (!f ? null : $('<span class="timeEntry_control" style="display: inline-block; ' + 'background: url(\'' + f + '\') 0 0 no-repeat; ' + 'width: ' + h[0] + 'px; height: ' + h[1] + 'px;' + ($.browser.mozilla && $.browser.version < '1.9' ? ' padding-left: ' + h[0] + 'px; padding-bottom: ' + (h[1] - 18) + 'px;' : '') + '"></span>')); d.wrap('<span class="timeEntry_wrap"></span>').after(i ? '<span class="timeEntry_append">' + i + '</span>' : '').after(j || ''); d.addClass(this.markerClassName).bind('focus.timeEntry', this._doFocus).bind('blur.timeEntry', this._doBlur).bind('click.timeEntry', this._doClick).bind('keydown.timeEntry', this._doKeyDown).bind('keypress.timeEntry', this._doKeyPress); if ($.browser.mozilla) { d.bind('input.timeEntry', function (a) { $.timeEntry._parseTime(e) }) } if ($.browser.msie) { d.bind('paste.timeEntry', function (a) { setTimeout(function () { $.timeEntry._parseTime(e) }, 1) }) } if (this._get(e, 'useMouseWheel') && $.fn.mousewheel) { d.mousewheel(this._doMouseWheel) } if (j) { j.mousedown(this._handleSpinner).mouseup(this._endSpinner).mouseover(this._expandSpinner).mouseout(this._endSpinner).mousemove(this._describeSpinner) } }, _enableTimeEntry: function (a) { this._enableDisable(a, false) }, _disableTimeEntry: function (a) { this._enableDisable(a, true) }, _enableDisable: function (b, c) { var d = $.data(b, m); if (!d) { return } b.disabled = c; if (b.nextSibling && b.nextSibling.nodeName.toLowerCase() == 'span') { $.timeEntry._changeSpinner(d, b.nextSibling, (c ? 5 : -1)) } $.timeEntry._disabledInputs = $.map($.timeEntry._disabledInputs, function (a) { return (a == b ? null : a) }); if (c) { $.timeEntry._disabledInputs.push(b) } }, _isDisabledTimeEntry: function (a) { return $.inArray(a, this._disabledInputs) > -1 }, _changeTimeEntry: function (a, b, c) { var d = $.data(a, m); if (d) { if (typeof b == 'string') { var e = b; b = {}; b[e] = c } var f = this._extractTime(d); extendRemove(d.options, b || {}); if (f) { this._setTime(d, new Date(0, 0, 0, f[0], f[1], f[2])) } } $.data(a, m, d) }, _destroyTimeEntry: function (b) { $input = $(b); if (!$input.hasClass(this.markerClassName)) { return } $input.removeClass(this.markerClassName).unbind('.timeEntry'); if ($.fn.mousewheel) { $input.unmousewheel() } this._disabledInputs = $.map(this._disabledInputs, function (a) { return (a == b ? null : a) }); $input.parent().replaceWith($input); $.removeData(b, m) }, _setTimeTimeEntry: function (a, b) { var c = $.data(a, m); if (c) { this._setTime(c, b ? (typeof b == 'object' ? new Date(b.getTime()) : b) : null) } }, _getTimeTimeEntry: function (a) { var b = $.data(a, m); var c = (b ? this._extractTime(b) : null); return (!c ? null : new Date(0, 0, 0, c[0], c[1], c[2])) }, _getOffsetTimeEntry: function (a) { var b = $.data(a, m); var c = (b ? this._extractTime(b) : null); return (!c ? 0 : (c[0] * 3600 + c[1] * 60 + c[2]) * 1000) }, _doFocus: function (a) { var b = (a.nodeName && a.nodeName.toLowerCase() == 'input' ? a : this); if ($.timeEntry._lastInput == b || $.timeEntry._isDisabledTimeEntry(b)) { $.timeEntry._focussed = false; return } var c = $.data(b, m); $.timeEntry._focussed = true; $.timeEntry._lastInput = b; $.timeEntry._blurredInput = null; var d = $.timeEntry._get(c, 'beforeShow'); extendRemove(c.options, (d ? d.apply(b, [b]) : {})); $.data(b, m, c); $.timeEntry._parseTime(c); setTimeout(function () { $.timeEntry._showField(c) }, 10) }, _doBlur: function (a) { $.timeEntry._blurredInput = $.timeEntry._lastInput; $.timeEntry._lastInput = null }, _doClick: function (b) { var c = b.target; var d = $.data(c, m); if (!$.timeEntry._focussed) { var e = $.timeEntry._get(d, 'separator').length + 2; d._field = 0; if (c.selectionStart != null) { for (var f = 0; f <= Math.max(1, d._secondField, d._ampmField); f++) { var g = (f != d._ampmField ? (f * e) + 2 : (d._ampmField * e) + $.timeEntry._get(d, 'ampmPrefix').length + $.timeEntry._get(d, 'ampmNames')[0].length); d._field = f; if (c.selectionStart < g) { break } } } else if (c.createTextRange) { var h = $(b.srcElement); var i = c.createTextRange(); var j = function (a) { return { thin: 2, medium: 4, thick: 6}[a] || a }; var k = b.clientX + document.documentElement.scrollLeft - (h.offset().left + parseInt(j(h.css('border-left-width')), 10)) - i.offsetLeft; for (var f = 0; f <= Math.max(1, d._secondField, d._ampmField); f++) { var g = (f != d._ampmField ? (f * e) + 2 : (d._ampmField * e) + $.timeEntry._get(d, 'ampmPrefix').length + $.timeEntry._get(d, 'ampmNames')[0].length); i.collapse(); i.moveEnd('character', g); d._field = f; if (k < i.boundingWidth) { break } } } } $.data(c, m, d); $.timeEntry._showField(d); $.timeEntry._focussed = false }, _doKeyDown: function (a) { if (a.keyCode >= 48) { return true } var b = $.data(a.target, m); switch (a.keyCode) { case 9: return (a.shiftKey ? $.timeEntry._changeField(b, -1, true) : $.timeEntry._changeField(b, +1, true)); case 35: if (a.ctrlKey) { $.timeEntry._setValue(b, '') } else { b._field = Math.max(1, b._secondField, b._ampmField); $.timeEntry._adjustField(b, 0) } break; case 36: if (a.ctrlKey) { $.timeEntry._setTime(b) } else { b._field = 0; $.timeEntry._adjustField(b, 0) } break; case 37: $.timeEntry._changeField(b, -1, false); break; case 38: $.timeEntry._adjustField(b, +1); break; case 39: $.timeEntry._changeField(b, +1, false); break; case 40: $.timeEntry._adjustField(b, -1); break; case 46: $.timeEntry._setValue(b, ''); break } return false }, _doKeyPress: function (a) { var b = String.fromCharCode(a.charCode == undefined ? a.keyCode : a.charCode); if (b < ' ') { return true } var c = $.data(a.target, m); $.timeEntry._handleKeyPress(c, b); return false }, _doMouseWheel: function (a, b) { if ($.timeEntry._isDisabledTimeEntry(a.target)) { return } b = ($.browser.opera ? -b / Math.abs(b) : ($.browser.safari ? b / Math.abs(b) : b)); var c = $.data(a.target, m); c.input.focus(); if (!c.input.val()) { $.timeEntry._parseTime(c) } $.timeEntry._adjustField(c, b); a.preventDefault() }, _expandSpinner: function (b) { var c = $.timeEntry._getSpinnerTarget(b); var d = $.data($.timeEntry._getInput(c), m); var e = $.timeEntry._get(d, 'spinnerBigImage'); if (e) { d._expanded = true; var f = $(c).offset(); var g = null; $(c).parents().each(function () { var a = $(this); if (a.css('position') == 'relative' || a.css('position') == 'absolute') { g = a.offset() } return !g }); var h = $.timeEntry._get(d, 'spinnerSize'); var i = $.timeEntry._get(d, 'spinnerBigSize'); $('<div class="timeEntry_expand" style="position: absolute; left: ' + (f.left - (i[0] - h[0]) / 2 - (g ? g.left : 0)) + 'px; top: ' + (f.top - (i[1] - h[1]) / 2 - (g ? g.top : 0)) + 'px; width: ' + i[0] + 'px; height: ' + i[1] + 'px; background: transparent url(' + e + ') no-repeat 0px 0px; z-index: 10;"></div>').mousedown($.timeEntry._handleSpinner).mouseup($.timeEntry._endSpinner).mouseout($.timeEntry._endExpand).mousemove($.timeEntry._describeSpinner).insertAfter(c) } }, _getInput: function (a) { return $(a).siblings('.' + $.timeEntry.markerClassName)[0] }, _describeSpinner: function (a) { var b = $.timeEntry._getSpinnerTarget(a); var c = $.data($.timeEntry._getInput(b), m); b.title = $.timeEntry._get(c, 'spinnerTexts')[$.timeEntry._getSpinnerRegion(c, a)] }, _handleSpinner: function (a) { var b = $.timeEntry._getSpinnerTarget(a); var c = $.timeEntry._getInput(b); if ($.timeEntry._isDisabledTimeEntry(c)) { return } if (c == $.timeEntry._blurredInput) { $.timeEntry._lastInput = c; $.timeEntry._blurredInput = null } var d = $.data(c, m); $.timeEntry._doFocus(c); var e = $.timeEntry._getSpinnerRegion(d, a); $.timeEntry._changeSpinner(d, b, e); $.timeEntry._actionSpinner(d, e); $.timeEntry._timer = null; $.timeEntry._handlingSpinner = true; var f = $.timeEntry._get(d, 'spinnerRepeat'); if (e >= 3 && f[0]) { $.timeEntry._timer = setTimeout(function () { $.timeEntry._repeatSpinner(d, e) }, f[0]); $(b).one('mouseout', $.timeEntry._releaseSpinner).one('mouseup', $.timeEntry._releaseSpinner) } }, _actionSpinner: function (a, b) { if (!a.input.val()) { $.timeEntry._parseTime(a) } switch (b) { case 0: this._setTime(a); break; case 1: this._changeField(a, -1, false); break; case 2: this._changeField(a, +1, false); break; case 3: this._adjustField(a, +1); break; case 4: this._adjustField(a, -1); break } }, _repeatSpinner: function (a, b) { if (!$.timeEntry._timer) { return } $.timeEntry._lastInput = $.timeEntry._blurredInput; this._actionSpinner(a, b); this._timer = setTimeout(function () { $.timeEntry._repeatSpinner(a, b) }, this._get(a, 'spinnerRepeat')[1]) }, _releaseSpinner: function (a) { clearTimeout($.timeEntry._timer); $.timeEntry._timer = null }, _endExpand: function (a) { $.timeEntry._timer = null; var b = $.timeEntry._getSpinnerTarget(a); var c = $.timeEntry._getInput(b); var d = $.data(c, m); $(b).remove(); d._expanded = false }, _endSpinner: function (a) { $.timeEntry._timer = null; var b = $.timeEntry._getSpinnerTarget(a); var c = $.timeEntry._getInput(b); var d = $.data(c, m); if (!$.timeEntry._isDisabledTimeEntry(c)) { $.timeEntry._changeSpinner(d, b, -1) } if ($.timeEntry._handlingSpinner) { $.timeEntry._lastInput = $.timeEntry._blurredInput } if ($.timeEntry._lastInput && $.timeEntry._handlingSpinner) { $.timeEntry._showField(d) } $.timeEntry._handlingSpinner = false }, _getSpinnerTarget: function (a) { return a.target || a.srcElement }, _getSpinnerRegion: function (a, b) { var c = this._getSpinnerTarget(b); var d = ($.browser.opera || $.browser.safari ? $.timeEntry._findPos(c) : $(c).offset()); var e = ($.browser.safari ? $.timeEntry._findScroll(c) : [document.documentElement.scrollLeft || document.body.scrollLeft, document.documentElement.scrollTop || document.body.scrollTop]); var f = this._get(a, 'spinnerIncDecOnly'); var g = (f ? 99 : b.clientX + e[0] - d.left - ($.browser.msie ? 2 : 0)); var h = b.clientY + e[1] - d.top - ($.browser.msie ? 2 : 0); var i = this._get(a, (a._expanded ? 'spinnerBigSize' : 'spinnerSize')); var j = (f ? 99 : i[0] - 1 - g); var k = i[1] - 1 - h; if (i[2] > 0 && Math.abs(g - j) <= i[2] && Math.abs(h - k) <= i[2]) { return 0 } var l = Math.min(g, h, j, k); return (l == g ? 1 : (l == j ? 2 : (l == h ? 3 : 4))) }, _changeSpinner: function (a, b, c) { $(b).css('background-position', '-' + ((c + 1) * this._get(a, (a._expanded ? 'spinnerBigSize' : 'spinnerSize'))[0]) + 'px 0px') }, _findPos: function (a) { var b = curTop = 0; if (a.offsetParent) { b = a.offsetLeft; curTop = a.offsetTop; while (a = a.offsetParent) { var c = b; b += a.offsetLeft; if (b < 0) { b = c } curTop += a.offsetTop } } return { left: b, top: curTop} }, _findScroll: function (a) { var b = false; $(a).parents().each(function () { b |= $(this).css('position') == 'fixed' }); if (b) { return [0, 0] } var c = a.scrollLeft; var d = a.scrollTop; while (a = a.parentNode) { c += a.scrollLeft || 0; d += a.scrollTop || 0 } return [c, d] }, _get: function (a, b) { return (a.options[b] != null ? a.options[b] : $.timeEntry._defaults[b]) }, _parseTime: function (a) { var b = this._extractTime(a); var c = this._get(a, 'showSeconds'); if (b) { a._selectedHour = b[0]; a._selectedMinute = b[1]; a._selectedSecond = b[2] } else { var d = this._constrainTime(a); a._selectedHour = d[0]; a._selectedMinute = d[1]; a._selectedSecond = (c ? d[2] : 0) } a._secondField = (c ? 2 : -1); a._ampmField = (this._get(a, 'show24Hours') ? -1 : (c ? 3 : 2)); a._lastChr = ''; a._field = Math.max(0, Math.min(Math.max(1, a._secondField, a._ampmField), this._get(a, 'initialField'))); if (a.input.val() != '') { this._showTime(a) } }, _extractTime: function (a, b) { b = b || a.input.val(); var c = this._get(a, 'separator'); var d = b.split(c); if (c == '' && b != '') { d[0] = b.substring(0, 2); d[1] = b.substring(2, 4); d[2] = b.substring(4, 6) } var e = this._get(a, 'ampmNames'); var f = this._get(a, 'show24Hours'); if (d.length >= 2) { var g = !f && (b.indexOf(e[0]) > -1); var h = !f && (b.indexOf(e[1]) > -1); var i = parseInt(d[0], 10); i = (isNaN(i) ? 0 : i); i = ((g || h) && i == 12 ? 0 : i) + (h ? 12 : 0); var j = parseInt(d[1], 10); j = (isNaN(j) ? 0 : j); var k = (d.length >= 3 ? parseInt(d[2], 10) : 0); k = (isNaN(k) || !this._get(a, 'showSeconds') ? 0 : k); return this._constrainTime(a, [i, j, k]) } return null }, _constrainTime: function (a, b) { var c = (b != null); if (!c) { var d = this._determineTime(a, this._get(a, 'defaultTime')) || new Date(); b = [d.getHours(), d.getMinutes(), d.getSeconds()] } var e = false; var f = this._get(a, 'timeSteps'); for (var i = 0; i < f.length; i++) { if (e) { b[i] = 0 } else if (f[i] > 1) { b[i] = Math.round(b[i] / f[i]) * f[i]; e = true } } return b }, _showTime: function (a) { var b = this._get(a, 'show24Hours'); var c = this._get(a, 'separator'); var d = (this._formatNumber(b ? a._selectedHour : ((a._selectedHour + 11) % 12) + 1) + c + this._formatNumber(a._selectedMinute) + (this._get(a, 'showSeconds') ? c + this._formatNumber(a._selectedSecond) : '') + (b ? '' : this._get(a, 'ampmPrefix') + this._get(a, 'ampmNames')[(a._selectedHour < 12 ? 0 : 1)])); this._setValue(a, d); this._showField(a) }, _showField: function (a) { var b = a.input[0]; if (a.input.is(':hidden') || $.timeEntry._lastInput != b) { return } var c = this._get(a, 'separator'); var d = c.length + 2; var e = (a._field != a._ampmField ? (a._field * d) : (a._ampmField * d) - c.length + this._get(a, 'ampmPrefix').length); var f = e + (a._field != a._ampmField ? 2 : this._get(a, 'ampmNames')[0].length); if (b.setSelectionRange) { b.setSelectionRange(e, f) } else if (b.createTextRange) { var g = b.createTextRange(); g.moveStart('character', e); g.moveEnd('character', f - a.input.val().length); g.select() } if (!b.disabled) { b.focus() } }, _formatNumber: function (a) { return (a < 10 ? '0' : '') + a }, _setValue: function (a, b) { if (b != a.input.val()) { a.input.val(b).trigger('change') } }, _changeField: function (a, b, c) { var d = (a.input.val() == '' || a._field == (b == -1 ? 0 : Math.max(1, a._secondField, a._ampmField))); if (!d) { a._field += b } this._showField(a); a._lastChr = ''; $.data(a.input[0], m, a); return (d && c) }, _adjustField: function (a, b) { if (a.input.val() == '') { b = 0 } var c = this._get(a, 'timeSteps'); this._setTime(a, new Date(0, 0, 0, a._selectedHour + (a._field == 0 ? b * c[0] : 0) + (a._field == a._ampmField ? b * 12 : 0), a._selectedMinute + (a._field == 1 ? b * c[1] : 0), a._selectedSecond + (a._field == a._secondField ? b * c[2] : 0))) }, _setTime: function (a, b) { b = this._determineTime(a, b); var c = this._constrainTime(a, b ? [b.getHours(), b.getMinutes(), b.getSeconds()] : null); b = new Date(0, 0, 0, c[0], c[1], c[2]); var b = this._normaliseTime(b); var d = this._normaliseTime(this._determineTime(a, this._get(a, 'minTime'))); var e = this._normaliseTime(this._determineTime(a, this._get(a, 'maxTime'))); b = (d && b < d ? d : (e && b > e ? e : b)); var f = this._get(a, 'beforeSetTime'); if (f) { b = f.apply(a.input[0], [this._getTimeTimeEntry(a.input[0]), b, d, e]) } a._selectedHour = b.getHours(); a._selectedMinute = b.getMinutes(); a._selectedSecond = b.getSeconds(); this._showTime(a); $.data(a.input[0], m, a) }, _normaliseTime: function (a) { if (!a) { return null } a.setFullYear(1900); a.setMonth(0); a.setDate(0); return a }, _determineTime: function (i, j) { var k = function (a) { var b = new Date(); b.setTime(b.getTime() + a * 1000); return b }; var l = function (a) { var b = $.timeEntry._extractTime(i, a); var c = new Date(); var d = (b ? b[0] : c.getHours()); var e = (b ? b[1] : c.getMinutes()); var f = (b ? b[2] : c.getSeconds()); if (!b) { var g = /([+-]?[0-9]+)\s*(s|S|m|M|h|H)?/g; var h = g.exec(a); while (h) { switch (h[2] || 's') { case 's': case 'S': f += parseInt(h[1], 10); break; case 'm': case 'M': e += parseInt(h[1], 10); break; case 'h': case 'H': d += parseInt(h[1], 10); break } h = g.exec(a) } } c = new Date(0, 0, 10, d, e, f, 0); if (/^!/.test(a)) { if (c.getDate() > 10) { c = new Date(0, 0, 10, 23, 59, 59) } else if (c.getDate() < 10) { c = new Date(0, 0, 10, 0, 0, 0) } } return c }; return (j ? (typeof j == 'string' ? l(j) : (typeof j == 'number' ? k(j) : j)) : null) }, _handleKeyPress: function (a, b) { if (b == this._get(a, 'separator')) { this._changeField(a, +1, false) } else if (b >= '0' && b <= '9') { var c = parseInt(b, 10); var d = parseInt(a._lastChr + b, 10); var e = this._get(a, 'show24Hours'); var f = (a._field != 0 ? a._selectedHour : (e ? (d < 24 ? d : c) : (d >= 1 && d <= 12 ? d : (c > 0 ? c : a._selectedHour)) % 12 + (a._selectedHour >= 12 ? 12 : 0))); var g = (a._field != 1 ? a._selectedMinute : (d < 60 ? d : c)); var h = (a._field != a._secondField ? a._selectedSecond : (d < 60 ? d : c)); var i = this._constrainTime(a, [f, g, h]); this._setTime(a, new Date(0, 0, 0, i[0], i[1], i[2])); a._lastChr = b } else if (!this._get(a, 'show24Hours')) { b = b.toLowerCase(); var j = this._get(a, 'ampmNames'); if ((b == j[0].substring(0, 1).toLowerCase() && a._selectedHour >= 12) || (b == j[1].substring(0, 1).toLowerCase() && a._selectedHour < 12)) { var k = a._field; a._field = a._ampmField; this._adjustField(a, +1); a._field = k; this._showField(a) } } } }); function extendRemove(a, b) { $.extend(a, b); for (var c in b) { if (b[c] == null) { a[c] = null } } return a } var n = ['getOffset', 'getTime', 'isDisabled']; $.fn.timeEntry = function (c) { var d = Array.prototype.slice.call(arguments, 1); if (typeof c == 'string' && $.inArray(c, n) > -1) { return $.timeEntry['_' + c + 'TimeEntry'].apply($.timeEntry, [this[0]].concat(d)) } return this.each(function () { var a = this.nodeName.toLowerCase(); if (a == 'input') { if (typeof c == 'string') { $.timeEntry['_' + c + 'TimeEntry'].apply($.timeEntry, [this].concat(d)) } else { var b = ($.fn.metadata ? $(this).metadata() : {}); $.timeEntry._connectTimeEntry(this, $.extend(b, c)) } } }) }; $.timeEntry = new TimeEntry() })(jQuery);

/* Masked Input */
/*
	Masked Input plugin for jQuery
	Copyright (c) 2007-2011 Josh Bush (digitalbush.com)
	Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) 
	Version: 1.3
*/

(function(a){var b=(a.browser.msie?"paste":"input")+".mask",c=window.orientation!=undefined;a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},dataName:"rawMaskFn"},a.fn.extend({caret:function(a,b){if(this.length!=0){if(typeof a=="number"){b=typeof b=="number"?b:a;return this.each(function(){if(this.setSelectionRange)this.setSelectionRange(a,b);else if(this.createTextRange){var c=this.createTextRange();c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select()}})}if(this[0].setSelectionRange)a=this[0].selectionStart,b=this[0].selectionEnd;else if(document.selection&&document.selection.createRange){var c=document.selection.createRange();a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length}return{begin:a,end:b}}},unmask:function(){return this.trigger("unmask")},mask:function(d,e){if(!d&&this.length>0){var f=a(this[0]);return f.data(a.mask.dataName)()}e=a.extend({placeholder:"_",completed:null},e);var g=a.mask.definitions,h=[],i=d.length,j=null,k=d.length;a.each(d.split(""),function(a,b){b=="?"?(k--,i=a):g[b]?(h.push(new RegExp(g[b])),j==null&&(j=h.length-1)):h.push(null)});return this.trigger("unmask").each(function(){function v(a){var b=f.val(),c=-1;for(var d=0,g=0;d<k;d++)if(h[d]){l[d]=e.placeholder;while(g++<b.length){var m=b.charAt(g-1);if(h[d].test(m)){l[d]=m,c=d;break}}if(g>b.length)break}else l[d]==b.charAt(g)&&d!=i&&(g++,c=d);if(!a&&c+1<i)f.val(""),t(0,k);else if(a||c+1>=i)u(),a||f.val(f.val().substring(0,c+1));return i?d:j}function u(){return f.val(l.join("")).val()}function t(a,b){for(var c=a;c<b&&c<k;c++)h[c]&&(l[c]=e.placeholder)}function s(a){var b=a.which,c=f.caret();if(a.ctrlKey||a.altKey||a.metaKey||b<32)return!0;if(b){c.end-c.begin!=0&&(t(c.begin,c.end),p(c.begin,c.end-1));var d=n(c.begin-1);if(d<k){var g=String.fromCharCode(b);if(h[d].test(g)){q(d),l[d]=g,u();var i=n(d);f.caret(i),e.completed&&i>=k&&e.completed.call(f)}}return!1}}function r(a){var b=a.which;if(b==8||b==46||c&&b==127){var d=f.caret(),e=d.begin,g=d.end;g-e==0&&(e=b!=46?o(e):g=n(e-1),g=b==46?n(g):g),t(e,g),p(e,g-1);return!1}if(b==27){f.val(m),f.caret(0,v());return!1}}function q(a){for(var b=a,c=e.placeholder;b<k;b++)if(h[b]){var d=n(b),f=l[b];l[b]=c;if(d<k&&h[d].test(f))c=f;else break}}function p(a,b){if(!(a<0)){for(var c=a,d=n(b);c<k;c++)if(h[c]){if(d<k&&h[c].test(l[d]))l[c]=l[d],l[d]=e.placeholder;else break;d=n(d)}u(),f.caret(Math.max(j,a))}}function o(a){while(--a>=0&&!h[a]);return a}function n(a){while(++a<=k&&!h[a]);return a}var f=a(this),l=a.map(d.split(""),function(a,b){if(a!="?")return g[a]?e.placeholder:a}),m=f.val();f.data(a.mask.dataName,function(){return a.map(l,function(a,b){return h[b]&&a!=e.placeholder?a:null}).join("")}),f.attr("readonly")||f.one("unmask",function(){f.unbind(".mask").removeData(a.mask.dataName)}).bind("focus.mask",function(){m=f.val();var b=v();u();var c=function(){b==d.length?f.caret(0,b):f.caret(b)};(a.browser.msie?c:function(){setTimeout(c,0)})()}).bind("blur.mask",function(){v(),f.val()!=m&&f.change()}).bind("keydown.mask",r).bind("keypress.mask",s).bind(b,function(){setTimeout(function(){f.caret(v(!0))},0)}),v()})}})})(jQuery);


