/*This script detects the following: 
Flash Windows Media Player Java 
Shockwave RealPlayer QuickTime Acrobat Reader 
SVG Viewer
*/
var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win) {	pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
		nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}

function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

//SAMPLE USAGE- detect "Flash"
//if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")
var detectFlash = pluginlist.indexOf("Flash") != -1;
var promotionTitle="Coke Zone";
var wtUri="cokezone";
var doTask=false;
var knownUserForSiteMap = null;
var contextRoot = "/home";

var encryptClassName = "Encrypted";
var isPromotionClosed="false";
var isPromoHomeFired="false";
var secLinkSel='';
var pinmessage = "";
var pinresponse = false;
var pintextfocus = false;
var divIdToEnable='';
var enabletip=false
var tipobj;
var loginBackURL="";
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
var addthis_pub = "rpowl";
var addthis_offset_top = 0;
var addthis_offset_left = 15;
var designStored = "true";

$.fn.ajaxSubmit = function(successHandler, contentType) { 
	/* Change a form's submission type to ajax */ 
	this.submit(function(){ 
		var params = {ajaxRequest: "true"}; 
		$(this) .find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea") .filter(":enabled") .each(function() { 
			var paramValue = $(this).is("." + encryptClassName) ? base64Encode(encrypt(this.value)) : this.value;
			if (this.checked){
				if(!params[this.name]) {
					var paramValueArray = [paramValue];
					params[this.name] = paramValueArray;
				} else {
					params[this.name].push(paramValue);
				}

			} else {
				params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = paramValue; 
			}
		});
		var submitButton = $(this) .find("input[@type='submit']"); 
		$(submitButton).attr("disabled", "true");
		$(submitButton).val(waitMessage);
		var response =$.post(this.getAttribute("action") , params, function(data) {
			var refreshPage = response.getResponseHeader('GRLP-Refresh-Page');
			var refreshPageURL = response.getResponseHeader('GRLP-Refresh-PageURL');
			if (refreshPage == "true") {
				window.location.href=refreshPageURL;
			} else {
				successHandler(data);
			}
		}, contentType); 
		return false; 
	}); 
	return false; 
}

$.fn.ajaxSubmitCheckout = function(successHandler, contentType) { 
	/* Change a form's submission type to ajax */ 
	this.submit(function(){ 
		var params = {ajaxRequest: "true"}; 
		$(this) .find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], option[@selected], textarea") .filter(":enabled") .each(function() { params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = $(this).is("." + encryptClassName) ? base64Encode(encrypt(this.value)) : this.value; });
		var submitButton = $(this) .find("#"); 
		$(submitButton).attr("disabled", "true");
		$(submitButton).val(waitMessage);
		params[$("#getthisnow").attr("name")]=$("#getthisnow").val();
		var response =$.post(this.getAttribute("action") , params, function(data) {
			var refreshPage = response.getResponseHeader('GRLP-Refresh-Page');
			var refreshPageURL = response.getResponseHeader('GRLP-Refresh-PageURL');
			if (refreshPage == "true") {
				window.location.href=refreshPageURL;
			} else {
				successHandler(data);
			}
		}, contentType); 
		return false; 
	}); 
	return false; 
}

function forgotPassword() {
	$.get(contextRoot + "/login/forgotPassword.jsp" , function(value) {
		displayIdContent('#popupContent',value);
		
		$("#popupContent").show();
	});
}

$.fn.forgotPwdProcessed = function (results){
	displayIdContent("#popupContent",results);

}

function refreshCaptcha(div){
	$("#"+div).load(contextRoot + "/common/jCaptcha.jsp");
}

function showPopup() {
	$("#commonPopup").show(); 
}

function logIn() {
	if(designStored != "false") {
		var loginParams = "";
		if (loginBackURL != "") {
			loginParams={backURL:loginBackURL};
		}
		loginParams.unforcedLogin="true";
		$.get(contextRoot + "/login/login.jsp" , loginParams, function(value) {
			displayIdContent("#popupContent",value);

			$("#commonPopup").show();
		});
	}
}

function logInWithBackURL(back_url,specialErrorURL) {	
	var loginParams = "";
	if (loginBackURL != "") {
		loginParams={backURL:back_url,"specialErrorURL":specialErrorURL,"noRegistration":"true"};
	}
	loginParams.unforcedLogin="true";
	$.get(contextRoot + "/login/login.jsp" , loginParams, function(value) {
		displayIdContent("#popupContent",value);

		$("#commonPopup").show();
	});
}


