/*
 * JS for work with phonesLayer.xhtml
 * 
 *  Show and hide the layer, read and write (or build) cookie with country code selected on layer.
 *  Define names of html elemets of the layer.
 * 
 *  REQUIRED commons.js and cookies.js
 */

var COOKIE_PHONE = 'cookiePhone';
var phoneCookiesOptions = {duration: 365};

var INPUT_CODE_COUNTRY = 'phoneCountryCodeDefault';
var LAYER_PHONE_COUNTRY = 'layerPhoneCountry_';
var LAYER_PHONE_NUMBER = 'layerPhoneNumber_';
var HEADER_PHONE_COUNTRY = 'phoneCountry';
var HEADER_PHONE_NUMBER = 'phoneNumber';
var PHONES_LAYER = 'layerPhones';

var CLASS_ACTIVE = 'activo';

var currentCountryCode = "";

function initLayerPhones(){
	if(get(HEADER_PHONE_COUNTRY) == null) return;
	var cookieValue = getCookieValue(COOKIE_PHONE);
	if(cookieValue == null){
		cookieValue = getValue(INPUT_CODE_COUNTRY);
		if(cookieValue == 'EN' || cookieValue == 'PT') cookieValue = 'GA'; //Global Access
	}
	currentCountryCode = cookieValue;
	get(HEADER_PHONE_COUNTRY).innerHTML = get(LAYER_PHONE_COUNTRY + currentCountryCode).innerHTML;
	get(HEADER_PHONE_NUMBER).innerHTML = get(LAYER_PHONE_NUMBER + currentCountryCode).innerHTML;
	addClass(get(LAYER_PHONE_COUNTRY + currentCountryCode), CLASS_ACTIVE);
}

function changePhone(countryCode){
	writeCookie(COOKIE_PHONE, countryCode, phoneCookiesOptions);	
	get(HEADER_PHONE_COUNTRY).innerHTML = get(LAYER_PHONE_COUNTRY + countryCode).innerHTML;
	get(HEADER_PHONE_NUMBER).innerHTML = get(LAYER_PHONE_NUMBER + countryCode).innerHTML;
	
	removeClass(get(LAYER_PHONE_COUNTRY + currentCountryCode), CLASS_ACTIVE)
	addClass(get(LAYER_PHONE_COUNTRY + countryCode), CLASS_ACTIVE);
	
	currentCountryCode = countryCode;
	
	showHide('layerPhones');
}