// Get base url
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);
var _dialogPromptID=null;
var _blackoutPromptID=null;

  setTimeout("checkIt()",5000);
  promptInput = "";
  function checkIt() {
  if (follow == 1) {
    setTimeout("checkLead(thisPage)",5000);
  }
  }
    function checkLead(tp) {
      followPage(thisPage);
      if (follow == 1) {
        setTimeout("checkLead(leader)",5000);
      }
    }
  if (lead == 1) {
    setTimeout("doLead(thisPage)",1000);
  }
  var currVote='';

function setVote(x) {
  currVote = x.value;
}

function procRequest (prog,sfx,typ) {
        // Does URL begin with http?
        prog = prog + ".php";
        url = "http://connect2dance.com/" + prog;
        if (sfx == 1) {
          sfx = sfx + '.value';
        }
        url = url + "?id=" + sfx;

        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}

function updPage (fld,data,typ) {
        // Does URL begin with http?
        prog = "updPage.php";
        url = "http://connect2dance.com/" + prog;
        if (typ == 1) {
          typ = type + '.value';
        }
        url = url + "?f=" + fld+ "&d=" + data;
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
function updStyle (fld,typ) {
        // Does URL begin with http?
        prog = "updStyle.php";
        url = "http://connect2dance.com/" + prog;
        if (typ == 1) {
          typ = type + '.value';
        }
        url = url + "?f=" + fld+ "&d=getstyle";
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}

 
function showDoc (sfx) {
        // Does URL begin with http?
        url = 'http://connect2dance.com/showdoc.php';
        url = url + "?id=" + sfx;
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
                                                                                
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
                                                                                
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
function followPage (sfx) {
        // Does URL begin with http?
        url = 'http://connect2dance.com/follow.php';
        url = url + "?id=" + leader + "&p=" + sfx;
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
                                                                                
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
function takeLead (sfx) {
        // Does URL begin with http?
        url = 'http://connect2dance.com/takelead.php';
        url = url + "?id=" + sfx;
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
                                                                                
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
                                                                                
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
function takeFollow (sfx) {
        IEprompt( 'Follow Whom?', 'Enter Username');
}
function promptCallback(sfx) {
//        p = prompt('Follow Whom?', 'Enter Username');
        p=sfx;
        // Does URL begin with http?
        url = 'http://connect2dance.com/takefollow.php';
        url = url + "?id=" + p;
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
                                                                                
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}

function doLead(sfx) {
        // Does URL begin with http?
        url = 'http://connect2dance.com/lead.php';
        url = url + "?id=" + sfx;
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
                                                                                
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
function dropLead(sfx) {
        // Does URL begin with http?
        url = 'http://connect2dance.com/leadout.php';
        url = url + "?id=" + sfx;
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
                                                                                
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
function doProfileType(sfx) {
        // Does URL begin with http?
        url = 'http://connect2dance.com/profile_type.php';
        url = url + "?id=" + sfx.value;
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
                                                                       
                                                                       
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
function showChat (sfx,usr,member) {
        url = 'http://connect2dance.com/chatbox1.php';
        url = url + "?u=" + usr + "&m=" + member + "&id=" + sfx.value;
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
function pollChat (member) {
         url = 'http://connect2dance.com/pollchat.php';
         url = url + "?m=" + member;
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
        x = "pollChat('" + member + "')";
//        setTimeout(x,10000);
}
function updPoll() {
 t=document.getElementById('voteType');
 typ = t.value;
 t=document.getElementById('voteView');
 vw = t.value;

         url = 'http://connect2dance.com/vote/doVote.cgi';
         url = url + "?type=" + typ + "&view=" + vw + "&vote=" + currVote;
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}

function IEprompt(innertxt,def) {

   that=this;   // A workaround to javascript's oop idiosyncracies.

   // Check to see if this is MSIE 7.   This isn't a great general purpose
   // detection system but it works well enough just to find MSIE 7.
   var _isIE7=(navigator.userAgent.indexOf('MSIE 7')>0);

   this.wrapupPrompt = function (cancled) {
      // wrapupPrompt is called when the user enters or cancels the box.
      // It's called only by the IE7 dialog box, not the non IE prompt box
      if (_isIE7) {
         // Make sure we're in IE7 mode and get the text box value
         val=document.getElementById('iepromptfield').value;
         // clear out the dialog box
         _dialogPromptID.style.display='none';
         // clear out the screen
         _blackoutPromptID.style.display='none';
         // clear out the text field
         document.getElementById('iepromptfield').value = '';
         // if the cancel button was pushed, force value to null.
         if (cancled) { val = '' }
         // call the user's function
         promptCallback(val);
      }
      return false;
   }

   //if def wasn't actually passed, initialize it to null
   if (def==undefined) { def=''; }

   if (_isIE7) {
      // If this is MSIE 7.0 then...
      if (_dialogPromptID==null) {
         // Check to see if we've created the dialog divisions.
         // This block sets up the divisons
         // Get the body tag in the dom
         var tbody = document.getElementsByTagName("body")[0];
         // create a new division
         tnode = document.createElement('div');
         // name it
         tnode.id='IEPromptBox';
         // attach the new division to the body tag
         tbody.appendChild(tnode);
         // and save the element reference in a global variable
         _dialogPromptID=document.getElementById('IEPromptBox');
         // Create a new division (blackout)
         tnode = document.createElement('div');
         // name it.
         tnode.id='promptBlackout';
         // attach it to body.
         tbody.appendChild(tnode);
         // And get the element reference
         _blackoutPromptID=document.getElementById('promptBlackout');
         // assign the styles to the blackout division.
         _blackoutPromptID.style.opacity='.9';
         _blackoutPromptID.style.position='absolute';
         _blackoutPromptID.style.top='0px';
         _blackoutPromptID.style.left='0px';
         _blackoutPromptID.style.backgroundColor='#555555';
         _blackoutPromptID.style.filter='alpha(opacity=90)';
         _blackoutPromptID.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px'; 
         _blackoutPromptID.style.display='block';
         _blackoutPromptID.style.zIndex='50';
         // assign the styles to the dialog box
         _dialogPromptID.style.border='2px solid blue';
         _dialogPromptID.style.backgroundColor='#DDDDDD';
         _dialogPromptID.style.position='absolute';
         _dialogPromptID.style.width='330px';
         _dialogPromptID.style.zIndex='100';
      }
      // This is the HTML which makes up the dialog box, it will be inserted into
      // innerHTML later. We insert into a temporary variable because
      // it's very, very slow doing multiple innerHTML injections, it's much
      // more efficient to use a variable and then do one LARGE injection.
      var tmp = '<div style="width: 100%; background-color: blue; color: white; "';
      tmp += 'font-family: verdana; font-size: 10pt; font-weight: bold; height: 20px">Input Required</div>';
      tmp += '<div style="padding: 10px">'+innertxt + '<BR><BR>';
      tmp += '<form action="" onsubmit="return that.wrapupPrompt()">';
      tmp += '<input id="iepromptfield" name="iepromptdata" type=text size=46 value="'+def+'">';
      tmp += '<br><br><center>';
      tmp += '<input type="submit" value="&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;">';
      tmp += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
      tmp += '<input type="button" onclick="that.wrapupPrompt(true)" value="&nbsp;Cancel&nbsp;">';
      tmp += '</form></div>';
      // Stretch the blackout division to fill the entire document
      // and make it visible.  Because it has a high z-index it should
      // make all other elements on the page unclickable.
      _blackoutPromptID.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px'; 
      _blackoutPromptID.style.width='100%';
      _blackoutPromptID.style.display='block';
      // Insert the tmp HTML string into the dialog box.
      // Then position the dialog box on the screen and make it visible.
      _dialogPromptID.innerHTML=tmp;
      _dialogPromptID.style.top=parseInt(document.documentElement.scrollTop+(screen.height/3))+'px';
      _dialogPromptID.style.left=parseInt((document.body.offsetWidth-315)/2)+'px';
      _dialogPromptID.style.display='block';
      // Give the dialog box's input field the focus.
      document.getElementById('iepromptfield').focus();
   } else {
      // we are not using IE7 so do things "normally"
      promptCallback(prompt(innertxt,def));
   }
}

