

function fncDisplay(verif){
if(verif==true){
	var ct=document.all("t_response").value;

		for(i=0;i<ct;i++)
			
			{
						
			 uneligne=document.all("a").insertRow();

			 cell=uneligne.insertCell();
			 //cell.name="td"+i;
			 j=i+1;
			 cell.innerHTML="<b>خيار "+j+"</b><input name='tdchoix"+i +"' type='text' />";

			}
 }
 else{
 l=document.all("a").rows.length;
 for(i=0;i<l;i++)
   document.all("a").deleteRow();
 }
}




function fncvalidedit(tag,vbform) {
  tag = tag.toUpperCase();
  tag1= "[" + tag + "]";
  tag2= "[/" + tag + "]";

  var oSelText = Editor_getSelText(vbform);
  if (oSelText.parentElement().name=="message")
    if (oSelText.text == "")
      alert("لم تختر أي نص للتحرير");
    else
      oSelText.text =tag1 + oSelText.text + tag2;
}

function fncvalidIcon(tag,vbform) {
 if (navigator.appName=="Netscape"){
	  fncReplaceIcon(tag,vbform.message);
  }
  else{
  var oSelText = Editor_getSelText(vbform);
  var oParentNode =oSelText.parentElement();
   if (oParentNode.name=="message")
      oSelText.text = oSelText.text + tag;
  }
}

 function fncReplaceIcon(tag,textfield){
	 textfield.focus();
	var startPos = textfield.selectionStart;
	var endPos = textfield.selectionEnd;
	strSelection = textfield.value.substring(startPos, endPos)
	strSelection = tag;
	textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);

 }

 function fncReplaceHelp(tag1,tag2,textfield){
 	 textfield.focus();
	var startPos = textfield.selectionStart;
	var endPos = textfield.selectionEnd;
	strSelection = textfield.value.substring(startPos, endPos)
	strSelection = tag1 + strSelection + tag2;
	textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);

 }

function fncvalidHelp(tag,vbform) {
  tag = tag.toUpperCase();
  tag1= "[" + tag + "]";
  tag2= "[/" + tag + "]";
  if (navigator.appName=="Netscape"){
	  fncReplaceHelp(tag1,tag2,vbform.message);
  }
  else{
  var oSelText = Editor_getSelText(vbform);
  if (oSelText.parentElement().name=="message")
    if (oSelText.text == "")
       document.input.message.value += " "+tag1 +  tag2;
    else
      oSelText.text =tag1 + oSelText.text + tag2;
  }
}

function fncvalidURL(tag,vbform) {
   var l_objWindow = self;
   l_arrDialogReturnValue = window.showModalDialog("templates/url.html",l_objWindow,"dialogHeight:220px;dialogWidth:650px;resizable:no;help:no;status:no");
   if(l_arrDialogReturnValue==null)  true;
   else{
   var tag1 = "URL=" + l_arrDialogReturnValue[0] + "";
   var tag2 = "URL"; 
   if(l_arrDialogReturnValue[1] != null && l_arrDialogReturnValue[1]!="")
       Editor_addVB(tag1,tag2,vbform,l_arrDialogReturnValue[1]); 
   else
       Editor_addVB(tag1,tag2,vbform); 
   }

}



function Editor_addVB(tag1,tag2,vbform,textToreplace) {
  tag1= "[" + tag1 + "]";
  tag2= "[/" + tag2 + "]";
    if (navigator.appName=="Netscape"){
		  fncReplaceHelp(tag1,tag2,vbform.message);
  }
  else{
  var oSelText = Editor_getSelText(vbform);
  if (oSelText.parentElement().name=="message"){
  if( textToreplace!= null && textToreplace!="")
                 oSelText.text = tag1 + textToreplace + tag2;
  else{
    if (oSelText.text == "")
      document.input.message.value += " "+tag1 +  tag2;
    else{
            oSelText.text = tag1 + oSelText.text + tag2;
    }
  }
  }
  }
}


function Editor_getSelText(vbform) {
    var oSelect,oSelectRange;
    vbform.message.focus();
    oSelect = document.selection;
    oSelectRange = oSelect.createRange();
    return oSelectRange;
}



function fncChooseAll(){
l_listCheck = document.all.tags("INPUT");

for(i=0;i<l_listCheck.length;i++){


   l_objCurrentItem = l_listCheck.item(i);
   if(l_objCurrentItem.type == "checkbox"){
     l_objCurrentItem.checked =true;
	 document.all('listThreads').value +=l_objCurrentItem.value + ',';
	 document.all('listThreadsmove').value +=l_objCurrentItem.value+',';
	 document.all('listThreadstop').value +=l_objCurrentItem.value + ',';

     }
  }
}


