function tvsNotCompletedMessage(){
	alert('TuVinh Soft said: This function will be completed soon!');
}

function sendWithAction( FormName, sAction ){
	if(document.forms[FormName]){
		document.forms[FormName].action = sAction;
		document.forms[FormName].submit();
	}	
	if(document.FormName){
		document.FormName.action = sAction;	
		document.FormName.submit();
	}	

}

function sendWithAtion( FormName, sAction ){
	if(document.forms[FormName]){
		document.forms[FormName].action = sAction;
		document.forms[FormName].submit();
	}	

	if(document.FormName){
		document.FormName.action = sAction;	
		document.FormName.submit();
	}

}

function send(FormName){
	if(document.forms[FormName]){
		document.forms[FormName].submit();
	}	
	if(document.FormName){
		document.FormName.submit();
	}
}

function sendID(id){
	if(document.getElementById(id)){
		document.getElementById(id).submit();
	}
}

function print(sMsg,sID){
	try{
		document.getElementById(sID).innerHTML=sMsg;
	}
	catch(e){
		try{
			document.sID.innerHTML=sMsg;
		}
		catch(e){
			try{
				document.all.sID.innerHTML=sMsg;
			}
			catch(e){
				alert(sMsg);
			}
		}
	}
}
	
function validateNumeric(Num){
	er=new RegExp("^[0-9]+$");
	return er.test(Num);
}

function validateDate(day,month,year){
	date=new Date();
	yearNow=1900+date.getYear();
	if(year==''||month==''||day==''){
		return false;
	}
	if(isNumber(year)||isNumber(month)||isNumber(day)){
		return false;
	}
	if(month<1||month>12){
		return false;
	}if(year>yearNow){
		return false;
	}
	
	var dayInFebruary=checkLeapYear(year)?29:28;
	var daysInMonth=new Array('Days',31,dayInFebruary,31,30,31,30,31,31,30,31,30,31);
	if(month<10&&month.length==2)month=month.substring(1);
	if(day>0&&day<=daysInMonth[month]){
		return true;
	}else{
		return false;
	}
}

function checkLeapYear(year){
	return(((year%4==0)&&((!(year%100==0))||(year%400==0)))?true:false);
}
function validateEmail(email){
	er=new RegExp("^([A-Za-z0-9.-_-]+)@[A-Za-z0-9-_]+(\.[A-Za-z0-9]+)?\.([A-Za-z]){2,4}$");
	return er.test(email);
}

function OpenWindow(URL,title,features,width,height,isCenter){
	var left=0;
	var top=0;
	if((window.screen)&&isCenter){
		var left=(window.screen.width/2)-(width/2);
		var top=(window.screen.height/2)-(height/2);
	}
	features+=(features!='')?',':'';
	features+='left='+left+',top='+top+',width='+width+',height='+height;
	window.open(URL,title,features);
}

function removeChar(characters,text){
	var ntext='';
	if(characters.length>0){
		for(i=0;i<text.length;i++){
			exist=false;
			for(j=0;j<characters.length;j++){
				if(text.charAt(i)==characters[j]){
					exist=true;
					break;
				}
			}
			if(!exist){
				ntext+=text.charAt(i);
			}
		}
		return ntext;
	}else{
		return text;
	}
}

function addClass(sID,sClassName){
	var oID=document.getElementById(sID);
	if(oID.className===''){
		oID.className=sClassName;
	}else{
		oID.className=oID.className+', '+sClassName;
	}
}

function removeClass(sID,sClassName){
	var oID=document.getElementById(sID);
	var aClass=oID.className.split(', ');
	oID.className='';
	for(i=0;i<=aClass.length;i++){
		if(!(aClass[i]===sClassName)&&typeof(aClass[i])!='undefined'){
			addClass(sID,aClass[i]);
		}
	}
}

function select(){
	fields=document.getElementsByTagName('input');
	for(i=0;i<fields.length;i++){
		if(fields[i].type=='checkbox'){
			if(fields[i].checked==false){
				selectAll();
				return;
			}
		}
	}
	unselectAll();
}

