//---------- [one.ngn] Content Managent System --------------
//----------    created by zerophobic.com      --------------
//-----------------------------------------------------------
// MODULE	:	misc javascript
// FUNCTION	:	tools and snippets
// AUTHOR	:	brett stanley <brett@zerophobic.com>
// CREATED	:	01/10/2001
// MODIFIED	:	11/01/2002
//-----------------------------------------------------------
//-----------------------------------------------------------


// check the browser type
//-----------------------------------------------------------
var menuReadyState=false; 
var exclude=true; 
var agt=navigator.userAgent.toLowerCase();
var ie=false; 
var ie4=false; 
var ie5=false; 
var op5=false; 
var op7=false; 
var konqi=false;

if (typeof document.all!="undefined"&&(agt.indexOf('msie')!=-1)){
	ie=true; 
	ie4=true; 
	exclude=false;
	if (agt.indexOf('msie 4')==-1){
		ie5=true; 
		ie4=false;
	}
	if (agt.indexOf('opera')!=-1){
		ie=false; 
		ie4=false; 
		ie5=false; 
		op5=true;
	}
}
var ns6=false; 
var mz7=false;
if (typeof document.getElementById!="undefined"&&!ie){
	ns6=true; 
	exclude=false;
	if (agt.indexOf('netscape6')==-1){
		ns6=false; 
		mz7=true;
	}
	if (typeof window.opera!="undefined"){
		mz7=false; 
		op5=true;
		if((agt.indexOf("opera 7")!=-1)||(agt.indexOf("opera/7")!=-1)){
			op5=false;
			op7=true;
		}
	}else if (agt.indexOf('gecko')==-1){
		mz7=false; 
		exclude=true;
	}
}
if (agt.indexOf('opera 4')!=-1){
	op5=false; 
	mz7=false; 
	exclude=true;
}
var ns4=false;
if ((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)&&!ie&&!op5&&!ns6&&!mz7){
	ns4=true; 
	exclude=false;
}
if (agt.indexOf('webtv')!=-1){
	ie=false; 
	ie4=false; 
	exclude=true;
}
var win=false; 
var mac=false; 
var lin=false;
if (agt.indexOf('win')!=-1){
	win=true; 
	mac=false; 
	lin=false;
}else if (agt.indexOf('mac')!=-1){
	win=false; 
	mac=true;
	lin=false;
}else{
	win=false; 
	mac=false; 
	lin=true;
}
if (typeof navigator.vendor!="undefined"){
	if (navigator.vendor =="KDE"){
		ie=false;
		ie4=false;
		ie5=false;
		konqi = true;
		ns6=true;
		ns4 = false;
		exclude = false;
		var thisKDE=agt;
		var splitKDE=thisKDE.split("konqueror/");
		var aKDE=splitKDE[1].split("; ");
		var KDEn=parseFloat(aKDE[0]);
		var oldKde=false;
		if(KDEn<2.2){
			oldKde=true;
			exclude=true;
			ns6=false;
			konqi=false;
		}
	}
}
var op6=false;
if((agt.indexOf("opera 6")!=-1)||(agt.indexOf("opera/6")!=-1)){
	op6=true;
	op5=false;
}
var ie6=false;
if(ie5&&agt.indexOf("msie 6")!=-1){
	ie6=true;
}
var dcm,com;
if(ie6){
	dcm=document.compatMode;
	com=false;
	if(dcm!="BackCompat"){
		com=true;
	}
}
var ice=false;
if(typeof navigator.__ice_version!="undefined"){
	ice=true; 
	ie=false; 
	ie5=false; 
	ie4=true; 
	ns4=false;
}
var ns7=false;
if(agt.indexOf("netscape/7")!=-1){
	mz7=false; 
	ns6=true; 
	ns7=true;
}
if(agt.indexOf("opera/3")!=-1){
	ie4=false;
	ice=false;
	op5=false;
	exclude=true;
}
if(agt.indexOf("opera 4")!=-1){
	ns4=false;
	exclude=true;
}

exclude = false;

//window openers
//---------------------------------------------------------------
function openWindow(file){
	window.open(file, 'image', config='width=150, height=150');
}

