
// For casts: http://www.jibbering.com/faq/faq_notes/type_convert.html
// Disable Return Key Press
document.onkeypress = disableReturnKey;

// -----------------------------------------------------------------------------------------------
function disableReturnKey(evt)
{
    var evt = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type == "text")) { return false; }    
}
// -----------------------------------------------------------------------------------------------
function Search(evt)
{
    var keyNum;
    if (window.event) { keyNum = evt.keyCode; } // IE
    else if (evt.which) { keyNum = evt.which; } // Netscape/Firefox/Opera

    if ((keyNum == 13) || (evt == 'do'))
    {
        // Read field name (its server side so it has 2 names - may change it to client side when time allows)
        var searchHeadInput = document.getElementById('ucSearch_ucSearch_searchHeadInput');
        if (searchHeadInput == null) { searchHeadInput = document.getElementById('ctl00_ucSearch_ucSearch_searchHeadInput'); }
        
        var strSearch = trim(removeSpaces(searchHeadInput.value));
        
        // Go to search page when there's a value to search for
        if (strSearch != '')
        {
            if (document.domain == 'localhost')
            {
                window.location = 'http://localhost/search.aspx?par1=' + strSearch;
            }
            else
            {
                window.location = 'http://' + document.domain + '/search/' + strSearch + '/';
            }
        }
    }
}
// -----------------------------------------------------------------------------------------------
function CheckQty()
{
    var txtQty = document.getElementById('txtQty');

    if (!isNumeric2(txtQty.value) || txtQty.value == '0')
    {
        txtQty.value = '1';
        return;
    }

    // Cast to int
    var iQtyVal = (+txtQty.value);

    // Max quantity set here only
    if (iQtyVal >= 100)
    {
        txtQty.value = '99';
    }
}
// -----------------------------------------------------------------------------------------------
function ResetTotal()
{
    eraseCookie('MOM');
    eraseCookie('InMemMOM');
    eraseCookie('InMemMOM2');
    eraseCookie('Login');

    if (document.getElementById('ctl00_ucCart_cartHeadTotal') != null)
    { document.getElementById('ctl00_ucCart_cartHeadTotal').innerHTML='&pound;0.00'; }
    else
    { document.getElementById('ucCart_cartHeadTotal').innerHTML='&pound;0.00'; }
}
// -----------------------------------------------------------------------------------------------
function imgSwap(imgElem, newImg)
{
    var targetImage = eval('document.' + imgElem);	
	targetImage.src = newImg;
}
// -----------------------------------------------------------------------------------------------
function QtyUp()
{
    // Cast to int
    var iQtyVal = (+document.getElementById('txtQty').value);
    document.getElementById('txtQty').value = ++iQtyVal;
}
// -----------------------------------------------------------------------------------------------
function QtyDown()
{
    // Cast to int
    var iQtyVal = (+document.getElementById('txtQty').value);
    if (iQtyVal != 1 ) { document.getElementById('txtQty').value = --iQtyVal; }
}
// -----------------------------------------------------------------------------------------------
function qtyValue(el, n)
{
     el.value = +el.value + n;
     if (el.focus) el.focus();
}
// -----------------------------------------------------------------------------------------------
function ShowHide(elId) {
	var elStyle = document.getElementById(elId).style;

    if (elStyle.display == 'block')
    {
        elStyle.display = 'none';
        //document.getElementById('arrImg_' + elId).src = '/images/dnp/arrDown.gif';
        document.getElementById('pAccessoryDisplay_' + elId).innerHTML = '<img src="Images/shop/gift.gif" alt="Open" width="16" height="16" style="vertical-align:text-bottom;" />&nbsp;View gift options and accessories (including gift message) <img src="Images/shop/down-arrows.gif" alt="Open" width="8" height="9" />'
    }
    else
    {
        elStyle.display = 'block';
        //document.getElementById('arrImg_' + elId).src = '/images/dnp/arrUp.gif';
        document.getElementById('pAccessoryDisplay_' + elId).innerHTML = '<img src="Images/shop/gift.gif" alt="Open" width="16" height="16" style="vertical-align:text-bottom;" />&nbsp;Hide gift options and accessories (including gift message) <img src="Images/shop/up-arrows.gif" alt="Close" width="8" height="9" />'
    }
}
// -----------------------------------------------------------------------------------------------
function ShowCopy() {
    if (document.getElementById('pageCopyMore').style.display == 'inline')
    {
        document.getElementById('pageCopyMore').style.display = 'none';
        document.getElementById('aCopyMore').innerHTML = "Read more &nbsp; <img src=\"/images/dnp/arrDown.gif\" alt=\"\" class=\"arr\" />";
        document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML = document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML.replace(/ <span/i, "...<span");
    }
    else
    {
        document.getElementById('aCopyMore').innerHTML = "Read less &nbsp; <img src=\"/images/dnp/arrUp.gif\" alt=\"\" class=\"arr\" />";
        document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML = document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML.replace(/...<span/i, " <span");
        document.getElementById('pageCopyMore').style.display = 'inline';
    }
    // bug in IE, where relative boxes got "stuck" when click more/less (#213)
    $(".leftColumnBot .boxBgr SPAN IFRAME").css({ position: "" });
    $(".leftColumnBot .boxBgr SPAN IFRAME").css({ position: "relative" });
    $(".rightColumnBot .boxBgr").css({ position: "" });
    $(".rightColumnBot .boxBgr").css({ position: "relative" });
}

