//<!--
/// <reference path="jquery-1.3.2-vsdoc2.js" />

function hidecontent(id) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(id).style.display == 'block') {
            document.getElementById(id).style.display = 'none';
        }
        else {
            document.getElementById(id).style.display = 'none';
        }
    }
}

function showMore(id, a) {
    if (a.innerHTML.toLowerCase() == 'Read less...') {
        document.getElementById(id).style.display = 'none';
        a.innerHTML = "Read more...";
    }
    else {
        document.getElementById(id).style.display = 'block';
        a.innerHTML = "Read less...";
                
    }

}

function showDiv(a) {
    $("div.moreInfo:visible").slideUp('200');
    $(a).siblings("div.moreInfo:hidden").slideDown('200', function() {
        var $div = $("#bkgBot");
        $div.css({ display: 'none', top: 0 });

        $("div.body_image").height('202px');
        $(a).parent(".body_copy").siblings("div.body_image").css('height', '230px')
        $("a[onclick*='showDiv']:hidden").css('display', 'block');
        $(a).css('display', 'none');

        var height = $(document).height();
        var top = height - 153;        
        
        if ($.browser.msie && $.browser.version >= 7 && $.browser.version < 8) {
            top = height - 154;
        }
        if ($.browser.msie && $.browser.version >= 8 && $.browser.version < 9) {
            top = height - 154;
        }
        if ($.browser.msie && $.browser.version >= 6 && $.browser.version < 7) {
            top = height - 154;
        }

        $div.css({
            top: top,
            display: 'block'
        });

    });   
    
}

var index = 0;
function showImage(id) {

    $.get("/Downloads/Images/" + path + "/" + id.toString(), function(result) {
        var data = eval('(' + result.toString() + ')');
        $("#imgWallpaper").attr('src', data.src);
        $("#aViewImg").click(function() { showGBIMG('', data.src); });
        $("#ddlDownload").children().remove();
        $("#ddlDownload").append("<option value=''>- Select -</option>");

        $("#div_Downloads a.add_opacity").css('opacity', '100');
        $("#img_" + id.toString()).css('opacity', '0.60');

        var dropdownList = document.getElementById("ddlDownload");

        if (data.desc != undefined) {
            $("#imgDesc").html(data.desc);            
        }

        if (dropdownList != undefined) {
            if (data.d1600 != '') {
                var opt1600 = document.createElement('option');
                opt1600.value = data.d1600;
                opt1600.innerHTML = "800 x 600 pixels";
                dropdownList.appendChild(opt1600);
            }
            if (data.d1024 != '') {
                var opt1024 = document.createElement('option');
                opt1024.value = data.d1024;
                opt1024.innerHTML = "1024 x 768 pixels";
                dropdownList.appendChild(opt1024);
            }
            if (data.d1280 != '') {
                var opt1280 = document.createElement('option');
                opt1280.value = data.d1280;
                opt1280.innerHTML = "1280 x 1024 pixels";
                dropdownList.appendChild(opt1280);
            }            
        }
        if (data.dPath != null) {            
            $("#hdnBox").attr('value', data.dPath);                        
        }
    });
}
function downloadItem(id) {
    var ddl = document.getElementById(id);
    if (ddl == undefined) {
        window.open($("#hdnBox").attr('value'), '', '');
    } else {
        if (ddl.selectedIndex == 0) { alert('Please select an image size'); return; }
        window.open(ddl[ddl.selectedIndex].value, '', '');
    }
}
function downloadBafanaItem() {
    //var ddl = document.getElementById(id);
   // if (ddl == undefined) {
        window.open($("#hdnBox").attr('value'), '', '');
    //} else {
    //    if (ddl.selectedIndex == 0) { alert('Please select an image size'); return; }
    //    window.open(ddl[ddl.selectedIndex].value, '', '');
    //}    
}
function isValid(ck1, ck2, ck3)
{
    var c1 = document.getElementById(ck1);
    var c2 = document.getElementById(ck2);
    var c3 = document.getElementById(ck3);

    if (!c1.checked && !c2.checked && !c3.checked) {
        alert('Please choose an option');
        return false;
    }
    else {
        return true;
    }
}
function showGBSize(title, url) {
    GB_showCenter(title, url, 406, 642);
    $('#ddlPlayers').css('visibility', 'hidden');
}
function showGBIMG(title, url) {
    $("#overlay").css('top', getYOffset()).fadeIn('50');
    $("#overlayz").css('top', getYOffset()).fadeIn('50');
    $("#lbImg").attr('src', url);
    //$("#flashheader").css('visibility', 'hidden');
    $(window).scroll(function() {
        if ($("#overlay").css('display')== 'block') {
            $("#overlay").css('top', getYOffset());
            $("#overlayz").css('top', getYOffset());
        }
    });
}

