var xmlHttp

var current_div



function playCaptcha()
{
//document.getElementById('captcha_audio').src 
//='/includes/captcha/securimage_show.php?' + Math.random();
//document.getElementById('code').focus();

current_div="play_captcha"

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
var url="/includes/captcha/securimage_play.php"
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}


function getVote(int,fileid,username)
{
current_div="poll"

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
var url="poll_vote.php"
url=url+"?vote="+int
url=url+"&fid="+fileid
url=url+"&username="+username
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 


function jobSampleVote(vote,wf_uid,lt_id)
{
current_div="poll_sample_vote_" + lt_id

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
if ( vote == 0 )
  {
  return;
  }
var url="job_sample_vote.php"
url=url+"?vote="+vote
url=url+"&lt_id="+lt_id
url=url+"&wf_uid="+wf_uid
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChanged() 
{ 
//alert ("a tagid = " + xmlHttp.readyState )

 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 // document.getElementById("poll").innerHTML=xmlHttp.responseText;
 document.getElementById(current_div).innerHTML=xmlHttp.responseText;

 } 
} 

function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
 {
 objXMLHttp=new XMLHttpRequest()
 }
else if (window.ActiveXObject)
 {
 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
 }
return objXMLHttp
}

function getTagVote(grpid,tagid,vote)
{
//alert ( "TVaa " + grpid + " " + tagid + " " + vote );

current_div="poll_" + tagid

xmlHttp=GetXmlHttpObject()
//alert ( "TVbb " + grpid + " " + tagid + " " + vote );
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
//alert ( "TVcc " + grpid + " " + tagid + " " + vote );
var url="tag_vote.php"
url=url+"?g="+grpid
url=url+"&tag="+tagid
url=url+"&v="+vote

xmlHttp.onreadystatechange=stateChanged

//alert ( "TVdd " + grpid + " " + tagid + " " + vote + " " + xmlHttp.onreadystatechange);

xmlHttp.open("GET",url,true)
//alert ( "TVee " + grpid + " " + tagid + " " + vote );
xmlHttp.send(null)
//alert ( "TVff " + grpid + " " + tagid + " " + vote );
}


function handleModerateVote(vote,user_id,comment_id)
{
current_div="poll_" + comment_id

//alert ( int + " " + user_id + " " + comment_id )



xmlHttp=GetXmlHttpObject()
//alert ( "TVbb " );
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
//alert ( "TVcc ")
var url="moderate_vote.php"
url=url+"?u="+user_id
url=url+"&c="+comment_id
url=url+"&v="+vote

xmlHttp.onreadystatechange=stateChanged

//alert ( "TVdd " + " " + user_id + " " + comment_id + " " + xmlHttp.onreadystatechange)

xmlHttp.open("GET",url,true)
//alert ( "TVee " + grpid + " " + tagid + " " + vote );
xmlHttp.send(null)
//alert ( "TVff " + grpid + " " + tagid + " " + vote );

}


/*
1 for a positive vote
0 for a negative vote
 */
function tagVote(vote,fileid,tagid, grpid,tagcount)
{
//alert ( "TVaa " + grpid + " " + tagid + " " + vote );

current_div="tag_" + tagid

xmlHttp=GetXmlHttpObject()
//alert ( "TVbb " + grpid + " " + tagid + " " + vote );
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
//alert ( "TVcc " + grpid + " " + tagid + " " + vote );
var url="tag_vote_moderate.php"
url=url+"?g="+grpid
url=url+"&tag="+tagid
url=url+"&v="+vote
url=url+"&f="+fileid
url=url+"&tc="+tagcount

xmlHttp.onreadystatechange=stateChanged

//alert ( "TVdd " + grpid + " " + tagid + " " + vote + " " + xmlHttp.onreadystatechange);

xmlHttp.open("GET",url,true)
//alert ( "TVee " + grpid + " " + tagid + " " + vote );
xmlHttp.send(null)
//alert ( "TVff " + grpid + " " + tagid + " " + vote );
}



