
  flickedStory=0;
  flickedComment=0;
  friendApproved=0;
  
  function flickIt(storyID,fkey){
   flickedStory=storyID;
    if (fkey==-1)
    {
   	alert("You must be logged in to flick stories.\nIf you are not already a member...join and let your vote be heard!");
   	$.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 flickItPhone(storyID,fkey){
   flickedStory=storyID;
    if (fkey==-1)
    {
   	alert("You must be logged in to flick stories.\nIf you are not already a member...join and let your vote be heard!");
   	//tb_show('', 'http://www.flickdirect.com/backlot/thick-registration.aspx?height=650&inlineId=div_cropphoto&width=750&modal=true&TB_iframe=true', null);
   	window.location='http://www.flickdirect.com/iphone/loginphone.aspx';
  }
  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 flickReadyPhone()
{
 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("Whoops soemthing blew up. Comment not posted.")
  }
  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('Whoops, either 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=document.getElementById('username').value;
  password=document.getElementById('password').value;
  //do error checking here
   if (error==false)
   {
    url='http://www.flickdirect.com/ajaxFunctions.asp?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=document.getElementById('username-page').value;
  password=document.getElementById('password-page').value;
  //do error checking here
   if (error==false)
   {
    url='http://www.flickdirect.com/ajaxFunctions.asp?action=login&username='+username+'&password='+password
   
    xmlHttp=GetXmlHttpObject();
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=loginReady;
    xmlHttp.send(null);
   
   }
 
 }
 
 function goLoginPhone()
  {
  error=false;
  username=document.getElementById('username-page').value;
  password=document.getElementById('password-page').value;
  //do error checking here
   if (error==false)
   {
    url='http://www.flickdirect.com/ajaxFunctions.asp?action=login&username='+username+'&password='+password
   
    xmlHttp=GetXmlHttpObject();
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=loginPhoneReady;
    xmlHttp.send(null);
   
   }
 
 }
 
 
 function doQuickLogin(){
  username=document.getElementById('username').value;
  password=document.getElementById('password').value;
   if (username=="username")
   {
    window.location='http://www.flickdirect.com/backlot/flick-registration.aspx';
   }
   else
   {
   var strToWhere = document.getElementById("towhere").value;
    url='http://www.flickdirect.com/ajaxFunctions.asp?action=login&username=' + username + '&password=' + password;
    
    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='http://www.flickdirect.com/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 = ''
        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 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 goSubmitNew(fkey){
     okToSubmit = true;
 newurl=document.getElementById('newurl').value;
 if (newurl=='http://')
 {
  alert('Please enter a url');
  okToSubmit=false;
 }
 
 if (newurl.indexOf('http://http://')==0)
 {
  alert('The url you entered does not appear to be working, please check it and try again. Its easiest to copy and paste from your web browser.')
  okToSubmit=false;
  }
  
  if (newurl.indexOf('http://')==-1)
  {
  alert('Your url must begin with http://, its easiest to copy and paste from your web browser.')
  okToSubmit=false;
  }

  if (okToSubmit == true) {
      url = 'http://www.flickdirect.com/ajaxFunctions.asp?action=submitNewUrl&fkey=' + fkey + '&newurl=' + escape(newurl)
      xmlHttp = GetXmlHttpObject();
      xmlHttp.open("GET", url, true);
      xmlHttp.onreadystatechange = newReady;
      xmlHttp.send(null);

  }
  else {
      document.getElementById('btnSubmitNews').disabled = false;
      document.getElementById('movieanimation').style.display = 'none';
  }
  
 }
 
 
 		function goSummaryLength(maxchars) 
		{
        if(document.getElementById("contents").value.length > maxchars) 
        {
            alert('Too much data in the summary Please remove '+
    (document.getElementById("contents").value.length - maxchars)+ ' characters');
   return false; }
 else
   return true; }
   

 
 function newReady()
 {
    if (xmlHttp.readyState==4)
    {
    myString=xmlHttp.responseText
    if (myString.indexOf('error-dupe')!=-1)
    {
    alert('This url has already been submitted...one moment while I pull up the page.');
    //alert(myString.substring(myString.indexOf(',')+1))
    window.location='http://www.flickdirect.com/news/movie-news-detail.aspx?id=' + myString.substring(myString.indexOf(',')+1);
    }
   else
   {
    //alert(xmlHttp.responseText);
    window.location='http://www.flickdirect.com/submit-new-step2.aspx?storyID=' + xmlHttp.responseText + '&url=' + document.getElementById("newurl").value;
   }
 }
 }
 

 
 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;
}