﻿// JScript File
function newWindow(file,window) {
     myUrl = 'private/sec/tagrecipe.aspx?id='+getrecipeid();
     newWin = open(myUrl, window, 'width=550,height=650,scrollbars=yes');
 };
// buttons
 function goLite(FRM, BTN) {
     window.document.forms[FRM].elements[BTN].style.backgroundColor = "#CC0000";
 }

 function goDim(FRM, BTN) {
     window.document.forms[FRM].elements[BTN].style.backgroundColor = "#800000";
 }
 function updateStatus(iUserID) {
     var status = 'UpdateStatus|' +iUserID+"|"+ document.getElementById("txtStatus").value.replace(/\|/g,"-");
     __doPostBack('__Page', status);
 }

function openTagVideoWindow(file,window) {
     myUrl = 'private/sec/tagrecipe.aspx?&vid=1&nobar=1&id='+getrecipeid();
     newWin = open(myUrl,window, 'width=500,height=450,scrollbars=yes');
     //msgWindow=open(file,'scrollbars=yes,width=300,height=400');
    //if (msgWindow.opener == null) msgWindow.opener = self;
 };

function gup( name ) // get url parameter, e.g., gup('id')
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
};
function getrecipeid( ) // get recipeid on url
{
  var regexS = 'http://www.bigoven.com/([0-9]*)-([.]*)';
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  //alert('We are currently upgrading the tags system.  Please check back soon.');
  //alert(tmpURL);
  
  //var results = regex.exec( 'http://www.bigoven.com/15844_asdfas_recipe.html' );
  var results = regex.exec( tmpURL );

  if (results != null)
      return results[1];

  regexS = 'http://localhost/([0-9]*)-([.]*)';
  regex = new RegExp(regexS);
  tmpURL = window.location.href;
  var results = regex.exec(tmpURL);
  if (results != null)
      return results[1];

    
    

  if( results == null )
    var regexS2 = 'http://www.bigoven.com/recipe([0-9]*)';
    var regex2 = new RegExp(regexS2);
    results = regex2.exec(tmpURL);
    if ( results == null)
       return gup('id');
    // must be rss_displayrecipe.aspx
    else
      if (results[1]=='')
      return gup('id');
      else
      //alert(results[1]);
      return results[1];
};

var req;

function InitializeXMLHttp() {
    try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            req = null;
        }
    }

    if (!req && typeof XMLHttpRequest != "undefined") {
        req = new XMLHttpRequest();
    }

}

function bumpup(iCommentID, iUserID) {
    if (iUserID <= 0) {
        alert('You must be signed in to vote comments up or down.  Please sign in and join the discussion!');
        return;}
    InitializeXMLHttp();
    var url = "/private/sec/bumpcomment.aspx?id=" + iCommentID + "&uid=" + iUserID+"&dir=1";
    if (req != null) {
        req.onreadystatechange = ProcessVote;
        req.open("GET", url, true);
        req.send(null);
    }
    else {
           alert('Could not create voting request.  Try again later.');
       }
    __doPostBack('__Page', 'MyCustomArgument');
    
};

function bumpdown(iCommentID, iUserID) {
    if (iUserID <= 0) {
        alert('You must be signed in to vote comments up or down.  Please sign in and join the discussion!');
        return;
    }
    InitializeXMLHttp();
    var url = "/private/sec/bumpcomment.aspx?id=" + iCommentID + "&uid=" + iUserID + "&dir=-1";
    if (req != null) {
        req.onreadystatechange = ProcessVote;
        req.open("GET", url, true);
        req.send(null);
    }
    else {
        alert('Could not create voting request.  Try again later.');
    }
    __doPostBack('__Page', 'MyCustomArgument');

};

function ProcessVote() {

    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            //alert('finished with response 200');
            // if (req.responseText == "")
            //     HideDiv("autocomplete");
            // else {
            //    ShowDiv("autocomplete");
            //     document.getElementById("autocomplete").innerHTML =
            //                                         req.responseText;
        }
    }
    else {
        //alert('error: ' + req.statusText);
        //     document.getElementById("autocomplete").innerHTML =
        //      "There was a problem retrieving data:<br>"
        //    + req.statusText;
    }
}