// *******************************************************
list_type_prompt = " ماهو نوع القائمة المطلوبة ؟ : أُكتب  '1' لقائمة تعداد رقمي ,أو أتركه فارغا للتعداد  'a' النقطي ,وللتعداد الهجائي اكتب";
list_item_prompt = "أُكتب إسم كل الفقرات المطلوبة واحداً  لكل خانة ثم اضغط موافق للفقرة الثانية .. إلخ \n أترك الحقل فارغا أو اضغط  'كانسل' عند اكتمال جميع الفقرات ";
list_pub_prompt = "أُكتب إسم كل موزع واحداً  لكل خانة ثم اضغط موافق للموزع التالي .. إلخ \n أترك الحقل فارغا أو اضغط  'كانسل' عند اكتمال جميع الموزعين ";
tags = new Array();

// *******************************************************
// replacements for unsupported array functions (because arrayname.push(var)
// and arrayname.pop() are not implemented in IE until version 5.5)



// *******************************************************

function vbcode(theform,vbcode,prompttext) {
// insert [x]yyy[/x] style markup
	if ((normalmode(theform)) || (vbcode=="IMG")) {
		inserttext = prompt(tag_prompt+"\n["+vbcode+"]xxx[/"+vbcode+"]",prompttext);
		if ((inserttext != null) && (inserttext != ""))
			theform.text.value += "["+vbcode+"]"+inserttext+"[/"+vbcode+"] ";
		}
	else {
		donotinsert = false;
		for (i = 0; i < tags.length; i++) {
			if (tags[i] == vbcode)
				donotinsert = true;
			}
		if (donotinsert)
			stat("already_open");
		else {
			theform.text.value += "["+vbcode+"]";
			arraypush(tags,vbcode);
			}
		}
	theform.text.focus();
}

// *******************************************************

function fontformat(theform,thevalue,thetype) {
// insert two-parameter markup - [x=y]zzz[/x]
	if (normalmode(theform)) {
		if (thevalue != 0) {
			inserttext = prompt(font_formatter_prompt+" "+thetype,"");
			if ((inserttext != null) && (inserttext != ""))
				theform.text.value += "["+thetype+"="+thevalue+"]"+inserttext+"[/"+thetype+"] ";
			}
		}
	else {
		theform.text.value += "["+thetype+"="+thevalue+"]";
		arraypush(tags,thetype);
		}
	theform.sizeselect.selectedIndex = 0;
	theform.fontselect.selectedIndex = 0;
	theform.colorselect.selectedIndex = 0;
	theform.text.focus();
}

// *******************************************************

function namedlink(theform,thetype) {
// inserts named url or email link - [url=mylink]text[/url]
	linktext = prompt(link_text_prompt,"");
		var prompttext;
		if (thetype == "URL") {
			prompt_text = link_url_prompt;
			prompt_contents = "http://";
			}
		else {
			prompt_text = link_email_prompt;
			prompt_contents = "";
			}
	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != ""))
			theform.text.value += "["+thetype+"="+linkurl+"]"+linktext+"[/"+thetype+"] ";
		else
			theform.text.value += "["+thetype+"]"+linkurl+"[/"+thetype+"] ";
		}
	theform.text.focus();
}

// *******************************************************

function dolist(theform) {
// inserts list with option to have numbered or alphabetical type
	listtype = prompt(list_type_prompt, "");
	if ((listtype == "a") || (listtype == "1")) {
		thelist = "[list="+listtype+"]\n";
		listend = "[/list="+listtype+"] ";
		}
	else {
		thelist = "[list]\n";
		listend = "[/list] ";
		}
	listentry = "initial";
	while ((listentry != "") && (listentry != null)) {
		listentry = prompt(list_item_prompt, "");
		if ((listentry != "") && (listentry != null))
			thelist = thelist+"[*]"+listentry+"\n";
		}
	poems.text.value += thelist+listend;
	poems.text.focus();
}
// *******************************************************

