

/*CREATOR: MY 18.12.14
	Set cookies of language&Country;
*/
if (typeof console === "undefined" || typeof console.log === "undefined") {
     console = {};
     console.log = function() {};
}

function CookieloginSet() {
	var set = {};
	var siteDomain = $('#siteDomain').text();
	var path = '';
	if (!$.cookie("apex__country") || !$.cookie("apex__language")){
		$('#contryLang .CountryCode').each(
			
		   function(index,elem){
			  var cc = $(elem).text();
			  set[cc]= true;
		   });
		
		
		jQuery.ajax( { 
			url: '//freegeoip.net/json/', 
			type: 'POST', 
			dataType: 'jsonp',
			success: function(location) {
				
				
				if (location.country_code && location.country_code in set ){
					updateCookie('country',location.country_code);
					updateCookie ('language', $('#'+location.country_code+' .LangugageCode').text());
					
				}
				else{
					updateCookie ('country','INT');
					updateCookie ('language', 'en');
					
				}
			},
			error: function(){
				updateCookie ('country','INT');
				updateCookie ('language', 'en');
				
			},
			timeout: 2000	
		} );
	}
	
	
}

function updateCookie(cookieName , cookieValue){ 
		var date = new Date();
		date.setTime(date.getTime()+(365*10*24*60*60*1000));   //set expire 10 years
		if(cookieValue){
				document.cookie = 'apex__'+cookieName+'='+cookieValue + ';' + 'path=/; expires=' +date.toGMTString(); +';'
		}			
}
CookieloginSet();