function flipCell(count, idTag){
  f = document.getElementById(idTag);
  f.style.display = (f.style.display == "none") ? showRow : "none";
}
  
var http_request = false;
function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!http_request) {
    alert('Cannot create XMLHTTP instance');
    return false;
  }
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function alertContents() {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      result = http_request.responseText;
      alert(result);
    } else {
      alert('There was a problem with the request.');
    }
  }
}

function swap(mode, postid){
  var cpage;
  var title;
  var surl;
  var strtmp;
  cpage = "c" + postid;
  title = 'test';
  surl  = escape('http://www.spoofee.com/index.php?section=deal&did=' + postid);
  if (mode == 'e'){
    strtmp = "<table>";
    strtmp += "<tr><td class=popuptext>Your Name :</td>";
    strtmp += "<td><input id=yn" + postid + " name=\"name\" type=\"text\" size=15></td>";
    strtmp += "</tr>";
		
    strtmp += "<tr><td class=popuptext>Friend's Email:</td>";
    strtmp += "<td><input id=fe" + postid + " name=email type=text size=15></td>";
    strtmp += "</tr>";
		
    strtmp += "<tr><td colspan=3 align=center>";
    strtmp += "<input type=submit value=\"Tell a Friend!\" onclick=\"javascript:post(this.parentNode, 'friend', '" + postid + "');\">";
	strtmp += "</td></tr>";
    strtmp += "</table>";
  }else if(mode == 's'){
    strtmp = "<table>";
    strtmp += "<tr><td class=popuptext>";
    strtmp += "<a target='ref' href='aim:goim?message=" + surl + "'><img src='images/icons/aol.gif' border=0'> aol IM</a><br>";
    strtmp += "<a target='ref' href='http://blinklist.com/index.php?Action=Blink/addblink.php&Url=" + surl + "&Title='" + title + "'><img src='images/icons/blinklist.gif' border=0'> blinklist</a><br>";
    strtmp += "<a target='ref' href='http://del.icio.us/post?url=" + surl + "'><img src='images/icons/delicious.jpg' border=0'> del.icio.us</a><br>";
    strtmp += "<a target='ref' href='http://digg.com/submit?phase=2&url=" + surl + "'><img src='images/icons/digg.png' border=0'> digg</a><br>";
    strtmp += "<a target='ref' href='http://www.facebook.com/share.php?u=" + surl + "'><img src='images/icons/facebook.gif' border=0'> facebook</a><br>";
    strtmp += "<a target='ref' href='http://furl.net/storeIt.jsp?u=" + surl + "'><img src='images/icons/furl.gif' border=0'> furl</a><br>";
    strtmp += "<a target='ref' href='http://www.google.com/bookmarks/mark?op=edit&bkmk=" + surl + "&title='" + title + "'><img src='images/icons/google.jpg' border=0'> google</a><br>";
    strtmp += "<a target='ref' href='https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=" + surl + "'><img src='images/icons/live.gif' border=0'> live</a><br>";
    strtmp += "</td><td class=popuptext>";
    strtmp += "<a target='ref' href='http://ma.gnolia.com/bookmarklet/add?url=" + surl + "&title='" + title + "'><img src='images/icons/magnolia.gif' border=0'> ma.gnolia</a><br>";
    strtmp += "<a target='ref' href='http://www.netscape.com/submit/?U=" + surl + "&T='" + title + "'><img src='images/icons/netscape.gif' border=0'> netscape</a><br>";
    strtmp += "<a target='ref' href='http://www.newsvine.com/_wine/save?u=" + surl + "'><img src='images/icons/newsvine.gif' border=0'> newsvine</a><br>";
    strtmp += "<a target='ref' href='http://reddit.com/submit?url=" + surl + "&title='" + title + "'><img src='images/icons/reddit.gif' border=0'> reddit</a><br>";
    strtmp += "<a target='ref' href='http://www.stumbleupon.com/submit?url=" + surl + "&title='" + title + "'><img src='images/icons/stumbleupon.gif' border=0'> stumbleupon</a><br>";
    strtmp += "<a target='ref' href='http://tailrank.com/share/?link_href=" + surl + "&title='" + title + "'><img src='images/icons/tailrank.gif' border=0'> tailrank</a><br>";
    strtmp += "<a target='ref' href='http://www.technorati.com/faves?add=" + surl + "'><img src='images/icons/technorati.gif' border=0'> technorati</a><br>";
    strtmp += "<a target='ref' href='http://myweb2.search.yahoo.com/myresults/bookmarklet?u=" + surl + "&t='" + title + "'><img src='images/icons/yahoo.jpg' border=0'> yahoo</a><br>";strtmp += "</td></tr></table>";
  }else if(mode == 'l'){
    strtmp = "<table>";
    strtmp += "<tr><td class=popuptext>To get the direct link to this deal, just right click and the copy the URL of the following<br><br>";
    strtmp += "<a href='http://www.spoofee.com/index.php?section=deal&did=" + postid + "'><b>Link to Deal</b></a><br>";
    strtmp += "</td></tr></table>";
  }
  document.getElementById(cpage).innerHTML = strtmp;
}

function post(obj, type, postid) {
  var poststr;
  if (type == 'friend'){
    var yn = 'yn' + postid;
    var fe = 'fe' + postid;
    poststr = "name=" + encodeURI( document.getElementById(yn).value ) +
      "&email=" + encodeURI( document.getElementById(fe).value ) +
      "&postid=" + encodeURI( postid );
    makePOSTRequest('ajax/tellfriend.php', poststr);
  }
}