
///////////////////////////////////////////////////////////////////////////////////////
//  Opens a new window with the given URL
//	Parameter:
//	- URL: [String] URL of the website to be opened in the new window
//  - windowName: [String]  Name of the new window
//  - windowFeatures: [String] Features for the new window
///////////////////////////////////////////////////////////////////////////////////////
function openWindow(URL, windowName, windowFeatures){
    newWindow = window.open(URL, windowName, windowFeatures)
}



///////////////////////////////////////////////////////////////////////////////////////
//  Opens a new window with the given URL
//	Parameter:
//	- URL: [String] URL of the website to be opened in the new window
//  - windowName: [String]  Name of the new window
//  - windowFeatures: [String] Features for the new window
///////////////////////////////////////////////////////////////////////////////////////
function loadBadge(badgeURL, badgeWidth, badgeHeight, divName) {
  document.getElementById(divName).innerHTML = '<embed src="'+badgeURL+'?image='+imageUrl+'&isLoggedIn='+isLoggedIn+'" width="'+badgeWidth+'" height="'+badgeHeight+'" wmode="transparent" allowScriptAccess="always">';
}



///////////////////////////////////////////////////////////////////////////////////////
//  Adds the profile to the top friends of the user
//	User has to be friend with the profile!!
//	Parameter:
//	- mail: [String] mail address of the advertiser profile
///////////////////////////////////////////////////////////////////////////////////////
function addToTopFriends(mail) {
  if(isFriend > 0) {
    window.location = 'http://search.myspace.com/index.cfm?fuseaction=user.editTopFriends&searchBy=Email&f_search='+mail;
  } else {
    alert("Du musst mit dem Profil befreundet sein, um es zu deinen Top-Freunden hinzuzufügen.");
  }
}



///////////////////////////////////////////////////////////////////////////////////////
//  Posts the given HTML-Snippet to user profile
//	Parameter:
//	- title:    [String] If your content has a title, pass it with this parameter
//	- content:  [String] The content of what you’re sharing 
//	- url:      [String] If you want to send a clickable URL, pass it with this parameter
//	- location: [String] default location you want your content posted to
//                       • L=1, Blog
//                       • L=2, Bulletin
//                       • L=3, About Me
//                       • L=4. I’d like to Meet
//                       • L=5, Interests
//                       • L=6, Music
//                       • L=7, Movies
//                       • L=8, Television
//                       • L=9, Books,
//                       • L=10, Heroes
///////////////////////////////////////////////////////////////////////////////////////
function postToMS(title, content, url, location) {
  var targetUrl = 'http://www.myspace.com/Modules/PostTo/Pages/?' + 
	't=' + encodeURIComponent(title) + 
	'&c=' + encodeURIComponent(content) + 
	'&u=' + encodeURIComponent(url) + 
	'&l=' + location;
  window.open(targetUrl);
}




///////////////////////////////////////////////////////////////////////////////////////
// Contact functions 
///////////////////////////////////////////////////////////////////////////////////////

// Add to friends
function addToFriends() {
	window.location.href="http://friends.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID="+MySpaceClientContext.DisplayFriendId;
}

// Add to favourites
function addToFavourites() {
	window.location.href="http://collect.myspace.com/index.cfm?fuseaction=user.addToFavorite&friendID="+MySpaceClientContext.DisplayFriendId+"&public=0";
}

// Forward to friend
function forwardToFriend() {
	window.location.href="http://messaging.myspace.com/index.cfm?fuseaction=mail.forward&friendID="+MySpaceClientContext.DisplayFriendId+"&f=forwardprofile";
}

// Send a message
function sendAMessage() {
	window.location.href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID="+MySpaceClientContext.DisplayFriendId;
}

// Add to group
function addToGroup() {
	window.location.href="http://groups.myspace.com/index.cfm?fuseaction=groups.addtogroup&friendID="+MySpaceClientContext.DisplayFriendId;
}

// Block user
function blockUser() {
	window.location.href="http://friends.myspace.com/index.cfm?fuseaction=block.blockUser&userID="+MySpaceClientContext.DisplayFriendId;
}

// Rank user
function rankUser() {
	window.location.href="http://collect.myspace.com/index.cfm?fuseaction=RateImage.UserRating&UserID="+MySpaceClientContext.DisplayFriendId;
}



///////////////////////////////////////////////////////////////////////////////////////
// Other generic links
///////////////////////////////////////////////////////////////////////////////////////

