﻿var Result;
var isiri2901_lang = 1;        // 1: Persian, 0: English
var isiri2901_nativelang = 0;  // 1: Persian, 0: English
var isirikey = [
  0x0020, 0x0021, 0x061B, 0x066B, 0xFDFC, 0x066A, 0x060C, 0x06AF,
  0x0029, 0x0028, 0x002A, 0x002B, 0x0648, 0x002D, 0x002E, 0x002F,
  0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7,
  0x06F8, 0x06F9, 0x003A, 0x06A9, 0x003E, 0x003D, 0x003C, 0x061F,
  0x066C, 0x0624, 0x200C, 0x0698, 0x06CC, 0x064D, 0x0625, 0x0623,
  0x0622, 0x0651, 0x0629, 0x00BB, 0x00AB, 0x0621, 0x0654, 0x005D,
  0x005B, 0x0652, 0x064B, 0x0626, 0x064F, 0x064E, 0x0670, 0x064C,
  0x0653, 0x0650, 0x06A9, 0x062C, 0x067E, 0x0686, 0x00D7, 0x0640,
  0x0698, 0x0634, 0x0630, 0x0632, 0x06CC, 0x062B, 0x0628, 0x0644,
  0x0627, 0x0647, 0x062A, 0x0646, 0x0645, 0x0626, 0x062F, 0x062E,
  0x062D, 0x0636, 0x0642, 0x0633, 0x0641, 0x0639, 0x0631, 0x0635,
  0x0637, 0x063A, 0x0638, 0x007D, 0x007C, 0x007B, 0x007E
];
GlobalFunc();
function Selecttextbox(Textbox, Start, End)
{
	var Range = Textbox.createTextRange(); 
    Range.moveStart("character", Start); 
    Range.moveEnd("character", -Textbox.value.length + End);      
    Range.select();  
}
function ConfirmDelete()
{
    return(confirm("آيا حذف را تاييد مي كنيد؟\n\n (غير قابل برگشت)"));
}
var KeylangFarsi=true;
function FarsiKeyDown()
{
    PersianKeyDown(event);
}
function FarsiKeyPress()
{
    PersianKeyPress(event);
}
function PersianKeyDown(e)
{
  if (window.event)
    e = window.event;
  if (e.keyCode==119)
  {
    if (isiri2901_lang == 0)
      setPersian();
    else
      setEnglish();
    try 
    {
      e.preventDefault();
    } 
    catch (err) 
    {
        //alert(err.message);
    }
    return false;
  }
  return true;
}

function PersianKeyPress(e)
{
  var key;
  if (window.event) 
  {
    e = window.event;
    obj = e.srcElement;
    key = e.keyCode;
  } else 
  {
    obj = e.target;
    key = e.charCode;
  }
  if (key >= 0x00FF) 
  {
    isiri2901_nativelang = 1;
    setPersian();
  } 
  else 
      if (isiri2901_nativelang == 1) 
      {
          isiri2901_nativelang = 0;
          setEnglish();
      }
  if (key < 0x0020 || key >= 0x007F || e.metaKey)
    return true;
  if (isiri2901_lang == 1) 
  {
    if (key == 0x0020 && e.shiftKey)
      key = 0x200C;
    else
      key = isirikey[key - 0x0020];
    try 
    {
      e.initKeyEvent("keypress", true, true, document.defaultView, false, false, true, false, 0, key, obj);
    } 
    catch (err) 
    {
        try 
        {
          e.keyCode = key;
        } 
        catch (err) 
        {
            try 
            {
              pnhMozStringInsert(obj, String.fromCharCode(key));
              e.preventDefault();
            } 
            catch (err) 
            {
              obj.value += String.fromCharCode(key);
              e.preventDefault();
            }
        }
    }
  }
  return true;
}
function setPersian (obj, quiet)
{
  isiri2901_lang = 1;
  if (obj) 
  {
    obj.style.textAlign = "right";
    obj.style.direction = "rtl";
    obj.focus();
  }
  if (!quiet)
    window.defaultStatus = "Persian Keyboard (Press F8 to switch English)";
}


