
var PHP = new Object();  // global to place data going to/from php

function brainkrash_wddx_deserialize()
{
  var MyWDDX = new WddxDeserializer;

  MyWDDX.preserveVarCase = true;
  PHP = MyWDDX.deserialize(getDocumentObject("JS_WDDX").value);
}

function brainkrash_wddx_serialize()
{
  MyWDDX = new WddxSerializer();
  wddxPacket = MyWDDX.serialize(PHP);

  if (wddxPacket != null)
  {
    document.forms[0].PHP_WDDX.value = wddxPacket;
    alert(document.forms[0].PHP_WDDX.value);
  }
  else
    alert("Couldn't wddx serialize data");
}

/* Function that handles the breadcrumb navigation. */
function breadCrumbs(base, delStr, defp, cStyle, tStyle, dStyle, nl)
{
  loc = window.location.toString();
  subs = loc.substr(loc.indexOf(base) + base.length - 1).split("/");
  document.write("<a href=\"" + getLoc(subs.length - 1) + defp + "\" class=\"" + cStyle + "\">Home</a>  " + "<span class=\"" + dStyle + "\">" + delStr + "</span> ");
  a = (loc.indexOf(defp) == -1) ? 1 : 2;

  for (i = 0; i < (subs.length - a); i++)
  {
    if (subs[i].indexOf("?") > 0)
      subs[i] = subs[i].substr(0, subs[i].indexOf("?"));

    if (subs[i].indexOf(".") > 0)
      subs[i] = subs[i].substr(0, subs[i].indexOf("."));

    subs[i] = makeCaps(unescape(subs[i]));
    document.write("<a href=\"" + getLoc(subs.length - i - 2) + defp + "\" class=\"" + cStyle + "\">" + subs[i] + "</a>  " + "<span class=\"" + dStyle + "\">" + delStr + "</span> ");
  }

  if (nl == 1)
      document.write("<br>");

  document.write("<span class=\"" + tStyle + "\">" + document.title + "</span>");
}

function go(where) {
  /* A javascript method for posting the page the a new location */
  document.forms[0].action=where;
  document.forms[0].method="POST";
  document.forms[0].submit();
}

function goGet(where) {

  document.location.href = where;
}

function goGetFromIndex(where)   //added by Param on 06-29-06 for popup window generation
{ 
 document.frmIndex.hButton.value=1;  
 document.location.href = where;
}

function goGetFormSafe(where,index) {

var query = '';
if(index ==1){ 
document.frmIndex.hButton.value=1;         //for generating popup window for index page by Param on 06-28-06
}

  if (document.forms[0]) {
    if (where.indexOf('?') != -1) { where += '&' }

    for(i=0; i < document.forms[0].elements.length; i++) {
      if (document.forms[0].elements[i].name.indexOf('FDC_') == 0) {
        switch(document.forms[0].elements[i].type) {
          case 'radio': // checked
          case 'checkbox':  // checked
            if (document.forms[0].elements[i].checked) {
              query += document.forms[0].elements[i].name+'='+document.forms[0].elements[i].value+'&'
            }
            break;

          case 'select-one': // selection
            query += document.forms[0].elements[i].name+'='+document.forms[0].elements[i].selectedIndex+'&';
            break;
          default:
            if (document.forms[0].elements[i].value) {
              query += document.forms[0].elements[i].name+'='+document.forms[0].elements[i].value+'&';
			  
            }
            break;
        }
      }
    }

    if (query) { query += 'formsafe=1'; }
  }

  goGet(where+query);
}

function doFormSafe() {
  var search = document.location.search.substring(1);
  var params = search.split('&');

  for(i=0; i < params.length; i++) {
    if (params[i].indexOf('FDC_') == 0) {
      var keyval = params[i].split('=');
      var obj = getDocumentObject(keyval[0]);

      if (obj.length > 1) {
        if (obj[0].type == 'radio' || obj[0].type == 'checkbox') {
          for(x=0; x < obj.length; x++) {
            if (obj[x].value == keyval[1]) {
              obj[x].checked = true;
            }
          }
        } else if (obj.type == 'select-one') {
          obj.selectedIndex = keyval[1];
        }
      } else {
        obj.value = unescape(keyval[1]);
      }
    }
  }
}

function smartWindow(html, restricted, width, height, centered)
{
  var agt        = navigator.userAgent.toLowerCase();
  var is_major   = parseInt(navigator.appVersion);
  var is_minor   = parseFloat(navigator.appVersion);
  var is_nav     = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                   && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                   && (agt.indexOf('webtv')==-1));
  var is_nav3    = (is_nav && (is_major == 3));
  var is_nav4up  = (is_nav && (is_major >= 4));
  var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
  var is_ie      = (agt.indexOf("msie") != -1);
  var is_ie3     = (is_ie && (is_major < 4));
  var is_ie4     = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
  var is_ie4up   = (is_ie  && (is_major >= 4));
  var is_ie5     = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
  var is_ie5up   = (is_ie  && !is_ie3 && !is_ie4);
  var is_aol     = (agt.indexOf("aol") != -1);
  var is_aol3    = (is_aol && is_ie3);
  var is_aol4    = (is_aol && is_ie4);
  var now  = new Date();
  var winname = now.getTime();
  var winParams = "";
  var left = Math.floor( (screen.width - width) / 2);
  var top = Math.floor( (screen.height - height) / 2);

  if (width > 0)
    winParams += "width="+width+",";

  if (height > 0)
    winParams += "height="+height+","

  if (restricted == true)
    winParams +="scrollbars=no,resizable=no,";

  if (centered == true)
    winParams += "left="+left+","+"top="+top+",";

  if (winParams.charAt(winParams.length-1) == ',')
    winParams = winParams.substring(0, winParams.length-1);

  if (html.substr(0,14) == "http://http://")
    html = html.substr(7);

  if (is_nav3 || is_nav4up)  {
    win1 = window.open(html,""+winname, winParams)
    win1.focus()
  }
  else if (is_ie4up) {
    win1 = window.open(html,""+winname, winParams)
    win1.focus()
  }
  else
    window.open(html,""+winname, winParams);
}

function makeRemote(where) {
  remote = window.open("","","width=322,height=242,scrollbars=no");
  remote.location.href = where;
}

function deleteItem(dtype, dname) {
  return(confirm('Are you sure you want to delete the '+dtype+', '+dname+'?  Press OK to delete.'));
}

function getDocumentObject(id) {
  if (document.all) {
    return(document.all.item(id));
  } else if (document.getElementById) {
    return(document.getElementById(id));
  } else if (document.layers) {
    return(eval("document."+id));
  } else {
    return null;
  }
}

/** GENERIC IMAGE ROLLOVER FUNCTIONS **/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function roundAccuracy(num, accuracy){
    var factor=Math.pow(10,accuracy);
    return Math.round(num*factor)/factor;
}
