//init globals
var isRichText = false;

function $(ElementId){
	return document.getElementById(ElementId);
}

function toggle(whichOne)
{
	if ($(whichOne).style.display == 'none')
		$(whichOne).style.display = '';
	else
		$(whichOne).style.display = 'none';
}

function _getCookie(name){
    var search = name;
    var returnval = '';

    if (document.cookie.length > 0){
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
		    offset += search.length+1;
		    end = document.cookie.indexOf(';', offset);
		    if (end == -1) {
				end = document.cookie.length;
		    }
	    	returnval = unescape(document.cookie.substring(offset, end));
		}
    }
    return returnval;		
}

var ajaxResponseDiv = "";

var Stage = {
	getWidth:function(){
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		return [ myWidth, myHeight ];
	},

	getScrollXY:function() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	}
}

function updateUserStatus(username, pmunread){
	var HTML = 'welcome, <a href="profile.php?user=' +username+ '">' +username+ '</a> | ';

	if(pmunread > 0)
		HTML += '<a href="my_messages.php"><img src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="emailOn"> <img src="http://static.networkpiece.com/c/pixel.gif" width="14" height="12" class="mailOn"></a> (<b><a href="my_messages.php">'+pmunread+'</a></b>) | ';
	else
		HTML += '<a href="my_messages.php"><img src="http://static.networkpiece.com/c/pixel.gif" width="14" height="12" class="emailOff"></a> (<a href="my_messages.php">0</a>) | ';
	HTML += '<a href="/profile.php?user='+username+'">my profile</a> | ';
	HTML += '<a href="/my_account.php">my account</a> | ';
	HTML += '<a href="/signup.php?action=logout">log out</a>';
	
	$('user_status').innerHTML = HTML;
}

var browse_index_media = 'rf', t_index_media = 'w';

function browseMediaList(browse, time) {
	if(browse=='' && time!='w' && time!='m' && time!='a')
		return;
	if(time=='' && browse!='rf' && browse!='rs' && browse!='mv' && browse!='tr' && browse!='md' && browse!='tf' && browse!='rr')
		return;

	if(browse != '')
		browse_index_media = browse;

	if(time != '')
		t_index_media = time;

	var browse_title, time_title;
	var b_titles = new Array();
	var browse_titles = new Array();
	var t_titles = new Array();
	var time_titles = new Array();

	b_titles[0] = "rf"; browse_titles[0] = "Featured";
	b_titles[1] = "rs"; browse_titles[1] = "Most Recent";
	b_titles[2] = "mv"; browse_titles[2] = "Most Viewed";
	b_titles[3] = "tr"; browse_titles[3] = "Top Rated";
	b_titles[4] = "md"; browse_titles[4] = "Most Discussed";
	b_titles[5] = "tf"; browse_titles[5] = "Top Favorited";
	b_titles[6] = "rr"; browse_titles[6] = "Rejected";

	t_titles[0] = "w"; time_titles[0] = "This Week";
	t_titles[1] = "m"; time_titles[1] = "This Month";
	t_titles[2] = "a"; time_titles[2] = "All Time";

	if (browse_index_media == "rf") {
		browse_title = 'Featured Media';
	} else if (browse_index_media == "rs") {
		browse_title = 'Most Recent Media';
	} else if (browse_index_media == "mv") {
		browse_title = 'Most Viewed Media';
	} else if (browse_index_media == "tr") {
		browse_title = 'Top Rated Media';
	} else if (browse_index_media == "md") {
		browse_title = 'Most Discussed Media';
	} else if (browse_index_media == "tf") {
		browse_title = 'Top Favorited Media';
	} else if (browse_index_media == "rr") {
		browse_title = 'Recently Rejected Media';
	}

	if(t_index_media == "d") {
		time_title = "Today";
	} else if(t_index_media == "w") {
		time_title = "This Week";
	} else if(t_index_media == "m") {
		time_title = "This Month";
	} else if(t_index_media == "a") {
		time_title = "All Time";
	}

	var listHeadHTML = '<span class="media_list_title">'+browse_title;
	if(t_index_media != "a")
		listHeadHTML+= ' ('+time_title+')';
	listHeadHTML+= '</span> <a href="/media.php?b='+browse_index_media+'&tm='+t_index_media+'">(view all)</a>';

	$('media_list_head').innerHTML = listHeadHTML;

	if(browse != '') {
		$('media_list_controls_b').innerHTML = '';
		for(var i=0; i<7; i++) {
			if(browse_index_media != b_titles[i]) {
				$('media_list_controls_b').innerHTML+= '<a onClick="browseMediaList(\''+b_titles[i]+'\',\'\')">'+browse_titles[i]+'</a>';
			} else {
				$('media_list_controls_b').innerHTML+= '<b>'+browse_titles[i]+'</b>';
			}
			if(i!=6)
				$('media_list_controls_b').innerHTML+= ' | '
		}

		if(browse=="rf" || browse=="rs" || browse=="rr") {
			$('media_list_controls_t').innerHTML = "This Week | This Month | All Time";
		} else {
			$('media_list_controls_t').innerHTML = "<b>This Week</b> | <a onClick=\"browseMediaList('','m')\">This Month</a> | <a onClick=\"browseMediaList('','a')\">All Time</a>";
		}
	}
	else if(time != '') {
		$('media_list_controls_t').innerHTML = '';
		for(var i=0; i<3; i++) {
			if(t_index_media != t_titles[i]) {
				$('media_list_controls_t').innerHTML+= '<a onClick="browseMediaList(\'\',\''+t_titles[i]+'\')">'+time_titles[i]+'</a>';
			} else {
				$('media_list_controls_t').innerHTML+= '<b>'+time_titles[i]+'</b>';
			}
			if(i!=2)
				$('media_list_controls_t').innerHTML+= ' | '
		}
	}

	$('media_list_more_bottom').innerHTML = '<a href="/media.php?b='+browse_index_media+'&tm='+t_index_media+'">See More '+browse_title+'</a>';

	ajaxResponseDiv = "media_list";
	var params = 'b='+browse_index_media+'&tm='+t_index_media;
	ajaxpack.getAjaxRequest("/ajax/preview_media_list.php", params, processGetPost, "txt")
}

