// common funtions
///////////////////////////////////////////////////////////////////////////////
// date related
/*
*
*/
function todayClicked ()
{
var startdate = document.getElementById ('start_date');
var enddate = document.getElementById ('end_date');
var today = new Date ();
var year = today.getYear () + 1900;
var day = today.getDay ();
var month = today.getMonth ();
month = addZero (month, 2);
day = addZero (day, 2);
var today_str = month + '/' + day + '/' + year;
startdate.value = enddate.value = today_str;
}
/*
*
*/
function lastDaysClicked (days)
{
var startdate = document.getElementById ('start_date');
var enddate = document.getElementById ('end_date');
var today = new Date ();
var year = today.getYear () + 1900;
var day = today.getDay ();
var month = today.getMonth ();
var day2 = day - days;
var month2 = month;
var year2 = year;
if (day2 < 1)
{
month2 -= 1;
if (month2 < 1)
{
month2 = 12;
year2 -= 1;
}
day2 = getDaysInMonth (month2, year2);
}
month = addZero (month, 2);
day = addZero (day, 2);
month2 = addZero (month2, 2);
day2 = addZero (day2, 2);
var today_str = month + '/' + day + '/' + year;
var today_str2 = month2 + '/' + day2 + '/' + year2;
startdate.value = today_str2;
enddate.value = today_str;
}
/*
*
*/
function getDaysInMonth (month, year)
{
var days;
// Return 31 days
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
days = 31;
}
// Return 30 days
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
days = 30;
}
// Return 29 days
else if (month == 2)
{
if (isLeapYear (year))
{
days = 29;
}
// Return 28 days
else
{
days = 28;
}
}
return (days);
}
/*
*
*/
function isLeapYear (Year)
{
if (((Year % 4) === 0) && ((Year % 100) !== 0) || ((Year % 400) === 0))
return true;
else
return false;
}
/*
*
*/
function addZero (value, resultLength)
{
var countZero = resultLength - String (value).length;
var result = String (value);
for (var i = 0; i < countZero; i ++)
result = "0" + result;
return result;
}
// string class prototypes
var string = new String ();
/*
*
*/
String.prototype.ucfirst = function ()
{
var first = this.slice (0, 1);
first = first.strtoupper ();
var out = first + this.slice (1);
return out;
}
/*
*
*/
String.prototype.strtoupper = function ()
{
return this.toUpperCase ();
}
/*
*
*/
String.prototype.strtolower = function ()
{
return this.toLowerCase ();
}
// debug & info
var debugging_enabled = true;
/*
*
*/
function debug (msg)
{
if (debugging_enabled)
{
//alert ("DEBUG:" + msg);
}
}
/*
*
*/
function findElementById (id)
{
var obj = document.getElementById (id);
if (obj) return obj;
else debug (id + ' not found');
return false;
}
/*
*
*/
function setHtmlById (id, html)
{
var obj = findElementById (id);
if (obj)
{
obj.innerHTML = html;
}
}
/*
*
*/
function getHtmlById (id)
{
var obj = findElementById (id);
if (obj)
{
return obj.innerHTML;
}
return false;
}
/*
*
*/
function disableButton (id)
{
var obj = findElementById (id);
if (obj)
{
obj.disabled = true;
obj.style.color = "#666666";
}
else debug (id + ' not found');
}
/*
*
*/
function enableButton (id)
{
var obj = findElementById (id);
if (obj)
{
obj.style.color = "#000000";
obj.disabled = false;
obj.style.visibility = "visible";
}
}
/*
* visibility with cookies
*/
function initVisibilityById(id,def)
{
var cookie_name = 'vis-'+id;
var value = getCookie(cookie_name);
if(!value)
{
value=def;
setCookie(cookie_name,value);
}
(value==1) ? showElementById(id):hideElementById(id);
}
function showElementById (id)
{
var obj = findElementById (id);
if (obj)
{
if(obj.old_style_display)
obj.style.display = obj.old_style_display;
else
obj.style.display = "block";
if(obj.old_style_height)
obj.style.height = obj.old_style_height;
if(obj.old_style_visibility)
obj.style.visibility = obj.old_style_visibility;
else
obj.style.visibility = 'visible';
setCookie('vis-'+id,1);
}
}
/*
*
*/
function hideElementById (id)
{
var obj = findElementById (id);
if (obj)
{
obj.old_style_display = obj.style.display;
obj.old_style_height = obj.style.height;
obj.old_style_visibility = obj.style.visibility;
obj.style.display = "none";
obj.style.height = '0px';
obj.style.visibility = "hidden";
setCookie('vis-'+id,-1);
}
}
function toggleVisibilityById(id)
{
//alert('toggleVisibilityById(id)');
var obj = findElementById (id);
if (obj)
{
//alert(obj.style.visibility);
//alert(obj.style.display);
//if(!obj.style.display)
// obj.style.display = "inherit";
//alert("toggle:"+obj.style.display);
if(obj.style.display == "none" || obj.style.visibility == "hidden")
showElementById (id);
else
hideElementById (id);
}
//else alert('nno !!');
}
/*
* e.g. addevent(window,'load', my_func);
*/
function addEvent (obj, evType, fn)
{
// alert("Handler '"+evType+"("+obj+','+fn+" will be attached");
if (obj.addEventListener)
{
obj.addEventListener (evType, fn, false);
return true;
}
else if (obj.attachEvent)
{
var r = obj.attachEvent ("on" + evType, fn);
return r;
}
else
{
alert ("Handler " + evType + " could not be attached");
}
return false;
}
function addOnLoadEvent(fn)
{
addEvent(window,'load', fn);
}
/*
function addKeyEvent(obj,fn)
{
var e = (document.addEventListener) ? 'keypress' : 'keydown';
addEvent(obj,e,fn);
}
*/
/**
* Submit a form
*/
function bzc_submitform(form,task, page,params){
if(task && form.task)
form.task.value=task;
if(page && form.page)
form.page.value=page;
if(params && form.params)
form.params.value=params;
try {
form.onsubmit();
}
catch(e){}
form.submit();
}
function submitform_debug(form,task, page,params){
alert(form);
if(task && form.task)
{
alert('task is : '+task);
form.task.value=task;
}
if(page && form.page)
form.page.value=page;
if(params && form.params)
form.params.value=params;
/*@ignore@*/
try {
// form.onsubmit();
}
/*@end@*/
catch(e){}
//form.submit();
alert('submitform_debug');
}
function dumpObject(obj)
{
var out;
for (propriete in obj)
{
out += propriete + "=" + obj[propriete] + "
";
}
return out;
}
function bzc_showErrors(msg)
{
var out;
out = msg.split('
');
alert(out.join('\n'));
}
function br2nl(msg)
{
var out;
out = msg.split('
');
return out;
}
// ********************* General Cookie handling *********************
// Cookie Functions - Second Helping (21-Jan-96)
// Written by: Bill Dortch, hIdaho Design
// The following functions are released to the public domain.
function _getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function getCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return _getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function setCookie (name, value)
{
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
var now = new Date();
if(expires=='never')
{
expires = new Date();
expires.setYear(now.getFullYear()+10);
}
//alert('expires:'+expires);
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
//alert('setcokie:'+document.cookie);
}
function deleteCookie (name)
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
// This cookie is history
var cval = getCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
// End Script
/*
* show hide functions
*/
var displays_by_id = new Array();
function initDisplayById(id,def)
{
var cookie = getCookie('display-'+id);
var obj = $(id);
if(cookie && obj)
obj.style.display = cookie;
else if(def)
obj.style.display = def;
}
function resetDisplayById(id)
{
deleteCookie('display-'+id);
}
function showDisplayById(id)
{
var obj = $(id);
if (obj)
{
if(displays_by_id[id])
{
obj.style.display = displays_by_id[id]['display'];
debug('showDisplayById :restore : '+displays_by_id[id]['display']);
}
else
{
obj.style.display ='block';
displays_by_id[id] = new Array();
}
displays_by_id[id]['display']=obj.style.display;
setCookie('display-'+id,obj.style.display);
}
}
function hideDisplayById(id)
{
var obj = $(id);
if (obj)
{
if(!displays_by_id[id])
displays_by_id[id] = new Array();
displays_by_id[id]['display'] = obj.style.display;
obj.style.display = "none";
//debug('hideDisplayById :saved as : '+displays_by_id[id]['display']);
setCookie('display-'+id,obj.style.display);
}
}
function toggleDisplayById(id)
{
var obj = $(id);
if (obj)
{
if(obj.style.display == "none")
showDisplayById (id);
else
hideDisplayById (id);
}
}
/*
* css manip
*/
var cssRules = false;
function getCss(theClass,attr)
{
if(!cssRules)
{
if (document.all) cssRules = 'rules';
else if (document.getElementById) cssRules = 'cssRules';
}
for (var S = 0; S < document.styleSheets.length; S++)
{
for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
{
if (document.styleSheets[S][cssRules][R].selectorText == theClass)
{
return document.styleSheets[S][cssRules][R].style[attr];
}
}
}
return false;
}
function changeCss(theClass,element,value)
{
if(!cssRules)
{
if (document.all) cssRules = 'rules';
else if (document.getElementById) cssRules = 'cssRules';
}
for (var S = 0; S < document.styleSheets.length; S++)
{
for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
{
if (document.styleSheets[S][cssRules][R].selectorText == theClass)
{
document.styleSheets[S][cssRules][R].style[element] = value;
}
}
}
}
function loadPanel(panel_name,args)
{
ajax_loadPanel(panel_name,args);
}
/*
Window.prototype.alert = function(msg)
{
msg = "************"+msg+"******************";
//alert(msg);
}*/
/*function
alert('hello');*/