var UploadableFilesCount = 1;
function New(Page)
{
var frmPage = xGetElementById("frmPage");
frmPage.action = Page;
frmPage.submit();
}
function Show()
{
var List = xGetElementById("ShowList")
var visibilityList = xGetElementById("ShowList").style.visibility
var positionList = xGetElementById("ShowList").style.position
if(visibilityList == "hidden")
{
List.style.visibility = "visible"
List.style.position = "static"
}
else
{
List.style.visibility = "hidden"
List.style.position = "absolute" 
}
}
function DelFile()
{
ST = "<input name='button2' type='button' class='ButtonClass' onClick='AddFile()' value='اضافه' title='اضافه کردن باکس ارسال عکس' style='color:#FF0000;width:100% '>";
TD = document.getElementById('Buttom');
TD.innerHTML = ST;
Table = xGetElementById('AddTable');
Table.innerHTML = "";
}
function AddFile()
{
TD = xGetElementById('Buttom');
STT = "<input name='button2' type='button' class='ButtonClass' onClick='DelFile()' value='حذف' title='حذف کردن' style='color:#FF0000;width:40% '>";
STT += "&nbsp;<input name='button2' type='button' class='ButtonClass' onClick='AddFile()' value='اضافه' title='اضافه کردن باکس ارسال عکس' style='color:#FF0000;width:40% '>";
TD.innerHTML = STT;
STR = "<table width='100%'><tr><td width='40%' colspan='1' align='right'><input type='file' name='txtFile[" + UploadableFilesCount + "]' id='txtFile" + UploadableFilesCount + "' class='textClass' style='width:90%; height:30'>";
STR += "</td><td width='6%' style='border:0'>توضيحات</td><td colspan='3' width='30%' align='right'>";
STR += "<input type='text' name='txtAttachInfo[" + UploadableFilesCount + "]' id='txtAttachInfo" + UploadableFilesCount + "' class='textClass' style='width:100%;height:30'></td></tr></table>";
Table = xGetElementById('AddTable')
Table.innerHTML += STR;
UploadableFilesCount += 1;
}

function AlertFileObjects()
{
showit(xGetElementById('txtFile1'));
FileObjects = document.getElementsByTagName('input');
alert(FileObjects.length);

for (i = 1; i < FileObjects.length; i++)
{
//alert(FileObjects[i].type);
if (FileObjects[i].type == 'file')
{alert(FileObjects[i].name + " = " + FileObjects[i].value);}
}

}

function PageChange(Page,Source)
{
var txtpage = xGetElementById("txtPage").value;
var frmPage = xGetElementById("frmPage");
frmPage.action = Source+".php?Page="+Page+"&UID="+txtpage+"";
frmPage.submit();
}
function SaveAttach()
{
var Action = xGetElementById("hidAction");
var frmPage = xGetElementById("frmPage");
Action.value = "NEW";
frmPage.action = "rfile.php";
frmPage.submit();
}
function DeleteAttach(Code)
{
var frmPage = xGetElementById("frmPage");
var i, j = 0;
var Temp = "";
var Action = xGetElementById("hidAction");
var Info = xGetElementById("hidInfo");
Temp = Code;
if(trim(Temp) != "")
{
if ( window.confirm("آيا مي خواهيد فايل را حدف کنيد؟") )
{
Info.value = Temp;
Action.value = "DELETE";
frmPage.action = "rfile.php";
frmPage.submit()
}
}
}
function SelectedAttach()
{
var frmPage = xGetElementById("frmPage");
var i, j = 0;
var Temp = "";
var Action = xGetElementById("hidAction");
var Info = xGetElementById("hidInfo");
var ChechBox = document.getElementsByTagName("input");
for(i = 0; i < ChechBox.length; i++)
{
if((ChechBox[i].type == "checkbox") && (ChechBox[i].checked) && (ChechBox[i].id > 0))
{
if(ChechBox[i].name == "Image")
{
if(j > 0)
Temp += "*"
Temp += ChechBox[i].id
j++;
}
else
{
alert("فایل برگزیده حتما باید از فایلهای عکسی باشد");	
return false;
}	
}
}

if(j == 0)
alert("هیچ فایلی انتخاب نشده است")
else if(j > 1)
alert("انتخاب بیش از یک فایل مجاز نمی باشد")
if(j == 1)
{
Info.value = Temp;
Action.value = "SELECTED";
frmPage.action = "rfile.php";
frmPage.submit()
}
}
function FindFile(Code)
{
var frmPage = xGetElementById("frmPage");
var Action = xGetElementById("hidAction");
var Info = xGetElementById("hidInfo");
Info.value = Code;
Action.value = "FINDFILE";
frmPage.action = "rfile.php";
frmPage.submit()
}
function Crop(State,UID,hidCode)
{
window.location = 'crop.php?State='+State+'&UID='+UID+'&hidCode='+hidCode;
}
function Close()
{
window.close()
}

function SaveFile()
{
var Action = xGetElementById("hidAction")
var frmPage = xGetElementById("frmPage")
Action.value = "NEW";
frmPage.action = "rfile.php";
frmPage.submit();
}

