/*------------------------------------------*/

function ebankingPop(url){
var url;
window.open (url,'mywindow','menubar=1,scrollbars=1,resizable=0,width=820,height=615'); 
}

function smartText(thefield){
    if(thefield.defaultValue == thefield.value){
    thefield.value = "";}
    else if(thefield.value == ""){
    thefield.value = thefield.defaultValue;}
}

/* change lang */
function langEn() {

var url=document.URL;
url =(url).replace('#1','');
countstr=url.length;
data=url.substr(countstr-1);

if(data=='/'){
url=url+'index.php';
}

sp_url=url.split("."); 
pointtype=(sp_url.length)-1;

type=sp_url[pointtype];
newurl =url.replace('.'+type,'-en.'+type);
window.location=newurl;
//alert(newurl);
}
function langTh() {
		var url=document.URL;
			url =(url).replace('#1','');
			newurl =(url).replace('-en','');
			window.location=newurl;
}


function strRootPath(){
	var strCfgRoot = "";
	var strCfgMainUrl = "";
	if("icweb.dyndns.info"==document.domain){ // webserver
		strCfgRoot = "/tmbbank";
		strCfgMainUrl = "http://" + document.domain + strCfgRoot ;
	}else if("192.168.1.9"==document.domain){ // webserver
		strCfgRoot = "/tmbbank";
		strCfgMainUrl = "http://" + document.domain + strCfgRoot ;
	}else if("127.0.0.1"==document.domain){ // webserver
		strCfgRoot = "/tmbbank";
		strCfgMainUrl = "http://" + document.domain + strCfgRoot ;
	}else{ // Server
		strCfgMainUrl = "http://" + document.domain + strCfgRoot ;
	}
	return strCfgMainUrl;
}


var numEnewsletter = 0;
function showEnewsletter(){
	if(this.numEnewsletter==0){
		$("#FormEnews").slideDown("slow");
		this.numEnewsletter = 1;
	} else {
		$("#FormEnews").slideUp("slow");
		this.numEnewsletter = 0;
	}
}


function getdata() {
	var str1 = document.getElementById("eEmail").value;
	var str2 = (document.getElementById("ePersonal").checked==true)? "1": "0";
	var str3 = (document.getElementById("eCorporate").checked==true)? "1": "0";
	var str4 = (document.getElementById("eSME").checked==true)? "1": "0";
	
	queryStr="Email="+str1+"&Personal=" + str2 +"&Corporate="+ str3 + "&SME=" + str4;
	
	$.ajax({
		type: "POST",
		url: "../../lib/enewletter.php",
		cache: false,
		data: queryStr,
			success: function(response){
			  alert("ขอบคุณที่สมัคร Enewletter กับเรา");	
			}
	});
}



function VF_frm_Search(){ //v2.0
	var theForm = document.frm_Search;
	var errMsg = "";
	var setfocus = "";

	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}//-->



function switchtopHeadMenu(){
  var strURL = document.URL;
  
  if(strURL.match("/personal/") || strURL.match("/calculator/")){  
    //$("#NavCat1").css("display",""); 
	$("#NavCat1").fadeIn("slow");
  } else if(strURL.match("/business/")){  
    //$("#NavCat2").css("display",""); 
	$("#NavCat2").fadeIn("slow");
  } else {  
  	//$("#NavCat3").css("display",""); 
	$("#NavCat3").fadeIn("slow");
  }
}


/*
function ShowNavLinkTop(){
	$("#strNavLinkTop").slideDown("slow");
}
function HideNavLinkTop(){
	$("#strNavLinkTop").fadeOut("slow");
}
*/
function HideAllNavLinkTop(){
  $("#strNavLinkTop").hide();
}


function switchTab(num){
	/* EX. By Cartoon
      <script>
		jQuery().ready(function(){
			$(".aTab").css("display","none");
			$("#Tab1").css("display","");
		});
      </script>
      <div id="Tab1" class="aTab">
	  	Tab1
		<a href="javascript: switchTab('2');">Tab2</a>
		<a href="javascript: switchTab('3');">Tab3</a>
	  </div>
      <div id="Tab2" class="aTab">
	  	<a href="javascript: switchTab('1');">Tab1</a>
		Tab2
		<a href="javascript: switchTab('3');">Tab3</a>
	  </div>
      <div id="Tab3" class="aTab">
		<a href="javascript: switchTab('1');">Tab1</a>
		<a href="javascript: switchTab('2');">Tab2</a>
		Tab3
	  </div>
	*/

			
	if(num!="") {
		$(".aTab").css("display","none");
		
		$("#Tab"+num).css("display","");
	}
}

