function ajax_load(config) { //(url, pars, where, onsuccess, hideloading) {
	if ((config.where != '') && (typeof(config.where) != 'undefined')) {
		if ($(config.where) != null) {
			if (config.hideloading == true) {
				//do nothing
			} else {
				var toinsert = '<span style="background:#CCFFCC;border:1px solid #77CC77;padding:3px;position:absolute;z-index:2">Loading...</span>'; //hardcoded loading
				$(config.where).innerHTML = toinsert + $(config.where).innerHTML;
			}
		} else {
			alert('id="' + config.where + '" not found. cannot load "' + config.url + '"');
		}
	} else {
		config.where = '';
	}
	
	var myAjax = new Ajax.Request(
		config.url,
		{
			method: 'post',
			parameters: 'random=' + Math.random() + '&' + config.pars,
			onSuccess: function(t) {
				if (config.where != '') {
					$(config.where).innerHTML = t.responseText;
				}
				eval(config.onsuccess);
				t.responseText.evalScripts();
			},
			onFailure: function(t) {
				error_filler(t, config.where, config.url);
			}
		}
	);
}

function request(config) {
	if (typeof(config.where) != 'string') {
		config.where = 'div_' + config.request;
	}
	
	ajax_load({
		url:			root_address + 'ajax.request.php',
		pars:			'request=' + config.request + '&w=' + all_rewrites + '&' + config.pars,
		where:			config.where,
		hideloading:	true || config.hideloading
	});

}

function request_modal(config) {
	Modalbox.show(
		config.title || 'Untitled',
		root_address + 'ajax.request.php',
		{
			width:			config.size ? config.size[0] : 400,
			height:			config.size ? config.size[1] : 300,
			params:			'request=' + config.request + '&w=' + all_rewrites + '&' + config.pars,
			loadingString:	config.loading || 'Loading...'
		}
	);
}
function flash(msg) {
	rndid = 'flash_message_' + (Math.random() + ' ').replace(/[^0-9]+/, '');
	
	$('js_flash_messages').innerHTML =
		'<div id="' + rndid + '_holder">' +
			'<div class="flash_messages" id="' + rndid + '">' +
				'<div class="info">' +
						msg +
				'</div>' +
			'</div>' +
		'</div>'
	;
	
	new Effect.Highlight(rndid);
	//setTimeout("Element.hide('" + rndid + "')", 3000);
	setTimeout("try{Effect.SlideUp('" + rndid + "_holder')}catch(e){}", 6000);
}
function update_friend_privacy(value) {
	request({
		where	: '',
		request	: 'friend.privacy',
		pars	: 'privacy=' + value
	})
}

function send_message (friend_id)
{
  window.open(root_address + 'friends/'+friend_id+'/msg', '_blank', 'width=355, height=230');
}function get_cities() {
	request({
		where:		'city_container',
		request:	'profile.cities',
		pars:		'country=' + $('country').value
	});
}
function lists_edit_item(item_id, title_label, loading_label) {
	request_modal({
		request:	'list.item.edit',
		pars:		'item_id=' + item_id,
		size:		[600, 250],
		title:		title_label ? title_label : 'Edit List Item',
		loading:	loading_label ? loading_label : 'Loading...'
	});
}
function donate ()
{
  document.getElementById ('donate_div_ask').style.display = 'none';
  document.getElementById ('donate_div_select').style.display = 'block';
  i = 0;
  while(document.getElementById ('donate_box_div'+'_'+i))
  {
    document.getElementById ('donate_box_div'+'_'+i).style.display = 'block';
    
    name = document.getElementById ('_item_name'+'_'+i).value + " donation";
    document.getElementById ('_item_name'+'_'+i).value = name;
    
    desc = document.getElementById ('_item_description'+'_'+i).value;
    desc = desc.replace("for", "donation from");
    document.getElementById ('_item_description'+'_'+i).value = desc;
    
    i++;
  }
}function showhide_org(status)
{
  document.getElementById('organisation_tr').style.display = status ? 'block' : 'none';
}
var swdCycleTime=50;


// Functional Code

var swd,swdObj,swdct,swdnow,swdcycle;
var swdObjAry=new Array();
hr = 0; min = 0; secs = 0; rem = 0;
hrStr = ''; minStr = ''; secStr = '';

function swdStart(id,ud){
 swdObj=document.getElementById(id);
 if (swdObj.value != 0 && swdObj.value != "" && swdObj.value != "00:00:00") {
     theExistingTime=(swdObj.value).split(":");
     if (theExistingTime.length==3)
        swdObj.d=parseInt(parseInt(theExistingTime[0])*60*60) + parseInt(parseInt(theExistingTime[1])*60) + parseInt(theExistingTime[2]);
     else
        swdObj.d=0;
 } else {
    swdObj.d=0;
    swdObj.value="00:00:00";
 }
 swdnow=new Date();
 swdObj.now=swdnow.getTime();
 swdObj.ud=ud*1000;
 if (!swdObj.c){
  swdObj.c=1;
  swdObjAry[swdObjAry.length]=swdObj;
 }
 if (swdObj.c==2){ swdObj.c=1; }
}

