<!--
 /*
 (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

var sb_menu_selectedLink = new Array();
var sb_menu_selectedDiv = new Array();
var sb_menu_urlTemplate = new Array();

var sb_layout_type = new Array();

var MMM_d_yyyy_format = 0;
var d_MMM_yyyy_format = 1;
var yyyy_MMM_d_format = 2;

var newWindow;  

function openWindow(url,name,w,h) {
  newWindow= window.open(url, name, 'width=' + w + ',height=' + h +',resizable=yes,scrollbars=yes');
  newWindow.focus();
}

function openSingleWindow(url,name,w,h) {
  if (newWindow != null) newWindow.close();
  newWindow = window.open(url, name, 'width=' + w + ',height=' + h +',resizable=yes,scrollbars=yes');
  newWindow.focus();
  //setTimeout('self.close()', 10000);
}

/*
function openContentWindow(content,name,css,cssclass,cssStyle,w,h) {
  if (newWindow != null) newWindow.close();
  newWindow = window.open('', name, 'width=' + w + ',height=' + h +',resizable=yes,scrollbars=yes');
  newWindow.document.write('<html><head><title>');
  newWindow.document.write(name + '</title>');
  newWindow.document.write('<link href="' + css + '" type="text/css" rel="stylesheet" />');
  newWindow.document.write('</head><body><div class="' + cssclass + '" style="' + cssStyle + '">' + content + '</div></body></html>');
  newWindow.document.close();  
  newWindow.focus();
  //return;
}
*/

function openContentWindow(content,name,cssStyle,w,h) {
  if (newWindow != null) newWindow.close();
  newWindow = window.open('', name, 'width=' + w + ',height=' + h +',resizable=yes,scrollbars=yes');
  newWindow.document.write('<html><head><title>');
  newWindow.document.write(name + '</title>');
  newWindow.document.write('</head><body><div style="' + cssStyle + '">' + content);
  newWindow.document.write('<p/><center><a href="javascript:window.close()">Close window</a></center></div></body></html>');
  newWindow.document.close();  
  newWindow.focus();
  //return;
}

function openOnParentWindow(url) {
	if (window.opener && !window.opener.closed) {
		window.opener.location.href= url;
		window.opener.focus();
		//self.close();
		//return false;
	} else {
		window.location.href=url;
		return false;
	}
}

function setFocusOnLoginField() {
    if (document.loginForm != null) {
    	document.loginForm.j_username.focus();
    } else if (document.registerForm != null) {
    	if (document.registerForm.username != null)
    	    document.registerForm.username.focus();
		else if (document.registerForm.oemail != null)
		    document.registerForm.oemail.focus();
    }
}

function showToolTips(obj) {
    if (document.layers && document.layers[obj] != null) {
        //netscape 4.x || Mozilla < 1.5
        document.layers[obj].visibility = 'visible';
    }else if (document.all) {
        //IE4+
        document.all[obj].style.visibility = 'visible';
    }else {
        //Netscape 6+ || Mozilla 1.5+
        document.getElementById(obj).style.visibility ='visible';
    }
}

function hideToolTips(obj) {
    if(document.layers && document.layers[obj] != null) {
        //netscape 4.x || Mozilla < 1.5
        document.layers[obj].visibility = 'hide';
    } else if (document.all) {
        //IE4+
        document.all[obj].style.visibility = 'hidden';
    } else {
        //Netscape 6+ || Mozilla 1.5+
        document.getElementById(obj).style.visibility ='hidden';
    }
}

function verifyCheckboxes(fields) {
    //check if the fields is an array (more than 1 check box)
    if (fields.length == undefined) {
        if (fields.checked == true) 
            return true;
        return false;
    } else {
        for (i=0; i < fields.length; i++) 
            if (fields[i].checked == true)
                return true;
        return false;
    }
}

function SwitchTab(obj, thePath, cls, subTabIndexes, parentIndexes, childIndex)
{
	var open = 'url("'+thePath + 'images/collapse_tab.gif")';
	var close = 'url("'+thePath + 'images/expand_right.gif")';
  	if(document.getElementById)  {
		var el = document.getElementById(obj);
		var title = document.getElementById(obj+'Title');

		for (var i =0; i < subTabIndexes.length; i++) {
			var selTab = document.getElementById('tab_selected_'+subTabIndexes[i]);
			var unselTab = document.getElementById('tab_'+subTabIndexes[i]);
			var selTabTitle = document.getElementById('tab_selected_'+subTabIndexes[i]+'Title');
			var unselTabTitle = document.getElementById('tab_'+subTabIndexes[i]+'Title');

			var isSelected = false;
			for ( var j=0; j < parentIndexes.length; j++) {
				if (parentIndexes[j] == subTabIndexes[i] || childIndex == subTabIndexes[i]) {
					isSelected = true;
					break;
				}
			}

			if (isSelected) continue;

			if(selTab != null) {
				if (selTab.style.display == "block") {
					selTabTitle.style.backgroundImage = close;
					selTab.style.display = "none";
				}
			} else if (unselTab != null) {
				if (unselTab.style.display == "block") {
					unselTabTitle.style.backgroundImage = close;
					unselTab.style.display = "none";
				}
			}
		}

		if(el.style.display != "block"){ 
		  title.style.backgroundImage = open;
		  el.style.display = "block";
		}else{
		  title.style.backgroundImage = close;
		  el.style.display = "none";
		}

		//if (cls == "SelectedTabTitle")
		//	title.className = "UnselectedTabTitle";
		//else
		//	title.className = "SelectedTabTitle";

		//return true;
   }
}

