function CheckId(Id)
{
	Email=Id;
	Email = Email.toLowerCase();

	if (Email == '')
		return '';

	if (Email.indexOf(' ') != -1)
		return '';

	if (Email.indexOf('..') != -1)
		return '';

	if (Email.indexOf('@') != -1)
		return '';

	if (Email.indexOf(':') != -1)
		return '';

	if (Email.charAt(0) >='0' && Email.charAt(0)<='9')
		return '';
	for (i=0; i < Email.length; i++)
	{
		c = Email.charAt(i);

		if (c >= '0' && c <= '9')
			continue;
		
		if (c >= 'a' && c <= 'z')
			continue;
		
		if ('`~!#$%^&*-_+=?/\\|@.'.indexOf(c) != -1)
			continue;

		return '';
	}

	//if ((i=Email.indexOf('@'))==-1)
	//	return '';

	//if (Email.substr(i + 1).indexOf('@')!=-1)
	//	return '';

	if (Email.charAt(0)=='.' || Email.charAt(Email.length - 1)=='.')
		return '';
	if(Email.length < 4 || Email.length >20)
		return '';
	return Email;
}
function CheckEmailAddress(Email)
{
	while (Email != '')
	{
		c = Email.charAt(0);	
		if (c==' ' || c=='<' || c==39 || c==':' || c=='.')
		{
			Email = Email.substr(1);
		}
		else
		{
			break;
		}
	}

	i = Email.indexOf('>');
	if (i==-1)
	{
		while (Email != '')
		{
			c = Email.charAt(Email.length - 1);
			if (c==' ' || c==39 || c=='.')
			{
				Email = Email.substr(0, Email.length - 1);
			}
			else
			{
				break;
			}
		}
	}
	else
	{
		Email = Email.substr(0, i);
	}

	if (Email.length > 96)
		return '';

	i = Email.lastIndexOf('@');
	j = Email.lastIndexOf('.');
	if (i < j)
		i = j;

	switch (Email.length - i - 1)
	{
	case 2:
		break;
	case 3:
		switch (Email.substr(i))
		{
		case '.com':
		case '.net':
		case '.org':
		case '.edu':
		case '.mil':
		case '.gov':
		case '.biz':
		case '.pro':
		case '.int':
		case '.vn':
			break;
		default:
			return '';
		}
		break;
	default:
		switch (Email.substr(i))
		{
		case '.name':
		case '.info':
			break;
		default:
			return '';
		}
		break;
	}

	Email = Email.toLowerCase();

	if (Email == '')
		return '';

	if (Email.indexOf(' ') != -1)
		return '';

	if (Email.indexOf('..') != -1)
		return '';

	if (Email.indexOf('.@') != -1)
		return '';

	if (Email.indexOf('@.') != -1)
		return '';

	if (Email.indexOf(':') != -1)
		return '';

	for (i=0; i < Email.length; i++)
	{
		c = Email.charAt(i);

		if (c >= '0' && c <= '9')
			continue;
		
		if (c >= 'a' && c <= 'z')
			continue;
		
		if ('`~!#$%^&*-_+=?/\\|@.'.indexOf(c) != -1)
			continue;

		return '';
	}

	if ((i=Email.indexOf('@'))==-1)
		return '';

	if (Email.substr(i + 1).indexOf('@')!=-1)
		return '';

	if (Email.charAt(0)=='.' || Email.charAt(Email.length - 1)=='.')
		return '';

	return Email;
}

//===================================================
function HTML_Text(st)
{ 
if (st==null || st == "") return "";
	var s,re;
	s	=	st;
	s	=	s.replace(/\"/g,"\"");
	s	=	s.replace(/\</g,"&lt;");
	s	=	s.replace(/\>/g,"&gt;");
	return s;
} 
//=====================================================
function pop(file, x, y)
{
	var popup=window.open(file,"ew", "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,center = 1,width=" + x + ",height=" + y) 
}


function ShowTab(k){
  var TabImages = document.all.item("Tab");
  if (TabImages != null){
    for (i=0; i < TabImages.length; i++) {
        TabImages.item(i).src=ImArU[i];
    }
  }
  if (window.event.srcElement.tagName == "IMG" ){
    window.event.srcElement.src =ImArD[k];
  }  
}


