/*
var ctlPrefix="";
function app_reload(){
	parent.frames[1].location.replace("left_nav.aspx");
	parent.frames[2].location.replace("main_body.aspx");
	parent.frames[4].location.replace("footer.aspx");
}

function getControl(strName){
	return document.frmContact[ctlPrefix + strName];
}

function readOnlyAlert(control){
	alert("B?n không th? s?a giá tr? trong textbox này!\n\nGiá tr? này s? ???c t? ??ng tính toán d?a vào\ncác giá tr? ?ă nh?p trong các textbox khác");
	control.blur();
}
	
function expandTextNode(index){
	
	var panelObj=eval(index);

	if(panelObj.style.display=="none"){
		panelObj.style.display="block";
	}
	else{
		panelObj.style.display="none";
	}
}
*/
function replaceStr(strSrc, strSearch, strReplace){
	var startIndex=strSrc.lastIndexOf(strSearch);
	var endIndex=strSrc.lastIndexOf(".");
	var endStr=strSrc.substring(endIndex);
	
	var strResult=strSrc.substring(0, startIndex) + strReplace + endStr;
	return strResult;				
}

function checkData(){
//					alert("Some data has not been saved!\nAre you sure to navigate away");
	return true;
}

function openCalendar(strTxtID){
	var w, h, left, top, setting;
	w=200;
	h=210;
			
	left=(screen.width - w)/2;
	top=(screen.height - h)/2;
		
	setting = "width=" + w + ",height=" + h + ", scrollbars=no, toolbar=no,titlebar=no," 
				+ "dependent=no, menubar=no,location=no,status=no, "		
				+ "top=" + top + ", left=" + left + "'";
	
	cal=window.open("calendar.aspx?txtID=" + strTxtID,"",setting);

	
}

function openCalendarClock(strTxtID){
	var w, h, left, top, setting;
	w=200;
	h=250;
			
	left=(screen.width - w)/2;
	top=(screen.height - h)/2;
		
	setting = "width=" + w + ",height=" + h + ", scrollbars=no, toolbar=no,titlebar=no," 
				+ "dependent=no, menubar=no,location=no,status=no, "		
				+ "top=" + top + ", left=" + left + "'";
	
	cal=window.open("../calendar_clock.aspx?txtID=" + strTxtID,"",setting);

	
}

function showPopup(strURL, w, h){
	var left, top, setting;
			
	left=(screen.width - w)/2;
	top=(screen.height - h)/2;
		
	setting = "width=" + w + ",height=" + h + ", scrollbars=no, toolbar=no,titlebar=no," 
				+ "dependent=yes, menubar=no,location=no,status=yes, directories=0, "		
				+ "top=" + top + ", left=" + left + "'";
	
	popupWin=window.open(strURL,"",setting);

}				


function checkFrame(){
	if(self==parent){
		document.location="";
	}
}

function actionConfirm(msg){
	if(confirm(msg)){
		return true;			
	}else{
		return false;
	}
}
//Exam type objects goes here
function examTypeItem(examTypeID, priceVn, priceEn){
	this.examTypeID=examTypeID;
	this.priceVn=priceVn;
	this.priceEn=priceEn;
	
	this.getExamTypeID=getExamTypeID;
	this.getPriceVn=getPriceVn;
	this.getPriceEn=getPriceEn;
	
}

function getExamTypeID(){
	return this.examTypeID;
}

function getPriceVn(){
	return this.priceVn;
}

function getPriceEn(){
	return this.priceEn;
}

//End exam type object

//Employee object goes here
function employeeItem(employeeID, roomID, employeeName){
	this.employeeID=employeeID;
	this.roomID=roomID;
	this.employeeName=employeeName;
	
	this.getEmployeeID=getEmployeeID;
	this.getRoomID=getRoomID;
	this.getEmployeeName=getEmployeeName;
	
}

function getEmployeeID(){
	return this.employeeID;
}

function getRoomID(){
	return this.roomID;
}
function getEmployeeName(){
	return this.employeeName;
}
//End Employee object here


//Image List object here
function ImageItem(fullFileName, shortFileName){
	this.fullFileName=fullFileName;
	this.shortFileName=shortFileName;
	
	this.getFullFileName=getFullFileName;
	this.getShortFileName=getShortFileName;
}

function getFullFileName(){
	return this.fullFileName;
}

function getShortFileName(){
	return this.shortFileName;
}

//End image list object here

function checkTextBox(txtName, msg){
	var txt=getControl(txtName);
	if(txt.value==""){
		alert(msg);
		txt.focus();
		return false;
	}
	else{
		return true;
	}
}

//End Employee object here

