//flash object activation:
// writeFlash( source, name/id, playerversion, bgcolor, width, height, wmode, style
function writeFlash(_source, _name, _playerversion, _bgcolor, _width, _height, _wmode, _style) {
	var theFlash = '';
	theFlash += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	theFlash += ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + _playerversion + ',0,0,0"';
	theFlash += ' width="' + _width + '" height="' + _height + '" id="' + _name + '" align="middle"';
	theFlash += ' style="' + _style + '">';
	theFlash += ' <param name="allowScriptAccess" value="sameDomain" />';
	theFlash += ' <param name="movie" value="' + _source + '" />';
	theFlash += ' <param name="wmode" value="' + _wmode + '">';
	theFlash += ' <param name="quality" value="high" />';
	theFlash += ' <param name="bgcolor" value="' + _bgcolor +'" />';
	theFlash += ' <embed src="' + _source + '" quality="high" bgcolor="' + _bgcolor + '" id="' + _name + '" name="' + _name + '" ';
	theFlash += ' wmode="' + _wmode + '" ';
	theFlash += ' width="' + _width + '" height="' + _height + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
	theFlash += ' swliveconnect="true" style="' + _style + '" />';
	theFlash += ' </object>';
	document.write(theFlash);	
}

//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
	    var extraHeight = 10; 
	    if (document.all) {
	    	extraheight = 10;
	    } else {
	    	extraHeight = 40 ; //IE needs less extra height
	    }
	    if (docHt) iframeEl.style.height = docHt + extraHeight + "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) || (pid==-10) ) {
		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 reloadCurDateTime() {
	setTimeout("writeCurDateTime()",1000);
}
function writeCurDateTime() {
	var Digital=new Date()
	var day = Digital.getDate();
	var month = (Digital.getMonth()+1);
	var year = Digital.getFullYear();
	var hours=Digital.getHours();
	var minutes=Digital.getMinutes();
	var seconds=Digital.getSeconds();

	if (month<=9){
		month="0"+month;
	}
	if (day<=9){
		day="0"+day;
	}
	if (minutes<=9) {
		minutes="0"+minutes;
	}
	if (seconds<=9) {
		seconds="0"+seconds;
	}
	document.getElementById('curdatetime').value=day+"-"+month+"-"+year+" "+hours+":"+minutes+":"+seconds+"";
	setTimeout("writeCurDateTime()",1000);
}

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();
}	