//bottling note
function ShowCopyProduct2() {
    if (document.getElementById('pageCopyMore2').style.display == 'inline') {
        document.getElementById('pageCopyMore2').style.display = 'none';
        document.getElementById('ctl00_ContentPlaceHolder1_ctl01_copyMoreInfo2').innerHTML = "...more";
        //document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML = document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML.replace(/ <span/i, "<span");
    }
    else {
        document.getElementById('pageCopyMore2').style.display = 'inline';
        document.getElementById('ctl00_ContentPlaceHolder1_ctl01_copyMoreInfo2').innerHTML = "...less";
       // document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML = document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML.replace(/...<span/i, " <span");
    }
}

//tasting note
function ShowCopyProduct() {
    if (document.getElementById('pageCopyMore').style.display == 'inline') {
        document.getElementById('pageCopyMore').style.display = 'none';
        document.getElementById('ctl00_ContentPlaceHolder1_ctl01_copyMoreInfo').innerHTML = "...more";
        //document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML = document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML.replace(/ <span/i, "<span");
    }
    else {
        document.getElementById('pageCopyMore').style.display = 'inline';
        document.getElementById('ctl00_ContentPlaceHolder1_ctl01_copyMoreInfo').innerHTML = "...less";
        // document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML = document.getElementById('ctl00_ContentPlaceHolder1_pageCopy').innerHTML.replace(/...<span/i, " <span");
    }
}
// -----------------------------------------------------------------------------------------------
function ShowTab(tNum)
{
    if (tNum == '1')
    {
        document.getElementById('prdTabCon2').style.display = 'none';
        document.getElementById('prdTabBtn2').className = 'tabBtnDark';
        document.getElementById('prdTabCon1').style.display = 'block';
        document.getElementById('prdTabBtn1').className = 'tabBtnLite';
    }
    else if (tNum == '2')
    {
        document.getElementById('prdTabCon1').style.display = 'none';
        document.getElementById('prdTabBtn1').className = 'tabBtnDark';
        document.getElementById('prdTabCon2').style.display = 'block';
        document.getElementById('prdTabBtn2').className = 'tabBtnLite';
    }
}
function ShowTab2(tNum) {
    if (tNum == '1') {
        document.getElementById('prdTabCon2').style.display = 'none';
        document.getElementById('prdTabBtn2').className = 'tabBtnDark2';
        document.getElementById('prdTabCon1').style.display = 'block';
        document.getElementById('prdTabBtn1').className = 'tabBtnLite2';
        document.getElementById('prdTabCon3').style.display = 'none';
        document.getElementById('prdTabBtn3').className = 'tabBtnDark2';
    }
    else if (tNum == '2') {
        document.getElementById('prdTabCon1').style.display = 'none';
        document.getElementById('prdTabBtn1').className = 'tabBtnDark2';
        document.getElementById('prdTabCon2').style.display = 'block';
        document.getElementById('prdTabBtn2').className = 'tabBtnLite2';
        document.getElementById('prdTabCon3').style.display = 'none';
        document.getElementById('prdTabBtn3').className = 'tabBtnDark2';
    }
    else if (tNum == '3') {
        document.getElementById('prdTabCon1').style.display = 'none';
        document.getElementById('prdTabBtn1').className = 'tabBtnDark2';
        document.getElementById('prdTabCon2').style.display = 'none';
        document.getElementById('prdTabBtn2').className = 'tabBtnDark2';
        document.getElementById('prdTabCon3').style.display = 'block';
        document.getElementById('prdTabBtn3').className = 'tabBtnLite2';
    }
}
function ShowTab3(tNum) {
    if (tNum == '1') {
        document.getElementById('prdTabCon2').style.display = 'none';
        document.getElementById('prdTabBtn2').className = 'tabBtnDark';
        document.getElementById('prdTabCon1').style.display = 'block';
        document.getElementById('prdTabBtn1').className = 'tabBtnLite';
        document.getElementById('prdTabCon3').style.display = 'none';
        document.getElementById('prdTabBtn3').className = 'tabBtnDark';
    }
    else if (tNum == '2') {
        document.getElementById('prdTabCon1').style.display = 'none';
        document.getElementById('prdTabBtn1').className = 'tabBtnDark';
        document.getElementById('prdTabCon2').style.display = 'block';
        document.getElementById('prdTabBtn2').className = 'tabBtnLite';
        document.getElementById('prdTabCon3').style.display = 'none';
        document.getElementById('prdTabBtn3').className = 'tabBtnDark';
    }
    else if (tNum == '3') {
        document.getElementById('prdTabCon1').style.display = 'none';
        document.getElementById('prdTabBtn1').className = 'tabBtnDark';
        document.getElementById('prdTabCon2').style.display = 'none';
        document.getElementById('prdTabBtn2').className = 'tabBtnDark';
        document.getElementById('prdTabCon3').style.display = 'block';
        document.getElementById('prdTabBtn3').className = 'tabBtnLite';
    }
}

