function labelChange(pageTitle) {
    if (pageTitle.toLowerCase() == "home") {
        document.title = "adidasGolf.com | Equipment For Your Body | " + pageTitle;
        changeHeader("");
    }
    else {
        $("#printContentsHeader").html("<h1>" + pageTitle + "</h1>");
        document.title = "adidasGolf.com | Equipment For Your Body | " + pageTitle;
        changeHeader(pageTitle);
    }
}

function changePage(pageUrl, pageTitle) {
	//alert('changePage: ' + pageTitle);
    if (pageTitle.toLowerCase() == "home") {
        //$("#headline").html("");
        document.title = "adidasGolf.com | Equipment For Your Body | " + pageTitle;
    }
    else {

        //$("#headline").html(pageTitle);
        document.title = "adidasGolf.com | Equipment For Your Body | " + pageTitle;
        changeHeader(pageTitle);

        //sIFR.replace(adihausright, {
        //    selector: 'h1',
        //    wmode: 'transparent',
        //    css: '.sIFR-root { color: #666666; font-size:40px; text-transform:uppercase; } .sIFR-root a { color:#999999; text-decoration:none;} .sIFR-root a:hover { color:#CCCCCC; text-decoration:none;}'
        //});
    }
}

function showBackGround() {
	//alert('show bg');
    if (useFlashUnderlay) {
        $('#masthead').hide();
        $('#footer').hide();


        $('#flashunderlay').fadeOut("slow");
        $('#masthead').fadeIn("slow");
        $('#footer').fadeIn("slow");
        $('#content').attr("background-image", "/images/flashcontainerbg.jpg");
    }
    //$('#contain').css('display', 'none');
    //$('#contain').css('background', 'url(/images/bg_masthead.jpg) no-repeat');
    //$('#contain').fadeIn("slow");
}







function changeHeader(header) {
    /* Call a function registered as callPlayBall in the SWF named myMovie. */
    //getMovieName("HeaderText").changeHeader(header);   
    $("#headlinecontainer").html("");
    
    
    var randNum = Math.random()*99999999;
    
    $('#headlinecontainer').flash(
        { src: '/swf/HeaderText.swf?guid=' + randNum,
          width: 673,
          height: 100,          
          wmode: "transparent",
          base:"/swf",
          salign:"tl",
          menu:"false",          
          flashvars: { _headerText: header }
          },
        { version: 9 }
    );
    
    //var soHeadlineNew = new SWFObject("/swf/HeaderText.swf?guid=" + randNum, "HeaderText" + randNum, "673", "100", "9", "#FFF");
    //soHeadlineNew.addParam("scale", "noScale");
    //soHeadlineNew.addParam("allowFullScreen", "true");
    //soHeadlineNew.addParam("allowScriptAccess", "always");
    //soHeadlineNew.addParam("menu", "false");
    //soHeadlineNew.addParam("salign", "tl");
    //soHeadlineNew.addParam("base", "/swf");
    //soHeadlineNew.addParam("wmode", "transparent");
    //soHeadlineNew.addParam("FlashVars", "_headerText=" + header);   
    //soHeadlineNew.write('mastheadcontain');
        
}
/* This utility function resolves the string movieName to a Flash object reference based on browser type. */
function getMovieName(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function printText(htmlContent) {
    //al ert(htmlContent);    
    $("#printContents").html(htmlContent);
}

function loadFlashByURL(url) {
    var urlString = { "url": url };
    var jsonStr = top.JSON.stringify(urlString);

    $.ajax({
        type: "POST",
        url: "/webservices/adidaswebservice.asmx/GetPageXMLString",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            //alert(msg.d);
         // alert(msg.d);
            top.getMovieName("sotester").doDeepLink(msg.d);
            // alert('completed');
        }
    });
}

/* Popup Related Code */
function PositionPopup() {
    var flashCoords = $('#content').offset();

    var height = 598; //600; // 568; //424;
    var width = (flashCoords.left * 2 + $('#content').width()); //992;
    var xoffset = 0;
    var yoffset = 30;

    $('#popup').height(height);
    $('#popup').width(width);
    $('#popup').css('left', 0);  //eval(eval(flashCoords.left) + eval(xoffset)));
    $('#popup').css('top', 0); //eval(eval(flashCoords.top) + eval(yoffset)));
}

var blurinc = 0;
var focusinc = 0;

var blurred = true;

function blurHTMLContent() {
    blurred = true;
    blurinc = blurinc + 1;
    //$('#inc').html($('#inc').html() + 'blurred new<br>');

    $('#content').css({ backgroundImage: "url(none)" });
    $('#popup').css("z-index", -1);
}

