﻿// JavaScript Document
startList=function () { 	
	// for visit counter in liveVistor.asp
	if (window.document.location.href.search("/acls/")!=-1) {
		if (window.document.location.href.search("/khm/")!=-1) loadXMLDoc('../../assets/liveVisitoracls.asp?lang=khm');
		else loadXMLDoc('../../assets/liveVisitoracls.asp?lang=eng');
	}else{
		if (window.document.location.href.search("/khm/")!=-1) loadXMLDoc('../../assets/liveVisitor.asp?lang=khm');
		else loadXMLDoc('../../assets/liveVisitor.asp?lang=eng');
	}
	//liveVisitor for page lao by thina
	if ((window.document.location.href.search("/la/")!=-1)||(window.document.location.href.search("/mobi/la/")!=-1)) {
		loadXMLDoc('../../assets/liveVisitorlao.asp');
	}
	// all pages in ie6
	if (document.all&&document.getElementById){
		var navRoot=document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++){
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI"){
				node.onmouseover=function(){
					if (this.id=='navHome')this.className+=" homeOver";
					else this.className+=" over";
				}
				node.onmouseout=function(){
					if (this.id=='navHome') this.className=this.className.replace(" homeOver", "");
					else this.className=this.className.replace(" over", "");
				}
			}
		}
		toolsRoot = document.getElementById("tools");
		for (i=0; i<toolsRoot.childNodes.length; i++){
			nodeTools=toolsRoot.childNodes[i];
			if (nodeTools.nodeName=="LI" && nodeTools.id=="tool"){
				nodeTools.onmouseover=function(){this.className+=" overTool";}
				nodeTools.onmouseout=function(){this.className=this.className.replace(" overTool", "");}
   			}			
  		}
		toolENRoot=document.getElementById("subTool");
		for (i=0; i<toolENRoot.childNodes.length; i++){
			nodeTools=toolENRoot.childNodes[i];
			if (nodeTools.nodeName=="LI"){
				nodeTools.onmouseover=function(){this.className+=" over";}
				nodeTools.onmouseout=function(){this.className=this.className.replace(" over", "");}
   			}
		}
				
		searchRoot=document.getElementById("optSearch");	
		for (i=0; i<searchRoot.childNodes.length; i++){
			nodeSearch=searchRoot.childNodes[i];
			if (nodeSearch.nodeName=="LI"){
				nodeSearch.onmouseover=function(){this.className+=" over";}
				nodeSearch.onmouseout=function(){this.className=this.className.replace(" over", "");}
   			}
		}
	}
	var strLoc=new String(document.URL);
	strLoc=strLoc.substring(strLoc.lastIndexOf(".")-2,strLoc.lastIndexOf("."));
	document.formSear.lang.value=strLoc;		
	showBtn(document.formSear.searWords.value); //function in currentSearch.js
	checkCookie(); //function in currentSearch.js
	
	// search box
	var Elm=document.getElementById('searchTop');
	var Elm1=document.getElementById('search');
	if (document.body.clientWidth <1120 && Elm1!=null) Elm1.id = 'searchTop';
	else if(Elm!=null) Elm.id = 'search';
	
	//-------------user comment on load------------
	if(Cookies['cookieyn']=="yes" || Cookies['cookieyn']=="no"){
		document.getElementById('cmtResult').style.display='block';
		document.getElementById('cmtQ').style.display='none';
		document.getElementById('cmtNo').style.display='none';
		Cookies.erase('cookieyn');
		
		if(document.all) pHeight=document.body.clientHeight;
		else pHeight=window.scrollMaxY;
		window.scrollTo(0,pHeight);
	}
	//-------------end user comment-----------------
}

//-------------------user comment-------------------
function cmt_click(cmt){
	if(cmt=="yes"){
		document.getElementById('cmtQ').style.display='none';
		document.getElementById('cmtYes').style.display='block';
	}else if(cmt=="no"){
		document.getElementById('cmtQ').style.display='none';
		document.getElementById('cmtNo').style.display='block';
	}
}
function cmt_frm_submit(){
	document.cmt_frm.submit();
}
/* COOKIES use in user comment and branch map */
var Cookies = {
init: function (){
	var allCookies = document.cookie.split('; ');
	for (var i=0;i<allCookies.length;i++){
		var cookiePair = allCookies[i].split('=');
		this[cookiePair[0]] = cookiePair[1];
	}
},
create: function (name,value){
	var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	this[name] = value;
},
erase: function (name){
	this.create(name,'',-1);
}
}; Cookies.init();
//------------------end user comment--------------------

