//Hien cua so
//*************************************************************************************
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function domain() { window.open("support/domain/domain.dll","Chuy","menubar=no,scrollbars=no,resizable=no,width=400,height=300");}
//*************************************************************************************

//Khong cho phep chon, to tren trang
//*************************************************************************************
/*
function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
*/
//*************************************************************************************


//Kiem tra form hop le
//*************************************************************************************
global_state = new Array('','');
global_val_message = " ('+' Hop lê, '-' không hop lê, '!' không hop lê hoac không có thông tin.) "; 
val_err_message = "This field can't be validated dynamically !"; 
curForm = null;

isNetscape475 = ( (navigator.appName.toUpperCase()=="NETSCAPE")&&(navigator.appVersion.substring(0,4)=='4.75') );
isNetscape6 = ( (navigator.appName.toUpperCase()=="NETSCAPE")&&(navigator.appVersion.substring(0,3)=='5.0') );
if (isNetscape6) val_err_message = "This field can't be validated correctly by this browser !";

function checkRegexp(pattern_, str) {
  if (str==null)
      return false;
  var pattern = new RegExp(pattern_);
  return (pattern.test(str));
}

function checkAnyField(field) {
 var curCheckFN=field.vf;
 if ( (curCheckFN!=null) && (window.document.VFScriptExist) && !isNetscape6 ) {
    if (curCheckFN=='') {
        if ( (checkFN==null)||((curCheckFN=checkFN[field.name])==null) )
	    return -1;
	else
	    curCheckFN+='(ThisField)';
    }
    var VFName=/\w+/
    var CheckFName=VFName.exec(curCheckFN);
    if ( (CheckFName!=null) && (existingVF[CheckFName[0]]) ) {
	ThisField=field; 
	return (eval(curCheckFN)) ? 1 : 0 ;
    }
 }
 return -1;
}                                                                    

function setStates(valid, fail) {
  global_state[0] = valid;
  global_state[1] = fail;
}

function showState(valid,img_name,ifv) {
    var img=window.document.images[img_name];
    if ( (img!=null) && (valid>=0) ) {
	var ind_img = 0;
	var ind_mes = 0;
	if (valid == 0) {
	    ind_img = ifv ? 1 : 2 ;
	    ind_mes = 1 ;
	}
	if (img.state != ind_img) {
    	    window.status = global_state[ind_mes]+global_val_message;
    	    img.src = status_images[ind_img];
            img.state = ind_img;
	}
    } else {
	window.status = val_err_message;
    }
}

function showOnFocus(field) {
    showState(checkAnyField(field),field.img_name,true);
}

function showOnBlur(field) {
    showState(checkAnyField(field),field.img_name,false);
}

function showOnKeyUp(field) {
    if (isNetscape475)
	showOnKeyN(field);
    else
	showState(checkAnyField(field), field.img_name, true);
}

function showOnKeyN(field) {
    field.blur();
    field.focus();
}

function checkForm(form,visible) {
 if (form == null) 
     return false;
 var errors = false;
 var messages="Errors: \n\n";
 var fields = form.elements;
 var failfield = null;
 var Name2Label = /^(_*)/
 if (fields != null)
 {     
    for (var i=0; i<fields.length; i++) {
	var cfield=fields[i];
	if ( cfield.vf!=null ) {
	    var img = window.document.images[cfield.img_name];
	    var valid = checkAnyField(cfield);
	    if ( valid >= 0 ) {
		if ( valid == 0 ) {
		    if (img != null ) img.src=status_images[2];
		    if (failfield==null) 
			failfield=cfield;
		    var Label=cfield.label;
		    if ( (Label==null)||(Label=='') ) 
			Label=cfield.name.replace(Name2Label,"").toUpperCase();
		    messages+=Label+": "+global_state[1]+"\n";
		    errors=true; 
		} else {
		    if (img != null ) img.src=status_images[0];
		}
	    }
	}
    }
    if (failfield!=null)
	failfield.focus();

    if (errors && visible)
	alert(messages);
 }
 return !errors;
}

function checkAllForms() {
 var valid = true;
 for (var i = document.forms.length-1; i >= 0 ; i--) {
    var cform = document.forms[i];
    if ( cform.wbv )
    {
	if (!checkForm(cform, false)) valid=false;
    }
 }
 return valid;
}

function getStringValue(field) {
    if (field.type == "select-one") {
	return field.options[field.selectedIndex].value;
    } else if ((field[0] != null) && (field[0].type == "radio")) {
	for (var i in field) {
	    if (field[i].checked == "1") return field[i].value;
        }
    } else if (field.value != null) {
	return field.value;
    }
    return "";
}

function getBooleanValue(field) {
    return (field.type == "checkbox") ? (field.checked ? true : false)
	: ((getStringValue(field) != "") ? true : false );
}
//*************************************************************************************