function selectAll(){
	fields=document.getElementsByTagName('input');
	for(i=0;i<fields.length;i++){
		if(fields[i].type=='checkbox'){
			fields[i].checked=true;
		}
	}
	fields=document.getElementsByTagName('tr');
	for(i=0;i<fields.length;i++){
		if(fields[i].id.charAt(0)==='t'&&fields[i].id.charAt(1)==='r')addClass(fields[i].id,'highlight3');
	}
}

function unselectAll(){
	fields=document.getElementsByTagName('input');
	for(i=0;i<fields.length;i++){
		if(fields[i].type=='checkbox'){
			fields[i].checked=false;
		}
	}
	fields=document.getElementsByTagName('tr');
	for(j=0;j<fields.length;j++){
		if(fields[j].id.charAt(0)==='t'&&fields[j].id.charAt(1)==='r')removeClass(fields[j].id,'highlight3');
	}
}

function mountMessages(sMsgs){
	aMsgs=sMsgs.split('||');
	aNewMsgs=Array();
	for(i=0;i<aMsgs.length;i++){
		aAux=aMsgs[i].split(':++:');
		aNewMsgs[aAux[0]]=aAux[1];
	}
	return aNewMsgs;
}

function getElement(sId,bUseOpener){
	if(bUseOpener){
		if(document.getElementById){
			return window.opener.document.getElementById(sId);
		}else{
			if(document.layers){
				return window.opener.document.sId;
			}else{
				return window.opener.document.all.sId;
			}
		}
	}else{
		if(document.getElementById){
			return document.getElementById(sId);
		}else{
			if(document.layers){
				return document.sId;
			}else{
				return document.all.sId;
			}
		}
	}
}

/*
aCheck[] = array[field_id, minimum_length, maximum_length, IsNumber, Is_show_message_follow_template]
*/

function validateFields(aCheck){
	for(i=0;i<aCheck.length;i++){
		if((document.getElementById(aCheck[i][0]))){
			var obj=document.getElementById(aCheck[i][0]).value;
			var size=obj.length;

			if(aCheck[i][1]==0&&aCheck[i][2]==0&&obj===''){
				if(aCheck[i][5]){
					print('Field '+aCheck[i][3]+' cannot be blank','msgs','att');
					scrollToByElement('msgs');
				}else{
					print(aCheck[i][3],'msgs','att');
						scrollToByElement('msgs');
				}
				return false;
			}
			else if(aCheck[i][4]&&isNumber(obj)){
				if(aCheck[i][5]){
					print('Field '+aCheck[i][3]+' must Accountin only number.','msgs','att');
					scrollToByElement('msgs');
				}else{
					print(aCheck[i][3],'msgs','att');
					scrollToByElement('msgs');
				}
				return false;
			}else if(aCheck[i][1]>0&&aCheck[i][2]&&(size<aCheck[i][1]||size>aCheck[i][2])){
				if(aCheck[i][5]){
					print('Field '+aCheck[i][3]+' must Accountin value in maximum '+aCheck[i][2]+' and minimum '+aCheck[i][1]+' characters.','msgs','att');
					scrollToByElement('msgs');
				}else{
					print(aCheck[i][3],'msgs','att');
					scrollToByElement('msgs');
				}
				return false;
			}
		}
	}
	return true;
}

function print(sMsg,sID,sClass){
	try{
		document.getElementById(sID).innerHTML=sMsg;
		if(sClass)addClass(sID,sClass)
	}
	catch(e){
		try{document.sID.innerHTML=sMsg;
		if(sClass)addClass(sID,sClass)
		}
		catch(e){
			try{
				document.all.sID.innerHTML=sMsg;
				if(sClass)addClass(sID,sClass)
			}
			catch(e){
				alert(sMsg);
			}
		}
	}
}

function addClass(sID,sClassName){
	if(document.getElementById){
		oID=document.getElementById(sID);
	}else{
		if(document.layers){
			oID=document.sID;
		}else{
			oID=document.all.sID;
		}
	}
	if(oID.className===''){
		oID.className=sClassName;
	}else{
		oID.className=oID.className+' '+sClassName;
	}
}

