//---------- [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="lib/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="#" onclick="window.print();">Print this page</a>&nbsp;|&nbsp;<a href="#" onclick="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'");
	}
}


//-------------------------------------------------------------------------
// Image Mouseover code
//-------------------------------------------------------------------------
// validate version of browser
var valid_browser;
valid_browser = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3.0) || (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4.0);

var image_array;
image_array = new Array();

function roll_image(image_object, src_mouseover_image, src_normal_image, status) {

    this.image_object = image_object;
    this.src_mouseover_image = src_mouseover_image;
    this.src_normal_image = src_normal_image;
    this.status = status;
}

// this will pre-load the image for the mouse over
function load_image(object_name, image_name, src_mouseover_image, status) {

    // don't worry if not a valid browser
    if (valid_browser) {

        // pump into array
        image_array[object_name] = new roll_image(document.images[image_name], src_mouseover_image, document.images[image_name].src, status);

        // pre-load image
        image_array[object_name].image_object_over = new Image();
        image_array[object_name].image_object_over.src = src_mouseover_image;

        // pre-load normal for IE
        image_array[object_name].image_object_normal = new Image();
        image_array[object_name].image_object_normal.src = document.images[image_name].src;
    }

    return true;
}

// this is for mouse over
function roll_over(object_name) {

    if (valid_browser) {

        // swap the image
        image_array[object_name].image_object.src = image_array[object_name].src_mouseover_image;

        // and set the status
        if (image_array[object_name].status != null && image_array[object_name].status != '' && image_array[object_name].status != 'undefined') {
            window.status = image_array[object_name].status;
        }
    }

    return true;
}

// this is for mouse out
function roll_out(image_name) {

    if (valid_browser) {

        // swap the image back
        image_array[image_name].image_object.src = image_array[image_name].src_normal_image;

        // and blank out the status
        window.status = '';
    }

    return true;
}






//-------------------------------------------------------------------------
// 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




//-------------------------------------------------------------------------
// Date Widget Code
//-------------------------------------------------------------------------

// build the date widget
var month_array = [
                    { name:'January', days:31 },
                    { name:'February', days:28 },
                    { name:'March', days:31 },
                    { name:'April', days:30 },
                    { name:'May', days:31 },
                    { name:'June', days:30 },
                    { name:'July', days:31 },
                    { name:'August', days:31 },
                    { name:'September', days:30 },
                    { name:'October', days:31 },
                    { name:'November', days:30 },
                    { name:'December', days:31 }
                  ];
					  
function setLeapYear(year) {

    var isLeapYear = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);

    month_array[1].days = (isLeapYear) ? 29 : 28;

    return isLeapYear;
}