function DeleteFile(path,Basepath)
{
var frmPage = xGetElementById("frmPage");
var Action = xGetElementById("hidAction");
var Info = xGetElementById("hidInfo");
var Info2 = xGetElementById("hidInfo2");
if ( window.confirm("Do You Want to Delete File") )
{
Info.value = path;
Info2.value = Basepath;
if (Info.value == 'undefined')
{Info.value = '';}
if (Info2.value == 'undefined')
{Info2.value = '';}
Action.value = "DELETE";
frmPage.action = "rfile.php";
frmPage.submit();
}
}
function ShowAllFile(UID)
{
var NewWindow = window.open("allfiles.php?UID="+UID+"", "", "left=20,top=50,width=800,height=600,status=1,scrollbars=1,menubar=0,toolbar=0,resizable=0");
}

function DeleteDir(path,page)
{
var frmPage = xGetElementById("frmPage");
var Dir = path +'/'+ page;
page = (page * 1) + 1;
var NextDir = path +'/'+ page;
var Action = xGetElementById("hidAction")
var Info = xGetElementById("hidInfo")
var Info2 = xGetElementById("hidInfo2")
if (window.confirm("Do You Want to Delete Folder") )
{
Info.value = Dir;
Info2.value = NextDir;
Action.value = "DELETE";
frmPage.action = "rfile.php";
frmPage.submit()
}
}
function PDFFile()
{
alert('این سیستم در نسخه های بعدی راه اندازی خواهد شد');
}
function ZipFile()
{
alert('این سیستم در نسخه های بعدی راه اندازی خواهد شد');
}
function PrintFile()
{
var frmPage = xGetElementById("frmPage");
frmPage.target = "_blank";
frmPage.action = "printfiles.php";
frmPage.submit();
}
function Back()
{
var frmPage = xGetElementById("frmPage");
var page = xGetElementById("hidPage").value;
frmPage.action = page;
frmPage.submit();
}
function PagingFile()
{
var frmPage = xGetElementById("frmPage");
var txtpage = xGetElementById("txtPage").value;
if( K != txtpage )
{
frmPage.action = "file.php";
frmPage.submit()
}
}
//--------------------------
function SaveAttachAlbum()
{
var frmPage = xGetElementById("frmPage");
var Action = xGetElementById("hidAction")
Action.value = "NEW";
frmPage.action = "ralbum.php";
frmPage.submit();
}

function SelectedAttachAlbum(Select)
{
var frmPage = xGetElementById("frmPage");
var i, j = 0;
var Temp = ""
var Action = xGetElementById("hidAction")
var Info = xGetElementById("hidInfo")
var ChechBox = document.getElementsByTagName("input")
for(i = 0; i < ChechBox.length; i++)
{
if((ChechBox[i].type == "checkbox") && (ChechBox[i].checked) && (ChechBox[i].id > 0))
{
if(ChechBox[i].name == "Image")
{
if(j > 0)
Temp += "*"
Temp += ChechBox[i].id
j++;
}
else
{
alert("فایل برگزیده حتما باید از فایلهای عکسی باشد");	
return false;
}	
}
}

if(j == 0)
alert("هیچ فایلی انتخاب نشده است")
else if(j > 1)
alert("انتخاب بیش از یک فایل مجاز نمی باشد")
if(j == 1)
{
Info.value = Temp;
if(Select == 0)
Action.value = "SELECTED";
if(Select == 1)
Action.value = "SELECTED_IMAGE";
frmPage.action = "ralbum.php";
frmPage.submit()
}
}

function DeleteAttachAlbum(Code)
{
var frmPage = xGetElementById("frmPage");
var i, j = 0;
var Temp = "";
var Action = xGetElementById("hidAction");
var Info = xGetElementById("hidInfo");
Temp = Code;
if(trim(Temp) != "")
{
if ( window.confirm("Are you sure to delete File") )
{
Info.value = Temp;
Action.value = "DELETE";
frmPage.action = "ralbum.php";
frmPage.submit()
}
}
}

function ManageHTMLFile()
{
var frmPage = xGetElementById("frmPage");
var Action = xGetElementById("hidAction");
var Info = xGetElementById("hidInfo");

Action.value = "EDITWEBPAGE";
frmPage.action = "file.php";
frmPage.submit()
}

function SaveEditedPage(ContentElementName, ContentFileNameElementName)
{
/*alert(*/eval(ContentElementName).getCode()/*)*/;
var frmPage = xGetElementById("frmPage");
var Action = xGetElementById("hidAction");
var Info = xGetElementById("hidInfo");
var Info2 = xGetElementById("hidInfo2");
var State = xGetElementById("hidState");

Action.value = "SAVEEDITEDWEBPAGE";

Info.value = ContentElementName;
Info2.value = ContentFileNameElementName;
State.value = 'File';

frmPage.action = "file.php";
frmPage.submit()
}

function CancelEditingPage()
{
if (confirm('فايل شما ذخيره نخواهد شد، آيا شما مطئين هستيد؟'))
{
EditTopic = xGetElementById('hidCode');
EditTopicUID = EditTopic.value;
EditTopicUID -= 0;
window.location = 'file.php?State=File&UID=' + EditTopicUID;
}
}
