
  flickedStory=0;
  flickedComment=0;
  friendApproved=0;
  
  function flickIt(storyID,fkey){
   flickedStory=storyID;
    if (fkey==-1)
    {
   	$.facebox({ ajax: '/ajax-login.aspx?url=' + document.location.href });
   	
  }
  else{
   url='http://www.flickdirect.com/ajaxFunctions.asp?action=flickStory&storyID=' + storyID + '&fkey=' +fkey
   xmlHttp=GetXmlHttpObject();  
   xmlHttp.open("GET",url,true);
   xmlHttp.onreadystatechange=flickReady;
 	xmlHttp.send(null);
  }
  }
  
function flickReady()
{
 if (xmlHttp.readyState==4)
 {
  if (xmlHttp.responseText=="error_dupe")
  {
  	alert("You may only vote once per story")
  }
  else
  {
    $('#votes' + flickedStory).fadeOut('slow', function(){document.getElementById('votes' + flickedStory).innerHTML=xmlHttp.responseText;});
    $('#flicktext' + flickedStory).fadeOut('slow', function(){document.getElementById('flicktext' + flickedStory).innerHTML='Flicked';document.getElementById('flicktext' + flickedStory).style.color='#9a5bd9';});
    $('#votes' + flickedStory).fadeIn('slow');
    $('#flicktext' + flickedStory).fadeIn('slow');

  }
 }
}

function addComment(storyID, userID, fkey) {
    comment = document.getElementById("txtMovieNewsComment").value;
    
        
 if (comment==''){
  alert('Please enter your comment before submitting.');
  }
  else {

      //update twitter
      dataToSend = 'storytype=1&storyid=' + storyID + '&comment=' + escape(comment);

      $.ajax({
          type: "GET",
          dataType: 'html',
          url: "/ajax-update-twitter.aspx",
          data: dataToSend,
          timeout: 10000,
          success: function(msg) {
          }
      })
  
   url='http://www.flickdirect.com/ajaxFunctions.asp?action=addComment&comment=' + escape(comment) + '&storyID=' + storyID + '&userID=' + userID + '&fkey='+ fkey
   
   xmlHttp=GetXmlHttpObject();  
   xmlHttp.open("GET",url,true);
   xmlHttp.onreadystatechange=addCommentReady;
 	xmlHttp.send(null);
  }

}

function addCommentReady() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.responseText == "error") {
            alert("We apologize but we could not post your comment at this time.")
        }
        else {
            $('#commentformblock').fadeOut('fast');
            document.getElementById('commentHolder').innerHTML = xmlHttp.responseText;
            document.getElementById('tempHolder').style.visibility = 'visible';
            $('#tempHolder').hide()
            $('#tempHolder').fadeIn('slow');

        }
    }
}

function addReviewComment(storyID,userID,fkey){
comment=document.getElementById("txtMovieNewsComment").value;
 if (comment==''){
  alert('Please enter your comment before submitting.');
  }
  else
  {

      //update twitter
      dataToSend = 'storytype=2&storyid=' + storyID + '&comment=' + escape(comment); 

        $.ajax({
        type: "GET",
            dataType: 'html',
            url: "/ajax-update-twitter.aspx",
            data: dataToSend,
            timeout: 10000,
            success: function(msg) {
            }
        })
        
   url='http://www.flickdirect.com/ajaxFunctions.asp?action=addReviewComment&comment=' + escape(comment) + '&storyID=' + storyID + '&userID=' + userID + '&fkey='+ fkey
   
   xmlHttp=GetXmlHttpObject();  
   xmlHttp.open("GET",url,true);
   xmlHttp.onreadystatechange=addCommentReady;
 	xmlHttp.send(null);
  }

}