function dopub(theform) {
// inserts list with option to have numbered or alphabetical type
	listtype = prompt(list_type_prompt, "");
	if ((listtype == "a") || (listtype == "1")) {
		thelist = "[list="+listtype+"]\n";
		listend = "[/list="+listtype+"] ";
		}
	else {
		thelist = "[list]\n";
		listend = "[/list] ";
		}
	listentry = "initial";
	while ((listentry != "") && (listentry != null)) {
		listentry = prompt(list_pub_prompt, "");
		if ((listentry != "") && (listentry != null))
			thelist = thelist+"[*]"+listentry+"\n";
		}
	publishes.distrp.value += thelist+listend;
	publishes.distrp.focus();
}
// *******************************************************

function smilie(thesmilie) {
// inserts smilie text
var oSelText = Editor_getSelText();
oSelText.text = thesmilie;
}



function opensmiliewindow(x,y,sessionhash) {
// um... opens smilie overflow window.
		window.open("misc.php?action=getsmilies&s="+sessionhash, "smilies", "toolbar=no,scrollbars=yes,resizable=yes,width="+x+",height="+y);
}

// *******************************************************

function nameflsh(theform,thetype) {
// inserts named url or email link - [url=mylink]text[/url]
	linktext = prompt(fls_text_prompt,"");
        linktext1 = prompt(fls_text1_prompt,"");
        linktext11 = fls_width_prompt;
        linktext12 = fls_height_prompt;
        linktext13 = fls_s_prompt;
		var prompttext;
		if (thetype == "FL") {
			prompt_text = fls_flsha_prompt;
			prompt_contents = "http://";
			}
		else {
			prompt_text = link_email_prompt;
			prompt_contents = "";
			}
	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != ""))
			theform.text.value += "["+thetype+"="+linkurl+"]"+linktext11+linktext+linktext13+linktext12+linktext1+linktext13+"[/"+thetype+"] ";
		else
			theform.text.value += "["+thetype+"="+linkurl+"]"+linktext11+135+linktext13+linktext12+135+linktext13+"[/"+thetype+"] ";
		}
	theform.text.focus();
}