function browsePeopleList(browse) {
	if(browse!='fd' && browse!='re' && browse!='me' && browse!='md' && browse!='mm')
		return;

	var browse_title;
	var b_titles = new Array();
	var browse_titles = new Array();

	b_titles[0] = "fd"; browse_titles[0] = "Featured";
	b_titles[1] = "re"; browse_titles[1] = "Most Repute";
	b_titles[2] = "me"; browse_titles[2] = "Most Experienced";
	b_titles[3] = "md"; browse_titles[3] = "Most Discussed";
	b_titles[4] = "mm"; browse_titles[4] = "Most Uploads";

	if (browse == "fd") {
		browse_title = 'Featured People';
	} else if (browse == "re") {
		browse_title = 'Most Repute People';
	} else if (browse == "me") {
		browse_title = 'Most Experienced People';
	} else if (browse == "md") {
		browse_title = 'Most Discussed People';
	} else if (browse == "mm") {
		browse_title = 'Most Uploads People';
	}

	$('people_list_head').innerHTML = '<span class="media_list_title">'+browse_title+'</span> <a href="/people.php?b='+browse+'">(view all)</a>';

	$('people_list_controls_b').innerHTML = '';
	for(var i=0; i<5; i++) {
		if(browse != b_titles[i]) {
			$('people_list_controls_b').innerHTML+= '<a onClick="browsePeopleList(\''+b_titles[i]+'\',\'\')">'+browse_titles[i]+'</a>';
		} else {
			$('people_list_controls_b').innerHTML+= '<b>'+browse_titles[i]+'</b>';
		}
		if(i!=4)
			$('people_list_controls_b').innerHTML+= ' | '
	}

	$('people_list_more_bottom').innerHTML = '<a href="/people.php?b='+browse+'">See More '+browse_title+'</a>';

	ajaxResponseDiv = "people_list";
	var params = 'b='+browse;
	ajaxpack.getAjaxRequest("/ajax/preview_people_list.php", params, processGetPost, "txt")
}

function browseCriteria(criteria, mediaId){

	var b_titles = new Array();
	var browse_titles = new Array();

	b_titles[0] = "r"; browse_titles[0] = "Related";
	b_titles[1] = "u"; browse_titles[1] = "Same User";
	b_titles[2] = "c"; browse_titles[2] = "Chronologically";

	$('browse_media_list').innerHTML = '';
	for(var i=0; i<3; i++) {
		if(b_titles[i] == criteria) $('browse_media_list').innerHTML+= '<b>'+browse_titles[i]+'</b>';
		else $('browse_media_list').innerHTML+= '<a onClick="browseCriteria(\''+b_titles[i]+'\',\''+mediaId+'\')">'+browse_titles[i]+'</a>';
		if(i!=2) $('browse_media_list').innerHTML+= ' | ';
	}

	ajaxResponseDiv = "mediaViewBrowseBlock";
	$(ajaxResponseDiv).innerHTML = '<div style="margin:0 auto; text-align:center; height:100px"><img src="http://static.networkpiece.com/c/LoadingGraphicSmall.gif"></div>';
	
	params = "c=" +criteria+ "&media_id=" +mediaId;
	ajaxpack.getAjaxRequest("/ajax/browse_criteria.php", params, processGetPost, "txt");
}

var alertHtmlWrap = 
	'<table height="170" cellpadding="0" cellspacing="0" style="background:#BDDD7A; width:400px"> \
		<tr> \
			<td align="center" > \
				<img src="http://static.networkpiece.com/c/pixel.gif" width="3" height="20"> \
		</tr> \
		<tr> \
			<td height="90" align="center" valign="top"> \
				<span id="_alertmessage" style="color:#317309; font: bold 20px Arial, Helvetica, sans-serif"></span><br /> \
				<img src="http://static.networkpiece.com/c/pixel.gif" width="7" height="7" /><br /> \
				<span id="_alertsubmessage" style="color:#333; font: 12px verdana, arial, Tahoma, sans-serif"></span><br /> \
			</td> \
		</tr> \
		<tr> \
			<td height="40" align="center" valign="top"> \
				<img style="display:none" id="_alertcancel" src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="btnCancel"> \
				<img src="http://static.networkpiece.com/c/pixel.gif" width="3" height="3"> \
				<img id="_alertok" src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="btnOk"> \
			</td> \
		</tr> \
	</table>';

var Alert = {

	html: alertHtmlWrap, 
	preload:function() {
		if(!$('_alert')){
			this.alert  = document.createElement('div');
			this.alert.id = '_alert';
			this.alert.style.position = 'absolute';
			this.alert.innerHTML = this.html;
			this.alert.style.display = 'none';
		}
	},
	
	show:function(listener, message, submessage, cancel, isLoginBox){

		if(!$('_alert')){
			this.alert  = document.createElement('div');
			this.alert.id = '_alert';
			this.alert.style.position = 'absolute';
			this.alert.style.zIndex = 999;
			this.alert.innerHTML = this.html;
			document.body.appendChild(this.alert);
		}

		var width = Stage.getWidth();
		var scroll = Stage.getScrollXY();

		var left = 1/2 * (width[0] - 400) + scroll[0];
		var top = 1/2 * (width[1] - 235) + scroll[1];

		this.move(left, top);

		if(isLoginBox == true) {
			$('_alertok').style.display = 'none';
		}
		if(cancel){
			$('_alertcancel').style.display = 'inline';
		}else{
			$('_alertcancel').style.display = 'none';
		}
		var me = this;
		$('_alertcancel').onmousedown = function(){
			me.doCancel();
		};
		if(isLoginBox != true) {
			$('_alertok').style.display = 'inline';
			$('_alertok').onmousedown = function(){
				 me.doOk();
			};
		}
		this.message = message;
		this.submessage = submessage;
		this.listener = listener;
		$('_alertmessage').innerHTML = this.message;
		$('_alertsubmessage').innerHTML = this.submessage;
		if(isLoginBox == true) {
			$('_alertok').onmousedown = function(){
				 me.doOk();
			};
		}
		this.alert.style.display = '';
	},

	doCancel:function(){
		if(this.listener && this.listener.onAlertCancel){
			this.listener.onAlertCancel(this.alert);
		}
		this.hide();
		$('_alertcancel').onmousedown = null;
		$('_alertok').onmousedown = null;
		$('_alertmessage').innerHTML = '';
		$('_alertsubmessage').innerHTML = '';
	},

	doOk:function(){
		if(this.listener && this.listener.onAlertOk){
			this.listener.onAlertOk(this.alert);
		}
		this.hide();
		$('_alertcancel').onmousedown = null;
		$('_alertok').onmousedown = null;
    	$('_alertmessage').innerHTML = '';
		$('_alertsubmessage').innerHTML = '';
	},

	hide:function(){
		this.alert.style.display = 'none';
	},

	move:function(x, y){
	   if (this.alert){
			this.alert.style.left = x + 'px';
			this.alert.style.top = y + 'px';
		}
	}
};