function swdCycle(){
 swdcycle=new Date().getTime();
 for (swd0=0;swd0<swdObjAry.length;swd0++){
  if (swdcycle>swdObjAry[swd0].now+swdObjAry[swd0].ud&&swdObjAry[swd0].c==1){
   swdObjAry[swd0].d++;
   swdObjAry[swd0].now=swdObjAry[swd0].now+swdObjAry[swd0].ud;
   timerVal = swdObjAry[swd0].d;
   if (timerVal >= 3600)
   {
    hr = timerVal % 3600;
    rem = timerVal - (hr*3600);
    if (hr < 10)
      hrStr = "0" + hr;
    else
      hrStr = hr;
   }
   else
   {
       hrStr = "00";
       rem = timerVal;
   }
   
   if (rem >= 60) {
       min = parseInt(rem/60);
       rem = rem - (min*60);
       if (min < 10)
        minStr = "0" + min;
       else if (min < 60)
        minStr = min;
       else
        min = 0;
        
       if (rem == 60) rem = 0;
   }
   else {
       minStr = "00";
   }
   secStr = (rem < 10) ? "0" + rem : rem;
   theTime = hrStr + ":" + minStr + ":" + secStr;
   swdObjAry[swd0].value=theTime;
  }
 }
}

function swdStop(id){
 swdObj=document.getElementById(id);
 swdObj.c=2;
}

setInterval('swdCycle()',swdCycleTime);

function showStopWatch(imgId, theRow, theTimer, theWatch) {
  theObj = document.getElementById(theRow);
  
  if (theWatch && !document.getElementById(theWatch).disabled) // the time can be edit so we won't start the timer
  {
    return false;
  }
  
  itemTimer = false;
  
  //todo: check and rebuild the below for/if/if structure
  /*
  if (document.getElementById('taskcount').value > 0) {
    totalTasks = document.getElementById('taskcount').value;
  } else {
    totalTasks = counter - 1;
  }
  totalTasks = item_counter - 1;
  for (i=1; i<=totalTasks; ++i) {
      if (theRow != ('stopwatch' + i)) {
          theImg = document.getElementById('img_stopwatch_' + i);
          theLoc = (theImg.src).split("/");
          if (document.getElementById('stopwatch' + i).style.display == 'block' && (theRow.toLowerCase() == "stopwatchlist" || theLoc[theLoc.length-1] == "stopwatch-off.gif")) {
              if (theRow.toLowerCase() != 'stopwatchlist' && confirm("Do you want to deactivate the running timer(s) and activate this one?")) {
			      swdStop('clock_' + i);
                  document.getElementById('clock_' + i).value = "00:00:00";
                  document.getElementById('stopwatch' + i).style.display = 'none';
                  document.getElementById('img_stopwatch_' + i).src = root_address + "images/stopwatch-on.gif";
                  document.getElementById('img_stopwatch_' + i).title = "Start the timer";
              }  else if (theRow.toLowerCase() == 'stopwatchlist' && confirm("Do you want to deactivate the item timer(s) and activate the LIST timer?")) {
                    for (j=1; j<=totalTasks; ++j) {
                      document.getElementById('stopwatch' + j).style.display = 'none';
                      document.getElementById('img_stopwatch_' + j).src = root_address + "images/stopwatch-on.gif";
                      document.getElementById('img_stopwatch_' + j).title = "Start the timer";
                      document.getElementById('clock_' + j).value = "00:00:00";
                    }
                    break;
              } else {
                  return;
              }
          }
      }
  }
  */
  if (theRow.toLowerCase() != 'stopwatchlist' && document.getElementById('stopwatchList').style.display == 'block') {
      alert('You have not stopped the LIST timer. Click "OK" and then stop the timer before moving to a different timer');
      return;
      /*if (confirm("Do you want to deactivate the LIST timer and activate timer for this item?")) {
      	  swdStop('clock_list');
          document.getElementById('stopwatchList').style.display = 'none';
          document.getElementById('img_stopwatch_list').src = "images/stopwatch-on.gif";
          document.getElementById('img_stopwatch_list').title = "Start the List timer";
          document.getElementById('clock_list').value = "00:00:00";
      } else {
          return;
      }*/
  }

  if (theObj.style.display == 'none' || theObj.style.display == '') {
      document.getElementById(theTimer).value="00:00:00";
      theObj.style.display = 'block';
  }
  theImg = document.getElementById(imgId);
  theLoc = (theImg.src).split("/");
  if (theLoc[theLoc.length-1] == "stopwatch-on.gif") {
      swdStart(theTimer, 1);
      theImg.src = root_address + "images/stopwatch-off.gif";
      theImg.title = t("Stop the timer");
  } else {
	request({
		where: '',
		request: 'stopwatch.save',
		pars: 'time_amount=' + $F(theTimer) + '&item_id=' + encodeURIComponent(theTimer.replace(/clock_/, ''))
	});
	theForm = $(theTimer).form;
  
  //theForm.submit();
	Element.hide(theRow);
	swdStop(theTimer);
	theImg.src = root_address + "images/stopwatch-on.gif";
	theImg.title = t("Start the timer");
  }
}


function editWatch(imgId, theRow, theTimer, theWatch) {
  theObj = document.getElementById(theRow);
  watch = document.getElementById(theWatch);
  
  if (theObj.style.display == 'none' || theObj.style.display == '');
  else // if the timer is started we won't allow edit
  {
    return false;
  }
  
  watch.disabled = false;
  
  theImg = document.getElementById(imgId);
  theLoc = (theImg.src).split("/");
  if (theLoc[theLoc.length-1] == "clock_edit.gif") {
      theImg.src = root_address + "images/stopwatch-off.gif";
      theImg.title = t("Save changes");
  } else {
    request({
      where: '',
      request: 'stopwatch.save',
      pars: 'total_time_amount=' + $F(theWatch) + '&item_id=' + encodeURIComponent(theTimer.replace(/clock_/, ''))
    });
    theForm = $(theTimer).form;
  
    //theForm.submit();
    Element.hide(theRow);
    theImg.src = root_address + "images/icons/clock_edit.gif";
    theImg.title = t("Edit the timer for the whole list");
    watch.disabled = true;
  }

}var translations = new Array();

function t(text)
{
  if (typeof translations[text] != undefined)
  {
    return translations[text];
  }
  return 
}