// all your window popping needs
function winPop(file,name,width,height){
	win=window.open(file, name, "width="+width+", height="+height+",status=no,scrollbars=no,scrolling=no,toolbar=no,menubar=no,location=no,resizable=yes");
	win.resizeTo(width,height);
	win.moveTo((screen.availWidth/2)-(width/2),(screen.availHeight/2)-(height/2));
	win.focus();
	return(win);
}


// Article select scripts
//---------------------------------------------------------------
function open_select_window(ids,field){
	// opens the right window
	thisWin = winPop('dsp_article_select.php?field='+field+'&selected='+ids,'link',300,300);
}

function article_select(articles,field){
	// this displays the articles in the Select Box
	//alert(articles);
	var article_ids = new Array();
	var thisFieldList = eval("document.this_form."+field+"_list");
	var thisField = eval("document.this_form."+field);
	var n=0;
	if (articles != ""){
		for (i = 0; i < articles.length; i++){
			var article = new Option(articles[i][1],articles[i][0]);
			thisFieldList.options.length = n;
			thisFieldList.options[n] = article;
			article_ids[n] = articles[i][0]+";"+articles[i][1];
			n++;
	  	}
	}else{
		thisFieldList.options.length = 1;
		thisFieldList.options[0].text = "---------No Linked Articles---------";
	}
	thisField.value = article_ids;
	//alert(articles);
}


//Disable right click
//---------------------------------------------------------------
function right(e) {
  	var msg = "   [ONE.NGN]\n\nContent Management\n\n ©2002 Zerophobic";

	if (navigator.appName == 'Netscape' && e.which == 3) {
	 	alert(msg);
	 	return false;
	}
	
	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
		alert(msg);
	 	return false;
	}
  	else return true;
}

function trap() {
	// trap right click on the page
	if(document){ 
	  	document.onmousedown = right;
	   	document.onmouseup = right;
	}
	// trap right click on any images
	if(document.images){ 
	  	for(i=0;i<document.images.length;i++) {
	   		document.images[i].onmousedown = right;
	   		document.images[i].onmouseup = right;
	  	}
	}
}

//trap();


/* Printer Friendly version
********************************************************************************/
function ShowPrintPage() {
	if ((document.all)&&(window.parent.name != 'print')) {
		isIE = true;
	    var innerContent = document.all.content.innerHTML;
		objWindow = winPop('','print',650,600);
		objWindow.document.open();
		objWindow.document.write('<html>');
		objWindow.document.write('<head>');
		objWindow.document.write('<title>'+document.title+'</title>\n');
		objWindow.document.write('<link href="styles/style_print.css" rel="stylesheet" type="text/css">');
		objWindow.document.write('</head>');
		objWindow.document.write('<body bgcolor="#FFFFFF" text="#000000" leftmargin="5" topmargin="5" marginwidth="5" marginheight="5">');
		objWindow.document.write('<a href="javascript:window.print();">Print this page</a>&nbsp;|&nbsp;<a href="javascript:window.close();">Close this window</a><p>');
		objWindow.document.write(innerContent);
		objWindow.document.write('<p>Printed from <a href="'+document.location+'">'+document.location+'</a>');
		objWindow.document.write('</body>');
		objWindow.document.write('</html>');	
		objWindow.document.close();
	} else if(document.layers) {
		window.print();
	} else {
		window.print();
		window.close('print');
	}
}


//html editor
//---------------------------------------------------------------
function bold(field) 
{
var dark=prompt('Bold text','Text');
if (dark)
	{
		field.value+=('<b>'+dark+'</b>');
	}
}

function highlight(field) 
{
var dark=prompt('highlight text','Text');
if (dark)
	{
		field.value+=('<h>'+dark+'</h>');
	}
}

function hrrule(field)
{
field.value+=('<hr>')
}

function putemotion(field,emo)
{
	field.value+=(emo);
}

function quote(field) 
{
var quotet=prompt('Quote Text','Text');
if (quotet)
	{
		field.value+=('<blockquote>'+quotet+'</blockquote>');
	}
}

function italic(field) 
{
var ital=prompt('Italicized Text','Text');
if (ital)
	{
		field.value+=('<i>'+ital+'</i>');
	}
}

function underlined(field)
{
var underline=prompt('Underlined Text','Text');
if (underline)
	{
		field.value+=('<u>'+underline+'</u>');
	}
}

