// JavaScript Document
/*
#####################################################################################
#####																			#####
#####	Webadmin JavaScript Module - forms.js									#####
#####																			#####
#####	Created on		= Tue, Sep 26, 2006 at 15:00 PM							#####
#####	Last Modified	= Mon, Oct 31, 2007 at 14:10 PM							#####
#####	Created by		= HANS (hans_agustinus@yahoo.com)						#####
#####																			#####
#####	Version			= 7.0													#####
#####	Copyright		= (c)2007												#####
#####																			#####
#####	This program is free software; you can redistribute it and/or modify	#####
#####	it under the terms of the GNU General Public License as published by	#####
#####	the Free Software Foundation; either version 2 of the License, or		#####
#####	(at your option) any later version.										#####
#####																			#####
#####	This program is distributed in the hope that it will be useful,			#####
#####	but WITHOUT ANY WARRANTY; without even the implied warranty of			#####
#####	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the			#####
#####	GNU General Public License for more details:							#####
#####																			#####
#####	http://www.gnu.org/copyleft/gpl.html									#####
#####																			#####
#####################################################################################
*/
var nbsp = 160;		// non-breaking space char
var node_text = 3;	// DOM text node-type
var emptyString = /^\s*$/ ;
var global_valfield;	// retain valfield for timer thread

if ( document.forms.length )
{
	if ( document.forms.length > 1 ) var fn = document.forms.length - 1;
	else var fn = 0;
	
	var frm = document.forms[fn];
	
	if( frm.cmd )
	{
		var cmd = frm.cmd;
	}
}

window.onload = function()
{
	if( loadmodule )
	{
		eval(loadmodule);
	}
	
	if( frm )
	{
		for (var i=0; i < frm.elements.length; i++)
		{
			var el = frm.elements[i];
			if ( (el.type == 'text') || (el.type == 'textarea') )
			{
				el.focus();
				break;
			}
		}
	}
	
}

/******************************
**
**	form submit functions
**
******************************/
function resetFormEdit()
{
    var frm = document.getElementById('frmEdit');
	frm.reset();
	return false;
}
	
function submitFormEdit()
{
    var frm = document.getElementById('frmEdit');
	var errs=0;
	var i=0;
	var vf;
	var __dom;
    var __elem;
	var __function;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
	
	if( tinyMCE )
	{
		tinyMCE.triggerSave();
	}
	
	frm.submit();
}

/*
**	form usability functions
*/
function cbox_select(cb)
{
	cbsel = frm.cbox_sel.value;
	
	stat = (cbsel == '1') ? false : true;
	
	for (i = 0 ; i < frm.elements.length; i++) {
		var el = frm.elements[i];
		
		if ( (el.type == 'checkbox') && (el.name == cb) )
		{
			el.checked = stat;
		}
	}
	
	if ( stat )	frm.cbox_sel.value = '1';
	else frm.cbox_sel.value = '0';
	
	return false;
}

function clearval()
{
	if (arguments.length)
	{
		for(i=0; i < arguments.length; i++)
		{
			var x = arguments[i];
			eval('el = frm.'+x);
			el.value = null;
		}
	}
	
	return false;
}

function clearval_v1(x)
{
	if( x != null )
	{
		eval('el = frm.'+x);
		el.value = null;
	}
	
	return false;
}

function whatkey(e)
{
	var unicode=e.keyCode? e.keyCode : e.charCode;
	
	if( unicode == '13' )
	{
		if( frm.submit_function ) frm.submit_function.value = "";
		get_filterdata();
		return true;
	}
	else
	{
		return false;	
	}
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '');
}


// --------------------------------------------
//                  setfocus
// Delayed focus setting to get around IE bug
// --------------------------------------------

function setFocusDelayed()
{
	global_valfield.focus();
}

function setfocus(valfield)
{
	// save valfield in global variable so value retained when routine exits
	global_valfield = valfield;
	setTimeout( 'setFocusDelayed()', 100 );
}

function post_remove()
{
	var chk = false;
	
	for (i = 0 ; i < frm.elements.length; i++) {
		var el = frm.elements[i];
		
		if ( (el.type == 'checkbox') && (el.name != 'toggle-all') && (el.checked) )
		{
			chk = true;
			break;
		}
	}
	
	if ( !chk )
	{
		alert("No record(s) has been selected!");
		return false;
	}
	else
	{
		var response = confirm('Are you sure you want to delete these data?');
		
		if( response ) {
			cmd.value = 'delete';
			
			frm.submit();
		}
		else
			return false;
	}
	
	return true;
}

function confirm_action(target, vs_dialog, vs_href) {
	if (confirm(vs_dialog)) {
		target.window.location.href = vs_href;
		return true;
	}
	return false;
}

function jumpURL(targ,selObj,restore){ //v3.0
	if( selObj.options[selObj.selectedIndex].value != '' ) {
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
		return true;
	}
	else return false;
}