function imgSwap(oImg)
{
   var strOver  = "_on"    // image to be used with mouse over
   var strOff = "_off"     // normal image
   var strImg = oImg.src
   if (strImg.indexOf(strOver) != -1) 
      oImg.src = strImg.replace(strOver,strOff)
   else
      oImg.src = strImg.replace(strOff,strOver)
}

function imgSwapId(oImg)
{
   var strOver  = "_on"    // image to be used with mouse over
   var strOff = "_off"     // normal image
   var strImg = document.getElementById(oImg).src
   if (strImg.indexOf(strOver) != -1)
      document.getElementById(oImg).src = strImg.replace(strOver,strOff)
   else
      document.getElementById(oImg).src = strImg.replace(strOff,strOver)
}
 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
/*------------------------------------------*/

function fnPrintAnalytic(){
	var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
      disp_setting+="scrollbars=yes,width=767, height=800, left=100, top=25"; 
  var content_A= document.getElementById("AnalyticsDetail").innerHTML;
  //alert(content_A)
  var strCfgMainUrl = strRootPath();

  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>TMB Bank Public Company Limited</title>'); 
   docprint.document.write('<link href="../css/tmbTH.css" rel="stylesheet" type="text/css" /><link href="../css/tmbAnalytics.css" rel="stylesheet" type="text/css" /><link href="../css/tmbAnalytics-print.css" rel="stylesheet" type="text/css" /></head><body onLoad="self.print();" style="margin-left:20px;margin-top:20px;">');
   docprint.document.write('<div style="padding-bottom:10px;"><img src="../common/img/logoTMB.png" alt="TMB" border="0" /></div>');
   docprint.document.write('<div id="Analytics"><div id="Wrapper"><div id="Body">');
   docprint.document.write(content_A);
   docprint.document.write('</div></div></div>');
   docprint.document.write('<div style="font-size:0.7em;">© สงวนลิขสิทธิ์ 2553 ธนาคารทหารไทย จำกัด (มหาชน)</div>');
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}
function promotionPrint(){
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
      disp_setting+="scrollbars=yes,width=767, height=800, left=100, top=25"; 
  var content_A= document.getElementById("Promotion").innerHTML;
  //var divHide="'Functions'";
  //var show="'none'";document.getElementById('+divHide+').style.display='+show+';
  var strCfgMainUrl = strRootPath();

  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>TMB Bank Public Company Limited</title>'); 
   docprint.document.write('<link href="../css/tmbTH.css" rel="stylesheet" type="text/css" /><link href="../css/tmbPromotion.css" rel="stylesheet" type="text/css" /></head><body onLoad="self.print();" style="margin-left:20px;margin-top:20px;">');
   docprint.document.write('<div style="padding-bottom:10px;"><img src="../common/img/logoTMB.png" alt="TMB" border="0" /></div>');
   docprint.document.write('<div id="Content"><div class="TwoColumnC"><div id="Promotion">');
   docprint.document.write(content_A);
   docprint.document.write('</div></div></div>');
   docprint.document.write('<div style="font-size:0.7em;">© สงวนลิขสิทธิ์ 2553 ธนาคารทหารไทย จำกัด (มหาชน)</div>');
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 

}
function newsPrint(){
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
      disp_setting+="scrollbars=yes,width=767, height=800, left=100, top=25"; 
  var obj=document.getElementById("NewsRoom");
  
  var content_A = obj.getElementsByTagName("div")[0].innerHTML;
  var content_B = obj.getElementsByTagName("div")[2].innerHTML;
  var divHide="'Functions'";
  var show="'none'";
  
  var strCfgMainUrl = strRootPath();

  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>TMB Bank Public Company Limited</title>'); 
   docprint.document.write('<link href="../css/tmbTH.css" rel="stylesheet" type="text/css" /><link href="../css/tmbPrint.css" rel="stylesheet" type="text/css" /></head><body onLoad="document.getElementById('+divHide+').style.display='+show+';self.print();" style="margin-left:20px;margin-top:20px;">');
   docprint.document.write('<div style="padding-bottom:10px;"><img src="../common/img/logoTMB.png" alt="TMB" border="0" /></div>');
   docprint.document.write('<div id="NewsRoom">');
   docprint.document.write('<div class="Header">'+content_A+'</div>');
   docprint.document.write('<div class="Display">'+content_B+'</div>');
   docprint.document.write('</div>');
   docprint.document.write('<div style="font-size:0.7em;">© สงวนลิขสิทธิ์ 2553 ธนาคารทหารไทย จำกัด (มหาชน)</div>');
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus();
}