function flipImage(url)
{
    if (window.event.srcElement.tagName == "IMG" ) {
        window.event.srcElement.src = url;
    }
}

//----------------------------------------------------------------------------------
function isNumerofPhone(strNumber){
var i, c, sTemp
sTemp = trim(strNumber);
for ( i = 0; i< sTemp.length; i++ ){
  c = sTemp.charAt(i);
  if ( !( c>='0' && c<='9') ) {
    return false;
  }
 }
 return true;	
}

//***************************************************************************************
function FormatNumber(f) // Format a float number (f) with group separators and 2 decimal digits
{
var s = "" + Math.floor(f); // conver to a string
var nDecPart = Math.round((f - Math.floor(f))*100); // the decimal part
var sRetVal = "";  var i, nGroupCount=0;
for (i=s.length-1; i>=0; i--){
  sRetVal += s.charAt(i);
  nGroupCount++;
  if (i>0 && nGroupCount % 3 == 0 ) sRetVal += ",";
}
s = sRetVal; sRetVal = "";
for (i=s.length-1; i>=0; i--){
  sRetVal += s.charAt(i);
}
sRetVal = sRetVal.replace('-,', '-');

return sRetVal + "." + nDecPart;
} // FormatNumber

////////////////////////////////////////////////////////

function CheckSIN ( SIN_Text )
{
	return document.qMiscJavaFns.CheckSIN( parseFloat( SIN_Text ));
} //CheckSIN
////////////////////////////////////////////////////////////////////

function getAge( sDate )
{
var d,n1,n2, nMonth, nYear, nDay, nCurrMonth, nCurrYear, nCurrDay, nAge;

n1 = sDate.indexOf( "/" );
n2 = sDate.lastIndexOf( "/" );
nMonth = parseInt(  sDate.substring( 0, n1  ),10);
nDay = parseInt(  sDate.substring( n1+1, n2  ),10);
nYear = parseInt(  sDate.substring(n2+1),10);
d = new Date();
nCurrMonth = (d.getMonth() + 1);
nCurrDay = d.getDate() ;
nCurrYear = d.getFullYear();

nAge = nCurrYear - nYear - 1;
if ( (nCurrMonth > nMonth ) || (nCurrMonth == nMonth && nCurrDay >= nDay) ) nAge++;
return nAge;
}


function isDate( s )
{
	var sDay, sMonth, sYear, nMonth, nDay, nYear, nSep1, nSep2;
	nSep1 = s.indexOf( "/" );	if ( nSep1 < 0 ) return false;
	nSep2 = s.lastIndexOf( "/" );	if ( nSep2 < 0 ) return false;
	if ( nSep1 == nSep2 ) return false;
	
	sMonth = s.substring( 0, nSep1  );
	sDay = s.substring( nSep1 + 1, nSep2 );
	sYear = s.substring( nSep2+1 );
	if ( !sMonth.length || !sDay.length || !sYear.length ) return false;
	// isNaN(empty) is false
	if ( isNaN(sMonth) || isNaN(sDay) || isNaN(sYear) ) return false;
	nMonth = parseInt(sMonth,10); nDay = parseInt(sDay,10); nYear = parseInt(sYear,10);
	if ( nMonth<=0 || nDay<=0 || nYear<=0 || sYear.length != 4) return false;
	if ( nMonth > 12 ) return false;
	if ((nYear<1753)||(nYear>9999))	return false;
				
	
	if (nMonth==1 || nMonth==3 || nMonth==5 || nMonth==7 || nMonth==8 || nMonth==10 || nMonth==12 )
		if ( nDay > 31 ) return false; 
	if (nMonth==4 || nMonth==6 || nMonth==9 || nMonth==11 )
		if ( nDay > 30 ) return false; 
	if (nMonth==2) {
		if ( (nYear % 4 == 0) && (nYear % 100 != 0)) { // leap year
			if ( nDay > 29 ) return false;
		} else if ( nDay > 28 ) return false;
	}
	return true;
} // isDate function





// CompareToToday: 

