﻿// JScript 文件


String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "")
};
function callback(container,response)
{
	container.children('.star-rating-result').html("resp from server is:"+response);
}

function getCookie(name){
	try{
		var str = (document.cookie.match(new RegExp("(^"+name+"| "+name+")=([^;]*)"))==null)?"":decodeURIComponent(RegExp.$2);
		if (str != '') {
			return str;
		}else {
			return "";
		}
	}catch(e){
		return "";
	};
}

function add_fav(nID)
{
     var sUri = "http://www.guoing.com/Ajax/movie_star.aspx?type=12&mid=" + nID;
     $.get(sUri, function(data){
       if (data == "No Login")
       {
            loginF('');
       } 
       if (data == "0") {
            alert("您已收藏了此短片！");
        }
       if (data == "1") {
            var iCount = document.getElementById("fav"+nID).innerHTML;
            iCount = parseInt(iCount) + 1;
            document.getElementById("fav"+nID).innerHTML = iCount;
            alert("已收藏成功！");
        }
     });
}

function recommand(nID)
{
     var sUri = "http://www.guoing.com/Ajax/movie_star.aspx?type=13&mid=" + nID;
     $.get(sUri, function(data){
        
       var d=data.split("_");
        a=d[1];d=d[0];
       
        if(a>0)
        { 
            document.getElementById("recommmand"+d).innerHTML = a;
            alert("推荐成功！");
        }
    });
}

function GetMovieTips(nID)
{
     var sUri = "http://www.guoing.com/Ajax/movie_tips.aspx?type=1&mid=" + nID;
     $.get(sUri, function(data){
        document.getElementById("movieTips").innerHTML = data;
    });
}

function GetRandomMovieList()
{
     var sUri = "http://www.guoing.com/Ajax/movie_list.aspx?type=1";
     $.get(sUri, function(data){
        document.getElementById("randomMovieList").innerHTML = data;
    });
}

function GetMovieComment(nID)
{
     var sUri = "http://www.guoing.com/Ajax/movie_tips.aspx?type=2&mid=" + nID;
     $.get(sUri, function(data){
        document.getElementById("movieComments").innerHTML = data;
    });
}

function GetMovieDetail(nID)
{
     var sUri = "http://www.guoing.com/Ajax/movie_tips.aspx?type=3&mid=" + nID;
     $.get(sUri, function(data){
        document.getElementById("movieDetail").innerHTML = data;
    });
}

function GetMovieFen(nID)
{
    var sUri = "http://www.guoing.com/Ajax/movie_tips.aspx?type=4&mid=" + nID;
     $.get(sUri, function(data){
        if(data.length >= 5)
        {
        
            var d=data.split("_");
           
            document.getElementById("number_b").innerHTML = d[1];
            document.getElementById("number_s").innerHTML = "." + d[2];
            document.getElementById("viewInfo_lblFenCount").innerHTML = d[0];
            document.getElementById("demo").innerHTML = "";
            $('#demo').raterShow('http://www.guoing.com/Ajax/movie_star.aspx',{params:{p:2,x:3},curvalue:d[3],maxvalue:10,style: 'middle',poslen:2,danwei: '分', EventRated:callback});
            
        }
    });
}


var subjectid=0;
var nOperType = 0;
function doDelete(a)
{
    nOperType = 1;
    subjectid=a;
    document.getElementById("iframe_proxy").src="http://www.guoing.com/Ajax/proxy.htm?"+(Math.floor(Math.random()*99999)+1)
}

function doUsefulVotes(a)
{
    nOperType = 0;
    subjectid=a;
    document.getElementById("iframe_proxy").src="http://www.guoing.com/Ajax/proxy.htm?"+(Math.floor(Math.random()*99999)+1);
}
function xlAjax(a,d,b){return document.getElementById("iframe_proxy").contentWindow.pxlAjax(a,d,b)}
function showUsefulVotes(a)
{    
    if (getCookie("guoing%5FCookie") != "" )
    {
        var d=a.responseText.split("_");
        a=d[1];d=d[0];if(a>0)document.getElementById("movie_subject_"+d).innerHTML=a;else if(a=="-1")alert("不存在短评主题!");else a=="-2"?alert("您已经对该短评投票过了!"):alert("投票出错!")
    }
    else
    {
        alert("请先登录！");
    }
}

