/*   OpenSource version 07.0224 write by SleepingMan - a02091945@hotmail.com */

var menuLayers = {
	Turn_key: 0,
  activeMenuID: null,
  activeSubMenuID: null,
  
  show: function(id) {
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
//    window.defaultStatus = 'id=' + document.activeElement.getAttribute('id');
	if (this.Turn_key==1){
	    if (this.activeMenuID!= null) {
	    		this.hideSub();
	    		this.hide(this.activeMenuID);
	    	}
		this.activeMenuID = id;
	    document.getElementById(id).style.display = 'inline';
	}
  },
  
  showSub: function(id) {
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
//    window.defaultStatus = 'id=' + document.activeElement;
    if (this.activeSubMenuID!= null)	this.hide(this.activeSubMenuID);
    	this.activeSubMenuID = id;
    this.show(this.activeMenuID);
    document.getElementById(id).style.display = 'inline';
  },
  
  hide: function(id) {
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
//    if (id != document.activeElement)  
   	document.getElementById(id).style.display = 'none';
  },

  hideAll: function(id) {
//	this.hideSub();
	if (this.activeMenuID!=null) {
		if (id=='Avim_div') {
			this.hide('Avim_div');
		} else if (id=='submenu'){
			this.hide('submenu1');
			}	
		this.activeMenuID=null;
		this.Turn_key=0;
	}
  },
hideSub: function() {

  },
  
  Switch_Turn_key_p: function() {
	if (this.Turn_key==0) { this.Turn_key=1;
	} else {this.Turn_key=0;
	}
  },

	Switch_p: function(id) {
		if(id!=this.activeMenuID) { 
			this.show(id);
			this.Turn_key=1;
		} else {
			this.Turn_key=0;
			this.hide(id);
			this.activeMenuID=null;
		}
	}
}

function kakap(xmlstr,tagstr,indexno){ //getelementsbytagname - get str in XML tag
	var begintagstr = '<'+tagstr+'>'; 
	var endtagstr = '</'+tagstr+'>';
	var beginpos=1;
	var endpos=1;
	var countno=0;
	var resultstr='';
	while (countno<=indexno) {
		countno++;
		beginpos = xmlstr.indexOf(begintagstr,beginpos)+begintagstr.length;
		endpos = xmlstr.indexOf(endtagstr,beginpos);	
		if (beginpos<=0) { break; }
	}
	if(beginpos>=0) { resultstr=xmlstr.substring(beginpos,endpos); }
	return resultstr;
}

function setloader(mystatus){
	if (mystatus){
		if (ver=='vn'){
		document.getElementById('loader').innerHTML='<br><img src="A02091945_lib/loading.gif"> &#273;ang t&#7843;i n&#7897;i dung v&#7873;...';
	} else {
		document.getElementById('loader').innerHTML='<br><img src="A02091945_lib/loading.gif"> loading...';
	}
		document.getElementById('loader').style.display='';
	}else {
		document.getElementById('loader').style.display='none';
	}
}

function alltrimp(str){
	str=str.replace(/^\s*|\s*$/g,"");
	return str.replace(/\s{1,}/g,"");
}

function bgcolor(obj,state) {
	if (state=="over") {
		obj.style.backgroundColor ='F8FFF4';
		obj.style.cursor='default';
	}
	else {
		obj.style.backgroundColor='';
	}
}

// SET UP ARGUMENTS FOR FUNCTION CALLS

//

var caseSensitive = true;

var notCaseSensitive = false;

var wholeWords = true;

var anySubstring = false;

// SEARCH FOR A TERM IN A TARGET STRING

//

// search(targetString,searchTerm,caseSensitive,wordOrSubstring)

//

// where caseSenstive is a boolean value and wordOrSubstring is a boolean

// value and true means whole words, false means substrings

//

function search(target,term,caseSens,wordOnly) {

  var ind = 0;

  var next = 0;

  if (!caseSens) {

    term = term.toLowerCase();

    target = target.toLowerCase();

  }

  while ((ind = target.indexOf(term,next)) >= 0) {

    if (wordOnly) {

      var before = ind - 1;

      var after = ind + term.length;

      if (!(space(target.charAt(before)) && space(target.charAt(after)))) {

        next = ind + term.length;

        continue;

      }

    }

    return true;

  }

  return false;

}

// SEARCH FOR A TERM IN A TARGET STRING AND REPLACE IT

//

// replace(targetString,oldTerm,newTerm,caseSensitive,wordOrSubstring)

//

// where caseSenstive is a boolean value and wordOrSubstring is a boolean

// value and true means whole words, false means substrings

//

function replace(target,oldTerm,newTerm,caseSens,wordOnly) {

  var work = target;

  var ind = 0;

  var next = 0;

  if (!caseSens) {

    oldTerm = oldTerm.toLowerCase();

    work = target.toLowerCase();

  }

  while ((ind = work.indexOf(oldTerm,next)) >= 0) {

    if (wordOnly) {

      var before = ind - 1;

      var after = ind + oldTerm.length;

      if (!(space(work.charAt(before)) && space(work.charAt(after)))) {

        next = ind + oldTerm.length;

        continue;

      }

    }

    target = target.substring(0,ind) + newTerm + target.substring(ind+oldTerm.length,target.length);

    work = work.substring(0,ind) + newTerm + work.substring(ind+oldTerm.length,work.length);

    next = ind + newTerm.length;

    if (next >= work.length) { break; }

  }

  return target;

}

// CHECK IF A CHARACTER IS A WORD BREAK AND RETURN A BOOLEAN VALUE

//

function space(check) {

  var space = " .,/<>?!`';:@#$%^&*()=-|[]{}" + '"' + "\\\n\t";

  for (var i = 0; i < space.length; i++)

    if (check == space.charAt(i)) { return true; }

  if (check == "") { return true; }

  if (check == null) { return true; }

  return false;

}

function querysignp (urlstr) {
	var result = search(urlstr,'?',true,false);
	return ((result)?'&':'?');
}

function opensubwindow(url) {
	newwindow=window.open(url,'A02091945Tool','toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=800, height=550, top=30, left=50');
	if (window.focus) {newwindow.focus()} 
	return false; 
}