/*
 * This file contains additional
 * JS functions for properly work
 * Expedite Prototype, lightbox and confirm.js must be included
 */


var PARTICIPANT = {BUYER:'1', SELLER:'0'};
window.nonCharKeyCodes = [112, 27, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 145, 19, 45, 36, 33, 34, 35, 46, 38, 39, 8, 40, 37, 144, 20, 9, 18, 17, 16];

window.nonCharKeyCodes.sort(function(a,b){
    return b>a;
});

var ALLOWED_DOCUMENTS = ['pdf']
var ALLOWED_IMAGES = ['tif', 'tiff', 'png', 'jpg', 'jpe', 'jpeg'];

Array.prototype.inArray = function (value){
    var i;
    for (i=0; i < this.length; i++) {
        if (this[i] === value)
            return true;
    }
    return false;
};

    function isObject(object){
        return object && object.constructor === Object;
    }
    function mergeObjects(source1, source2){
        for(var x in source2){
                source1[x] = source2[x];
        }
    }

    function parseIEFileValue(txx){
        if(__ie){
            var sttt=txx;
            var laa=1;
             while(sttt.indexOf('\\', laa)>-1){
                 laa=sttt.indexOf('\\', laa)+1;
             }
            return sttt.substring(laa);
        }else
            return txx;
    }

    function txtFileInputChange(input_txt, allowed_array){
        if(__ie){
            var pNode = input_txt.parentNode;
            pNode=$(pNode);
            while((!pNode.hasClassName('input-file-container'))&&(pNode.nodeName!='BODY')){
                pNode = pNode.parentNode;
                pNode=$(pNode);
            }
            pNode = pNode.getElementsByClassName('filename-txt').first();
            input_file = pNode;
        }else{
            var input_file = input_txt.parentNode.parentNode.parentNode.parentNode.getElementsByClassName('filename-txt')[0];
        }


        if (allowed_array){
            var file_extension = input_txt.value.substr(input_txt.value.lastIndexOf('.')+1);
            if(allowed_array.inArray(file_extension.toLowerCase())){
                if(input_file)
                    input_file.value = parseIEFileValue(input_txt.value);
                return true;
            } else {
                t=input_txt.parentNode;
                tinH = t.innerHTML;
                t.innerHTML = '';
                t.innerHTML = tinH;
//                if(!__ie){
                    var b = new ConfirmLightbox('Warning', 'The selected file type is not permitted and will not be saved.\nPlease, select another file.', 'ai', 'Close', true);
                    b.open();
//                }else{
//                    alert('The selected file type is not permitted and will not be saved.\nPlease, select another file.');
//                }
            }
        }else{
            if(input_file)
                input_file.value = parseIEFileValue(input_txt.value);
        }
        return false;
    }

    /* Experimental MAX-CHARS functional */

    function maxCharsTxt(obj, lbl, char_length){
        obj=$(obj);
        lbl=$(lbl);
        
        obj.observe('keydown', function(e){charUpdate(obj, lbl, char_length, e);});
        obj.observe('keyup', function(e){charUpdate(obj, lbl, char_length, e);});
        obj.observe('keypress', function(e){charUpdate(obj, lbl, char_length, e);});
        obj.observe('paste', function(e){charUpdate(obj, lbl, char_length, e);});
        obj.observe('change', function(e){charUpdate(obj, lbl, char_length, e);});
        Event.observe(window.document, 'somelb:opened',function() {charUpdate(obj, lbl, char_length, null);});
        Event.observe(window, 'load',function() {charUpdate(obj, lbl, char_length, null);});
    }

    function charUpdate(obj, lbl, max_length, e){
        if ((max_length-(obj.value.length+1)) < 0){
            obj.value = obj.value.substring(0, max_length);
        }
        if ((max_length-(obj.value.length)) < 0){
            if (e!=null){
                e.stop();
            }
        } 
        countChars(obj, lbl, max_length, e);
    }

    function countChars(obj, lbl, max_length, e){
        lbl.innerHTML = (max_length-obj.value.length)+' of ' + max_length + ' characters remaining.';
    }

function isVisible(elm) {
		while(elm.tagName != 'BODY') {
			if(!$(elm).visible()) return false;
			elm = elm.parentNode;
		}
		return true;
	}