function CompareToToday(sDate)
{
var d,n1,n2, nMonth, nYear, nDay, nCurrMonth, nCurrYear, nCurrDay;

n1 = sDate.indexOf( "/" );
n2 = sDate.lastIndexOf( "/" );
nMonth = parseInt(  sDate.substring( 0, n1  ),10 );
nDay = parseInt(  sDate.substring( n1+1, n2  ),10);
nYear = parseInt(  sDate.substring(n2+1),10);
d = new Date();
nCurrMonth = (d.getMonth() + 1);
nCurrDay = d.getDate() ;
nCurrYear = d.getFullYear();

// alert( nYear + ":" + nMonth + ":" + nDay + "-" + nCurrYear + ":" + nCurrMonth + ":" + nCurrDay );

if ( nYear > nCurrYear ) return 1;
if ( nYear < nCurrYear ) return -1;
// Now nYear == nCurrYear
if ( nMonth > nCurrMonth ) return 1;
if ( nMonth < nCurrMonth ) return -1;
// Now nMonth == nCurrMonth
if ( nDay > nCurrDay ) return 1;
if ( nDay < nCurrDay ) return -1;
return 0;
	    	
} // CompareToToday

function CompareDate( sStartDate, sEndDate)
{
var f, startDay, startMonth, startYear, endMonth, endDay, endYear, n1, n2,n3, n4;
n1 = sStartDate.indexOf( "/" );
n2 = sStartDate.lastIndexOf( "/" );
n3 = sEndDate.indexOf( "/" );
n4 = sEndDate.lastIndexOf( "/" );

startDay = parseInt( sStartDate.substring( 0, n1  ),10);
startMonth = parseInt( sStartDate.substring( n1 + 1, n2 ),10);
startYear = parseInt( sStartDate.substring( n2+1 ),10);

endDay = parseInt( sEndDate.substring( 0, n3  ),10);
endMonth = parseInt( sEndDate.substring( n3+1, n4 ),10);
endYear = parseInt( sEndDate.substring( n4+1 ),10);

if ( startYear > endYear ) return 1;
if ( startYear < endYear ) return -1;
// Now startYear == endYear
if ( startMonth > endMonth ) return 1;
if ( startMonth < endMonth ) return -1;
// Now startMonth == endMonth
if ( startDay > endDay ) return 1;
if ( startDay < endDay ) return -1;
return 0;

} // compareDate


function trim( s )
{
var i, sRetVal = "";
i = s.length - 1;
while ( i>=0 && s.charAt(i) == ' ' ) i--;
s = s.substring( 0, i+1 ); // trim blanks on the right
i = 0;
while ( i< s.length && s.charAt(i) == ' ') i++;
return s.substring( i );
}

function CheckBuy(lCheck)
{
	var strCheck;
	if (lCheck == 0) 
		strCheck = "";
	else if (lCheck == 1)
		strCheck = "You must type or search a Fund Symbol!";
	else if (lCheck ==2)
		strCheck = "You must type Amount of Dollars!";
	else if (lCheck == 3)
		strCheck = "You must type Amount of Shares!";
	else if (lCheck == 5)
		strCheck = "You must choose a Fund Account first!";
	else if (lCheck == 4)
		strCheck = "You must type Date of Order\nIt must be less than current date!";
	else if (lCheck == 7)
		strCheck = "Invalid Date!\nYou must type date with format (mm/dd/yyyy)!";
	else if (lCheck == 6)
		strCheck = "Date of Order must be less than current date!";
	return strCheck;
}

