var AttachmentCode = 0;
var RefreshTimeForLayerMoving = 10;
var DivLayerIsMoving = 10;
var Lang;
var PrevScrollTop = 0;
var PrevScrollLeft = 0;

var DivLayer;

function ManageHTMLPage()
{
}

function LoadPage()
{
DivLayer = xGetElementById('newAttachments');
RefreshMethod();
}

function ToggleAbility(CompID, StatusComp)
{
oObject = xGetElementById(StatusComp);
oSubject = xGetElementById(CompID);
//alert (typeof oObject.checked);
//alert (typeof oSubject.disabled);
oSubject.disabled = !oObject.checked;

if (!oSubject.disabled)
{
oSubject.focus();
}
else
{
oSubject.value = '';
}
//alert(CompID + '=' + State);
}

function RefreshMethod()
{
if (xGetElementById('newAttachments'))
{CenteralizeDivLayer('newAttachments');}

setTimeout('RefreshMethod()', RefreshTimeForLayerMoving);
}

function CenteralizeDivLayer(DivID)
{
DivLayer = xGetElementById(DivID);
if (DivLayer.style.visibility != 'visible')
{return;}

//if (DivLayerIsMoving)
//{return;}

//DivLayerElement = dd.elements.newAttachments;

//FromTop = DivLayerElement.y - document.body.scrollTop;
//FromLeft = DivLayerElement.x - document.body.scrollLeft;

//alert(DivLayer.style.height);

if (document.body.scrollLeft)
{var scrollLeft = document.body.scrollLeft;}
else
{var scrollLeft = 0;}

if (document.body.scrollTop)
{var scrollTop = document.body.scrollTop}
else
{var scrollTop = 0;}

if (document.documentElement.clientWidth)
{var clientWidth = document.documentElement.clientWidth;}
else
{var clientWidth = 800;}

if (document.documentElement.clientHeight)
{var clientHeight = document.documentElement.clientHeight;}
else
{var clientHeight = 600;}

//alert(DivLayer);

if (DivLayer.style.Width)
{var DivWidth = parseInt(DivLayer.style.Width);}
else
{var DivWidth = 300;}

if (DivLayer.style.Height)
{var DivHeight = parseInt(DivLayer.style.Height);}
else
{var DivHeight = 50;}

var xpos1 = scrollLeft + Math.floor(clientWidth / 2) - Math.floor(DivWidth / 2) - 0;
var ypos1 = scrollTop + Math.floor(clientHeight / 2) - Math.floor(DivHeight / 2) - 0;

DivLayer.style.top = ypos1 + 'px';

DivLayer.style.left = xpos1 + 'px';

//DivLayerElement.moveTo(xpos1, ypos1);
}

function AddAttachEquivalentWithPostMethod()
{
Element = xGetElementById('hidCode');
var AttachmentSubjectCode = Element.value - 0;
SendString = './AddAttachmentDesc.php?Remote&Lang=' + /*DefLang + */'&Subject=' + AttachmentSubjectCode + '&Attachment=' + AttachmentCode + '&redirect=' + escape(window.location.search.substring(1, window.location.search.length));

DescriptionsForm = xGetElementById('AttachDescform')
DescriptionsForm.action = SendString;
//alert (DescriptionsForm.action)
DescriptionsForm.submit();

//alert (SendString);
//DivLayer.style.visibility = 'hidden';
}

function AttachDesc(AID)
{
//alert (typeof  )
if ((typeof NoEquivalentsAvailable) != 'undefined' )
{
alert('هيچ معادلي موجود نمي باشد');
return;
}

AID = AID - 0;

TextBoxes = new Array();

InputObjects = document.getElementsByTagName('input');

var countTextBoxes = 0;
for (var i = 0; i < InputObjects.length; i++)
{
if (InputObjects[i].name.substring(0, 25).toLowerCase() == 'attachementdescriptionfor')
{
TextBoxes[countTextBoxes] = InputObjects[i];
TextBoxes[countTextBoxes].value = '';
countTextBoxes++;
}
}

DivLayer = xGetElementById('newAttachments');

DivLayerElement = dd.elements.newAttachments;

var xpos1 = document.body.scrollLeft + Math.floor(document.body.clientWidth / 2) - Math.floor(25/*DivLayerElement.w / 2*/);
var ypos1 = document.body.scrollTop + Math.floor(document.body.clientHeight / 2) - Math.floor(25/*DivLayerElement.h / 2*/);
//alert("x=" + xpos1 + ", y=" + ypos1);
//DivLayerElement.moveTo(xpos1, ypos1);
xMoveTo(DivLayer, xpos1, ypos1);

//FromTop = DivLayerElement.y - document.body.scrollTop;
//FromLeft = DivLayerElement.x - document.body.scrollLeft;

DivLayer.style.visibility = 'visible';
AttachmentCode = AID;
}

