			var VIRK_LAYOUT = "";
			var VIRK_NOKBD = /*#VIRK_NOKBD*/false/*#end*/;
			if (!window.VIRK_PATH)
			   window.VIRK_PATH = "";
			var VIRK_SIZE = [/*#VIRK_SIZE*/310,134/*#end*/];
			var theVirk = null;
			var TOP_VK=120, LEFT_VK=260;
			
			ctrlAttachEvent (window, "load", function () { theVirk = new Virk () });
			ctrlAttachEvent (window, "unload", function () { kbdShowHide () });
			
			function Browser () {
			   var userAgent = navigator.userAgent.toLowerCase ();
			   this.major    = parseInt (navigator.appVersion);
			   this.version  = parseFloat (navigator.appVersion);
				if (userAgent.indexOf ("safari") >= 0) {
			      this.sfr    = true;
			   }
			   else if (userAgent.indexOf ("opera") >= 0) {
			      this.opera = true;
			   }
			   else if (userAgent.indexOf ("msie") >= 0) {
			      this.ie    = true;
			   }
			   else if (userAgent.indexOf ("mozilla") >= 0) {
			      this.ns    = true;
			      this.ns4   = (this.version >= 4 && this.version < 5);
			   }
			   this.win      = (userAgent.indexOf ("win") >= 0);
			   this.mac      = (userAgent.indexOf ("mac") >= 0);
			   this.unix     = (userAgent.indexOf ("x11") >= 0);
			   this.lineSep  = (this.mac ? '\r' : '\n');
			   this.ie6SP2   = (userAgent.indexOf("sv1") != -1)
			   
			}
			
			var browser = new Browser ();
			
			function kbdShowHide (fShow) {
			   if (theVirk)
			      fShow ? theVirk.show () : theVirk.hide ();
			}
			
			function Virk () {
			   this.elem = document.getElementById ("virk");
			   if (this.elem && this.elem.tagName == "IFRAME") {
			      this.wnd = window.frames ["virk"];
			      this.show = virkFrameShow;
			      this.hide = virkFrameHide;
			      if (this.elem.style.visibility != "hidden" && this.elem.style.display != "none")
			         this.show ();
			   }
			   else {
			      this.show = virkDialogShow;
			      this.hide = virkDialogHide;
			   }
			   
			   this.attachOnFocus ();
			   if (VIRK_NOKBD) {
			      this.blockKbd ();
			      this.show ();
			   }
			}
			
			function virkDialogShow () {
			TOP_VK="200"; 
			
			if (TOP_VK == "")   TOP_VK = 10;
			if (LEFT_VK == "") LEFT_VK = 10;
			   if (this.wnd && !this.wnd.closed)
			      return;
			   
			   var href = window.VIRK_PATH + "virk.htm";
			   if (VIRK_LAYOUT)
			      href += "?layout=" + VIRK_LAYOUT;
			   if (window.showModelessDialog) {
			
			      var st_bar_resizer = 22;
			      if(browser.ie6SP2) st_bar_resizer = 50;
			      
			      var features = "dialogWidth:" + (VIRK_SIZE [0] + 6) + "px;dialogHeight:" + (VIRK_SIZE [1] + st_bar_resizer) + "px;dialogTop:"+TOP_VK+"px;dialogLeft:"+LEFT_VK+"px;"
			                   + ";scroll:no;help:no;status=no;";
			      this.wnd = window.showModelessDialog (href, window, features);
			   }
			   else {   
			      var features = "dependent=yes,width=" + VIRK_SIZE [0] + ",height=" + VIRK_SIZE [1]
			                   + ",top="+TOP_VK+", left="+LEFT_VK+", scroll=no,help=no,status=no,directories=no,menubar=no,resizable=no";
			      if (navigator.platform.indexOf ("Mac") < 0)
			         features += ",dialog=yes";
			      this.wnd = window.open (href, "Virk", features);
			   }
			}
			
			function virkDialogHide () {
			   if (this.wnd && !this.wnd.closed)
			      this.wnd.close ();
			   this.wnd = null;
			}
			
			function virkFrameShow () {
			   this.elem.style.visibility = "visible";
			   if (this.wnd && this.wnd.virkCtrl) {
			      if (VIRK_LAYOUT) {
			         this.wnd.virkCtrl.setLayout (VIRK_LAYOUT);
			         VIRK_LAYOUT = "";
			      }
			      this.wnd.virkCtrl.attach (window);
			   }
			}
			
			function virkFrameHide () {
			   this.elem.style.visibility = "hidden";
			   if (this.wnd && this.wnd.virkCtrl)
			      this.wnd.virkCtrl.detach ();
			}
			
			Virk.prototype.blockKbd = function () {
			   for (var i = 0; i < document.forms.length; ++i) {
			      var ctrls = document.forms [i].elements;
			      for (var j = 0; j < ctrls.length; ++j) {
			         if (isEditable (ctrls [j])) {
			            ctrls [j].onkeypress = function () { return false; }
			            ctrls [j].onclick = function () { theVirk.show (); }
			         }
			      }
			   }
			}
			
			Virk.prototype.attachOnFocus = function (wnd) {
			   try {
			      wnd = wnd ? wnd : window;
			      var forms = wnd.document.forms;
			      for (var i = 0; i < forms.length; ++i) {
			         var ctrls = forms [i].elements;
			         for (var j = 0; j < ctrls.length; ++j) {
			            if (isEditable (ctrls [j]))
			               ctrlAttachEvent (ctrls [j], "focus", virkOnFocus);
			         }
			      }
			      
			      var frames = wnd.document.getElementsByTagName ("FRAME");
			      for (var i = 0; i < frames.length; ++i)
			         ctrlAttachEvent (frames [i], "load", virkOnLoadFrame);
			      
			      frames = wnd.document.getElementsByTagName ("IFRAME");
			      for (var i = 0; i < frames.length; ++i)
			         ctrlAttachEvent (frames [i], "load", virkOnLoadFrame);
			      
			      for (var i = 0; i < wnd.frames.length; ++i)
			         this.attachOnFocus (wnd.frames [i]);
			   }
			   catch (e) {
			   }
			}
			
			Virk.prototype.getLayout = function () {
			   if (!this.wnd || this.wnd.closed)
			      return "";
			   return this.wnd.virkCtrl.getLayout ();
			}
			
			function virkOnLoadFrame () {
			   theVirk.attachOnFocus ();
			}
			
			function virkOnFocus (e) {
			   e = e || window.event;
			   theVirk.activeCtrl = e.srcElement || e.target;
			}
			
			function isEditable (ctrl) {
			   return ctrl.isContentEditable
			       || ctrl.tagName == "INPUT" && ctrl.type == "text"
			       || ctrl.tagName == "TEXTAREA";
			}
			
			function ctrlAttachEvent (ctrl, type, listener) {
			   if (ctrl.addEventListener) {
			      ctrl.addEventListener (type, listener, false);
			   }
			   else if (ctrl.attachEvent) {
			      ctrl.detachEvent ("on" + type, listener);
			      ctrl.attachEvent ("on" + type, listener);
			   }
			   else {
			      ctrl ["on" + type] = listener;
			   }
			}
	
	
	   //---------------------------------------------------------------------------
		var flag
		flag=0
		
		function change(obj) {
		  if (flag==0)
		    flag=1
		  else
		    flag=0;
		
		  obj.focus();
		}
		
		
		function convert(myfield,e) {
		  if (flag != 0) {
		    return true;
		  }
		
		  if (window.event) {
		    e = window.event;
		    obj = e.srcElement;
		    key = e.keyCode;
		  } else {
		    obj = e.target;
		    key = e.charCode;
		  }
		
		
		  if ((key > 32) && (key < 128)) {
		    if (key==42 || key==126 || key==63) return;
		    key=' !"#$%،گ)(×+و-./0123456789:ك,=.؟@ِذ}ىُىلآ÷ـ،/’د×؛َءٍف‘{ًْإ~جژچ^_پشذزيثبلاهتنمئدخحضقسفعرصطغظ<|>ّ'.charCodeAt(key-32);
		
		    try {
		      // Gecko before banning fake key emission.
		      e.initKeyEvent("keypress", true, true, document.defaultView, false, false, true, false, 0, key, obj);
		    } catch (err) {
		      try {
		        // Windows
		        e.keyCode = key;
		      } catch (err) {
		        try {
		          // Try inserting at cursor position, Gecko after banning fake key emission
		          pnhMozStringInsert(obj, String.fromCharCode(key));
		          e.preventDefault();
		        } catch (err) {
		          // Everything else, simply add to the end of buffer
		          obj.value += String.fromCharCode(key);
		          e.preventDefault();
		        }
		      }
		    }
		  } //if
		
		
		  return true;
		}	
	
	
	
		//------------------------------------------------------------------------------------------------	
	
	
		function checkLang () {
		  
		  
		  
		  if ((document.mainForm.dic[2].checked) ) {   // Toggle to English
		    change(document.mainForm.word) ;
		    setLeftToRight ();
		    return;
		  }
		
		  if ((document.mainForm.dic[0].checked) || (document.mainForm.dic[1].checked) ) {   // Toggle to Farsi
		    change(document.mainForm.word) ;
		    setRightToLeft ();
		    return;
		  }
		}
				
		function setRightToLeft () {
		  document.mainForm.word.title = "You can type in Farsi";
		  document.mainForm.word.style.textAlign = "right";
		  document.mainForm.word.style.direction = "rtl";
		  document.mainForm.word.focus ();
		  flag=0;
		}
		
		function setLeftToRight () {
		  document.mainForm.word.title = "You can type in English";
		  document.mainForm.word.style.textAlign = "left";
		  document.mainForm.word.style.direction = "ltr";
		  document.mainForm.word.focus ();
		  flag=1;
		}
				
		function setLanguage () {
		  if (!document.mainForm.dic[2].checked) {//Farsi
		    document.mainForm.dic[0].checked = true;
		    setRightToLeft ();
		  }
		  else {//English
		    document.mainForm.dic[2].checked = true;
		    setLeftToRight ();
		  }
		}  	

