
// <script type="text/javascript">
var current_site_domain = 'www.rayfile.com';
var current_site_basedomain = 'rayfile.com';
function _v(){}
function isDefined(object, variable){
return (typeof(eval(object)[variable]) == 'undefined')? false : true;
}
function qe() {
    var obj = document.createElement(arguments[0]);
    if (arguments[2] != '' && arguments[2] != null) {
        var textNode = document.createTextNode(arguments[2]);
        obj.appendChild(textNode);
    }
    var len = arguments.length;
    for (var i = 3; i < len; i += 2) {
        obj.setAttribute(arguments[i], arguments[i+1]);
    }
    arguments[1].appendChild(obj);
    return obj;
}
function ae(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}
function removeEvent(obj, evType, fn) {
    if (obj.removeEventListener) {
        obj.removeEventListener(evType, fn, false);
        return true;
    } else if (obj.detachEvent) {
        obj.detachEvent("on" + evType, fn);
        return true;
    } else {
        return false;
    }
}
function gfn(fn) {
  var re = new RegExp(/([^\/\\]+)$/);
  var m = re.exec(fn);
  if (m == null) {
    return null;
  } else {
   return m[0];
  }
}
function gu()
{
	var uuid = '';
	var hex = new Array('0','1','2','3','4','5','6','7','8', '9','a','b','c','d','e','f');
	
	for (count = 0; count < 32; count++)
	{
		if(count == 8 || count == 12 || count == 16 || count == 20)
			uuid += '-';
		uuid += hex[Math.floor(Math.random() * 16)];
	}
	return uuid;
}
function showMask(show)
{
	var mask = document.getElementById('dmask');
	var frmmask = document.getElementById('frmmask');
	if(mask && frmmask)
	{
		var width = document.body.scrollWidth;
		if(width < document.body.clientWidth)
			width = document.body.clientWidth;
		if(width < document.documentElement.clientWidth)
			width = document.documentElement.clientWidth;
		if(width < document.documentElement.scrollWidth)
			width = document.documentElement.scrollWidth;
			
		var height = document.body.scrollHeight;
		if(height < document.body.clientHeight)
			height = document.body.clientHeight;
		if(height < document.documentElement.clientHeight)
			height = document.documentElement.clientHeight;
		if(height < document.documentElement.scrollHeight)
			height = document.documentElement.scrollHeight;

		mask.style.top = '0px';
		mask.style.left = '0px';
		mask.style.width = width + 'px';
		mask.style.height = height + 'px';
		frmmask.style.top = '0px';
		frmmask.style.left = '0px';
		frmmask.style.width = width + 'px';
		frmmask.style.height = height + 'px';

		if(show)
		{
			mask.style.visibility = 'visible';
			frmmask.style.visibility = 'visible';
		}else
		{
			mask.style.visibility = 'hidden';
			frmmask.style.visibility = 'hidden';
		}
	}
}
var dialogObj = null;
var onDialogClose = function() { return; };

var dragObject  = null;
var mouseOffset = null;

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	if(document.body)
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	else
		return {x:0, y:0};
}

function getMouseOffset(target, ev){
	ev = ev || window.event;

	var docPos    = getPosition(target);
	var mousePos  = mouseCoords(ev);
	return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}

function getPosition(e){
	var left = 0;
	var top  = 0;

	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;

	return {x:left, y:top};
}

function mouseMove(ev){
	ev           = ev || window.event;
	var mousePos = mouseCoords(ev);

	if(dragObject){
		dragObject.style.position = 'absolute';
		var shiftTop = mousePos.y - mouseOffset.y - dragObject.offsetTop;
		var shiftLeft = mousePos.x - mouseOffset.x - dragObject.offsetLeft;
		shiftDialog(shiftTop, shiftLeft)
		
		return false;
	}
}
function mouseUp(){
	dragObject = null;
}