function removeClass(sID,sClassName){
	if(document.getElementById){
		oID=document.getElementById(sID);
	}else{
		if(document.layers){
			oID=document.sID;
		}else{
			oID=document.all.sID;
		}
	}
	
	var aClass=oID.className.split(' ');
	oID.className='';
	for(i=0;i<=aClass.length;i++){
		if(!(aClass[i]===sClassName)&&typeof(aClass[i])!='undefined'){
			addClass(sID,aClass[i]);
		}
	}
}

function checkByID(sID,sTRID){
	if(document.getElementById){
		oID=document.getElementById(sID);
	}else{
		if(document.layers){
			oID=document.sID;
		}else{
			oID=document.all.sID;
		}
	}
	if(oID.checked===true){
		oID.checked=false;
		removeClass(sTRID,'highlight3');
	}else{
		oID.checked=true;
		addClass(sTRID,'highlight3');
	}
}


function countChars(eFrom,iIdTo){
	var countFrom=eFrom;
	var printIn=getElement(iIdTo);
	printIn.value=countFrom.value.length;
}

function openURLOpener(sURL,bClose){
	window.opener.location.href=sURL;
	if(bClose==true){
		window.close();
	}
}


function protegerEmail(dominio,extensao,usuario){
	document.write("<a href="+"mail"+"to:"+usuario+"@"+dominio+extensao+">"+usuario+"@"+dominio+extensao+"</a>");
}


function scrollToByElement(sID){
	if ( !getElement(sID) ) return;
	var eOBJ=getElement(sID);
	var iWidth=encontrarPosX(eOBJ);
	var iHeight=encontrarPosY(eOBJ);
	window.scrollTo(iWidth,iHeight);
}

function encontrarPosY(eOBJ){
	var iPosTop=0;
	if(eOBJ.offsetParent){
		while(eOBJ.offsetParent){
			iPosTop+=eOBJ.offsetTop;
			eOBJ=eOBJ.offsetParent;
		}
	}else if(eOBJ.y){
		iPosTop+=eOBJ.y;
	}
	return iPosTop;
}

function encontrarPosX(eOBJ){
	var iPosLeft=0;
	if(eOBJ.offsetParent){
		while(eOBJ.offsetParent){
			iPosLeft+=eOBJ.offsetLeft;
			eOBJ=eOBJ.offsetParent;
		}
	}else if(eOBJ.x){
		iPosLeft+=eOBJ.x;
	}
	return iPosLeft;
}

/*
   function: hide
      Hide an Element

   parameters:

      id - ID of Element
*/
function hide(id) {
    if (document.getElementById) // DOM3 = IE5, NS6
    {
        document.getElementById(id).style.display = 'none';
        document.getElementById(id).style.visibility = 'hidden';
    }
    else 
    {
        if (document.layers) // Netscape 4
        {
            document.id.display = 'none';
            document.id.visibility = 'hidden';
        }
        else // IE 4
        { 
            document.all.hideshow.style.display = 'none';
            document.all.hideshow.style.visibility = 'hidden';
        }
    }
}

/*
   function: show
      Show an Element

   parameters:

      id - ID of Element
      sDisplayProp - Type of display that allows modify. Block, table, table-row
*/

function show(id, sDisplayProp ) 
{
    if ( typeof( sDisplayProp ) == "undefined" )
        sDisplayProp = 'block';

    if (document.getElementById) // DOM3 = IE5, NS6
    {
        try { 
            document.getElementById(id).style.display = sDisplayProp;
            document.getElementById(id).style.visibility = 'visible';
        }
        catch(e)
        { // current tables has problems with IE
            document.getElementById(id).style.display = 'block';
            document.getElementById(id).style.visibility = 'visible';
        }
    }
    else
    {
        if (document.layers) // Netscape 4
        {
            document.id.display = sDisplayProp;
            document.id.visibility = 'visible';
        }
        else // IE 4
        {
            document.all.id.style.display = sDisplayProp;
            document.all.id.style.visibility = 'visible';
        }
    }
}

