/**
 * Rounded Corners -->DD_roundies.js
 */
DD_roundies.addRule('.feature', '8px 0 8px 0', true);
DD_roundies.addRule('.mtype1-title, .mtype2-title, .mtype3-title', '8px 8px 0 0', true);
DD_roundies.addRule('#toggler, .mtype1-body, .mtype2-body, .mtype3-body', '0 0 8px 8px', true);

/**
 * SCRIPT FOR FORM ONFOCUS STYLING  - jtj
 */
var styleOnFocus = function(formID){
    $(formID).getElements('input[type!=submit], textarea, select').addEvents({
        focus: function(){
            this.getParent('li').addClass('focused');
        },
        blur: function(){
            this.getParent('li').removeClass('focused');
        }
    });
};

/**
 * SCRIPT FOR ADDING ORDERED TABINDEX TO ELEMENT  - jtj
 */
var addTabIndex = function(formID){
    var form = $(formID);
    for (var i = 0, j = form.elements.length; i < form.elements.length; i++, j--) {
        form.elements[i].tabIndex = i + 1
    }
};

/**
 * SCRIPT FOR ALT BKG COLORS  - jtj
 */
var zebraTable = function(co, oddClass, evenClass){
    $$(co).each(function(el, n){
        el.removeClass(n % 2 == 0 ? oddClass : evenClass);
        el.addClass(n % 2 == 0 ? evenClass : oddClass);
    });
};

/**
 * SCRIPT FOR REMOVING LAST CHARACTER OF A STRING  - jtj
 */
var removeLastChar = function(str, chr){
	var outstr = ((str.charAt(str.length-1,1) == chr) ? str.substring(0,str.length-1) : str);
	return outstr;
};

/**
 * SCRIPT AUTOCOMPLETE FROM XML --> autocompleter.js
 */
var fldCompleteSingle = function(fld, url){
    new Autocompleter.Request.HTML(fld, url, {
        'indicatorClass': 'autocompleter-loading', // class added to the input during request
        'selectMode': 'type-ahead' // Instant completion
    });
};
var fldCompleteMultiple = function(fld, url){
    new Autocompleter.Request.HTML(fld, url, {
        'indicatorClass': 'autocompleter-loading', // class added to the input during request
        'selectMode': 'type-ahead', // Instant completion
        'multiple': true // Tag support, by default comma separated
    });
};

/**
 * INITIALIZE SCRIPTS ONDOMREADY
 **/
window.addEvent('domready', function(){
    // RESET ASSET LOCATION FOR CNET PLUGINS --> clientcide.js
    //setAssetLocation("/_cnet.assets");
    // LAST MODULE OF SIDEBAR ADD 20px	MARGIN-BOTTOM
    $$('#content-sidebar .module:last-child').setStyle('margin-bottom', '20px');
    //NAVIGATION -->MooDropMenu.js
    if ($('nav')) {
        $('nav').MooDropMenu({
            onOpen: function(el){
                el.fade('in');
                el.getParent().addClass('current');
            },
            onClose: function(el){
                el.fade('out');
                el.getParent().removeClass('current');
            },
            onInitialize: function(el){
                el.fade('hide').set('tween', {
                    duration: 500
                });
            }
        });
    };
    // Warranty Star onclick event
    if ($('warrantyStar')) {
        $('warrantyStar').addEvents({
            click: function(){
                window.location.href = '/news/details.asp?strID=x2';
            },
            mouseenter: function(){
                this.setStyle('cursor', 'pointer');
            }
        });
    }
    //ADD ICONS  TO LINKS -->LinkAlert.js
    var context = new LinkAlert({
        extensions: {
            pdf: '/_img/icons/pdf.gif',
            xls: '/_img/icons/page_excel.gif',
            jpg: '/_img/icons/image.gif'
        },
        protocols: {
            http: '/_img/icons/external.gif'
        },
        preloadImages: true,
        sticky: true,
        onShow: function(el, image){
            this.image.fade('in');
        },
        onHide: function(el, image){
            this.image.fade('out');
        }
    });
    //ADD CLASS TO ALL FIRST AND LAST <LI> TAGS
    $$('#content li:first-child').addClass('first');
    $$('#content li:last-child').addClass('last');
    //ADD ZEBRA STYLE TO ALL TABLES
    zebraTable('.tbl tbody tr', 'odd', 'even');
});

