function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
	var friend_email = document.getElementById('friend_email');
	var friend_name = document.getElementById('friend_name');
	var your_name = document.getElementById('tell_a_friend_name');
	var your_email = document.getElementById('tell_a_friend_email');
	var comment = document.getElementById('tell_a_friend_comment');
	
	var qstr = 'friend_email=' + escape(friend_email.value);  // NOTE: no '?' before querystring
	qstr = qstr + '&friend_name=' + escape(friend_name.value);
	qstr = qstr + '&your_name=' + escape(your_name.value);
	qstr = qstr + '&your_email=' + escape(your_email.value);
	qstr = qstr + '&comment=' + escape(comment.value);
		
	return qstr;
}

// Change object from AJAX
function updatepage(result){
	if (1 != result){
		document.getElementById('tell_a_friend_error').style.visibility = 'visible';
    	document.getElementById('tell_a_friend_error').innerHTML = '<b>Oops!</b> There seems to be a problem with the form:' + result + '<br /><br /><a href="javascript:;" onclick="javascript:document.getElementById(\'tell_a_friend_error\').style.visibility=\'hidden\'; close_e();" style="color: #' + color + ';">back to form</a>'; //s.split("|")[1];
    } else {
    	document.getElementById('friend_name').value = '';
		document.getElementById('friend_email').value = '';
    	document.getElementById('tell_a_friend_error').style.visibility = 'visible';
		document.getElementById('tell_a_friend_error').innerHTML = '<br /><h3>Thank you!</h3> Your friend recieved your invitation.' + '<br /><br /><a href="javascript:;" onclick="javascript:document.getElementById(\'tell_a_friend_error\').style.visibility=\'hidden\'; close_e();">close</a>';
	}
}

// Code for showing pop-up tell a friend
var cX = 0; var cY = 0;

function AssignPosition(d) {
	d.style.left	= cX + "px";
	d.style.top		= cY + "px";
}
function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}
function HidePrivacy(d){
	var dd = document.getElementById(d);
	dd.style.visibility = 'hidden';
}

function ShowPrivacy(d){
	var dd = document.getElementById(d);
	dd.style.visibility = 'visible';
}

function close_e(){
	// document.getElementById('button_send').src='img/tell_a_friend_btn_' + color + '.gif';
}

function findPosition( oLink ) {
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;
    }
    cX = posX - 150;
    cY = posY - 330;
    if (posY<330){
    	cY = 330 - posY;
    }
    // return [ posX, posY ];
  } else {
  	cX = oLink.x;
    cY = oLink.y;
    if (oLink.y < 330){
    	cY = 330 - oLink.y;
    }
    // return [ oLink.x, oLink.y ];
  }
}
 
function favShowResponse(req)
{
    $('fav_link_holder').innerHTML = req.responseText;
    $('fav_link_holder1').innerHTML = req.responseText;
    new Ajax.Updater('fav_count', '?a=profile_ajax&fav_count=1'); 
}
function bbShowResponse(req)
{
    $('bb_link_holder').innerHTML = req.responseText;
    $('bb_link_holder1').innerHTML = req.responseText;
     new Ajax.Updater('bb_count', '?a=profile_ajax&bb_count=1'); 
}
 function blockUserShowResponse(req)
 {
      new Ajax.Updater('blu_count', '?a=profile_ajax&bu_count=1');
      new Ajax.Updater('fav_count', '?a=profile_ajax&fav_count=1');
      new Ajax.Updater('bb_count', '?a=profile_ajax&bb_count=1');  
 }
