// JavaScript Document
var bingMapSearch = null;
var bingMapSearchContent = {
    'defaultCitySelection': {
        'en': 'Choose a City',
        'fr': 'Sélectionner une ville'
    },
    'invalidSearchCriteria': {
        'en': 'Please enter a city or a valid postal code.',
        'fr': 'Veuillez écrire une ville ou un code postal valide'
    },
    'invalidPostalCode': {
        'en': 'The Postal Code format is invalid!',
        'fr': 'Le code postal est invalide.'
    },
    'outOfProvince': {
        'en': 'The postal code that you entered is invalid for this province.',
        'fr': 'Le code postal entré n’est pas valide dans cette province.'
    },
    'noResult': {
        'en': 'Sorry. It seems there are no schools that meet your criteria.',
        'fr': 'Nous sommes désolés, il ne semble pas y avoir d’écoles rencontrant vos critères de recherches.'
    },
    'mapUnavailable': {
        'en': 'Map unavailable',
        'fr': 'Carte non disponible.'
    },
    'resultSummary': {
        'en': 'Showing [count] of [total]',
        'fr': 'représentation de [count] de [total]'
    },    
    'daycareServiceLabel': {
        'en': 'Daycare service',
        'fr': 'Service de garde'
    },
    'distanceDisplayButtonLabel': {
        'en': 'Distance',
        'fr': 'Distance'
    },
    'distanceDisplayUnit': {
        'en': 'km',
        'fr': 'km'
    }
};
bingMapSearchControls = new bingMapToolsControls();
function bingMapToolsControls() {
    this.postalFirstUpdated = false;
    this.currentPublicSchoolChecked = false;
    this.currentCatholicSchoolChecked = false;
    this.radiobuttonHandler = function(obj, val) {
        if (val) {
            obj.checked = false;
        }
        return obj.checked;
    }
    this.clearCity = function(obj) {
        if (obj.value.length > 0) $(bingMapSearch.controlCity).val('');
    }
    this.clearPostalCode = function(obj) {
        if (obj.value.length > 0) {
            $(bingMapSearch.controlPostalFirst).val('');
            $(bingMapSearch.controlPostalLast).val('');
        }
    }
    this.focusPostalLast = function(obj, key) {
        if (key == 9 || key == 16) return;
        if (obj.value.length == 3 && this.postalFirstUpdated) {
            $(bingMapSearch.controlPostalLast).focus();
        } else {
            this.postalFirstUpdated = true;
        }
    }
}
bingMapSearch = new bingMapTools(null);
function bingMapTools(options) {
    target = this;
    this.criteria = new Object();
    this.criteria.publicSchool = false;
    this.criteria.catholicSchool = false;
    this.result = [];
    this.distanceLookup = "";
    this.summaryPrefix = 'display_';
    this.mapiconPrefix = 'holderIcon_';
    this.resultDiv = '.searchResultsWrap';
    this.locationsPanel = '#locationsTable';
    this.locationsDiv = '.searchResultsLeft';
    this.locationActiveBackColour = '#BCBCBC';
    this.locationInactiveBackColour = 'transparent';
    this.distanceButtonDiv = '.distanceBut';
    this.distanceDisplayDiv = '.distance';
    this.mapDiv = '.searchResultsRight';
    this.mapPlaceHolder = '#locationsMap';
    this.resultSummary = '#resultSummary';
    this.controlSearch = "#searchNow";
    this.controlCity = '#searchCity';
    this.controlPostalFirst = '#searchPostalFirst';
    this.controlPostalLast = '#searchPostalLast';
    this.controlRadius = '#searchRadius';
    this.controlSchoolType = '#schoolType';
    this.controlPublicSchool = '#publicSchool';
    this.controlCatholicSchool = '#catholicSchool';
    this.errorDiv = '.errorMessage';
    this.waitingImgID = 'nowLoading'
    this.waitingImgURL = 'images/loading.gif'
    $.extend(this, options);
    this.loadSearchCriteria = function() {
        $(this.controlCity).append('<option value="">' + bingMapSearchContent.defaultCitySelection[filterObject.lang] + '</option>');
        var cities = filterObject[filterObject.prov + "CityData"];
        for (var i = 0; i < cities.length; i++) {
            $(this.controlCity).append('<option value="' + cities[i] + '">' + cities[i] + '</option>');
        }
    }
    this.showLoadingImg = function(where, className){
        this.hideLoadingImg();
        $(where).before('<span id="'+this.waitingImgID+'" style="float:right;" class="'+className+'"><img src="'+this.waitingImgURL+'" /></span>');
    }
    this.hideLoadingImg = function(){
        $('#' + this.waitingImgID).remove();
    }
    this.performSearch = function() { 
        this.showLoadingImg(this.controlSearch, 'loadingButton1');
        
        /* reset error message, result and map area */
        $(this.errorDiv).html('');
        $(this.resultDiv).hide();
        $(this.locationsPanel).empty();
        if (map == null){
			
            loadMap();
        }
        map.DeleteAllShapes();
        
        /* capture search criteria */
        this.criteria.radius = $(this.controlRadius).val();
        this.criteria.publicSchool = $(this.controlPublicSchool + ':checked').length == 1;
        this.criteria.catholicSchool = $(this.controlCatholicSchool + ':checked').length == 1;
        if (!this.criteria.publicSchool && !this.criteria.catholicSchool) { // if both are false, they want both public and catholic
            this.criteria.publicSchool = true;
            this.criteria.catholicSchool = true;
        }
        this.criteria.schoolType = $(this.controlSchoolType).val();
        
        /* determine the type of search */
        if ($(this.controlCity).val().length > 0) { // city search
            this.criteria.searchType = 'city';
            $(this.controlPostalFirst).val('');
            $(this.controlPostalLast).val('');
            this.getLatLonByCity($(this.controlCity).val());
			
        } else if ($(this.controlPostalFirst).val().length > 0 && $(this.controlPostalLast).val().length > 0) { // postal code search
            if (!this.validatePostalCode($(this.controlPostalFirst).val(), $(this.controlPostalLast).val())) { // validate postal code format
                $(this.errorDiv).html(bingMapSearchContent.invalidPostalCode[filterObject.lang]);
                return;
            }
            this.criteria.searchType = 'postal';
            $(this.controlCity).val('');
            this.getLatLonByPostalCode($(this.controlPostalFirst).val() + $(this.controlPostalLast).val());
        } else {
            /* error - no city selected nor postal code entered */
			
            $(this.errorDiv).html(bingMapSearchContent.invalidSearchCriteria[filterObject.lang]);
            this.hideLoadingImg();
        }
    }
    this.validatePostalCode = function(a, b) {
        if (a.length != 3 || b.length != 3) return false;
        var pc = a + b, az = 'AZ', num = '09';
        for (var i = 0; i < pc.length; i++) {
            if (i % 2 == 0) { //letter
                if (pc.charCodeAt(i) < az.charCodeAt(0) || pc.charCodeAt(i) > az.charCodeAt(1)) {
                    return false;
                }
            } else { // number
                if (pc.charCodeAt(i) < num.charCodeAt(0) || pc.charCodeAt(i) > num.charCodeAt(1)) {
                    return false;
                }
            }
        }
        return true;
    }
    this.getLatLonByCity = function(city) { // get lat/long base on city search
        if (city.toUpperCase() == 'BORDEN'){
            this.getLatLonByPostalCode('L0M 1C0')
        }
        else{
            this.criteria.city = city + ', ' + filterObject.prov + ', Canada';
            this.getLatLon(this.criteria.city);
        }
    }
    this.getLatLonByPostalCode = function(postal) { // get lat/long base on postal code search
        this.criteria.postal = postal + ', Canada';
        this.getLatLon(this.criteria.postal);
    }
    this.getLatLon = function(searchString) { // get lat/long using bing map
		
        map.Find(null, searchString, null, null, null, null, null, null, false, null, bingMapSearch.mapFindCallback);
    }
    this.mapFindCallback = function(a, b, c, d, e) { // single hit     
		// if (c != null && c.length == 1) { // center the map
		//jlee removed the length check and always use the first returned, for some reason Azilda returns 2 only after it is hit a second time.
        if (c != null) { // center the map
            var name = c[0].Name;
            if (name.toUpperCase() == "CANADA") { // postal code not found
                /* error - invalid postal code */
                $(bingMapSearch.errorDiv).html(bingMapSearchContent.invalidPostalCode[filterObject.lang]);
            }
            else if (name.substr(name.length - 2, 2).toUpperCase() != filterObject.prov.toUpperCase()) { // outside province
                /* error - postal code falls outside of the province */
                $(bingMapSearch.errorDiv).html(bingMapSearchContent.outOfProvince[filterObject.lang]);
            }
            else{
                $(bingMapSearch.resultDiv).show();
                map.SetCenter(new VELatLong(c[0].LatLong.Latitude, c[0].LatLong.Longitude)); // capture the lat and long
                bingMapSearch.criteria.lat = c[0].LatLong.Latitude;
                bingMapSearch.criteria.lon = c[0].LatLong.Longitude; // populate the map base on the address
                bingMapSearch.filterLocations();
            }
        } else { // will need to handle address disambiguation or return an error;
            /* error - more than one possible address matched...*/
			
            return;
        }
        bingMapSearch.hideLoadingImg();
    }
    this.textBoolean = function(val) {
        switch (val.toUpperCase()) {
        case "YES":
        case "OUI":
        case "ALL":
            return true;
            break;
        default:
            return false;
            break;
        }
    }
    this.filterLocations = function() {
        this.criteria.minLat = this.criteria.lat;
        this.criteria.minLon = this.criteria.lon;
        this.criteria.maxLat = this.criteria.lat;
        this.criteria.maxLon = this.criteria.lon;
        this.source = filterObject.prov + "Data";
        this.result = [];
        for (var i = 0; i < filterObject[this.source].length; i++) {
            var item = filterObject[this.source][i];
            /* check for search criteria */
            var dist = filterObject.calcDist(this.criteria.lat, this.criteria.lon, item.lat, item.lon);
            if (parseFloat(dist) > parseFloat(this.criteria.radius)) continue;
            if (!this.filterSchoolType(item)) continue;
            if (this.textBoolean(item.publicSchool) && !this.criteria.publicSchool) continue;
            if (this.textBoolean(item.catholicSchool) && !this.criteria.catholicSchool) continue;
            /* define the max/min lat/long */
            this.criteria.minLat = Math.min(this.criteria.minLat, item.lat);
            this.criteria.minLon = Math.min(this.criteria.minLon, item.lon);
            this.criteria.maxLat = Math.max(this.criteria.maxLat, item.lat);
            this.criteria.maxLon = Math.max(this.criteria.maxLon, item.lon);
            /* add the qualify location to the result set */
            this.result.push({
                id: i,
                lat: item.lat,
                lon: item.lon,
                distance: dist.toFixed(1)
            });
        }
        this.plotResult();
    }
    this.filterSchoolType = function(item) {
        var basicCond = this.textBoolean(this.criteria.schoolType) || item.type == this.criteria.schoolType;
        if (this.criteria.schoolType != 'Daycare service') {
            return basicCond;
        }
        else {
            return basicCond || item.dayCareName.replace(/ /gi, "").length > 0 ;
        }
    }
    this.plotResult = function() {
        if (this.result.length == 0) {
            $(this.resultDiv).hide();
            $(this.errorDiv).html(bingMapSearchContent.noResult[filterObject.lang]);
        }
        else{
            this.result.sort(this.sortDistance);
            var pin = 0;
            for (var j = 0; j < this.result.length; j++) {
                pin++;
                this.addPushpin(this.result[j], pin);
            }
            this.mapSetView();
            this.checkPoints();
        }
        this.hideLoadingImg();
    }
    this.loadDirections = function(id, lat, lon) { // get the direction using bing map
        this.showLoadingImg('#' + id + ' ' + this.distanceDisplayDiv, 'loadingButton2');

        this.distanceLookup = id;
        var myOptions = new VERouteOptions();
        myOptions.RouteOptimize = VERouteOptimize.MinimizeDistance;
        myOptions.DistanceUnit = VERouteDistanceUnit.Kilometer;
        myOptions.DrawRoute = false;
        myOptions.SetBestMapView = true; // Don't change map view
        myOptions.RouteCallback = this.mapRouteCallback; // Gets VERoute
        map.GetDirections([new VELatLong(this.criteria.lat, this.criteria.lon), new VELatLong(lat, lon)], myOptions);
    }
    this.mapRouteCallback = function(route) { // get the route and populate distance text
        if (route.RouteLegs.length > 0) { /*            
            var startLoc = route.RouteLegs[0].StartLocation;
            var startLat = startLoc.Latitude;
            var startLon = startLoc.Longitude; */
            var distance = route.Distance.toFixed(1) + bingMapSearchContent.distanceDisplayUnit[filterObject.lang];
            $("#" + bingMapSearch.distanceLookup + " " + bingMapSearch.distanceDisplayDiv).html(distance);
            $("#" + bingMapSearch.distanceLookup + " " + bingMapSearch.distanceButtonDiv).hide();
        }
        bingMapSearch.hideLoadingImg();
    }
    this.sortDistance = function(a, b) {
        return a.distance - b.distance;
    }
    this.addPushpin = function(result, pin) {
        var source = filterObject.prov + "Data";
        var item = filterObject[source][result.id];
        item.dayCarePhone = "";
        switch (item.type){
            case "Elementary":
            case "Secondary":
                var daycareName = filterObject[source][result.id].dayCareName;
                for (var k = result.id - 2 ; k <= result.id + 2 ; k++){
                    if (k < 0 || k >= filterObject[source].length)
                        continue;
                    if (k == result.id || filterObject[source][k].dayCareName != daycareName || filterObject[source][k].type != "Daycare service")
                        continue;
                    item.dayCarePhone = filterObject[source][k].phone;
                    break;
                }
                break;
        }
        var point = new VELatLong(item.lat, item.lon, 0, VEAltitudeMode.RelativeToGround);
        var shape = new VEShape(VEShapeType.Pushpin, point);
        map.ClearInfoBoxStyles();
        map.AddShape(shape);
        var id = shape.GetID();
        result.shapeID = id;
        shape.SetCustomIcon(this.mapPointerActive(id));
        shape.point = point;
        $(this.locationsPanel).append(this.loadInfo(item, id));
        return;
    }
    this.mapPointerActive = function(shapeID) {
        var icon = "<span id='holderIcon" + shapeID + "' >";
        icon += "<img src='images/pointer_off.gif' name='icon" + shapeID + "' ";
        icon += "onmouseover='this.src=\"images/pointer_on.gif\";' ";
        icon += "onmouseout='this.src=\"images/pointer_off.gif\";' />";
        icon += "</span>";
        return icon;
    }
    this.mapPointerInactive = function() {
        return "<span><img src='images/pointer_on.gif' /></span>";
    }
    this.formatAddress = function(isEN, item, incParagraph) {
        var postalcode = item.postal_code;
        if (postalcode.length == 6){
            postalcode = postalcode.substr(0, 3) + ' '  + postalcode.substr(3, 3)
        }
        var retval = (isEN ? item.addressDisplay: item.addressDisplayFr);
        retval += '<br/>' + item.city + ', ' + item.province.toUpperCase() + ' ' + postalcode;
        retval += '<br/>' + item.phone;
        if (incParagraph)
        retval = '<p>' + retval + '</p>';
        return retval;
    }
    this.formatURL = function(url, display, incParagraph) {
        if (url.length == 0)
            return "";
        if (url.substr(0, 4) != 'http') 
            url = 'http://' + url;
        if (display == null)
            display = url;
        var retval = '<a target="_new" href="' + url + '">' + display + '</a>';
        if (incParagraph)
        retval = '<p>' + retval + '</p>';
        return retval;
    }
    this.loadInfo = function(item, shapeID) {
        var isEN = filterObject.lang.toUpperCase() == "EN";
        var display = '<td id="' + this.summaryPrefix + shapeID + '" '; 
        display += 'onmouseover="bingMapSearch.switchStyle(this, true, false); bingMapSearch.highlightMapPoint(\'' + shapeID + '\',false);" ';
        display += 'onmouseout="bingMapSearch.switchStyle(this, false, false); bingMapSearch.highlightMapPoint(\'' + shapeID + '\',true);" ';
        display += '>';
		
		if(isEN && item.websiteEN != ''){
			var websiteURL = item.websiteEN;
		}else{
			var websiteURL = item.website;
		}
		
		if (this.criteria.schoolType == 'Daycare service' || item.type == 'Daycare service') {
                display += '<h5>' + item.dayCareName + '</h5>';
                display += this.formatAddress(isEN, item, true);
				
                display += this.formatURL(websiteURL, null, true);
                display += this.formatURL(websiteURL, item.schoolName, true);
                display += this.formatURL(item.websiteSB, item.schoolBoard, true);
		}
		else {
            switch (item.type) {
                case "Elementary":
                case "Secondary":
                    display += '<h5>' + item.schoolName + '</h5>';
					if (item.gradesEn) {
							display += '<span>' + item.gradesEn + '</span><br /><br />';
						};
					if (item.editAddressEn) {
							display += '<span style="color:#058FCF; font-weight: bold; text-decoration: underline;">' + item.editAddressEn + '</span><br />';
						};
                    display += this.formatAddress(isEN, item, true);
                    display += this.formatURL(websiteURL, null, true);
                    display += this.formatURL(item.websiteSB, item.schoolBoard, true);
                    if (item.dayCareName.length > 0){
                        var daycare = this.formatURL(websiteURL, item.dayCareName, false);
                        display += '<p>';
                        display += bingMapSearchContent.daycareServiceLabel[filterObject.lang] + ": ";
                        display += (daycare.length > 0 ? daycare : item.dayCareName);
                        if (item.dayCarePhone.length > 0 && item.dayCarePhone != item.phone){
                            display += '<br/>' + item.dayCarePhone;
                        }
                        display += '</p>';
                    }
                    break;
                case "Post-secondary":
                    display += '<h5>' + (isEN && item.postSecondaryName.length > 0 ? item.postSecondaryName: item.schoolName) + '</h5>';
                    display += '<p>';
                    display += this.formatAddress(isEN, item, false);
                    var email = isEN ? item.email: item.emailFr;
                    if (email.length > 0) {
                        display += '<br/>' + '<a href="mailto:' + email + '">'+email+'</a>';
                    }
                    display += '</p>';
                    display += this.formatURL(websiteURL, null, true);
                    break;
                default:
                    display += '<h5>' + item.schoolName + '</h5>';
                    display += this.formatAddress(isEN, item, true);
                    display += this.formatURL(websiteURL, null, true);
                    break;
            }
        }
        display += '<div class="distance" style="float:left;color:#666666;font-size:14px;"></div>';
        display += '<div class="distanceBut"><a href="javascript:bingMapSearch.loadDirections(\'' + this.summaryPrefix + shapeID + '\', ' + item.lat + ', ' + item.lon + ')">' + bingMapSearchContent.distanceDisplayButtonLabel[filterObject.lang] + '</a></div>';
        display += '</td>';
        return '<tr>' + display + '</tr>';
    }
    this.mapSetView = function() {
        var zoomLevel = 0,
        zoom1 = 0,
        zoom2 = 0;
        var mapWidth = $(this.mapPlaceHolder).width(),
        mapHeight = $(this.mapPlaceHolder).height(),
        buffer = 0;
        var cLatitude = (this.criteria.maxLat + this.criteria.minLat) / 2;
        var cLongitude = (this.criteria.maxLon + this.criteria.minLon) / 2; //Determine the best zoom level based on the map scale and bounding coordinate information
        
		if (this.criteria.maxLon != this.criteria.minLon && this.criteria.maxLat != this.criteria.minLat) { //best zoom level based on map width
            zoom1 = Math.log(360.0 / 256.0 * (mapWidth - 2 * buffer) / (this.criteria.maxLon - this.criteria.minLon)) / Math.log(2); //best zoom level based on map height
            zoom2 = Math.log(180.0 / 256.0 * (mapHeight - 2 * buffer) / (this.criteria.maxLat - this.criteria.minLat)) / Math.log(2);
        } else { //if all dots are in the same location
            zoom1 = 19;
            zoom2 = 19;
        } //use the most zoomed out of the two zoom levels
		zoomLevel = Math.floor(Math.min(zoom1, zoom2));
		// map.SetCenterAndZoom(new VELatLong(this.criteria.lat, this.criteria.lon), zoomLevel,false);
        map.SetCenterAndZoom(new VELatLong(cLatitude, cLongitude), zoomLevel,false);
		if (map.GetZoomLevel() != zoomLevel) {
			map.SetZoomLevel(zoomLevel);
		}
    }
    this.highlightMapPoint = function(shapeID, boolMouseout) {
        var shape = map.GetShapeByID(shapeID);
        if (boolMouseout) {
            shape.SetCustomIcon(this.mapPointerActive(shapeID));
            shape.SetZIndex(1000);
        } else {
            shape.SetCustomIcon(this.mapPointerInactive());
            shape.SetZIndex(1001);
        }
    }
    this.switchStyle = function(obj, boolMouseover, boolScroll) {
        if (boolMouseover) {
            obj.style.backgroundColor = bingMapSearch.locationActiveBackColour;
        } else {
            obj.style.backgroundColor = bingMapSearch.locationInactiveBackColour;
        }
        if (boolScroll) {
            $(bingMapSearch.locationsDiv).stop();
            $(bingMapSearch.locationsDiv).animate({ scrollTop: obj.parentNode.offsetTop }, 1000);
        }
    }
    this.shapeInfo = function(e) {
        if (e.elementID != null) {
            var shape = map.GetShapeByID(e.elementID);
            var id = shape.GetID();
            var obj = document.getElementById(bingMapSearch.summaryPrefix + id);
            if (e.eventName == "onclick") {
                bingMapSearch.switchStyle(obj, true, true);
                bingMapSearch.SetZIndex(shape, 1);
            } else if (e.eventName == "onmouseover") {
                bingMapSearch.switchStyle(obj, true, false);
                bingMapSearch.SetZIndex(shape, 1);
            } else {
                bingMapSearch.switchStyle(obj, false, false);
                bingMapSearch.SetZIndex(shape, -1);
            }
        }
    }
    this.SetZIndex = function(shape, delta) { 
        /* We could use shape.SetZIndex here, but it may create problems with onmouseout, so */
        /* we use a different approach, by directly setting the zIndex to the element. */
        if (shape && shape.GetPrimitive) {
            var shapeElem = document.getElementById(shape.GetPrimitive(0).iid);
            if (shapeElem && shapeElem.style) shapeElem.style.zIndex = parseInt(shapeElem.style.zIndex) + delta;
        }
    }
    this.mapViewContains = function(lat, lon) { // determine if the lat and lon is shown on the map
        var y = parseFloat(lat);
        var x = parseFloat(lon);
        var view = map.GetMapView();
        var topleft = view.TopLeftLatLong;
        var bottomright = view.BottomRightLatLong;
        return (y < topleft.Latitude && y > bottomright.Latitude && x > topleft.Longitude && x < bottomright.Longitude);
    }
    this.checkPoints = function() {
        var display = bingMapSearchContent.resultSummary[filterObject.lang];
        var list = bingMapSearch.result;
        if (typeof(list) == 'undefined') return;
        var count = 0;
        for (var i = 0; i < list.length; i++) {
            var item = list[i];
            var shapeID = "#" + bingMapSearch.summaryPrefix + item.shapeID;
            if (bingMapSearch.mapViewContains(item.lat, item.lon)) { //in View
                $(shapeID).show();
                count++;
            } else {
                $(shapeID).hide();
            }
        }
        $(bingMapSearch.resultSummary).html(display.replace('[count]', count).replace('[total]', list.length));
        
    }
}
$(document).ready(function() {
    $(bingMapSearch.controlSearch).click(function() {
        bingMapSearch.performSearch();
    });
    $(bingMapSearch.controlCity).blur(function() {
        bingMapSearchControls.clearPostalCode(this);
    });
    $(bingMapSearch.controlPostalFirst).blur(function() {
        this.value = this.value.toUpperCase();
        bingMapSearchControls.clearCity(this);
    }).focus(function() {
        bingMapSearchControls.postalFirstUpdated = false;
        this.select();
    }).keyup(function(e) {
        bingMapSearchControls.focusPostalLast(this, e.keyCode);
    });
    $(bingMapSearch.controlPostalLast).blur(function() {
        this.value = this.value.toUpperCase();
        bingMapSearchControls.clearCity(this);
    }).focus(function() {
        this.select();
    });
    $(bingMapSearch.controlPublicSchool).click(function() {
        bingMapSearchControls.currentPublicSchoolChecked = bingMapSearchControls.radiobuttonHandler(this, bingMapSearchControls.currentPublicSchoolChecked);
    });
    $(bingMapSearch.controlCatholicSchool).click(function() {
        bingMapSearchControls.currentCatholicSchoolChecked = bingMapSearchControls.radiobuttonHandler(this, bingMapSearchControls.currentCatholicSchoolChecked);
    });
    
    if ($.browser.msie && $.browser.version < 8) {
    }
    else
    {
//            alert($.browser.msie);
//            alert($.browser.version);
    }
});