function showTabN(tNum, tCou) {
    for (var i = 1; i<=tCou; i++)
    {
        document.getElementById('prdTabCon' + i.toString()).style.display = 'none';
        document.getElementById('prdTabBtn' + i.toString()).className = 'tabBtnDark';
    }

    document.getElementById('prdTabCon' + tNum.toString()).style.display = 'block';
    document.getElementById('prdTabBtn' + tNum.toString()).className = 'tabBtnLite';
}

function membershipSelect(dropdown) {
    var myindex  = dropdown.selectedIndex;
    var SelValue = dropdown.options[myindex].value;

    for (var i = 1; i <= 8; i++) {
        document.getElementById('Bronze-' + i.toString()).style.display = 'none';
        document.getElementById('Silver-' + i.toString()).style.display = 'none';
        document.getElementById('Gold-' + i.toString()).style.display = 'none';
    }
    $('#Bronze-' + SelValue.toString()).fadeIn('slow', function () {
        // Animation complete
    });
    $('#Silver-' + SelValue.toString()).fadeIn('slow', function () {
        // Animation complete
    }); 
    $('#Gold-' + SelValue.toString()).fadeIn('slow', function () {
        // Animation complete
    });
}

// -----------------------------------------------------------------------------------------------
function ProductReview(action)
{   
    CheckDivCookie();

    if (action == 'AddNew')
    {
        document.getElementById('addNewReview').style.display = 'none';
        document.getElementById('newReviewForm').style.display = 'block';
    }
    else if (action == 'Cancel')
    {
        document.getElementById('newReviewForm').style.display = 'none';
        document.getElementById('addNewReview').style.display = 'block';
    }
    else if (action == 'Submit')
    {
        alert('Thanks you for rating this product!\n\ntitle: ' + document.getElementById('prdReviewTitle').value + '\nrating: ' + document.getElementById('prdReviewRating').value + '\nreview: ' + document.getElementById('prdReviewText').value);
        // ajax the thing here before collapsing the form
        document.getElementById('newReviewForm').style.display = 'none';
        document.getElementById('addNewReview').style.display = 'block';
    }
}
// -----------------------------------------------------------------------------------------------
function CheckDivCookie() {
    if (javaCookie == true && document.getElementById("DivCookie") != null) {
        document.getElementById("DivCookie").innerHTML = "Please note: Cookies must be enabled for you to use this website properly.";
        document.getElementById("DivCookie").style.display = "block";
    }
}
// -----------------------------------------------------------------------------------------------
// Useful utility functions
// -----------------------------------------------------------------------------------------------
String.prototype.startsWith = function(str)
{ return (this.match("^" + str) == str) }

// -----------------------------------------------------------------------------------------------
String.prototype.endsWith = function(str)
{ return (this.match(str + "$") == str) }

