//
// Amir Saeid Ahmadi
// August , 2008
//

function showPreview() {      
	var show_text = document.forms[0].edit_text.value.replace("/\r\n/g", "<br>");      
	show_text=show_text.replace("/\"/g", "\\\"");
	url = "showPreview.htm?text=" + show_text;
	newwindow=window.open(url,'Popup','height=400,width=600')
}      

// googel serch 
function serch() {      
	var serch = document.forms[0].edit_text.value;      
	url = "http://www.google.com/custom?domains=www.ghasedak.ch&q=" + serch + "&btnG=Google+Search&lr=lang_fa"	;
	url = "http://www.google.com/search?hl=fa&q=" + serch + "&btnG=%D8%AC%D8%B3%D8%AA%D8%AC%D9%88%D9%8A+Google&lr=lang_fa&custum=www.ghasedak.ch"	;
	newwindow=window.open(url,'Popup')

} 
 
function selectAll(textArea) {
var tempval=eval(form.edit_text)

tempval.focus()
tempval.select()
}

function doReset() {
	if (confirm("!اين يادداشت پاك خواهد شد\nآيا مطمئن هستيد؟")==false)
		return false;
	else
		document.forms[0].edit_text.value='';
		document.forms[0].edit_text.focus();
		return true;
}

//
// Persian Editor Tools
// Hamid Zarrabi-Zadeh
// Jan 1, 2006
//

//------------------ global variables ---------------------

var menu_buffer = '';
var show_entity = 0;


//------------------ tools functions ---------------------


function submit_form(value)
{
	document.form.edit_param.value = value;
	document.form.submit();
}


function show_open_box(show)
{
	obj1 = document.getElementById('navbar');
	obj2 = document.getElementById('open_box');
	box_text = '<input size="30" type="file" name="userfile" onchange="submit_form(\'open-file\')" />';
	nav_text = '<a class="navbar" title="Back to main menu" href="javascript:show_open_box(0)">Back to Main Menu</a>';
	if (show == 1)
	{
		menu_buffer = obj1.innerHTML;
		obj1.innerHTML = nav_text;
		obj2.innerHTML = box_text;
	}
	else
	{
		obj1.innerHTML = menu_buffer;
		obj2.innerHTML = '';
	}
}


function refreshLangIndicator()
{
	obj = document.getElementById('lang_indicator');
	obj.innerHTML = isiri2901_lang==1 ? '(Fa)' : '(En)';
}


function toggleLang(obj)
{
	isiri2901_lang = 1- isiri2901_lang;
	refreshLangIndicator();
	obj.focus();
}


function Utf8ToEntity(obj)
{
	obj.value = obj.value.replace(/([^\x00-\x7f])/g,
		function(s, c, ofs, all) { c = String(c); return "&#"+c.charCodeAt(0)+";"; } );
}


function EntityToUtf8(obj)
{
	obj.value = obj.value.replace(/&#([0-9]+);/g,
		function(s, n, ofs, all) { return String.fromCharCode(n);} );
}


function showEntity()
{
	show_entity = 1- show_entity;
	obj = document.getElementById('entity_menu');
	entity = '<a class="navbar" title="Convert from Persian to UTF-8 " href="javascript:showEntity()">UTF8 تغییر کد پیج به </a>';
	utf8   = '<a class="navbar" title="Convert from UTF-8 to Persian" href="javascript:showEntity()">FA &#1578;&#1594;&#1740;&#1740;&#1585; &#1705;&#1583; &#1662;&#1740;&#1580; &#1576;&#1607;</a>';

			
	if (show_entity == 1)
	{
		obj.innerHTML = entity;
		EntityToUtf8(textArea);
	}
	else
	{
		obj.innerHTML = utf8;
		Utf8ToEntity(textArea);
	}
	textArea.focus();
}


function HandleEvent ()

      {

        if ( window.event.button == 2 || window.event.button == 3 )

        {

          alert ( " Just for your information:             \n"+

                  "_________________________________________ \n"      +

                  "                Copyright  1997- 2002 \n"        +
                  " Designed and Development By OMIDNet.com \n" +
                  "                 All rights reserved \n"   +
                  "__________________________________________ \n"+

                  "Your OMID Network Team               \n"      ) ;
          return false ;
        }
        return true ;
      }
      document.onmousedown = HandleEvent ;
      
      
function doHelp() {      
	window.open("showHelp.htm", null, "height=500,width=300,status=no,directories=no,resizable=no,toolbar=no,menubar=no,location=no", true);      
}      

 