function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function linkToURL(url){
    location.href=url;
}
function formSubmit(url){
   if(document.forms['_anthanh_form_']){
   	  document.body.removeChild(document.forms['_anthanh_form_']);
   }
   var form=document.createElement("form");
   form.setAttribute("name", "_anthanh_form_");
   if(location.href.indexOf("https") != -1) form.setAttribute("method","get");
   else form.setAttribute("method","post");   
   
   document.body.appendChild(form);
   
   if(url.indexOf("?") < 0){
     form.setAttribute("action", url);
     form.submit();
   }else{
     var arg = url.split("?");
     form.setAttribute("action", arg[0]);
     arg = arg[1].split("&");
     var input;
     var xxx;
     for(var i=0;i<arg.length;i++){
       xxx=arg[i].indexOf("=");
       input = document.createElement("input");
       input.setAttribute("type", "hidden");
       input.setAttribute("name", arg[i].substring(0,xxx));
       input.setAttribute("value",arg[i].substring(xxx+1, arg[i].length));
       form.appendChild(input);
     }
     form.submit();
   }
}
//Begin Ajax funcs
function getXmlHttpObject() {
	var http_request = null;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      return http_request;
}
function bindData(url, customFunction){ 
	var xmlHttp = getXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	xmlHttp.onreadystatechange = function() {
		if(customFunction && xmlHttp.readyState == 4) {
			customFunction(xmlHttp.responseText);
		}
	}
	url = url.indexOf('?') >=0 ? url + "&_ssssssss=" + new Date().getTime() : url + "?_ssssssss=" + new Date().getTime();
	xmlHttp.open("GET", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(null);
}
function submitFormUsingAjax(form, successFunc, errFunc){ 
    var	xmlHttp = getXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var params = getFormValues(form);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200){
				successFunc(xmlHttp.responseText);
			}	
		}
	}
	xmlHttp.open("POST", form.action, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}		