function irPrint(){
	
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
      disp_setting+="scrollbars=yes,width=767, height=800, left=100, top=25"; 
  var obj=document.getElementById("Content");
  
  var content_A = obj.getElementsByTagName("div")[1].innerHTML;
  var divHide="'Functions'";
  var show="'none'";
  var strCfgMainUrl =strRootPath();

  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>TMB Bank Public Company Limited</title>'); 
   docprint.document.write('<link href="'+strCfgMainUrl+'/css/tmbTH.css" rel="stylesheet" type="text/css" /><link href="'+strCfgMainUrl+'/css/tmbIR.css" rel="stylesheet" type="text/css" /><link href="'+strCfgMainUrl+'/css/tmbIR.css" rel="stylesheet" type="text/css" /><link href="'+strCfgMainUrl+'/css/tmbPrint.css" rel="stylesheet" type="text/css" /><body onLoad="document.getElementById('+divHide+').style.display='+show+';self.print();" style="margin-left:20px;margin-top:20px;">');
   docprint.document.write('<div style="padding-bottom:10px;"><img src="'+strCfgMainUrl+'/common/img/logoTMB.png" alt="TMB" border="0" /></div>');
   docprint.document.write('<div id="Content">');
   docprint.document.write('<div class="TwoColumnC">'+content_A+'</div>');
   docprint.document.write('</div>');
   docprint.document.write('<div style="font-size:0.7em;">© สงวนลิขสิทธิ์ 2553 ธนาคารทหารไทย จำกัด (มหาชน)</div>');
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus();
}
function ratesPrint(){

document.getElementById("TMBGadget").style.display = "none";
  
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
      disp_setting+="scrollbars=yes,width=767, height=800, left=100, top=25"; 
  var obj=document.getElementById("Content");
  var content_A = obj.getElementsByTagName("div")[1].innerHTML;
  
  //var content_A=content_A.replace("line-height: 18px;", "line-height: 10px;");
 
  
  var divHide="'Functions'";
  var divHideFoot="'footComment'";
  var show="'none'";
  var strCfgMainUrl =strRootPath();
  
  //document.getElementById('footComment').style.display='none';
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>TMB Bank Public Company Limited</title>'); 
   docprint.document.write('<link href="'+strCfgMainUrl+'/css/tmbRatesPrint.css" rel="stylesheet" type="text/css" />');
   
   /*docprint.document.write('<style type="text/css">');
   docprint.document.write('@media print { .headPrint { background: url(http://'+location.hostname+'/common/img/rates/Header-Exchange.jpg) right no-repeat;height: 89px; } }');
   docprint.document.write('</style>');*/
   
   docprint.document.write('</head><body onLoad="document.getElementById('+divHide+').style.display='+show+';self.print();" style="margin-left:20px;margin-top:1px;">');
   //docprint.document.write('<div style="padding-bottom:1px;"><img src="'+strCfgMainUrl+'/common/img/logoTMB.png" alt="TMB" border="0" /></div>');
   
   docprint.document.write('<img src="../common/img/rates/Header-Exchange.jpg" alt="" style="margin-bottom:10px;" />');
   docprint.document.write(content_A);
   
   docprint.document.write('<div style="font-size:0.7em;">&copy; สงวนลิขสิทธิ์ 2553 ธนาคารทหารไทย จำกัด (มหาชน)</div>');
   docprint.document.write('</body></html>');
   

   docprint.document.close(); 
   docprint.focus();
}
function productPrint(){
  self.print();
  /*var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
      disp_setting+="scrollbars=yes,width=767, height=800, left=100, top=25"; 
  var obj=document.getElementById("Content");
  var strCfgMainUrl =strRootPath();
  var divHide="'Functions'";
  var show="'none'";
  
  var content_A = obj.getElementsByTagName("div")[1].innerHTML;
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>TMB Bank Public Company Limited</title>'); 
   docprint.document.write('<link href="'+strCfgMainUrl+'/css/tmbTH.css" rel="stylesheet" type="text/css" /><link href="'+strCfgMainUrl+'/css/tmbProductPrint.css" rel="stylesheet" type="text/css" /><body onLoad="document.getElementById('+divHide+').style.display='+show+';self.print();" style="margin-left:20px;margin-top:20px;">');
   docprint.document.write('<div style="padding-bottom:10px;"><img src="'+strCfgMainUrl+'/common/img/logoTMB.png" alt="TMB" border="0" /></div>');
   docprint.document.write('<div id="Content">');
   docprint.document.write('<div class="MainC">'+content_A+'</div>');
   docprint.document.write('</div>');
   docprint.document.write('<div style="font-size:0.7em;">© สงวนลิขสิทธิ์ 2553 ธนาคารทหารไทย จำกัด (มหาชน)</div>');
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus();*/
	
}
function careerPrint(){
	var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
      disp_setting+="scrollbars=yes,width=767, height=800, left=100, top=25"; 
  var obj=document.getElementById("Content");
  
  var content_A = obj.getElementsByTagName("div")[1].innerHTML;
  var divHide="'Functions'";
  var show="'none'";
  var strCfgMainUrl =strRootPath();

  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>TMB Bank Public Company Limited</title>'); 
   docprint.document.write('<link href="'+strCfgMainUrl+'/css/tmbTH.css" rel="stylesheet" type="text/css" /><link href="'+strCfgMainUrl+'/css/tmbCareer.css" rel="stylesheet" type="text/css" /><link href="'+strCfgMainUrl+'/css/tmbIR.css" rel="stylesheet" type="text/css" /><link href="'+strCfgMainUrl+'/css/tmbPrint.css" rel="stylesheet" type="text/css" /><body onLoad="document.getElementById('+divHide+').style.display='+show+';self.print();" style="margin-left:20px;margin-top:20px;">');
   docprint.document.write('<div style="padding-bottom:10px;"><img src="'+strCfgMainUrl+'/common/img/logoTMB.png" alt="TMB" border="0" /></div>');
   docprint.document.write('<div id="Content">');
   docprint.document.write('<div class="TwoColumnC">'+content_A+'</div>');
   docprint.document.write('</div>');
   docprint.document.write('<div style="font-size:0.7em;">© สงวนลิขสิทธิ์ 2553 ธนาคารทหารไทย จำกัด (มหาชน)</div>');
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus();
}
function fnEnews(){
	lroot=strRootPath();
	tb_show('', lroot+'/lib/enewletter.php?height=300&width=500', '') ;
}
function fnCareer(id){
	lroot=strRootPath();
	tb_show('', lroot+'/career/confirm.php?height=300&width=500&id='+id, '') ;
}
function fnCareers(id){
	lroot=strRootPath();
	tb_show('', lroot+'/career/confirm.php?height=300&width=500&id='+id+"&part=1", '') ;
}

