// Library used for community services
var thisHost = window.location.host;

if (typeof(prependDomain) == "undefined") {
	prependDomain = "";
}

var Prefix = prependDomain;
var SIGNPAGE = Prefix + '/community/account/signin.jhtml';
var REGPAGE =  Prefix + '/community/account/join.jhtml';
var BOARDPAGE = Prefix + '/community/message_boards/adredirect.jhtml';
var BOARDTHREADPAGE = Prefix + '/community/message_boards/viewthread.jhtml';
var REDFLAGPAGE = Prefix + '/community/message_boards/redflag.jhtml';
var ARTISTBOARDPAGE = Prefix + '/community/message_boards/artistboard.jhtml';
var CHATPAGE = Prefix + '/community/chat/chat.jhtml';
var IMPAGE = Prefix + '/community/im/imlaunch.jhtml';
var IMDOWNLOAD = Prefix + '/community/im/imdownload.jhtml';
var INFOPAGE = Prefix + '/community/account/smryinfo.jhtml';
var mcPAGE = Prefix + '/community/messages/mclaunch.jhtml';
var VMPHONEPAGE = Prefix + '/secure/vmu/editvmu.jhtml?returnPage='+escape('http://'+thisHost+'/community/account/editvmusuccess.jhtml');
var VMPHONETEXT = Prefix + '/secure/vmu/editvmu.jhtml?returnPage='+escape('http://'+thisHost+'/community/account/editvmutext.jhtml?updateVMUser=true');
var winTarget= "im";

 
var openPARAMS = 'resizable=yes,menubar=no,location=no,toolbar=no,status=no,scrollbars,directories=no,width=605,height=500';
// This is the default for winPARAMS
var winPARAMS = 'resizable=no,menubar=no,location=no,toolbar=no,status=no,scrollbars=no,directories=no,width=260,height=425';
var mcPARAMS = openPARAMS;
var vmPARAMS = 'resizable=no,menubar=no,location=no,toolbar=no,status=no,scrollbars=no,directories=no,width=376,height=260';

var USER_BROWSER = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3 )) || ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 )))

function popMsg(daURL){
	newwin = window.open(daURL,'messages','width=556,height=486,scrollbars,resizable');
}

function signin(){
	signinPop();
}

function signinMsg(mtvparams, service){
	if(arguments.length != 2) {
		mtvparams="";
		service="";
	}
	editwindow = window.open(SIGNPAGE + '?serv=signin&mtvparams=' + mtvparams + '&oparam=' + service + '&target=', 'SignIn', openPARAMS); 
}

function signinPop(){
	editwindow = window.open(SIGNPAGE + '?serv=signin&mtvparams=&target=', 'SignIn', openPARAMS); 
}

function popSignin(){
	editwindow = window.open(SIGNPAGE + '?serv=signin&mtvparams=&target=', 'SignIn', openPARAMS); }

function editProfile(){
	if(USER_BROWSER){
		var editwindow;
		editwindow = window.open(SIGNPAGE + '?serv=profile&mtvparams=&target=self&oparam=edit_profile&mesg=', 'SignIn', openPARAMS); 
	}else{	
		editwindow = window.open(SIGNPAGE + '?serv=signin&mtvparams=&oparam=edit_profile&target=', 'mtv', openPARAMS);
		//window.open(SIGNPAGE + '?serv=profile&mtvparams=&target=self&mesg=','EditProfile',IEPARAMS); 
	}
}

function boardPop(bid,tid,mid,offset){
	var mbPARAMS = 'resizable=yes,menubar=no,location=no,toolbar,status,scrollbars,directories=no,width=760,height=435';
	if(arguments.length == 2){editwindow = window.open(BOARDPAGE + '?bID=' + bid + '&tID=' + tid, 'Board' + bid, mbPARAMS);}
	else if(arguments.length == 4){editwindow = window.open(BOARDTHREADPAGE + '?bID=' + bid + '&tID=' + tid + '&mID=' + mid + '&offset=' + offset, 'Board' + bid, mbPARAMS);}
	else{editwindow = window.open(BOARDPAGE + '?bID=' + bid, 'Board' + bid, mbPARAMS);}
	editwindow.focus;
}

function redFlag(bid,mid) {
	open(REDFLAGPAGE + '?mID=' + mid + '&bID=' + bid, 'RedFlag', 'width=400,height=200');
}

function artistBoardPop(artistid){
var mbPARAMS = 'resizable=yes,menubar=no,location=no,toolbar,status,scrollbars,directories=no,width=600,height=440';
	editwindow = window.open(ARTISTBOARDPAGE + '?artistid=' + artistid, 'Board' + artistid, mbPARAMS); }

function popChat(room){
	var chatPARAMS = 'resizable=yes,menubar=no,location=no,toolbar=no,status=no,scrollbars,directories=no,width=605,height=560';
	editwindow = window.open(CHATPAGE + '?oparam=chat&room=' + room, 'chat' + room,chatPARAMS); }

// legacy chat opener
function launchPopUpApp(p,room){
	l = room.length; var room = room.substring(5,l) 
	var chatPARAMS = 'resizable=yes,menubar=no,location=no,toolbar=no,status=no,scrollbars,directories=no,width=605,height=560';
	editwindow = window.open(CHATPAGE + '?room=' + room, 'chat' + room,chatPARAMS);
		}

function popIm(){
	randid = new String(Math.random());
	var editwindow;
	popimwin = window.open(IMPAGE + '?rnd=' + randid,winTarget,winPARAMS); }

function popImDownload(){
	editwindow = window.open(IMDOWNLOAD, 'imdownload',openPARAMS); 	}

function sendMessage(username){
	randid = new String(Math.random());
	editwindow = window.open(IMPAGE + '?rnd=' + randid + '&sendto=' + username,'im',openPARAMS); }

function popEmailLogin(){
	editwindow = window.open(SIGNPAGE + '?serv=mail&mtvparams=email&target=self&mesg=', 'EmailLogin', openPARAMS); }

function popEmailRegister(){
	editwindow = window.open(REGPAGE + '?serv=mail&mtvparams=email&target=self&mesg=', 'EmailLogin', openPARAMS); }

function popMessageCenter(){
	editwindow = window.open(mcPAGE, 'messages', mcPARAMS); }

function editAccount(){
	editwindow = window.open(INFOPAGE, 'EditAccount', openPARAMS); }

function linkPhone(host){
	window.open(host+VMPHONEPAGE, 'LinkPhone', vmPARAMS); }
	
function linkPhoneForText(host){
	window.location.href = host+VMPHONETEXT; 
}