/*
function: showhide
    Similar Hide with accordancing a div
    
parameters:

      id - ID of Element
      sDisplayProp - Type of display that allows modify. Block, table, table-row
*/
function showhide( id, sDisplayProp )
{
    if (document.getElementById) // DOM3 = IE5, NS6
    {
        if ( document.getElementById(id).style.display == 'none' )
            show( id, sDisplayProp );
        else
            hide( id );
    }
    else
    {
        if (document.layers) // Netscape 4
        {
            if ( document.id.display == 'none' )
                show( id, sDisplayProp );
            else
                hide( id );
        }
        else // IE 4
        {
            if ( document.all.id.style.display == 'none' )
                show( id, sDisplayProp );
            else
                hide( id );
        }
    }
}

/*
    function: setFocus
       Set focus

    parameters:

       string:

       FormName - 
       FieldName - 
*/
function setFocus( sFormName, sFieldName )
{
    if (document.forms[sFormName])
    {
    document.forms[sFormName][sFieldName].focus();
    }
    else if (document.sFormName)
    {
    document.sFormName.sFieldName.focus();
    }
}

function inspect(elm){
  var str = "";
  for (var i in elm){
    str += i + ": " + elm.getAttribute(i) + "\n";
  }
  alert(str);
}

// Source: http://www.mikezilla.com/exp0015.html

function addZero(vNumber){ 
    return ((vNumber < 10) ? "0" : "") + vNumber 
} 

function formatDate(vDate, vFormat){ 
    var vDay              = addZero(vDate.getDate()); 
    var vMonth            = addZero(vDate.getMonth()+1); 
    var vYearLong         = addZero(vDate.getFullYear()); 
    var vYearShort        = addZero(vDate.getFullYear().toString().substring(3,4)); 
    var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
    var vHour             = addZero(vDate.getHours()); 
    var vMinute           = addZero(vDate.getMinutes()); 
    var vSecond           = addZero(vDate.getSeconds()); 
    var vDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
    vDateString           = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 
    return vDateString 
} 

/*
function: PageCatchingQuery
    Return result or definative variable of a query
    
parameters:

    sVariable - 
    
returns:
        
        mixed
*/
function PageCatchingQuery( sVariable ) {
  var sEndereco = window.location.search.substring(1);
  aVars = sEndereco.split( '&' );
  
  if ( typeof( sVariable ) == 'undefined' ) 
    return aVars;
  
  for (var i=0;i<aVars.length;i++) 
  {
    var sPar = aVars[i].split("=");
    
    if ( sPar[0] == sVariable ) {
      return sPar[1];
    }
  } 
  
  return false;
}

function stripSpaces(x) {
    while (x.substring(0,1) == ' ') x = x.substring(1);
    return x;
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else
  {
    return document.getElementById(movieName);
  }
}

function GotoFrameFlashMovie(FrameNumber)
{
    var flashMovie=getFlashMovieObject("alerts");
    flashMovie.GotoFrame(FrameNumber);
}

function tocarSom( cNada, sTipo )
{
    if ( sTipo == 'som' )
    {
        GotoFrameFlashMovie(2);
    }
    else
    {
        GotoFrameFlashMovie(1);
    }
}

// Source: http://www.codebrain.com/javascript/kits/index.html
function tocarSomJS( doWhat, toWhat )
{
    var A = eval('document.'+toWhat);

    if (A != null)
    {
        if (doWhat=='stop')
        {
            A.stop();
        }
        else
        {
            if (navigator.appName == 'Netscape')
            {
                A.play();
            }
            else
            {
                if (document.M == null)
                {
                    document.M = false; 
                    var m;
                    for(m in A)
                    {
                        if (m == "ActiveMovie")
                        {
                            document.M = true; 
                            break;
                        }
                    }
                }
                
                if (document.M)
                {
                    A.SelectionStart = 0;
                }
                
                if (document.M) 
                {
                    A.play();
                }
            }
        }
    }
}

function trimAll(sString)
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}