function showFavLoading()
{
    $('fav_link_holder').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
    $('fav_link_holder').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
}
function showBBLoading()
{
    $('bb_link_holder').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
    $('bb_link_holder1').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
}
function showBLLoading()
{
    $('blocked_list').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
} 
/*-------------------------------------------------------------------------*/
/* Bojan new Ajax functions */
function fnFavShowResponse(req)
{
    $get('fav_link_holder').innerHTML = req.responseText;
    $get('fav_link_holder1').innerHTML = req.responseText;
    setTimeout("new Net.Updater('fav_count', '/?a=profile_ajax&fav_count=1')", 1);
}
function fnBbShowResponse(req)
{
    $get('bb_link_holder').innerHTML = req.responseText;
    $get('bb_link_holder1').innerHTML = req.responseText;
    setTimeout("new Net.Updater('bb_count', '/?a=profile_ajax&bb_count=1')", 1);
}
function fnShowFavLoading()
{
    $get('fav_link_holder').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
    $get('fav_link_holder1').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
}
function fnShowBBLoading()
{
    $get('bb_link_holder').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
    $get('bb_link_holder1').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
}
function fnShowBLLoading()
{
    $get('blocked_list').innerHTML = "<img src='templates/coedsingles/images/mozilla_blu.gif'>";
} 
function fnBlockUserShowResponse()
{
	/*
	var blu = new Net.Updater('blu_count', '?a=profile_ajax&bu_count=1');
	var fav = new Net.Updater('fav_count', '?a=profile_ajax&fav_count=1');
	var bb = new Net.Updater('bb_count', '?a=profile_ajax&bb_count=1');
	*/
	var summurry = new Net.Loader('/?a=profile_ajax&summ=1', 
	{
		onSuccess : fnShowSummury
	});
}
function fnShowSummury(transport)
{
	var sResult = transport.responseText;
	oS = eval('(' + sResult + ')');
	if(oS.summ)
	{
		if (oS.summ.blackbook != null) $get('bb_count').innerHTML = oS.summ.blackbook;
		if (oS.summ.favorites != null) $get('fav_count').innerHTML = oS.summ.favorites;
		if (oS.summ.blocked != null) $get('blu_count').innerHTML = oS.summ.blocked;
	}
	else if(oS.allSumm)
	{
		if (oS.allSumm.blackbook.length)
		{
			var sBB = '';
			for (var i = 0, l = oS.allSumm.blackbook.length; i < l; i += 1)
			{
				if (sBB == '') 
				{
					sBB += oS.allSumm.blackbook[i];
					continue;
				}
				sBB += ', ' + oS.allSumm.blackbook[i];
			}
			$get('bb_count').innerHTML = sBB;
		}
		if (oS.allSumm.favorites.length)
		{
			var sFav = '';
			for (var i = 0, l = oS.allSumm.favorites.length; i < l; i += 1)
			{
				if (sFav == '') 
				{
					sFav += oS.allSumm.favorites[i];
					continue;
				}
				sFav += ', ' + oS.allSumm.favorites[i];
			}
			$get('fav_count').innerHTML = sFav;
		}
		if (oS.allSumm.blocked.length)
		{
			var sBlock = '';
			for (var i = 0, l = oS.allSumm.blocked.length; i < l; i += 1)
			{
				if (sBlock == '') 
				{
					sBlock += oS.allSumm.blocked[i];
					continue;
				}
				sBlock += ', ' + oS.allSumm.blocked[i];
			}
			$get('blu_count').innerHTML = sBlock;
		}
	}
}

/* DUKA new_design Ajax functions */
function new_design_fnFavShowResponse(req)
{    
  if (req.responseText !== "")
  {    
    $get('fav_link_holder').innerHTML = req.responseText;
//    setTimeout("new Net.Updater('fav_count', '/?a=profile_ajax&fav_count=1')", 1);
  }
  else
  {
    $get('fav_link_holder').innerHTML = "<a href=\"#\"><img src='templates/_general/images/mozilla_blu.gif'></a>";
  }
}

function new_design_fnBbShowResponse(req)
{ 
  if (req.responseText !== "")
  {           
    $get('bb_link_holder').innerHTML = req.responseText;
//    setTimeout("new Net.Updater('bb_count', '/?a=profile_ajax&bb_count=1')", 1);
  }  
  else
  {
    $get('bb_link_holder').innerHTML = "<a href=\"#\"><img src='templates/_general/images/mozilla_blu.gif'></a>";
  }
}

function new_design_fnShowFavLoading()
{      
    $get('fav_link_holder').innerHTML = "<a href=\"#\"><img src='templates/_general/images/mozilla_blu.gif'></a>"; 
//    $get('fav_link_holder').innerHTML = "<li class=\"addToFaves\"><a href=\"#\"><img src='templates/coedsingles/images/mozilla_blu.gif'></a></li>"; 
}
function new_design_fnShowBBLoading()
{
    $get('bb_link_holder').innerHTML = "<a href=\"#\"><img src='templates/_general/images/mozilla_blu.gif'></a>";
//    $get('bb_link_holder').innerHTML = "<li class=\"addToBB\"><a href=\"#\"><img src='templates/coedsingles/images/mozilla_blu.gif'></a></li>";
}
function new_design_fnShowBLLoading()
{
    $get('blocked_list').innerHTML = "<img src='templates/_general/images/mozilla_blu.gif'>";
}