// JavaScript Document
//פונקציה לחלון הוספת התמונה הסתרה/הצגה
document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1255\" />");
//הסתרת דיב
function show_hide(msg_id){
msg_id.style.display=msg_id.style.display=="none" ? "" : "none"
}

function show_hideP(msg_id){
obj=document.getElementById(msg_id);
obj.style.display=obj.style.display=="none" ? "" : "none";
}
//הסתרת חלקים
function show_visP(msg_id){
obj=document.getElementById(msg_id);
obj.style.visibility=obj.style.visibility=="hidden" ? "" : "hidden"
}

//פונקציה ללשנויות
function show_hide_ticket(msg_idC,cases_w){
msg_idC.style.display=cases_w;
}
function beginCode(area) 
{
    with (area) 
    {
        focus();
        value += "|הקוד|\r\n";
        area.dir="ltr" 
    }
}

function he(area) 
{
    with (area) 
    {
        focus();
        area.dir="rtl"
    }
}
function en(area) 
{
    with (area) 
    {
        focus();
        area.dir="ltr"
    }
}

function br(area) 
{
    with (area) 
    {
        focus();
        value += "\r\n|enter|\r\n"; 
    }
}
function hr(area) 
{
    with (area) 
    {
        focus();
        value += "|line|"; 
    }
}
function bs(area) 
{
    with (area) 
    {
        focus();
		value += "|bold|";
    }
}
function be(area) 
{
    with (area) 
    {
        focus();
		value += "|ebold|";
    }
}

function goup(area) 
{
    with (area) 
    {
        focus();
		value += "|goup|";
	    area.dir="ltr"
    }
}
//הצגת תמונות בגלריה
function imageBig(selObj,pic) 
{
   	 with (pic) 
    {
        focus();
		src = "/pipewrench/gallery/pic/" + selObj;
		alt = "no image";
    }
}
//שינוי לחצן
function addpicButton(selObj,pic) 
{
   	 with (pic) 
    {
        focus();
		src = "images/" + selObj;
		alt = "no image";
    }
}

//פונקציה להצגת תמונה בחלון ולהוספה לתיבת טקסט
function addpicVI(selObj,pic) 
{
   	 with (pic) 
    {
        focus();
		src = selObj.options[selObj.selectedIndex].value;
		alt = "no image";
    }
}

function addpicT(area,selObj) 
{
    with (area) 
    {
        focus();
		value += "|pic|" + selObj.options[selObj.selectedIndex].value + "|epic|\r\n";
    }
	
}

// apply tagOpen/tagClose to selection in textarea,
// use sampleText instead of selection if there is none
function insertTags(tagOpen, tagClose, sampleText) {
	var txtarea;
	if (document.frm) {
		txtarea = document.frm.tarea;
	} else {
		// some alternate form? take the first one we can find
		var areas = document.getElementsByTagName('textarea');
		txtarea = areas[1];
	}
	var selText, isSample = false;

	if (document.selection  && document.selection.createRange) { // IE/Opera

		//save window scroll position
		if (document.documentElement && document.documentElement.scrollTop)
			var winScroll = document.documentElement.scrollTop
		else if (document.body)
			var winScroll = document.body.scrollTop;
		//get current selection  
		txtarea.focus();
		var range = document.selection.createRange();
		selText = range.text;
		//insert tags
		checkSelectedText();
		range.text = tagOpen + selText + tagClose;
		//mark sample text as selected
		if (isSample && range.moveStart) {
			if (window.opera)
				tagClose = tagClose.replace(/\n/g,'');
			range.moveStart('character', - tagClose.length - selText.length); 
			range.moveEnd('character', - tagClose.length); 
		}
		range.select();   
		//restore window scroll position
		if (document.documentElement && document.documentElement.scrollTop)
			document.documentElement.scrollTop = winScroll
		else if (document.body)
			document.body.scrollTop = winScroll;

	} else if (txtarea.selectionStart || txtarea.selectionStart == '0') { // Mozilla

		//save textarea scroll position
		var textScroll = txtarea.scrollTop;
		//get current selection
		txtarea.focus();
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		selText = txtarea.value.substring(startPos, endPos);
		//insert tags
		checkSelectedText();
		txtarea.value = txtarea.value.substring(0, startPos)
			+ tagOpen + selText + tagClose
			+ txtarea.value.substring(endPos, txtarea.value.length);
		//set new selection
		if (isSample) {
			txtarea.selectionStart = startPos + tagOpen.length;
			txtarea.selectionEnd = startPos + tagOpen.length + selText.length;
		} else {
			txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length;
			txtarea.selectionEnd = txtarea.selectionStart;
		}
		//restore textarea scroll position
		txtarea.scrollTop = textScroll;
	} 

	function checkSelectedText(){
		if (!selText) {
			selText = sampleText;
			isSample = true;
		} else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char
			selText = selText.substring(0, selText.length - 1);
			tagClose += ' '
		} 
	}

}
//מספר תוים שנותור + הגבלה
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // אם ארוך מדי - קצר אותו
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
//שליחת טופס
function submitform(myform)
{
    document.forms[myform].submit();
}

//גישה לכתובת באמצעות תפרטי נגלל
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