function fnCareerPartSet(id,part){
	lroot=strRootPath();
	tb_show('', lroot+'/career/confirm.php?height=300&width=500&id='+id+'&npart='+part, '') ;
}

function newWinPopup(target){
	lroot=strRootPath();
	tb_show('', lroot+'/pupupconfirm/confirm.php?height=300&width=500&target='+target, '') ;
}

function fnNewOutSite(url,width,height){	

	if(confirm("คุณต้องการดูข้อมูลจากเว็บภายนอกใช่หรือไม่?"))
	{
	var urlname = url + "?KeepThis=true&TB_iframe=true&width=" + width +"&height=" + height;
	tb_show("Outside", urlname);
	}
}
function fnSend2friend(){
	lroot=strRootPath();
	tb_show('', lroot+'/lib/sendtofriend.php?height=400&width=510', '') ;
}

function fnSend2friendEvens(){
	//lroot=strRootPath();
	tb_show('', '../../../../lib/sendtofriend.php?height=400&width=510', '') ;
}

function fnFeedback(){
	lroot=strRootPath();
	tb_show('', lroot+'/ssi/feedback.php?height=465&width=360', '') ;
}
function fnRegis(){
	lroot=strRootPath();
	tb_show('', lroot+'/popup/registration.php?height=585&width=430', '') ;
}
function fnPrivacy(){
	lroot=strRootPath();
	window.open (lroot+"/personal/e-banking/popup/policy.html","mywindow","'toolbar=0,location=0,resizeable=0,directories=0,menubar=0,scrollbars=0,status=0,width=820,height=610");
}
function fnPrivacyEn(){
	lroot=strRootPath();
	window.open (lroot+"/personal/e-banking/popup/policy-en.html","mywindow","'toolbar=0,location=0,resizeable=0,directories=0,menubar=0,scrollbars=0,status=0,width=820,height=610");
}