window.onload = startList;
window.onerror = function() {return true;}

// ------------------- tooltip -------------------------
function showToolTip(e,text){
	if(document.all) var e=event;
	var obj=document.getElementById('tooltip');
	document.getElementById('content').innerHTML=text;
	obj.style.display='block';
	var stY = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	var stX = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
	var lp=e.clientX-20;
	if(lp>1155) lp=1155;
	obj.style.top=(e.clientY-235)+stY+'px';
	obj.style.left=lp-140+stX+'px';
}	
function hideToolTip(){
	document.getElementById('tooltip').style.display='none';
}
// ------------------ end ---------------------------------

/* START TAB FUNCTION */
	function findObj(id){return document.getElementById(id);}
	function setBlock(strName,intTabLength,intStart,unselect_class,select_class){
    	try{
			var strDivName=strName.substring(0,strName.indexOf("_"));
			var stri=strDivName;
        	for (var i=1; i<=intTabLength; i++){   
           		var temp=i+intStart;
           		if(temp<10)stri=strDivName+'_'+temp;
           		else stri=strDivName+'_'+temp;
           		findObj(stri).className=unselect_class;
           		findObj(findObj(stri).headers).style.display="none";
        	}
        	findObj(strName).className=select_class;
			findObj(findObj(strName).headers).style.display="block";
    	}
    	catch(ex){}
	}

// JavaScript search box written by Mr. Dorn Damol ---------
function showBtn(a){
	var btn_search=document.getElementById('btnSearch');
	var btn_opt=document.getElementById('btnDropdown');	
	if (a.length>0 && a!="Search..." || a.length>0 && a!="ស្វែងរក..."){			
		btn_search.style.display="block";			
		btn_opt.style.display="block";
	}
	if (a.length>0 && a=="Search..." || a.length>0 && a=="ស្វែងរក..."){
		document.getElementById('optSearch').style.visibility="hidden";
		btn_search.style.display="none";
		btn_opt.style.display="none";
	}
}
	
//set cookie
function setCookie(c_name,value){document.cookie=c_name+ "=" +escape(value);}
function getCookie(c_name){
if (document.cookie.length>0){
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1){
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    }
  }
return ""
}
function checkCookie(){
	searchOpt=getCookie('currentOpt')
	if (searchOpt!=null && searchOpt!=""){
  		if (searchOpt=='default') document.getElementById("acledabank").style.fontWeight="bold";
		else if (searchOpt=='branch') document.getElementById("branch").style.fontWeight="bold";
		else if (searchOpt=='ATM') document.getElementById("ATM").style.fontWeight="bold";
		else document.getElementById("fullOperationBranch").style.fontWeight="bold";	
 	}else{setCookie('currentOpt','default')}
}
// ------------------------ end search box --------------------------------

/*------------------start Online Visitor ------------------------------*/
function loadXMLDoc(url){
 try{xmlHttp=new XMLHttpRequest();}
  catch (e){
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){
      try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
      catch (e){
		alert("Your browser does not support AJAX!");
      	return false;
        }
      }
    }
 if (xmlHttp!=null){  
  xmlHttp.onreadystatechange=state_Change
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)  
 }else{alert("Your browser does not support XMLHTTP.")}
}

function state_Change(){
	if (xmlHttp.readyState==4){
 	if (xmlHttp.status==200){
		var objElm=document.getElementById("liveVisitor");
 		if (objElm) objElm.innerHTML=xmlHttp.responseText
	}
  }
}
/*------------------END Online Visitor ------------------------------*/

function getemail(domain,name){
	document.write("<a href='mail"+"to:"+name.replace(/%23/g,"@")+domain.replace(/%23/g,".")+"'>"+name.replace(/%23/g,"@")+domain.replace(/%23/g,".")+"</a>");
}