/* 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
   _proxy_jslib_handle(document, 'write', '', 1, 0)('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
 var contentloadtag= _proxy_jslib_handle(document, 'getElementById', '', 1, 0)("contentloadtag")
  contentloadtag.onreadystatechange=function() {
    if (this.readyState=="complete")
      SetContactLinkUrls()
 }
}




if(/Safari/i.test(navigator.userAgent)){ //Test for Safari
  var _timer= _proxy_jslib_handle(null, 'setInterval', setInterval, 1, 0)(function() {
  if(/loaded|complete/.test(document.readyState)){
    clearInterval(_timer)
 SetContactLinkUrls()  
 }}, 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;
	var viewAllFriendsUrl ='http://friends.myspace.com/index.cfm?fuseaction=user.viewfriends&friendID=' + profileId;
	var viewAllCommentsUrl ='http://comment.myspace.com/index.cfm?fuseaction=user.viewComments&friendID=' + profileId;
	var addCommentsUrl = 'http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm&friendID=' + profileId;	
	var viewAllTopicsUrl = 'http://forum.myspace.com/index.cfm?fuseaction=messageboard.viewcategory&type=friendForum&friendID=' + profileId;
	
	
    //if these elements exist in the page replace them.
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('addToFriends') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('addToFriends'), 'href', '=', ( addToFriendsUrl));
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('addToFavorites') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('addToFavorites'), 'href', '=', ( addToFavoritesUrl));
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('forwardToFriends') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('forwardToFriends'), 'href', '=', ( forwardToFriendsUrl));
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('addToGroups') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('addToGroups'), 'href', '=', ( addToGroupsUrl));
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('addToGroup') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('addToGroup'), 'href', '=', ( addToGroupsUrl));
	if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('sendMessage') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('sendMessage'), 'href', '=', ( sendMessageUrl));
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('rankUser') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('rankUser'), 'href', '=', ( rankUserUrl));
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('viewPictures') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('viewPictures'), 'href', '=', ( viewPicturesUrl));
	if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('subscribeBlog') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('subscribeBlog'), 'href', '=', ( subscribeBlogUrl));
	if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('linkViewAllFriends') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('linkViewAllFriends'), 'href', '=', ( viewAllFriendsUrl));
	if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('linkViewAllComments') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('linkViewAllComments'), 'href', '=', ( viewAllCommentsUrl));
	if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('linkAddComments') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('linkAddComments'), 'href', '=', ( addCommentsUrl));
	if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('linkViewAllTopics') != null)
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('linkViewAllTopics'), 'href', '=', ( viewAllTopicsUrl));
   
   
}









/************************************************************
* 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)
	     _proxy_jslib_handle(window, 'open', '', 1, 0)(url);
	else
    	 _proxy_jslib_assign('', document, 'location', '=', ( 'http://login.myspace.com/index.cfm?fuseaction=login'));
}



/************************************************************
* Writes swf object
* 
* 
************************************************************/
function flashcontent(url, width, height) {
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<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+'">');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<param name="movie" value="'+url+'" />');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<param name="quality" value="high" />');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<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+'">');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</embed>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</object>');
} ;
_proxy_jslib_flush_write_buffers() ;