function ConfirmDelete(url){
  var msg="Deleting this record, and probably all related records in other tables?";
  if (confirm(msg)) window.location=url;
}
/*
function body_onUnload(){
  var msg="Please use the logout button to exit the database!";
  if(confirm(msg)) msg="ok";//window.location="logout.php";
}*/
//==========================================================================
function du(myurl){//change location
	document.location.href = myurl;
}
function cw(myurl){//use current window
  window.location.href=myurl;//SAME as above
}
function w(url){//open a new virtual window using my window manager lib
	//TODO: Use 'window.top.YAHOO.myext.newWin()'
	try{
		if(window.top){
			if(window.top.YAHOO){
				if(window.top.YAHOO.myext) 
					window.top.YAHOO.myext.desktop.newWin(url, 'Loading..' ,true);
			}else{
				if(window.top.MyDesktop){
					if(window.top.MyDesktop.w)
						window.top.MyDesktop.w(url);
				}else{
					if(parent.w)
						parent.w(url);
				}
			}
		}
	}catch(e){
	  alert('Unexpected error: '+e);//or do nothing
	}
}
function w2(myurl,w,h){//new REAL window
	var s="toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes"
		+ ',width=' + w + ',height=' + h;
	window.open(myurl,'_blank',s);
}
/*
function unloadwins(){//unload all popup windows opened previously!!!
  for(i=0;i<wins.length;i++)
	  if(wins[i]!=null) wins[i].close();
}
*/
//======================================================================
//usage: closeByIfr(window.frameElement);
function closeByIfr(){
	try{
		if(parent){
			if(parent.YAHOO && parent.YAHOO.myext) 
				parent.YAHOO.myext.desktop.closeByIfr(window.frameElement);
			else
				if(parent.closeByIfr) parent.closeByIfr();
		}
	}catch(e){
	  //alert('Unexpected error: '+e);//or do nothing
	}
}
function myMsg(msg){
	try{
		if(parent){
			if(parent.YAHOO && parent.YAHOO.myext) 
				parent.YAHOO.myext.desktop.myMsg(msg);
			else
				if(parent.myMsg) parent.myMsg(msg);
		}
	}catch(e){
	  alert('Unexpected error: '+e);//or do nothing
	}
}
function showSelectFrame(url, callback){	
	try{
		if(parent){
			if(parent.YAHOO && parent.YAHOO.myext) 
				parent.YAHOO.myext.desktop.showSelectBox(url, callback);
			else
				if(parent.showSelectFrame) parent.showSelectFrame(url, callback);
		}
	}catch(e){
	  alert('Unexpected error: '+e);//or do nothing
	}
}
function selectOption(selectbox, value){
	try{
		if(selectbox.options == undefined){//DISABLED SELECT BOXES ARE NOW HIDDEN INPUTS
			//alert('Unknown listbox!\n[main.js::selectOption()]');
			return false;
		}
	  //TRIM and COMPARE because of a lot CHAR fields in SUN
	  var s = '', j = -1, v = '', find = trim(''+value);
		for(var i=0; i < selectbox.options.length; i++){
		  s += 'Option: '+i+' => \''+selectbox.options[i].value+'\'\n';
		  v = trim(''+selectbox.options[i].value);
			if(v === find){
				if(j==-1){//none selected before
					j = i;
					break;//comment to log for alert box
				}
			}
		}
		if(j >= 0){//only if value is found!
			selectbox.selectedIndex = j;
		}
		//alert(selectbox.name + '\nFind: \''+value+'\'\nOptions: \n'+s+'Selected: '+j);
	}catch(e){
		alert('Unexpected error: '+e+'[main.js::selectOption()');//or do nothing
	}
}

function comboValue(id){
  var c = document.getElementById(id);
  if(c) return c.options[c.selectedIndex].value;
  return false;
}

//use body onload='expand();' to expand window to desktop
function expand(wid, hei){
  window.moveTo(0,20);
  window.resizeTo(wid, hei);
}

function dcal(myurl){
	if(parent.document.getElementById('cal_notes'))
		parent.document.getElementById('cal_notes').src = myurl;
	else
		document.location.href = myurl;
}

function myCalRefresh(){
	if(parent.document.getElementById('calendar'))
		parent.document.getElementById('calendar').src = 'cal_week.php?abc=1';//parent.document.getElementById('calendar').src;
	
}
function textCounter(field, countfield, maxlimit) {//to limit TEXT in textareas
	if(field.value.length > maxlimit)// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	else // otherwise, update 'characters left' counter 
		countfield.value = maxlimit - field.value.length;
}

// new function for date objects
Date.prototype.add = function (sInterval, iNum){
	var dTemp = this;
	if (!sInterval || iNum == 0) return dTemp;
	switch (sInterval.toLowerCase()){
		case "ms": dTemp.setMilliseconds(dTemp.getMilliseconds() + iNum); break;
		case "s": dTemp.setSeconds(dTemp.getSeconds() + iNum); break;
		case "mi": dTemp.setMinutes(dTemp.getMinutes() + iNum); break;
		case "h": dTemp.setHours(dTemp.getHours() + iNum); break;
		case "d": dTemp.setDate(dTemp.getDate() + iNum); break;
		case "mo": dTemp.setMonth(dTemp.getMonth() + iNum); break;
		case "y": dTemp.setFullYear(dTemp.getFullYear() + iNum); break;
	}
	return dTemp;
}
function my_today(format){
	var f=format.split("/");
	var dt=new Date();
	var d=dt.getDay();
	var m=dt.getMonth();
	var y=dt.getYear();
	if(y<1000) y+=1900;
	if(format='d/m/y') return d+'/'+m+'/'+y;
	if(format='d.m.y') return d+'.'+m+'.'+y;
	if(format='m/d/y') return m+'/'+d+'/'+y;
	if(format='y-m-d') return y+'-'+m+'-'+d;
}

