//BROWSER DETECTION: RETURNS WHETHER IT'S A ROGUE BROWSER && THE NAME
var thisAgent = "";
var rogueAgent = false;
function browserDetect(){
	userAgent = navigator.userAgent.toLowerCase(); $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); thisAgent = "" + $.browser.version.substring(0, 1);
	if ($.browser.msie) { thisAgent = "browserIE" + $.browser.version.substring(0, 1); if (thisAgent.toLowerCase() == "browserie7") { rogueAgent = true; } if (thisAgent.toLowerCase() == "browserie6") { rogueAgent = true; } }
	if ($.browser.chrome) { userAgent = userAgent.substring(userAgent.indexOf('chrome/') + 7); userAgent = userAgent.substring(0, 1); thisAgent = "browserChrome" + $.browser.version.substring(0, 1); $.browser.safari = false; }
	if ($.browser.safari) { userAgent = userAgent.substring(userAgent.indexOf('version/') + 8); userAgent = userAgent.substring(0, 1); thisAgent = "browserSafari" + userAgent; }
	if ($.browser.mozilla) { if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1) { userAgent = userAgent.substring(userAgent.indexOf('firefox/') + 8); userAgent = userAgent.substring(0, 1); thisAgent = "browserFirefox" + userAgent.substring(0, 1); } else { thisAgent = "browserMozilla"; } }
	if ($.browser.opera) { thisAgent = "browserOpera"; }
	return rogueAgent, thisAgent;}

//SOCIAL LINKS
var strUrl = "http://www.supersavvyme.com/olaywakeupwonder/login.aspx?ReturnUrl=http%3a%2f%2fwww.supersavvyme.com%2folaywakeupwonder%2fhome.aspx%3fCampaignId%3d69cdfbb2-ed4c-4329-a006-e2bced08386f#";
var strUrl2 = "http://www.supersavvyme.com/olaywakeupwonder/";
function fbs_click() {u=strUrl;t='I just got a free sample of Olay\'s new total effects wake up wonder moisturiser. Follow the link below to get yours:';window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer');return false;}
function twitter(){u=strUrl2;t='I got a free sample of Olay\'s new total effects moisturiser. Get yours here:';window.open('http://twitter.com/home?status='+encodeURIComponent(t)+'+'+encodeURIComponent(u),'twitter');return false;}

//POP UP
function vpos(objDiv){var windowHeight = document.documentElement.clientHeight;var scrollPosition = $(window).height() + $(window).scrollTop();var iwindowHeight = (scrollPosition - windowHeight);	return iwindowHeight + 164;}
function hpos(objDiv){return (document.documentElement.clientWidth/2)-($(objDiv).width()/2);}


(function($) {
	$.fn.popup = function(options) {
		var config = { objbg:'', objbox:''};
		if (options) $.extend(config, options);
		$(config.objbg + ', #terms-close, #ingredients-close').live('click', function() {
			if(thisAgent.match('browserIE')){$('.lg-visible').hide();}
			else{$('.lg-visible').fadeOut('slow');}
			
			$(this).removeClass('lg-visible');
			return false;
		});
		
		$(this).click(function() {
			if(!thisAgent.match('browserIE'))
			{
				$(config.objbg).css({ 'height': document.documentElement.clientHeight, 'opacity': '0.75' }).fadeIn('slow').addClass('lg-visible');
				$(config.objbox).css({ 'position': 'absolute', 'top': vpos(config.objbox) + 12, 'left': hpos(config.objbox) }).addClass('lg-visible').fadeIn('slow');
			}
			else
			{
				$(config.objbg).css({ 'width': document.documentElement.clientWidth, 'height': document.documentElement.clientHeight, 'opacity': '0.75' }).show().addClass('lg-visible');
				$(config.objbox).css({ 'position': 'absolute', 'top': vpos(config.objbox) + 12, 'left': hpos(config.objbox) }).addClass('lg-visible').show();
			}
			return false;
		});
		return this;
	};
})(jQuery);

//CHX TERMS READ
(function($) {
	$.fn.readterms = function() {
		$(this).click(function() {
			if($('#terms-agree').is(':checked')){return true;}
			$('.home-bx-mid LABEL').addClass('errmsg');
			$('.home-bx-mid LABEL SPAN').html('*');	
			return false;
		});
		return this;
	};
})(jQuery);

//CHX TERMS READ
(function($) {
	$.fn.readtermsEm = function() {
		$(this).click(function() {
			if($('#terms-agree').is(':checked'))
			{
				$('.mgm-terms LABEL').removeClass('errmsg');
				$('.mgm-terms LABEL SPAN').html('');
					
				return true;
			}
			$('.mgm-terms LABEL').addClass('errmsg');
			$('.mgm-terms LABEL SPAN').html('*');	
			
			return false;
		});
		return this;
	};
})(jQuery);

//ROLLOVER
(function($) {
	$.fn.rollOverThis = function() {
		var strtype = "";
		$(this).hover(function() {				
				strtype = findexts($(this).attr("src"));
				
				if($(this).attr("src").indexOf("on.") == -1) {
					var newSrc = $(this).attr("src").replace("off."+strtype+"","on."+strtype+"#hover");
					$(this).attr("src",newSrc);
				}
			},
			function(){
				if($(this).attr("src").indexOf("on."+strtype+"#hover") != -1) {
					var oldSrc = $(this).attr("src").replace("on."+strtype+"#hover","off."+strtype+"");
					$(this).attr("src",oldSrc);
				}
			}
		);
		return this;
	};
})(jQuery);



$(document).ready(function() {
	browserDetect();
	$('#ingredients-open').popup({objbg:'#bg-wrap', objbox:'#ingredients-wrap'});
	
	$('.form_buttons #ctl00_WebPartManager1_wp1201264120_ctl00_imgBtnSend').readtermsEm();
	$('.form_buttons #ctl00_WebPartManager1_wp1103898551_ctl00_imgBtnSend').readtermsEm();
	
	$('.social-links-fb').click(function(){fbs_click();});
	$('.social-links-tw').click(function(){twitter()});
	
	var checkLostPasswordPage = $('.PaddingLogin .MemberHeader h1').text();
	
	if(checkLostPasswordPage == "Password forgotten"){
		/*PASSWORD FORGOT*/
		$('#share').hide();
		$('body').addClass('lostpassword');
		$('.PaddingLogin .MemberHeader h1').text("Password reminder");
		$('.Membercontainer .calageinnercontainer .padbottom12').html('Your password has just been sent to your email box<br><br>See you right away!<br><br>The supersavvyme team. ');
		$('#ctl00_WebPartManager1_wp750451364_ctl00_ImageHome').attr('src','/ITGCFiles/BrandSite/OlayWakeUpWonder2/btn-gotosupersavvyme.jpg');
		$('#ctl00_WebPartManager1_wp750451364_ctl00_HyperLinkBtnAccueilBack').attr('href','home.aspx');
	}	
	else
	{
		$('#ctl00_WebPartManager1_wp750451364_ctl00_PanelLogin .NotMemberHeader h1').text('New to supersavvyme?');		
		$('#ctl00_WebPartManager1_wp750451364_ctl00_PanelLogin .notmemberwrapper .txtLoginMemberSmallFont').html('<p>Supersavvyme.com is a fabulous new site with ideas, inspiration and wisdom to help you make the most out of life. Registering only takes a few moments, and gives you access to lots of exclusive offers and extras.</p>');		
	}
});