function closeLoginPopup(){	
	$("#commonPopup").hide();
}


function enableButton() {
    if(document.getElementById(divIdToEnable) != null && isGetThisNowButtonDisabled == 'false') {
        if(divIdToEnable == 'getthisnow'){
            document.getElementById(divIdToEnable).disabled = disabledState;
        }
        else {
            document.getElementById(divIdToEnable).disabled = false;
        }
    document.getElementById(divIdToEnable).value=labelValueBeforeDisable;
    }
}

function disableButton(buttonIdToDisable, textToDisplay) {
    labelValueBeforeDisable=document.getElementById(buttonIdToDisable).value;
    divIdToEnable=buttonIdToDisable;
    document.getElementById(buttonIdToDisable).value=document.getElementById(textToDisplay).value;
    document.getElementById(buttonIdToDisable).disabled = true;

}

/*
*
* This function is used to display home by calling grlp_middle.jsp and then rendering the html wid new value
*
*/
function displayHome() {
    if (document.getElementById('homepage-id')){
        loadHomePage();
    }
}

function loadHomePage(){
	window.location.href = contextRoot + "/index.jsp";
}


function addNugget(){
	$.get(contextRoot + "/common/addNugget.jsp");
}

function showConsumptionSurvey(URL){
	$.load(contextRoot+URL+"?nextURL=/marketPostProcessing/welcomeConsumptionSurvey.jsp");	
}



function resetPassword() {
	$("#resetForm").ajaxSubmit($.fn.processResetPasswordData, "json");
}

$.fn.processResetPasswordData = function (results){ 
	if (results.status == "error") {
          var html="";
        for (var i=0;i<=results.errors.length-1; i++ ) {
            html = html + results.errors[i].c + "<br>";
        }
        document.getElementById("reset-errors-div").innerHTML = html;
        document.getElementById("resetForm").reset();
        if((results.status=="error")&&(results.enterfirst=="error") && (results.entersecond=="error")){
            document.getElementById("enter-new-password").style.borderColor="red";
            document.getElementById("passwordtext1").style.color="red";
            document.getElementById("passwordtext2").style.color="red";
            document.getElementById("reenter-new-password").style.borderColor="red";
        } else if((results.status=="error")&&(results.enterfirst=="error")&&(results.entersecond!="error")){
            document.getElementById("enter-new-password").style.borderColor="red";
            document.getElementById("passwordtext1").style.color="red";
            document.getElementById("passwordtext2").style.color="black";
            document.getElementById("reenter-new-password").style.borderColor="#ccc";
        } else if((results.status=="error")&&(results.entersecond=="error")&&(results.enterfirst!="error")){
            document.getElementById("reenter-new-password").style.borderColor="red";
            document.getElementById("passwordtext1").style.color="black";
            document.getElementById("passwordtext2").style.color="red";
            document.getElementById("enter-new-password").style.borderColor="#ccc";
        }
        enableButton();
     } else {
			$.get(contextRoot + "/login/resetPasswordSuccess.jsp" , function(value) {
				document.getElementById('reset-password-div').style.display = 'none';
                document.getElementById('knownuser-login-div').style.display = 'none';
                document.getElementById('reset-pass-success-div').innerHTML = value;
                document.getElementById('reset-pass-success-div').style.display = 'block';
			});
     }
}



function reloadTopNav(URLParameter)
{
	$.post(contextRoot + "/catalog/top-nav.jsp" , { idParam: URLParameter } , function(data) {
		document.getElementById('tabNav').innerHTML = data;
	});
}

function onIndexLoad(){
    setCookie('SiteVisited', 'true', 3600000);
    jumpScroll();
    isPromotionClosed="true";
    isPromoHomeFired="false";
    sniffernet=2;
}

function setCookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    if (navigator.userAgent.indexOf("Safari") != -1) {
	    document.cookie=c_name+ "=" +  escape(value);
    } else {
    	document.cookie=c_name+ "=" +  escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
    }
}


function jumpScroll() {
    window.scroll(130,0); // horizontal and vertical scroll targets
}