/**
 *
 * MAGENTO decorate classes (Thank you guys).
 *
 * Add classes to specified elements.
 * Supported classes are: 'odd', 'even', 'first', 'last'
 *
 * @param elements - array of elements to be decorated
 * [@param decorateParams] - array of classes to be set. If omitted, all available will be used
 */
function decorateGeneric(elements, decorateParams){
    var allSupportedParams = ['odd', 'even', 'first', 'last'];
    var _decorateParams = {};
    var total = elements.length;
    if (total) {
        // determine params called
        if (typeof(decorateParams) == 'undefined') {
            decorateParams = allSupportedParams;
        }
        if (!decorateParams.length) {
            return;
        }
        for (var ka in allSupportedParams) {
            _decorateParams[allSupportedParams[ka]] = false;
        }
        for (var kn in decorateParams) {
            _decorateParams[decorateParams[kn]] = true;
        }
        // decorate elements
        // elements[0].addClassName('first'); // will cause bug in IE (#5587)
        if (_decorateParams.first) {
            Element.addClassName(elements[0], 'first');
        }
        if (_decorateParams.last) {
            Element.addClassName(elements[total-1], 'last');
        }
        for (var i = 0; i < total; i++) {
            if ((i + 1) % 2 == 0) {
                if (_decorateParams.even) {
                    Element.addClassName(elements[i], 'even');
                }
            } else {
                if (_decorateParams.odd) {
                    Element.addClassName(elements[i], 'odd');
                }
            }
        }
    }
}
/**
 * Decorate table rows and cells, tbody etc
 * @see decorateGeneric()
 */
function decorateTable(table, options) {
    var table = $(table);
    if (table) {
        // set default options
        var _options = {
            'tbody'    : false,
            'tbody tr' : ['odd', 'even', 'first', 'last'],
            'thead tr' : ['first', 'last'],
            'tfoot tr' : ['first', 'last'],
            'tr td'    : ['last']
        };

        // overload options
        if (typeof(options) != 'undefined') {
            for (var k in options) {
                _options[k] = options[k];
            }
        }
        // decorate
        if (_options['tbody']) {
            decorateGeneric(table.select('tbody'), _options['tbody']);
        }
        if (_options['tbody tr']) {
            decorateGeneric(table.select('tbody tr'), _options['tbody tr']);
        }
        if (_options['thead tr']) {
            decorateGeneric(table.select('thead tr'), _options['thead tr']);
        }
        if (_options['tfoot tr']) {
            decorateGeneric(table.select('tfoot tr'), _options['tfoot tr']);
        }
        if (_options['tr td']) {
            var allRows = table.select('tr');
            if (allRows.length) {
                for (var i = 0; i < allRows.length; i++) {
                    decorateGeneric(allRows[i].getElementsByTagName('TD'), _options['tr td']);
                }
            }
        }
    }
}

function hangupHoverEffect(obj, selector_, classname, hfunc){
    if ($(obj)){
         $$('#'+obj+ ' ' + selector_).each(function(key){
             Event.observe(key, 'mouseout', function(event) {
                key.removeClassName(classname)
             });
            Event.observe(key, 'mouseover', function(event) {
                 key.addClassName(classname) 
             });
            if(hfunc)
            { 
                Event.observe(key, 'click', function(event) {
                     hfunc(key, event) 
                 });
            }
         });
    }
}

/*
 * Select option element by value
 */
function selectOption(selectElement, value)
{
	selectElement.select('option').each(function(option){
		if(option.value == value)
			selectElement.selectedIndex = option.index;
	});
}

/*
 * Select option element by value or add if it absent
 */
function selectOrAddOption(selectElement, value, name){
    var founded=false;
    var newId;
	selectElement.select('option').each(function(option){
		if(option.value == value){
			selectElement.selectedIndex = option.index;
            founded=true;
        }
	});
    if (!founded){
        newId = selectElement.options.length;
        selectElement.options[newId] = new Option(name, value);
        selectElement.selectedIndex = newId;
    }
}

/*
 *
 */
function showPreloader(obj){
    //obj - my favorite predmet in the school, that's why I call this attribute so.
    var b=document.createElement('div');
    obj.__preloader = b;
    b.className = 'loading-pimp';
    obj.parentNode.insertBefore(b, obj);
    obj.hide();
}
function hidePreloader(obj){
    //obj - my favorite predmet in the school, that's why I call this attribute so.
    if (obj.__preloader == null) {return;}
    (function(){
        Element.remove(obj.__preloader);
    }).defer();
    obj.show();
}

