﻿// Hayag Forum Edit http://www.hayag.com/forum
//window.onerror = handleErrors;
//function handleErrors()
//{
//   return true;
//}
var viewMode = 1;
function eButton(cmdButton, buttonval)
{
   if (buttonval == "over")
   {
      cmdButton.style.backgroundColor = "threedhighlight";
      cmdButton.style.borderColor = "threeddarkshadow threeddarkshadow threeddarkshadow threeddarkshadow";
   }
   else if (buttonval == "out")
   {
      cmdButton.style.backgroundColor = "threedface";
      cmdButton.style.borderColor = "threedface";
   }
   else if (buttonval == "down")
   {
      cmdButton.style.backgroundColor = "threedlightshadow";
      cmdButton.style.borderColor = "threedshadow threedshadow threedshadow threedshadow";
   }
   else if (buttonval == "up")
   {
      cmdButton.style.backgroundColor = "threedhighlight";
      cmdButton.style.borderColor = "threedshadow threedshadow threedshadow threedshadow";
      cmdButton = null;
   }
   else
   {
      return;
   }
}
function isEmpty(s) { return ((s == null) || (s.length == 0));	}

function insertPhoto(photo)
{
    document.getElementById('editbox').contentWindow.focus();
    document.getElementById('editbox').contentWindow.document.execCommand("InsertImage", false,photo);
}

function insertVideo(videoid, thumbsource)
{
    document.getElementById('editbox').contentWindow.focus();
    createVideo(videoid,thumbsource);
}
function createVideo(videoid)
{
    //var NewVideo =  "<img name=\"hayagvideo\" id=\"" + videoid + "\" width=\"320\" height=\"304\" src=\"" + thumbsource + "\">";
    var NewVideo = "<object width=\"424\" height=\"265\" type=\"application/x-silverlight-2\" style=\"background-color: #000000\" >";
    NewVideo += "<param name=\"source\" value=\"http://www.hayag.com/hp/hp.xap\"/><param name=\"onerror\" value=\"onSilverlightError\" />";
    NewVideo += "<param name=\"background\" value=\"#000000\" /><param name=\"minRuntimeVersion\" value=\"2.0.31005.0\" /><param name=\"autoUpgrade\" value=\"true\" /><param name=\"enablehtmlaccess\" value=\"true\" /><param name=\"windowless\" value=\"true\" />";
    NewVideo += "<param name=\"InitParams\" value=\"w="+ videoid + "\" /><a href=\"http://go.microsoft.com/fwlink/?LinkID=124807\" style=\"text-decoration: none;\">";
    NewVideo += "<img src=\"http://go.microsoft.com/fwlink/?LinkId=108181\" alt=\"Get Microsoft Silverlight\" style=\"border-style: none\"/></a></object>";
    if(document.getElementById('editbox').contentWindow.document.selection){
        document.getElementById('editbox').contentWindow.focus();
        document.getElementById('editbox').contentWindow.document.selection.createRange().pasteHTML(NewVideo);
    }
    else if (document.getElementById('editbox').contentWindow.getSelection) { 
        document.getElementById('editbox').contentWindow.focus();
        document.getElementById('editbox').contentWindow.document.execCommand('insertHTML',false,NewVideo); 
        
    }
}

function MaxEdit()
{
     var viewportwidth;
     var viewportheight;
     var editboxsize;
     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
     if (typeof window.innerWidth != 'undefined'){
          viewportwidth = window.innerWidth;
          viewportheight = window.innerHeight;
     }
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
     else if (typeof document.documentElement != 'undefined'
         && typeof document.documentElement.clientWidth !=
         'undefined' && document.documentElement.clientWidth != 0){
           viewportwidth = document.documentElement.clientWidth;
           viewportheight = document.documentElement.clientHeight;
     }
     // older versions of IE
     else{
           viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
           viewportheight = document.getElementsByTagName('body')[0].clientHeight;
     }
    // 110px is the total size of toolbars
    editboxsize = viewportheight - 130;
    
    if(editboxsize<50) editboxsize = 50;
    
    if(document.getElementById('divNewThr').style.position == 'fixed') {
        document.getElementById('divNewThr').style.position = 'static';
        document.getElementById('divNewThr').style.height = '270px';
        document.getElementById('editbox').style.height = '140px';
    }
    else {
        document.getElementById('divNewThr').style.position = 'fixed';
        document.getElementById('divNewThr').style.height = '100%';
        document.getElementById('divNewThr').style.top = '0px';
        document.getElementById('divNewThr').style.left = '0px';
        document.getElementById('editbox').style.height = editboxsize + 'px';
        document.getElementById('divNewThr').style.zIndex = 9990;
    }
}