function toUSCurrency (input)
{
	// Make sure input is a string:
	input += "";

	// Keep original copy of input string:
	var original_input = input;

	// Strip leading dollar sign if necessary:
	if (input . charAt (0) == "$")
		input = input . substring (1, input . length);
	else if
	(
		input . substring (0, 2) == "-$"
	||	input . substring (0, 2) == "+$"
	)
		input = input . charAt (0) + input . substring (2, input . length);

	// Get float value:
	var amount = parseFloat (input);

	// Return unmodified input if we weren't able to convert it:
	if (isNaN (amount))
		return original_input;


	// Express amount in pennies, rounded to the nearest penny:
	amount = Math . round (100 * amount);

	// Prepare to add a US currency prefix:
	var prefix = "";
	if (amount < 0)
	{
		prefix = "-" + prefix;
		amount = - amount;
	}

	// Convert amount to string and pad with leading zeros if necessary:
	var string;
	if (amount < 10)
		string = "00" + amount;
	else if (amount < 100)
		string = "0" + amount;
	else
		string = "" + amount;

	// Insert prefix:
	string = prefix + string;

	// Insert decimal point before last two digits:
	string =
		string . substring (0, string . length - 2) +
		"." +
		string . substring (string . length - 2, string . length);


	
	string=string.substring(0, string.length-6) + "," + string.substring(string.length-6, string.length);

	var len=string.length-4;
	var step=3;
	
	var divCount=Math.floor(len/step);
	var remainVal=len/step - divCount;
	if(remainVal==0){
		divCount=divCount-1;
	}
//	alert("len=" + len + ", step=" + step + ",money=" + string + ", div=" + divCount + ", remain=" + remainVal);
	
	// Return formatted currency string:	
	return string;
}

function isNumeric(objName,minval,maxval,comma,period,hyphen){
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
	var checkOK = "0123456789" + comma + period + hyphen;
	var checkStr = objName;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";

	for (i = 0;  i < checkStr.value.length;  i++){
		ch = checkStr.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j)) break;
			
		if (j == checkOK.length){
			allValid = false;
			break;
		}
		
		if (ch != ",") allNum += ch;
	}
	
	if (!allValid){	
		alertsay = "Xin nh?p các ch? s? trong ph?m vi sau \""
		alertsay = alertsay + checkOK + "\" vào textbox này!\n\nHo?c nh?n Ctrl+Z ?? ph?c h?i giá tr? c?"
		alert(alertsay);
		return (false);
	}

	// set the minimum and maximum
	var chkVal = allNum;
	
	var prsVal = parseInt(allNum);
	
	if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval)){
		alertsay = "Xin hăy nh?p giá tr? l?n h?n ho?c "
		alertsay = alertsay + "b?ng v?i \"" + minval + "\" và nh? h?n ho?c "
		alertsay = alertsay + "b?ng v?i \"" + maxval + "\" vào textbox này!"
		alert(alertsay);
		return (false);
	}
}

function checkTextBoxIsNumeric(txtTextBox){
	if(txtTextBox.value=="0.00" || txtTextBox.value=="0" || txtTextBox.value=="0."  || txtTextBox.value==".0" || txtTextBox.value=="" || txtTextBox.value=="." || txtTextBox.value==","){
		txtTextBox.value="0.00";
	}			
	return checkNumeric(txtTextBox, 0, 1000000000, ",", ".", "");

}
function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (isNumeric(objName,minval,maxval,",",".","") == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

//prevent Enter key
function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else{
		return true;
	}
}      

function setDefaultFocus(form){
	var element, strElement="";
	
	if(form.elements.length>0){
		for(i=0;i<form.elements.length;i++){
			element=form.elements[i];
				strElement+=element.name + '\n';

		}
		alert(strElement);
	}
}


//end prevent enter key
//allow Enter key to submit
function enterSubmit (field, nextElementID, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		field.form[nextElementID].click();
//		field.form[nextElementID].disabled=true;		
		return false;
	} 
	else{
		return true;
	}
}      

/*
Submit Once form validation- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
	for (i=0;i<theform.length;i++){
		var tempobj=theform.elements[i]
		if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
		//disable em
			tempobj.disabled=true
		}
	}
}

//end prevent enter key
//hightlight form element here
var highlightcolor="lightyellow"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
	if (which.style&&intended.test(which.tagName)){
		if (ns6&&eventobj.nodeType==3){
			eventobj=eventobj.parentNode.parentNode
		}
		return true
	}
	else{
		return false
	}
}


function highlight(e){
	eventobj=ns6? e.target : event.srcElement
	if (previous!=''){
	if (checkel(previous))
	previous.style.backgroundColor=''
	previous=eventobj
	if (checkel(eventobj))
	eventobj.style.backgroundColor=highlightcolor
	}
	else{
	if (checkel(eventobj))
	eventobj.style.backgroundColor=highlightcolor
	previous=eventobj
	}
}

function modelesswin(url,mwidth,mheight){
	if (document.all&&window.print){ //if ie5
		eval('window.showModelessDialog(url,"","help:0;resizable:0;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")');
	}		
	else{
		eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")');
	}
}

// check email
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->







