﻿window.setTimeout("showAllDropDownLists();", 1000);
var oPopup = window.createPopup();

function putSelectValueIntoText()
{
	var ddl = window.event.srcElement;
	document.getElementById(ddl.id + "_Text").value = ddl.value;
}

// This function is used to capitalize the code of entities
function toUpper()
{
	if (window.event.keyCode >= 97 /* a */ && window.event.keyCode <= 122 /* z */)
		window.event.keyCode -= 32;
}

function toLower()
{
	if (window.event.keyCode >= 65 /* A */ && window.event.keyCode <= 90 /* Z */)
		window.event.keyCode += 32;
}

// This is because of a bug in ComponentArt Snap Control where it hides DropDownList controls
function showAllDropDownLists()
{
	var elements = document.getElementsByTagName("select");
	var i;
	
	for (i=0; i < elements.length; i++)
	{
		if (elements[i].id.toUpperCase().indexOf("DROPDOWNLIST") != -1)
			elements[i].style.visibility="visible";
	}
}

function ReloadParent()
{
	window.opener.document.location.reload();
	window.close();
}

function OpenPopUp(Address, Width , Height, scroll, top, left)
{
	if (scroll == null) scroll="off";
	if (top == null)
		top = (screen.height - Height) / 2;
	if (left == null)
		left = (screen.width - Width) / 2;

	var Features = 'width='+Width+',height='+Height+',top=' + top + ',left=' + left + ',scroll='+ scroll +', resizable=0,status:off;';
	window.open(Address, "_blank", Features);
}

function OpenModalDialog(Address, Width , Height, scroll, pcname, top, left)
{
	if (scroll == null) scroll="off";
	if (top == null)
		top = (screen.height - Height) / 2;
	if (left == null)
		left = (screen.width - Width) / 2;
	
	var Features = 'dialogHeight=' + Height +'px;dialogWidth=' + Width+' px;dialogTop=' + top + ';dialogleft=' + left  +'px;'+ 'resizable:no; scroll:'+ scroll + '; help:off; status:off; unadorned:yes;';
	
	var rvalue = window.showModalDialog(Address, self, Features); 
	if (pcname != null && rvalue != null)
		document.getElementById(pcname).value = rvalue;
}

function CloseWindow(returnId, returnName)
{
	if (returnId)
	{
		// see if there is a pc in the query string
		var is_q = document.URL.indexOf('pc=');

		// check the pc is there
		if (is_q != -1)
		{ 
			var opener = window.dialogArguments;
			if (!opener)
				opener = window.opener;
			
			opener.document.getElementById(document.URL.substring(is_q+3, document.URL.length)).value = returnId;
		}
	}
	window.returnValue = returnName;
	window.close();
}

function CloseWindowAndAppend(returnId, returnName)
{
	if (returnId)
	{
		// see if there is a pc in the query string
		var is_q = document.URL.indexOf('pc=');

		// check the pc is there
		if (is_q != -1)
		{ 
			var opener = window.dialogArguments;
			if (!opener)
				opener = window.opener;
			
			opener.document.getElementById(document.URL.substring(is_q+3, document.URL.length)).value += returnId;
		}
	}
	window.returnValue += returnName;
	window.close();
}

function PrintPage(control)
{
	control.style.visibility = "hidden";
	window.print();
	control.style.visibility = "visible";		  
}

function richToolTip(control,title , description,width,height)
{	
	var lefter = event.offsetX + 15;
	var topper = event.offsetY + 15;
	var result = oToolTip.innerHTML.replace('{0}', title ); 
	result = result.replace('{1}', description);
	oPopup.document.body.innerHTML = result;
	oPopup.show(lefter, topper, width, height, control);
}

function CheckLength(control)
{
	LenString = control.value.length;
	if (LenString > 500)
	{
		control.value = control.value.substring(0,500);
	}
}

function changecolor(n)
{
	if (n == null)
		n = 4;

	con = window.event.srcElement;
	con_hidden = document.getElementById(con.id + "_Hidden");
	con_hidden.value++;
	con_hidden.value%=n;
	
	con.className = "ColorChanger" + con_hidden.value;
}

function changebackcolor()
{
	window.event.srcElement.className = "Evaluation" + window.event.srcElement.value;
}

function setFocus(id)
{
	try
	{
		document.getElementById(id).focus();
	}
	catch(myError)
	{}
}

function get_evaluation_by_name(n)
{
    if (n == 'روغن نو')
            return 1;

    if (n == 'رضایت‌بخش')
            return 2;

    if (n == 'قابل قبول')
            return 3;

    if (n == 'مرزی')
            return 4;

    if (n == 'رسیدگی سریع')
            return 5;

    if (n == 'بحرانی')
            return 6;

    if (n == 'فاقد ارزیابی')
            return 7;

            return 0;
}