var LoginAlert = {
	finishOriginatingRequests : new String(),
	requestParameters : new Array(),
    
	loginCallback:function(){
		var myajax=ajaxpack.ajaxobj
		if (myajax.readyState == 4){ //if request of file completed
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally

				var params = myajax.responseText.split("&");
				var status = params[0].split('=')[1];
			   
				if(status == 'true'){
					if(LoginAlert.finishOriginatingRequests){
						LoginAlert.finishOriginatingRequests.apply(LoginAlert.finishOriginatingRequests, LoginAlert.requestParameters);
					}else{
						Alert.show(undefined, 'Yay!', 'Logged in!', false);
					}
					var username = params[1].split('=')[1];
					var pmunread = params[2].split('=')[1];
					updateUserStatus(username, pmunread);
				} else {
					var errmsg = params[1].split('=')[1];
					Alert.show(undefined, 'Login Error!', errmsg, false, false);
				}
			   
				if(LoginAlert.finishOriginatingRequests){
					LoginAlert.finishOriginatingRequests=null;
				}
			}
		}
	},

	show:function(parameters){
		
		if(parameters && parameters.originatingRequest){
			this.finishOriginatingRequests=parameters.originatingRequest;
			this.requestParameters=parameters.requestParameters;
		}
		var o = new Object();
		var me = this;
		o.onAlertOk = function(e){
			params = "username="+ escape($('pop_username').value) + "&password="+ escape($('pop_password').value);
			ajaxpack.getAjaxRequest("/ajax/login.php", params, me.loginCallback, "txt");
		};
		
		var alertHTML = 
			'<table cellpadding="0" cellspacing="0" style="width:342px"> \
			<tr> \
			<td style="color: #333; text-align:left;">username</td><td style="color: #333; text-align:left;">password</td><td></td> \
			</tr> \
			<tr> \
			<td style="width:145px;" align=left><input id="pop_username" name="pop_username" type="text" style="width:130px;"/></td><td style="width:145px;" align=left><input id="pop_password" name="pop_password" type="password" style="width:130px;"/></td><td> <img id="_alertok" src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="btnSignin"></td> \
			</tr>   \
			<tr><td colspan="3" align=center style="padding-top:14px;"><a href="/signup.php"><b>JOIN HEAVEN666, It\'s Easy and Free!</b></a></td></tr>\
			</table>';
		
		Alert.show(o, "You are not logged in.", alertHTML, true, true);
	}
};

function addToFav(mediaId){
	var userId = _getCookie("h6userid");
	if(userId == '') {
		LoginAlert.show({originatingRequest: addToFav, requestParameters:[mediaId]});
	} else {
		var params = "media_id=" + mediaId;
		ajaxpack.getAjaxRequest("/ajax/add_to_fav.php", params, callbackFunction, "txt");
	}
}

function subscribeToUser(subscribe, toUserid, toUsername){
	var userId = _getCookie("h6userid");
	if(userId == '') {
		LoginAlert.show({originatingRequest: subscribeToUser, subscribeToUser:[subscribe, toUserid, toUsername]});
	} else {
		var params = "subscribe=" + subscribe + "&user_id=" + userId + "&to_userid=" + toUserid + "&to_username=" + toUsername;
		ajaxpack.getAjaxRequest("/ajax/subscribe_to_user.php", params, subscribeToUserCallback, "txt");
	}
}

function subscribeToUserCallback(){
	var myajax=ajaxpack.ajaxobj
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var params = myajax.responseText.split("&");
			var status = params[0].split('=')[1];
			var toUserId = params[1].split('=')[1];
			var toUserName = params[2].split('=')[1];
			var subscribe = params[3].split('=')[1];
				   
			if(status == 'true'){
				var msg = params[4].split('=')[1];
				if(subscribe=="1"){
					html = '<a class=\"unsubButton\" onClick=\"subscribeToUser(\'0\', \''+toUserId+'\', \''+toUserName+'\')\"><b><b><b>Unsubscribe</b></b></b></a>';
				}
				else{
					html = '<a class=\"subButton\" onClick=\"subscribeToUser(\'1\', \''+toUserId+'\', \''+toUserName+'\')\"><b><b><b>Subscribe</b></b></b></a>';
				}
				$('subscribe_to_user').innerHTML = html;
				Alert.show(undefined, 'Success', msg, false);
			} else {
				var errmsg = params[4].split('=')[1];
				Alert.show(undefined, 'Error!', errmsg, false, false);
			}
		}
	}
}

function addFriend(friendId, friendUsername){
	var userId = _getCookie("h6userid");
	if(userId == '') {
		LoginAlert.show({originatingRequest: addFriend, requestParameters:[friendId, friendUsername]});
	} else {
		var params = "user_id=" + userId + "&friend_id=" + friendId + "&friend_username=" + friendUsername;
		ajaxpack.getAjaxRequest("/ajax/add_friend.php", params, callbackFunction, "txt");
	}
}

function blockUser(block, blockedId){
	var userId = _getCookie("h6userid");
	if(userId == '') {
		LoginAlert.show({originatingRequest: blockUser, requestParameters:[block, blockedId]});
	} else {
		var params = "block=" + block + "&user_id=" + userId + "&blocked_id=" + blockedId;
		ajaxpack.getAjaxRequest("/ajax/block_user.php", params, blockUserCallback, "txt");
	}
}

function blockUserCallback(){
	var myajax=ajaxpack.ajaxobj
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var params = myajax.responseText.split("&");
			var status = params[0].split('=')[1];
			var userId = params[1].split('=')[1];
			var block  = params[2].split('=')[1];
				   
			if(status == 'true'){
				var msg = params[3].split('=')[1];
				html = '<img src="http://static.networkpiece.com/c/pixel.gif" width="17" height="17" class="blockUser"> ';
				if(block==1){
					html += '<a onClick="blockUser(\'0\', \''+userId+'\')">Unblock User</a>';
				}
				else{
					html += '<a onClick="blockUser(\'1\', \''+userId+'\')">Block User</a>';
				}
				$('block_user').innerHTML = html;
				Alert.show(undefined, 'Success', msg, false);
			} else {
				var errmsg = params[3].split('=')[1];
				Alert.show(undefined, 'Error!', errmsg, false, false);
			}
		}
	}
}

function callbackFunction(){
	var myajax=ajaxpack.ajaxobj
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var params = myajax.responseText.split("&");
			var status = params[0].split('=')[1];
				   
			if(status == 'true'){
				var msg = params[1].split('=')[1];
				Alert.show(undefined, 'Success', msg, false);
			} else {
				var errmsg = params[1].split('=')[1];
				Alert.show(undefined, 'Error!', errmsg, false, false);
			}
			if(params.length == 3)
			{
				var close = params[2].split('=')[1];
				if(close == 'panel1') closePanel('panel1');
				else if(close == 'panel2') closePanel('panel2');
			}
		}
	}
}