function imageSelect ( the_type , user_id,file_id, grp_id) 
  {
  if ( the_type == 1 )
    {
    current_div="poll_select";
    }
  else if (  the_type == 2 )
    {
    current_div="poll_adult";
    }
  else if (  the_type == 3 )
    {
    current_div="poll_favorite";
    }
  else if (  the_type == 4 )
    {
    current_div="poll_adult_" + file_id ;
    }
  else if (  the_type == 5 )
    {
    current_div="poll_select_" + file_id ;
    }
  else if (  the_type == 6 )
    {
    //    alert ("got here");
    var x = document.getElementsByName ( "a_thumbnail" );

    for (var i=0; i < x.length; i++) 
      {
      var w = x[i];
      
      //      alert("I am a " + w.tagName + " element " + w.width + " id=" + w.id )
      current_div="poll_select_" + w.id ;
      
      var url="quick_select.php";
      url=url+"?typ=5";
      url=url+"&uid="+user_id;
      url=url+"&fid="+w.id;
      url=url+"&g="+grp_id;

      xmlHttp=GetXmlHttpObject();

      var contentHandler = new TagHandler(null);

      if (xmlHttp==null)
        {
        alert ("Browser does not support HTTP Request");
        return;
        }
      xmlHttp.asyncFlag=false;
      //xmlHttp.onreadystatechange=stateChanged ;
      xmlHttp.onreadystatechange = responseHandler ( xmlHttp , contentHandler , w );
      xmlHttp.open("GET",url,true);
      // responseHandler() 
      //      contentHandler.tagName = w.id;
      var f=0;

      //xmlHttp.onreadystatechange = responseHandler ( xmlHttp , contentHandler , w );

      //while ( xmlHttp.readyState < 4 )
      //{
        //        xmlHttp.onreadystatechange = responseHandler ( xmlHttp , contentHandler , w );
        //f = f + 1;
        //if ( f > 10 ) break;

        //}
      //      contentHandler.tagName = tagName;
      //      setTimeout ("xmlHttp", 500);

            xmlHttp.send(null);
      //      break;
      }
    return;
    }

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    } 
  var url="quick_select.php";
  url=url+"?typ="+the_type;
  url=url+"&uid="+user_id;
  url=url+"&fid="+file_id;
  url=url+"&g="+grp_id;
  xmlHttp.onreadystatechange=stateChanged ;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }

/*
0 = by filename
1 = by score
*/

function setSortOrder ( the_value ) 
  {
  current_div="setsortorder";

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    } 
  var url="set_sort_order.php";
  url=url+"?v="+the_value;
  xmlHttp.onreadystatechange=stateChanged ;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }

/*
*/

function setAdultTolerance ( the_value ) 
  {
  current_div="setadulttolerance";

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    } 
  var url="set_adult_tolerance.php";
  url=url+"?v="+the_value;
  xmlHttp.onreadystatechange=stateChanged ;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }

function setCommentLevel ( the_value ) 
  {
  current_div="setcommentlevel";

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    } 
  var url="set_desired_comment_level.php";
  url=url+"?v="+the_value;
  xmlHttp.onreadystatechange=stateChanged ;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }



function establishRelationShip ( the_action , c_yp_uid , comment_count )
{
//alert ( the_action + " " + c_yp_uid );

  current_div="iconrelationships" + comment_count;

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    } 
  var url="makefriend.php";
  url=url+"?a="+the_action;
  url=url+"&c="+c_yp_uid;
  url=url+"&cc="+comment_count;
  xmlHttp.onreadystatechange=stateChanged ;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  //  location.reload(true);
}

function ChangeRank ()
{
alert ("got here");
}

function danTest2 (userid,newrank)
{
//alert ("got here");
var anewrank="friend";
if ( newrank==0)
  {
  anewrank="foe";
  }
else
  {
  anewrank="foe";
  }


var thediv = "userstyle"+userid ;
var newstyle = '<style type=\"text/css\">\rdiv.user_rank'+ userid + " { background: url(\"http://www.yurpics.com/images/"+anewrank+".gif\") }\r</style>";

alert (newstyle);

document.getElementById(thediv).value = newstyle;

/*
  current_div="iconrelationships" + comment_count;

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    } 
  var url="makefriend.php";
  url=url+"?a="+the_action;
  url=url+"&c="+c_yp_uid;
  url=url+"&cc="+comment_count;
  xmlHttp.onreadystatechange=stateChanged ;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
*/ 

}

function TagHandler(tagName)
{
var tagName;
return tagName;
}

function responseHandler(ajax,contentHandler,objCurrent) 
  {
  //var objCurrent = document.getElementById(contentHandler.tagName)
  if(ajax.readyState == 0) { objCurrent.innerHTML = "Sending Request…If this continues to load with no results, click the link again or reload the page."; }
  if(ajax.readyState == 1) { objCurrent.innerHTML = "Loading…If this continues to load with no results, click the link again or reload the page."; }
  if(ajax.readyState == 2) { objCurrent.innerHTML = "Loaded…If this continues to load with no results, click the link again or reload the page."; }
  if(ajax.readyState == 3) { objCurrent.innerHTML = "Almost done…If this continues to load with no results, click the link again or reload the page."; }

  if(ajax.readyState == 4)
    {
    if(ajax.status == 200)
      {
      objCurrent.innerHTML = "";
      var updateContent = ajax.responseText;
      if(updateContent) 
        {
        objCurrent.innerHTML = updateContent;
        }
      }
    else if(ajax.status == 404)
      {
      // Retrive error message or redirect to error page
      objCurrent.innerHTML = "File not found";
      }
  else
    {
    // Give a catch all error message
    objCurrent.innerHTML = "We are currently experiencing technical difficulties and are addressing the issue.";
    }

  //set a tabindex to - 1 to help screen readers focus on the changed content. Then set the focus to the changed content.
  objCurrent.tabIndex = -1;
  objCurrent.focus();
}
}