function link(field) 
{
var hyper=prompt('URL for the link','http://');
var hypertwo=prompt('Text for the link','Text');
var hyperthree=prompt('Window for the link (leave empty for current window)','_blank');
if (hyper) 
	{
		field.value+=('<a href=\"'+hyper+'\" target=\"'+hyperthree+'\">'+hypertwo+'</a>');	
	}
}

function ftplink(field) 
{
var hyper=prompt('URL for the link','ftp://');
var hypertwo=prompt('Text for the link','Text');
var hyperthree=prompt('Window for the link (leave empty for current window)','_blank');
if (hyper)
	{
		field.value+=('<a href=\"'+hyper+'\" target=\"'+hyperthree+'\">'+hypertwo+'</a>');
	}
}

function securelink(field) 
{
var hyper=prompt('URL for the link','https://');
var hypertwo=prompt('Text for the link','Text');
var hyperthree=prompt('Window for the link (leave empty for current window)','_blank');
if (hyper)
	{
		field.value+=('<a href=\"'+hyper+'\" target=\"'+hyperthree+'\">'+hypertwo+'</a>');
	}
}

function emaillink(field) 
{
var emailit=prompt('Your E-Mail Address','nobody@nowhere.com');
var emailittwo=prompt('Text for the link','Text');
if (emailit)
	{
		field.value+=('<a href=\"mailto:'+emailit+'\">'+emailittwo+'</a>');
	}
}

function image(field) 
{
var img=prompt('URL for the image','');
if (img)
	{
		field.value+=('<img src=\"'+img+'\">');
	}
}

function orderedl(field)
{
field.value+=('<ol></ol>')
}

function unorderedl(field)
{
field.value+=('<ul></ul>')
}

function newlistentry(field)
{
var newentry=prompt('Text for new entry','Text')
if (newentry)
	{
		field.value+=('<li>'+newentry+'\r\n')
	}
}



//---------------------------------------------------------------
//all the stuff for the resizer
//---------------------------------------------------------------
var d = document;
var isNav = false, isNS6 = false, isIE = false;

if(d.layers) {
	isNav = true;
	var range = "";
	var styleObj = "";
	} 
else if (d.all) {
	isIE = true;
	range = "all.";
	styleObj = ".style";
	} 
else if(d.getElementById) {
	isNS6 = true;
	var range = "getElementById('";
	var styleObj = "').style";
}

//do the resize	
function erection(iw,ih) {
	if(isIE) {
		var cx = parseInt(top.document.body.clientWidth);
		var cy = parseInt(top.document.body.clientHeight);
	}
	else {
		var cx = (window.innerWidth);
		var cy = (window.innerHeight);	
	}
	var speed = 2;
	
	//resize width
	if (cx < iw-10) {
		resizeBy(((iw-cx)/speed),0);
	}
	else if(cx > iw+10) {
		resizeBy(((iw-cx)/speed),0);
	}
	else {
		resizeBy(iw-cx,0);
	}
	
	//resize height
	if (cy < ih-10) {
		resizeBy(0,((ih-cy)/speed));
	}
	else if (cy > ih+10) {
		resizeBy(0,((ih-cy)/speed));
	}
	else {
		resizeBy(0,ih-cy);
	}
	
	if((cx != iw) || (cy != ih)) {
		setTimeout('erection('+iw+','+ih+')','20');
	}
	else {
		if(isIE) {
			if(document.all)for(var i in document.links)document.links[i].onfocus=document.links[i].blur;
			hide('loadinglayer');
		}
	}
}
		
function getObject(obj) {
	var theObj = eval("document." + range + obj + styleObj);
	return theObj;
}
		

function hide(layername) {
	if(isIE)
		eval("d.all['"+layername+"'].style.visibility = 'hidden'");
	else if(isNS6) {
		eval("d.getElementById('"+layername+"').style.visibility = 'hidden'");
		}
	else {
		eval("d."+layername+".visibility = 'hide'");
		}
}

function show(layername) {
	if(isIE)
		eval("d.all['"+layername+"'].style.visibility = 'visible'");
	else if(isNS6) {
		eval("d.getElementById('"+layername+"').style.visibility = 'visible'");
		}
	else {
		eval("d."+layername+".visibility = 'show'");
	}
}


// table Mouseover code
//---------------------------------------------------------------
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object   the table row
 * @param   string   the action calling this script (over, out or click)
 * @param   string   the default background color
 * @param   string   the color to use for mouseover
 * @param   string   the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function