function makeDraggable(item){
	if(!item) return;
	item.onmousedown = function(ev){
		dragObject  = this;
		mouseOffset = getMouseOffset(this, ev);
		return false;
	}
}
function shiftDialog(shiftTop, shiftLeft)
{
	var iClose = document.getElementById('iClose');
	var iMove = document.getElementById('iMove');
	if(iClose && iClose.style && iMove && iMove.style && dialogObj && dialogObj.style)
	{
		dialogObj.style.top = dialogObj.offsetTop + shiftTop + 'px';
		dialogObj.style.left = dialogObj.offsetLeft + shiftLeft + 'px';
		iClose.style.top = iClose.offsetTop + shiftTop + 'px';
		iClose.style.left = iClose.offsetLeft + shiftLeft + 'px';
		iMove.style.top = iMove.offsetTop + shiftTop + 'px';
		iMove.style.left = iMove.offsetLeft + shiftLeft + 'px';
	}
}

function moveDialog(top, left)
{
	var iClose = document.getElementById('iClose');
	var iMove = document.getElementById('iMove');
	if(iClose && iClose.style && iMove && iMove.style && dialogObj && dialogObj.style)
	{
		var shiftTop = top - dialogObj.offsetTop;
		var shiftLeft = left - dialogObj.offsetLeft;
		shiftDialog(shiftTop, shiftLeft);
	}
}

function closeDialog()
{
	var iClose = document.getElementById('iClose');
	if(iClose) {
		try {
			if( document.createEvent ) {
				var eObj = document.createEvent('MouseEvents');
				eObj.initEvent('click', true, false);
				iClose.dispatchEvent(eObj);
				}
			else if (document.createEventObject) {
				iClose.fireEvent('onclick');
				}
			}catch(e) {}
		}
}

function doObjDialog(isModal, obj, width, height, onclose)
{
	if(!obj || !obj.style)
		return false;
	if(!width)
		width = 320;
	if(!height)
		height = 180;
	var top = window.screen.height/2 + (document.body.scrollTop>document.documentElement.scrollTop ? document.body.scrollTop:document.documentElement.scrollTop) - height/2 - 100;
	var left = window.screen.width/2 + (document.body.scrollLeft>document.documentElement.scrollLeft ? document.body.scrollLeft:document.documentElement.scrollLeft) - width/2;
	
	if(isModal)
		showMask(true);

	obj.style.top = top + 'px';
	obj.style.left = left + 'px';
	obj.style.width = width + 'px';
	obj.style.height = height + 'px';
	
	var iClose = document.getElementById('iClose');
	if(iClose && iClose.style)
	{
		iClose.style.top = (top + 2) + 'px';
		iClose.style.left = (left + width - 12) + 'px';
		iClose.style.visibility = 'visible';
	}
	
	var iMove = document.getElementById('iMove');
	if(iMove && iMove.style)
	{
		iMove.style.top = (top + 5) + 'px';
		iMove.style.left = (left + 5) + 'px';
		iMove.style.visibility = 'visible';
	}

	if (onclose)
		onDialogClose = onclose;
	else
		onDialogClose = function() { return; };
	
	obj.style.visibility = 'visible';
	dialogObj = obj;
}

function doFrmDialog(isModal, url, width, height, onclose, onload)
{
	if(!url)
		return false;
	
	var frm = document.getElementById('frmDialog');
	if(frm)
	{
		var func = function (){
			if(onclose)
				if(false == onclose())
					return false;
			if (frm)
				frm.contentWindow.location.replace("about:blank");
		}
		
		if(onload)
			ae(frm, 'load', onload);
		
		frm.contentWindow.location.replace(url);
		doObjDialog(isModal, frm, width, height, func);
	}
}
function fs2you_init(obj){
	obj.innerHTML = '<div id="dmask" style="z-index:10000; display:block; background:#000; filter:alpha(opacity=70); -moz-opacity:0.7; opacity:0.7; position:absolute; visibility:hidden;"></div>\
<iframe id="frmmask" frameborder="0" scrolling="no" src="about:blank" style="z-index:9999; display:block; background:#000; filter:alpha(opacity=0); -moz-opacity:0; opacity:0; position:absolute; visibility:hidden;"></iframe>\
<img id="iClose" src="http://static.'+current_site_basedomain+'/media/img/close.gif" alt="" style="z-index: 20010; position: absolute; width: 10px; height: 10px; display: block; visibility: hidden; cursor: pointer;" />\
<img id="iMove" src="http://static.'+current_site_basedomain+'/media/img/icon_move.gif" alt="" style="z-index: 20010; position: absolute; width: 8px; height: 8px; display: block; visibility: hidden; cursor:move;" />\
<iframe id="frmDialog" frameborder="0" scrolling="no" src="about:blank" style="z-index: 10010; position: absolute; display: block; visibility: hidden;"></iframe>\
<div style="display: block; float: right; font-size: 11px; text-align: right;">Powered by <a href="http://'+current_site_domain+'/"><b>RayFile</b></a></div>\
<div style="display: block; float: left; font-size: 11px;">只支持MP3/WMA 单个文件大小限制为: 10.0 MB</div><div style="clear: both;"/>';
	var iClose = document.getElementById('iClose');
	var iMove = document.getElementById('iMove');
	if (iClose) {
		ae(iClose, 'click',  function(e) {
			if(e.returnValue == false)
				return e.returnValue;
			if (onDialogClose)
				if(false == onDialogClose()) {
				    e.returnValue = false;
					if (!e.returnValue && e.preventDefault)
						e.preventDefault();
					return false;
				}
			iClose.style.visibility = 'hidden';
			if (iMove)
				iMove.style.visibility = 'hidden';
			if (dialogObj)
				dialogObj.style.visibility = 'hidden';
			showMask(false);
		})
	}
    makeDraggable(iMove);
}
ae(document, 'mousemove', mouseMove);
ae(document, 'mouseup', mouseUp);