function launchEmailFriendPanel(section, url){
	if(!$('email_to_friends')){
	var width = Stage.getWidth();
	var scroll = Stage.getScrollXY();
			
	var _x = 1/2 * (width[0] - 400) + scroll[0];
	var _y = 1/2 * (width[1] - 300) + scroll[1];

	var initObj = {width:"400px", visible:true, constraintoviewport:true, modal:true, xy:[_x,_y]};
	panel1 = new YAHOO.widget.ResizePanel('email_to_friends', initObj);

	var panelBody = 
		'<table cellpadding="2" cellspacing="0" style="width:342px; text-align:left; font:12px Verdana; color: #333"><tr> \
		<td colspan=2><div id="sendEmailError" class="red"></div></td> \
		</tr><tr> \
		<td>your name*</td><td>your email*</td><td></td> \
		</tr><tr> \
		<td style="width:200px"><input id="sender_name" name="sender_name" type="text" style="width:185px"></td><td style="width:200px"><input type="text" id="sender_email" name="sender_email" style="width:185px"></td> \
		</tr><tr> \
		<td colspan=2>your friend(s) email address(es)*</td> \
		</tr><tr> \
		<td colspan=2><textarea id="recipient_emails" name="recipient_emails" style="width:375px; height:28px"></textarea><br>(separate multiple email address with a comma)</td> \
		</tr><tr> \
		<td colspan=2 style="padding-top:2px"><input type="button" value="Send" onClick="sendEmail(\''+section+'\', \''+url+'\')"></td> \
		</tr> \
		</table>';

	panel1.setHeader('Email '+section+' to a friend');
	panel1.setBody(panelBody);
	panel1.render(document.body);
	}
	else{
		panel1.show();
	}
}

function sendEmail(section, url){
	params = 'section='+section+'&url='+url+'&recipient_emails='+$('recipient_emails').value+'&sender_email='+$('sender_email').value+'&sender_name='+$('sender_name').value;
	ajaxpack.getAjaxRequest("/ajax/email_to_friends.php", params, sendEmailCallback, "txt")
}

function sendEmailCallback(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			
			var params = myajax.responseText.split("&");
			var status = params[0].split('=')[1];
				   
			if(status == 'true'){
				var msg = params[1].split('=')[1];
				$('sendEmailError').innerHTML = '';
				Alert.show(undefined, 'Success', msg, false);
				closePanel('panel1');
			} else {
				var errmsg = params[1].split('=')[1];
				$('sendEmailError').innerHTML = errmsg;
			}
		}
	}
}

function launchFlagContentPanel(mediaId){
	var userId = _getCookie("h6userid");
	if(userId == '') {
		LoginAlert.show({originatingRequest: launchFlagContentPanel, requestParameters:[mediaId]});
	} else {
		if(!$('flag_content')){
		var width = Stage.getWidth();
		var scroll = Stage.getScrollXY();
				
		var _x = 1/2 * (width[0] - 400) + scroll[0];
		var _y = 1/2 * (width[1] - 300) + scroll[1];

		var initObj = {width:"400px", visible:true, constraintoviewport:true, modal:true, xy:[_x,_y]};
		panel2 = new YAHOO.widget.ResizePanel('flag_content', initObj);

		var panelBody = 
			'<table cellpadding="2" cellspacing="0" style="width:342px; text-align:left; font:12px Verdana; color: #333"><tr> \
			<td>Please help us keep this website clean and protect its essance. Select your reason for flagging this media as inappropriate from the dropdown below</td><td></td> \
			</tr><tr> \
			<td><select id="reason" name="reason"> \
				<option value="0">Choose a Reason</option> \
				<option value="1">Repost</option> \
				<option value="16">Pornographic or sexually explicit</option> \
				<option value="2">Pointless without any redeeming qualities</option> \
				<option value="12">Depictions of death and/or Extreme violence</option> \
				<option value="15">Bad Tags</option> \
				<option value="11">Media has other websites\' logos or names on it</option> \
				<option value="3">Not working</option> \
				<option value="9">Other</option> \
			  </select></td> \
			</tr><tr> \
			<td colspan=2 style="padding-top:6px"><img src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="btnSend" onmousedown="flagContent(\''+userId+'\', \''+mediaId+'\')"> <img src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="btnCancel" onmousedown="closePanel(\'panel2\')"></td> \
			</tr> \
			</table>';

		panel2.setHeader('This media is inappropriate');
		panel2.setBody(panelBody);
		panel2.render(document.body);
		}
		else{
			panel2.show();
		}
	}
}

function flagContent(userId, mediaId){
	params = 'user_id='+userId+'&media_id='+mediaId+'&reason='+$('reason').options[$('reason').selectedIndex].value;
	ajaxpack.getAjaxRequest("/ajax/flag_content.php", params, callbackFunction, "txt")
}

function commentsRatingAbuse(userId, commentId){
	params = 'user_id='+userId+'&comment_id='+commentId;
	ajaxpack.getAjaxRequest("/ajax/comments_rating_abuse.php", params, callbackFunction, "txt")
}

var panel1, panel2;

function include(type, file){
	var head = document.getElementsByTagName("head")[0];
	if(type == 'css'){
		var elem = document.createElement('link');
		elem.id = 'RichTextEditorStyles';
		elem.type = 'text/css';
		elem.rel = 'stylesheet';
		elem.href = file;
	}
	head.appendChild(elem);
}

function launchAddProfileComment(toUserid, toUsername){
	var userId = _getCookie("h6userid");
	if(userId == ''){
		LoginAlert.show({originatingRequest: launchAddProfileComment, requestParameters:[toUserid, toUsername]});
	}else{
		if(!$('add_profile_comment')){
			if(!$('RichTextEditorStyles')) include('css', '/javascript/rte/rte.css');

			var width = Stage.getWidth();
			var scroll = Stage.getScrollXY();
			var _x = 1/2 * (width[0] - 520) + scroll[0];
			var _y = 1/2 * (width[1] - 368) + scroll[1];

			var initObj = {width:"520px", height:"368px", visible:true, constraintoviewport:true, modal:true, xy:[_x,_y]};
			panel1 = new YAHOO.widget.ResizePanel('add_profile_comment', initObj);
			panel1.setHeader('Add a profile comment');

			if(!$('send_message'))
				initRTE("./javascript/rte/images/", "./javascript/rte/", "");
			rte1 = new richTextEditor('rte1');
			var html = '<input type=hidden id=touserid name=touserid value="">';
			html+= '<input type=hidden id=tousername name=tousername value="">';
			html+= '<div style="text-align:left; font:12px Verdana, Arial, sans-serif" id=to></div>';
			panel1.appendToBody(html);
			rte1.build();
		}else{
			if (isRichText){
				html='<iframe id="rte1" name="rte1" frameborder="0" style="visibility:visible; width:508px; height:260px; margin:0; padding:0; border: 1px solid #000"></iframe>';
				panel1.appendToBody(html);
			}
			$('contain_rte1').style.visibility = "visible";
			enableDesignMode("rte1", "");
			$('panel_buttons').className = ""; $('panel_loading').className = "hid";
			panel1.show();
		}
		$('touserid').value = toUserid;
		$('tousername').value = toUsername;
		$('to').innerHTML = 'To: <a href="/profile.php?user='+toUsername+'">'+toUsername+'</a>';
	}
}

