/**************************************************************
	Genneral Config
***************************************************************/
var IE = (document.all) ? 1 : 0;
var NS = (document.layers) ? 1 : 0;
var preloadFlag = false;

if (document.all != null) 
    IE = 1
else if ((document.layers != null) || (document.getElementById))
    NS = 1

/**************************************************************
 LTrim: Returns a String containing a copy of a specified 
        string without leading spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without both leading and trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}

function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}

/**************************************************************
 Left: Returns a String containing a specified number of 
       characters from the left side of a string.

 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 

 Returns: String
***************************************************************/
function Left(String, Length)
{
	if (String == null)
		return (false);

	return String.substr(0, Length);
}

/**************************************************************
 Right: Returns a String containing a specified number of 
        characters from the right side of a string.

 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 

 Returns: String
***************************************************************/
function Right(String, Length)
{
	if (String == null)
		return (false);

    var dest = '';
    for (var i = (String.length - 1); i >= 0; i--)
		dest = dest + String.charAt(i);

	String = dest;
	String = String.substr(0, Length);
	dest = '';

    for (var i = (String.length - 1); i >= 0; i--)
		dest = dest + String.charAt(i);

	return dest;
}
/**************************************************************
 InStr: Returns a Long specifying the position of the first 
        occurrence of one string within another. Is String1
        or String2 are null, false is returned.

 Parameters:
      String1 = String expression being searched.
      String2 = String expression sought

 Returns: Integer
***************************************************************/

function InStr(String1, String2)
{
	var a = 0;

	if (String1 == null || String2 == null)
		return (false);

	String1 = String1.toLowerCase();
	String2 = String2.toLowerCase();

	a = String1.indexOf(String2);
	if (a == -1)
		return 0;
	else
		return a + 1;
}

/**************************************************************
 IsDate: Returns a Boolean (true) if the date is true, false
         is not

 Parameters:
	- DateStr: String date in format (MM/DD/YYYY)

 Returns: Boolean
***************************************************************/
function IsDate(dateStr)
{
	// Checks for the following valid date formats:
	// MM/DD/YYYY   MM-DD-YYYY

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat)
	if (matchArray == null)
		return false

	month = matchArray[1]
	day = matchArray[3]
	year = matchArray[4]
	if (month < 1 || month > 12)
		return false

	if (day < 1 || day > 31)
		return false

	if ((month==4 || month==6 || month==9 || month==11) && day==31)
		return false

	if (month == 2)
	{
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
		if (day>29 || (day==29 && !isleap))
			return false;
	}
	return true;
}


/*******************************************************
	- Ham SelectRow dung de chon mot dong tu Hop danh sach (Option) nay chuyen sang Opt khac
	- Dau vao: ten cua Opt nguon ([ten form].[ten opt]) va ten cua Opt dich (optDName - Option Destination Name)
	- Dau ra: phan tu duoc chon ben Opt nguon se duoc chuyen (Move) sang Opt dich
********************************************************/
	function SelectData(optSName,optDName){
		var ok=true;
		var optDNameLen = optDName.options.length;
		var optSNameLen = optSName.options.length;

		if(optSNameLen > 0){
		//Neu chon thi moi lam
		if(optSName.options[optSName.selectedIndex].value != "" && optSName.options[optSName.selectedIndex].value != "-1" ){
		// Neu danh sach dich rong thi them 1
			if(optDNameLen==0){
					optDName.options.length = 1;
					optDName.options[0].value=optSName.options[optSName.selectedIndex].value;
					optDName.options[0].text=optSName.options[optSName.selectedIndex].text;			
		// Neu danh sach dich da co them them vao cuoi
			}else{
		/// Kiem tra xem da ton tai chua
				for(index=0;index<optDNameLen;index++){
					if(optDName.options[index].value==optSName.options[optSName.selectedIndex].value){
						ok=false
						break;
					}else{
						ok=true
					}
				}
		// Neu chua ton tai thi them vao (flag=true)
				if(ok){
					optDName.options.length = optDName.options.length + 1;
					optDName.options[optDName.options.length - 1].value=optSName.options[optSName.selectedIndex].value;
					optDName.options[optDName.options.length - 1].text=optSName.options[optSName.selectedIndex].text;					
				}
			}
		}
		optSName.remove(optSName.selectedIndex)
		}		
	}