function getFormValues(formNode) { // convert form elements to urlQueryString 
	var values = [];
	for(var i = 0; i < formNode.elements.length; i++){
		var elm = formNode.elements[i];
		if(!elm || elm.tagName.toLowerCase() == "fieldset" || !formFilter(elm)) { continue; }
		var name = enc(elm.name);
		var type = elm.type.toLowerCase();

		if(type == "select-multiple"){
			for(var j = 0; j < elm.options.length; j++){
				if(elm.options[j].selected) {
					values.push(name + "=" + enc(elm.options[j].value));
				}
			}
		}else if(type=="radio" || type=="checkbox"){
			if(elm.checked){
				values.push(name + "=" + enc(elm.value));
			}
		}else{
			values.push(name + "=" + enc(elm.value));
		}
	}
	// now collect input type="image", which doesn't show up in the elements array
	var inputs = formNode.getElementsByTagName("input");
	for(var i = 0; i < inputs.length; i++) {
		var input = inputs[i];
		if(input.type.toLowerCase() == "image" && input.form == formNode
			&& formFilter(input)) {
			var name = enc(input.name);
			values.push(name + "=" + enc(input.value));
			values.push(name + ".x=0");
			values.push(name + ".y=0");
		}
	}
	return values.join("&") + "&";
}
function formFilter(node) {
	var type = (node.type||"").toLowerCase();
	var accept = false;
	if(node.disabled || !node.name) {
		accept = false;
	} else if(type=="submit" ||type=="button"||type=="image") {
		if(!this.clickedButton) { this.clickedButton = node; }
		accept = node == this.clickedButton;
	} else {
		accept = !(type=="file" || type=="submit"|| type=="reset"|| type=="button");
	}
	return accept;
}	
function enc(v) { // encode HTML
	return v;
}
function inList(arr, va){
	for(var i=0; i<arr.length; i++){
		if(arr[i] == va)
			return true;
	}
	return false;
}
function turnOnWaiting(){
    unHide("pleaseWaitLayer");
	unHide("DivShim");
}
function turnOffWaiting(){
    hide("pleaseWaitLayer");
	hide("DivShim");
}
function unHide(id){
	if (document.layers)
		document.layers[id].visibility = "show"
	else if (document.all)
		document.all[id].style.visibility = "visible"
	else if (document.getElementById(id))
		document.getElementById(id).style.visibility = "visible"
}
function hide(id){
	if (document.layers)
		document.layers[id].visibility = "hidden"
	else if (document.all)
		document.all[id].style.visibility = "hidden"
	else if (document.getElementById(id))
		document.getElementById(id).style.visibility = "hidden"
}
//end Ajax Funcs
function popup(url) {
   window.open(url,'','menubar=no, scrollbars=no,location=no,personalbar=no,resizable=yes');
   return false;
}
function newWindow(url) {
  if(url != "#"){
   window.open(url,'','statusbar=yes, menubar=yes, scrollbars=yes,location=yes,personalbar=yes,resizable=yes,fullscreen=no,top=0,left=0');
   return false;
  }
}
function newWindowfull(url) {
  if(url != "#"){
   window.open(url,'','statusbar=yes,menubar=no,scrollbars=yes,toolbar=no,location=no,personalbar=yes,resizable=yes,fullscreen=no,top=0,left=0');
   return false;
  }
}
function livequote(addressSQ, compUrl, registerUrl) {
		
	width = screen.width;
	height = screen.height;
	
	features = "width=" + width +",height=" + height +",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,copyhistory=no,resizable=no,fullscreen=yes,top=0,left=0";
	
	sq = window.open("","sqwindow",features);
	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		width = sq.innerWidth;
		height = sq.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		width = sq.document.documentElement.clientWidth;
		height = sq.document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		width = sq.document.body.clientWidth;
		height = sq.document.body.clientHeight;
	}
	sq.document.write("<html>");
	sq.document.write("<head>");
	sq.document.write("<title>Habubank Securities - Bang giao dich truc tuyen</title>");
	sq.document.write("<STYLE TYPE='text/css'>");
	sq.document.write("  BODY {margin: 0pt}");
	sq.document.write("</STYLE>");
	sq.document.write("</head>");
	sq.document.write("<body scroll=no topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\" marginwidth=\"0\" marginheight=\"0\" bgcolor='000000' onLoad='Javascript:self.focus();'>");
	sq.document.write("<object classid = 'clsid:8AD9C840-044E-11D1-B3E9-00805F499D93' codebase = 'http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,3' WIDTH = '"+ width +"' HEIGHT = '"+ height +"'>");
	sq.document.write("    <PARAM NAME = CODE VALUE = 'com.hbbs.gui.sq.SQViewer' >");
	sq.document.write("    <PARAM NAME = CODEBASE VALUE = 'java' >");
	sq.document.write("    <PARAM NAME = ARCHIVE VALUE = 'sq.jar' >");
	sq.document.write("    <PARAM NAME = 'defaultSTC' VALUE = 'HOSTC' >");
	sq.document.write("    <PARAM NAME = 'host' VALUE = '"+ addressSQ +"' >");
	sq.document.write("    <PARAM NAME = 'width' VALUE = '"+ width +"' >");
	sq.document.write("    <PARAM NAME = 'height' VALUE = '"+ height +"' >");
	sq.document.write("    <PARAM NAME = 'compUrl' VALUE = '"+ compUrl +"' >");
	sq.document.write("    <PARAM NAME = 'registerUrl' VALUE = '"+ registerUrl +"' >");
	sq.document.write("    <param name = 'type' value = 'application/x-java-applet;version=1.5'>");
	sq.document.write("    <param name = 'scriptable' value = 'false'>");
	sq.document.write("    <comment>");
	sq.document.write("		<embed type = 'application/x-java-applet;version=1.5' host='" + addressSQ + "' compUrl='"+ compUrl +  "' registerUrl='" + registerUrl  + "' defaultSTC='HOSTC' CODE = 'com.hbbs.gui.sq.SQViewer' JAVA_CODEBASE = 'java' ARCHIVE = 'sq.jar' WIDTH = '"+ width +"' HEIGHT = '"+ height +"' scriptable = false pluginspage = 'http://java.sun.com/products/plugin/index.html#download'>");
	sq.document.write("	    <noembed></noembed>");
	sq.document.write("	    </embed>");
	sq.document.write("    </comment>");
	sq.document.write("</object>");
	sq.document.write("</body>");
	sq.document.write("</html>");
	sq.document.close();
}
function trim(s) {
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