/****************************************************
/ List of functions
/***************************************************
function fncFlashIn(theObj,theContent)
function fncFlashOut(theObj,theContent)
function fncGetRealPos(l_objInputField, l_strWhichOffset)
function fncShowDetails(l_strControlId,l_intTop,l_intLeft)
function fncStopTimer() {
function fncHideItem() {

/****************************************************/


var g_intDelay = 750; // Delay to hide in milliseconds.
var sDisplayTimer = null, g_objLastItem;
var dateField;
var focusDay = 0;
var g_strCurrentDate = "";



// fncFlashIn(): when the mouse cursor is entering the object theObj, change its
// style based on its content (only if it is an existing day and not the currently
// selected one)
function fncFlashIn(theObj,theContent)
{
if ((theObj.className != 'stlSelectedCal') && (theContent.innerText != ' '))
{
theObj.className='stlBrowsedInCal';
theContent.className='stlBrowsedInCal';
}
}

// fncFlashOut(): same as fncFlashIn() but called when the cursor is leaving theObj
function fncFlashOut(theObj,theContent)
{
if ((theObj.className != 'stlSelectedCal') && (theContent.innerText != ' '))
{
theObj.className='stlNotSelectedCal';
theContent.className='stlNotSelectedCal';
}
}

// fncGetRealPos(): function used by the calendar tooltip to determine the
// current position of the calendar.
function fncGetRealPos(l_objInputField, l_strWhichOffset)
{
var l_intPos = 0;
while (l_objInputField!=null)
{
l_intPos += l_objInputField["offset" + l_strWhichOffset];
l_objInputField = l_objInputField.offsetParent;
}
return l_intPos;
}

// fncShowDetails(): function used to display the calendar
function fncShowDetails(l_strControlId,l_intTop,l_intLeft,l_strFormatDate)
{

var l_objInputControl = event.srcElement;

fncStopTimer();
if (document.all)
{
l_objDestControl = document.all[l_strControlId];
}
else{
l_objDestControl = eval(l_strControlId);
}
if ((g_objLastItem!=null) && (g_objLastItem!=l_objDestControl))
fncHideItem();
if (l_objDestControl)
{
 if (l_intLeft)
  l_objDestControl.style.pixelLeft = l_intLeft;
 else
  l_objDestControl.style.pixelLeft = fncGetRealPos(l_objInputControl,"Left") + l_objInputControl.offsetWidth -300;

if (l_intTop)
l_objDestControl.style.pixelTop = l_intTop;
else
l_objDestControl.style.pixelTop = fncGetRealPos(l_objInputControl,"Top")+25;
l_objDestControl.style.display = "block"
}

g_objLastItem = l_objDestControl;

}

// fncStopTimer(): function called when the cursor enters the calendar area, which
// means that it won't be hidden after the g_intDelay milli-seconds defined above.
function fncStopTimer() {
clearTimeout(sDisplayTimer)
}

// fncStartTimer(): function to start a new timer when the mouse cursor leaves the
// calendar object area. When the delay is reached, the calendar will be hidden
// thanks to the fncHideItem() function.
function fncStartTimer(el) {
if (!el.contains(event.toElement)) {
fncStopTimer()
sDisplayTimer = setTimeout("fncHideItem()",g_intDelay)
}
}

// fncHideItem(): calendar related function to hide the object
function fncHideItem()
{
if (g_objLastItem)
{
g_objLastItem.style.display="none"
}
}


