//functions for the correct iframe height !!
function goSetHeight() {
  if (parent == window) return;
  // no way to obtain id of iframe object doc loaded into? no parentNode or parentElement or ...
  else parent.setIframeHeight('container');
}


function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  //var iframeWin = window.frames[iframeName];
  //more than 1 iframes?
  //for (var j=0; j<window.frames.length; j++) {
	//iframeWin = window.frames[j];
	  //var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	  var iframe_els = document.getElementsByName("container");
	  var iframeEl = '';
	  var iframeWin = '';
	  for (var i=0; i<iframe_els.length; i++) {
	  	 iframeEl = iframe_els[i];
	  	 iframeWin = window.frames[i];
	  if ( iframeEl && iframeWin ) {
	    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
	    var docHt = getDocHeight(iframeWin.document);
	    // need to add to height to be sure it will all show
	    if (docHt) iframeEl.style.height = docHt + 55 + "px";
	  }
	}
	//}
}

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;
    return false;
  }
  else return true;
}

function toggle(El) {
	if( document.getElementById ) {
		var ElStyle = document.getElementById(El).style;
		ElStyle.display=(ElStyle.display=='none') ? '' : 'none' ;
	}
}

/* function to disable fullwidth checkbox in advanced menu options when not a main menu type */
function checkParentMenuOptionsType() {
	var pid = document.getElementById('pid').value;
	if ((pid==0) || (pid==-1) ) {
		document.getElementById('fullwidth').disabled = false;
	} else {
		document.getElementById('fullwidth').disabled = true;
	}
}

function disableLinkToParentMenuEdit() {
	document.getElementById('linktoparentmenuedit').style.display = 'none';
}

// function to focus the author field of a form
function doFocus() {
	if (document.text) {
		if (document.all["author"]) {
			document.text.author.focus();
		}
	}
}


// function to open a text preview window
function preview() {
	//document.text.action='javascript:newWin("preview.php");';
	document.text.action='_preview.php';
	net = (document.layers && true);
	bWidth = (net) ? top.innerWidth:parseInt(top.document.body.clientWidth);
	bHeight = (net) ? top.innerHeight:parseInt(top.document.body.clientHeight);
	bLeft = (net) ? top.screenX:parseInt(top.screenLeft);
	bTop = (net) ? top.screenY:parseInt(top.screenTop);
	width = 800;
	height = 600;
	xLeft = bLeft + 30;
	xTop = bTop + 30;
	args = "width=" + width + ",height=" + height + ",screenX=" + xLeft + ",screenY=" + xTop + ",left=" + xLeft + ",top=" + xTop + ",scrollbars=yes,resizable=yes,menubar=no,locationbar=no,directories=no,status=no,toolbar=no";
	newwin = window.open("_preview.php",'preview',args);
	//wleft = (screen.width - 640) / 2;
	//wtop = (screen.height - 480)/2;
	//window.newwin.moveTo(wleft,wtop);
	window.newwin.focus();

	document.text.target='preview';
	document.text.submit();
}
//function for a regular submit target & action on the mng_text.php edit & add pagese
function regularSubmit() {
	document.text.action='?';
	document.text.target='_self';
	document.text.submit();
}

function showtime(){
    var time    = new Date()
    var day 	= fixtime(time.getDate());
    var month 	= fixtime(time.getMonth()+1);
    var year	= time.getFullYear();
    var hours   = fixtime(time.getHours());
    var minutes = fixtime(time.getMinutes());
    var seconds = fixtime(time.getSeconds());

	if (document.time) {
 	   document.time.timebox.value = day + " - " + month + " - " + year + "  "  +  "  " + hours + " : " + minutes + " : " + seconds;
	}
    if (document.time2) {
    	document.time2.timebox.value = hours + " : " + minutes + " : " + seconds;
    }
    timerID = setTimeout("showtime()",1000)
}

function fixtime(time) {
	if(time < 10) {
		time = "0" + time;
	}
	return time;
}

function newWin(page){
	args = "width=800,height=600,scrollbars=yes,resize=yes,menubar=no,locationbar=no,directories=no,status=no,toolbar=no";

	newwin = window.open(page,'popUp',args);
	wleft = (screen.width - 850) / 2;
	wtop = (screen.height - 850)/2;
	window.newwin.moveTo(wleft,wtop);
	window.newwin.focus();
}	