// -----------------------------------------------------------------------------------------------
String.prototype.trim = function()
{ return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "")) }

// -----------------------------------------------------------------------------------------------
function removeSpaces(str)
{
    return str.replace(/\s+/, " ");
}

// -----------------------------------------------------------------------------------------------
function trim(str)
{
    var result = str.replace(/^\s+|\s+$/g, '');
    return result;
}

// -----------------------------------------------------------------------------------------------
function isNumeric1(strIn)
{
    var validChars = "0123456789.";
    var isNumeric = true;
    var cChar;

    if (strIn == '') { return false; }

    for (i = 0; i < strIn.length && isNumeric == true; i++)
    {
        cChar = strIn.charAt(i);
        if (validChars.indexOf(cChar) == -1)
        {
            isNumeric = false;
        }
    }
    return isNumeric;
}

// -----------------------------------------------------------------------------------------------
function isNumeric2(str)
{
    if (str == '') { return false; }
    var result = str.match(/^[0-9]*$/);
    return result;
}

// -----------------------------------------------------------------------------------------------
function isValidEmail(email)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if (email.match(emailExp)) { return true; }
	else { return false; }
}

// -----------------------------------------------------------------------------------------------
function createCookie(name, value, days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

// -----------------------------------------------------------------------------------------------
//readCookie("ssCookie")
//readCookie("ssCookie", "cUserType")
// -----------------------------------------------------------------------------------------------
function readCookie(name, branch)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	var retString;

    for (var i = 0; i < ca.length; i++)
    {
	    var c = ca[i];
	    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
	    if (c.indexOf(nameEQ) == 0) { retString = c.substring(nameEQ.length, c.length); }
    }

	if (branch == null)
	{
	    return retString;
	}
	else
	{
	    var br = retString.split('&');
	    
        for (var i = 0; i < br.length; i++)
        {
	        var b = br[i];
	        while (b.charAt(0) == ' ') b = b.substring(1, b.length);
	        if (b.indexOf(branch) == 0) { retString = b.substring(branch.length, b.length).replace("=", ""); }
        }
    
	    return retString;
	}

	return null;
}

// -----------------------------------------------------------------------------------------------
function eraseCookie(name)
{
	createCookie(name, "", -1);
}

//Gets Domain Name
function GetDomainName(url) {
    var returnurl;
    if (url.indexOf("http://") == 0) {
        returnurl = url.substring(0, url.indexOf("/", url.indexOf("http://") + 7));
    }
    else if (url.indexOf("https://") == 0) {
        returnurl= url.substring(0, url.indexOf("/", url.indexOf("https://") + 8));
    }
    else {
        return url;
    }
    return returnurl + "/"; //append trailing slash
}