function displayNextBanner() {	  
     try {
         if (curRotBannerValue) {
             curRotBannerValue.style.display = 'none';
             do {
                 curRotBannerValue = curRotBannerValue.nextSibling;
             } while (curRotBannerValue.nodeType != 1);
         } else {
             curRotBannerValue = document.getElementById('image0');
         }
         curRotBannerValue.style.display = 'block';		 
    }catch(e) {
        curRotBannerValue = document.getElementById('image0');
        if (curRotBannerValue) {
            curRotBannerValue.style.display = 'block';            
        }
    }    
    bannerDisplayEvent();
}

function bannerDisplayEvent() {
	var $span = $(curRotBannerValue).find("span:first");
	//alert($span.length); 			
   	if($span.length > 0) {   		
   			//alert($span.attr("id")); 		
    		eval($span.attr('id'));
    }
}


var pointsAfterLogin=0;
var pointsAfterLoginForKnownUser=0;
var handleRewardSubmitNode="";

var isFromAllRewards="false";
var isFromSearch="false";
var promoTitle="Coke Zone";
  

function whatIsCode(){
	if(designStored != "false") {
		$.get(contextRoot + "/pinEntry/whatIsCode.jsp" , function(value) {
			displayIdContent("#popupContent",value);

			$("#commonPopup").show();
			//activeXContent();
		});
	}
}

function hideWhatIsCode(){
	$("#commonPopup").hide();
}


function loadWtSessionValuesForRewards(productId,productType, urlParameters){
    $.get(contextRoot + "/catalog/webTrendsDetails.jsp?"+urlParameters);
}


function pinResponseMessage() {
    pinresponse = false;
}

/* Clears the fields if the user cancels the operation */
function clearForgotPwdFields() {
    document.getElementById('pwdForm').reset();
    document.getElementById('forgot-pass-div').style.display='none';
    document.getElementById('forgot-pass-success-div').style.display='none';
    document.getElementById('forgot-pass-div').innerHTML = "";
}

function refreshCaptchaForgotPwd() {
	$.get(contextRoot+"/common/jCaptcha.jsp", function(value){
		document.getElementById('captcha').innerHTML=value;
        document.getElementById('securityCode').value="";
	});
}


function trimurl(){
    var mainurl = window.location.href;
    lengt = mainurl.length;
    var incr=0;
     for(count=0;count<lengt;count=count+1){
        if(mainurl.charAt(count)=='?')
         {
         break;
         }
     }
     str=mainurl.substring(0,count);
     window.location.href=str;
}


function checkEnter(event,view,tot,rec)
{
    if(event){
        if(event.keyCode == 13) {
            gotoSearchView(view,tot,rec);
        }
    }else if(evt){
        if(evt.keyCode == 13) {
            gotoSearchView(view,tot,rec);
        }
    }
}

function moreHotRewards(categoryId, startIndex) {
	$("#hot-rewards-id").load(contextRoot+"/common/hotRewardsPanel.jsp", {"id": categoryId, "start": startIndex});
}
var isPinBoxOnFocus = false;
var dontShowPinDrop = true;
function setPinBoxFocus(focus){
	isPinBoxOnFocus = focus;
	if(true == focus){
		document.getElementById('enter-code-message-box').style.display="block";
	}
}
function hidePinMessage() {
	if (true == dontShowPinDrop){
		document.getElementById('enter-code-message-box').style.display="none";
}
}

function showPinMessage(){
	if (true == isPinBoxOnFocus){
		document.getElementById('enter-code-message-box').style.display="block";
	}
}
$.fn.pinEntryProcessed = function (results){
	displayIdContent("#pinEntryDiv",results);

	$("#pinSubmit").removeAttr("disabled"); 
	refreshPointsSection(); 
}


function clearPinErrorMessage(){
	dontShowPinDrop = true;
	$("#pinMessage").hide();
	$("#defaultPinMessage").show();
	$("#enter-code-message-box").hide();
}