/*JS Funct*/
function doubleDateInputs(inputDateObj, inputDaysCount, sourceInput){
    var DATECONSTHUIPIZDA = 60*60*1000*24;
    function inpDateObjChangeF(){
        var inputDate = new Date(inputDateObj.value );
        var sourceDate = new Date(sourceInput.value );
        var resDate = new Date(inputDate - sourceDate);
        if (sourceInput.value!=''){
            inputDaysCount.value = Math.ceil(resDate/DATECONSTHUIPIZDA);
        }else{
            if(inputDaysCount.value!=''){
                sourceDate = new Date(inputDate.setHours(-inputDaysCount.value*24));
                b = (sourceDate.getMonth() <= 8) ? '0':'';
                c = (sourceDate.getDate() <= 9) ? '0':'';
                sourceInput.value = b+(sourceDate.getMonth()+1) + '/' + c + sourceDate.getDate() + '/' + sourceDate.getYear();
            }
        }
        Validation.validate(inputDaysCount);
    }
    inputDateObj.observe('alcc:dateChanged', inpDateObjChangeF);
    sourceInput.observe('alcc:dateChanged', function(){
        var inputDate = new Date(inputDateObj.value );
        var sourceDate = new Date(sourceInput.value );
        var resDate = new Date(inputDate - sourceDate);
        if (inputDateObj.value!=''){
            inputDaysCount.value = Math.ceil(resDate/DATECONSTHUIPIZDA);
        }else{
            if(inputDaysCount.value!=''){
                inputDate = new Date(sourceDate.setHours(inputDaysCount.value*24));
                b = (inputDate.getMonth() <= 8) ? '0':'';
                c = (inputDate.getDate() <= 9) ? '0':'';
                inputDateObj.value = b+(inputDate.getMonth()+1) + '/' + c + inputDate.getDate() + '/' + inputDate.getYear();
            }
        }
        Validation.validate(inputDaysCount);
    });
    inputDaysCount.observe('change', function(){
        var inputDate = new Date(inputDateObj.value );
        var sourceDate = new Date(sourceInput.value );
        if((Validation.validate(inputDaysCount))&& (sourceInput.value!='')){
                inputDate = new Date(sourceDate.setHours(inputDaysCount.value*24));
                 b = (inputDate.getMonth() <= 8) ? '0':'';
                c = (inputDate.getDate() <= 9) ? '0':'';
                inputDateObj.value = b+(inputDate.getMonth()+1) + '/' + c + inputDate.getDate() + '/' + inputDate.getYear();
        }else{
            return 'Na hui!';
        }
    });
    inpDateObjChangeF();
}

function updateInput(id, val){
    var elem = $(id);
    if (elem) {
        elem.removeClassName('loading-back');
        if (val) elem.value = val;
        //elem.enable();
    }
}