function showGBLanding() {
    $("#overlay").css('top', getYOffset()).fadeIn('50');

    $("#overlay").css('height', $(document).height());
    $("body").css('overflow','hidden');

    $("#overlayz").css('top', getYOffset()).fadeIn('50');
    $(window).resize(function() {
        if ($("#overlay").css('display') == 'block') {
            $("#overlay").css('top', getYOffset());
            $("#overlayz").css('top', getYOffset());
        }
    });
}

function closeImg() {
    $('#ddlPlayers').css('visibility', 'visible');
    $("#overlay").fadeOut('50');
    $("#overlayz").fadeOut('50', function() { $("#lbImg").attr('src', ''); });
    $("#flashheader").css('visibility', 'visible');
}

function getYOffset() {
    var pageY;
    if (typeof (window.pageYOffset) == 'number') {
        pageY = window.pageYOffset;
    }
    else {
        pageY = document.body.scrollTop;
    }
    return pageY;
}

function showPreviousImage() {    
    var $imgs = $("#div_Downloads a.add_opacity");   
    
    var total = $imgs.length;
    var result;

    index++;    
    result = Math.abs(total - (index % total)) % total + 1;

    var id = $imgs[result - 1].id.replace(/img_/, '');

    $("#div_Downloads a.add_opacity").css('opacity', '100');
    $("#" + $imgs[result - 1].id).css('opacity', '0.60');
    
    showImage(id);
}



function showNextImage() {
    var $imgs = $("#div_Downloads a.add_opacity");

    var total = $imgs.length;
    var result;

    index--;
    result = Math.abs(total - (index % total)) % total + 1;

    var id = $imgs[result - 1].id.replace(/img_/, '');

    $("#div_Downloads a.add_opacity").css('opacity', '100');
    $("#" + $imgs[result - 1].id).css('opacity', '0.60');
    showImage(id);
}

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;
}

function showBottomSlant() {
    $(function() {
        var height = $(document).height();

        var $div = $("#bkgBot");
        $div.css('display', 'none');
        var top = height - 151;

        if ($.browser.msie) {
            top = height - 154;
        }

        if ($.browser.msie && $.browser.version >= 6 && $.browser.version < 7) {
            top = height - 182;
        }

        $div.css({
            top: top
        });        
    });    
}

function showTerms() {
    showPopup('/termsandconditions', 'Terms and Conditions', 406, 642);
}
function showSurveyTerms() {
    showPopup('/surveytermsandconditions', 'Consumer Surbey Terms and Conditions', 406, 642);
}
function showPopup(url, title, height, width) {
    leftVal = (width - screen.width) / 2;
    topVal = (height - screen.height) / 2;
    window.open(url, "", "location=0,status=0,scrollbars=1,width=" + width + ",height=" + height + ",left=" + leftVal + ",top=" + topVal);
}
function ResetWrapHeight() {
    if ($(document).height() > $(window).height()) {
        $(window).scroll(function () { $('#wrap').css('height', $(document).height()); });
    }

    $(window).resize(function() { $('#wrap').css('height', $(document).height()); });
    $('#wrap').css('height', $(document).height());
}
//-->

function MM_preloadImages() 
{ //v3.0
    var d = document; if (d.images) 
    {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) 
            {
                d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; 
            }
    }
}


function hideOverlays() {
    if (checkAge() == true) {
        var o = document.getElementById("overlay");
        var oz = document.getElementById("overlayz");
        o.style.display = 'none';
        oz.style.display = 'none';
        document.cookie = "over18=true;";
        $(function () {$("#awinners").trigger('click');});        
    }
}

function checkAge() {

    var dd = parseInt(document.getElementById("txtdd").value);
    var mm = parseInt(document.getElementById("txtmm").value - 1);
    var yy = parseInt(document.getElementById("txtyy").value);

    var d = new Date();
    var today = new Date();
    var dateToCheck = new Date((yy + 18), mm, dd);

    if ((dd != "DD" && (isNumber(dd))) && (mm - 1 != "MM" && isNumber(mm)) && (yy != "YYYY" && isNumber(yy))) {
        if ((today.getTime() - dateToCheck.getTime()) < 0 || (d.getFullYear() - 100 > yy)) {
            document.location.href = 'http://www.appletiser.co.za';
            return false;
        }
        else {
            return true;
        }
    }
    else {
        return false;

    }

}


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;
}

function isNumber(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}