function AddAttachEquivalentWithGetMethod()
{
Element = xGetElementById('hidCode');
var AttachmentSubjectCode = Element.value - 0;

TextBoxes = new Array();
var countTextBoxes = 0;
//alert(AttachmentSubjectCode);

DivLayer = xGetElementById('newAttachments');

SendString = './AddAttachmentDesc.php?Remote&Lang=' + /*DefLang + */'&Subject=' + AttachmentSubjectCode + '&Attachment=' + AttachmentCode;

for (var i = 0; i < InputObjects.length; i++)
{
if (InputObjects[i].name.substring(0, 25).toLowerCase() == 'attachementdescriptionfor')
{
LangIdentifier = InputObjects[i].name.substring(26, InputObjects[i].name.length - 1);
LangDesc = InputObjects[i].value;
SendString += '&Lang' + LangIdentifier + '=' + LangDesc;
//
//alert (LangDesc + AttachmentCode + '-- ' + SendString);
//TextBoxes[countTextBoxes] = InputObjects[i];
//TextBoxes[countTextBoxes].value = '';
countTextBoxes++;
}
}

//alert (SendString);
Remote(SendString);
DivLayer.style.visibility = 'hidden';
}

//function ToggleAblity(ObjectName, Status)
//{
//	Element = getElementsByName(ObjectName)
//}

function DelFile2()
{
txtFileValues = new Array();
txtAttachInfoValues = new Array();
for (i = 1; i < UploadableFilesCount; i++)
{
txtFileValues[i] = xGetElementById('txtFile' + i).value;
txtAttachInfoValues[i] = xGetElementById('txtAttachInfo' + i).value;
}
if (UploadableFilesCount > 1)
{
UploadableFilesCount -= 1;
if (UploadableFilesCount == 1)
{ST = "<input name='button2' type='button' class='ButtonClass' onClick='AddFile2()' value='اضافه' title='اضافه کردن باکس ارسال عکس' style='color:#FF0000;width:100% '>";}
else
{ST = "<input name='button2' type='button' class='ButtonClass' onClick='DelFile2()' value='حذف' title='حذف کردن' style='color:#FF0000;width:40% '> &nbsp;<input name='button2' type='button' class='ButtonClass' onClick='AddFile2()' value='اضافه' title='اضافه کردن باکس ارسال عکس' style='color:#FF0000;width:40%'>";}
TD = xGetElementById('Buttom')
TD.innerHTML = ST;
Table = xGetElementById('AddTable')
Table.innerHTML = "";

for (i = 1; i < UploadableFilesCount; i++)
{
STR = "<table width='100%'><tr><td width='40%' colspan='1' align='right'><input type='file' name='txtFile[" + i + "]' id='txtFile" + i + "' class='textClass' style='width:90%; height:30' value='" + txtFileValues[i] + "'>";
STR += "</td><td width='6%' style='border:0'>توضيحات</td><td colspan='3' width='30%' align='right'>";
STR += "<input type='text' name='txtAttachInfo[" + i + "]' id='txtAttachInfo" + i + "' class='textClass' style='width:100%;height:30' value='" + txtAttachInfoValues[i] + "'></td></tr></table>";
Table = xGetElementById('AddTable')
Table.innerHTML += STR;
}

for (i = 1; i < UploadableFilesCount; i++)
{
xGetElementById('txtFile' + i).value = txtFileValues[i];
xGetElementById('txtAttachInfo' + i).value = txtAttachInfoValues[i];
}
}
else
{
alert('امکان حذف کردن وجود ندارد!');
}

}

function AddFile2()
{
txtFileValues = new Array();
txtAttachInfoValues = new Array();
for (i = 1; i < UploadableFilesCount; i++)
{
txtFileValues[i] = xGetElementById('txtFile' + i).value;
txtAttachInfoValues[i] = xGetElementById('txtAttachInfo' + i).value;
}

TD = xGetElementById('Buttom')
STT = "<input name='button2' type='button' class='ButtonClass' onClick='DelFile2()' value='حذف' title='حذف کردن' style='color:#FF0000;width:40% '>";
STT += "&nbsp;<input name='button2' type='button' class='ButtonClass' onClick='AddFile2()' 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;

for (i = 1; i < UploadableFilesCount; i++)
{
d = xGetElementById('txtFile' + i).value = txtFileValues[i];
xGetElementById('txtAttachInfo' + i).value = txtAttachInfoValues[i];
}

UploadableFilesCount += 1;
}

function GoToNewBlankWithSize(URL, Width, Height)
{
ScreenHeight = screen.availHeight;
ScreenWidth = screen.availWidth;

var Left = Math.floor((ScreenWidth - Width) / 2);
var Top = Math.floor((ScreenHeight - Height) / 2);

var NewWindow = window.open(URL, "", "left=" + Left + ",top=" + Top + ",width=" + Width + ",height=" + Height + ",status=1,scrollbars=1,menubar=0,toolbar=0,resizable=0");
}

function FloatTopDiv()
{
var startX = 3,
startY = 150;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function ml(id)
{
var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
if(d.layers)el.style=el;
el.sP=function(x,y){this.style.left=x;this.style.top=y;};
el.x = startX;
if (verticalpos=="fromtop")
el.y = startY;
else{
el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
el.y -= startY;
}
return el;
}
window.stayTopLeft=function()
{
if (verticalpos=="fromtop"){
var pY = ns ? pageYOffset : document.body.scrollTop;
ftlObj.y += (pY + startY - ftlObj.y)/8;
}
else{
var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
ftlObj.y += (pY - startY - ftlObj.y)/8;
}
ftlObj.sP(ftlObj.x, ftlObj.y);
setTimeout("stayTopLeft()", 10);
}
ftlObj = ml("newAttachments");
stayTopLeft();
}