function startLoading(elem, val){
    if (elem) {
        elem.addClassName("loading-back");
        elem.value = "";
        //elem.disable();
        setTimeout('updateInput(\''+elem.id+'\', \''+val+'\')',500);
    }
}
window.propertyAddress={};
window.propertyAddressPrefix='';
function updatePropertyAddress(prefixInn){
    if(prefixInn){
        window.propertyAddressPrefix=prefixInn;
    }
    var prefix = window.propertyAddressPrefix;
        var zip = $(prefix+'_zip'),
            address = $(prefix),
            city = $(prefix + '_city'),
            state = $(prefix + '_state');
    window.propertyAddress['zipCode']=zip.value;
    window.propertyAddress['addressProp']=address.value;
    window.propertyAddress['cityValue']=city.value;
    window.propertyAddress['stateValue']=state.value;
}
// TODO: Move this stuff to Select_state_city.js
    function onAddressChanged(prefix, fnc, chckbox){
        updatePropertyAddress(prefix);
        fnc();
        var zip = $(prefix+'_zip'),
            address = $(prefix),
            city = $(prefix + '_city'),
            state = $(prefix + '_state'),
            chck = $(chckbox),
            self = this;
        chck.observe('click', function(){fnc();});
        zip.observe('change', function(){fnc();});
        address.observe('change', function(){fnc();});
        city.observe('dd:change', function(){fnc();});
        state.observe('dd:change', function(){fnc();});
    }

    function u_sameAsProperty(prefix, container, propAddres, selectStateCityObj){
        var chbk = $('same_as_property_address_'+prefix);
        if(chbk.checked){
            var zip = $(prefix+'_zip'),
                address = $(prefix),
                self = this;
            startLoading(address, propAddres.addressProp);
            startLoading(zip, propAddres.zipCode);
            selectStateCityObj.startLoading(prefix+'_state');
            selectStateCityObj.stateChanged(null, propAddres.stateValue, propAddres.cityValue);
        }else{
            u_disableAddressInputs(prefix, container);
        }
    } 

    function u_sameAsProperty_globalPropAddress(prefix, container, selectStateCityObj){
        updatePropertyAddress();
        u_sameAsProperty(prefix, container, window.propertyAddress, selectStateCityObj);
    }
    function u_disableAddressInputs(prefix, container, e){
        var chbk = $('same_as_property_address_'+prefix);
            var zip = $(prefix+'_zip'),
                address = $(prefix);

        [address, zip].each(function(elem) {
            if(chbk.checked){
                elem.readOnly = true;
                elem.addClassName('disabled-field');
            } else {
                elem.readOnly = false;
                elem.removeClassName('disabled-field');
            }
        });
        $$(container + ' input').each(function(key){
            if(chbk.checked){
                key.enable();
                key.disable();
            }else{
                key.enable();
            }
        });
    }
    function searchFor(str,obj){
        window.search_depth=0;
        searchForRec(str,obj);
    }
    function searchForRec(str, obj){
        for (var b in obj){
            if (typeof(obj[b]) == 'object'){
                if(window.search_depth<10){
                    window.search_depth++;
                    searchForRec(str, obj[b]);
                    window.search_depth--;
                }
            }else{
                if (obj[b] == str){
                    console.log(b + ' = ' + obj[b]);
                }
                if (typeof obj[b] == typeof str == 'string'){
                    if(obj[b].indexOf(str)){
                        console.log(b + ' = ' + obj[b] + " shodstvo chastichnbo");
                    }
                }
            }
        }
    }

var EFFECT_DURATION = 0.4;
var EFFECT_DURATION_HALF = 0.3;
var EFFECT_DURATION_HIDE = 0.3;
var EFFECT_DURATION_HALF_HIDE = 0.08;
if(Prototype.BrowserFeatures.SpecificElementExtensions){
        window.HTMLDivElement.prototype.showFX = function(){
            element = this;
            if(this.style.display=='none'){
                element = $(element);
                if (Effect != null){
                    new Effect.BlindDown(element, {duration:EFFECT_DURATION});
                    new Effect.Appear(element, {duration:EFFECT_DURATION});
                }else{
                    element.style.display = '';
                }
            }
            return element;
        };
        window.HTMLDivElement.prototype.hideFX = function() {
            element = this;
            if(this.style.display !='none'){
                element = $(element);
                if (Effect != null){
                    new Effect.BlindUp(element, {duration:EFFECT_DURATION_HIDE});
                    new Effect.Fade(element, {duration:EFFECT_DURATION_HIDE});
                }else{
                    element.style.display = 'none';
                }
            }
            return element;
        };
}

function animateRows(table_id, click_funct){
    $$('#'+table_id+' tbody tr').each(function(key){
        key.observe('mouseover', function(){
            this.addClassName('hover-class');
        }.bind(key));
    });
    $$('#'+table_id+' tbody tr').each(function(key){
        key.observe('mouseout', function(){
            this.removeClassName('hover-class');
        }.bind(key));
    });
    if(click_funct){
        $$('#'+table_id+' tbody tr').each(function(key){
            key.observe('click', function(){
                click_funct(this);
            }.bind(key));
        });
    }
}

function isElementVisible(elm) {
		while(elm.tagName != 'BODY') {
			if(!$(elm).visible()) return false;
			elm = elm.parentNode;
		}
		return true;
}


