﻿// JScript File

    function enableDropDown(ddName,option)
    {
        var dropDown = document.getElementById(ddName);
        dropDown.disabled = (! option);

    }

    function SwapImage(imageID)
    {
      imageID
      var item = document.getElementById(imageID);
      var items =item.src.split("/");
      var imgFile = items[items.length-1];
      if (imgFile=="plus.gif")
      {
        item.src = "/foodline/images/minus.gif";
      }
      else
      {
        item.src = "/foodline/images/plus.gif";
      }
    }
    
    function SwapImageNames(imageID,image1,image2,adPath)
    {
      imageID
      var item = document.getElementById(imageID);
      var items =item.src.split("/");
      var imgFile = items[items.length-1];
      if (imgFile==image1)
      {
        item.src = "/foodline/images/" + adPath + image2;
      }
      else
      {
        item.src = "/foodline/images/" + adPath + image1;
      }
    }

    function SetImage(imageID,image,adPath)
    {
      imageID
      var item = document.getElementById(imageID);
      var items =item.src.split("/");
      var imgFile = items[items.length-1];
     
      item.src = "/foodline/images/" + adPath + image;
     

    }


    function setDivText(divName,divText)
    {
        document.getElementById(divName).innerHTML = divText;

    }

    function getURLVAR(name)
    {
        var varName, url = window.location.search.substring(1);
        if ('' != url)
        {
              var re = new RegExp(escape(name) + '=([^&$]+)');
              if (varName = url.match(re))
              {
                    return varName[1];
              }
              else
              { 
                    return '';
              }
        }
        return '';
    }
  
    function showMEHideME(d)
        {
        var style2 = document.getElementById(d).style;
        if (style2.display == "none")
        {
            style2.display = "block";
        }
        else
        {
            style2.display = "none";
        }

    }

  
    function showHideDiv(d)
    {
        var style2 = document.getElementById(d).style;
        if (style2.display == "none")
        {
            style2.display = "block";
        }
        else
        {
            style2.display = "none";
        }
  
    }
    
    function getItem(itemName)
    {
      //this is simple for now but might add functionality for NS
      return document.getElementById(itemName);
    }
    
    function setDivLoc(divName,outerDiv,divWidth,offx,offy)
    {
        var d = getItem(divName);
        var wD = getItem(outerDiv);
        var x = window.event.clientX;
        var y = window.event.clientY;
        var mWidth =(wD.offsetLeft +wD.offsetWidth ) - divWidth;
       //need some code for this to cover firefox
        var yoff =document.body.scrollTop
          //d.style.left = x ;
        if ((divWidth + x) >= (wD.offsetLeft +wD.offsetWidth))
        {
          d.style.top = (y + yoff) - 45; 
          d.style.left = mWidth;
        }
        else
        {
          d.style.top = (y + yoff)  - 45; 
          d.style.left = x +10;
        }
    }
  
    function hideDiv(d)
    {
        var style2 = document.getElementById(d).style;
        style2.display = "none";
  
    }

    function showDiv(d)
    {
        var style2 = document.getElementById(d).style;
        style2.display = "block";
   
  
    }
  
    function setDiv(d,style)
    {
        var style2 = document.getElementById(d).style;
        style2.display = style;


    }
  
    function getCookie(name) 
    {
        var theCookies = document.cookie.split(/[; ]+/);
        for (var i = 0 ; i < theCookies.length; i++) {
            var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));
            if (aName == name) {
                    return theCookies[i];
            }
        
        
        }
    }
    //this function will only work if the cookie data has only one value 
    function getVar(cookieDetails,varName)
    {     
        //var theVars = cookieDetails.indexOf(varName)
        /*for(var j= 0;j < theVars.length;j++)
        {
            if (theVars[j] == varName)
            {
                return theVars[j+1];
            }

        }*/
        var cd = cookieDetails.toUpperCase();
        var vn = varName.toUpperCase();
        
        
        return cookieDetails.substring(cookieDetails.indexOf('=',cd.indexOf(vn))+1,cd.length);
    }
  
    

function PopUpWindow(pageName1) { //v1.0
window.open(pageName1,"newwindow","toolbar=no,titlebar=1,scrollbars=1,location=no,directories=no,focus=true,status=no,menubar=no,resizable=yes,width=650,height=460,screenX=10,screenY=10,top=100,left=10,copyhistory=no,border=no,title='yes'");
}


//keepiing session alive


function sessionKeepAlive() {
 var wRequest = new Sys.Net.WebRequest();
 wRequest.set_url("/foodline/sitemain/pages/security/keepSessionAlive.aspx");
 wRequest.set_httpVerb("POST");
 wRequest.add_completed(sessionKeepAlive_Callback);
 wRequest.set_body('');
 wRequest.get_headers()["Content-Length"] = 0;
 wRequest.invoke();
}

// This callback function processes the
// request return values. It is called asynchronously
// by the current executor.
function sessionKeepAlive_Callback(executor, eventArgs)
{
        // No need to do anything, but if you are sending a value
        // from the server as an additional safety measure, then
        // you can check that here.
}