function setEnglish (obj, quiet)
{
  isiri2901_lang = 0;
  if (obj) {
    obj.style.textAlign = "left";
    obj.style.direction = "ltr";
    obj.focus();
  }
  if (!quiet)
    window.defaultStatus = "English Keyboard (Press F8 to switch Persian)";
}
function NumberKeyPress(e)
{
    var KeyCodePressed;
    if (window.event) 
    {
        KeyCodePressed = e.keyCode;
    } 
    else 
    {
        KeyCodePressed=e.charCode;
    }
	if (KeyCodePressed>=48 && KeyCodePressed<=57)
	{ // Numbers
	}
	else if(KeyCodePressed==40)
	{return false; // (
	}
	else if(KeyCodePressed==41){return false; // )
	}
	else if(KeyCodePressed==43){ // +
	}
	else if(KeyCodePressed==45){ // -
	}
	else if(KeyCodePressed==47){ // /
	}
	else if(KeyCodePressed==32)
	{ // SPACE
	    return false;
	}		
	else 
	{
		return false;
	}
	return true;
}
function Disable(objMenu)
{
    objMenu.style.display="none";
}
function ShowLoading(LeftPos,TopPos)
{
    if(document.getElementById && document.getElementById('dvLoading') && document.getElementById('dvLoading').style.display !='block')
    {
        if(LeftPos)
            document.getElementById('dvLoading').style.posLeft=LeftPos;
        if(TopPos)
            document.getElementById('dvLoading').style.posTop=TopPos;
        document.getElementById('dvLoading').style.display='block';
    }
}
function HideLoading()
{
    if(document.getElementById && document.getElementById('dvLoading'))
        document.getElementById('dvLoading').style.display='none';
}
function ShowException(ex,Lang)
{
    if(Lang.toLowerCase()=='fa')
        alert('خطا در بازخواني اطلاعات'+'\n'+ex.message);
    else
        alert('Error Loading Data Please Try Again.\n Error:'+ex.message)
    DeterminSpeed();
    HideLoading();
}
function OpenWindow(Path,Width,Height,modal)
{
    if(!Width)Width='600';
    if(!Height)Height='400';
    if(modal && document.all)
        window.showModalDialog( Path ,'DialogBox','dialogTop:50px;dialogLeft:200px;edge:sunken ;center: Yes; resizable: Yes; status: No;dialogWidth:'+Width+'px;dialogHeight:'+Height+'px;');
    else
	    window.open( Path ,'DialogBox','scrollbars=yes,width='+Width+',height='+Height+'');
	return true;
}
function NavigateTo(Path)
{
    if(document.location)
    {
        document.location=Path;
    }
    else if(typeof(navigate)=="function")
    {
        navigate(Path);
    }
}
function GlobalFunc()
{
    window.status=document.title;
    //if(top.frames.length==0)document.location='../Login.aspx';
    if(document.all)
    {
        //document.oncontextmenu=
        function AvoidRightClick()
        {
            window.event.returnValue = false;
            window.status="Not Allowed!!";
        }
    }
}
function ShowControl(ControlName)
{
    var el=document.getElementById(ControlName);
    if(document.all)
        el.style.display=el.style.display=="block"?"none":"block";
    else
    {
        var csstext=el.getAttribute("style");
        if(csstext=="display: none;")
        {
            el.setAttribute("style","display:block;");
        }
        else
            el.setAttribute("style","display:none;");
    }
}
function InvisibleCon(obj,time)
{
    if(obj==null)
        obj=document.getElementById(obj);
    setTimeout("ShowControl('"+obj.id+"');",time);
}
function LocateMessage()
{
    if(document.all)
        document.all["tblContainer"].style.display="none";
    else if(document.getElementById && document.getElementById("tblContainer"))
    {
        var el=document.getElementById("tblContainer");
        var csstext=el.getAttribute("style");
        el.setAttribute("style","display:none;");
    }
}
function SetDefault(objTargetID,e)
{
    var objTarget=document.getElementById(objTargetID);
    if (window.event) 
    {
        if(e.keyCode==13)
            objTarget.focus();
    } 
    else 
    {
        alert(e);
        if(e.charCode==13)
            objTarget.focus();
    }
}
