function addFavorite(title,url){
	title=title?title:document.getElementsByTagName('title')[0].text;;
	url=url?url:window.location.href;
	try{
		window.external.addFavorite(url,title);
	}catch(e){
		try{
			window.sidebar.addPanel(title,url,'');
		}catch(e){
			alert('您的浏览器不支持或不允许此操作，请按"Ctrl+D"或手动加入收藏。');
		}
	}
}
function setHome(url){
	url=url?url:window.location.href;
	try{
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch(e){
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
			}
			var prefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',url);
		}else{
			alert('您的浏览器不支持或不允许此操作，请您手动设为首页。');
		}
	}
}
function resize(o,w,h){
	var x=o.width/w,y=o.height/h;
	if(x>1&&x>=y)o.width=w;
	if(y>1&&y>=x)o.height=h;
	o.resized=true;
	o.onload=null;
}
function trim(str){
	var l=/^\s+/,r=/\s+$/;
	return str?(str.trim?str.trim():str.toString().replace(l,'').replace(r,'')):'';
}
function cookie(name, value, options) {
    if (typeof value != 'undefined') {
        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();
        }
        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 {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
function valid(id,param){
	var dom=$('#'+id);
	var tip=$("#msg"+id);
	var val=trim(dom.val());
	if(param.req&&val.length==0){
		return msg(tip,param.reqMsg);
	}
	if(!param.req&&val.length==0){
		return msg(tip);
	}
	if(param.max&&val.length>param.max){
		return msg(tip,param.maxMsg);
	}
	if(param.reg&&!param.reg.test(val)){
		return msg(tip,param.regMsg);
	}
	if(param.ajax){
		var r=1;
		$.ajax({
			async:false,
			url:'http://member.topoyo.com/ajax_myhome.php',
			data:{value:val,type:'verify'},
			dataType:'text',
			success:function(d,s){
				if(d.indexOf('true')>-1){
					r=msg(tip);
				}else{
					r=msg(tip,param.ajaxMsg);	
				}
			},
			error:function(){
				r=msg(tip,param.ajaxMsg);	
			}
		});
		return r;
	}
	if(!param.ajax){
		return msg(tip);
	}
}
function msg(tip,msg){
	tip.html(msg?msg:'');
	return msg?1:0;
}
$(function(){
	$("#banner").cycle({
		fx:'fade',
		timeout:'5000'
	});	
});
