﻿// JavaScript Document written by Mr. Dorn Damol
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 "default"
}

function checkCookie(){
	searchOpt=getCookie('currentOpt')
	if (searchOpt!=null && searchOpt!=""){
  		if (searchOpt=='default'){
			document.getElementById("acledabank").style.fontWeight="bold";
			document.getElementById("acledabank").style.fontFamily="Trebuchet MS";
			document.getElementById("acledabank").innerHTML="<img src='../../assets/layout/tick.gif' />www.acledabank.com.kh";
		}else if (searchOpt=='branch'){
			document.getElementById("branch").style.fontWeight="bold";
			document.getElementById("branch").innerHTML="<img src='../../assets/layout/tick.gif' />Branch location";
		}else if (searchOpt=='ATM'){
			document.getElementById("ATM").style.fontWeight="bold";
			document.getElementById("ATM").innerHTML="<img src='../../assets/layout/tick.gif' />ATM location";
		}else if (searchOpt=='POS'){
			document.getElementById("POS").style.fontWeight="bold";	
			document.getElementById("POS").innerHTML="<img src='../../assets/layout/tick.gif' />POS location";
		}else if (searchOpt=='branchKM'){
			document.getElementById("branchKM").style.fontWeight="bold";
			document.getElementById("branchKM").innerHTML="<img src='../../assets/layout/tick.gif' />បណ្តាញ​ប្រតិបត្តិការ";
		}else if (searchOpt=='ATMKM'){
			document.getElementById("ATMKM").style.fontWeight="bold";
			document.getElementById("ATMKM").innerHTML="<img src='../../assets/layout/tick.gif' />បណ្តាញ​ម៉ាស៊ីន​អេធីអឹម";
		}else if (searchOpt=='POSKM'){
			document.getElementById("POSKM").style.fontWeight="bold";	
			document.getElementById("POSKM").innerHTML="<img src='../../assets/layout/tick.gif' />បណ្តាញ​ម៉ាស៊ីន​ឆូត​កាត​";
		}
  }else{
	 setCookie('currentOpt','default') 
  }
}

if (document.layers){ // Netscape
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown = clickOutSearchList;	
}else if (document.all){ // Internet Explorer
	document.onmousedown = clickOutSearchList;
}else if (document.getElementById){ // Netcsape 6
	document.onmousedown = clickOutSearchList;
}

function clickOutSearchList(e){
	if (!e) {var e=window.event;}
	if (e.target) {targ=e.target;}
	else if (e.srcElement){targ=e.srcElement;}
	if (targ.nodeType==3){targ = targ.parentNode;}
	var tname,tid;
	tid = targ.id;
	if (tid =="acledabank" || tid=="branch" || tid=="ATM" || tid=="POS" || tid=="branchKM" || tid=="ATMKM" || tid=="POSKM") document.getElementById('optSearch').style.visibility='visible';
	else{	
		document.getElementById('optSearch').style.visibility='hidden';
		document.getElementById('btnDropdown_click').id='btnDropdown';
	}
}
function btnDropdown_click(){
	document.getElementById('optSearch').style.visibility='visible';
	document.getElementById('btnDropdown').id='btnDropdown_click';
}

function btnSearch_click(){	
	checkCookie();		
	if (getCookie('currentOpt')=='default') document.formSear.submit();
	else address();
}

/*search*/
function qs(){ 
	var f=document.formSear;
	var qe=f.searWords.value;
	if(window.encodeURIComponent)qe=encodeURIComponent(qe);		
	var pt=document.location.href;
	var iq=pt.indexOf('?');
	if(iq!=-1) pt=pt.substring(0, iq);
	if(f.action) 
		if(f.action!="") pt=f.action;
		var ue=pt+"?searWords="+qe;
		document.location=ue;
		return false;
}