function showDelete(a)
{

    var d=a.responseText.split("_");
    a=d[1];d=d[0];
    if(a>0)
    {
        document.getElementById("tips"+d).style.display = "none";
        alert("删除成功！");        
        GetMovieTips(nMovieID);
    }
    else 
        alert("删除评论出错!")
}
    
function __init__(a) {
    if(nOperType == 0)
        a && xlAjax("http://www.guoing.com/Ajax/movie_star.aspx?Type=3&tid=" + a + "&rnd=" + (Math.floor(Math.random() * 99999) + 1), "", showUsefulVotes).get();
        
    if(nOperType == 1)
        a && xlAjax("http://www.guoing.com/Ajax/movie_star.aspx?Type=7&tid=" + a + "&rnd=" + (Math.floor(Math.random() * 99999) + 1), "", showDelete).get();
}


function cmCheck(a) {
    if (!cmCheckLogin()) {
        document.getElementById("error" + a).innerHTML = "您还未登录";
        return false
    }
    if (a == "L") {
        var d = document.getElementById("title" + a).value.trim(),
        b = document.getElementById("text" + a).value.trim();
        if (d == "" || d == "请输入标题") {
            document.getElementById("error" + a).innerHTML = "请填写标题";
            document.getElementById("title" + a).focus();
            return false
        } else if (b == "" || b == "请填写内容") {
            document.getElementById("error" + a).innerHTML = "您还未输入影评内容";
            document.getElementById("text" + a).focus();
            return false
        } else if (b.length < 100) {
            document.getElementById("error" + a).innerHTML = "字数不够哦！";
            document.getElementById("text" + a).focus();
            return false
        } else if (b.length > 1E3) {
            document.getElementById("error" + a).innerHTML = "字数超出限制啦！";
            document.getElementById("text" + a).focus();
            return false
        }
    } else if (a == "S") {
        d = document.getElementById("text" + a).value.trim();
        if (d == "" || d == "请填写内容") {
            document.getElementById("error" + a).innerHTML = "您还未输入任何内容";
            document.getElementById("text" + a).focus();
            return false
        } else if (d.length > 80) {
            document.getElementById("error" + a).innerHTML = "字数超出限制啦";
            document.getElementById("text" + a).focus();
            return false
        }
    }
    document.getElementById("errorS").innerHTML = "";
    document.getElementById("errorL").innerHTML = "";
    
   // a == "S" && sendCmKkpv(6800);
   // a == "L" && sendCmKkpv(6801);
    return true
}
function copyToS() {
    if (document.getElementById("textL").value != "请填写内容") if (document.getElementById("textS").value != document.getElementById("textL").value) document.getElementById("textS").value = document.getElementById("textL").value;
    document.getElementById("textS").style.color = "";
    
    keyDown()
}
function copyToL() {
    if (document.getElementById("textS").value != document.getElementById("textL").value && document.getElementById("textS").value.trim() != "") {
        document.getElementById("textL").value = document.getElementById("textS").value;
        document.getElementById("textL").style.color = ""
    }
    keyDown()
}
function keyDown() {

    if (/msie/.test(window.navigator.userAgent.toLowerCase()) && document.getElementById("textL").scrollHeight >= 60 && document.getElementById("textL").scrollHeight <= 220) 
        document.getElementById("textL").style.posHeight = document.getElementById("textL").scrollHeight;
        
           
    var a = document.getElementById("textS").value.trim(),
    
    d = document.getElementById("textL").value.trim();
    
    if (cmCheckLogin() != false) {
    
        if (a.length <= 80) 
            document.getElementById("tipsS").innerHTML = "还可以输入" + (80 - a.length) + "个字";
        else if (a.length > 80 && a.length < 100) 
            document.getElementById("tipsS").innerHTML = "已超出<em>" + (a.length - 80) + "</em>个字"; 
        else if (a.length >= 100) 
            document.getElementById("tipsS").innerHTML = "已超出<em>" + (a.length - 80) + "</em>个字,建议您<a href='javascript://' onclick=\"cmSwitch('sendCm',1,2,'on','')\" title=\"发布为长影评\">发布为长影评</a>";
         
        if (d.length < 100 && d != "请填写内容") document.getElementById("tipsL").innerHTML = "还需要输入<em>" + (100 - d.length) + "</em>个字";
        else if (d.length >= 100 && d.length <= 1E3) document.getElementById("tipsL").innerHTML = "已输入" + d.length + "个字";
        else if (d.length > 1E3) document.getElementById("tipsL").innerHTML = "已超出<em>" + (d.length - 1E3) + "</em>个字"
    }
}
function cmCheckLogin() {

     if (getCookie("guoing%5FCookie") != "" ) {
        document.getElementById("sendCmS").style.display = "";
        document.getElementById("sendCmL").style.display = "";
        document.getElementById("registerS").style.display = "none";
        document.getElementById("registerL").style.display = "none";
        document.getElementById("loginS").style.display = "none";
        document.getElementById("loginL").style.display = "none";
        return true
    } else {
        document.getElementById("sendCmS").style.display = "none";
        document.getElementById("sendCmL").style.display = "none";
        document.getElementById("registerS").style.display = "";
        document.getElementById("registerL").style.display = "";
        document.getElementById("loginS").style.display = "";
        document.getElementById("loginL").style.display = "";
        document.getElementById("tipsS").innerHTML = "请先登录，如果还没账号就注册一个吧！";
        document.getElementById("tipsL").innerHTML = "请先登录，如果还没账号就注册一个吧！";
        return false
    }
}

