var breaker = 1;
function ajax_start()
{
		var XMLHttpRequestObject = false; 
		if (window.XMLHttpRequest)
		{
			XMLHttpRequestObject = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			XMLHttpRequestObject = new ActiveXObject('Microsoft.XMLHTTP');
		}	
		return XMLHttpRequestObject;
}
function display_ajax_html(page, args, div_id, XMLHttpRequestObject, callback, callback_args, args2)
{
	if(XMLHttpRequestObject)
	{
		var params = args;

		XMLHttpRequestObject.open('POST', '/ajax.php?do='+page, true); 
		XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		XMLHttpRequestObject.onreadystatechange = function() 
			{ 
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
					{ 
						if(callback)
							callback(XMLHttpRequestObject.responseText, callback_args, args2);
						else
							document.getElementById(div_id).innerHTML = XMLHttpRequestObject.responseText;

					} 
			} 
		XMLHttpRequestObject.send(params); 
	}
}
function select_team(id)
{
	//Unmark current one
	if(document.getElementById('team_'+document.getElementById('team_id').value))
		document.getElementById('team_'+document.getElementById('team_id').value).className = "team";
	document.getElementById('team_id').value = id;
	document.getElementById('team_'+id).className = "team tselected";
}
function urlEncode(str)
{
	return str.replace("&", "%26");
}
function forgot_pass()
{
	//Ajax to send
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('forgot_pass', '&username='+document.getElementById('forgot_passbox').value, 'forgot_pass', XMLHttpRequestObject);	
}
function change_pass()
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('change_pass', '&id='+document.getElementById('id_form').value+'&code='+document.getElementById('code_form').value+'&new_password='+document.getElementById('new_password').value, 'pass_content', XMLHttpRequestObject);
}
function show_team(type, limit, name, domain, invites, noinvite)
{
	if(!name)
		var name = '';
	else
		name = encodeURIComponent(name);
	if(!domain)
		var domain = '';
	else
		domain = encodeURIComponent(domain);
	if(!invites)
		var invites = '';	
	if(!noinvite)
			var noinvite = '';
	else
		name = encodeURIComponent(name);
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('show_team', '&type='+type+'&limit='+limit+'&name='+name+'&domain='+domain+'&invites='+invites+noinvite, 'team_box', XMLHttpRequestObject);	
}
function show_reply(id)
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('show_reply', '&id='+id, 'reply', XMLHttpRequestObject);		
}
function edit_reply(id)
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('edit_reply', '&id='+id, 'reply_'+id, XMLHttpRequestObject);		
}
function save_reply(id)
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('save_reply', '&id='+id+'&message='+urlEncode(document.getElementById('message'+'_'+id).value), '', XMLHttpRequestObject, update_reply, id);		
}
function update_reply(json, id)
{
	document.getElementById('reply_'+id).innerHTML = json;
	$("#post_"+id).effect('highlight', {}, 1000);
}
function cancel_edit(id)
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('cancel_edit', '&id='+id, 'reply_'+id, XMLHttpRequestObject);		
}
function cancel_reply(id)
{
	document.getElementById('reply').innerHTML = "<div class='post_links'><a href='javascript:void(0);' onclick='show_reply("+id+");'>Reply</a></div><br clear='all'/>";
}
function post_reply(id)
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('post_reply', '&id='+id+'&message='+urlEncode(document.getElementById('message').value), '', XMLHttpRequestObject, insert_row);	
	cancel_reply(id);
}
function delete_reply(id)
{
	var answer = confirm("Are you sure you want to delete this post?");
	if(answer)
	{
		XMLHttpRequestObject = ajax_start();
		display_ajax_html('delete_post', '&id='+id, '', XMLHttpRequestObject, removeRow);
	}
}
function add_member()
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('add_member', '&username='+document.getElementById('new_username').value, 'new_member', XMLHttpRequestObject);
}
function own_domain()
{
	document.getElementById('subdomain').innerHTML = "<a href='javascript:void(0);' onclick='domain_info();'>Click here for a guide</a> or <a href='javascript:void(0);' onclick='use_sub();'>use our subdomain</a></span>";
}
function use_sub()
{
	document.getElementById('subdomain').innerHTML = ".teteams.com (or <a href='javascript:void(0);' onclick='own_domain();'>use your own domain</a>)</span>";	
}
function domain_info()
{
	centerPopup(false, 'subdomain');
	var title = "Using your own domain";
	var content = "To use your own name, you will have to setup a CNAME in your domain registar that points to http://www.teteams.com.";
	loadPopup(title, content);
}
function add_suggest()
{
	//load img
	document.getElementById('submit_load').innerHTML = "<img src='/images/small_load.gif' alt='loading...'/>";
	XMLHttpRequestObject = ajax_start();
	if(document.getElementById('suggestion').value.length > 0)
	{
		display_ajax_html('add_suggestion', '&suggestion='+urlEncode(document.getElementById('suggestion').value), '', XMLHttpRequestObject, add_suggestion);
		document.getElementById('suggestion').value = '';
	}
	else
	{
		alert('You must enter a suggestion!');
		document.getElementById('submit_load').innerHTML = "<input type='submit' value='Suggest' onclick='add_suggest();'/>";
	}
}
function add_suggestion(json)
{
	document.getElementById('submit_load').innerHTML = "<input type='submit' value='Suggest' onclick='add_suggest();'/>";
	var json_array = eval('(' + json + ')');
	document.getElementById('suggestion_added').innerHTML = json_array['msg'];
	if(json_array['add'].length > 0)
	{
		document.getElementById('suggestions').innerHTML = json_array['add'] + document.getElementById('suggestions').innerHTML;
		$("#sugg_new").effect("highlight", {color:"#444444"}, 3000);
		document.getElementById('sugg_new').id = 'sugg_old';
		if(document.getElementById('none_yet'))
			document.getElementById('none_yet').style.display = 'none';
	}
	else
		document.getElementById('suggestion').value = json_array['sug'];
}
function check_referrer()
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('check_referrer', '&referrer_name='+document.getElementById('referrer_name').value, '', XMLHttpRequestObject, update_team_div);		
}
function update_team_div(json)
{
	document.getElementById('team_id_div').style.display = 'block';
	document.getElementById('team_id_div').innerHTML = json.substring(1);
	$("#member_q").hide();
	$('#h4_twave').fadeIn();
	if(json.substring(0, 1) == 'Y')
	{
		$('#enter_twave').fadeIn();
	}
	else
	{
		$('#enter_twave').fadeIn();
		//ugly as f
		setTimeout("show_team('own', false, false, false, false, '&noinvite=t');", 200);
	}
}
function max_chars(textarea, counter_id) 
{
	counter_id.value = 256 - textarea.value.length;
}
function suggest(id)
{
	if(document.getElementById('suggest_text'+id).innerHTML != 'Liked')
	{
		var likes = document.getElementById('likes'+id).innerHTML;
		document.getElementById('likes'+id).innerHTML = parseInt(likes)+1;
		document.getElementById('suggest_text'+id).innerHTML = 'Liked';
		XMLHttpRequestObject = ajax_start();
		display_ajax_html('inc_suggestion', '&id='+id, '', XMLHttpRequestObject);
	}
}
function validate(form, check_email)
{
	if(document.getElementById(form))
		var form_el = document.getElementById(form);
	else
	{
		var form_el = form;
		form = form_el.id;
	}
	if(form == 'username')
	{
		if(form_el.value.length < 3)
			validate_output(form, false, 'Username must be 3 or more characters');
		else if(form_el.value.match(/[^a-zA-Z0-9]/))
			validate_output(form, false, 'Username can only contain letters and numbers');			
		else
		{
			//Ajax to check availability
			XMLHttpRequestObject = ajax_start();
			display_ajax_html('check_avail', '&username='+form_el.value, '', XMLHttpRequestObject, is_available, 'user');
		}	
	}
	else if(form == 'email')
	{
		if(!form_el.value.match(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/))
			validate_output(form, false, 'Please enter a valid email address');	
		else if(!check_email)
		{
			//Ajax to check availability
			XMLHttpRequestObject = ajax_start();
			display_ajax_html('check_avail', '&email='+form_el.value, '', XMLHttpRequestObject, is_available, 'email');
		}
		else
			validate_output(form, true);		
	}
	else if(form == 'password')
	{
		if(form_el.value.length < 6)
			validate_output(form, false, 'Password must be 6 or more characters');
		else
			validate_output(form, true);
	}
	else if(form == 'password2')
	{
		if(form_el.value.length < 6)
			validate_output(form, false, 'Password must be 6 or more characters');
		else if(document.getElementById('password').value != form_el.value)
			validate_output(form, false, 'Your passwords did not match');		
		else
			validate_output(form, true);
	}
	else if(form == 'blog')
	{
		//Std varchar
		if(form_el.value.length > 0 && form_el.value.substring(0, 7) != 'http://')
			validate_output(form, false, 'Blog must be a url');		
		else			
			validate_output(form, true);
	}
	else if(form == 'facebook')
	{
		//Std varchar
		if(form_el.value.match(/[^a-zA-Z0-9+@._\?&= \/-]/))
			validate_output(form, false, 'Invalid Character');		
		else			
			validate_output(form, true);	
	}	
	else if(form == 'linkedin')
	{
		//Std varchar
		if(form_el.value.match(/[^a-zA-Z0-9+@._\?&= \/-]/))
			validate_output(form, false, 'Invalid Character');		
		else			
			validate_output(form, true);	
	}
	else
	{
		//Std varchar
		if(form_el.value.match(/[^a-zA-Z0-9+@._ -]/))
			validate_output(form, false, 'Username can only contain letters, spaces, numbers + @ _ . and -');		
		else			
			validate_output(form, true);
	}
		
}
function is_available(json, type)
{
	var json_array = eval('(' + json + ')');	
	if(type == 'user')
	{
		if(json_array['error'] == 'true')
			validate_output('username', false, 'That usename is taken');
		else
			validate_output('username', true);
	}
	else
	{
		if(json_array['error'] == 'true')
			validate_output('email', false, 'That email is taken');
		else
			validate_output('email', true);	
	}
}
function validate_output(form, success, message)
{
	document.getElementById(form+'_message').style.display = 'block';
	if(success)
	{
		document.getElementById(form+'_message').innerHTML = '<font color="#008C00">Success</font>';
		document.getElementById(form).style.border = '1px solid #008C00';		
	}
	else
	{
		document.getElementById(form+'_message').innerHTML = "<img src='/images/arrow.gif' alt='>'/> "+message+" <img src='/images/arrow_opp.gif' alt='<'/>";
		document.getElementById(form).style.border = '1px solid #CC0000';		
	}
	
}
function request_com()
{
	var paypal = document.getElementById('paypal_email').value;
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('request_com', '&paypal='+paypal, 'commission', XMLHttpRequestObject);	

}
function submit_feedback()
{
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('submit_feedback', '&feedback='+urlEncode(document.getElementById('feedback').value)+'&email='+document.getElementById('f_email').value, '', XMLHttpRequestObject, slim);
}
function slim(response)
{
	document.getElementById('login_box').innerHTML = response;
	$("#login_bar").animate({height: 30}, 300);	
}
function insert_filler(table, text)
{
	//Insert a no campaigns row
	var Parent = document.getElementById(table);
    var row = document.createElement("tr");

	//Create tds
	var td = document.createElement("td");
	if(table == 'tbody')
		var id = 'filler';
	else if(table == 'auto_body')
		var id = 'filler_auto';
	else
		var id = 'filler_completed';
	td.id = id;
	td.colSpan = 5;
	row.appendChild(td);
    
    Parent.appendChild(row);
    document.getElementById(id).innerHTML = text;
   	//$("#"+id).effect('highlight', {}, 2000);
}
function show_tut(vid, height)
{
	var margin = height+45;
	document.getElementById('tut_vid').innerHTML = "<a href='javascript:void(0);' onclick=\"hide_tut('"+vid+"')\"><b>Close</b></a><br /><div id='container' style='position:absolute;margin-left:-487px;margin-top:-"+margin+"px;background-color:#fa9300;z-index:100;border:6px solid #111111;'><a href='/guide#"+vid+"'>Click here for a text version</a><br /><a  href='/media/"+vid+".flv' style='display:block;width:520px;height:"+height+"px' id='player'></a></div>";
	flowplayer("player", "/flowplayer/flowplayer-3.1.5.swf");
}
function hide_tut(vid)
{
	document.getElementById('tut_vid').innerHTML = "<img src='/images/television.png' style='border:0px;' /><a href='javascript:void(0);' onclick=\"show_tut('"+vid+"');\"><b>Click here to watch our tutorial video for this page</b></a>";
}
function delete_row(json, campaign)
{
	removeRow(json, campaign);
}
function insert_row(json)
{	
	//See if error or not
	if(json.indexOf("{") == -1)
		alert(json);
	else
	{
		var table = document.getElementById('tbody');
	    var row = document.createElement("tr");
	
		var json_array = eval('(' + json + ')');	
		for(var i in json_array)
		{
			if(i != 'credits' && i != 'id')
			{
				//Create tds
				var td = document.createElement("td");
				i = i+"_"+json_array['id'];
				td.id = i;
				td.setAttribute('valign', 'top');
		     	row.appendChild(td);
		     	var index = i;
	     	}
		}
	    row.id = 'post_'+json_array['id'];
	    
	    table.appendChild(row);
	    //Update tds
		for(var i in json_array)
		{
			if(i != 'credits' && i != 'id')
			{
				var index = i+"_"+json_array['id'];
	    		document.getElementById(index).innerHTML = json_array[i];
			}
	    }
	    
		//Highlight
		$("#"+row.id).effect('highlight', {}, 2000);
		//Remove load msg
	}
}
function share(refname, give_creds)
{
	if(!give_creds)
		centerPopup(false, 'tweetthis');
	else
		centerPopup(false);
	var title = "Tweet this!";
	if(give_creds)
		var content = "<p style='margin-bottom:0px;'>Type in your twitter username and twitter password (we don't store any of this data) -- we'll post it to Twitter for you and add 5 credits to your account!</p><br /><span class='label'><span style='font-weight:500;'>Tweet:</span></span><br />Explode your social network following and promote YOU: http://www.thumbvu.com/ref/"+refname+" #thumbvu<p><span class='label'><span style='font-weight:500;'>Twitter Username:</span></span> <input type='text' id='username'/></p><p><span class='label'><span style='font-weight:500;'>Twitter Password:</span></span> <input type='password' id='password' onkeydown='if (event.keyCode == 13) retweet_send(true);'/></p><p><input type='submit' value='Tweet this' onclick='retweet_send(true)'/> <a href='javascript:void(0);' onclick='disablePopup();'>Cancel</a></p><img src='/images/twitter_logo.png'/>";
	else
		var content = "<p style='margin-bottom:0px;'>Type in what you want to tweet, your twitter username and twitter password (we don't store any of this data) -- we'll post it to Twitter for you!</p><br /><span class='label'><span style='font-weight:500;'>Tweet:</span></span><br /><textarea id='tweet_content' onKeyDown=\"max_chars(document.getElementById('tweet_content'), document.getElementById('tweet_counter'))\" onKeyUp=\"max_chars(document.getElementById('tweet_content'), document.getElementById('tweet_counter'))\">Explode your social network following and promote YOU: http://www.thumbvu.com/ref/"+refname+" #thumbvu</textarea><br /><input readonly type='text' id='tweet_counter' size='3' maxlength='3' value='140' />characters left.<br /><p><span class='label'><span style='font-weight:500;'>Twitter Username:</span></span> <input type='text' id='username'/></p><p><span class='label'><span style='font-weight:500;'>Twitter Password:</span></span> <input type='password' id='password' onkeydown='if (event.keyCode == 13) retweet_send();'/></p><p><input type='submit' value='Tweet this' onclick='retweet_send()'/> <a href='javascript:void(0);' onclick='disablePopup();'>Cancel</a></p><img src='/images/twitter_logo.png'/>";
	loadPopup(title, content);	
}
function retweet_send(give_creds)
{
	if(document.getElementById('tweet_content') && document.getElementById('tweet_content').value.length > 140)
		alert('Your tweet must be 140 characters or less!');
	else
	{
		XMLHttpRequestObject = ajax_start();
		if(give_creds)
			display_ajax_html('post_to_twitter', '&give_creds=true&username='+document.getElementById('username').value+'&password='+document.getElementById('password').value, '', XMLHttpRequestObject, retweet_send_update);	
		else
			display_ajax_html('post_to_twitter', '&tweet_content='+document.getElementById('tweet_content').value+'&username='+document.getElementById('username').value+'&password='+document.getElementById('password').value, '', XMLHttpRequestObject, retweet_send_update);	
	}
}
function retweet_send_update(response)
{
	if(response.substring(0,5) == '<span')
	{
		document.getElementById('contactArea').innerHTML = response+document.getElementById('contactArea').innerHTML;
	}
	else
		document.getElementById('contactArea').innerHTML = response;
}
function tweet_this()
{
	document.getElementById('tweet_submit').innerHTML = '<img src="images/small_load.gif" alt="loading" />';
	XMLHttpRequestObject = ajax_start();
	display_ajax_html('thanks_tweet', '&username='+document.getElementById('username').value+'&password='+document.getElementById('password').value, '', XMLHttpRequestObject, tweet_this_update);		
}
function tweet_this_update(response)
{
	if(response.substring(0,5) == '<span')
	{
		document.getElementById('twitter').innerHTML = response+document.getElementById('twitter').innerHTML;
		document.getElementById('tweet_submit').innerHTML = "<input type='submit' value='Tweet this' onclick='tweet_this()'/>";		
	}
	else
		document.getElementById('twitter').innerHTML = response;
}
function removeRow(json, campaign, nojson) 
{
	if(!nojson)
	{
		var json_array = eval('(' + json + ')');
		var id = json_array['id'];	
	}
	else
		var id = json;
	
	var tr = document.getElementById(id);
	if (tr) 
	{
		if (tr.nodeName == 'TR') 
		{
			var tbl = tr; // Look up the hierarchy for TABLE
			while (tbl != document && tbl.nodeName != 'TBODY')
			{
				tbl = tbl.parentNode;
			}
	 
			if (tbl && tbl.nodeName == 'TBODY') 
			{
				while (tr.hasChildNodes()) 
				{
					tr.removeChild( tr.lastChild );
				}
			var Parent = tr.parentNode;
			tr.parentNode.removeChild( tr );
			}
			//Insert filler if none left
			if(id != 'filler')
			{
				nodeNum = Parent.childNodes.length; 
				if(nodeNum == 0)
				{
					//Redirect
					window.location = '/forum';
				}
			}
	    } 
	    else 
	    {
	 		//alert( 'Specified document element is not a TR. id=' + id );
	    }
	} 
	else 
	{
		//alert( 'Specified document element is not found. id=' + id );
	}
}
//Tooltips
var cur_user = 0;
var go = true;
var tooltip=function()
{
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h,smallw;
	var ie = document.all ? true : false;
	return{
		show:function(v,doc, userid, hide_pic, smallw1)
		{
			if(tt == null)
			{
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				tt.setAttribute('onmouseover', "go=false;");
				tt.setAttribute('onmouseout', "go=true;setTimeout('tooltip.hide();', 1000);");
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				tt.appendChild(c);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				if(smallw1)
					smallw = smallw1;
				else
					smallw = false
   			}
			this.pos(doc);
   			//lazy
			w = 120;
			tt.style.display = 'block';
			if(v)
				c.innerHTML = v;
			else if(cur_user != userid)
			{
				cur_user = userid;
				//Load prof
				c.innerHTML = 'loading...';
				if(hide_pic)
					var extras = '&hide_pic=t';
				else
					var extras = '';
				
				XMLHttpRequestObject = ajax_start();
				display_ajax_html('get_profile', '&id='+userid+extras, '', XMLHttpRequestObject, update_profile, userid, c);
			}
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie)
			{
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  		},
  		pos:function(doc)
  		{
  			var u = findPos(doc);
  			var l = findPosX(doc);
			//var u = ie ? event.clientY + document.docElement.scrollTop : e.pageY;
			//var l = ie ? event.clientX + document.docElement.scrollLeft : e.pageX;

			tt.style.top = (u) + 10 + 'px';
			if(!smallw)
				tt.style.left = (l + left) + 80 + 'px';
			else
				tt.style.left = (l + left) + 100 + 'px';				
  		},
  		fade:function(d)
 		{
   			var a = alpha;
  			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
    		var i = speed;
   			if(endalpha - a < speed && d == 1)
   			{
    			i = endalpha - a;
   			}
   			else if(alpha < speed && d == -1)
   			{
    			i = a;
   			}
   				alpha = a + (i * d);
   				tt.style.opacity = alpha * .01;
   				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}
  			else
  			{
    			clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function()
 		{
 		 	//don't wanna comment this, it's a pain, gl
  			if(go)
	  		{
				clearInterval(tt.timer);
				tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
			}
		}
	};
}();
function update_profile(json, userid, c)
{
	if(cur_user == userid)
	{
		if(json.length > 75)
			c.innerHTML = json;
		else
			c.innerHTML = json + "<p>No info listed</p>";
	}
}
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup without jQuery magic!
function loadPopup(title, content, count){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$('#backgroundPopup').fadeIn("slow");
		$('#popupContact').fadeIn("slow");
		document.getElementById('popup_title').style.display = 'block';
		document.getElementById('contactArea').style.display = 'block';
		replace_html(document.getElementById('popup_title'), title);
		replace_html(document.getElementById('contactArea'), content);
		popupStatus = 1;
	}
}
//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$('#backgroundPopup').fadeOut("slow");
		$('#popupContact').fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(id, id2){
	//request data for centering

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	
	if(id)
		var pos = findPos(document.getElementById(id+'_assign'))
	else if(id2)
		var pos = findPos(document.getElementById(id2))
	else
		var pos = 170;
	pos = pos-150;
	if(pos<0)
		pos = windowHeight/2-popupHeight/2;
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": pos,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
});
function findPos(obj) 
{
	var curtop = 0;
	if(obj)
	{
		if (obj.offsetParent) 
		{
			do {
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
	}
return curtop;
}
function findPosX(obj) 
{
	var curtop = 0;
	if (obj.offsetParent) 
	{
		do {
			curtop += obj.offsetLeft;
		} while (obj = obj.offsetParent);
	}
return curtop;
}
function replace_html(el, html) {
	if( el ) {
                var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
                //var oldEl = el;
                var newEl = document.createElement(oldEl.nodeName);

                // Preserve any properties we care about (id and class in this example)
                newEl.id = oldEl.id;
                newEl.className = oldEl.className;

                //set the new HTML and insert back into the DOM
                newEl.innerHTML = html;
                if(oldEl.parentNode)
        	        oldEl.parentNode.replaceChild(newEl, oldEl);
                else
		        oldEl.innerHTML = html;

                //return a reference to the new element in case we need it
                return newEl;
	}
};