// fncDisplayCalendar(): main function to produce the display of the
// tooltip calendar given the selected day, month and year.
function fncDisplayCalendar(l_intDay, l_intMonth, l_intYear)
{
var l_intDay = parseInt(l_intDay,10);
var l_intMonth = parseInt(l_intMonth,10);
var l_intYear = parseInt(l_intYear,10);
var i = 0;
var l_dteNow = new Date();

if (l_intDay == 0)
var l_intNowDay = l_dteNow.getDate();
else
var l_intNowDay = l_intDay;

var l_intDays = fncGetDaysInMonth( l_intMonth + 1, l_intYear);
var l_dteFirstOfMonth = new Date (l_intYear, l_intMonth, 1);
var l_intStartingPos = l_dteFirstOfMonth.getDay();
var l_intStartingCol = eval(colSpanTags.length - 42);
l_intDays += l_intStartingPos;

// MAKE BEGINNING NON-DATE BUTTONS BLANK
for (var i = l_intStartingCol; i < (l_intStartingCol+l_intStartingPos); i++)
{
colSpanTags[i].innerHTML = "&nbsp;";
colSpanTags[i].className = "stlNotSelectedCal";
colSpanTags[i].parentElement.className = "stlNotSelectedCal";
}

// SET VALUES FOR DAYS OF THE MONTH
for (i = (l_intStartingCol+l_intStartingPos); i < (l_intStartingCol+l_intDays); i++)
{
colSpanTags[i].innerText = i-l_intStartingPos-l_intStartingCol+1;
colSpanTags[i].className = "stlNotSelectedCal";
colSpanTags[i].parentElement.className = "stlNotSelectedCal";
}

// MAKE REMAINING NON-DATE BUTTONS BLANK
for (i=(l_intStartingCol+l_intDays); i < colSpanTags.length; i++)
{
colSpanTags[i].innerHTML = "&nbsp;";
colSpanTags[i].className = "stlNotSelectedCal";
colSpanTags[i].parentElement.className = "stlNotSelectedCal";
}

// GIVE FOCUS TO CORRECT DAY
colSpanTags[l_intStartingCol+l_intDay+l_intStartingPos-1].className = "stlSelectedCal";
colSpanTags[l_intStartingCol+l_intDay+l_intStartingPos-1].parentElement.className = "stlSelectedCal";
}

// Calendar function to set the input field value associated
// with the tooltip with the date selected through the calendar interface.
function fncReturnDate(l_strInDay)
{
var l_intResultTest = parseInt(l_strInDay,10);
if (!isNaN(l_intResultTest))
{
g_objDate.Day = l_strInDay;
g_objDate.Month = (document.calControl.month.selectedIndex)+1;
g_objDate.Year = document.calControl.year.value;

dateField.value = fncBuildDate(top.COM_Banner.g_strGlobalDateFormat);
fncSetDate();

// Call the onblur event of the dateField to simulate the user input
dateField.focus();
dateField.hasChanged = true;
dateField.blur();
}
}



	// Display & remove the server time at the status bas
	function clock(gap)
	{
		cur_date = new Date();
		calc_date = cur_date;// new Date(cur_date - gap);
		calc_hours = calc_date.getHours();
		calc_minuts = calc_date.getMinutes();
		calc_seconds = calc_date.getSeconds();
		if (calc_hours < 10) calc_hours = "0" + calc_hours;
		if (calc_minuts < 10) calc_minuts = "0" + calc_minuts;
		if (calc_seconds < 10) calc_seconds = "0" + calc_seconds;
		calc_time = calc_hours + ":" + calc_minuts + ":" + calc_seconds;
		window.status = "الساعة " + calc_time;

		clock_disp = setTimeout("clock('" + gap + "')", 1000);
	}

	function stop_clock()
	{
		clearTimeout(clock_disp);
		window.status = '';
	}


function Popup(url, window_name, window_width, window_height) 
{ settings= 
"toolbar=no,location=no,directories=no,"+ 
"status=no,menubar=no,scrollbars=yes,"+ 
"resizable=yes,width="+window_width+",height="+window_height; 

NewWindow=window.open(url,window_name,settings); }

function icon(theicon) { 
document.input.message.value += " "+theicon; 
document.input.message.focus(); 
} 


helpmode = false;
	normalmode = false;
	advmode = true;

function AddText(NewCode) {
	document.input.message.value+=NewCode;
	document.input.message.focus();
}


function chcolor(color) {
	
		AddTxt="[color="+color+"] [/color]";
		AddText(AddTxt);
	
}

function fncChgAction(LeForm,LeSelect)
{
 
 var ValList=LeSelect.value;
 if(ValList==""){
 LeForm.action="index.php?sid=" + sid.value;
  return;
  }
 var  sendAction=ValList.substring(0,1);
 if(sendAction=="g")
  {
    Ngid=ValList.substring(1,LeSelect.value.length);
    LeForm.action="index.php?gid=" + Ngid + "&sid=" + sid.value;
  }
  else
  {
    Ngid=ValList;
	LeForm.action="forumdisplay.php?fid=" + Ngid + "&sid=" + sid.value;
  }
}

function fncReplaceB(l_strVar){
 if(l_strVar.substring(0,1)!="<")
    return l_strVar;
 l_strTmp=l_strVar.substring(3,l_strVar.length-4);
 return l_strTmp;
}

