//判断浏览器类型
if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=='Netscape')?1:0;
	var isIE=(navigator.appName.indexOf('Microsoft')!=-1)?1:0;
}

var userDefaultPhoto = new Image;
userDefaultPhoto.src = '/images/user_default_photo.gif';


//################### cookie start ###################

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (';', offset);
	if (endstr == -1) {
        endstr = document.cookie.length;
    }
	return unescape(document.cookie.substring(offset, endstr));
}
function getCookie (name) {  
	var arg = name + '=';  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg){      
            return getCookieVal (j);
        }
        i = document.cookie.indexOf(' ', i) + 1;    
        if (i == 0) { 
            break;
        }  
	}  
	return null;
}
function setCookie (name, value) { 
    var exp1 = null;
//	var exp1 = new Date(); 
//	exp1.setTime(exp1.getTime() + (30*24*60*60*1000));
	var argv = setCookie.arguments;  
	var argc = setCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : exp1;
	var path = (argc > 3) ? argv[3] : '/';  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + '=' + escape (value) + 
	((expires == null) ? '' : ('; expires=' + expires.toGMTString())) + 
	((path == null) ? '' : ('; path=' + path)) +  
	((domain == null) ? '' : ('; domain=' + domain)) +    
	((secure == true) ? '; secure' : '');
}
function deleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = getCookie (name);  
	document.cookie = name + '=' + cval + '; expires=' + exp.toGMTString();
}

//################### cookie end ###################



//################### Login or Logout start ###################
      function isLogin() {
        var a = getCookie('MyID');
        return (a != null && a != '');
    }

    
    function getLoginLink() {
        var bLogined = isLogin();
        var sLoginLink = '';
        if (bLogined) {
            sLoginLink = '<a href="#" onclick="execLogout(); return false;" class="a5">退出</a>';
        } else {
            sLoginLink = '<a href="/member/login.html" class="a5">登录</a>';
        }
        return sLoginLink;
    } 

    /* 功能： 执行退出 */
    function execLogout() {
        if(window.confirm('您确定要退出吗？')){
            window.location.href='/php/member/logout.php';
        }
    } 

//################### Login or Logout end ###################



//################### Open Little Book start ###################
    /* 
    功能： 打开窗口显示指定会员的小本子
    参数： nUserId: 会员ID
          opModule: 所在模块，用于处理小本子右边的按钮
          sUrlLeft: 小本子左边iframe的URL
          sUrlMain: 小本子右边iframe的URL
          sOther:   其他参数（备用）
    参数：(无)
    */
    function openLittleBook(nUserId, opModule, sUrlLeft, sUrlMain, sOther) {
        var nNeedWidth = 932;
        var nNeedHeight = 538;
        var nCurrentWidth = 0;
        var nCurrentHeight = 0;

        var nCurrentTop = top.screenTop + 10;
        var nCurrentLeft = top.screenLeft + 10;
        if(nCurrentTop > 100 || nCurrentLeft > 100){
            nCurrentTop = 0;
            nCurrentLeft = 0;
        }

        var sFeature = 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizeable=no'
        sFeature += ',left='+nCurrentLeft+',top='+nCurrentTop;
        if(nNeedWidth > screen.width) {
            nCurrentWidth = screen.width;
        } else {
            nCurrentWidth = nNeedWidth;
        }
        if(nNeedHeight > (screen.height - 60)) {
            nCurrentHeight = screen.height - 60;
        } else {
            nCurrentHeight = nNeedHeight;
        }
        sFeature += ',width=' + nCurrentWidth + ',height=' + nCurrentHeight;
        if(nCurrentWidth < nNeedWidth || nCurrentHeight < nNeedHeight) {
            sFeature += ',scrollbars=yes';
        } else {
            sFeature += ',scrollbars=no';
        }

		if('undefined' != typeof(sUrlMain)){
			if(sUrlMain.indexOf('/')>=0){
				sUrlLeft = escape(sUrlLeft);
				sUrlMain = escape(sUrlMain);
			}
		}

        sWinName = 'MemberLittleBook' + nUserId;
        var sUrlPage = '/member/life_book.html';
		if("undefined" == typeof(opModule)){
			opModule = "";
		}
		if("undefined" != typeof(nUserId) && "" != nUserId){
			sUrlPage += '?userId=' + nUserId + '&opModule=' + opModule + '&sUrlLeft=' + sUrlLeft + '&sUrlMain=' + sUrlMain + '&sOther=' + sOther;
		}

        oWin = window.open(sUrlPage, sWinName, sFeature);
        oWin.focus();
    }

    	function openSingle(sUrl){
        sWinName = "single";
		sFeature = "scrollbars=yes,width=420,height=366,left=10,top=10";
		oWin = window.open(sUrl, sWinName, sFeature);
    }