function addPinWaitMsg(){
	document.getElementById("defaultPinMessage").style.display="none";
	document.getElementById("pinMessage").innerHTML=waitMessage;
	document.getElementById("pinMessage").style.display="block";
	document.getElementById("enter-code-message-box").style.display="block";
}
function refreshPointsSection(){
	$("#header_links").load("/home/common/header_links.jsp");
}
function Get_Cookie( name ) {

var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

function deleteAllCookies() {
	if(designStored != "false") {
		Delete_Cookie("FirstName","/",""); 
		Delete_Cookie("LoginName","/","");
		refreshPointsSection();
	}
}

/* Method to Delete the cookie */
function Delete_Cookie( name, path, domain ) {
  if ( Get_Cookie( name ) ) {
	document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ";domain=.cokezone.co.uk" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}
function showLoadingImage(){
	document.getElementById("loading-image-div").style.display="block";
}

/* This method displays the flash in main panel if flash is enabled */
function showMainFlashAsset(categoryName,paramsToPass) {
	$.get(contextRoot+ "/common/mainAssetFlash.jsp", {catName: categoryName, paramsToPass: paramsToPass}, function(value){
		displayIdContent('#main-banner-div',value);
				
		activeXContent();
	});
}

/* This method displays the flash in main panel if flash is enabled and promotion session context is set*/
function showPromoMainFlashAsset(categoryName, paramsToPass) {
	$.get(contextRoot+ "/common/promotionMainAssetFlash.jsp", {catName: categoryName, paramsToPass: paramsToPass}, function(value){
		displayIdContent('#main-banner-div',value);

		//activeXContent();
	});
}

/* This method shows the common popup */
function showCommonPopup() {
	$("#commonPopup").removeClass("hide");
}

/* This method closes the common popup */
function closeCommonPopup() {
	$("#commonPopup").hide();
}

/* this method is required by wt1.js used for webtrends */
function getCookie(c_name)
{
	var c_start;
	if (document.cookie.length>0)
	{
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

/* This method displays the Reward flash in main panel if flash is enabled */
function showMainFlashReward(productId) {
	$.get(contextRoot+ "/common/mainFlashReward.jsp", {prodId: productId}, function(value){
		displayIdContent('#large-reward-main',value);
	
		//activeXContent();
	});
}

/* This method is used to show the consumption survey questions */
function startConsumptionSurvey(){
	$.get(contextRoot+"/marketPostProcessing/startConsumptionSurvey.jsp", function(value){
		displayIdContent("#post-login-survey",value);

		$('#post-login-survey').show();
		$('#survey-popup').hide();
		
	});			
}

/* This method processes the questions answered for consumption survey */
$.fn.processConsumptionSurveyData = function (results){ 
	startConsumptionSurvey();
}

/* This method is called on Ajax Submit for last question in consumption survey */
$.fn.processFinishConsumptionSurveyData = function (results){ 
	postConsumptionSurvey();
}

/* This method calls the jsp to show the thanks message once all questions of consumption survey have been answered */
function postConsumptionSurvey(){
	$.get(contextRoot+"/marketPostProcessing/PostConsumptionSurvey.jsp", function(value){
		$('#post-login-survey').hide();
		displayIdContent("#post-login-finish-survey",value);

		$('#post-login-finish-survey').show();
		refreshPointsSection();
	});	
}


/* This method is used to show the longitudinal survey questions */
function startLongitudinalSurvey(){
	$.get(contextRoot+"/marketPostProcessing/startLongitudinalSurvey.jsp", function(value){
		displayIdContent("#post-login-survey",value);

		$('#post-login-survey').show();
		$('#survey-popup').hide();
		
	});			
}

/* This method processes the questions answered for consumption survey */
$.fn.processLongitudinalSurveyData = function (results){ 
	startLongitudinalSurvey();
}

/* This method is called on Ajax Submit for last question in consumption survey */
$.fn.processFinishLongitudinalSurveyData = function (results){ 
	postLongitudinalSurvey();
}

/* This method calls the jsp to show the thanks message once all questions of consumption survey have been answered */
function postLongitudinalSurvey(){
	$.get(contextRoot+"/marketPostProcessing/PostLongitudinalSurvey.jsp", function(value){
		$('#post-login-survey').hide();
		displayIdContent("#post-login-finish-survey",value);

		$('#post-login-finish-survey').show();
		refreshPointsSection();
	});	
}



/* This method enables the Next button on selecting a radio button option */
function enableNextButton(surveybuttonval) {
	$("#"+surveybuttonval).removeAttr("disabled");
	$("#"+surveybuttonval).css("cursor","pointer");
}

/* This method closes the div for consumtion survey */
function closeConsumptionSurveyDiv(){
	$("#survey-popup").hide();
	displayIdContent("#survey-popup","");

	$("#survey-popup-welcome").hide();
	displayIdContent("#survey-popup-welcome","");
	
	$("#post-login-finish-survey").hide();
	displayIdContent("#post-login-finish-survey","");

	$("#post-login-survey").hide();
	displayIdContent("#post-login-survey","");

	
}


/* **************** Coke Games - START ******************** */

function getGameTopResults(id,randomKey) {
	var results;
	$.ajax({
		url: contextRoot + "/content/gameResults.jsp?action=getGameTopResults&gameid=" + id + "&randomKey=" + randomKey,
		dataType: "json",
		async: false,
		success: function(msg){
		 	results = msg.resultString;
	   }
	});
	if(results.length < 100){
		return "<HighScores>  <row>    <nickName>coco</nickName>    <score>1800</score>  </row>  <row>    <nickName>sandra</nickName>    <score>1785</score>  </row>  <row>    <nickName>coco</nickName>    <score>1770</score>  </row>  <row>    <nickName>rocky</nickName>    <score>1690</score>  </row>  <row>    <nickName>coco</nickName>    <score>1685</score>  </row>  <row>    <nickName>SANDRA</nickName>    <score>1655</score>  </row>  <row>    <nickName>sandra</nickName>    <score>1645</score>  </row>  <row>    <nickName>sandra</nickName>    <score>1645</score>  </row>  <row>    <nickName>sandra</nickName>    <score>1640</score>  </row>  <row>    <nickName>sandra</nickName>    <score>1625</score>  </row></HighScores>";
	}else {
		return results;
	}
}


function updateGameResults(id, resultString, randomKey) {
	var results = '301';
	    /*$.ajax({
		 url: contextRoot + "/content/gameResults.jsp?action=updateGameResults&gameid=" + id + "&resultString=" + resultString + "&randomKey=" + randomKey,
		 dataType: "json",
	 	 async: false
		});*/	
	return results;	
}


function activeXContent() {
	var jActivating =
		{
		
			/**
			 * Declare constants
			 * IS_MSIE	checks for Internet Explorer 6 and later versions
			 * TAGS		array with affected HTML tags
			 */
			IS_MSIE : (document.removeNode && document.createAttribute) ? true : false,
			TAGS : ['object', 'embed', 'applet'],
			
			
			/**
			 * Activates embedded content reinserting it.
			 * @return void
			 */
			activateContent : function()
			{
				var i = 0;
				for(var _tagName; _tagName = jActivating.TAGS[i]; i++)
				{
					var j = 0;
					for(var _node; _node = document.getElementsByTagName(_tagName)[j]; j++)
					{
						if(jActivating.IS_MSIE)
						{
							jActivating.reinsertHtml(_node);
						}
						else
						{
							jActivating.reinsertNode(_node);
						}
					}
					
				}
				jActivating = null;
			},
			
			
			/**
			 * Sets outerHTML property.
			 * @param object	- The node
			 * @return void
			 */
			reinsertHtml : function(_node)
			{
				var _htmlCode = jActivating.getHtmlCode(_node);
				if(_htmlCode)
				{
					_node.outerHTML = _htmlCode;
				}
			},
			
			
			/**
			 * Replaces the node for a clone.
			 * @param object - The original node
			 * @return void
			 */
			reinsertNode : function(_node)
			{
				var _clone = _node.cloneNode(true);
				var _parent = _node.parentNode;
				if(_clone && _parent)
				{
					_parent.replaceChild(_clone, _node);
				}
			},
			
			
			/**
			 * Retrieves the object and its content in HTML.
			 * @param object - The analyzed node
			 * @return string - The HTML received, NULL for malformed syntax (end tag)
			 */
			getHtmlCode : function(_node)
			{
				var _htmlCode = _node.outerHTML;
				var _name = _node.nodeName.toLowerCase();
				if(_name == 'embed')
				{
					return _htmlCode;
				}
				if(_name == 'object' || _name == 'applet')
				{
					var _startTag = _htmlCode.substr(0, _htmlCode.indexOf('>') + 1);
					var _endTag = _htmlCode.substr(_htmlCode.length - 9).toLowerCase();
					// Filters malformed syntax for avoid unexpected results
					if(_endTag != '</object>' && _endTag != '</applet>')
					{
						return null;
					}
					var _innerHtml = jActivating.getInnerHtml(_node);
					_htmlCode = _startTag + _innerHtml + _endTag;
					return _htmlCode;
				}
			},
			
			
			/**
			 * Retrieves the HTML between start and end tags of the object.
			 * @param object - The analyzed node
			 * @return string - The HTML received
			 *
			 * NOTE: the innerHTML property isn't used because Internet Explorer
			 * sometimes returns a empty result.
			 */
			getInnerHtml : function(_node)
			{
				var _innerHtml = '';
				var i = 0;
				for(var _childNode; _childNode = _node.childNodes[i]; i++)
				{
					_innerHtml += _childNode.outerHTML;
				}
				return _innerHtml;
			}
		}	
		if(jActivating.IS_MSIE)
		{
			jActivating.activateContent();
		}
		else if(window.opera)
		{
			document.addEventListener('DOMContentLoaded', jActivating.activateContent, false);
		}
}
/* Pass key value and its id to display*/

function displayIdContent(id,value){	
	if(navigator.userAgent.indexOf('MultiSafari') == -1){
		$(id).html(value);	
	}else{
		$(id).html("<div>" + value + "</div>");	
	}	
}

function enableLongitudinalNextButton(formId){

}


/* script to resolve image cache issue in IE 6 */
// Function to fix IE6 Background Image Flicker issue
var isCacheIE;
if (navigator.appName == "Microsoft Internet Explorer"){isCacheIE = true;}
if (isCacheIE) {
	try {
		document.execCommand("BackgroundImageCache",false,true);
	} catch(e) {

	}
}


/* Function to Show Cherry Coke Survey questions*/
function startCherryCokeSurvey(){
	$("#welbutton").attr("disabled", "disabled");	
	$("#welbutton").val(waitMessage);
	$.get(contextRoot+"/marketPostProcessing/cherryCokeSurvey.jsp", function(value){
		displayIdContent("#post-login-survey",value);
		$('#post-login-survey').show();
		$('#survey-popup').hide();		
	});			
}

$.fn.processCherryCokeSurveyData = function (results){ 
	startCherryCokeSurvey();
}

$.fn.finishCherryCokeSurveyData = function (results){ 
	postCherryCokeSurvey();
}


/* This method calls the jsp to show the thanks message once all questions of cherry coke survey have been answered */
function postCherryCokeSurvey(){
	$.get(contextRoot+"/marketPostProcessing/postCherryCokeSurvey.jsp", function(value){
		$('#post-login-survey').hide();
		displayIdContent("#post-login-finish-survey",value);
		$('#post-login-finish-survey').show();
		/*refreshPointsSection();*/
	});	
}


/* This method closes the div for consumtion survey */
function closeSurveyDiv(){
	$("#survey-popup").hide();
	displayIdContent("#survey-popup","");

	$("#survey-popup-welcome").hide();
	displayIdContent("#survey-popup-welcome","");
	
	$("#post-login-finish-survey").hide();
	displayIdContent("#post-login-finish-survey","");

	$("#post-login-survey").hide();
	displayIdContent("#post-login-survey","");

	
}

function showCherryCokePreviousPage(pageNumber) {
	$.get(contextRoot+"/marketPostProcessing/cherryCokeSurvey.jsp", {backToPage: pageNumber}, function(value){
		displayIdContent("#post-login-survey",value);

		$('#post-login-survey').show();
		$('#survey-popup').hide();
	});	
}


/* Function to Show Coke Zero Survey questions*/
function startCokeZeroSurvey(){
	$("#welbutton").attr("disabled", "disabled");	
	$("#welbutton").val(waitMessage);
	$.get(contextRoot+"/marketPostProcessing/cokeZeroSurvey.jsp", function(value){
		displayIdContent("#post-login-survey",value);
		$('#post-login-survey').show();
		$('#survey-popup').hide();
		var height = $(".body-content").height()+$(".tab-navigation").height()+10;
		$(".disabled-div").height(height);
	});		
	

}

function flashAddThis() {
	addthis_offset_left = 740;
	addthis_offset_top = -40;
	addthis_open(document.getElementById('large-reward-main'), '', '[URL]', '[TITLE]');
}

$.fn.processCokeZeroSurvey = function (results){ 
	startCokeZeroSurvey();
}

function setCheckBoxAnswer(questionId,answerId,value) {
    if (document.getElementById(questionId+'_'+answerId).checked) {
        document.getElementById(questionId).value = value;
    }else {
        document.getElementById(questionId).value='No';
    }
}

function processRadioButtonInfo(questionId,answerId,answerText) {
    document.getElementById(questionId).value= answerText;
    document.getElementById(questionId+'_answer').value= answerId;
}

$.fn.postFreePoll = function (results){
	$("#popupContent").addClass("popup-post-free-poll");
	displayIdContent("#popupContent",results);
	showPopup();
}

function openFreePolls(questionId) {
		var pollsParams = "";
		if (questionId != "") {
			pollsParams	={questionId:questionId};
		}
		$.get(contextRoot + "/polls/PollsPopup.jsp" , pollsParams, function(value) {
			$("#popupContent").addClass("popup-post-free-poll");
			displayIdContent("#popupContent",value);
			$("#commonPopup").show();
		});
}

function getProductList(category, count) {
	var param = {category: category, count: count};
	var result;
	$.ajax({
	  url: contextRoot + "/common/worldCupRewards.jsp",
	  async: false,
	  dataType: 'json',
	  data: param,
	  success: function(value){
			result = value;
		  }
	});
	return eval(result);
}

function replaceGreyImage()
{
	var firstListItem;
	firstListItem = $("ul.tab-nav li:first-child a:first-child");
	if(firstListItem.attr("id") ==  "current" )
	{
		$("#left-div").removeClass();
		$("#left-div").addClass('tab-nav-left-red');
	}

	firstListItem = $("ul.tab-nav-bottles li:last-child a:first-child");
	if(firstListItem.attr("id") ==  "current" )
	{
		$("#right-div").removeClass();
		$("#right-div").addClass('tab-nav-right-red');
	}
}
function jsClearCommentBox(checkbox, textarea) {
	if(checkbox == 0) {
		document.getElementById(textarea).value ='';
	} 
}

function jsSelectCheckBox(checkbox) {
	checkbox.checked = true;
}

$(document).ready(function() {

   $("input[value=Search]").click(function() {
   	var searchText = $("#search").val();
	  if(searchText=="" || searchText=="Search rewards")
		{	  
			return false;
		}
	  else
		{
			return true;
		}
   }); 
});
function showOlympicPopup()
{
	$.get(contextRoot + "/olympic/olympicMessage.jsp?loginBckUrl="+loginBackURL , function(value) {
		displayIdContent('#popupContent',value);
		
		$("#commonPopup").show();
	});
}
function showOlympicRegistrationPopup()
{
	var backParams = "";		
	
	
	var backURL=loginBackURL;
	backParams={backURL:backURL};
	$.get(contextRoot + "/olympic/olympicRegistration.jsp" ,backParams, function(value) {
		displayIdContent('#popupContent',value);
		
		$("#commonPopup").show();
	});
}
function closeOlympicPopup()
{
	$("#commonPopup").hide();
}

function showOlympicLogIn() {
	if(designStored != "false") {
		var loginParams = "";		
		
		
		var backURL=loginBackURL+"?nextURL=/olympic/olympicMessage.jsp";
		var specialURL=loginBackURL+"?nextURL=/login/login.jsp";
		loginParams={backURL:backURL,specialErrorURL:specialURL};
		loginParams.unforcedLogin="true";
		$.get(contextRoot + "/login/login.jsp" , loginParams, function(value) {
			displayIdContent("#popupContent",value);

			$("#commonPopup").show();
		});
	}
}

function closeMgmPopup(){	
	$("#commonPopup").hide();
}

function openMgmPopup() {
	var mgmParams = "";
	if (loginBackURL != "") {
		mgmParams = {backURL:loginBackURL};
	}
	$.get(contextRoot + "/mgm/mgm_popup.jsp", mgmParams, function(value) {
		displayIdContent("#popupContent",value);
		$("#commonPopup").show();
	});
}

function replaceGreyImage()
{
	var firstListItem;
	firstListItem = $("ul.tab-nav-bottles li:first-child a:first-child");
	if(firstListItem.attr("id") ==  "current" )
	{
		$("#left-div").removeClass();
		$("#left-div").addClass('tab-nav-left-red');
	}
	
}

/* Method to Delete the cookie */
function Delete_Cookie( name, path, domain ) {
  if ( Get_Cookie( name ) ) {
	document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ";domain=.cokezone.ie" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}