function addReviewCommentReady(){
  if (xmlHttp.readyState==4){
  if (xmlHttp.responseText=="error"){
      alert("We apologize but we could not post your comment at this time.")
  }
  else{
  $('#commentformblock').fadeOut('fast');
  document.getElementById('commentHolder').innerHTML=xmlHttp.responseText;
  document.getElementById('tempHolder').style.visibility='visible';
  $('#tempHolder').hide()
  $('#tempHolder').fadeIn('slow');
  
  }
 }
 }

 function addMediaComment(storyID, userID, fkey) {
     comment = document.getElementById("txtMovieNewsComment").value;
     if (comment == '') {
         alert('Please enter your comment before submitting.');
     }
     else {

         //update twitter
         dataToSend = 'storytype=4&storyid=' + storyID + '&comment=' + escape(comment);

         $.ajax({
             type: "GET",
             dataType: 'html',
             url: "/ajax-update-twitter.aspx",
             data: dataToSend,
             timeout: 10000,
             success: function (msg) {
             }
         })

         url = 'http://www.flickdirect.com/ajaxFunctions.asp?action=addMediaComment&comment=' + escape(comment) + '&storyID=' + storyID + '&userID=' + userID + '&fkey=' + fkey

         xmlHttp = GetXmlHttpObject();
         xmlHttp.open("GET", url, true);
         xmlHttp.onreadystatechange = addCommentReady;
         xmlHttp.send(null);
     }

 }

 function addMediaCommentReady() {
     if (xmlHttp.readyState == 4) {
         if (xmlHttp.responseText == "error") {
             alert("We apologize but we could not post your comment at this time.")
         }
         else {
             $('#commentformblock').fadeOut('fast');
             document.getElementById('commentHolder').innerHTML = xmlHttp.responseText;
             document.getElementById('tempHolder').style.visibility = 'visible';
             $('#tempHolder').hide()
             $('#tempHolder').fadeIn('slow');

         }
     }
 }

 function goForgot() {
     email = document.getElementById('email').value;
     if (email == '') {
         alert('Please Enter Your Email Address')
     }
     else {
         url = 'http://www.flickdirect.com/ajaxFunctions.asp?action=forgot&email=' + email
         xmlHttp = GetXmlHttpObject();
         xmlHttp.open("GET", url, true);
         xmlHttp.onreadystatechange = forgotReady;
         xmlHttp.send(null);
     }

 }

 function forgotReady() {
     if (xmlHttp.readyState == 4) {
         if (xmlHttp.responseText == "error_notfound") {
             alert("The email address you entered was not found")
         }
         else {
             alert("Your username and password have been emailed to you")
         }
     }
 }
 
 function addTag(storyID,fkey)
 {
   if (fkey==-1)
    {
        alert('You must be logged in to tag stories');
        window.location='/login.aspx'
   }
   
   
   tag = document.getElementById('tag').value;
   tag = tag.replace(/&/,"%26");
   
    if (tag=='')
    {
        alert('Please enter a tag before submitting.')
  }
  else
  {
   url='http://www.flickdirect.com/ajaxFunctions.asp?action=addTag&storyID=' + storyID + '&fkey=' +fkey +'&tag=' + tag
   xmlHttp=GetXmlHttpObject();  
   xmlHttp.open("GET",url,true);
   xmlHttp.onreadystatechange = tagReady;
   xmlHttp.send(null);
  }  
}
 
 
 
 function goApproveFriend(me,them)
 {
 	  friendApproved=them
 	  url='http://www.flickdirect.com/ajaxFunctions.asp?action=approveFriend&me='+me+'&them='+them
    //alert(url)
    xmlHttp=GetXmlHttpObject();
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=friendApproveReady;
 	 xmlHttp.send(null);
}

  function friendApproveReady()
  {
 if (xmlHttp.readyState==4){
  myResult=xmlHttp.responseText
  if (myResult=="error"){
   alert('Whoops, something blew up. Your friend request was not approved.');
  }
   else
  {
   //alert('here');
   window.location.reload( false );
  }

 }
 }
 
 function goAddFriend(userID,friendRequestID)
 {
 	  url='http://www.flickdirect.com/ajaxFunctions.asp?action=addFriend&userID='+userID+'&friendRequestID='+friendRequestID
    //alert(url)
    xmlHttp=GetXmlHttpObject();
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=friendRequestReady;
 	  xmlHttp.send(null);
}

  function friendRequestReady()
  {
 if (xmlHttp.readyState==4){
  myResult=xmlHttp.responseText
  if (myResult=="error-dupe"){
  alert('This person is already your friend or there is a pending request.');
  }
  else{
   alert("A Request Has Been Sent To This User To Add Them As Your Friend!")
   document.getElementById('friendButton').innerHTML='<img src="/images/added-friend.gif" border="0">'
  }
 }
 }
 
 
  function goLogin()
  {
  error=false;
  username=encodeURIComponent(document.getElementById('username').value);
  password=encodeURIComponent(document.getElementById('password').value);
  //do error checking here
   if (error==false)
   {
    url='/flick-ajax.aspx?action=login&username='+username+'&password='+password
    //alert(url)
    xmlHttp=GetXmlHttpObject();
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=loginReady;
    xmlHttp.send(null);
   
   }
}
 
   function goLoginPage()
  {
  error=false;
  username=encodeURIComponent(document.getElementById('username-page').value);
  password=encodeURIComponent(document.getElementById('password-page').value);
  //do error checking here
   if (error==false)
   {
    url='/flick-ajax.aspx?action=login&username='+username+'&password='+password
   
    xmlHttp=GetXmlHttpObject();
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=loginReady;
    xmlHttp.send(null);
   
   }
 
 }
 
 function goLoginPhone()
  {
   var error=false;
   var username=encodeURIComponent(document.getElementById('username-page').value);
   var password=encodeURIComponent(document.getElementById('password-page').value);
  //do error checking here
   if (error==false)
   {
       var url = '/flick-ajax.aspx?action=login&username=' + username + '&password=' + password;
       xmlHttp=GetXmlHttpObject();
       xmlHttp.open("GET",url,true);
       xmlHttp.onreadystatechange=loginPhoneReady;
       xmlHttp.send(null);
   }
 
 }
 
 
 function doQuickLogin(){
  username=encodeURIComponent(document.getElementById('username').value);
  password=encodeURIComponent(document.getElementById('password').value);
   if (username=="username")
   {
    window.location='/backlot/flick-registration.aspx';
   }
   else
   {
   var strToWhere = document.getElementById("towhere").value;
    url='/ajaxFunctions.asp?action=login&username=' + username + '&password=' + password;
   // alert (url);
    xmlHttp=GetXmlHttpObject();
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=loginReady;
 	  xmlHttp.send(null);
   
   }
 }
 
 
 function loginReady()
 {
 if (xmlHttp.readyState==4)
 {
  if (xmlHttp.responseText=='error-nouser')
  {
     alert('Your username or password were incorrect, please try again')
    window.location='/login.aspx'
   }
   else
   {
        var strURL = ''
        if ( document.getElementById("url")) 
            strURL = document.getElementById("url").value;
        
        if (document.getElementById("towhere-page"))
        {
            var strToWhere = document.getElementById("towhere-page").value;
            }
        else 
        {
            var strToWhere = document.getElementById("towhere").value;
            }
            
        window.location='/loginout.aspx?uid=' + xmlHttp.responseText + '&type=login&url=' + strURL + '&towhere=' + strToWhere;
        //alert( '/loginout.aspx?uid=' + xmlHttp.responseText + '&type=login&url=' + strURL + '&towhere=' + strToWhere)
       
     }
 }
 }
 
 function loginPhoneReady()
 {
     if (xmlHttp.readyState==4)
     {
         if (xmlHttp.responseText=='error-nouser')
         {
             alert('Your username or password were incorrect, please try again');
         }
         else
         {
             var strURL = '';
             var strToWhere = '';
             if (document.getElementById("url")) {
                 strURL = document.getElementById("url").value;
             }
             if (document.getElementById("towhere-page")) {
                 strToWhere = document.getElementById("towhere-page").value;
             }
             else
             {
                 strToWhere = document.getElementById("towhere").value;
             }
 
             window.location='/loginout.aspx?uid=' + escape(xmlHttp.responseText) + '&type=login&url=' + escape(strURL) + '&towhere=' + escape(strToWhere);
             //alert( '/loginout.aspx?uid=' + xmlHttp.responseText + '&type=login&url=' + strURL + '&towhere=' + strToWhere)
 
         }
     }
 }

 function tagReady() {
     if (xmlHttp.readyState == 4) {
         if (xmlHttp.responseText == 'error-dupe') {
             alert('That tag already exists for this story')
         }
         else {
             myResult = xmlHttp.responseText.split(',');
             if (myResult[0] >= 4) {
                 document.getElementById('tagdiv').style.visibility = 'hidden';
                 document.getElementById('addTagButton').style.visibility = 'hidden';
             }

             document.getElementById('myTags').innerHTML = document.getElementById('myTags').innerHTML + '<a href=http://www.flickdirect.com/news/movie-news.aspx?tag=' + myResult[1].replace(' ', '+') + '>' + myResult[1] + '</a>&nbsp;&nbsp;';
         }
     }
 }
 

 function logout(){
 //alert("logout")
 window.location='http://www.flickdirect.com/loginout.aspx?type=logout'
 }
  
  function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function URLEncode(str) {
    var nstr = escape(str);

    nstr = nstr.replace(/\+/g, '%2B');
    nstr = nstr.replace(/\%20/g, '+');

    return nstr;
}
