
// GLOBALNO

var ERROR = new Object();
ERROR.IsError = false;
ERROR.Message = "";

var oWin = new Array();
function openWindowNew(winName,w,h,nameofwin,index){
   oWin[index] = window.open(winName, nameofwin, "bar=0,toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=0,width="+w+",height="+h);
}

function replace(string,text,by) {
      var stringLength = string.length
      var textLength = text.length;
      if ((stringLength == 0) || (textLength == 0)) return string;

      var i = string.indexOf(text);
      if ((!i) && (text != string.substring(0,textLength))) return string;
      if (i == -1) return string;

      var newstr = string.substring(0,i) + by;

      if ( (i+textLength) < stringLength)
        newstr += replace(string.substring(i+textLength,stringLength),text,by);
      return newstr;
    }

function doReplace(fldName){
  var s = document.getElementById(fldName).value;
  var t = document.getElementById('WBF_' + fldName);


  s = replace(s,'&','&#38;');
  s = replace(s,'"','&#148;'); // "  &#148;
  s = replace(s,'<','&#60;');
  s = replace(s,'>','&#62;');
  s = replace(s,'%','&#37;');
  s = replace(s,"'",'&#146;');
  t.value=s;
  }

function showPostPreview(){

  var html = new String('');
  var openerDoc = window.opener.document;
  var cont = document.getElementById('cnt');

  if(openerDoc.getElementById('PostSadrzaj') && (openerDoc.getElementById('PostSadrzaj') != null))
    {
       html += replace(openerDoc.getElementById('PostSadrzaj').value,'\n','<br>');
    }

  if(openerDoc.getElementById('Citat') && (openerDoc.getElementById('Citat') != null) && (openerDoc.getElementById('Citat').value != '')){
       html += '<br><br><div style=\'margin-left:5px; padding:3px; border-left:1px solid #555555;\' class=\'txtDefault\'><b>Citat:</b><br><font color=#CC0000>';
       html += replace(openerDoc.getElementById('Citat').value,'\n','<br>');
       html += '</font></div>';
    }

  cnt.innerHTML = html;
 }

function showThemePreview(){

// treba napraviti i za novu temu
//alert("Tema!!!");


  var html = new String('');
  var openerDoc = window.opener.document;
  var cont = document.getElementById('cnt');

  if(openerDoc.getElementById('TemaSadrzaj') && (openerDoc.getElementById('TemaSadrzaj') != null))
    {
//       html += '<b>Preview:</b> <br>';
       txt = openerDoc.getElementById('TemaNaslov').value;
       txt = replace(txt,'<','&#60;');
       txt = replace(txt,'>','&#62;');
       html += '<b>' + txt + '</b><br><br>';

       txt = openerDoc.getElementById('TemaSadrzaj').value;
       txt = replace(txt,'<','&#60;');
       txt = replace(txt,'>','&#62;');
       html += replace(txt,'\n','<br>');
    }

/*  if(openerDoc.getElementById('Citat') && (openerDoc.getElementById('Citat') != null) && (openerDoc.getElementById('Citat').value != '')){
       html += '<br><br><div style=\'margin-left:5px; padding:3px; border-left:1px solid #555555;\' class=\'txtDefault\'><b>Citat:</b><br>';
       html += replace(openerDoc.getElementById('Citat').value,'\n','<br>');
       html += '</div>';
    }

*/
  cnt.innerHTML = html;


 }


function showPreview(){
  if(window.opener.document.getElementById('PostSadrzaj')){
     showPostPreview();
    }else{
        showThemePreview();
      }
  }

function setPreview(){
   openWindowNew('preview.wbsp',650,500,'wPreviewPost',88);
  }

function doAppend(what, where){
  var fldWhat = document.getElementById(what);
  var fldWhere = document.getElementById(where);

  if(fldWhat.value.length>0){
    fldWhat.value = replace(fldWhat.value,'"','&#148;');
    fldWhere.value += '<br><br><div style=\'margin-left:5px; padding:3px; border-left:1px solid #555555;\' class=\'txtDefault\'><b>Citat:</b><br><font color=#CC0000>' + fldWhat.value + '</font></div>';
  }
 }


function doSubmit(frmName){
  if(ERROR.IsError == false){ document.getElementById(frmName).submit();}
  else{ alert(ERROR.Message); ERROR.IsError = false; ERROR.Message = "";}
  }


 function openWin(param){
   window.open(param, "Window", "top=0,left=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=350");
}



function WriteFlash(f_id, f_movie, f_width, f_height){
  html = '';
  html += '<object id="' + f_id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + f_width + '" height="' + f_height + '" align="middle">';
  html += '<param name="allowScriptAccess" value="sameDomain" />';
  html += '<param name="movie" value="' + f_movie + '" />';
  html += '<param name="quality" value="high" />';
  html += '<param name="wmode" value="transparent" />';
  html += '<param name="bgcolor" value="#000000" /><embed wmode="transparent" id="' + f_id + '" src="' + f_movie + '" quality="high" bgcolor="#ffffff" width="' + f_width + '" height="' + f_height + '" name="' + f_id + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
  html += '</object>';
  document.write(html);
  }