var fs2you_fileserver = "file22.rayfile.com:8421";


var fs2you_bfss_group = [['file30.rayfile.com:8421', 'file24.rayfile.com:8421', 'file22.rayfile.com:8421', 'file16.rayfile.com:8421', 'file21.rayfile.com:8421', 'file36.rayfile.com:8421'], ['file.rayfile.com:8421', 'file12.rayfile.com:8421', 'file34.rayfile.com:8421', 'file7.rayfile.com:8421', 'file20.rayfile.com:8421'], ['file26.rayfile.com:8421', 'file15.rayfile.com:8421', 'file9.rayfile.com:8421', 'file23.rayfile.com:8421', 'file17.rayfile.co:8421'], ['file25.rayfile.com:8421', 'file31.rayfile.com:8421', 'file18.rayfile.com:8421', 'file10.rayfile.com:8421'], ['file35.rayfile.com:8421', 'file6.rayfile.com:8421', 'file8.rayfile.com:8421', 'file19.rayfile.com:8421', 'file11.rayfile.com:8421', 'file32.rayfile.com:8421'], ['file5.rayfile.com:8421', 'file3.rayfile.com:8421', 'file33.rayfile.com:8421', 'file14.rayfile.com:8421', 'file13.rayfile.com:8421']];
var fs2you_bfss = [];

function fs2you_rebuild_bfss()
{
	fs2you_bfss = [];
	var ayes = [], ano = [];
	for(var i=0; i<fs2you_bfss_group.length; i++)
	{
		var flag = false;
		for(var j=0; j<fs2you_bfss_group[i].length; j++)
		{
			if(fs2you_bfss_group[i][j] == fs2you_fileserver)
			{
				flag = true;
				break;
			}
		}
		if(flag)
		{
			ayes.push(i);
		}else
		{
			ano.push(i);
		}
	}
	for(var i=0; i<ayes.length; i++)
	{
		var index = ayes[i];
		for(var j=0; j<fs2you_bfss_group[index].length; j++)
		{
			if(fs2you_bfss_group[index][j] != fs2you_fileserver)
			{
				var flag = true;
				for(var k=0; k<fs2you_bfss.length; k++)
				{
					if(fs2you_bfss_group[index][j] == fs2you_bfss[k])
						flag = false;
				}
				if(flag)
					fs2you_bfss.push(fs2you_bfss_group[index][j]);
			}
		}
	}
	for(var i=0; i<ano.length; i++)
	{
		var index = ano[i];
		for(var j=0; j<fs2you_bfss_group[index].length; j++)
		{
			if(fs2you_bfss_group[index][j] != fs2you_fileserver)
			{
				var flag = true;
				for(var k=0; k<fs2you_bfss.length; k++)
				{
					if(fs2you_bfss_group[index][j] == fs2you_bfss[k])
						flag = false;
				}
				if(flag)
					fs2you_bfss.push(fs2you_bfss_group[index][j]);
			}
		}
	}
}

