var locale = '';
var serverName = '';

var strLang = '';
var strCountry = '';

var typPag = '';
var selectedVal = '';
var region = '';
$.fn.get_labels =function(opts){
var $this = $(this);
	
		typPag = opts.param;
		var currentURL = window.location.toString().split("/");
		var add = currentURL[2];
		webURL = window.location.href ;
		x = webURL.split("/");
		serverName = x[2];	
		region = jQuery('#hiddenlocale').html();
		strLocale = region.split("-");
		strLang = strLocale[0];	
		strCountry = strLocale[1];
		//alert(strLang);
		//alert(strCountry);
		
		if(serverName.match(/cmsprd/g) || serverName.match(/uslaxcmsqa/g) || serverName.match(/cms05/g))
		{
			navpath = '/xml/'+'Navigations.xml';
			path = "http://" + serverName + "/iw-cc/Herbalife/HerbalifeSports/" + "CountryTranslations.xml";
		}
		else
		{
			navpath = '/'+ region +"/xml/Navigations.xml";
			path = '/'+ 'Global' + '/' +'Herbalife' + '/' + 'HerbalifeSports' + '/' + 'CountryTranslations.xml';

		}
			



			$.ajaxSetup({
			type: 'GET',
			dataType: 'xml',
			async : false
		});
		
		$.ajax({
			url: path,
			success: function(xml) {
				if (typPag == 'BIOGRAPHY_ATHLETE' || typPag == 'BIOGRAPHY_TEAM')
			{
				
				writeBiographyLabels(xml,typPag);			
			}
			else if (typPag == 'event_landing' || typPag == 'home_landing')
			{
				//alert("here");
				writeschd(xml,typPag);			
			}
				else if (typPag == 'LIBRARY_ATHLETE' || typPag == 'LIBRARY_TEAM' || typPag == 'LIBRARY_PHOTO' || typPag == 'LIBRARY_VIDEO'  )
			{
				//alert("here");
				writeLibraryLabels(xml,typPag);			
			}
			else if (typPag == 'ATHLETE' || typPag == 'TEAM')
			{
				//alert("here");
				writeArticlesLibraryLabels(xml);	
				
			}

			else if (typPag == 'Events')
			{
				writeEvents(xml);			
			}
		},
		  error: function(xhr, textStatus, errorThrown){}
		});





function writeschd(xml,typPag){


	var strLangTemp = '';
	var strCountryTemp = '';
	
	var schedlabel = '';

	jQuery(xml).find('HLCountry').each(function()
	{		
		strLangTemp = jQuery(this).find('LanguageCode').text();
		strCountryTemp = jQuery(this).find('CountryISOCode').text();
		
		if ((strLangTemp == strLang) && (strCountryTemp == strCountry))
		{
			if(typPag == 'home_landing')
			{
				schedlabel = $(this).find('ScheduleInformation').find('GSMSchedLabel').text();
				schedlabel = getSchedType(schedlabel);
			}
			if(typPag == 'event_landing')
			{
				schedlabel = $(this).find('ScheduleInformation').find('EventSchedLabel').text();
			
			}
		}			
	});

	if (jQuery('#sprite-module-master').length > 0 )
	{
		jQuery('#sprite-module-master').html(schedlabel);
	}

	if (jQuery('#scsprite-module-master').length > 0 )
	{
		jQuery('#scsprite-module-master').html(schedlabel);
	}

	if (jQuery('#stsprite-module-master').length > 0 )
	{
		jQuery('#stsprite-module-master').html(schedlabel);
	}



}

function getSchedType(sched) {
	var schedlabel='';
	var schedlabelArr = new Array();
	var schedlabelType = '';
	schedlabel = sched;
		schedlabelArr = schedlabel.split(':');
				if(schedlabelArr.length > 0) {
					return schedlabel = schedlabelArr[0] + ':<span class="schedlabelType">' + schedlabelArr[1] + '</span>';
				}
			
}


		function writeBiographyLabels(xml,typPag)
{

//alert(typPag);
	//alert("in biography");
	var strLangTemp = '';
	var strCountryTemp = '';
	
	var strBiographyLabel = '';
	var strCountryLabel = '';
	var strTeamsLabel = '';
	var strAchievementsLabel = '';
	var strDownloadsLabel = '';
	var strAthletesNewsLabel = '';
	var strVideosLabel = '';
	var schedlabel = '';
	var favolabel = '';
	
	jQuery(xml).find('HLCountry').each(function()
	{		
	
		strLangTemp = jQuery(this).find('LanguageCode').text();
		strCountryTemp = jQuery(this).find('CountryISOCode').text();
		
		if ((strLangTemp == strLang) && (strCountryTemp == strCountry))
		{
			
			Allnewslabel = $(this).find('BiographyInformation').find('AllNewsLabel').text();
			Biographylabel = $(this).find('BiographyInformation').find('BiographyLabel').text();
			Countrylabel = $(this).find('BiographyInformation').find('CountryLabel').text();
			Achievementslabel = $(this).find('BiographyInformation').find('AchievementsLabel').text();
			downloadslabel = $(this).find('BiographyInformation').find('DownloadsLabel').text();
			sponsoredeventslabel = $(this).find('BiographyInformation').find('SponsoredEventsLabel').text();
			schedlabel = $(this).find('ScheduleInformation').find('GSMSchedLabel').text();
			schedlabel = getSchedType(schedlabel);
			favolabel = $(this).find('BiographyInformation').find('FavoprodsLabel').text();

			if(typPag == 'BIOGRAPHY_ATHLETE')
						{

			specific_news_label = $(this).find('BiographyInformation').find('AtheleteNewsLabel').text();
						}


						if(typPag == 'BIOGRAPHY_TEAM')
						{
			specific_news_label = $(this).find('BiographyInformation').find('TeamNewsLabel').text();
						}


VideosLabel = $(this).find('BiographyInformation').find('VideosLabel').text();
TeamsLabel = $(this).find('BiographyInformation').find('TeamsLabel').text();
			
			
		}
				
	});
	
	if (jQuery('#biography_label').length > 0 )
	{
		jQuery('#biography_label').html(Biographylabel);
	}
	
	if (jQuery('#country_label').length > 0 )
	{
		jQuery('#country_label').html(Countrylabel);
	}
	
	if (jQuery('#teams_label').length > 0 )
	{
		jQuery('#teams_label').html(TeamsLabel);
	}
	
	if (jQuery('#achievements_label').length > 0 )
	{
		jQuery('#achievements_label').html(Achievementslabel);
	}
	
	if (jQuery('#downloads_label').length > 0 )
	{
		jQuery('#downloads_label').html(downloadslabel);
	}
	
	
	if (jQuery('#athlete_news_label').length > 0 )
	{
		jQuery('#athlete_news_label').html(specific_news_label);
	}

		if (jQuery('#all_athlete_news_label').length > 0 )
	{
		jQuery('#all_athlete_news_label').html(Allnewslabel);
	}
	
	if (jQuery('#videos_label').length > 0 )
	{
		jQuery('#videos_label').html(VideosLabel);
	}

	if (jQuery('#sponsored_events_label').length > 0 )
	{
		jQuery('#sponsored_events_label').html(sponsoredeventslabel);
	}
	if (jQuery('#sprite-module-master').length > 0 )
	{
		jQuery('#sprite-module-master').html(schedlabel);
	}

	if (jQuery('#scsprite-module-master').length > 0 )
	{
		jQuery('#scsprite-module-master').html(schedlabel);
	}

	if (jQuery('#stsprite-module-master').length > 0 )
	{
		jQuery('#stsprite-module-master').html(schedlabel);
	}

		if (jQuery('#favProducts_label').length > 0 )
	{
		jQuery('#favProducts_label').html(favolabel);
	}


	
}



function writeEvents(xml)
{
//alert("In Events");
var strLangTemp = '';
	var strCountryTemp = '';
	
	var strBiographyLabel = '';
	var strCountryLabel = '';
	var strTeamsLabel = '';
	var strAchievementsLabel = '';
	var strDownloadsLabel = '';
	var strAthletesNewsLabel = '';
	var strVideosLabel = '';
	var schedlabel = '';
	
	jQuery(xml).find('HLCountry').each(function()
	{		
	
		strLangTemp = jQuery(this).find('LanguageCode').text();
		strCountryTemp = jQuery(this).find('CountryISOCode').text();
		
		if ((strLangTemp == strLang) && (strCountryTemp == strCountry))
		{
			Eventnewslabel = $(this).find('EventsInformation').find('EventNewsLabel').text();
GeneralInfolabel = $(this).find('EventsInformation').find('GeneralInformationLabel').text();
Eventlocationlabel = $(this).find('EventsInformation').find('EventLocationLabel').text();
Eventphotoslabel = $(this).find('EventsInformation').find('EventPhotosLabel').text();
Eventvideoslabel = $(this).find('EventsInformation').find('EventVideosLabel').text();
schedlabel = $(this).find('ScheduleInformation').find('EventSchedLabel').text();
			
			
		}
				
	});
	//alert(Eventnewslabel);
	if (jQuery('#all_athlete_news_label').length > 0 )
	{
		jQuery('#all_athlete_news_label').html(Eventnewslabel);
	}
	
	if (jQuery('#generalInformation_label').length > 0 )
	{
		jQuery('#generalInformation_label').html(GeneralInfolabel);
	}
	
	if (jQuery('#eventlocation_label').length > 0 )
	{
		jQuery('#eventlocation_label').html(Eventlocationlabel);
	}
	
	if (jQuery('#eventphotos_label').length > 0 )
	{
		jQuery('#eventphotos_label').html(Eventphotoslabel);
	}
	
	if (jQuery('#eventvideos_label').length > 0 )
	{
		jQuery('#eventvideos_label').html(Eventvideoslabel);
	}
	if (jQuery('#sprite-module-master').length > 0 )
	{
		jQuery('#sprite-module-master').html(schedlabel);
	}
	
	
	

}

// ********** LIBRARIES LABELS **********
function writeLibraryLabels(xml,typPag)
{

	//alert(typPag);
	var strLangTemp = '';
	var strCountryTemp = '';
	
	var strSponsoredAthletesTeamsLabel = '';
	var strSortByLabel = '';
	var strAllNewsLabel = '';
		
	jQuery(xml).find('HLCountry').each(function()
	{		
		//alert("innnnn");
	
		strLangTemp = jQuery(this).find('LanguageCode').text();
		strCountryTemp = jQuery(this).find('CountryISOCode').text();
		
		if ((strLangTemp == strLang) && (strCountryTemp == strCountry))
		{
			//alert(strLang);
			//alert(strCountry);

			if (typPag == 'LIBRARY_ATHLETE')
			{
				
				strSponsoredAthletesTeamsLabel = jQuery(this).find('LibraryInformation').find('SponsoredAthletesLabel').text();	
				strAllNewsLabel = jQuery(this).find('LibraryInformation').find('AllNewsLabel').text();
				sponsoredlabel = jQuery(this).find('LibraryInformation').find('AllNewsLabel').text();
				strSortByLabel = jQuery(this).find('LibraryInformation').find('SortByLabel').text();
				//alert(strAllNewsLabel);
				
				
			}
			else if (typPag == 'LIBRARY_TEAM')
			{
				strSponsoredAthletesTeamsLabel = jQuery(this).find('LibraryInformation').find('SponsoredTeamsLabel').text();
				strAllNewsLabel = jQuery(this).find('LibraryInformation').find('AllNewsLabel').text();
				sponsoredlabel = jQuery(this).find('LibraryInformation').find('AllNewsLabel').text();
				strSortByLabel = jQuery(this).find('LibraryInformation').find('SortByLabel').text();
				//alert(strAllNewsLabel);
			}
			
			else if(typPag == 'LIBRARY_VIDEO'){
			
			strSortByLabel = jQuery(this).find('LibraryInformation').find('SortByLabel').text();
			photovideolibrarytitle = jQuery(this).find('LibraryInformation').find('VideoLibraryLabel').text();
			videochanneltitle = jQuery(this).find('LibraryInformation').find('VideoChannelTitle').text();
			}
			
			else if(typPag == 'LIBRARY_PHOTO'){
			
			strSortByLabel = jQuery(this).find('LibraryInformation').find('SortByLabel').text();
			photovideolibrarytitle = jQuery(this).find('LibraryInformation').find('PhotoLibraryTitle').text();
			}

			strSortByLabel = jQuery(this).find('LibraryInformation').find('SortByLabel').text();
			strSponsoredeventsLabel = jQuery(this).find('LibraryInformation').find('SponsoredEventsLabel').text();
			newsroomlabel = jQuery(this).find('LibraryInformation').find('NewsRoomLabel').text();
			//alert(newsroomlabel);
			schedlabel = $(this).find('ScheduleInformation').find('GSMSchedLabel').text();
				schedlabel = getSchedType(schedlabel);

					
			
		}
				
	});
			
			
	
	
	if (jQuery('#sort_by_label').length > 0 )
	{
		jQuery('#sort_by_label').html(strSortByLabel);
	}
	
	if (jQuery('#all_news_label').length > 0 )
	{
		jQuery('#all_news_label').html(strAllNewsLabel);
	}


if (jQuery('#sponsored_events_label').length > 0 )
	{
		jQuery('#sponsored_events_label').html(strSponsoredeventsLabel);
	}
	
	if (jQuery('#sponsored_label').length > 0 )
	{
		jQuery('#sponsored_label').html(strSponsoredAthletesTeamsLabel);
	}
	


	if (jQuery('#newsroom_label').length > 0 )
	{
		jQuery('#newsroom_label').html(newsroomlabel);
	}
	
	if (jQuery('#media_label').length > 0 )
	{
		jQuery('#media_label').html(photovideolibrarytitle);
	}

	if (jQuery('#tabs_sprite_sidebar').length > 0 )
	{
		//salert("in if");
		//alert(videochanneltitle);
		jQuery('#tabs_sprite_sidebar').html(videochanneltitle);
	}


	if (jQuery('#sprite-module-master').length > 0 )
	{
		jQuery('#sprite-module-master').html(schedlabel);
	}

	if (jQuery('#scsprite-module-master').length > 0 )
	{
		jQuery('#scsprite-module-master').html(schedlabel);
	}

	if (jQuery('#stsprite-module-master').length > 0 )
	{
		jQuery('#stsprite-module-master').html(schedlabel);
	}

	
	

	
		
}

// ********** ARTICLES LIBRARIES LABELS **********
function writeArticlesLibraryLabels(xml)
{
	var strLangTemp = '';
	var strCountryTemp = '';
	
	var strSportsNewsroomTeamsLabel = '';
	var strSortByLabel = '';
	var strAllNewsLabel = '';
	var schedlabel = '';
		
	jQuery(xml).find('HLCountry').each(function()
	{		
	
		strLangTemp = jQuery(this).find('LanguageCode').text();
		strCountryTemp = jQuery(this).find('CountryISOCode').text();

		//alert(strLangTemp);
		//alert(strCountryTemp);
		
		if ((strLangTemp == strLang) && (strCountryTemp == strCountry))
		{

			//alert(strLangTemp);
		   //alert(strCountryTemp);

			
			if (typPag == 'ATHLETE')
			{					
				strAllNewsLabel = jQuery(this).find('ArticleInformation').find('AtheleteNews').text();
				//alert(strAllNewsLabel);
				
			}
			else if (typPag == 'TEAM')
				
			{			
				strAllNewsLabel = jQuery(this).find('ArticleInformation').find('TeamNews').text();
				//alert(strAllNewsLabel);
				
			}

			schedlabel = $(this).find('ScheduleInformation').find('GSMSchedLabel').text();
				schedlabel = getSchedType(schedlabel);

			
			jQuery('#all_athlete_news_label').html(strAllNewsLabel);


				if (jQuery('#sprite-module-master').length > 0 )
				{
		jQuery('#sprite-module-master').html(schedlabel);
				}


					if (jQuery('#scsprite-module-master').length > 0 )
				{
		jQuery('#scsprite-module-master').html(schedlabel);
				}

					if (jQuery('#stsprite-module-master').length > 0 )
				{
		jQuery('#stsprite-module-master').html(schedlabel);
				}
	
			
			
		}
				
	});
			
	

	
}



} ;