function tableDialog()
{
    document.getElementById('tblDialog').style.display='block';
}
function tableInsert(){
   if (isNaN(document.getElementById('formNumRows').value))
   {
      alert ('The rows field can only contain numbers'); return;
   }
   else if (isNaN(document.getElementById('formNumCols').value))
   {
      alert ('The colums field can only contain numbers'); return;
   }
   createTable();
}
function createTable()
{
   var rtNumRows =document.getElementById('formNumRows').value;
   var rtNumCols = document.getElementById('formNumCols').value;
   var rtTblAlign = document.getElementById('formTblAlign').value;
   var rtTblWidth = document.getElementById('formTblWidth').value;
   
   if (rtNumRows == "" || rtNumRows == "0")
   {
      rtNumRows = "1";
   }
   if (rtNumCols == "" || rtNumCols == "0")
   {
      rtNumCols = "1";
   }
   var rttrnum=1
   var rttdnum=1
   var rtNewTable = "<table border='1' style='border-collapse: collapse;' align='" + rtTblAlign + "' cellpadding='0' cellspacing='0' width='" + rtTblWidth + "'>"
   while (rttrnum <= rtNumRows)
   {
      rttrnum=rttrnum+1
      rtNewTable = rtNewTable + "<tr>"
      while (rttdnum <= rtNumCols)
      {
         rtNewTable = rtNewTable + "<td>&nbsp;</td>"
         rttdnum=rttdnum+1
      }
      rttdnum=1
      rtNewTable = rtNewTable + "</tr>"
   }
   rtNewTable = rtNewTable + "</table>"
   //alert(rtNewTable);
   if(document.getElementById('editbox').contentWindow.document.selection){
        document.getElementById('editbox').contentWindow.focus();
        document.getElementById('editbox').contentWindow.document.selection.createRange().pasteHTML(rtNewTable);
   }
   else if (document.getElementById('editbox').contentWindow.getSelection) { 
        document.getElementById('editbox').contentWindow.focus();
        document.getElementById('editbox').contentWindow.document.execCommand('insertHTML',false,rtNewTable); 
        
   }
   document.getElementById('tblDialog').style.display='none';
}

function fColorSelect(fColor)
{
    if (fColor != null){
        document.getElementById('editbox').contentWindow.focus();
        document.getElementById('editbox').contentWindow.document.execCommand("ForeColor", false, fColor);
        document.getElementById('divfColors').style.display='none';
    }
}
function bColorSelect(bColor)
{ 
    if (bColor != null){
        document.getElementById('editbox').contentWindow.focus();
        document.getElementById('editbox').contentWindow.document.execCommand("BackColor", false, bColor);
        document.getElementById('divbColors').style.display='none';
    }
}

function foreColor()
{
   document.getElementById('divfColors').style.display='block';
}
function backColor()
{
   document.getElementById('divbColors').style.display='block';
}
function eStat(status)
{
   //----- Updates Status Bar With Information -----
   var editStat = document.getElementById("editorStatus");
   editStat.innerHTML = status;
}
function modeSelect()
{
      iText = document.getElementById('editbox').contentWindow.document.body.innerText; document.getElementById('editbox').contentWindow.document.body.innerHTML = iText;
      linkCtrl.style.display = 'inline'; lineCtrl.style.display = 'inline';
      tableCtrl.style.display = 'inline'; hr1Ctrl.style.display = 'inline';
      orderedCtrl.style.display = 'inline'; unorderedCtrl.style.display = 'inline';
      hr2Ctrl.style.display = 'inline'; strikeCtrl.style.display = 'inline';
      subCtrl.style.display = 'inline'; superCtrl.style.display = 'inline';
      hr3Ctrl.style.display = 'inline'; forecolorCtrl.style.display = 'inline';
      backcolorCtrl.style.display = 'inline'; hr4Ctrl.style.display = 'inline';
      indentCtrl.style.display = 'inline'; outdentCtrl.style.display = 'inline';
      hr5Ctrl.style.display = 'inline'; toolBar1.style.display = 'inline'; newCtrl.style.display = 'inline';
      document.getElementById('editbox').contentWindow.focus();  viewMode = 1;
}
