// JavaScript Document
//
// format date as dd-mmm-yy
// example: 12-Jan-99
//
function date_ddmmmyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();

  // handle different year values 
  // returned by IE and NS in 
  // the year 2000.
  if(y >= 2000)
  {
    y -= 2000;
  }
  if(y >= 100)
  {
    y -= 100;
  }

  // could use splitString() here 
  // but the following method is 
  // more compatible
  var mmm = 
    ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
    ( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
    ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
    (10==m)?'Oct':(11==m)?'Nov':'Dec';

  return "" +
    (d<10?"0"+d:d) + "-" +
    mmm + "-" +
    (y<10?"0"+y:y);
}


//
// get last modified date of the 
// current document.
//
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }

  return s;
}

function expand(s)
{
  var td = s;
  var d = td.getElementsByTagName("div").item(0);

  td.className = "menuHover";
  d.className = "menuHover";
}

function collapse(s)
{
  var td = s;
  var d = td.getElementsByTagName("div").item(0);

  td.className = "menuNormal";
  d.className = "menuNormal";
}

function toggle(name) {
	var x = document.getElementById(name);
	if(x.style.display=='none') {
		x.style.display='block';
	} else {
		x.style.display='none';
	}
}

function archivePage() {
 var myForm = document.createElement("form");
  myForm.method="post" ;
  myForm.action = "/ADMIN/archive.php" ;
  
    var myInput = document.createElement("input") ;
	myInput.setAttribute("type","hidden");
    myInput.setAttribute("name", "body") ;
    myInput.setAttribute("value", document.getElementById("bodyCell").innerHTML);
    myForm.appendChild(myInput) ;
  
  document.body.appendChild(myForm) ;
  myForm.submit() ;

}


function addLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
  } else { 
    window.onload = function() { 
      if (oldonload) { 
        oldonload(); 
      } 
      func(); 
    } 
  } 
}
//addLoadEvent(roundCorners);

function loadComments(article, collapse) {
	var dv = document.getElementById('comments_'+article);
	if(dv.style.display == 'none') {
		dv.style.display = 'block';
	} else {
		if(collapse) {
			dv.style.display = 'none';
		}
	}		
	
	if(dv.style.display != 'none') {
		new Ajax.Request('/db/loadComments.php?id='+article, 
		{method:'get',
		  onSuccess: function(transport) {
			var response = transport.responseText;
			dv.innerHTML = response;
		  },
		  onFailure: function(){;}
		});
		
		var dv2 = document.getElementById('ccnt_'+article);
		new Ajax.Request('/db/loadComments.php?ccnt='+article, 
		{method:'get',
		  onSuccess: function(transport) {
			var response = transport.responseText || "Could not load count";
			dv2.innerHTML = response;
		  },
		  onFailure: function(){;}
		});
	}		
	
	
}
function myCustomSetupContent() {
    tinyMCE.getInstanceById('body').getWin().document.body.style.backgroundColor='#ffffff';
    tinyMCE.getInstanceById('body').getWin().document.body.style.backgroundImage='';
}
function showForm() {
	document.getElementById("addNewForm").style.display = 'block';
	myCustomSetupContent();
}
function hideForm() {
	document.getElementById("addNewForm").style.display = 'none';
}

