﻿var oldcolor;
var button_label0='获取地址';
var button_label1='正在获取';
var result_label0='等待提交...';
var result_label1='<img src="loading.gif" alt="loading" /> 获取中(专辑需时稍长,不要关闭本页)...';
var msg = "请用右键“目标另存为”或用快车下载\n【提示：大部分视频无法使用迅雷下载】";
String.prototype.queryString = function(key){
    var sValue=this.match(new RegExp("[\?\&]"+key+"=([^\&]*)(\&?)","i"));
    return sValue ? sValue[1]:sValue
}

String.prototype.setKeyValue = function(key,value){
    if(this.queryString(key) != null){
        var reg = new RegExp("([\?\&])(" + key + "=)([^\&]*)(\&?)","i");
        return this.replace(reg,"$1$2" + value + "$4");
    }else{
        var add = arguments[2];
        if(add === true){
            return this + (this.indexOf("?") > -1 ? "&" : "?") + key + 
"=" + value;
        }else return this;
    }
}
$(document).ready(function(){
	var lc=location.toString();
	var videoPageURI=lc.queryString('url');
	$('#fetchButton').val(button_label0);
	if(videoPageURI==null){
		$('#resultbox').hide();
	} else {
		if(videoPageURI.indexOf('http')===0){
			$('#url').val(decodeURIComponent(videoPageURI));
			getFlv();
		} else {
			videoPageURI=decodeBase64(videoPageURI);
			$('#url').val(videoPageURI);
			getFlv();
		}
	}

	oldcolor = $('#url').css('color');
	urlaction('onblur');
	$('#url').blur(function(){
		urlaction('onblur');
		});
	$('#url').focus(function(){
		this.select();
		urlaction('onfocus');
		});
	$.getScript("http://www.flvxz.com/v/recommend.js");
	$.getScript("http://www.flvxz.com/v/random.js");
	$.getScript("http://www.flvxz.com/supportsite.php");
});
function urlaction(act){
	var emptystr = '请在这里粘贴视频播放页面的地址（IE浏览器地址栏地址）';
	if( act == 'onblur' ){
		//alert('onblur');
		if($('#url').val()=='' || $('#url').val()==emptystr){
			$('#url').css('color','#cccccc');
			$('#url').val(emptystr);
		}
	}
	if( act == 'onfocus' ){
		//alert('onfocus');
		if($('#url').val()==emptystr){
			$('#url').css('color',oldcolor);
			$('#url').val('');
		}
	}
	if($('#url').val()!=emptystr){
		$('#url').css('color',oldcolor);
	}
}
function getFlv() {
  var uri = $('#url').val();
  if ((uri == null) || (uri == "")) return;
  $('#fetchButton').attr('disabled',"disabled");
  $('#fetchButton').attr('value',button_label1);
  $('#resultbox').css('display','block');
  $('#result').html(result_label1);
	$.getScript("http://www.flvxz.com/getFlv.php?url="+encodeBase64(uri), function(){
		$('#fetchButton').attr('disabled','');
		$('#fetchButton').attr('value',button_label0);
		} );
}
function down(flv) {
	var winobj=window.open(flv,"down");
	if(winobj==null) window.location=flv;
	return false;
}
function seturl(uri){
	$('#url').val(uri);
	$('#url').focus();
}
function floatwin(wid,wWidth,wHeight){
	//var wWidth=600;
	//var wHeight=400;
	var clientWidth = document.body.clientWidth;
	var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
	var wLeft=(clientWidth-wWidth)/2;
	var wTop=(clientHeight-wHeight)/2+scrollTop;
	var vwin = document.createElement('div');
	vwin.id=wid;
	vwin.style.cssText="z-index:999;position:absolute;width:"+wWidth+"px"+";height:"+wHeight+"px"+";left:"+wLeft+"px;"+"top:"+wTop+"px"+";background:#8bcee4;";
	document.body.appendChild(vwin);
	document.getElementById(wid).innerHTML='<div style="width:'+(wWidth-10)+'px;height:'+(wHeight-10)+'px;margin:5px;background:#f1f5fa;"><div style="width:'+(wWidth-40)+'px;height:20px;margin:0 auto;"></div><div class="vwin_line" style="width:'+(wWidth-40)+'px;"><span style="float:right;"><a href="javascript:void(0);" onclick="floatclose(\''+wid+'\');"></a></span></div><div id="'+wid+'content" style="width:'+(wWidth-80)+'px;height:'+(wHeight-110)+'px;margin:0 auto;"></div></div>';
}
function floatclose(wid){
	var vwin = document.getElementById(wid);
	document.body.removeChild(vwin);
}