function addRequires(divid, classT){
    $$('#' + divid + ' input').each(function(davidguetta){
        if(classT && davidguetta.hasClassName(classT)){
            davidguetta.addClassName('required')
        }
        if(!classT){
            davidguetta.addClassName('required')
        }
    });
    $$('#' + divid + ' select').each(function(davidguetta){
        if(classT && davidguetta.hasClassName(classT)){
            davidguetta.addClassName('validate-selection')
        }
        if(!classT){
            davidguetta.addClassName('validate-selection')
        }
    });
}
 
function removeRequires(divid){
    $$('#' + divid + ' input').each(function(davidguetta){
        davidguetta.removeClassName('required');
    });
    $$('#' + divid + ' select').each(function(davidguetta){
        davidguetta.removeClassName('required');
        davidguetta.removeClassName('validate-selection');
    });
}

function disableInputs(divid){
    $$('#' + divid + ' input').each(function(carl_cox){
        carl_cox.disable();
    })
}
function enableInputs(divid){
    $$('#' + divid + ' input').each(function(carl_cox){
        carl_cox.enable();
    })
}

function refreshCustomSelectsInContainer(selector){
    $$(selector + ' select').each(function(key){
        u_updateSelect(key.id);
    });
}

function u_updateSelect(combo_id){
    var combo = $(combo_id+'_combo');
    var combo_opt = $(combo_id+'_options');
    if (combo && combo_opt) {
        combo.remove();
        combo_opt.remove(); 
        new Autocompleter.SelectBox(combo_id);
    }
}
/**/
//generate word function
var sgl=['b','c','d','f','g','h','j','k','l','m','n','p','r','s','t','v','w','x','z','ch','sh', 'fr','q'];
var gl=['a','e','i','o','u','y', 'oo', 'ou', 'ae', 'ea'];
function generateWord(lngth){
    if(!lngth){
        lngth=Math.floor(Math.random()*10)+2;
    };
    var resultWord='';
    var newSymbol;
    var bbbb=true;
    while (resultWord.length < lngth){
        newSymbol = bbbb?sgl[Math.floor(Math.random()*sgl.length)]:gl[Math.floor(Math.random()*gl.length)];
        bbbb=!bbbb;
        resultWord+=newSymbol;
    }
    if(!__ie)
        resultWord = resultWord[0].toUpperCase() + resultWord.substring(1);
    return resultWord;
}


function aVSan(istr){
    return ['a','e','o','u','y','i'].inArray(istr.substr(0,1).toLowerCase())?'an':'a';
}



var inviteClass =  function(isLogged, ajaxUrl)
{
    this.roleSelect = $('role_select');
    this.validation2 = new Validation('invite_friend',{onSubmit: false})
    this.initialize.apply(this, arguments);
}

inviteClass.prototype =
{
    initialize : function(isLogged, ajaxUrl){
        this.isLogged=isLogged;
        this.ajaxUrl=ajaxUrl;
        this.initLightBox();
        this.initShowLightBoxAction(this);
    },

    initShowLightBoxAction : function(){
        var openHandler = this.openLightBox.bind(this);
        $('showInviteButton').observe('click',openHandler);
    },

    openLightBox : function(){
        this.validation2.reset();
        this.roleSelect.selectedIndex = 0;
        $(this.roleSelect.id + '_combo').value = this.roleSelect.options[0].innerHTML;
        $('recipient_name').value = '';
        $('recipient_email').value = '';

        if(!this.isLogged){
            $('inviter_name').value = '';
            $('inviter_email').value = '';
        }
        this.inviteLightBox.open();
    },

    initLightBox : function(){
        this.inviteLightBox = new Lightbox($('invite_friend'));
        this.initLightBoxHandlers();
    },

    initLightBoxHandlers : function(){
        var closeHandler = this.inviteLightBox.close.bind(this.inviteLightBox)
        $('closeButton').observe('click',closeHandler);
        $('closeImage').observe('click',closeHandler);

        var sendHandler = this.sendInvite.bind(this);
        $('sendButton').observe('click',sendHandler);
    },

    sendInvite : function(){
        this.validation2.reset();
        Validation.add('validate-select-special', 'Please make a selection', function (v,elm) {
            return elm.options ? elm.value != -1 : !Validation.get('IsEmpty').test(v);
        });
        if(!this.validation2.validate())
        {
            return;
        }

       // $(this.roleSelect.id + '_combo').addClassName("combo-loading");
        var successHandler = this.sendSuccess.bind(this);
        var failureHandler = this.sendFailure.bind(this);
        var completeHandler = this.sendComplete.bind(this);

        var params = $('invite_friend_form').serialize(true);
        new Ajax.Request(
                            this.ajaxUrl,
                            {
                                onSuccess: successHandler,
                                onFailure: failureHandler,
                                onComplete: completeHandler,
                                parameters: params
                            }
                        );
    },

    sendSuccess : function(transport){
        var response = transport.responseText.evalJSON();
        if(response.success == true){
        	messageLightBox = new Lightbox($('success_msg'));
            $$('#success_msg .ins-content')[0].innerHTML = response.message;
            messageLightBox.open();
        }
        if(response.success == false){
        	messageLightBox = new Lightbox($('error_msg'));
            $$('#error_msg .ins-content')[0].innerHTML = response.message;
            messageLightBox.open();
        }

    },

    sendFailure : function(error){
        alert('error');
    },

    sendComplete : function(transport){
        $(this.roleSelect.id + '_combo').removeClassName("combo-loading");
        this.inviteLightBox.close();
    }

}