function CheckKYC(lCheck)
{
	var strCheck;
	if (lCheck == 0) 
		strCheck = "";
	else if (lCheck == 1)
		strCheck = "Annual Income field must have numeric value!";
	else if (lCheck ==2)
		strCheck = "Household Income field must have numeric value!";
	else if (lCheck == 3)
		strCheck = "Net Worth field must have numeric value!";
	else
		strCheck = "Liability field must have numeric value!";

	return strCheck;
}
//-----------------------------
function	NextList(_Page)
{
	if (_Page=="Goto")
	{
		x	=	parseInt(document.form1.AbsolutePage.value);
		if (isNaN(x))
		{
			alert("Please enter a numeric value");
			document.form1.AbsolutePage.select();
			return;
		}
		else
		{
			document.form1.AbsolutePage.value=x;
		}
	}
	else
	{
		document.form1.AbsolutePage.value	=	_Page;
	}
//	document.frmSelectPage.hidOrderType.value	=	"GotoPage";
	//document.document.form1.action	=	manager_file;
	document.form1.submit();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function getSelected(value){
	if(value=='3') {
		this.sltLanguage.selectedIndex = 0;
	}

	if(value=='1') {
		this.sltLanguage.selectedIndex = 1;
	}
	
	if(value=='2') {
			this.sltLanguage.selectedIndex =2;
	}
}
function checkAll(_theForm) {
	for (i = 0; i < eval(_theForm).chkSelect.length; i++) {
	eval(_theForm).chkSelect[i].checked = true;}
}
function UncheckAll(_theForm) {
	for (i = 0; i < eval(_theForm).chkSelect.length; i++) {
	eval(_theForm).chkSelect[i].checked = false;}
}


function submitForm(thisForm, _Page, _Type)
{
		var cool = eval(thisForm).elements;
		var i, ntotal=0
		var sID = '';
		var sTID = '0';
		var sPID = '0';
		var sAction = '';
		var ssArr;
		var srtTemp;
		sID = '0';
		if (cool != null) {
			for (i = 0; i < cool.length; i++) {
					switch (cool.elements(i).type) {
						case 'checkbox' :
						{
							if (cool.elements(i).name == "chkSelect"  && cool.elements(i).checked)
							{
								ntotal +=  1;
								if (_Type == 'A')
								{
									srtTemp = cool.elements(i).value;
									ssArr = srtTemp.split("$###$");
									if (typeof(ssArr[0]) != 'undifined')
									if (ssArr[0] == 'P')
										sPID = sPID + ',' + ssArr[1];
									else
										sTID = sTID + ',' + ssArr[1];
									
								}
								else
								{
								if (sID == '' && cool.elements(i).value != '')
									sID = cool.elements(i).value;
								else
									sID = sID + ','	+ cool.elements(i).value;
								}
							}
						}
					}
			}

		}
			
		if (_Type == 't')
			sAction = _Page + '/t/' + sID + '/p/0';				
		
		if (_Type == 'A')
			sAction = _Page + '/t/' + sTID + '/p/'+ sPID ;				
			
		if (_Type == 'p')
			sAction = _Page + '/t/0/p/'+ sID;				
		
		if (_Type == 'd')
			sAction = _Page + '/d/'+ sID;		
			
		
		//thisForm.hidListID.value = sID;
		eval(thisForm).action = sAction //; _Page + '?lid='+ sID + '&type='+_Type;
		eval(thisForm).submit();
		
}

//===================================================
function MM_jumpMenu_Admin(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}	

function getSelected(value){
	if(value=='3') {
		this.sltLanguage.selectedIndex = 1;
	}

	if(value=='1') {
		this.sltLanguage.selectedIndex = 0;
	}
	
	if(value=='2') {
			this.sltLanguage.selectedIndex =2;
	}
}

function validNumber(ss){
		var passw = ss;
		var ValidChars = '0123456789.';
		var IsNumber=true;
		var Char='';
		
		for (i = 0; passw.length > i && IsNumber == true; i++) 
		{ 
		Char = passw.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
		IsNumber = false;
		}
		}
		
		if (IsNumber)
		{ 
		return (1);
		}
		else
		{
		return (0);
		}
	}

//code by sinhnv
function postSelected(_theForm,_Action,_ActionFile,_Lang) 
	{
	//alert('sd sds');
		if (typeof(eval(_theForm).chkSelect) == "undefined") return;
		var strId;
		var strTemp;
		strId = '0,';
		for (i = 0; i < eval(_theForm).chkSelect.length; i++) 
		{			
			if(eval(_theForm).chkSelect[i].checked == true) 
			{
				strTemp = eval(_theForm).chkSelect[i].value;
				strId = strId + strTemp + ',';
			}
		}
		strId = strId + '0'
		if(_Action=='Post')
			{
			eval(_theForm).action = _ActionFile + '?mode=Post&IdList=' + strId + '&lang=' + _Lang;
			}
		else if(_Action=='UnPost')
			{
			eval(_theForm).action = _ActionFile + '?mode=UnPost&IdList=' + strId + '&lang=' + _Lang;
			}
		else
			{
			if(!confirm('Ban co muon xoa cac muc da duoc chon khong?'))  return;
			eval(_theForm).action = _ActionFile + '?mode=DeleteSelected&IdList=' + strId + '&lang=' + _Lang;
			}
		eval(_theForm).submit();
	}