// Temporoary included functions

       function GetElementByIdEndsWith(tagName, endsWith) {
                  var elements =
             document.getElementsByTagName(tagName);

                  for (var i = 0; i < elements.length; i++) {
                      if (elements[i].id.endsWith(endsWith)) {
                          return elements[i];
                      }
                  }

                  return null;
              }

              String.prototype.endsWith = function(txt, ignoreCase) {
                  var rgx;

                  if (ignoreCase) {
                      rgx = new RegExp(txt + "$", "i");
                  }
                  else {
                      rgx = new RegExp(txt + "$");
                  }

                  return this.match(rgx) != null;
              }

		  function getParameterByName( name ) 
{ 
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
  var regexS = "[\\?&]"+name+"=([^&#]*)"; 
  var regex = new RegExp( regexS ); 
  var results = regex.exec( window.location.href ); 
  if( results == null ) 
    return ""; 
  else 
    return results[1]; 
} 

function SortByList(list,path)
{
	if(path.indexOf("?") != -1)
	{
		if(getParameterByName("sortby")!='')
		{
			var newPath = path.replace("sortby="+getParameterByName("sortby"), "sortby="+list.options[list.selectedIndex].value);
			window.location.replace(newPath);
			
		}
		else
		{
			window.location.replace(path + "&sortby="+list.options[list.selectedIndex].value); 
		}
		
	}
	else
	{
		window.location.replace(path + "?sortby="+list.options[list.selectedIndex].value); 
	}    
}

/*hardcoded to remove the view all link which should not exist in the primary nav*/
$(document).ready(function(){

$('#DvContentPopup3 div:last').css({display:'none'});
$('#DvContentPopup2 div:last').css({display:'none'});
$('#DvContentPopup1 H2').css({display:'none'});

if($('.productBulletStyleDesc:last').length > 0)
{
	if($(".ProductDetailProductDescription").length > 0)
	{
		if($.trim($(".ProductDetailProductDescription").html().substring($(".ProductDetailProductDescription").html().indexOf($('.productBulletStyleDesc:last').html())+$('.productBulletStyleDesc:last').html().length+10)) == "")
		{
			$('.productBulletStyleDesc:last').css({'margin-bottom':'0px'});
		}
	}
}

if($('.productBulletStyle:last').length > 0)
{

	if($(".productInformation").length > 0)
	{
		if($.trim($(".productInformation").html().substring($(".productInformation").html().indexOf($('.productBulletStyle:last').html())+$('.productBulletStyle:last').html().length+10)) == "")
		{
			$('.productBulletStyle:last').css({'margin-bottom':'0px'});
		}
	}
}






});

/*hardcoded need to remove once shoppinglist is fixed.*/
$(document).ready(function(){

if ($('.wishListSimplifiedItemRow').length >= 1)
{
	$('.continueShoppingLink').css({display:'none'});
}

//added code to hide the button text.  To be removed once code change is complete
$('.go input').attr('value', '');
$('.actions input').attr('value', '');

$('.submitCancelButtons .cancel a').css({clear:'left'});


//added code to Quickly patch up links

$(".menuAlignRight a").attr("href", "/pages/offers.aspx");
$('.caratlabel').each(

function() {

 var link = $(this).attr('href');
 
 if(link == "OlayWebPresentation")
 {
	$(this).attr('href', '/pages/securejoinclubolay.aspx');
 }
 

 }

)



});

/*Added additional functionality to buyAll in simplifed shoppinglist*/
$(document).ready(function(){

	if($('.wishListSimplifiedBuyNow').length > 0)
	{
		
		var cookieValue = $.cookie('olayWishList');
		var cookieArray = cookieValue.split(";");
		var link = $('.wishListSimplifiedBuyNow a').attr('href');
		if(cookieArray.length > 2)
		{
			var newValue = "";
			for ( var i in cookieArray)
			{
			  	if(cookieArray[i] !="")
				{
					 newValue = newValue + cookieArray[i] + "|1,";
				}
			}
		
			$('.wishListSimplifiedBuyNow a').attr('href', link + "?view=buyall&pidList=" + newValue);
		
		}
		else
		{
			$('.wishListSimplifiedBuyNow a').attr('href', link + "?pid="+cookieArray[0]);
		}
		
  
	}
	

});

/*temporary fix the article issues */

$(document).ready(function(){

if($('.articleItem').length >0)
{

	$('.articleItem a').each(

		 function() {

	     if($(this).attr('href').toLowerCase().indexOf("//pages//") != -1)
	     {
	     	correctedVal = $(this).attr('href').toLowerCase().replace("//pages//", "/pages/");
	     	$(this).attr('href', correctedVal);
	     }
	}

)



	
}


	



});

$(document).ready(function(){

if($('.boutiqueListingGridViewLink a').length == 1)
{
	var link = window.location.href.toLowerCase();
	if(link.indexOf("products") != -1)
	{
		$('.boutiqueListingGridViewLink a').attr('href',link.replace("products", "grid"))
	}	
}

if($('.boutiqueListingListViewLink a').length == 1)
{
	var link = window.location.href;
	if(link.indexOf("grid") != -1)
	{
		$('.boutiqueListingListViewLink a').attr('href',link.replace("grid", "products"))
	}	
}

$('.steps a').each(

function() {

 var link = $(this).attr('href').replace(/ /g , '');
 
 $(this).attr('href', link.replace(/%20/g,''));

 }

)


});