//This function hides Cart urls from google
//This function hides Cart urls from google
function GoTocart()
 {
    sloc = GetDomainName(window.location.href) + 'ShoppingBasket.aspx';
    if (sloc.indexOf('localhost') > 0)
    { window.location = sloc; }
    else {
        sloc2 = sloc.replace('http', 'https');
        window.location = sloc2.replace('httpss', 'https');
         }
     }

     function DestractRiddle(sInput) {
        //debugger;
         sInput = get_cookie(sInput)
         
         if (sInput.length > 0) {
             var myArr = sInput.split("|")
             var i = 0;
             for (i = 0; i <= myArr.length; i++) {
                 if (myArr[i] != null) {
                     var sOut = myArr[i].toString()
                     var sID = sOut.substring(0, sOut.indexOf(","))
                     var sLink = sOut.substring(sOut.indexOf(",") + 1, sOut.length - sOut.indexOf(",") + 1)
                     FindAndReplaceRiddle(sID, sLink)
                 }
            }

         }

     }

     function FindAndReplaceRiddle(sID, sLink) {
         //debugger;
         if (sID != null && sID > 0) {
             document.getElementById('special_' + sID).innerHTML = sLink
         }

     }

     //Get cookie routine by Shelley Powers
     function get_cookie(Name) {
         var search = Name + "="
         var returnvalue = "";
         if (document.cookie.length > 0) {
             offset = document.cookie.indexOf(search)
             // if cookie exists
             if (offset != -1) {
                 offset += search.length
                 // set index of beginning of value
                 end = document.cookie.indexOf(";", offset);
                 // set index of end of cookie value
                 if (end == -1) end = document.cookie.length;
                 returnvalue = unescape(document.cookie.substring(offset, end))
             }
         }
         return returnvalue;
     }


     /* RC4 symmetric cipher encryption/decryption
     * Copyright (c) 2006 by Ali Farhadi.
     * released under the terms of the Gnu Public License.
     * see the GPL for details.
     *
     * Email: ali[at]farhadi[dot]ir
     * Website: http://farhadi.ir/
     */

     /**
     * Encrypt given plain text using the key with RC4 algorithm.
     * All parameters and return value are in binary format.
     *
     * @param string key - secret key for encryption
     * @param string pt - plain text to be encrypted
     * @return string
     */
     function rc4Encrypt(key, pt) {
         s = new Array();
         for (var i = 0; i < 256; i++) {
             s[i] = i;
         }
         var j = 0;
         var x;
         for (i = 0; i < 256; i++) {
             j = (j + s[i] + key.charCodeAt(i % key.length)) % 256;
             x = s[i];
             s[i] = s[j];
             s[j] = x;
         }
         i = 0;
         j = 0;
         var ct = '';
         for (var y = 0; y < pt.length; y++) {
             i = (i + 1) % 256;
             j = (j + s[i]) % 256;
             x = s[i];
             s[i] = s[j];
             s[j] = x;
             ct += String.fromCharCode(pt.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);
         }
         return ct;
     }

     /**
     * Decrypt given cipher text using the key with RC4 algorithm.
     * All parameters and return value are in binary format.
     *
     * @param string key - secret key for decryption
     * @param string ct - cipher text to be decrypted
     * @return string
     */
     function rc4Decrypt(key, ct) {
         return rc4Encrypt(key, ct);
     }
     /*
     * Movember page bottles tabs
     */
     function movemberShowDetails(id) {
         for (i = 1; i <= 5; i++) {
             document.getElementById("movemberBottle" + i).style.backgroundImage = "none";
             document.getElementById("movemberBottle" + i).style.border = "none";
             document.getElementById("movemberDetails" + i).style.display = "none";
         }
         document.getElementById("movemberBottle" + id).style.backgroundImage = "url(http://www.masterofmalt.com/images/dnp/box-bgr.gif)";
         document.getElementById("movemberBottle" + id).style.border = "1px solid #DFDACF";
         document.getElementById("movemberBottle" + id).style.borderBottom = "none";
         document.getElementById("movemberDetails" + id).style.display = "block";
     }


//Check if the homepage product boxes have text overflow, and if true, add a fade graphic.
function checkTextOverflow() {
    $('div[class^=ctrl_PBNh_Right_Desc]').filter(function () {
        return /ctl\d+_\d+_ProductDesc$/.test(this.id);
    }).each(function () {

        var curOverflow = this.style.overflow;
        if (!curOverflow || curOverflow === "visible")
            this.style.overflow = "hidden";

        var isOverflowing = this.clientWidth < this.scrollWidth
            || this.clientHeight < this.scrollHeight;

        this.style.overflow = curOverflow;

        if (isOverflowing) {
            var IDMatch = this.getAttribute('id');
            IDMatch = IDMatch.replace(/ProductDesc/, "TextFade");
            document.getElementById(IDMatch).style.display = 'block';            
        }
    });
}

//Flags whether age has been confirmed by user. If not, redirect.
function setAgeCookie(confirm, days) {
    if (confirm == '1') {
        createCookie('aC', confirm, days);
        document.getElementById('entireAC').style.display = "none";
    }
    else {
        createCookie('aC', confirm, days);
        window.location = "http://www.drinkaware.co.uk/";
    }

    return false;
}

function tastingShowTabN(tNum, tCou) {
    for (var i = 1; i <= tCou; i++) {
        document.getElementById('bespokeTastingContent' + i.toString()).style.display = 'none';
        document.getElementById('bespokeTastingTab' + i.toString()).className = 'whiskyTastingsTabHide';
    }

    document.getElementById('bespokeTastingContent' + tNum.toString()).style.display = 'block';
    document.getElementById('bespokeTastingTab' + tNum.toString()).className = 'whiskyTastingsTabShow';
}