function addProfileComment(){
	updateRTEs();
	if($('hdnrte1').value.length > 2){
		params = "to_userid=" +$('touserid').value+ "&to_username="+$('tousername').value+ "&comment="+$('hdnrte1').value;
		ajaxpack.getAjaxRequest("/ajax/add_profile_comment.php", params, addProfileCallback, "txt")
	}else{
		Alert.show(undefined, 'Error', 'Your comment must have at least 2 caracters', false);
		
		$('panel_buttons').className = ""; $('panel_loading').className = "hid";
	}
}

function addProfileCallback(){
	var myajax=ajaxpack.ajaxobj
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var params = myajax.responseText.split("&");
			var status = params[0].split('=')[1];
				   
			if(status == 'true'){
				var toUserId = params[1].split('=')[1];
				var msg = params[2].split('=')[1];

				moreProfileItems('comments', toUserId, 'xxx', '', '1', '', '');
				Alert.show(undefined, 'Success', msg, false);
				closePanel('panel1');
			} else {
				var errmsg = params[1].split('=')[1];
				Alert.show(undefined, 'Error!', errmsg, false, false);
			}
		}
	}
}

function launchSendMessage(toUserid, toUsername){
	var userId = _getCookie("h6userid");
	if(userId == ''){
		LoginAlert.show({originatingRequest: launchSendMessage, requestParameters:[toUserid, toUsername]});
	}else{
		if(!$('send_message')){
			if(!$('RichTextEditorStyles')) include('css', '/javascript/rte/rte.css');

			var width = Stage.getWidth();
			var scroll = Stage.getScrollXY();
			var _x = 1/2 * (width[0] - 520) + scroll[0];
			var _y = 1/2 * (width[1] - 392) + scroll[1];

			var initObj = {width:"520px", height:"392px", visible:true, constraintoviewport:true, modal:true, xy:[_x,_y]};
			panel2 = new YAHOO.widget.ResizePanel('send_message', initObj);
			panel2.setHeader('Send message');
			
			if(!$('add_profile_comment'))
				initRTE("./javascript/rte/images/", "./javascript/rte/", "");
			rte2 = new richTextEditor('rte2');
			var html = '<input type=hidden id=touserid2 name=touserid value="">';
			html+= '<input type=hidden id=tousername2 name=tousername value="">';
			html+= '<div style="text-align:left; font:12px Verdana, Arial, sans-serif" id=to2></div>';
			html+= '<div style="text-align:left; font:12px Verdana, Arial, sans-serif; padding-top:2px; padding-bottom:2px">Subject: <input type=text maxlength="249" name="subject" id="subject2" style="width:420px"></div>';
			panel2.appendToBody(html);
			rte2.build();
		}else{
			html='<iframe id="rte2" name="rte2" frameborder="0" style="visibility:visible; width:508px; height:260px; margin:0; padding:0; border: 1px solid #000"></iframe>';
			panel2.appendToBody(html);
			$('contain_rte2').style.visibility = "visible";
			enableDesignMode("rte2", "");
			$('panel_buttons').className = ""; $('panel_loading').className = "hid";
			panel2.show();
		}
		$('touserid2').value = toUserid;
		$('tousername2').value = toUsername;
		$('to2').innerHTML = 'To: <a href="/profile.php?user='+toUsername+'">'+toUsername+'</a>';
		$('subject2').value = '';
	}
}

function sendMessage(){
	updateRTEs();
	if($('subject2').value.length <= 0){
		Alert.show(undefined, 'Error', 'Subject missing. Please check the subject of your message', false);

		$('panel_buttons').className = ""; $('panel_loading').className = "hid";
	}
	else if($('hdnrte2').value.length <= 2){
		Alert.show(undefined, 'Error', 'Your message must have at least 2 caracters', false);

		$('panel_buttons').className = ""; $('panel_loading').className = "hid";
	}
	else if($('hdnrte2').value.length > 65535){
		Alert.show(undefined, 'Error', 'Your message is too long. 65535 is the max number of characters allowed', false);

		$('panel_buttons').className = ""; $('panel_loading').className = "hid";
	}
	else{
		params = "to_userid=" +$('touserid2').value+ "&to_username="+$('tousername2').value+ "&subject="+$('subject2').value+ "&comment="+$('hdnrte2').value;
		ajaxpack.getAjaxRequest("/ajax/send_message.php", params, callbackFunction, "txt")		
	}
}

function certify(userId, userName){
	if (confirm('Are you sure you want to certify this profile?'))
	{
		params = "certified_userid=" + userId + "&certified_username=" + userName;
		ajaxpack.getAjaxRequest("/ajax/certify.php", params, callbackFunction, "txt")
	}
}

function closePanel(panel){
	if(panel=='panel1'){
		if(isRichText){
			if($('rte1').parentNode){if($('rte1').parentNode.removeChild){$('rte1').parentNode.removeChild($('rte1'))}}
			if($('cp').style.visibility == "visible"){$('cp').style.visibility = "hidden";}
			if($('contain_rte1').style.visibility == "visible"){$('contain_rte1').style.visibility = "hidden";}	
		}
		panel1.hide()
	}else if(panel=='panel2'){
		if(isRichText){
			if($('rte2').parentNode){if($('rte2').parentNode.removeChild){$('rte2').parentNode.removeChild($('rte2'))}}
			if($('cp').style.visibility == "visible"){$('cp').style.visibility = "hidden";}
			if($('contain_rte2').style.visibility == "visible"){$('contain_rte2').style.visibility = "hidden";}
		}
		panel2.hide()
	}else if(panel=='panel3'){
		panel3.hide()
	}

}

function addComment(mediaId){
	var userId = _getCookie("h6userid");
	if(userId == '') {
		LoginAlert.show({originatingRequest: addComment, requestParameters:[mediaId]});
	} else {
		params = "media_id=" + mediaId + "&comment=" + escape($('comment').value);
		ajaxpack.getAjaxRequest("/ajax/add_comment.php", params, addCommentCallback, "txt")
	}
}