function SwitchTabRTL(obj, thePath, cls, subTabIndexes, parentIndexes, childIndex)
{
	var open = 'url("'+thePath + 'images/collapse_tab.gif")';
	var close = 'url("'+thePath + 'images/expand_left.gif")';
  	if(document.getElementById)  {
		var el = document.getElementById(obj);
		var title = document.getElementById(obj+'Title');

		for (var i =0; i < subTabIndexes.length; i++) {
			var selTab = document.getElementById('tab_selected_'+subTabIndexes[i]);
			var unselTab = document.getElementById('tab_'+subTabIndexes[i]);
			var selTabTitle = document.getElementById('tab_selected_'+subTabIndexes[i]+'Title');
			var unselTabTitle = document.getElementById('tab_'+subTabIndexes[i]+'Title');

			var isSelected = false;
			for ( var j=0; j < parentIndexes.length; j++) {
				if (parentIndexes[j] == subTabIndexes[i] || childIndex == subTabIndexes[i]) {
					isSelected = true;
					break;
				}
			}

			if (isSelected) continue;

			if(selTab != null) {
				if (selTab.style.display == "block") {
					selTabTitle.style.backgroundImage = close;
					selTab.style.display = "none";
				}
			} else if (unselTab != null) {
				if (unselTab.style.display == "block") {
					unselTabTitle.style.backgroundImage = close;
					unselTab.style.display = "none";
				}
			}
		}

		if(el.style.display != "block"){ 
		  title.style.backgroundImage = open;
		  el.style.display = "block";
		}else{
		  title.style.backgroundImage = close;
		  el.style.display = "none";
		}
   }
}

// Calculate four digit year.
function fourdigits(number) {
  	return (number < 1000) ? number + 1900 : number;
}

function getDateFormat(theformat) {
    switch (theformat) {
        case "yyyy_MMM_d":
            return yyyy_MMM_d_format;
        case "d_MMM_yyyy":
            return d_MMM_yyyy_format;
        default:        
            return MMM_d_yyyy_format;

    }
}

function MM_findObj(n, d) { //v3.0
  	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); 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 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 ChangeImageOver(name)
{
	document.images[name].src = "/thaiwebsite/thai_portlets/homepage/images/"+name+"_on.gif";
}

function ChangeImageOut(name)
{
	document.images[name].src = "/thaiwebsite/thai_portlets/homepage/images/"+name+"_off.gif";
}

function SwitchLang(obj)
{
	address = document.location.href;
	language = obj.options[obj.selectedIndex].value;
	
	if (address.indexOf("/en/")>=0){
		newurl = address.replace("/en/","/"+language+"/");
	}
	if (address.indexOf("/sc/")>=0){
		newurl = address.replace("/sc/","/"+language+"/");
	}
	if (address.indexOf("/kr/")>=0){
		newurl = address.replace("/kr/","/"+language+"/");
	}
	document.location.href=newurl;
}

function PopUp(url, w, h)
{
	npop = window.open(url,'popwin','width='+w+',height='+h+',menubar=no,status=no,scrollbars=no,resizable=no,toolbar=no,location=no,directories=no')
}

function changeCase(cs)
{
	hideAllCases();
	displayCases(cs,true);
}

function displayCases(layerName, dis){
	
	var obj;
	if (document.all) {//For I.E.
		obj = document.all[layerName].style;
		obj.display = dis ? "inline" : "none";
	}
	else if (document){//For Netscape or FireFox
		obj = document.getElementById(layerName).style;
		obj.display = dis ? "inline" : "none";
	}
	if(dis){
		document.images["tab_"+layerName].src="/thaiwebsite/thai_portlets/homepage/images/"+"tab_"+layerName+"_on.gif";
	}
	else{
		document.images["tab_"+layerName].src="/thaiwebsite/thai_portlets/homepage/images/"+"tab_"+layerName+"_off.gif";
	}
	
}	

function hideAllCases(){
	
	for (var j=0; j < csArray.length; j++) {		
		displayCases(csArray[j], false);		
	}
}

/*//shane
function go()
{
location=document.forms[0].gowhere.value
}
//shane*/

//-->