// display function for the date
function date_widget(day_field, month_field, year_field, hour_field, minute_field, hidden_field, default_date, style) {
	
	// for reference
    if (default_date == null)
        default_date = new Date();

    var output;

    setLeapYear(default_date.getFullYear());

    // do days of the month
    output = '<select class="' + style +'" name="' + day_field + '" onChange="return doDateChange(this.form.elements[\'' + day_field + '\'], this.form.elements[\'' + month_field + '\'], this.form.elements[\'' + year_field + '\'], this.form.elements[\'' + hour_field + '\'], this.form.elements[\'' + minute_field + '\'], this.form.elements[\'' + hidden_field + '\']);">';
    for (var day = 1 ; day <= month_array[default_date.getMonth()].days ; day++) {
        output += '<option value="' + day + '"' + (day == default_date.getDate() ? ' selected>' : '>') + day + '</option>';
    }
    output += '</select>';

    // do months
    output += '<select class="' + style +'" name="' + month_field + '" onChange="return doDateChange(this.form.elements[\'' + day_field + '\'], this.form.elements[\'' + month_field + '\'], this.form.elements[\'' + year_field + '\'], this.form.elements[\'' + hour_field + '\'], this.form.elements[\'' + minute_field + '\'], this.form.elements[\'' + hidden_field + '\']);">';
    for (var month = 0 ; month < month_array.length ; month++) {
        output += '<option value="' + (month + 1) + '"' + (month == default_date.getMonth() ? ' selected>' : '>') + month_array[month].name + '</option>';
    }
    output += '</select>';

    // and year, just do from a minimum of this year, or default year
    var today = new Date();
    var start_date = today.getFullYear();
    if (default_date.getFullYear() < start_date) {
        start_date = default_date.getFullYear();
    }

    output += '<select class="' + style +'" name="' + year_field + '" onChange="return doDateChange(this.form.elements[\'' + day_field + '\'], this.form.elements[\'' + month_field + '\'], this.form.elements[\'' + year_field + '\'], this.form.elements[\'' + hour_field + '\'], this.form.elements[\'' + minute_field + '\'], this.form.elements[\'' + hidden_field + '\']);">';
    for (var year = start_date ; year >= today.getFullYear() - 50 ; year--) {
        output += '<option value="' + year + '"' + (year == default_date.getFullYear() ? ' selected>' : '>') + year + '</option>';
    }
    output += '</select>';

	/*
	// Do the hours bit first.
    output += '&nbsp;&nbsp;<select class="' + style +'" name="' + hour_field + '" onChange="return doDateChange(this.form.elements[\'' + day_field + '\'], this.form.elements[\'' + month_field + '\'], this.form.elements[\'' + year_field + '\'], this.form.elements[\'' + hour_field + '\'], this.form.elements[\'' + minute_field + '\'], this.form.elements[\'' + hidden_field + '\']);">';
    for (var hour = 0 ; hour < 24 ; hour++) {
        output += '<option value="' + (hour < 10 ? "0" : "") + hour + '"' + (hour == default_date.getHours() ? " SELECTED" : "") + '>' + (hour < 10 ? "0" : "") + hour + '</option>';
    }
    output += '</select>';

    // The divider (should probably be more locale specific)
    output += ":";

    // And then the minutes
	
    output += '<select class="' + style +'" name="' + minute_field + '" onChange="return doDateChange(this.form.elements[\'' + day_field + '\'], this.form.elements[\'' + month_field + '\'], this.form.elements[\'' + year_field + '\'], this.form.elements[\'' + hour_field + '\'], this.form.elements[\'' + minute_field + '\'], this.form.elements[\'' + hidden_field + '\']);">';
    for (var minute = 0 ; minute < 60 ; minute++) {
        output += '<option value="' + (minute < 10 ? "0" : "") + minute + '"' + (minute == default_date.getMinutes() ? " SELECTED" : "") + '>' + (minute < 10 ? "0" : "") + minute + '</option>';
    }
    output += '</select>';
    */
    // This can be changed to a text field to check the value of the
    output += '<input type="hidden" name="' + hidden_field + '" value="' +  default_date.getFullYear() + '-' + (default_date.getMonth() + 1) + '-' + default_date.getDate() + '">';// + (default_date.getHours() < 10 ? "0" : "") + default_date.getHours() + ':' + (default_date.getMinutes() < 10 ? "0" : "") + default_date.getMinutes() + '">';

    document.write(output);

    return true;
}

// event functions
function doDateChange(day_field, month_field, year_field, hour_field, minute_field, hidden_field) {

    // first set the leap year
    var year = year_field.options[year_field.selectedIndex].value,
        month = month_field.options[month_field.selectedIndex].value - 1,
        day = day_field.options[day_field.selectedIndex].value;
		hour = "";//hour_field.options[hour_field.selectedIndex].value;
		minute = "";//minute_field.options[minute_field.selectedIndex].value;
		
    // set the month_array up
    setLeapYear(year);

    // and then reset the days field
    day_field.options.length = month_array[month].days;

    // reset the day value if no longer valid
    if (day > month_array[month].days)
        day = month_array[month].days;

    for (var index = 0 ; index < month_array[month].days ; index++) {

        // options goes from 0 to day-1
        day_field.options[index].text = day_field.options[index].value = index + 1;

        // and set the default
        if (index + 1 == day)
            day_field.options[index].selected = true;
    }

    // update the hidden field with the combined data from the drop-down select lists.
    hidden_field.value = year + '-' + (month + 1) + '-' + day;// + " " + hour + ":" + minute;


    return true;
}



