//=====================================================================||
//             Education Design Showcase General Include               ||
//                                                                     ||
// This JS should be included on all EDS.com pages, and contains only  ||
// shared functions that may be called from most any page.             ||
//                                                                     ||
// Portions of this script are used with permission from the NOP Design||
// Free-Shopping Cart, located at http://www.nopdesign.com/freecart    ||
//                                                                     ||
//=====================================================================||

function SetParentBg(pHrefObj, strColor)
{
    if( pHrefObj ) {
       var pParent = pHrefObj.parentNode;
       if( pParent ) {
          if( pParent.style ) {
             pParent.style.backgroundColor = strColor;
          }
       }
    }
}


function EdsNavSwap(strImgId, strUrl)
{
   if( document.getElementById ) {
      pImg = document.getElementById(strImgId);
      if( pImg ) {
         pImg.src = strUrl;
      }
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    FallBackPopup                                          ||
// PARAMETERS:  Url, width of popup, height of popup                   ||
// RETURNS:     False on popup successfull                             ||
// PURPOSE:     Create popup, or go to URL ere appropriate             ||
//---------------------------------------------------------------------||
function FallBackPopup( strUrl, iWidth, iHeight )
{
   wind=window.open(strUrl,'','width='+iWidth+',height='+iHeight+',resizable=yes,scrollbars=yes,status=yes');
   if ( wind ) return false;

   return true;
}



//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();

   date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}


//---------------------------------------------------------------------||
// FUNCTION:    SetCookie                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain) {
   if ( GetCookie(name) ) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    UrlDecode                                              ||
// PARAMETERS:  String to url decode                                   ||
// RETURNS:     Decoded string                                         ||
// PURPOSE:     Returns plain text string urldecoded.                  ||
//---------------------------------------------------------------------||
function UrlDecode(strEncodeString) 
{
  var lsRegExp = /\+/g;
  return unescape(String(strEncodeString).replace(lsRegExp, " ")); 
}

//---------------------------------------------------------------------||
// FUNCTION:    QueryString                                            ||
// PARAMETERS:  Key to read                                            ||
// RETURNS:     value of key                                           ||
// PURPOSE:     Read data passed in via GET mode                       ||
//---------------------------------------------------------------------||
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString(key) {
   var value = null;
   for (var i=0;i<QueryString.keys.length;i++) {
      if (QueryString.keys[i]==key) {
         value = QueryString.values[i];
         break;
      }
   }
   return value;
}


//---------------------------------------------------------------------||
// FUNCTION:    QueryString_Parse                                      ||
// PARAMETERS:  (URL string)                                           ||
// RETURNS:     null                                                   ||
// PURPOSE:     Parses query string data, must be called before Q.S.   ||
//---------------------------------------------------------------------||
function QueryString_Parse() {
   QueryString.keys = new Array();
   QueryString.values = new Array();
   var query = window.location.search.substring(1);
   var pairs = query.split("&"); 
   for (var i=0;i<pairs.length;i++) {
      var pos = pairs[i].indexOf('=');
      if (pos >= 0) {
         var argname = pairs[i].substring(0,pos);
         var value = pairs[i].substring(pos+1);
         QueryString.keys[QueryString.keys.length] = argname;
         QueryString.values[QueryString.values.length] = value;
      }
   }
}




//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
   dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   return(dollars + "." + cents);
}

var g_strLargePhotoUrl = '';
//---------------------------------------------------------------------||
// FUNCTION:    ShowLargePhoto                                         ||
// PARAMETERS:  Name of photo in document                              ||
// RETURNS:     N/A                                                    ||
// PURPOSE:     Create image popup                                     ||
//---------------------------------------------------------------------||
function ShowLargePhoto( strId )
{
   pImg = document.getElementById(strId);
   if( pImg ) {
      if( pImg.src ) {
         var pWinPop = window.open('', 'largeImage', 'width=660,height=580,resizable=1,scrollbars=auto');
         if( pWinPop ) {
            if( g_strLargePhotoUrl != '' ) pWinPop.document.write('<p align=center><img src="'+g_strLargePhotoUrl+'"></p><p align=center>');
            else pWinPop.document.write('<p align=center><img src="'+pImg.src+'"></p>');
            pWinPop.document.write('<center><a href="Javascript:window.close()"><font face="arial,helvetica">Close Window</font></a></center>');
         }
      }
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    EraAzQuickSwap                                         ||
// PARAMETERS:  N/A                                                    ||
// RETURNS:     True if photo could NOT be swapped                     ||
// PURPOSE:     Swaps out photo without forcing page load.             ||
//---------------------------------------------------------------------||
function EdsQuickSwap( strNewPhoto, strFullSize )
{
   var bReturn = true;
   if ( document.mainphoto ) {
      if ( document.mainphoto.src ) {
         document.mainphoto.src = strNewPhoto;
         g_strLargePhotoUrl = strFullSize;
         bReturn = false;
      }
   }
   return bReturn;
}

