/*-------------------------------------------
    New Common JS File.
    Dependency: jQuery 1.2.6
    Henrik G / Sept 2008
-------------------------------------------*/

var top, topH, left, minX, maxX, minY, maxY, maxHY, gapSize, gapTop, gapBottom, mapExtend;
top = topH = left = -999;
minX = maxX = minY = maxY = maxHY = gapTop = gapBottom = gapSize = mapExtend = 0;

var $j = jQuery.noConflict();

$j(document).ready(function(){

        initEmailNotification();

});

function initEmailNotification() {
    if($j('#nfLoading').html()=="")
        $j('#nfLoading').html('<img src="/sbiir/images/loading-small.gif" alt="">');

    $j('#notificationForm').submit(function(event) {
        event.preventDefault();
        $j('#nfSubmit').addClass('hide');
        $j('#nfLoading').removeClass('hide');
        $j('#nfMin').val($j('#nfMin').val().replace('.',','));
        $j('#nfMax').val($j('#nfMax').val().replace('.',','));
        var callback = function(data) {
            $j('#nfSubmit').removeClass('hide');
            $j('#nfLoading').addClass('hide');
            alert(data);
        };
        var params = 'tsid=' + $j('#nfTsid').val() + '&min=' + $j('#nfMin').val() + '&max=' +
                     $j('#nfMax').val() + '&email=' + $j('#nfEmail').val();
        $j.post('../common/notification.action', params, callback);
     });
}



function setMain(d,p) {
    $j('#moDate').text(d);
    $j('#moClosing').text(p);
}


function openNews(s) {
    s = s.replace(/,/g,' ');
    window.open('/sbiir/common/defaultnews.page?magic=(cc (newstype news) (newsid ' + s + '))', 'win','status=1,height=600,width=600,resizeable=1,scrollbars=1')
}


function initImageMap() {
    $j('#chartContainer area').each(function() {
        var coords = $j(this).attr('coords').split(',');
        if((coords[3]-coords[1])>30) {
            // Press & insider links are now excluded
            $j(this).attr('coords',coords[0]+','+coords[1]+','+coords[2]+','+coords[3]+mapExtend);
            $j(this).css({ cursor: 'default' });
        }
    });
}

function chartMouseMove(e) {

    if(e.pageX > minX && e.pageX < maxX && e.pageY > minY && e.pageY < maxY)
        left = e.pageX;

    if(e.pageX > minX && e.pageX < maxX && e.pageY > minY && e.pageY < maxHY && (e.pageY < gapTop || e.pageY > gapBottom))
        topH = e.pageY;

    $j('#bar').css({ top: top+"px", left: left+"px" });
    $j('#bar-h').css({ top: (topH-1)+"px", left: minX+"px" });

}

function initDatePickers() {
    $j('.datepicker').each(function(){

        $j(this).blur(function() {
                /* Parse the date. (Using DateJS, http://www.datejs.com/) */
                var d = this.value;

                if(d.length==6 && d>100) {
                    d=d.substring(0,2) + '-' + d.substring(2,4) + '-' + d.substring(4);
                    if(d.substr(0,1)=='9' || d.substr(0,1)=='8' || d.substr(0,1)=='7')
                        $j(this).val('19' + d);
                    else
                        $j(this).val('20' + d);
                }
                else if(d.length==8 && d>20000) {
                    d=d.substring(0,4) + '-' + d.substring(4,6) + '-' + d.substring(6);
                    $j(this).val(d);
                }
                else {
                    try {
                        $j(this).val(parseDate(d,'yyyy-MM-dd'));
                    }
                    catch(err) {
                        //Do nothing, leave it to iserver.
                    }
                }
                setExcelLink();
            });
        });

}

function setExcelLink() {
    // Override in customer.js
}

function parseDate(s,f) {
    try {
        var d = Date.parse(s);
        s = d.toString(f);
    }
    catch(err) {
        //Do nothing, leave it to iserver.
    }
    return s;
}