function addCommentCallback(){
	var myajax=ajaxpack.ajaxobj
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var params = myajax.responseText.split("&");
			var status = params[0].split('=')[1];
				   
			if(status == 'true'){
				var mediaId = params[1].split('=')[1];
				var username = params[2].split('=')[1];
				var avatarpath = params[3].split('=')[1];
				var commentId = params[4].split('=')[1];
				var comment = $('comment').value;

				var commentBlock = '<table width="100%" cellpadding=2>';
				commentBlock += '<tr><td valign=top align=center class=avatar><a href="/profile.php?user='+username+'"><img src="http://u.heaven666.org/p75/'+avatarpath+'"></a></td>';
				commentBlock += '<td valign=top><div class=title><a href="/profile.php?user='+username+'">'+username+'</a> posted 0 minutes ago</div><br>'+comment;
		
				commentBlock += ' <a text-decoration: underline" onClick="displayReplyComment(\''+commentId+'\', \''+mediaId+'\')">reply</a></td></tr>';
				commentBlock += '</table>';

				commentBlock += '<div id="reply_comment_form_id_'+commentId+'" style="display:none"></div>';

				$('user_comments').innerHTML = $('user_comments').innerHTML + commentBlock;
				$('comment').value='';
			} else {
				var errmsg = params[1].split('=')[1];
				Alert.show(undefined, 'Error!', errmsg, false, false);
			}
		}
	}
}

function rateComment(rating, commentId, mediaId, commentUserid){
	var userId = _getCookie("h6userid");
	if(userId == '')
	{
		LoginAlert.show({originatingRequest: rateComment, requestParameters:[rating, commentId, mediaId, commentUserid]});
	}
	else
	{
		params = "comment_id=" +commentId+ "&media_id=" + mediaId + "&comment_userid=" + commentUserid + "&rating=" + rating + "&current_rating=" + $('rating_'+commentId).innerHTML;

		$('rating_'+commentId).innerHTML = '<div style="margin:0 auto; text-align:center; height:250px; padding-top:5px"><img src="http://static.networkpiece.com/c/LoadingGraphicSmall.gif"></div>';

		ajaxpack.getAjaxRequest("/ajax/rate_comment.php", params, rateCommentCallback, "txt");
	}
}

function rateCommentCallback(){
	var myajax=ajaxpack.ajaxobj
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var params = myajax.responseText.split("&");
			var status = params[0].split('=')[1];
				   
			if(status == 'true'){
				var currentRating = parseInt(params[1].split('=')[1]);
				var rating = parseInt(params[2].split('=')[1]);
				var commentId = params[3].split('=')[1];

				if(currentRating == 0){
					if(rating == -1){
						$('rating_'+commentId).innerHTML = -1;
						$('rating_'+commentId).style.color = '#C40000';
					}
					else{
						$('rating_'+commentId).innerHTML = +1;
						$('rating_'+commentId).style.color = 'green';
					}
					$('rating_'+commentId).style.fontWeight = 'bold';
				}
				else{
					if((currentRating+rating)!=0){
						$('rating_'+commentId).innerHTML = currentRating+rating;
						if(currentRating+rating>0) $('rating_'+commentId).innerHTML = '+' + $('rating_'+commentId).innerHTML;
					}
					else
						$('rating_'+commentId).innerHTML = '';
				}

				$('rate_links_'+commentId).style.display = 'none';
			} else {
				var currentRating = parseInt(params[1].split('=')[1]);
				var commentId = params[2].split('=')[1];
				var errmsg = params[3].split('=')[1];
				
				$('rating_'+commentId).innerHTML = currentRating;
				Alert.show(undefined, 'Error!', errmsg, false, false);
			}
		}
	}
}

function replyComment(commentParentId, mediaId, filter){
	ajaxResponseDiv = "user_comments";
	
	params = "parent_id=" + commentParentId + "&media_id=" + mediaId + "&filter=" + filter + "&reply=" + escape($('reply').value);
	
	$(ajaxResponseDiv).innerHTML = '<div style="margin:0 auto; text-align:center; height:100px; padding-top:5px"><img src="http://static.networkpiece.com/c/LoadingGraphicSmall.gif"></div>';

	ajaxpack.getAjaxRequest("/ajax/reply_comment.php", params, processGetPost, "txt");
}

function displayReplyComment(commentId){
	var userId = _getCookie("h6userid");
	if(userId == '')
	{
		LoginAlert.show({originatingRequest: displayReplyComment, requestParameters:[commentId]});
	}
	else
	{
		div = 'reply_comment_form_id_' + commentId;

		mediaId = $('media_id').value;
		filter = $('filter').value;

		html = '<div class="reply_block bg1">';
			html+= '<span class="red bold">Reply to Comment</span><br>';

			html+= '<form action="" method="post" style="margin:0">';
			html+= '<textarea id="reply" name="reply" rows=4 style="width:333px"></textarea><br>';
			html+= '<input type="button" value="Add comment" onClick="replyComment(\''+commentId+'\', \''+mediaId+'\', \''+filter+'\'); this.disabled=true">';
			html+= '<input type="button" value="Discard" onClick="$(\'reply_comment_form_id_'+commentId+'\').style.display=\'none\'">';
			html+= '</form>';
		html+= '</div>';

		$(div).innerHTML = html;

		var obj = $('reply_comment_form_id_' + commentId);
		if (obj.style.display == 'none'){
			obj.style.padding = '0 0 0 30px';
			obj.style.display = '';
		}	
		else{
			obj.style.display = 'none';
		}
	}
}

function displayComments(mediaId, fromRating){
	ajaxResponseDiv = "user_comments";
	$(ajaxResponseDiv).innerHTML = "<div style=\"margin:0 auto; text-align:center; height:250px; padding-top:5px\"><img src=\"http://static.networkpiece.com/c/LoadingGraphicSmall.gif\"></div>";

	params = "media_id=" + mediaId + "&from_rating=" + fromRating;
	ajaxpack.getAjaxRequest("/ajax/display_comments.php", params, processGetPost, "txt");
}

function scaleProfileImages() {
	var imgs = $("my_comments").getElementsByTagName("img");
	for (var i=0; i<imgs.length; i++) {
		imgs[i].onload = function() {

			actualHeight = this.height;
			actualWidth = this.width;

			if(actualWidth > 278) {
				this.width = 278;
				this.height = (actualHeight/actualWidth) * this.width;
				this.style.cursor = "pointer";

				this.onclick = function() {
					enlargeImage(this.src, "Profile comment image", "");
				}
			}
		}
	}
}

function scaleMainImage(elem, src, title, description) {
	
	actualWidth = elem.width;

	if(actualWidth > 500) {
		actualHeight = elem.height;

		elem.width = 500;
		elem.height = (actualHeight/actualWidth) * elem.width;

		elem.style.cursor = "pointer";

		elem.onclick = function() {
			enlargeImage(src, title, description);
		}
	}
}