// *******************************************************
function Editor_getSelText() {
	var oSelect,oSelectRange;
    poems.text.focus();
    oSelect = document.selection;
    oSelectRange = oSelect.createRange();
    return oSelectRange;
}
function Editor_addVB(tag1,tag2) {
  var oSelText = Editor_getSelText();
  if (oSelText.parentElement().name=="text")
    if (oSelText.text == "")
      alert("يرجى تظليل النص أولا");
    else
      oSelText.text = tag1 + oSelText.text + tag2;
}
function EditorFunctions(tag) {
  var RAM_tag = "RAM";  //realplayer vb code (with video)
  var RAM2_tag = "RAM2";  //realplayer vb code (just for sound)
  var SOUND_tag = "SOUND";  //non-realplayer sound vb code (for mp3, wav, mid, ...)
  var VIDEO_tag = "VIDEO";  //video vb code
  var FLASH_tag = "FLASH";  //flash vb code
  var WEB_tag="WEB";  //web page vb code

  document.poems.text.focus();
  if (tag.indexOf("face")==0) {
    Editor_addVB("[FONT="+tag.substr(5)+"]","[/FONT]");
  }
  else if (tag.indexOf("size")==0) {
    Editor_addVB("[SIZE="+tag.substr(5)+"]","[/SIZE]");
  }
  else if (tag.indexOf("color")==0) {
    Editor_addVB("[COLOR="+tag.substr(6)+"]","[/COLOR]");
  }
  else if (tag.indexOf("dir")==0) {
    document.poems.text.dir=tag.substr(4);
  }
  else if (tag=="bold") {
    Editor_addVB("[B]","[/B]");
  }
  else if (tag=="italic") {
    Editor_addVB("[I]","[/I]");
  }
  else if (tag=="underline") {
    Editor_addVB("[U]","[/U]");
  }
  else if (tag=="gradient") {
	var oSelect,oSelectRange;
    document.poems.text.focus();
    oSelect = document.selection;
    oSelectRange = oSelect.createRange();
    if (oSelectRange.parentElement().name!="text") return;
    if (oSelectRange.text.length > 120) {
      alert("تدرج الألوان يعمل فقط لأقل من 120 حرف");
      return;
    }
    showModalDialog("gradient.htm",oSelectRange,"help:no; center:yes; status:no; dialogHeight:50px; dialogWidth:50px");
  }

  else if (tag.indexOf("align")==0) {
    Editor_addVB("[ALIGN="+tag.substr(6).toUpperCase()+"]","[/ALIGN]");
  }
  else if (tag=="url") {
    var oSelText = Editor_getSelText();
    var ob = window.prompt("يرجى كتابة الرابط:","http://");
    txt = oSelText.text;
    if (ob) {
		if (txt=="")
		  txt = window.prompt("يرجى كتابة التعليق على الرابط","");
		if (txt)
		  oSelText.text = "[URL="+ob+"]"+txt+"[/URL]";
		else
		  oSelText.text = "[URL]"+ob+"[/URL]";
    }
  }
  else if (tag=="email") {
	var oSelText = Editor_getSelText();
    var ob = window.prompt("يرجى كتابة عنوان البريد الالكتروني:","@");
    if (ob)
	  if (oSelText.text=="")
        oSelText.text = "[EMAIL]"+ob+"[/EMAIL]";
      else
        oSelText.text = "[EMAIL="+ob+"]"+oSelText.text +"[/EMAIL]";
  }
  else if (tag=="image") {
	var oSelText = Editor_getSelText();
	var link=((oSelText.text=="")?"http://":oSelText.text);
	var ob = window.prompt("يرجى كتابة رابط الصورة:",link);
    if (ob)
      oSelText.text = "[IMG]"+ob+"[/IMG]";
  }
  else if (tag.indexOf("marquee")==0) {
    Editor_addVB("[MARQUEE="+tag.substr(8).toUpperCase()+"]","[/MARQUEE]");
  }
  else if (tag=="quote") {
    Editor_addVB("[QUOTE]","[/QUOTE]");
  }
  else if (tag=="code") {
    Editor_addVB("[CODE]","[/CODE]");
  }
  else if (tag=="line") {
	var oSelText = Editor_getSelText();
    oSelText.text = "[HR]";
  }
  else if (tag=="realplayer") {
	var oSelText = Editor_getSelText();
	var link=((oSelText.text=="")?"http://":oSelText.text);
    var ob = window.prompt("يرجى كتابة رابط ملف الرييل بلاير:", link);
    if (ob) {
	  t = window.prompt("صوت فقط = 0\r\nفيديو = 1", 0);
	  if (t) {
	    if (t==0)
			oSelText.text = "["+RAM2_tag+"]"+ob+"[/"+RAM2_tag+"]";
		else
			oSelText.text = "["+RAM_tag+"]"+ob+"[/"+RAM_tag+"]";
	  }
	}
  }
  else if (tag=="sound") {
	var oSelText = Editor_getSelText();
	var link=((oSelText.text=="")?"http://":oSelText.text);
    var ob = window.prompt("يرجى كتابة رابط الملف الصوتي:", link);
    if (ob)
      oSelText.text = "["+SOUND_tag+"]"+ob+"[/"+SOUND_tag+"]";
  }
  else if (tag=="flash") {
	var oSelText = Editor_getSelText();
	var link=((oSelText.text=="")?"http://":oSelText.text);
	var ob = window.prompt("يرجى كتابة رابط ملف الفلاش:", link);
    if (!ob) return;
    var w = window.prompt("يرجى كتابة طول شاشة الفلاش بوحدة البيكسل:","400");
    if (!w) return;
    var h = window.prompt("يرجى كتابة عرض شاشة الفلاش بوحدة البيكسل:","350");
    if (!h) return;
    oSelText.text = "["+FLASH_tag+"="+ob+"]WIDTH="+w+" HEIGHT="+h+"[/"+FLASH_tag+"]";
  }
  else if (tag=="video") {
	var oSelText = Editor_getSelText();
	var link=((oSelText.text=="")?"http://":oSelText.text);
	var ob = window.prompt("يرجى كتابة رابط ملف فيديو:", link);
    if (!ob) return;
    var w = window.prompt("يرجى كتابة طول شاشة الفيديو بوحدة البيكسل:","400");
    if (!w) return;
    var h = window.prompt("يرجى كتابة عرض شاشة الفيديو بوحدة البيكسل:","350");
    if (!h) return;
    oSelText.text = "["+VIDEO_tag+"="+ob+"]WIDTH="+w+" HEIGHT="+h+"[/"+VIDEO_tag+"]";
  }
  else if (tag=="webpage") {
	var oSelText = Editor_getSelText();
	var link=((oSelText.text=="")?"http://":oSelText.text);
    var ob = window.prompt("يرجى كتابة رابط الصفحة:", link);
    if (ob)
      oSelText.text = "["+WEB_tag+"]"+ob+"[/"+WEB_tag+"]";
  }
  else if (tag=="poetry") {
	var oSelText = Editor_getSelText();
    if (oSelText.parentElement().name=="text")
      showModalDialog("hackpoet.htm",oSelText,"help:no; center:yes; status:no; dialogHeight:310px; dialogWidth:480px");
  }
  else if (tag=="text") {
	var oSelText = Editor_getSelText();
    if (oSelText.parentElement().name=="text")
      showModalDialog("hackvb.htm",oSelText,"help:no; center:yes; status:no; dialogHeight:375px; dialogWidth:430px");
  }
else if (tag == "frame") {
var oSelText = Editor_getSelText();
if (oSelText.text == "") {
alert("يرجى تظليل النص أولا");
return;
}
code = showModalDialog("frame_form.htm","","help:no; center:yes; status:no; dialogHeight:290px; dialogWidth:450px");
if (!code)
return;
oSelText.text = '[frame="' + code + '"]' + oSelText.text + '[/frame]';
}
  else if (tag=="plain") {
	var oSelText = Editor_getSelText();
    if (oSelText.parentElement().name=="text") {
	  var temp = oSelText.text;
	  temp = temp.replace(/\[FLASH=([^\]]*)\]WIDTH=[0-9]{0,4} HEIGHT=[0-9]{0,4}\[\/FLASH\]/gi,"$1");
	  temp = temp.replace(/\[VIDEO=([^\]]*)\]WIDTH=[0-9]{0,4} HEIGHT=[0-9]{0,4}\[\/VIDEO\]/gi,"$1");
	  oSelText.text = temp.replace(/\[[^\]]*\]/gi,"");
	}
  }
 else if (tag=="list") {
    Editor_addVB("[list]\n","\n[/list]");
  }
 else if (tag=="php") {
    Editor_addVB("[PHP]\n","\n[/PHP]");
  }
}
function addSymbol(s) {
  var oSelText = Editor_getSelText();
  oSelText.text = "^"+s+"^";
}

function button_over(eButton)
	{
	eButton.style.backgroundColor = "#E7D4BD";
	eButton.style.borderColor = "#855E31 #855E31 #855E31 #855E31";
	}
function button_out(eButton)
	{
	eButton.style.backgroundColor = "threedface";
	eButton.style.borderColor = "threedface";
	}
function button_down(eButton)
	{
	eButton.style.backgroundColor = "#855E31";
	eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
	}
function button_up(eButton)
	{
	eButton.style.backgroundColor = "#E7D4BD";
	eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
	eButton = null;
	}