function showXBox(a, d) {
    document.getElementById("successBox").innerHTML = a;
    document.getElementById("successBox").style.display = "";
    if (d) {
        document.getElementById("textS").value = "";
        document.getElementById("textL").value = "";
        document.getElementById("titleL").value = "";
        document.getElementById("titleL").style.color = "";
        keyDown()
    }
    if(d == "1")    
        setTimeout("RefreshTips()", 5E3)
    else
        setTimeout("RefreshComment()", 5E3)
}

function RefreshTips()
{
    document.getElementById('successBox').style.display="none";
    GetMovieTips(nMovieID);
}


function RefreshComment()
{
    document.getElementById('successBox').style.display="none";
    GetMovieComment(nMovieID);
}


function PlayMovie(nID)
{

    if (getCookie("guoing%5FCookie") != "" )
    {
        var sUri = "http://www.guoing.com/Ajax/PageCheck.aspx?type=22&value=" + nID;

         $.get(sUri, function(data){   
            if (data == "OK") {
                location.href="http://www.guoing.com/movie/Play.aspx?ID=" + nID;
            }
            else
            {
                showPriceF(nID);
            }
         });        
    }
     else
     {
        var success_action = "CheckLogin();PlayMovie(" + nID + ")";
        loginF(success_action);
     }
}



function showPriceF(nID){
	var loginFun = new funDialog();
	loginFun.show({
		"width" : 455,
		"title" : "扣费提醒",
		"titleClass" : "diaMovieTitle",
		"content" : moviePayCon
	});
	
	$("#noview").click(function(){ funDialog().close(); });
	
	$("#movie_pay_confirm").submit(function(){
	    var jsont = $("#movie_pay_confirm").serialize();
		$.ajax({
			type : "POST",
			url : "http://www.guoing.com/Ajax/PageCheck.aspx?type=21&value=" + nID,
			data : jsont,
			success : function(info){
			    if (info == "OK") {
			        loginFun.msg("过影网扣费提示","扣费成功！影片马上播放！",{"callBackTime" : 1000},function(){
						location.href="http://www.guoing.com/movie/Play.aspx?ID=" + nID;
					});
                    
                }
                if (info == "Money") {
                   alert("余额不足！请进行充值！");
                }
                if (info == "Error") {
                   alert("支付异常！");
                }
			}
		});
		return false;
	});

}