function moreProfileItems(items, userId, userName, site, page, totalItems, orderBy){
	if(items == 'comments') {
		ajaxResponseDiv = 'my_comments';
		blockHeight = '500px';
	}
	else if(items == 'uploads') {
		ajaxResponseDiv = 'my_uploads';
		blockHeight = '325px';
	}
	else if(items == 'fav') {
		ajaxResponseDiv = 'my_favorites';
		blockHeight = '325px';
	}
	else if(items == 'friends') {
		ajaxResponseDiv = 'my_friends';
		blockHeight = '200px';
	}
	else if(items == 'subscribers') {
		ajaxResponseDiv = 'my_subscribers';
		blockHeight = '200px';
	}
	else if(items == 'subscriptions') {
		ajaxResponseDiv = 'my_subscriptions';
		blockHeight = '200px';
	}

	$(ajaxResponseDiv).innerHTML = "<div style=\"margin:0 auto; text-align:center; width:100%; height:" +blockHeight+ "\"><img src=\"http://static.networkpiece.com/c/LoadingGraphicSmall.gif\"></div>";

	params = "items=" +items+ "&searched_userid=" +userId+ "&searched_username=" +userName+ "&page=" +page+ "&site=" +site+ "&total_items=" +totalItems+ "&order_by=" +orderBy;
	ajaxpack.getAjaxRequest("/ajax/more_profile_items.php", params, processGetPost, "txt");
}

/* Enlarge Image */

function enlargeImage(src, title, description) {
	launchEnlargePanel(src, title, description);
	$('theimage').onload = function() {
		scaleImg('theimage');
		scaleMovePanel('theimage');
		$('loading').style.display = 'none';
	}
}

function launchEnlargePanel(src, title, description){
	if($('enlarged_image_panel')){
		panel3.destroy();
	}
	if(!$('enlarged_image_panel')){
	var width = Stage.getWidth();
	var scroll = Stage.getScrollXY();
			
	var _x = 1/2 * (width[0] - 400) + scroll[0];
	var _y = 1/2 * (width[1] - 300) + scroll[1];

	var initObj = {width:"400px", height:"300px", visible:true, constraintoviewport:true, modal:true, xy:[_x,_y]};
	panel3 = new YAHOO.widget.ResizePanel('enlarged_image_panel', initObj);

	var panelBody =
		'<div id="loading" style="margin:0 auto; text-align:center; height:280px"><img src="http://static.networkpiece.com/c/LoadingGraphicSmall.gif"></div> \
		<img id="theimage" onClick="closePanel(\'panel3\')" src="'+src+'" alt="'+title+'"> \
		<table cellpadding="4" cellspacing="0" style="width:100%"><tr> \
		<td align=left style="font: bold 12px Verdana, Arial; color:#333">'+description+'</td> \
		<td align=right><img src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="btnCancel" onmousedown="closePanel(\'panel3\')"></td> \
		</tr> \
		</table>';

	panel3.setHeader(title);
	panel3.setBody(panelBody);
	panel3.render(document.body);
	}
}

function launchRecordingPanel(){
	if($('recording_panel')){
		panel3.destroy();
	}
	if(!$('recording_panel')){
	var width = Stage.getWidth();
	var scroll = Stage.getScrollXY();
			
	var _x = 1/2 * (width[0] - 407) + scroll[0];
	var _y = 1/2 * (width[1] - 360) + scroll[1];

	var initObj = {width:"407px", height:"360px", visible:true, constraintoviewport:true, modal:true, xy:[_x,_y]};
	panel3 = new YAHOO.widget.ResizePanel('recording_panel', initObj);

	var panelBody =
		'<iframe src="http://live.heaven666.org/flashcoms/recorder/server/php/recorder.php" width="396" height="296" marginheight="0" marginwidth="0" scrolling="no" frameborder=0 align="MIDDLE"></iframe> \
		<table cellpadding="4" cellspacing="0" style="width:100%"><tr> \
		<td align=right><img src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="btnCancel" onmousedown="closePanel(\'panel3\')"></td> \
		</tr> \
		</table>';

	panel3.setHeader("Profile video recorder");
	panel3.setBody(panelBody);
	panel3.render(document.body);
	}
}

function launchPlayerPanel(movieName, userId, userName, description){
	if($('player_panel')){
		panel2.destroy();
	}
	if(!$('player_panel')){
	var width = Stage.getWidth();
	var scroll = Stage.getScrollXY();
			
	var _x = 1/2 * (width[0] - 415) + scroll[0];
	var _y = 1/2 * (width[1] - 400) + scroll[1];

	var initObj = {width:"415px", height:"400px", visible:true, constraintoviewport:true, modal:true, xy:[_x,_y]};
	panel2 = new YAHOO.widget.ResizePanel('player_panel', initObj);

	var panelBody = 
		'<object \
		classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" \
		codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" \
		width="400" \
		height="330"> \
		<param name="flashVars" value="v=' + movieName + '&uid=' + userId + '" /> \
		<param name="movie" value="flvProfilePlayer.swf" /> \
		<param name="quality" value="high" /> \
		<param name="AllowScriptAccess" value="always" /> \
		<param name="wmode" value="transparent" /> \
		<param name="allowFullScreen" value="true" /> \
		<embed \
		 type="application/x-shockwave-flash" \
		 showstatusbar="1" \
		 width="400" \
		 height="330" \
		 wmode="transparent" \
		 src="flvProfilePlayer.swf" \
		 allowFullScreen="true" \
		 flashVars="v=' + movieName + '&uid=' + userId + '" \
		 quality="high" \
		 AllowScriptAccess="always" \
		 pluginspage="http://www.macromedia.com/go/getflashplayer"> \
		</embed> \
		</object> \
		<table cellpadding="4" cellspacing="0" style="width:100%"><tr> \
		<td align=left style="font: bold 12px Verdana, Arial; color:#333">'+description+'</td> \
		<td align=right><img src="http://static.networkpiece.com/c/pixel.gif" width="52" height="22" class="btnCancel" onmousedown="closePanel(\'panel2\')"></td> \
		</tr> \
		</table>';

	panel2.setHeader(userName + "'s profile recording");
	panel2.setBody(panelBody);
	panel2.render(document.body);
	}
}

function tableWidth() {
	return windowWidth()-100;
}

function windowWidth() {
	var width = Stage.getWidth();
	var scroll = Stage.getScrollXY();

	return width[0] + scroll[0];
}