function openLifebook(){
    //Begin get the size of the lifebook window
    var nNeedWidth = 980;
    var nNeedHeight = 670;
    if(screen.width < 1024){
        nNeedWidth = Math.round(nNeedWidth * 0.78125);
        nNeedHeight = Math.round(nNeedHeight * 0.78125);
    }
    var nCurrentWidth = 0;
    var nCurrentHeight = 0;

    var nCurrentTop = top.screenTop + 10;
    var nCurrentLeft = top.screenLeft + 10;
    if(nCurrentTop > 100 || nCurrentLeft > 100){
        nCurrentTop = 0;
        nCurrentLeft = 0;
    }

    if(nNeedWidth > screen.avilWidth) {
        nCurrentWidth = screen.avilWidth;
    } else {
        nCurrentWidth = nNeedWidth;
    }
    if(nNeedHeight > screen.avilHeight) {
        nCurrentHeight = screen.avilHeight;
    } else {
        nCurrentHeight = nNeedHeight;
    }
    var sFeature = 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizeable=yes';
    sFeature += ',left='+nCurrentLeft+',top='+nCurrentTop;
    sFeature += ',width=' + nCurrentWidth + ',height=' + nCurrentHeight;
    if(nCurrentWidth < nNeedWidth || nCurrentHeight < nNeedHeight) {
        sFeature += ',scrollbars=yes';
    } else {
        sFeature += ',scrollbars=no';
    }
    //End get the size of the lifebook window

    //get parameters
    var aArg = openLiftbook.arguments;
    var nArg = aArg.length;
    var nOwnerID = (nArg>0)? aArg[0] : '';
    var sModule = (nArg>1)? aArg[1] : '';
    var sUrlMenu = (nArg>2)? escape(aArg[2]) : '';
    var sUrlMain = (nArg>3)? escape(aArg[3]) : '';
    var sOther = (nArg>4)? aArg[4] : '';

    var sWinName = 'winLifebook_' + nOwnerID;
    var sUrlPage = '/lifebook/default/index.html';
    if(nOwnerID != ''){
        sUrlPage += '?nOwnerID=' + nOwnerID + '&sModule=' + sModule + '&sUrlMenu=' + sUrlMenu + '&sUrlMain=' + sUrlMain + '&sOther=' + sOther;
    }

    oWin = window.open(sUrlPage, sWinName, sFeature);
    oWin.focus();
    return oWin;
}
//################### Open Little Book end ###################

//在线帮助图标
function writeOnlineHelpButton(){
//    document.write('<sc'+'ript language="JavaScript" src="http://testing.chinacircle.com/~cysig/phplive/js/status_image.php?base_url=http://testing.chinacircle.com/~cysig/phplive&l=rock&x=1&deptid=0&"></sc'+'ript>');
    var sFeature = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizeable=no,scrollbars=no,width=350,height=200,left=10,top=10";
    var sStr = '<img src="/images/mycc/help.gif" border="0" style="cursor:pointer" onclick="window.open(\'/help/help_online.html\', \'help_online\',\''+sFeature+'\')">';
    document.write(sStr);
}
//交友速递图标
function writeMobileSubscribeButton(){
    document.write('<a href="/php/club/club_detail.php?clubid=2856" target="_blank"><img src="/images/mycc/kefusmalllogo.jpg" border="0" ></a>');
//    document.write('<a href="#"><img src="/images/mycc/alerts.gif" border="0" onclick="window.alert(\'将于近期推出，敬请关注。\'); return false;"></a>');
}
//更新网页
function updateStaticPage(rsModule, rnTime){
    var objTime = new Date();
    var nNowTime = Math.ceil(objTime.getTime() / 1000);
    if(nNowTime > rnTime){
        document.write('<iframe width="0" height="0" src="/php/common/com_update_static_page.php?sModule='+rsModule+'&nTime='+rnTime+'"></iframe>');
    }
}
//获取URL的参数
function getValueFromURL(sName){
    var sValue = '';
    var sURL = window.location.href;
    if(sName.length>0 && sURL.indexOf('?')>0){
        var sParameter = sURL.substr(sURL.indexOf('?')+1);
        var aTmpParameter = sParameter.split('&');
        for(var i=0; i<aTmpParameter.length; i++){
            if(aTmpParameter[i].indexOf('=')>0){
                aTmp = aTmpParameter[i].split('=');
                if(aTmp[0] == sName){
                    sValue = aTmp[1];
                    break;
                }
            }
        }
    }
    return sValue;
}
//网站推广iFrame
function website_promote(){
    inviteFriend();
    statistic_from_1tong();
}