// Subscribe to blog
function subscribeToBlog() {
	window.location.href="http://blog.myspace.com/index.cfm?fuseaction=blog.ConfirmSubscribe&friendID="+MySpaceClientContext.DisplayFriendId;
}

// View all blog entries
function viewAllBlogEntries() {
	window.location.href="http://blog.myspace.com/index.cfm?fuseaction=blog.ListAll&friendID="+MySpaceClientContext.DisplayFriendId;
}

// View all videos
function viewAllVideos() {
	window.location.href="http://vids.myspace.com/index.cfm?fuseaction=vids.showvids&friendID="+MySpaceClientContext.DisplayFriendId;
}

// View all pictures
function viewAllPics() {
	window.location.href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID="+MySpaceClientContext.DisplayFriendId;
}




///////////////////////////////////////////////////////////////////////////////////////
// Function for PNG fix in browsers < IE7
///////////////////////////////////////////////////////////////////////////////////////
function doPngFix(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (document.body.filters)){
		for(var i=0; i<document.images.length; i++){
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
}


///////////////////////////////////////////////////////////////////////////////////////
// Checks if the given text is made up of numbers
///////////////////////////////////////////////////////////////////////////////////////
function checkForNumbers(textValue) {
  var chkZ = 1;
  for (i = 0; i < textValue.length; ++i) {
    if (textValue.charAt(i) < "0" || textValue.charAt(i) > "9") chkZ = -1;
  }
		
  if (chkZ == -1) {
    return false;
  } else {
    return true;
  }
}



///////////////////////////////////////////////////////////////////////////////////////
// Video functions
///////////////////////////////////////////////////////////////////////////////////////
// Create objects and vars
var videoVars = new Object();


// ========= VIDEO FUNCTIONS ==========

// Create MySpace video player
function vid(divid, vidid, bg, width, height, autoPlay) {
	// Check that the name does not conflict
	newdivid = "myspacevidcontainer_"+divid;
	if(document.getElementById(newdivid)){
		alert("ERROR ENCOUNTERED BY vid():\nMore than one video player has the same name");
	}else{
		// First create the dynamic global variables. Each video will have its own variables.
		videoVars[divid] = new Object();
		videoVars[divid].vidid = vidid;
		videoVars[divid].bg = bg;
		videoVars[divid].width = width;
		videoVars[divid].height = height;
		
		if(autoPlay==true){
			aplay='1';
		}else{
			aplay='0';
		}
		// Create the code
		vidcode='<div id="'+newdivid+'" style="width:'+width+'px;height:'+height+'px;"><embed type="application/x-shockwave-flash" src="http://mediaservices.myspace.com/services/media/embed.aspx/m='+vidid+',t=1,mt=video,ap='+aplay+'" style="" id="'+divid+'" name="'+divid+'" bgcolor="#000000" quality="high" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" flashvars="e=http%3A//vids.myspace.com/&primaryColor=0x'+bg+'&secondaryColor=0x'+bg+'&sr=0" height="'+height+'" width="'+width+'"></div>';
		document.write(vidcode);
	}
}

// Change video in existing player
function changeVid(divid, newvidid, autoPlay){
	// Check that the target exists
	var newdivid = "myspacevidcontainer_"+divid;
	if(!document.getElementById(newdivid)){
		alert("ERROR ENCOUNTERED BY changeVid():\nThe target video does not exist");
	}else{
		// Set the current video id
		videoVars[divid].vidid = newvidid;
		
		if(autoPlay==true){
			aplay='1';
		}else{
			aplay='0';
		}
		// Create the code
		document.getElementById(newdivid).innerHTML = '<embed type="application/x-shockwave-flash" src="http://mediaservices.myspace.com/services/media/embed.aspx/m='+newvidid+',t=1,mt=video,ap='+aplay+'" style="" id="'+divid+'" name="'+divid+'" bgcolor="#000000" quality="high" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" flashvars="e=http%3A//vids.myspace.com/&primaryColor=0x'+videoVars[divid].bg+'&secondaryColor=0x'+videoVars[divid].bg+'&sr=0" height="'+videoVars[divid].height+'" width="'+videoVars[divid].width+'">';
	}
}



// Add the current video to profile
function addVid(target) {
	// Check that the target exists
	var newdivid = "myspacevidcontainer_"+target;
	if(!document.getElementById(newdivid)){
		alert("ERROR ENCOUNTERED BY addVid():\nThe target video does not exist");
	}else{
		window.location.href = "http://vids.myspace.com/index.cfm?fuseaction=vids.addToProfileConfirm&videoid="+videoVars[target].vidid;
	}
}

