function isEmail(strEmail){
    return !(strEmail==""||strEmail.search(/^\s*\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+(\s*,\s*\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+)*\s*$/) == -1);
}

function isNumber(num){
    return ! NaN(num);
}

function initSlider(){
    initSlider1(5, 35);
}
function initSlider1(psize, mleft){
    var pageSize = 5; 
    var currentPage=0;
    var marginLeft=35;
    
    if(psize!=null)
        pageSize=psize;
    if(mleft!=null)
        marginLeft=mleft;
    
    var showPage=function (page)
    {
        var unitwidth = $('div#downContent').find('li').first().width()+marginLeft;
        var len = $('div#downContent').find('li').length;
        var page_number = Math.ceil(len/pageSize);
        
        if( !$('div#downContent').is(":animated") ){
            currentLeft=page*pageSize;
            $('div#downContent').animate({
                left:"-"+unitwidth*currentLeft+"px"
            }, "fast", function() {
                $('.ban_tiright ul li a.active').removeClass('active');
                currentPage=page;
                pageid=1+parseInt(page);
                $("#view"+pageid).addClass("active");
            
                if ( $.browser.webkit && $.browser.safari)
                {
                    document.getElementById("downContent").style.display = "none";
                    setTimeout('document.getElementById("downContent").style.display = "block";',1); 
                }

            });
        }
        if(page==page_number-1)
            $('span#buttom_right img').css({
                "opacity":"0.5",
                "filter":"Alpha(opacity=50)"
            });
        else
            $('span#buttom_right img').css({
                "opacity":"1",
                "filter":"Alpha(opacity=100)"
            });
        if(page==0)
            $('span#buttom_left img').css({
                "opacity":"0.5",
                "filter":"Alpha(opacity=50)"
            });
        else
            $('span#buttom_left img').css({
                "opacity":"1",
                "filter":"Alpha(opacity=100)"
            });
    }
    
    $('span#buttom_right').click(function(){
        var len = $('div#downContent').find('li').length;
        var page_number = Math.ceil(len/pageSize);
        if(currentPage<page_number-1)
            showPage(currentPage+1);
    });
    $('span#buttom_left').click(function(){
        if(currentPage>0)
            showPage(currentPage-1);
    });
    $('.ban_tiright ul li a').click(function(){
        var page = $(this).attr('page');
        showPage(parseInt(page));
    });
}

function dealSlider(psize, mleft, containerid){
    var pageSize = 5; 
    var currentPage=0;
    var marginLeft=35;
    
    if(psize!=null)
        pageSize=psize;
    if(mleft!=null)
        marginLeft=mleft;
    
    var showPage=function (page)
    {
        var unitwidth = $('#'+containerid+' div.downContent').find('li').first().width()+marginLeft;
        var len = $('#'+containerid+' div.downContent').find('li').length;
        var page_number = Math.ceil(len/pageSize);
        
        if( !$('#'+containerid+' div.downContent').is(":animated") ){
            currentLeft=page*pageSize;
            $('#'+containerid+' div.downContent').animate({
                left:"-"+unitwidth*currentLeft+"px"
            }, "fast", function() {
                currentPage=page;
                pageid=1+parseInt(page);
/*                $('#'+containerid+' .ban_tiright ul li a.active').removeClass('active');
                currentPage=page;
                pageid=1+parseInt(page);
*/
                if ( $.browser.webkit && $.browser.safari)
                {
                    $(".downContent").hide();
                    setTimeout('$(".downContent").show();',1); 
                }
            });
        }
        if(page==page_number-1)
            $('#'+containerid+' span.buttom_right img').css({
                "opacity":"0.5",
                "filter":"Alpha(opacity=50)"
            });
        else
            $('#'+containerid+' span.buttom_right img').css({
                "opacity":"1",
                "filter":"Alpha(opacity=100)"
            });
        if(page==0)
            $('#'+containerid+' span.buttom_left img').css({
                "opacity":"0.5",
                "filter":"Alpha(opacity=50)"
            });
        else
            $('#'+containerid+' span.buttom_left img').css({
                "opacity":"1",
                "filter":"Alpha(opacity=100)"
            });
    }
    
    $('#'+containerid+' span.buttom_right').click(function(){
        var len = $('#'+containerid+' div.downContent').find('li').length;
        var page_number = Math.ceil(len/pageSize);
        if(currentPage<page_number-1)
            showPage(currentPage+1);
    });
    $('#'+containerid+' span.buttom_left').click(function(){
        if(currentPage>0)
            showPage(currentPage-1);
    });
}

function addBookmark(title,url) {

    var msg_netscape = "NetScape message";
    var msg_opera    = "This function does not work with this version of Opera.  Please bookmark us manually.";
    var msg_other    = "Your browser does not support automatic bookmarks.  Please bookmark us manually.";
    var ns="Netscape and FireFox users, use CTRL+D to bookmark this site."
    var agt          = navigator.userAgent.toLowerCase();


    if (agt.indexOf("opera") != -1) 
    {
        if (window.opera && window.print)
        {
            return true;
        } else 
{
            alert(msg_other);
        }
    }    
    else if (agt.indexOf("firefox") != -1) alert(ns);
    else if ((agt.indexOf("msie") != -1) && (parseInt(navigator.appVersion) >=4)) window.external.AddFavorite(url,title); 
    else if (agt.indexOf("netscape") != -1) alert(ns);         
    else if (window.sidebar && window.sidebar.addPanel) alert(ns);
    else alert(msg_other);
  
}

var callBack = function(obj){
    return function(){
        resizeImage(obj);
    };
};

function resizeImage(img){
    var maxsize=img.getAttribute('maxsize');
    if(maxsize==null)
        maxsize=104;
    else
        maxsize=parseInt(maxsize);

    img.style.display="block";
    if(img.width==0||img.height==0)
    {
        img.style.display="none";
        setTimeout(callBack(img),100); 
        return;
    }
    if(img.width>=img.height&&img.width>maxsize)
    {
        img.width=maxsize;
    }
    else if(img.width<img.height&&img.height>maxsize)
    {
        img.height=maxsize;
    }
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
