function process_form_json(myform, furl, targ, but){
      but.disabled=true;
      var queryString = $('#'+myform).formSerialize(); 
      $('#'+targ).html('<center><img src=working.gif style="vertical-align:middle;"> Processing...</center>');
      $.post(furl, queryString, function(ret,sta){
	  $('#'+targ).html(ret.message);
	  if (ret.status==1){
	      but.disabled=true;
	  }else{
	      but.disabled=false;
	  }
	  if (ret.redirect==1){
	      document.location=ret.redirect_url;
	  }
      }, "json");
}

function process_form(myform, furl, targ){
      var queryString = $('#'+myform).formSerialize(); 
      $('#'+targ).html('<center><img src=working.gif style="vertical-align:middle;"> Processing...</center>');
      $.post(furl, queryString, function(ret,sta){
	  $('#'+targ).html(ret);
      });
}

function process_form_callback(myform, furl, targ, func){
      var queryString = $('#'+myform).formSerialize(); 
      $('#'+targ).html('<center><img src=working.gif style="vertical-align:middle;"> Processing...</center>');
      $.post(furl, queryString, function(ret,sta){
	  $('#'+targ).html(ret);
	  eval(func);
      });
}

function get_url(furl, targ){ 
      $('#'+targ).html('<center><img src=working.gif style="vertical-align:middle;"> Processing...</center>');
      $.post(furl, '', function(ret,sta){
	  $('#'+targ).html(ret);
      });
}

function get_url_smooth(furl, targ){ 
      $.post(furl, '', function(ret,sta){
	  $('#'+targ).html(ret);
      });
}

function toggle(id){
	var element=document.getElementById(id);

	if (element.style.display=='none'){
		element.style.display='';
	}else{
		element.style.display='none';
	}
} 

function hide(id){
	var element=document.getElementById(id);
	element.style.display='none';
} 
function show(id){
	var element=document.getElementById(id);
	element.style.display='';
}
function destroy(id){
	var element=document.getElementById(id);
	element.innerHTML='';
} 


function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
} 

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



function get_light_content(url, msg, wid, hei){
	$('#'+msg).html('<center><img src=working.gif style="vertical-align:middle;"> Processing...</center>');

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	// center loadingImage if it exists
	document.getElementById('light').style.height=hei+ 'px' ;
	document.getElementById('light').style.width =wid+ 'px';

	var ttt = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - hei) / 2) + 'px');
	document.getElementById('light').style.left = (((arrayPageSize[0] - 20 - wid) / 2) + 'px');
	
	document.getElementById('light').style.top=ttt;
				
	// set height of Overlay to take up whole page and show
	document.getElementById('fade').style.height = (arrayPageSize[1] + 'px');
	document.getElementById('fade').style.display='block';

	$.get(url, '', function(ret,sta){
		$('#'+msg).html(ret);
		document.getElementById('light').style.display='block';			
	    });
} 
