/*
This javascript file is the collection of the functions used on AEON page. This file
adds on its own javascript function and interacts with prototype library which is 
one of the javascript framework. Have fun :D
created by: Prakarn Klinbuathong
This function catches the id, class (maybe), or tag (whatever), 
and access the style through document object.
*/
	var newwindow; 
function poptastic(url)
{ 
	newwindow=window.open(url,'name','height=768,width=1024');
	if (window.focus) {newwindow.focus()}
}//End of poptastic
//-----------------------------------------------------------------------------------
//created by: Prakarn Klinbuathong
function swapFlagImage(flag){

  //alert("CLICK");

  var e2;		var intImage;

  if(flag=='th'){intImage=1;}
  if(flag=='en'){intImage=2;}
  
  switch (intImage){

   case 1:
	   e2 = document.getElementById('flag');
	   e2.src = "images/frontend/en_menu_Thai.gif";
	   intImage = 2
	   return(false);
   
   case 2:   
	   e2 = document.getElementById('flag');
	   e2.src = "images/frontend/en_menu_English.gif";
	   intImage = 1   
	   return(false);
  }//End switch
}//End swapImage
//-----------------------------------------------------------------------------------
//created by: Prakarn Klinbuathong
function swapFontSizeImage(flag){

  var e3;	var e4;		var e5;		var intImage;			

  e3 = document.getElementById('small');
  e4 = document.getElementById('medium');
  e5 = document.getElementById('large');

  if(flag=='small'||flag=='A-'){intImage=1;}
  if(flag=='medium'||flag=='A'){intImage=2;}
  if(flag=='large'||flag=='A+'){intImage=3;}
  
  switch (intImage){
   case 1:
	   e3.src = "images/frontend/menu_textsizeSActive.gif";
	   e4.src = "images/frontend/menu_textsizeM.gif";
	   e5.src = "images/frontend/menu_textsizeL.gif";
	   return(false);
   
   case 2:   
	   e3.src = "images/frontend/menu_textsizeS.gif";
	   e4.src = "images/frontend/menu_textsizeMActive.gif";
	   e5.src = "images/frontend/menu_textsizeL.gif";
	   return(false);

   case 3:
	   e3.src = "images/frontend/menu_textsizeS.gif";
	   e4.src = "images/frontend/menu_textsizeM.gif";
	   e5.src = "images/frontend/menu_textsizeLActive.gif";
	   return(false);	
  }//End switch
}//End swapImage
//-----------------------------------------------------------------------------------
function fontsizeS() {
  swapFontSizeImage('small');	
  active = getActiveStyleSheet();
  //alert(active);
  switch (active) {
    default :
      setActiveStyleSheet('A-'); if(typeof(IE7)!="undefined") {window.location.reload(false);}
      break;
  }

}

function fontsizeM() {
  swapFontSizeImage('medium');
  active = getActiveStyleSheet();
  //alert(active);
  switch (active) {
    default :
      setActiveStyleSheet('A');  if(typeof(IE7)!="undefined") {window.location.reload(false);}
      break;
  }

}

function fontsizeL() {
  swapFontSizeImage('large');
  active = getActiveStyleSheet();
  //alert(active);
  switch (active) {
    default :
      setActiveStyleSheet('A+');  if(typeof(IE7)!="undefined") {window.location.reload(false);}
      break;
  }

}
//-----------------------------------------------------------------------------------
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
	  //alert('no1 ' + title + ":" + a.title + a.disabled);
      if(a.getAttribute("title") == title) {
		  a.disabled = false;
		  //alert('no2'+ title + ":" + a.title + a.disabled);
	  }
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('A');
}
//-----------------------------------------------------------------------------------
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
//-----------------------------------------------------------------------------------
window.onload = function(e) {
  //alert(document.cookie);
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  //alert(document.cookie);
  //setActiveStyleSheet(title);
  swapFontSizeImage(title);
}
/*
window.onunload = function(e) {
  //alert(document.cookie);
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
*/

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);

//-----------------------------------------------------------------------------------


function openLoginScreen(lang)
{
    var Width = 800;
    var Height =  window.screen.availHeight;
    var Properties,nTop,nLeft;
    var Width,Height;
    screenY = window.screen.availHeight;
    screenX = window.screen.availWidth;
    nLeft=(screenX-Width)/2;
    nTop=(screenY-Height)/2;
    Properties="Toolbar=0,width=" + Width + ",height=" + (Height - 50)+ ",Resizable=no,Status=yes,Scrollbars=yes,Top=" + nTop + ",Left="+ nLeft;    
    url = 'https://enrollment.aeonthailand.com/i2inquiry/th/form_UserLogin_th.asp?ScreenStatus=true';
    if (lang == 'en') {
	url = 'https://enrollment.aeonthailand.com/i2inquiry/form_UserLogin.asp?ScreenStatus=true';
    }
    window.open(url,"_blank",Properties); 

}

function openRegisterScreen(lang)
{
    var Width = 800;
    var Height =  window.screen.availHeight;
    var Properties,nTop,nLeft;
    var Width,Height;
    screenY = window.screen.availHeight;
    screenX = window.screen.availWidth;
    nLeft=(screenX-Width)/2;
    nTop=(screenY-Height)/2;
    Properties="Toolbar=0,width=" + Width + ",height=" + (Height - 50)+ ",Resizable=no,Status=yes,Scrollbars=yes,Top=" + nTop + ",Left="+ nLeft;    
    url = 'https://enrollment.aeonthailand.com/i2inquiry/th/form_UserRegistrationInput_th.asp';
    if (lang == 'en') {
        url = 'https://enrollment.aeonthailand.com/i2inquiry/form_UserRegistrationInput.asp';
    }
    window.open(url,"_blank",Properties); 

}

function openAppInquiryScreen(lang)
{
    var Width = 800;
    var Height =  window.screen.availHeight;
    var Properties,nTop,nLeft;
    var Width,Height;
    screenY = window.screen.availHeight;
    screenX = window.screen.availWidth;
    nLeft=(screenX-Width)/2;
    nTop=(screenY-Height)/2;
    Properties="Toolbar=0,width=" + Width + ",height=" + (Height - 50)+ ",Resizable=no,Status=yes,Scrollbars=yes,Top=" + nTop + ",Left="+ nLeft;    
    url = 'https://enrollment.aeonthailand.com/th/inquiry_th.asp?ScreenStatus=true';
    if (lang == 'en') {
        url = 'https://enrollment.aeonthailand.com/en/inquiry.asp?ScreenStatus=true';
    }
    window.open(url,"_blank",Properties);

}

function openApplyScreen(url)
{
    var Width = 800;
    var Height =  window.screen.availHeight;
    var Properties,nTop,nLeft;
    var Width,Height;
    screenY = window.screen.availHeight;
    screenX = window.screen.availWidth;
    nLeft=(screenX-Width)/2;
    nTop=(screenY-Height)/2;
    Properties="Toolbar=0,width=" + Width + ",height=" + (Height - 50)+ ",Resizable=no,Status=yes,Scrollbars=yes,Top=" + nTop + ",Left="+ nLeft;    
	window.open(url,"_blank",Properties);

}
