/* awap hilight */
function swaphilight(h1,h2,h3,s1) { 
  document.getElementById(h1).style.display = "none" ;
  document.getElementById(h2).style.display = "none" ;
  document.getElementById(h3).style.display = "none" ;
  document.getElementById(s1).style.display = "block" ;
}

/* open browser image */
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/* change lang */
chl = new Array(5);
chl[0]=".html",
chl[1]=".htm",
chl[2]=".aspx",
chl[3]=".asp",
chl[4]=".php",
chl[5]=".jsp";
function chlangen() {
	for (i = 0; i <= 5 ; i++) {
		var url=document.URL;
		if(url.search(chl[i])>1) 
		{ 
			newurl =(document.URL).replace(chl[i],'_en'+chl[i]);
			window.location=newurl;
			break;
		} 
			
	
	}
}
function chlangth() {
		var url=document.URL;
			newurl =(document.URL).replace('_en','');
			window.location=newurl;
}

/* print - th */
function fixprint()
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  var content_P = document.getElementById("tb_printtitle").innerHTML; 
  var content_H = document.getElementById("tb_heading").innerHTML;
  var content_C= document.getElementById("print_content").innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>Government Savings Bank</title>'); 
   docprint.document.write('<link href="http://www.gsb.or.th/css/global.css" rel="stylesheet" type="text/css"></head><body onLoad="self.print()">');
   docprint.document.write('<table width="590" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="210">');
   docprint.document.write('<img src="http://www.gsb.or.th/engine/print/logo.gif" width="210" height="83"></td><td>');
   docprint.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>&nbsp;</td></tr><tr><td align="right" height="25" valign="bottom"  class="pathhead">');
   docprint.document.write(content_P);
   docprint.document.write('</td></tr><tr><td align="right" valign="top" class="pathurl" height="25">');
   docprint.document.write('<script>document.write(document.URL)</script>');
   docprint.document.write('</td></tr></table></td></tr></table>');  
   docprint.document.write('<table width="590" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>');
   docprint.document.write(content_H);
   docprint.document.write('</td></tr></table><table width="590" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td valign="top">');
   docprint.document.write(content_C);
   docprint.document.write('</td></tr></table>');
   docprint.document.write('<table width="590" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td valign="bottom">');
   docprint.document.write('<img src="http://www.gsb.or.th/engine/print/footer.gif" width="590" height="100" /></td></tr></table>');
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}


///////////////////////////// ADDED 01-2010 ///////////////////////////////////////////
function createRequestObject() {
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}
FORM_DATA = createRequestObject();
  // This is the array/object containing the GET data.
  // Retrieve information with 'FORM_DATA [ key ] = value'.


// -->

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
var path = '/'
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
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 getBookURL()
{
	var ReferID = getCookie('ReferID')
	if (ReferID)
	{
		document.write('<a style="TEXT-DECORATION: none" target="_blank" href="https://booking.ihotelier.com/istay/istay.jsp?HotelID=72395&ReferID='+ ReferID +'"> <font face="Microsoft Sans Serif"  size="2"> <b>Book Now</b></font></a>')
	//return 'https://booking.ihotelier.com/istay/istay.jsp?HotelID=72395&ReferID='+ReferID;
		}
		else
		{
			document.write('<a style="TEXT-DECORATION: none" target="_blank" href="https://booking.ihotelier.com/istay/istay.jsp?HotelID=72395"> <font face="Microsoft Sans Serif"  size="2"> <b>Book Now</b></font></a>')
			//return 'https://booking.ihotelier.com/istay/istay.jsp?HotelID=72395';
		}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