var shareApp = {
	cmts:'',
	thumb:'',
	name_cn:'',
	thumb:'',
	mediaid:0,
	tips:{sina:'新浪微博', qq:'腾讯微博', renren:'人人网', kaixin:'开心网', zone:'QQ空间', souhu:'搜狐微博',wangyi:'网易微博',douban:'豆瓣',baishehui:'白社会',tieba:'百度贴吧'},
	e:function(m){return encodeURIComponent(m);},
	tip:function(n){
		return '分享到' + (this.tips[n] || '');
	},
	url:function(type){
		if(this.mediaid) return "http://www.guoing.com/movie/" + this.mediaid + ".html?f="+type;
		var link = window.location.href.split('#')[0];
		return this.param(link, type);
	},
	emptyUrl:function(url){
		return url ? url : 'http://www.guoing.com/';
	},
	param:function(link, type){
		return link += (link.match(/\?/) ? '&' : '?') + 'f='+type;
	},
	title:function(){
		if(this.name_cn) return "过影网：《"+this.name_cn+"》";
		return document.title.indexOf('过影网') > -1 ? document.title : '过影网 ' + document.title;
	},
	getMsg:function(){
		return this.cmts.substr(0, 140);
	},
	google:function(){		
	},
	kaixin:function(obj){
		var site='http://www.kaixin001.com/~repaste/repaste.php?';
		if(!obj){site+='rurl='+escape(this.url('kaixin'))+'&rtitle='+escape(this.title())+'&rcontent='+escape(this.getMsg());}
		else{site+='rurl='+escape(this.param(this.emptyUrl(obj.url), 'kaixin'))+'&rtitle='+escape(obj.content)+'&rcontent='+escape(obj.content);}
		window.open(site,'w');
		this.google();
		return false;
	},
	douban:function(obj){
		var u='http://www.douban.com/recommend/?url=';
		if(!obj) u+=this.e(this.url('douban'))+'&title='+this.e(this.title())+'&comment='+this.e(this.getMsg());
		else u+=this.e(this.param(this.emptyUrl(obj.url), 'douban'))+'&title='+this.e(obj.content)+'&comment='+this.e(obj.content);
		window.open(u,'w','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330');
		this.google();
		return false;
	},
	renren:function(obj){
		var s = window.screen;var d = document;var e = this.e;var f='http://share.xiaonei.com/share/buttonshare.do?link=';var u,l;
		if(!obj){u=this.url('renren');l=this.title() +'  '+ this.getMsg();}else{u=e(this.param(this.emptyUrl(obj.url), 'renren'));l=e(obj.content);};
		var p=[e(u),'&title=',e(l)].join('');
		if(!window.open([f,p].join(''),'w',['toolbar=0,status=0,resizable=1,width=626,height=436,left=',(s.width-626)/2,',top=',(s.height-436)/2].join(''))) u.href=[f,p].join('');
		this.google();
		return false;
	},
	baishehui:function(obj){
		var u="http://bai.sohu.com/share/blank/addbutton.do?from=fengyin&link=";
		if(!obj) u+=this.e(this.url('bai'))+"&title="+this.e(this.title() +' '+ this.getMsg());
		else u+=this.e(this.param(this.emptyUrl(obj.url), 'bai'))+"&title="+this.e(obj.content);
		window.open(u);
		this.google();
		return false;
	},
	sina:function(obj){
		var url = "http://v.t.sina.com.cn/share/share.php?appkey=1054533429&url=";
		if(!obj){		    
			url += this.e(this.url('sinat'))+"&title="+this.e( this.title()+ this.getMsg())+"&content=utf-8&pic="+this.e(this.thumb);
		}else{
			url += this.e(this.param(this.emptyUrl(obj.url), 'sinat'))+"&title="+this.e(obj.content)+"&content=utf-8&pic="+this.e(obj.image);
		}
		window.open(url, "w", 'width=700, height=580, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );		
		this.google();
		return false;
	},
	tieba:function(obj){
		var _u = "http://tieba.baidu.com/i/sys/share?link=";
		if(!obj) _u+=this.e(this.url('tieba'))+"&type=text&title="+this.e(this.title())+"&content="+this.e(this.getMsg());
		else _u+=this.e(this.param(this.emptyUrl(obj.url), 'tieba'))+"&type=text&title="+this.e(obj.content)+"&content="+this.e(obj.content);
		window.open(_u, "w");
		this.google();
		return false;
	},
	qq:function(obj){
		var _t = this.e(this.title()+ this.getMsg());
		var _url = this.e(this.url('qqt'));
		var _appkey = '51389aedce694369a96084742746320d';
		var _site = 'http://www.guoing.com';
		var _u = 'http://v.t.qq.com/share/share.php?';
		if(!obj){
			_u += 'title='+_t+'&url='+_url+'&appkey='+_appkey+'&site='+_site+'&pic='+this.thumb;
		}else{
			_u += 'title='+this.e(obj.content)+'&url='+this.e(this.param(this.emptyUrl(obj.url), 'qqt'))+'&appkey='+_appkey+'&site='+_site+'&pic='+this.e(obj.image);
		}
		window.open( _u,'转播到腾讯微博', 'width=700, height=580, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );
	},
	zone:function(obj){
		var u="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=";
		var _site = 'http://www.guoing.com';
		if(!obj) u+=this.e(this.url('zone'))+'&title='+this.e(this.title())+'&site='+_site+'&pic='+this.thumb;
		else u+=this.e(this.param(this.emptyUrl(obj.url), 'zone'))+'&title='+this.e(obj.content);
		window.open(u)
	},
	pengyou:function(obj){
		var u="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?to=pengyou&url=";
		var _site = 'http://www.guoing.com';
		if(!obj) u+=this.e(this.url('zone'))+'&title='+this.e(this.title()) +'&site='+_site+'&pic='+this.thumb;
		else u+=this.e(this.param(this.emptyUrl(obj.url), 'zone'))+'&title='+this.e(obj.content);
		window.open(u)
	},
	souhu:function(obj){
		var _u = "http://t.sohu.com/third/post.jsp?url=";
		if(!obj) _u+=this.e(this.url('souhu'))+"&title="+this.e(this.title() + this.getMsg())+"&content=utf-8&pic="+this.e(this.thumb);
		else _u+=this.e(this.param(this.emptyUrl(obj.url), 'souhu'))+"&title="+this.e(obj.content)+"&content=utf-8&pic="+this.e(obj.image);
		window.open( _u,'转播到搜狐微博', 'width=660, height=470, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );
	},
	wangyi:function(obj){
		var _u = 'http://t.163.com/article/user/checkLogin.do?link=';
		if(!obj) _u+=this.e('http://www.guoing.com')+'&source='+this.e('过影网')+'&info='+this.e(this.title() + this.getMsg())+' '+this.e(this.url('163'))+"&pic="+this.thumb;
		else _u+=this.e('http://www.guoing.com')+'&source='+this.e('过影网')+'&info='+this.e(obj.content)+' '+this.e(this.param(this.emptyUrl(obj.url), '163'))+"&pic="+this.e(obj.image);
		window.open(_u, '转播到网易微博','width=510,height=300, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no');
	},
	init:function(obj){
		this.cmts = obj.content,
		this.thumb = obj.image,
		this.name_cn = '';
		this.mediaid = 0;
		return this;
	},
	snsClose:function(obj){
		clearTimeout(obj.timer);
		obj.timer = setTimeout(function(){
			removeClassName(obj, 'share-span-hover');
		},200);
	},
	sns:function(obj){
		clearTimeout(obj.timer);
		var rel = obj.getAttribute('rel').split('-');
		if(rel.length != 2) return;
		var ele = rewrite.getElement(obj, 'sns-share-layout', 'div');
		if(ele.length == 0) return;
		addClassName(obj, 'share-span-hover');
		var d = ele[0];
		if(obj.loading || d.getElementsByTagName('a').length > 0) return;
		obj.loading = 1;
		d.innerHTML = "<div class='padding loading'></div>";
		ajaxGet("/ajax/get_event/"+rel[0]+"/"+rel[1], function(resp){
			if(!resp) return;
			var json = evaljson(resp);
			if(!json || json.status != 200){
				obj.loading = '';
				return alert('出错了，服务器未正确返回数据');
			}
			if($(json.id) == null) return;
			$(json.id).innerHTML = "<div class='padding'>"+['<a title="'+shareApp.tip('sina')+'" onclick=\'return shareApp.sina('+json.ret+');\' class="sina" href="###"></a>',
				'<a title="'+shareApp.tip('qq')+'" onclick=\'return shareApp.qq('+json.ret+');\' class="qq" href="###"></a>',
				'<a title="'+shareApp.tip('renren')+'" onclick=\'return shareApp.renren('+json.ret+');\' class="rr" href="###"></a>',
				'<a title="'+shareApp.tip('kaixin')+'" onclick=\'return shareApp.kaixin('+json.ret+');\' class="xx" href="###"></a>',
				'<a title="'+shareApp.tip('zone')+'" onclick=\'return shareApp.zone('+json.ret+');\' class="zone" href="###"></a>',
				'<a title="'+shareApp.tip('souhu')+'" onclick=\'return shareApp.souhu('+json.ret+');\' class="sohu" href="###"></a>',
				'<a title="'+shareApp.tip('wangyi')+'" onclick=\'return shareApp.wangyi('+json.ret+');\' class="wangyi" href="###"></a>',
				'<a title="'+shareApp.tip('douban')+'" onclick=\'return shareApp.douban('+json.ret+');\' class="hh" href="###"></a>',
				'<a title="'+shareApp.tip('baishehui')+'" onclick=\'return shareApp.baishehui('+json.ret+');\' class="bsh" href="###"></a>',
				'<a title="'+shareApp.tip('tieba')+'" onclick=\'return shareApp.tieba('+json.ret+');\' class="ib" href="###"></a>'].join('')+"</div>";
		});
	}
};

