// function to retrieve the information that user have saved in the system
function getLanguageStatus() {
   if ( getCookie('LanguageTransysa') == 0 ) {
      // if there is not define the cookie the page asign by default the language of the system and save it in the cookie
	  setCookie('LanguageTransysa', getLanguage() );
   }
   return getCookie('LanguageTransysa')
}

function goToLanguagePage( origin ) {
   x = getLanguageStatus();

  switch(x) {
      case "en": switch( origin ) {
		             case "index": window.location = "en/home/index.shtml"; break;
					 case "Transysa - Financial Institutions": window.location = "../../en/financial/fin.shtml"; break;
					 case "Transysa - Consumers": window.location = "../../en/consumers/consumers.shtml"; break;
					 case "Transysa - Retailers": window.location = "../../en/retailers/retailers.shtml"; break;
					 default: window.location = "../../en/home/index.shtml";
	             }
				 break;
	  case "sp": switch( origin ) {
		             case "index": window.location = "en/home/index.shtml"; break;
					 case "Transysa - Financial Institutions": window.location = "../../en/financial/fin.shtml"; break;
					 case "Transysa - Consumers": window.location = "../../en/consumers/consumers.shtml"; break;
					 case "Transysa - Retailers": window.location = "../../en/retailers/retailers.shtml"; break;
					 default: window.location = "../../en/home/index.shtml";
	             }
				 break;
	  default: switch( origin ) {
		             case "index": window.location = "en/home/index.shtml"; break;
					 case "Transysa - Financial Institutions": window.location = "../../en/financial/fin.shtml"; break;
					 case "Transysa - Consumers": window.location = "../../en/consumers/consumers.shtml"; break;
					 case "Transysa - Retailers": window.location = "../../en/retailers/retailers.shtml"; break;
					 default: window.location = "../../en/home/index.shtml";
	             } 
   }
}

function setLanguageStatus( langToAsign, pageOrigin ) {
   setCookie( 'LanguageTransysa', langToAsign );
   goToLanguagePage( pageOrigin );
}

// function to select the language by default
function getLanguage() {
   var lang=navigator.userLanguage?navigator.userLanguage:navigator.language
   return lang.substr(0,2)
}

//
// JavaScript cookie functions
//
function getCookie(name) {
   var cookies=document.cookie.split('; ')
   if (document.cookie=='') cookies.length=0
   for (var i=0;i<cookies.length;i++)
      if (cookies[i].indexOf(name+'=')==0) {
         var value=unescape(cookies[i].split('=')[1])
         return isNaN(value)?value:parseInt(value)
      }
   return void 0
}

function setCookie(name,value) { 
  document.cookie=name+'='+value+'; path=/' 
}