function scaleImg(imageId) {
	what = $(imageId);
	actualHeight = what.height;
	actualWidth = what.width;

	if(fitsInWindow(imageId)) return;

	what.width = tableWidth();
	what.height = (actualHeight/actualWidth) * what.width;
}

function fitsInWindow(imageId) {
	what = $(imageId);
	var actualWidth = what.width;
	if (actualWidth <= tableWidth()) {
		return true;
	} else {
		return false;
	}
}

function scaleMovePanel(imageId) {
	panelWidth = $(imageId).width + 13;
	panelHeight = $(imageId).height + 70;

	var width = Stage.getWidth();
	var scroll = Stage.getScrollXY();

	var _x = 1/2 * (width[0] - panelWidth) + scroll[0];
	var _y = 1/2 * (width[1] - panelHeight) + scroll[1];

	panel3.cfg.setProperty("width", panelWidth+'px');
	panel3.cfg.setProperty("height", panelHeight+'px');
	panel3.cfg.setProperty("xy", [_x,_y]);
}

/* Search system function */
function advSearchSubmit(advSearchForm)
{
	var and_queries=$(advSearchForm).and_queries.value;
	var or_queries=$(advSearchForm).or_queries.value;
	var negative_queries=$(advSearchForm).negative_queries.value;
	var search_query = and_queries;

	if($(advSearchForm).or_queries) {
		var or_queries_array=or_queries.split(' ');
		for(var x=or_queries_array.length-1;x>=0;x--){
			if(or_queries_array[x]==''){
				or_queries_array.splice(x,1);
			}
		}
		if(or_queries_array.length>0){
			search_query+=' '+or_queries_array.join(' OR ');
		}
	}

	if($(advSearchForm).negative_queries) {
		var negative_queries_array=negative_queries.split(' ');
		for(var x=negative_queries_array.length-1;x>=0;x--){
			if(negative_queries_array[x]==''){
				negative_queries_array.splice(x,1);
			}else{
				negative_queries_array[x]='-'+negative_queries_array[x];
			}
		}
		if(negative_queries_array.length>0){
			search_query+=' '+negative_queries_array.join(' ');
		}
	}


	$(advSearchForm).q.value = search_query;

	$(advSearchForm).submit();
}

function toggleAdvSearch(searchQuery)
{
	if($('advanced_search_frame').style.display == 'block')
	{
		$('advanced_search_frame').style.display = 'none';
	}
	else
	{
		$('advanced_search_frame').style.display = 'block';
		$('advanced_search_frame').innerHTML = '<div style="width:755px" class="bg3">Loading...</div><br>';

		ajaxResponseDiv = "advanced_search_frame";
		ajaxpack.getAjaxRequest("/ajax/toggle_adv_search.php", searchQuery, processGetPost, "txt")
	}	
}

/* Thumb rotation */

var th_img = null;
var th_img_start = null;

var th_folder = null;
var th_title = null;
var th_pos = 0;
var th_preload = null;
var th_watchdog = null;
var th_lastframe = 0;

function th_start(img) {

 if (th_img == img)
  return;

 th_stop();
 th_img = img;
 th_img_start = img.src;
 th_pos = 0;
 
 var x = img.src.lastIndexOf('/');
 th_folder = img.src.substring(0,x+1);
 th_title = img.src.substring(x+1);
 var x = th_title.lastIndexOf('-');
 th_title = th_title.substring(0,x+1);

 th_shortname = img.src.substring(x+1);
 x = th_shortname.lastIndexOf('.jpg');
 th_shortname = th_shortname.substring(0,x);
 th_lastframe = 0;
 th_rotate();
 th_watchdog = setTimeout(th_swap, 25);

};

function th_stop(img) {

 if (th_watchdog)
	 clearTimeout(th_watchdog);
 if (th_img && th_img_start)
	 th_img.src = th_img_start;
 th_img = null;
};

function th_rotate() {

 th_preload = new Image();
 th_preload.src = th_folder + th_title + th_pos + ".jpg";
 
 th_pos += 1;
 if (th_pos>7)
  th_pos = 0;  
};

function th_swap() {

 if (th_img == null)
  return;
 if (!th_preload.complete) {
	 th_watchdog = setTimeout(th_swap, 25); 
	 return;
 }
 if (th_preload.width == 0) {
	 th_rotate();
	 return;
 }
 var diff = new Date().getTime() - th_lastframe;
 if (diff<0)
 	diff = 0;
 else if (diff > 500)
 	diff = 500;
 if (diff>=500) {
	 th_img.src = th_preload.src;
	 th_lastframe = new Date().getTime();
	 th_watchdog = setTimeout(th_swap, 500);
	 th_rotate();
	 return;
 }
 th_watchdog = setTimeout(th_swap, 25);

};

/* Signup checkups */

function updateUsernameStatus(){
	var username = document.register.username.value;
	if(username != ""){
		var theElemenet = $('check_username');
		theElemenet.style.display = "block";

		ajaxResponseDiv = "check_username";
		params = "field=username&username=" + username;

		ajaxpack.getAjaxRequest("/ajax/signup_checkups.php", params, processGetPost, "txt");
	}
}

/* Myaccount function */

function checkAll(formObj, is_checked) 
{
	for (var i=0;i < formObj.length;i++) {
		fldObj = formObj.elements[i];
		if (fldObj.type == 'checkbox') {
			fldObj.checked = is_checked;
		}
	}
}

function resetCheckAllValue(formObj, is_checked) {
	if(!is_checked) {
		main_checkbox = document.getElementById("checkall_checkbox");
		main_checkbox.checked = false;
	}
}

function mySubscriptionsSubmenu(userId, page) {
	$('my_subscriptions_submenu').innerHTML = "<li><img src=\"http://static.networkpiece.com/c/LoadingGraphicSmall.gif\"></li>";
	$('my_subscriptions_submenu').style.height = '245px'; 

	params = "userid=" +userId+ "&page="+page;
	ajaxResponseDiv = "my_subscriptions_submenu";
	ajaxpack.getAjaxRequest("/ajax/mysubscriptions_submenu.php", params, processGetPost, "txt");
}

//Step 2: Define a "callback" function to process the data returned by the Ajax request:
function processGetPost(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			$(ajaxResponseDiv).innerHTML = myajax.responseText;

			// post process calls
			if(ajaxResponseDiv == 'my_comments') {
				scaleProfileImages();
			}
			else if(ajaxResponseDiv=='mediaViewBrowseBlock' || ajaxResponseDiv=='media_list' || ajaxResponseDiv=='people_list') {
				sweetTitles.init();
			}
		}
	}
}

//textarea maxsize
function limitlength(obj, length){
	var maxlength=length
	if (obj.value.length>maxlength)
	obj.value=obj.value.substring(0, maxlength)
}

if(top.location!=document.location)top.location = document.location;