function fncFormatTextarea(l_strInput, l_intMaxLines, l_intMaxCols, l_blnIsFreeText)
{
  var l_strResult = "";
  // We use the key word "hard" for the wrapping of textarea. In this case, when the word is too long, there is
  // an automatic "carriage return" but the last character of the sentence is a space. Therefore, to avoid a
  // concatenation of words, we have to add a carriage return instead of the space. The data below is used to
  // determine the position of the last space in the sentence.
  var l_intLastSpacePosition = -1;
  
  var l_intCountCol = 0;
  var l_intCountRow = 1; // we have 1 because we test > for the number of lines
  // Then remove any trailing carriage return line feed at then end of the text
  l_strInput = l_strInput.replace(/\r\n$/,"");
  for (k=0; k<l_strInput.length; k++)
  {
    l_chrOne = l_strInput.charAt(k);
    // If the character is a carriage return, we copy it and reset the line counter:
    if ((l_chrOne == "\r")
     || (l_chrOne == "\n"))
    {
      l_strResult += "\n";
      l_intCountCol = 0;
      l_intCountRow++;
      l_intLastSpacePosition = -1;
      // The current character will be followed by a linefeed
      // and hence we let the counter k jump by one when there is a carriage return
      if (l_chrOne == "\r")
      {
        k++;
      }
    }
    // If the counter is equal to the maximum number of characters per line, to avoid the problem of wrapping,
    // we insert a carriage return after the last space. If there is not a space, we just add a carriage return
    // before the character and reset the counter. 
    else if (l_intCountCol == l_intMaxCols)
    {
      if (l_intLastSpacePosition == -1)
      {
        l_strResult += "\n";
        l_intCountCol = 0;
      }
      else
      {
        l_strResult = l_strResult.slice(0,l_strResult.length-(k-l_intLastSpacePosition)+1) + "\n" +
                      l_strResult.slice(l_strResult.length-(k-l_intLastSpacePosition)+1);
        l_intCountCol = k-l_intLastSpacePosition;
        l_intLastSpacePosition = -1;
      }
      l_strResult += l_chrOne;
      l_intCountRow++;
    }
    // Otherwise we simply copy the character and increment the counter:
    else
    {
      l_strResult += l_chrOne;
      // we keep the last position of the space character for the problem of wrapping
      if (l_chrOne == " ")
      {
         l_intLastSpacePosition = k;
      }
      l_intCountCol++;
    }
  }
  // Remove the lines where only blank characters are found for swift textareas ONLY
  // (parameter 'l_blnIsFreeText' added by TA 02/10/2003)
  if (!l_blnIsFreeText)
    l_strInput = l_strInput.replace(/\n\s*\r\n/g,"\n");
  // Test if the size of the result string is exceeding the maximum (include
  // the eventual linefeed to determine the maximum)
  if ((l_strResult.length > ((l_intMaxLines * l_intMaxCols) + l_intCountRow))
   || (l_intCountRow > l_intMaxLines))
    return [false, "التوقيع طويل جداً \n  العدد الأقصى للسطور المسموح بها : "+ l_intMaxLines+ "\n العدد الأقصى للأعمدة المسموح بها : "+ l_intMaxCols ];
  else
    return [true, l_strResult];
}



function fncFormatTextareaforChamps(l_objInput, l_intMaxLines, l_intMaxCols, l_blnIsFreeText)
{
  var l_arrReturn = fncFormatTextarea(l_objInput.value, l_intMaxLines, l_intMaxCols);

  if (l_arrReturn[0])
  {
    l_objInput.value = l_arrReturn[1];
  }
  else
  {
    alert(l_arrReturn[1]);
    l_objInput.focus();
  }
}

function fncForLink(l_blnlink){
	if(l_blnlink==true){
		document.all("tr_forlink").style.display = "block";
		document.all("tr_message").style.display = "none";
	}
	else{
		document.all("tr_forlink").style.display = "none";
		document.all("tr_message").style.display = "block";
	}
}

function fnPrint(l_strSid){

var MyWindow=window.open('./print.php?thesid='+l_strSid,'PrintWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=450'); 
return false;
}

function fnSendto(l_strSid){

var MyWindow=window.open('./sendto.php?thesid='+l_strSid,'PrintWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=450'); 
return false;
}

function fnSave(l_strSid){

document.execCommand('SaveAs',null,l_strSid);
}