//autofill function
Event.observe(document, 'keyup', function(evt) {
	if (evt.altKey && evt.ctrlKey && evt.keyCode==71){
        $$('.required').each(function(key){
            if(!evt.shiftKey){if(key.value!=''){return;}}
            if(key.hasClassName('validate-email')){
                key.value= generateWord() + '@a-' + generateWord(22) +'.com';
            }else{
                if((key.id.indexOf('date')!=-1)||key.hasClassName('validate-date')){
                    key.value = '07/'+(Math.floor(Math.random()*14)+10)+'/10';

                }else if((key.id.indexOf('_zip')!=-1)){
                    key.setValue('10001');
                    key.focus();
                    if(key.blur){key.blur();}
                }else if(key.hasClassName('validate-digits')||key.hasClassName('validate-number')||key.hasClassName('validate-positive-number-date')){
                    if(key.value=='')
                        key.value=Math.floor(Math.random()*100000);
                }else{
                    key.value=generateWord();
                }
            }
        }.bind(evt));
        $$('.validate-positive-number-date').each(function(key){
            key.value =  (Math.floor(Math.random()*14)+10);
            key.focus();
        });
	}
    if (evt.altKey && evt.ctrlKey && evt.shiftKey && evt.keyCode==81){
        window.location=window.logoutUrl;
    }
    if (evt.shiftKey && evt.ctrlKey && evt.keyCode==69){
        $$('.page .left-text')[0].innerHTML = "<h3>PIMP mode</h3>";
        $$('.page')[0].addClassName('page-p');
        new Insertion.Bottom($$('body')[0], '<div class="danechka"></div>');
        $$('input,textarea,select,li').each(function(inp){
            //if(inp.type=="text"){
                nc='rgb('+ Math.floor(Math.random()*255) + ','+ Math.floor(Math.random()*255) + ','+ Math.floor(Math.random()*255) + ')';
                nc=nc.parseColor();
                inp.style.backgroundColor=nc;
                inp.style['-moz-transform']='rotate(28deg)';
            //}
        })
    }
    if (evt.shiftKey && evt.keyCode==69){
        console.log(            $$('.one_column_content').first().className);
        console.log(            $$('.sub-header').first().style.zIndex);
        console.log(            $$('.one_column_content').first().style.zIndex);
    }
});


function doubleInputCount(a, b, req){
    $(a).observe('keyup', function(){
        if(req){
            $(a).removeClassName('required');
            $(b).removeClassName('required');
            $(a).addClassName('required');
        }
        if($(a).value!=''){
            $(b).value='';
        }
    });
    $(b).observe('change', function(){
        if(req){
            $(a).removeClassName('required');
            $(b).removeClassName('required');
            $(b).addClassName('required');
        }
        if($(b).value!=''){
            $(a).value='';
        }
    });
}
Math.floor2n = function(n){
    if (n)
        return Math.floor(n*100)/100;
};
Math.floor3n = function(n){
    if(n==0)
        return 0;
    if (n)
        return Math.floor(n*1000)/1000;
};

isIEUnder8Version = function () {
      if(Prototype.Browser.IE){
		var index = navigator.userAgent.indexOf('MSIE');
		if (index == -1) return;
		return (parseFloat(navigator.userAgent.substring(index+5))<8);
      }else{
        return false;
      }
  };