//halve the height of the blurb div when too much text, then give more/less button to show/hide the extra text when desired.
function cutBlurbOnLoad() {
    var link = $('a[id$=blurbMoreLink]');
    var textBlock = $('div[id$=dvPromoBlurb]');

    if (textBlock.text().length > 170) {
        textBlock.css('height', textBlock.height() / 2 + 'px');
        $('img[id$=promoBlurbFade]').css('display', 'block');
        link.css('display', 'block');
    }
    else {
        $('img[id$=promoBlurbFade]').css('display', 'none');
        link.css('display', 'none');
    }
}

function hideShowPromoBlurb() {
    var link = $('a[id$=blurbMoreLink]');
    var textBlock = $('div[id$=dvPromoBlurb]');

    if (link.text() == '...less') {
        textBlock.css('height', textBlock.height() / 2 + 'px');
        $('img[id$=promoBlurbFade]').css('display','block');
        link.text('...more');
    }
    else {
        textBlock.css('height', 'auto');
        $('img[id$=promoBlurbFade]').css('display', 'none');
        link.text('...less');
    }
}

var PersonalisedTipShown = false;
function toggleCanPersonaliseTip() {
    var personalisedTip = $('div[id$=CanPersonaliseTip]');
    if (personalisedTip.css('display') == 'none') {
        personalisedTip.fadeIn('slow', function () { });
        //PersonalisedTipShown = true;
    }
    else {
        personalisedTip.fadeOut('slow', function () { });
        //PersonalisedTipShown = false;
    }
}

var MoreOldAndRareTipShown = false;
function toggleMoreOldAndRareTip() {
    if (MoreOldAndRareTipShown == false) {
        $('#MoreOldAndRareTip').fadeIn('slow', function () { });
        PersonalisedTipShown = true;
    }
    else {
        $('#MoreOldAndRareTip').fadeOut('slow', function () { });
        MoreOldAndRareTipShown = false;
    }
}

function CloseTradeIntro() {
    createCookie('HideTradeIntro', 1, '');
    $('div[id$=TradeIntroEntireBox]').css('display', 'none');
    $('div[id$=TradeIntroBackground]').css('display', 'none');
}

function SwitchIntroPages(prefix, GoToNext)
{
    //Grab page no.
    var pageNo = parseInt(document.getElementById("IntroPageNo").firstChild.data);
    if (pageNo == 0) {
        document.getElementById("Span_PageNo").style.display = "inline";
    }

    if (GoToNext) {
        if (pageNo < 5) {
            document.getElementById(prefix + "Title" + pageNo).style.display = "none";
            document.getElementById(prefix + "Intro" + pageNo).style.display = "none";
            document.getElementById(prefix + "Title" + (pageNo + 1)).style.display = "block";
            document.getElementById(prefix + "Intro" + (pageNo + 1)).style.display = "block";
            document.getElementById("IntroPageNo").firstChild.data = pageNo + 1;
        }
    }
    else {
        if (pageNo > 1) {
            document.getElementById(prefix + "Title" + pageNo).style.display = "none";
            document.getElementById(prefix + "Intro" + pageNo).style.display = "none";
            document.getElementById(prefix + "Title" + (pageNo - 1)).style.display = "block";
            document.getElementById(prefix + "Intro" + (pageNo - 1)).style.display = "block";
            document.getElementById("IntroPageNo").firstChild.data = pageNo - 1;
        }
    }

    pageNo = parseInt(document.getElementById("IntroPageNo").firstChild.data);

    if (pageNo == 5) {
        document.getElementById(prefix + "IntroNextG").style.display = "inline";
        document.getElementById(prefix + "IntroNext").style.display = "none";
    }
    else {
        document.getElementById(prefix + "IntroNext").style.display = "inline";
        document.getElementById(prefix + "IntroNextG").style.display = "none";
    }

    if (pageNo == 1) {
        document.getElementById(prefix + "IntroBackG").style.display = "inline";
        document.getElementById(prefix + "IntroBack").style.display = "none";
    }
    else {
        document.getElementById(prefix + "IntroBack").style.display = "inline";
        document.getElementById(prefix + "IntroBackG").style.display = "none"; 
    }
}

function SetTradeIntroWindowCookie() {
    var chked = $('input[id$=chkBxNoRepeat]').attr('checked');
    if (chked) {
        createCookie('HideTradeIntro', 1, '');
    }
    else {
        createCookie('HideTradeIntro', 0, '');
    }
}

function SuppressTradeIntroWindowForever() {
    $.ajax({
        type: "POST",
        url: "/DefaultTrade.aspx/SuppressIntroWindow",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            // Do something interesting here.
        }
    });

    CloseTradeIntro();
}