fs2you_rebuild_bfss();

var fs2you_bfs_index = -1;

var fs2you_upctrl = document.getElementById('fs2you_upctrl');
var fs2you_post_submit = false;
var fs2you_file_count = 1;

function fs2you_run(){
	if(fs2you_upctrl){
		fs2you_init(fs2you_upctrl);
		if(isDefined(window, 'ajaxpost')&&isDefined(ajaxpost, 'postForm')){
			ajaxpost.postForm = function(){return true;}
		}
		if(!fs2you_account){fs2you_upctrl.innerHTML='您没有设置fs2you_account变量.';return;}
		var p = qe('p', fs2you_upctrl, '');
		qe('span', p, '描述: ');
		var fd = qe('input', p, '', 'name', 'fs2you_fd', 'type', 'text');
		qe('span', p, '文件: ');
		var f = qe('input', p, '', 'name', 'fs2you_f', 'type', 'file');
		ae(f, 'change', function(){
			var fn = gfn(f.value);
			if(fn!=null&&fd.value=='') fd.value=fn;
		});
		var pa = qe('p', fs2you_upctrl, '');
		ae(qe('a', pa, ' ', 'href', 'javascript:_v()'), 'click', function(){
			if(!isDefined(window,'fs2you_max_file_count') || fs2you_max_file_count<=0 || fs2you_file_count<fs2you_max_file_count){
				var p = document.createElement('p');
				fs2you_upctrl.insertBefore(p, pa);
				qe('span', p, '描述: ');
				var fd = qe('input', p, '', 'name', 'fs2you_fd', 'type', 'text');
				qe('span', p, '文件: ');
				var f = qe('input', p, '', 'name', 'fs2you_f', 'type', 'file');
				ae(f, 'change', function(){
					var fn = gfn(f.value);
					if(fn!=null&&fd.value=='') fd.value=fn;
				});
				ae(qe('a', p, '移除', 'href', 'javascript:_v()'), 'click', function(){
					fs2you_upctrl.removeChild(p);
					fs2you_file_count--;
				});
				fs2you_file_count++;
			}else{
				alert('对不起, 您每次最多只能上传' + fs2you_max_file_count + '个文件.');
			}
		});
		var frc = false;
		if(document.characterSet) frc = document.characterSet;
		if(document.charset) frc = document.charset;
		if(frc) qe('input', fs2you_upctrl, '', 'type', 'hidden', 'name', 'fs2you_r_charset', 'value', frc);
		qe('input', fs2you_upctrl, '', 'type', 'hidden', 'name', 'fs2you_account', 'value', fs2you_account);
		if(isDefined(window, 'fs2you_message_body_name')) qe('input', fs2you_upctrl, '', 'type', 'hidden', 'name', 'fs2you_message_body_name', 'value', fs2you_message_body_name);
		if(isDefined(window, 'fs2you_display_template')) qe('input', fs2you_upctrl, '', 'type', 'hidden', 'name', 'fs2you_display_template', 'value', unescape(fs2you_display_template));
		var frm = fs2you_upctrl;
		while(frm.parentNode&&frm.tagName.toLowerCase()!='form') frm=frm.parentNode;
		if(frm.tagName.toLowerCase()!='form'){fs2you_upctrl.innerHTML='fs2you_upctrl必须在一个form里面.';return;}
		if(frm.method.toLowerCase()!='post'){fs2you_upctrl.innerHTML='您页面的form的方法必须是POST.';return;}
		frm.os = frm.onsubmit;
		if(frm.onsubmit){
			frm.onsubmit=_v;
		}
		var sbe = null;
		var osb = function(e){
			if(frm.os){
				if(!sbe){
					sbe = e;
					if(frm.os(e)==false){
						e.returnValue = false;
						if (!e.returnValue && e.preventDefault) e.preventDefault();
					}
					sbe = null;
				}
			}
			if(fs2you_post_submit) return true;
			if(e.returnValue == false) return e.returnValue;
			var hf = false;
			var ps = fs2you_upctrl.getElementsByTagName('p');
			for(var i=0;i<ps.length;i++){
				var fs = ps[i].getElementsByTagName('input');
				if(fs.length > 1)
					if(fs[1].value==''){
						fs2you_upctrl.removeChild(ps[i]);
						i--;
					}
					else
						hf = true;
			}
			if(hf){
				frm.enctype='multipart/form-data';
				frm.encoding='multipart/form-data';
				var fru = frm.action;
				if((typeof(fru)+'').toLowerCase()!='string'){
					for(var i_a=0;i_a<frm.attributes.length;i_a++){
						if(frm.attributes[i_a].nodeName.toLowerCase()=='action'){
							fru = frm.attributes[i_a].nodeValue;
							break;
						}
					}
				}
				if((typeof(fru)+'').toLowerCase()!='string'){
					fru = location.pathname+location.search;
				}
				if(fru.indexOf(location.protocol) != 0){
					var _bu = location.protocol+'//'+location.hostname;
					if(location.port!='')
						_bu += ':'+location.port;
					if(fru.indexOf('/') == 0)
						fru = _bu+fru;
					else{
						_bu += location.pathname.substring(0, location.pathname.lastIndexOf('/')+1);
						while(fru.indexOf('./')==0||fru.indexOf('../')==0){
							if(fru.indexOf('../')==0){
								fru = fru.substring(3);
								_bu = _bu.substring(0, _bu.lastIndexOf('/', _bu.length-2)+1);
							}else{
								fru = fru.substring(2);
							}
						}
						fru = _bu+fru;
					}
				}
				qe('input', fs2you_upctrl, '', 'type', 'hidden', 'name', 'fs2you_return_url', 'value', fru);
				var uuid=gu();
				var fa = 'http://file22.rayfile.com:8421/zh-cn/ctrlupload/?'+uuid;
				if((typeof(frm.action)+'').toLowerCase()=='string'){
					frm.action=fa;
				}else{
					var saa = frm.attributes.getNamedItem('action');
					if(saa){
						saa.nodeValue = fa;
					}else{
						saa = document.createAttribute('action');
						saa.nodeValue = fa;
						frm.attributes.setNamedItem(saa);
					}
				}
				var prog_url = "http://file22.rayfile.com:8421/zh-cn/progress/?"+uuid;
				var onFrmDialogLoad = function() {
					if(window.location.href.indexOf('#fs2youuploading')>0){
						fs2you_post_submit = true;
						if(frm && frm.submit)
							frm.submit();
					}else{
						fs2you_bfs_index++;
						while(fs2you_bfs_index < fs2you_bfss.length && fs2you_bfss[fs2you_bfs_index] == fs2you_fileserver){
							fs2you_bfs_index++;
						}
						if(fs2you_bfs_index < fs2you_bfss.length){
							var fa = "http://" + fs2you_bfss[fs2you_bfs_index] + "/zh-cn/ctrlupload/?" + uuid;
							if((typeof(frm.action)+'').toLowerCase()=='string'){
								frm.action=fa;
							}else{
								var saa = frm.attributes.getNamedItem('action');
								if(saa){
									saa.nodeValue = fa;
								}else{
									saa = document.createAttribute('action');
									saa.nodeValue = fa;
									frm.attributes.setNamedItem(saa);
								}
							}
							prog_url = "http://" + fs2you_bfss[fs2you_bfs_index] + "/zh-cn/progress/?" + uuid;
							var frmDialog = document.getElementById('frmDialog');
							frmDialog.contentWindow.location.replace(prog_url);
						}else{
							alert("对不起, 服务器暂时不能访问, 请稍后再试.");
						}
					}
				};
				doFrmDialog(true, prog_url, 460, 100, function() {
					if(!confirm("您真的想要取消上传文件吗?"))
						return false;
					removeEvent(document.getElementById('frmDialog'), 'load', onFrmDialogLoad);
					window.location.replace(window.location.href.substring(0,window.location.href.lastIndexOf('#fs2youuploading')));
					},
					onFrmDialogLoad
					);
			}
			e.returnValue = false;
			if (!e.returnValue && e.preventDefault) e.preventDefault();
		};
		frm.ds = frm.submit;
		if(frm.submit){
			frm.submit=function(){
				if(!sbe){
					return frm.ds();
				}else{
					return osb(sbe);
				}
			};
		}
		ae(frm, 'submit', osb);
	}else{
		alert('找不到fs2you_upctrl代码.');
	}
}
fs2you_run();
// </script>
