/**
 * In The Name of Allah, The Most Gracious, The Most Merciful
 * 
 * @version 6.0.x.x
 * @copyright Copyright (c) 2008/1387, vwideas.com
 */

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 CenteralizeLayer(Layer)
{
	return CenteralizeDivLayer(Layer);
}

function CenteralizeDivLayer(DivID)
{
	DivLayer = xGetElementById(DivID);
	if (DivLayer.style.visibility == 'hidden')
	{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;

	InputObjects = xGetElementsByTagName('input');

	TextBoxes = new Array();
	var countTextBoxes = 0;
	for (var i = 0; i < InputObjects.length; i++)
	{
		if (InputObjects[i].name.substring(0, 24).toLowerCase() == 'attachmentdescriptionfor')
		{
			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;

	xVisibility(DivLayer, true);
	AttachmentCode = AID;
}

function EquateObjectFileForObjectsMultiLingualEquivalents(ObjectUID, Languages)
{
	Languages = Languages.split(';');
	var LLength = Languages.length;
	if (LLength)
	{
		var NewLayerForEquation = xCreateElement('div');
		for(var i = 0; i < LLength; i++)
		{
			Languages[i] = Languages[i].split(':');
			if (Languages[i].length != 2)
			{
				return false;
			}
			var NewEquivalent = xCreateElement('input');
			NewEquivalent.type = 'text'; 
			NewEquivalent.title = Languages[i][0]; 
			NewEquivalent.value = Languages[i][1]; 
			xAppendChild(NewLayerForEquation, NewEquivalent);
		}
		xAppendChild(document.body, NewLayerForEquation);
	}
}

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, 24).toLowerCase() == 'attachmentdescriptionfor')
		{
			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);
	xVisibility(DivLayer, false);
}

//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')
		xInnerHtml(TD, ST);
		Table = xGetElementById('AddTable')
		xInnerHtml(Table, "");

		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')
			xInnerHtml(Table, xInnerHtml(Table) + 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% '>";
	xInnerHtml(TD, 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')
	xInnerHtml(Table, xInnerHtml(Table) + STR);
	
	for (i = 1; i < UploadableFilesCount; i++)
	{
		d = xGetElementById('txtFile' + i).value = txtFileValues[i];
		xGetElementById('txtAttachInfo' + i).value = txtAttachInfoValues[i];
	}

	UploadableFilesCount += 1;
}

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();
}

function GetDocFileOfCurrentList(Evt, TableID)
{
	TableID = xGetElementById(TableID);

	hiddenValue = "";
	var n = 0;
	for (var i = 0; i < TableID.rows.length; i++) {
		Row = TableID.rows[i];
		//Cell = Row.cells[0];
		if (xFirstChild(Row.cells[0]))
		{
			if (Row.cells[0].firstChild.checked)
			{
				if (n > 0)
				{
					hiddenValue += "*";
				}
				hiddenValue += Row.id;
				n++;
			}
		}
	}
	if (n > 0)
	{
		if (confirm(W_WARNING_CONFIRM))
		{
			alert(_system_URL = 'docfile.php?Objects=' + hiddenValue);
			document.URL = _system_URL;
		}
	}
	else
	{
		alert(W_WARNING_NO_SELECTED);
	}
}