/*pagination still need cleanup*/
$(document).ready(function(){


if(!isNaN(parseInt($('#pagingItemCount').text())))
{

var pageValue = parseInt($('#pagingItemCount').text());
var maxPageValue = Math.ceil(parseInt($('#totalItemCount').text())/pageValue);	
var text = '';

if(window.location.href.indexOf("?") != -1)
{
	if(getParameterByName("pages") !='')
	{	
	    var val = parseInt(getParameterByName("pages"));	
	
		
		
	
			if(val == 0)
			{
				text  = text + "<a href='" + window.location.href.replace("pages="+getParameterByName("pages"),"pages=1") + "'> View " + pageValue + " per page" + "</a>";
				$('.gridPagination').html(text);
				$('.gridPaginationBottom').html(text);
			}
			else
			{
		
				for(i=0; i<maxPageValue; i++)
				{
					if(val == i+1)
					{
						text = text + "<a style='text-decoration:underline' href='" + window.location.href.replace("pages="+getParameterByName("pages"), "pages=" + (i+1)) + "'>" + (i+1) + "</a>";
					}
					else
					{
						text = text + "<a href='" + window.location.href.replace("pages="+getParameterByName("pages"), "pages=" + (i+1)) + "'>" + (i+1) + "</a>";
					}

				}
				text = text + "<a href='#'> | </a>" + "<a href='" + window.location.href.replace("pages="+getParameterByName("pages"), "pages=0") + "'>View All</a>";
				$('.gridPagination').html(text);
				$('.gridPaginationBottom').html(text);

				
			}
			
			
	
		
	}
	else
	{
		for(i=0; i<maxPageValue; i++)
		{
			text = text + "<a href='" + window.location.href + "&pages=" + (i+1) + "'>" + (i+1) + "</a>";
		}
		text = text + "<a href='#'> | </a>" + "<a href='" + window.location.href + "&pages=0'>View All</a>";
		$('.gridPagination').html(text);
		$('.gridPaginationBottom').html(text);

	
	}
	
	
}
else
{
	for(i=0; i<maxPageValue; i++)
	{
		text = text + "<a href='" + window.location.href + "?pages=" + (i+1) + "'>" + (i+1) + "</a>";
	}
	text = text + "<a href='#'> | </a>" + "<a href='" + window.location.href + "?pages=0'>View All</a>";
	$('.gridPagination').html(text);
	$('.gridPaginationBottom').html(text);


}


}



});




// JavaScript Document

function show(val){
	 document.getElementById("div"+val).style.display="block"
	 document.getElementById("row"+val).style.borderBottomColor="#d4aa54"
	 document.getElementById("row"+val).style.borderTopColor="#d4aa54"
	 document.getElementById("row"+val).style.borderLeftColor="#d4aa54"
}

function hide(val){
	 document.getElementById("div"+val).style.display="none"
	  document.getElementById("row"+val).style.borderBottomColor="#080605"
	 document.getElementById("row"+val).style.borderTopColor="#080605"
	 document.getElementById("row"+val).style.borderLeftColor="#080605"
	 	 
}

//tree menu//
 

					
			function toggleBB(srcElement,srcArrow,loc) 
			{
				if (document.getElementById(srcElement).style.display == "none") 
				{
					document.getElementById(srcElement).style.display = "";					
				} 
				else
				{
					document.getElementById(srcElement).style.display = "none";
				}
				
			}
						
			function toggleBB2(srcElement,srcArrow,loc) 
			{
				if (document.getElementById(srcElement).style.display == "none") 
				{
					document.getElementById(srcElement).style.display = "";
					document.getElementById(srcArrow).src="/PublishingImages/expand.gif";					
				} 
				else
				{
					document.getElementById(srcElement).style.display = "none";
					document.getElementById(srcArrow).src="/PublishingImages/collapse.gif";

				}
				
			}
			
			
	
			function hideallDivs()
			{	
				document.getElementById('DivOFR1').style.display = "none";
				document.getElementById('DivOFR2').style.display = "none";
				document.getElementById('DivOFR3').style.display = "none";
				document.getElementById('DivOFR4').style.display = "none";
				document.getElementById('DivOFR5').style.display = "none";
				document.getElementById('DivOFR6').style.display = "none";
			}

		
/* 
	Toggle Country window
*/
function toggle_country_selection() {
	var _id_selector = 'countryOverlay';
	var _div_element  = document.getElementById(_id_selector);
	if (  _div_element === null ) 
	{
			try { console.log("Unable to find element with id \"" + _id_selector + "\"") } catch(err) { /* silent */ }
			return false;
	}
	switch ( _div_element.style.display) {
		case "block" :
			_div_element.style.display = "none";
			break;
		default :
			_div_element.style.display = "block";
	}
	
} 	
//--> 