function focusHTMLContent() {
    blurred = false;
    focusinc = focusinc + 1;
    //$('#inc').html($('#inc').html() + 'focused new<br>');

    $('#content').css({ backgroundImage: "url(/images/flashcontainerbg.jpg)" });
    $('#popup').css("z-index", 200);
}

function ModalPopup(url) {

    blurred = false;

    var flashCoords = $('#content').offset();

    var height = 598;  //600;  //568; //424;
    var width = (flashCoords.left * 2 + $('#content').width()); //992;
    var xoffset = 0;
    var yoffset = 30;


    $('#popup').height(height);
    $('#popup').width(width);
    $('#popup').css('position', 'absolute');

    $('#popup').css('left', 0);  //eval(eval(flashCoords.left) + eval(xoffset)));
    $('#popup').css('top', 0); //eval(eval(flashCoords.top) + eval(yoffset)));


    $('#popup').css("display", "block");


    $('#popup').html('<iframe src="' + url + '" id="PopIFrame" FRAMEBORDER="0" height="' + height + 'px" width="100%"  allowtransparency="true" background-color="transparent" scrolling="no"></iframe>');
    //$('#popup').html('test');
    $('#popup').css("z-index", 200);


    $(window).wresize(PositionPopup);

}

function findARetailer() {
    ModalPopup('/FindARetailer.aspx');
}

function searchAdidas(query) {
    setNavCookie();
    labelChange('Search');
    ModalPopup('/search.aspx?query=' + query);
}

function contactAdidas() {
    ModalPopup('/contact.aspx');
}

function signupAdidas() {
    ModalPopup('/signup.aspx');
}

function sitemapAdidas() {
    ModalPopup('/sitemap.aspx');
}

function errorAdidas() {
    ModalPopup('/error/404.aspx');
}

function closeModalFromFlash() {

    $('#popup').css('display', 'none');
    $('#popup').css('position', 'absolute');
    $('#popup').css('z-index', '-1');
    $('#popup').html('');

    return "true";
}

function goBack() {
    history.back();
}

function getCookie(c_name) {
    var retVal = getCookieTmp(c_name);
    getMovieName("sotester").returnCookie(retVal);
    return retVal;
}

function getCookieTmp(c_name) {
    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 "false";
}

function setCookie(name, value, expires) {
    Set_Cookie(name, value, expires, '/', '', 'false');
}

function Set_Cookie(name, value, expires, path, domain, secure) {

    myDate = new Date();
    myDate.setDate(myDate.getDate() + expires);
    document.cookie = name + "=" + value + "; path=/; expires=" + myDate;
}

function NoFlashTest() {    
    $(document).ready(function() {
        if ($("#content").html().length < 8 & useFlashUnderlay == false) {       
            $("#masthead").css("display","none");
            $("#footer").css("display","none");
            $("#content").css("background-image", "none");
         
            $("#content").css("text-align","center");
            $("#content").html("<a href=\"http://get.adobe.com/flashplayer/\"><img src=\"/images/noFlashImg.jpg\" style=\"margin-top:84px;\" alt=\"You must have flash installed to view this website\" border=\"0\"></a>");
        }
        else if ($("#content").html().length < 8 & useFlashUnderlay == true) {
            $("#flashunderlay").css("text-align", "center");
            $("#flashunderlay").css("z-index", "200");
            $("#flashunderlay").html("<a href=\"http://get.adobe.com/flashplayer/\"><img src=\"/images/noFlashImg.jpg\" style=\"margin-top:84px;\" alt=\"You must have flash installed to view this website\" border=\"0\" /></a>");
        }   
    });
}

function setNavCookie() {
    //Store the last page as it unloads
    if (document.URL != '') {
        var expire = new Date();
        expire.setFullYear(expire.getFullYear() + 1);
        cookieSet("LastPage", document.URL, expire);
    }
}

function getLastPage() {
    var last = cookieGet("LastPage");
    return last;
}

function cookieSet(name, value, expiry) {
    //delete old before setting new one
    //document.cookie = name.toString() + "=" + "" + "; expires=Thu, 01-Jan-70 00:00:01 GMT;";
    document.cookie = name + "=" + encodeURI(value) + "; expires=" + expiry + "; path=/";
}

//Simple function to get a cookie
function cookieGet(name) {
    var returnVal;
    name = name + "=";
    //Check that there are existing cookies
    if (document.cookie.length > 0) {

        var allcookies = document.cookie;
        var pos = allcookies.indexOf(name);

        //if exists then set else create new
        if (pos > -1) {
            var start = pos + name.toString().length;
            var end = allcookies.indexOf(";", start);
            if (end == -1) {
                end = allcookies.length;
            }
            returnVal = decodeURIComponent(allcookies.substring(start, end));
        }
        else {
            returnVal = null;
        }
    }
    else {
        returnVal = null;
    }

    return returnVal
}