//<![CDATA[

var loadmodule = null;


function isUsername(string,minlength,maxlength)
{
	var valid = '/^[a-z][-a-z0-9_]{'+(minlength-1)+','+(maxlength-1)+'}$/';
	
	if (!minlength) minlength = 1;
	if (!maxlength) maxlength = 255;
	
	var result = (valid.test(string) && (string.length >= minlength) && (string.length <= maxlength));
	
	return result;
}

function isEmail(string)
{
	if (!string) return false;
	
	tfld = trim(string);
	
	var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
	if (!email.test(tfld))
	{
		return false;
	}

	var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
	if (!email2.test(tfld)) 
	{
		return false;
	}
	
	return true;
}

function isAlphaNumeric(string)
{
   if (!string) return false;
   if (string == " ") return false;
   
   var iChars = "*|,\":<>[]{}`\';()@&$#%";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '');
}

function formatcurrency(st)
{
	st += "";
	var theValue = st;
	var finalString = '';
	
	if(theValue.length < 4)
	{
		finalString = theValue;
	}
	else
	{
		if(theValue.indexOf(".")==-1)
		{
			theValueEx = "";
		}
		else
		{
			temp = theValue.split(".");
			theValue=temp[0];
			theValueEx= "." + temp[1];
		}
		
		var modulus = theValue.length % 3
		var count = 0
		finalString = theValue.substring(0, modulus)
		
		if(modulus != 0) finalString += ','
		for(i = modulus; i < theValue.length; i++)
		{
			if(count == 3)
			{
				finalString += ',';
				count = 0;
			}
			finalString += theValue.charAt(i);
			count++;
		}
		finalString = finalString + theValueEx;
	}
	
	return finalString;
}


//	layout functions
function getURL(url)
{
	window.location.href = url;
}

function open_window(s_url, s_name, sw, sh, sr, ss, sd)
{
	d = '1';
	r = 'no';
	s = 'yes';
	w = '420';
	h = '500';
	
	if( sd ) d = sd;
	if( sr ) r = sr;
	if( ss ) s = ss;
	if( sw ) w = sw;
	if( sh ) h = sh;
	
	if( !s_name ) s_name = 'popup';
	
	wleft = (screen.width) ? (screen.width-w)/2 : 0;
	wtop = (screen.height) ? (screen.height-h)/2 : 0;
	
	s_prop = 'dependent='+ d
		+ ',resizable=' + r 
		+ ',scrollbars=' + s 
		+ ',width=' + w 
		+ ',height=' + h
		+ ',top=' + wtop
		+ ',left=' + wleft + '';
	
	window.open(s_url, s_name, s_prop)
}

function copy_to_parent(s_elm, s_val) {
  eval('window.opener.frm.' + s_elm + ".value = '" + s_val + "'");
}

function confirm_action(target, vs_dialog, vs_href)
{
	if (confirm(vs_dialog))
	{
		target.window.location.href = vs_href;
	}
	return true;
}

function NewWindow(mypage,myname,w,h,scroll)
{
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}


function viewPic(img)
{
	picfile = new Image();
	picfile.src=(img);
	fileCheck(img); 
}

function fileCheck(img)
{
	if((picfile.width!=0)&&(picfile.height!=0))
	{
		makeWindow(img);
	}
	else
	{
		funzione="fileCheck('"+img+"')";
		intervallo=setTimeout(funzione,50);
	}
}

function makeWindow(img)
{
	ht=picfile.height+20; wd=picfile.width+20;
	var args="height="+ht+",innerHeight="+ht;
	args+=",width="+wd+",innerWidth="+wd;
	if (window.screen)
	{
		var avht=screen.availHeight; var avwd=screen.availWidth;
		var xcen=(avwd-wd)/2; var ycen=(avht-ht)/2;
		args+=",left="+xcen+",screenX="+xcen;
		args+=",top="+ycen+",screenY="+ycen+",resizable=1,scrollbars=0"; 
	}
	return window.open(img, '', args); 
}

Array.prototype.in_array_minus = function(search_term) {
  var i = this.length;
  if (i > 0) {
	 do {
		if (this[i] === search_term) {
		   return true;
		}
	 } while (i--);
  }
  return false;
}
//]]>