// DFP ad serving variables
var ord		= Math.random()*10000000000000000;
var ordnum	= Math.round(Math.random() * 1000000000);


/*******************************************************************
 *	Menu navigation script added by RRO
 *******************************************************************/

function goOn(newURL) 
{

    //--If the selected file name isn't blank, send it to reader.

    if (newURL != "") 
    {

        location.href=newURL

    }

}

/*******************************************************************
 *	Cookie Functions
 *******************************************************************/
// WRITE THE COOKIE
function createCookie(name,value,days,related)
{
	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=/";
	if (related == 'team') {
		myTeamDisplay();
	}
}

// Check for a cookie's existance
function getCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');

    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) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
// Create a new cookie
function setCookie(name, value, expires, path, domain, secure) 
{
    var expDate		= new Date(expires);
    var curCookie	= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expDate.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}
// Delete an existing cookie
function deleteCookie(name, path, domain) 
{
    if (getCookie(name)) 
    {
        var curCookie	= name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
        document.cookie = curCookie;
    }
}

// DELETE THE COOKIE
function eraseCookie(name) {
	createCookie(name,"",-1,'team');
}


/*******************************************************************
 *	FireClick Functions
 *******************************************************************/
// Track a click and redirect the page
function flashFire (name, url) 
{
    window.open(url);
    fc_click(name, 'ad', url);
}
// Track a click without redirecting page
function flashFireNoGo (name, url) 
{
    fc_click(name, 'ad', url);
}


/*******************************************************************
 *	CNN Video Player Functions
 *******************************************************************/
// Open popup window
function CNN_openPopup( url, name, widgets, openerUrl )
{
    var host = location.hostname;
    try 
    {
        window.top.name = "opener";
    } catch (e) {}
    var popupWin = window.open( url, name, widgets );
    if ( popupWin) 
    {
        popupWin.focus();
    }
}
// Play a PGATOUR.com video
function cnnVideo( mode, arg, expiration ) 
{
    cnnVideoArgs = 'url=' + arg;
    openURL = '/video/player/player.html';;
    CNN_openPopup( 'http://www.pgatour.com/'+openURL+'?'+cnnVideoArgs, 'CNNVideoPlayer', 'scrollbars=no,resizable=no,width=770,height=570' );
}

//Gets the current URL and replaces '.../index.html' with '.../print.html'
//Used on the microsite news articles to pop up a printable version of the article
//NAB - 7/13/2008
function GetPrintURL()
{
    var myURL;
    var newURL; 
    var f = "/index.html";
    var fileRegEx = /\/index.html$/;
    var prnFile = "/print.html";

    myURL = window.location;
    myURL = String(myURL);
    if (myURL.match(fileRegEx)) {
        newURL = myURL.replace(fileRegEx, prnFile);
    }
    else {
        newURL = myURL + prnFile;
    }

    window.open(newURL, "mywindow","location=1,status=1,scrollbars=1,width=650,height=800");
    //testwindwo.moveTo(0,0);
}

//Used to assist in closing a window in Firefox.
//TFH - 6/28/2007
function closeWindow() 
{

    window.open('','_parent','');

    window.close();

}
//Used to open to the video page of pga.com from Senior PGA 2008 Microsite
function cnnOpen(url) 
{
    if (url) 
    {
        lowerUrl = url.toLowerCase().replace(" ", "");
		
        if (lowerUrl.indexOf("/video") != -1 || lowerUrl.indexOf("/audio") != -1) 
        {
            if (lowerUrl.indexOf("?") != -1) 
            { 
                openURL = url;
            }
            else 
            {
                openURL = "/video/?" + url
            }
			
            CNN_openPopup( 'http://www.pga.com' + openURL, 'CNNVideoPlayer', 'scrollbars=yes,status=yes,resizable=yes,width=1000,height=700' );
        }
		
        else if (lowerUrl.indexOf("/video/video") > -1 ||
            lowerUrl.indexOf("/video/audio") > -1 ||
            lowerUrl.indexOf("/video/") > -1 &&
            lowerUrl.indexOf("/video/liveat/") < 0) 
        {
            window.location = "/video/?" + url;
        } 
        else if (lowerUrl.indexOf("/photos/20") > -1) 
        {
            window.location = "/photos/?" + url;
        } 
        else if (lowerUrl.indexOf("/video/liveat/?") == 0) 
        {
            openLiveAt(url.replace("/video/liveat/?", ""));
        } 
        else if (lowerUrl.indexOf("/swingplex") > -1) 
        {
            CNN_openPopup(url, "780x445", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=780,height=445");
        } 
        else 
        {
            window.location = url;
        }
    }
}
function pgaVidOpen( url ) { cnnOpen(url); }

function MSloadPhotoGallery(_GalleryObj, _link) {

    if (!_GalleryObj || !_link) { 

        return; 

    }

	

    $("MSphotoGalH1").innerHTML = _GalleryObj.getElementsByTagName('h4')[0].innerHTML

    $("MSphotoGalBlurb").innerHTML = _GalleryObj.getElementsByTagName('span')[0].innerHTML;

	

    $("MSphotoGalFlashIF").src = _link;

}

function MSgetPhotoGalleryRef(_LinkObj, _link) {

    if (!_LinkObj || !_link) { 

        return; 

    }

	

    var oParentNodeRef;

    var oGrandParentNodeRef;

	

    try {

        oParentNodeRef = _LinkObj.parentNode;

        oGrandParentNodeRef = oParentNodeRef.parentNode;

        MSloadPhotoGallery(oGrandParentNodeRef, _link);

    } catch(e) {}

}

function configPageByPlayer(_playerName) {
     var playerNameLowercase = _playerName.toLowerCase();
    document.title = document.title + " " + _playerName + " Scorecard";
    try {
      document.getElementById("sc_name").innerHTML = "&nbsp;&raquo; &nbsp;" + _playerName + " Scorecard";
      
      var oSelectBoxProfile = document.getElementById("playerScorecardListBox");
      for (var i=0; i<oSelectBoxProfile.options.length; i++) {
          if (oSelectBoxProfile.options[i].text.toLowerCase().indexOf(playerNameLowercase) != -1) {
              oSelectBoxProfile.options[i].selected = true;
              break;
          }
      }
    }
    catch(e) {
         alert('error setting player select box or player breadcrumbs');
    }
}