﻿/*
 * jQuery base plug-in 0.1
 *
 *
 * Copyright (c) 2010 uutan (uutan@qq.com)
 *
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
 

$(function(){
    /* 全站tab 切换 */
    var tabset = $('ul.tab-holder li');
    tabset.mouseover(function(){
        $(this).addClass('on').siblings().removeClass('on');
        $('div.bd div.tab-panel').eq(tabset.index(this)).show().siblings().hide();
    });
});
	

//--------------------  兼设为首页 & 加入收藏  --------------------
jQuery.home77 = {
    _homeUrl: 'http://www.028028.net',
    homepage: function(objIn){//设为首页  $.home77.homepage(this);
        try{
            objIn.style.behavior='url(#default#homepage)';
            objIn.setHomePage(this._homeUrl);
        }
        catch(e){
            alert("您现在使用的浏览器无法自动设为首页，请手动设置！");
        }
    },
    addFavorite: function(){//添加为收藏  $.home77.addFavorite();
        var url = this._homeUrl;
        var title = "成都房产超市网站-成都楼盘-成都二手房-成都租房-成都商铺";
        if (window.sidebar) window.sidebar.addPanel(title, url, "");
        else if( document.all ) window.external.AddFavorite(url, title);
        else if( window.opera && window.print ) return true;
    },
    addSearch: function(pam){var url = "/default/search";
        $.get(url,pam, function(data){
            $('#load_home77maxsearch').hide();$('#home77maxsearch').html(data);});
    }
};


//--------------------  兼容之前的 TAB 标签切换  --------------------
jQuery.Tabs = {
    _tab: 'tab_a',
    _sub: 'sub_a',
    show: function(id,c){
        $('#'+this._tab+id).get(0).className = c;
        $('#'+this._sub+id).show();
    },
    hide: function(id,a,b,c,e) // 当前id号,a为开始ID号，b为结束ID号,c为显示类名,e为显示类名
    {
        for(i = a; i < b; i++)
        {
            $('#'+this._tab+i).get(0).className = e;
            $('#'+this._sub+i).hide();
        }
    },
    set: function(id,a,b,c,e){
        this.hide(id,a,b,c,e);
        this.show(id,c);
    }
};


//--------------------  广告代码展示  --------------------
/**
  * width 宽度
  * height 高度
  * url 访问地址
  * file 广告文件
  * id  广告标识
  */
jQuery.fn.extend({
    showFlash: function(width,height,url,file,id) {
		html ="<embed width='"+width+"' height='"+height+"' src='"+file+"' quality='autohigh' wmode='opaque' type='application/x-shockwave-flash' plugspace='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' id='obj_randomDiv_"+id+"'></embed>";
		
		if(url != '' && url != '###') html +="<a href='"+url+"' target='_blank'><img src='/images/place.gif' style='position:absolute;left:0px;top:0px;width:"+width+";height:"+height+";border:none;'/></a>";
        return this.html(html);
    },
    showImage: function(width,height,url,file,id) {
        html ="<a href='"+url+"' target='_blank'>";
        html +="<img src='"+file+"' width="+width+" height="+height+" border='0' /></a>";
        return this.html(html);
    },
    showPhoto: function(w,h,pics,links,texts){
        var swf_height = h+22;
        html = '<object ID="focus_flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ w +'" height="'+ swf_height +'">';
        html += '<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="/flash/pixviewer_andy.swf"><param name="quality" value="high">';
        html += '<param name="menu" value="false"><param name=wmode value="opaque">';
        html += '<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+w+'&borderheight='+h+'&textheight=22">';
        html += '<embed ID="focus_flash" src="/flash/pixviewer_andy.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+w+'&borderheight='+h+'&textheight=22" menu="false" quality="high" width="'+ w +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        html += '</object>';
        return this.html(html);
    }
});


//--------------------  新闻内容字体大小切换  --------------------
jQuery.Pages = {
    _speed: function(div,cls)
    {
        var id = div || "artibody";
        $('#'+id).removeClass();
        $('#'+id).addClass(cls);
    },
    normal: function(div){ // 12号字体 $.font.normal();
        return this._speed(div,'normal');
    },
    ssmall: function(div){// 16号字体 $.font.ssmall();
        return this._speed(div,'font_ssmall');
    },
    large: function(div){ // 20号字体 $.font.large();
        return this._speed(div,'large');
    },
    close: function(){ // 关闭页面
        parent.window.opener = null;
        parent.window.open("", "_self");
        parent.window.close();
    }
};




//--------------------  Cookie  --------------------
var Cookie = {
	setCookie : function(name, value, expires, path, domain, secure)
	{
		var path=document.getElementById("hidRoot").value;
		if(domain == null) domain = '';
       
        expiryday=new Date();
        expiryday.setTime(expiryday.getTime()+30*30*24*60*60*1*1000);
 
	    // alert(the_cookie_date);  
	    // alert((today.getTime() + (2*24*60*60*1000)).toGMTString());
	    
		document.cookie = name + "=" + escape(value) + "; expires=" + expiryday.toGMTString() + 
			// ((expires) ? "; expires=" + expiryday.toGMTString() : "") +
			((path) ? "; path=" + path : "; path=/") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
	},

	getCookie : function(name)
	{
		var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));

		if (arr != null)
		{
			return unescape(arr[2]);
		}
		return null;
	},

	clearCookie : function(name, path, domain)
	{
		if (Cookie.getCookie(name))
		{
			 document.cookie = name + "=" +
				((path) ? "; path=" + path : "; path=/") +
				((domain) ? "; domain=" + domain : "") +
				";expires=Fri, 02-Jan-1970 00:00:00 GMT";
		}
	}
};


$(document).ready(function(){
	var working = false;
	$('#addCommentForm').eq(0).submit(function(event){
		if (event) event.preventDefault();
        if (window.event) window.event.returnValue = false;
		if(working) return false;
		
		working = true;
		$('#submit').val('正在保存数据...').attr('disabled',true);
		$('span.error').remove();
		var data = $(this).serialize();
		$.post(this.action,data,function(msg){
			working = false;
			$('#submit').val('发布评论').attr('disabled',false);
			if(msg.status){
				$(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
				$('[clear=true]').val('');
			}
			else {
				$.each(msg.errors,function(k,v){
					$('label[for='+k+']').append('<span class="error">'+v+'</span>');
				});
			}
		},'json');

	});
	
});

