/* Set of common functionality that can be used throughout profile building proccess. */

/*  hack to override this so we can use the body onload event
    Now if we want to use an onload event we just redefine the function called LoadPage()
    Note: this relies on the Javascript function getDisplayFriendID already exists.
*/
function initJSControl()
{
    try
    {    
        loadOverlay();
    }
    catch (ex){}

    try
    {
        SetContactLinkUrls();
        LoadPage();
    }
    catch (ex){}
    
} 


/***********************************************************
// dom ready hack
// hack to load the contact links module at dom ready instead of onload
***********************************************************/

if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", SetContactLinkUrls, false);

if (document.all && !window.opera){ //Crude test for IE
//Define a "blank" external JavaScript tag
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete")
      SetContactLinkUrls()
  }
}




if(/Safari/i.test(navigator.userAgent)){ //Test for Safari
  var _timer=setInterval(function(){
  if(/loaded|complete/.test(document.readyState)){
    clearInterval(_timer)
    SetContactLinkUrls() // call target function
  }}, 10)
}

/****************end dom ready hack************************/



/*****************************************************
Example HTML that uses this:
<div id="contactLinks">
    <a id="addToFriends" name="&lid=AddToFriends">add to friends</a>
    <a id="addToFavorites" name="&lid=AddToFavorites">add to favorites</a>
    <a id="forwardToFriends" name="&lid=ForwardToFriends">forward to friends</a>
    <a id="addToGroups" name="&lid=AddToGroups">add to groups</a>
</div>
******************************************************/

function SetContactLinkUrls()
{
    var profileId = getDisplayFriendID();
    var addToFriendsUrl = 'http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_advertiser&friendID=' + profileId;
    var addToFavoritesUrl = 'http://collect.myspace.com/index.cfm?fuseaction=user.addToFavorite&friendID=' + profileId + '&public=1';
    var forwardToFriendsUrl = 'http://messaging.myspace.com/index.cfm?fuseaction=mail.forward&friendID=' + profileId + '&f=forwardprofile';
    var addToGroupsUrl = 'http://groups.myspace.com/index.cfm?fuseaction=groups.addtogroup&friendID=' + profileId;
    var addToGroupUrl = 'http://groups.myspace.com/index.cfm?fuseaction=groups.addtogroup&friendID=' + profileId;
	var sendMessageUrl = 'http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID=' + profileId;
	var rankUserUrl = 'http://collect.myspace.com/index.cfm?fuseaction=RateImage.UserRating&UserID=' + profileId;
	var viewPicturesUrl = 'http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=' + profileId;    
	var subscribeBlogUrl = 'http://blog.myspace.com/index.cfm?fuseaction=blog.ConfirmSubscribe&friendID=' + profileId;
	
	
	
    //if these elements exist in the page replace them.
    if (document.getElementById('addToFriends') != null)
        document.getElementById('addToFriends').href = addToFriendsUrl;
    if (document.getElementById('addToFavorites') != null)
        document.getElementById('addToFavorites').href = addToFavoritesUrl;
    if (document.getElementById('forwardToFriends') != null)
        document.getElementById('forwardToFriends').href = forwardToFriendsUrl;
    if (document.getElementById('addToGroups') != null)
        document.getElementById('addToGroups').href = addToGroupsUrl;
    if (document.getElementById('addToGroup') != null)
        document.getElementById('addToGroup').href = addToGroupsUrl;
	if (document.getElementById('sendMessage') != null)
        document.getElementById('sendMessage').href = sendMessageUrl;
    if (document.getElementById('rankUser') != null)
        document.getElementById('rankUser').href = rankUserUrl;
    if (document.getElementById('viewPictures') != null)
        document.getElementById('viewPictures').href = viewPicturesUrl;
	if (document.getElementById('subscribeBlog') != null)
        document.getElementById('subscribeBlog').href = subscribeBlogUrl;
   
   
}









/************************************************************
* Opens a page if the user is logged in.  Otherwise, redirects
* them to the myspace login page. 
* Assumes that the isLoggedIn variable is defined on a page.
************************************************************/
function GetUrlWithLoginCheck(url)
{
	if (isLoggedIn > 0)
	    window.open(url);
	else
    	document.location = 'http://login.myspace.com/index.cfm?fuseaction=login';
}



/************************************************************
* Writes swf object
* 
* 
************************************************************/
function flashcontent(url, width, height)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+url+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<embed src="'+url+'" quality="high" allowScriptAccess="always" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'">');
	document.write('</embed>');
	document.write('</object>');
}