// WINDOW STATUS
window.defaultStatus = "";
function winStatus( msg ){
	window.status = msg;
	return true;
}
function setAction(value){
	try{
		document.forms(0).Action.value = value;
		return true;
	}catch(e){}
	return false;
}
// ------------------------------------------
function MyOpenWindow(parURL, parheight, parwidth, target){
	try{
		var tempConfig= 'toolbar=no, ';
	    tempConfig+= 'minimize=no, ';
		tempConfig+= 'maximize=no, ';
		tempConfig+= 'menubar=no, ';
	    tempConfig+= 'scrollbars=yes, ';
		tempConfig+= 'resizable=no, ';
	    tempConfig+= 'location=no, ';
		tempConfig+= 'status=no, ';
		tempConfig+= 'directories=no, ';
		
		if((parwidth != null)&&(parwidth!=0)){
		tempConfig += 'width='+ parwidth +', ';		
		}else{tempConfig += 'width='+ (screen.availWidth -10) +', ';}


		if((parheight != null)&&(parheight!=0)){
		tempConfig += 'height='+ parheight +', ';		
		}else{tempConfig += 'height='+ (screen.availHeight-30) +', ';}		

		if(target == null){
		    var dt = new Date()
		    var num = dt.getTime()
			target ="VRwindow" + num.toString();
		}
		
		tempConfig += 'left=0, ';
		tempConfig += 'top=0, ';

		var tempWindow = window.open(parURL, target, config = tempConfig);
		tempWindow.opener = window;
	}catch(e){}
}

function MyshowModalDialog(parURL, parheight, parwidth, target){
	try{
		var tempConfig = 'scroll:yes; ';
    	//Resizable
		tempConfig += 'resizable:no; ';
		
		tempConfig += 'moveable:no; ';
    	//Address Bar
	    tempConfig += 'help:no; ';

		tempConfig += 'status:no; ';
		// Minimize, Maximize
	  //  tempConfig += 'minimize=no, ';
	//	tempConfig += 'maximize=no, ';
		
		//edge:{ sunken | raised }
		tempConfig += 'center:yes; ';
		
		if(parwidth != null){
		tempConfig += 'dialogWidth:'+ parwidth +'; ';		
		}//else{tempConfig += 'dialogWidth:'+ (screen.availWidth -10) +'; ';}

		if(target == null){
		target="VRwindow";}	

		if(parheight != null){
		tempConfig += 'dialogHeight:'+ parheight +'; ';		
		}//else{tempConfig += 'dialogHeight:'+ (screen.availHeight-30) +'; ';}		

		tempConfig += 'dialogLeft:0; ';
		tempConfig += 'dialogTop:0;';
		var tempWindow = window.showModalDialog(parURL, target, config = tempConfig);
		tempWindow.opener = window;

		//showModalDialog("xong.htm", window, "resizable: no; help: no; status: no; scroll: no; center: yes; dialogHeight:10; dialogWidth:30; ");

	}catch(e){}
}
//---------------------- TV -------------------------
function VRToggleDisplay(oButton, oItems) {

	if ((oItems.style.display == "") || (oItems.style.display == "none")) {
		oItems.style.display = "block";
		oButton.src = "../Images/TVIcons/minus.gif";
	}	else {
		oItems.style.display = "none";
		oButton.src = "../Images/TVIcons/plus.gif";
	}

	return false;

}

function VRHideDisplay(oItems) {

	oItems.style.display = "none";

}

function VRShowDisplay(oItems) {

	oItems.style.display = "block";

}

// ---------------
	function VRFstrReverse(strTemp){
		var strRe = "";
		strRe = Right(strTemp,1);
		strTemp = Left(strTemp,strTemp.length-1);
				
		while(strTemp.length>0){
			strRe = strRe + Right(strTemp,1);
			strTemp = Left(strTemp,strTemp.length-1);
		}
		VRFstrReverse = strRe;
		return VRFstrReverse;
	}		