function ShowImagefile(ShowFile){
	lroot=strRootPath();
	tb_show('', ShowFile, '') ;
}

function fnHiglightS(img,id){
	$('.Menu li').css("background", "#EBEBEB");
	$('.Menu li').css("color", "#006cb7");
	//$('.Menu li').css("border", "1px solid #EBEBEB");
	Cufon.replace('span.navMenu', { 
		color: '#006cb7'
	});
	$('#menu0'+id).css("background", "#57A1CE");
	$('#menu0'+id).css("color", "#FFF");
	//$('#menu0'+id).css("border", "1px solid #57A1CE");
	Cufon.replace('#menu0'+id+' span.navMenu', { 
		color: '#FFF'
	});
	$('#boxHighlight').hide();
	//$('#boxHighlight').fadeOut(200);
	
	fadeImg(img,id)
	
	//setTimeout("fadeImg('"+img+"','"+id+"')",100);
	
}
function fnHiglightH(img,id){
	$('#menu0'+id).css("background", "#57A1CE");
	$('#menu0'+id).css("color", "#FFF");
	Cufon.replace('#menu0'+id+' span.navMenu', { 
		color: '#006cb7'
	});
	//$('#menu0'+id).css("border", "1px solid #57A1CE");
}

function fadeImg(img,id){
	//alert(img)
	document.getElementById('jpgHighlight').src="img/H-"+img+".jpg";
	//$('#boxHighlight').fadeIn(300);
	$('#boxHighlight').show();
	Cufon.replace('span.navMenu', { 
		color: '#006cb7'
	});
	Cufon.replace('#menu0'+id+' span.navMenu', { 
		color: '#FFF'
	});
}

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_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_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];}
}

window.onerror = null;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer >= 4);
var IE4 = (bName == "Microsoft Internet Explorer" 
&& bVer >= 4);
var NS3 = (bName == "Netscape" && bVer < 4);
var IE3 = (bName == "Microsoft Internet Explorer" 
&& bVer < 4);
var blink_speed=500;
var i=0;

if (NS4 || IE4) {
if (navigator.appName == "Netscape") {
layerStyleRef="layer.";
layerRef="document.layers";
styleSwitch="";
}else{
layerStyleRef="layer.style.";
layerRef="document.all";
styleSwitch=".style";
}
}

//BLINKING
function Blink(layerName){
if (NS4 || IE4) { 
if(i%2==0)
{
eval(layerRef+'["'+layerName+'"]'+
styleSwitch+'.visibility="visible"');
}
else
{
eval(layerRef+'["'+layerName+'"]'+
styleSwitch+'.visibility="hidden"');
}
} 
if(i<1)
{
i++;
} 
else
{
i--
}
setTimeout("Blink('"+layerName+"')",blink_speed);
}

  function startBlink(layerName){
    window.blinker = setInterval(function(){
        if(window.blink){
           $('.'+layerName+'').css('color','');
           window.blink=false;
         }
        else{
                $('.'+layerName+'').css('color','white');
                window.blink = true;
        }
    },500);
  }

  function stopBlink(){
    if(window.blinker) clearInterval(window.blinker);
  } 
  
  function ajaxinclude(url) {
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.open('GET', url, false) //get page synchronously 
page_request.send(null)
writecontent(page_request)
}

function writecontent(page_request){
if (window.location.href.indexOf("http")==-1 || page_request.status==200)
document.write(page_request.responseText)
}