//邀请朋友
function inviteFriend(){
    var sCommendID = getValueFromURL('commandid');
    if(sCommendID==''){
        sCommendID = getValueFromURL('commendid');
    }
    if(sCommendID=='40232'){ sCommendID = ''; }
    var sInviterID = getValueFromURL('inviterid');
    var sInviterCode = getValueFromURL('invitercode');
    var sInviterType = getValueFromURL('invitertype');
    var sInviterExtra = getValueFromURL('inviterextra');

    if(sCommendID!=''){
        setCookie('promoteWebsiteByUserID', sCommendID);
    }
    if(sInviterID!=''){
        setCookie('promoteWebsiteByInviterId', sInviterID);
    }
    if(sInviterCode!=''){
        setCookie('promoteWebsiteByInviterCode', sInviterCode);
    }
    if(sInviterType!=''){
        setCookie('promoteWebsiteByInviterType', sInviterType);
    }
    if(sInviterExtra!=''){
        setCookie('promoteWebsiteByInviterExtra', sInviterExtra);
    }
//    document.write('<iframe name="iframe_website_promote" id="iframe_website_promote" width="0" height="0" src="http://pic2.9i0.com/admin/website_promote/hits.php?commendid='+id+'" frameborder="0" scrolling="no"></iframe>');
}

//第三方流量统计
function statistic_from_1tong(){
    document.write('' +
        '<table width="780" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#d0d0d0">' +
        '  <tr> ' +
        '    <td height="15">&nbsp;</td> ' +
        '  </tr> ' +
        '  <tr> ' +
        '    <td align="center"><scr'+'ipt src="http://vip6.1tong.com.cn/link/count.php?id=121"></scr'+'ipt></td> ' +
        '  </tr> ' +
        '</table> '
    );
}

//
//显示会员在线状态的符号
function writeOnlineStatus(rnUserID){
    document.write('<label id="tagOnlineStatus'+rnUserID+'" title="离线" style="color:#d0d0d0;">●</label>');
}

//设置各模块的广告内容
function ouputAD(sModule) {
    outputAD(sModule);
}

//设置各模块的广告内容
function outputAD(sModule) {
    switch (sModule) {
        case 'club':
            break;
        case 'blog':
            break;
        case 'photo':
            break;
        case 'video':
            break;
        case 'soho':
            break;
        case 'job':
            break;
        case 'mycc':
            break;
        case 'beautiful':
            break;
        case 'search':
            break;
    }
    
    //取出下一个广告
    var nAD = getCookie("nChinaCircleAD");
    if ("" == nAD || null == nAD || nAD > 2) {
        nAD = 0;
    } else {
        nAD = parseInt(nAD);
    }
    switch (nAD) {
        case 0:
            sType = "swf";
            sFile = "/images/adv/paper.swf";
            sUrl = "";
            break;
        case 1:
            sType = "img";
            sFile = "/images/adv/clubweekly05.jpg";
            sUrl = "http://www.chinacircle.com/php/club/club_bbs_detail.php?clubid=2732&opFlag=detail&id=64391";
            break;
        default:
            sType = "img";
            sFile = "/images/adv/weeklytopic07.jpg";
            sUrl = "http://www.chinacircle.com/php/video/video_gest_detail.php?videoId=616&code=afed68085f713b043939c3a2bbc93ae4";
            break;
    }
    
    //设置COOKIE显示下一个广告
    nAD += 1;
    if (3 == nAD) {
        nAD = 0;
    }
    setCookie("nChinaCircleAD", nAD);

    if ("swf" == sType) {
        //输出FLASH
        sHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="548" height="177"><param name=movie value="'+sFile+'"><param name=quality value=high><param name=wmode value=opaque><embed src="'+sFile+'" quality=high width="548" height="177" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash"></embed></object>';
    } else {
        //输出图像
        sHTML = '<a href="'+sUrl+'" target="_blank"><img src="'+sFile+'" width="549" height="179" border="0"></a>';
    }
    document.write(sHTML);
}

inviteFriend();
