// ---------------------- 预览图片 -------------------------

var SupportFolder = new String();
var NeedPreview = false;
var BarID = null;
var FrmID = null;

function SetWebUploaderBar() 
{
	var div = document.getElementById(BarID);
 
	if (div == '[object]')
	{
	    var left = document.body.scrollLeft + (document.body.clientWidth - div.clientWidth) / 2;
	    var top = document.body.scrollTop + (document.body.clientHeight - div.clientHeight) / 2 ;
    	
	    div.style.display = 'inline';	
	    div.style.posLeft = left;
	    div.style.posTop = top;
	    div.style.position = "absolute";	
	}
}

function DoInit(strSupportFolder)
{
	SupportFolder = strSupportFolder;

	var frm = document.getElementById(FrmID);
	if (frm == '[object]')
	{   
    	frm.src = SupportFolder + 'Uploader/UploaderBar.aspx?ProgressID=';	
	}
}

function DoPreviewImage(img)    
{
	var ext = img.src.substring(img.src.lastIndexOf('.')).toLowerCase();
	var pics = '.jpg, .jpeg, .gif, .bmp, .tif';

	if (pics.indexOf(ext) == -1)
	{
		img.style.display = 'none';
	}
	else
	{
		img.style.display = 'inline';
	}
}

function DoUpload()
{
	SetWebUploaderBar(); SetWebUploaderBar(); // 要执行两次的，ｔｎｎｄ位置才能正确移动。
	
	var _theUniqueID = (new Date()).getTime() % 1000000000;
	var _href = window.location.href;
	var _search = window.location.search;
	var _action;
	var _form = document.forms[0];
	
	if (_search == '')	// 地址栏未携带参数使用? 否则使用&
	{
		_action = _href + '?UploadID=' + _theUniqueID;
	}
	else
	{
		if (_search.indexOf('UploadID=') == -1)
		{
			_action = _href + '&UploadID=' + _theUniqueID;			
		}
		else
		{
			var _start = _search.indexOf('UploadID=');
			var _end = _start + 18;			 
			var _arg = _search.substring(_start, _end);
			
			_action = _href.replace(_arg, 'UploadID=' + _theUniqueID);
		}
	}
	_form.action = _action;
	_form.submit();	
	
	var frm = document.getElementById(FrmID);
	if (frm == '[object]')
	{
		frm.src = SupportFolder + 'Uploader/UploaderBar.aspx?ProgressID=' + _theUniqueID + '&BarID=' + BarID;
	}
}

function ShowProgressBar(strSupportFolder, strBarID, strFrmID) 
{
	if (typeof(Page_ClientValidate) == 'function') 
	{		
		if(!Page_ClientValidate())
		{										
			return false;
		}
	}

	BarID = strBarID;
	FrmID = strFrmID;
	
	DoInit(strSupportFolder);
	DoUpload();
	
	return true;
}