var DefaultPath=null;
var FilePathObj;
var IsImagePath=false;
var SiteID;
var ImageServerID;
var MediaServerID;
var OtherServerID;
function SelectTemplatePath(obj){
FilePathObj=obj;
IsImagePath=false;
var content="<iframe src=\"selectfile.ashx?rootpath=" + escape("../app_data/template/") + "&extension=.esp\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"100%\"></iframe>";
EasyMask.init({ width: document.documentElement.clientWidth-20 > 705 ? 705 : document.documentElement.clientWidth-20, height: 400, padding:"0", title: '选取模板文件(后缀名.esp)', detail: content, padding:'0'});
}

function SelectImagePath(obj,defaultMaxImageWidth,defaultMaxImageHeight,defaultWatermarkMode,isToSourceFile){
FilePathObj=obj;
IsImagePath=true;
var url;
if(isToSourceFile){
var imageUrl=obj.value.replace("{$file","");
var imageUrls = imageUrl.split("}");
var serverids = imageUrls[0].split("-");
url="listfile.ashx?siteid=" + serverids[0] + "&serverid=" + serverids[1] + "&path=" + imageUrls[1].substring(0,imageUrls[1].lastIndexOf("/") + 1) + "&filepath=" + imageUrls[1];
}
else{
url="listfile.ashx?siteid=" + SiteID + "&serverid=" + ImageServerID;
if(DefaultPath!=null){
url+="&path=";
}
}
url+="&height=265&extension=.gif,.jpg,.jpeg,.bmp,.png";
if(defaultMaxImageWidth){
url+="&maximagewidth="+defaultMaxImageWidth;
}
if(defaultMaxImageHeight){
url+="&maximageheight="+defaultMaxImageHeight;
}
if(defaultWatermarkMode){
url+="&watermarkmode="+defaultWatermarkMode;
}
else{
url+="&watermarkmode=1";
}
var content="<iframe src=\""+url+"\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"100%\"></iframe>";
EasyMask.init({ width: document.documentElement.clientWidth-10 > 705 ? 705 : document.documentElement.clientWidth-10, height: 440, padding:"0", title: '选取图片文件', detail: content, padding:'0'});
}

function SelectMediaPath(obj,isToSourceFile){
FilePathObj=obj;
IsImagePath=false;
var url;
if(isToSourceFile){
var imageUrl=obj.value.replace("{$file","");
var imageUrls = imageUrl.split("}");
var serverids = imageUrls[0].split("-");
url="listfile.ashx?siteid=" + serverids[0] + "&serverid=" + serverids[1] + "&path=" + imageUrls[1].substring(0,imageUrls[1].lastIndexOf("/") + 1) + "&filepath=" + imageUrls[1];
}
else{
url="listfile.ashx?siteid=" + SiteID + "&serverid=" + MediaServerID;
}
url+="&height=265&extension=.swf,.flv,.asf,.wmv,.mpeg,.wma,.mp3&watermarkmode="+DefaultWatermarkMode;
var content="<iframe src=\""+url+"\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"100%\"></iframe>";
EasyMask.init({ width: document.documentElement.clientWidth-10 > 705 ? 705 : document.documentElement.clientWidth-10, height: 440, padding:"0", title: '选取音视频文件', detail: content, padding:'0'});
}

function SelectOtherPath(obj,isToSourceFile){
FilePathObj=obj;
IsImagePath=false;
var url;
if(isToSourceFile){
var imageUrl=obj.value.replace("{$file","");
var imageUrls = imageUrl.split("}");
var serverids = imageUrls[0].split("-");
url="listfile.ashx?siteid=" + serverids[0] + "&serverid=" + serverids[1] + "&path=" + imageUrls[1].substring(0,imageUrls[1].lastIndexOf("/") + 1) + "&filepath=" + imageUrls[1];
}
else{
url="listfile.ashx?siteid=" + SiteID + "&serverid=" + OtherServerID;
}
url+="&height=265&watermarkmode="+DefaultWatermarkMode;
var content="<iframe src=\""+url+"\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"100%\"></iframe>";
EasyMask.init({ width: document.documentElement.clientWidth-10 > 705 ? 705 : document.documentElement.clientWidth-10, height: 440, padding:"0", title: '选取文件', detail: content, padding:'0'});
}

function ClearImagePath(obj){
obj.value="";
$(obj.id+"container").innerHTML="";
}

function FileSelected(path,url){
EasyMask.close();
FilePathObj.value=path;
if(IsImagePath){
FilePathObj.ownerDocument.getElementById(FilePathObj.id+"container").innerHTML="<a href=\""+url+"\" target=\"_blank\"/><img src=\""+url+"?"+new Date()+"\" class=\"smallimage\"/></a><br/><a href=\"#\" onclick=\"SelectImagePath($('imageurl'),DefaultMaxImageWidth,DefaultMaxImageHeight,1,true);return false;\">定位到图片</a>/<a href=\"#\" onclick=\"ClearImagePath($('"+FilePathObj.id+"'));return false;\">清空图片</a>";
}
FilePathObj.focus();
}