function openAWindow( pageToLoad, winName, width, height, center, scroll) {
	xposition=0;
	yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
  	xposition = (screen.width - width) / 2;
  	yposition = (screen.height - height) / 2;
  }

  args = "width=" + width + "," + "height=" + height + "," + "location=0," + "scrollbars=" + scroll + "," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;

  window.open( pageToLoad, winName, args );
}

function popupwin(url, width, height)
{
	var newParameter = "width="+ width +",height="+ height +",scrollbars=yes,toolbar=no,resizable=yes,top=50,left=150";
	window.open(url, "", newParameter);
}

function target_form(action, targetName, width, height)
{
	features = "width="+ width +",height="+ height +",scrollbars=no,toolbar=no,resizable=1,top=150,left=300";
	window.open(action,targetName,features);
}	
	
function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}

function expand_height(boxid, pixelvalue)
{
	var box = fetch_object(boxid);
	var boxheight = parseInt(box.style.height);
	var newheight = boxheight + pixelvalue;
	if (newheight > 0)
	{
		box.style.height = newheight + "px";
	}
	return false;
}

function is_valid_email(email) {

 return /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(email);
}

function getbyid( id )
{
 val = null;

 if ( document.getElementById )
 {
  val = document.getElementById( id );
 }
 else if ( document.all )
 {
  val = document.all[id];
 }
 else if ( document.layers )
 {
  val = document.layers[id];
 }

 return val;
}

function send2iframe(the_form,the_iframe,query) {
 var frm = document.forms[the_form];
 frm.target = the_iframe;
 frm.action = 'ajax/' + query;
 frm.submit();
}

function view_profile(userid) {
 //alert('(' + userid + ') to be continued...');
 openAWindow( 'view_profile.php?params[uid]=' + userid, 'view_profile', 250, 400, 1, 0);
}

function zoom_full(query,sizew,sizeh) {
 openAWindow( 'zoom_full.php?' + query, 'zoom', sizew, sizeh, 1, 0);
}

function open_fullsize(page,sizew,sizeh) {
 openAWindow( page, 'zoom', sizew, sizeh, 1, 0);
}

function replace( s, t, u )
{
 /*
 **  Replace a token in a string
 **    s  string to be processed
 **    t  token to be found and removed
 **    u  token to be inserted
 **  returns new String
 */
 i = s.toLowerCase().indexOf( t.toLowerCase() );
 r = "";

 if ( i == -1 )
  return s;

 r += s.substring( 0, i ) + u;
	
 if ( i + t.length < s.length )
  r += replace( s.substring( i + t.length, s.length ), t, u );
	

 return r;
}