/**
 * object/variable information
 */
function js_vardump(obj, parent){
	var msg = '';
	for(var i in obj){
		if(parent){
			msg = parent + "." + i + "\n" + obj[i];
		}else{
			msg = i + "\n" + obj[i];
		}
		if (!confirm(msg)) { return; }
		if (typeof obj[i] == "object"){
			if (parent){
				js_vardump(obj[i], parent + "." + i);
			}else{
				js_vardump(obj[i], i);
			}
		}
	}
}

/**
 * parseFloat removing commas
 */
function pf(v){
	var s = '' + (v==''?0:v);
	s = s.replace(/,/g, "");
	s = parseFloat(s);
	return (isNaN(s)?0:s);
}

function divert_form(my_frm, my_action, my_target){
	var t = my_frm.target;//temp
	var a = my_frm.action;//temp
	
	my_frm.target = my_target;
	my_frm.action = my_action;
	my_frm.submit();
	
	my_frm.target = t;//back
	my_frm.action = a;//back
}

function domEl(id){
	return document.getElementById(id);
}

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}


function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()

//change iFRAME source
function ifrSrc(ifr, src){
	try{
		if(document.getElementById(ifr))
			document.getElementById(ifr).src = src;
	}catch(e){
		//exception
		//alert('Unexpected error: ' + e.description);
	}
}

//Prints the date in a string according to the given format.
Date.prototype.myFormat = function (str) {
	var m = this.getMonth();
	var d = this.getDate();
	var y = this.getFullYear();
	var wn = this.getWeekNumber();
	var w = this.getDay();
	var s = {};
	var hr = this.getHours();
	var pm = (hr >= 12);
	var ir = (pm) ? (hr - 12) : hr;
	var dy = this.getDayOfYear();
	if (ir == 0)
		ir = 12;
	var min = this.getMinutes();
	var sec = this.getSeconds();
	s["%a"] = Calendar._SDN[w]; // abbreviated weekday name [FIXME: I18N]
	s["%A"] = Calendar._DN[w]; // full weekday name
	s["%b"] = Calendar._SMN[m]; // abbreviated month name [FIXME: I18N]
	s["%B"] = Calendar._MN[m]; // full month name
	// FIXME: %c : preferred date and time representation for the current locale
	s["%C"] = 1 + Math.floor(y / 100); // the century number
	s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31)
	s["%e"] = d; // the day of the month (range 1 to 31)
	// FIXME: %D : american date style: %m/%d/%y
	// FIXME: %E, %F, %G, %g, %h (man strftime)
	s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format)
	s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format)
	s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366)
	s["%k"] = hr;		// hour, range 0 to 23 (24h format)
	s["%l"] = ir;		// hour, range 1 to 12 (12h format)
	s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12
	s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
	s["%n"] = "\n";		// a newline character
	s["%p"] = pm ? "PM" : "AM";
	s["%P"] = pm ? "pm" : "am";
	// FIXME: %r : the time in am/pm notation %I:%M:%S %p
	// FIXME: %R : the time in 24-hour notation %H:%M
	s["%s"] = Math.floor(this.getTime() / 1000);
	s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59
	s["%t"] = "\t";		// a tab character
	// FIXME: %T : the time in 24-hour notation (%H:%M:%S)
	s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn;
	s["%u"] = w + 1;	// the day of the week (range 1 to 7, 1 = MON)
	s["%w"] = w;		// the day of the week (range 0 to 6, 0 = SUN)
	// FIXME: %x : preferred date representation for the current locale without the time
	// FIXME: %X : preferred time representation for the current locale without the date
	s["%y"] = ('' + y).substr(2, 2); // year without the century (range 00 to 99)
	s["%Y"] = y;		// year with the century
	s["%%"] = "%";		// a literal '%' character

	var re = /%./g;
	if (!Calendar.is_ie5 && !Calendar.is_khtml)
		return str.replace(re, function (par) { return s[par] || par; });

	var a = str.match(re);
	for (var i = 0; i < a.length; i++) {
		var tmp = s[a[i]];
		if (tmp) {
			re = new RegExp(a[i], 'g');
			str = str.replace(re, tmp);
		}
	}

	return str;
};

function myDate_addDays(myDate, myDays){//, myFormatStr){
	var myTime = myDate.getTime();
	var myDate2 = new Date(myTime);
	myDate2.setDate(myDate.getDate() + myDays);//add days
	return myDate2;//.myFormat(myFormatStr);
}

function myDate_addMonths(myDate, myMonths){//, myFormatStr){//'%d/%m/%Y'
	var myTime = myDate.getTime();
	//myTime += Date.WEEK * 4 * myMonths;
	var myDate2 = new Date(myTime);
	myDate2.setMonth(myDate.getMonth() + myMonths);//add months
	return myDate2;//.myFormat(myFormatStr);
}

// concatenate + to a string
function add_plus_to_string(myStr){
	var s = trim(myStr);
	if(s =='') return s;
	var s1 = s.substr(0,2);
	if( s1=='00'){
		//first two chars '00' hence international
	  s1 = '+' + s.substr(2,s.length);
	  return s1;
	}
	return s;
}

function replace_tel_num_00(txt){
	txt.value = add_plus_to_string(txt.value);
	return true;
}

