//##########################################################
//##                                                                       
//##  SENDITNOW AJAX scripts to load banner on index.epl 
//##  (c) 2007 Neopost Loop One
//##  Coding and Documentation by Austin Programming Solutions (APS)       
//##  Core Developers: Kevin Ludlow (ludlow@aps-tx.com) and                
//##                   Travis Huber (thuber@aps-tx.com)                    
//##                                                                       
//##  The following software/script was designed and written for           
//##  Neopost Loop One as a work for hire.                                       
//##                                                                       
//##  No portion of this script may be duplicated, sold, distributed,      
//##  or otherwise used without the owner's explicit written consent.      
//##                                                                       
//##  FILE:      sinjax.js                                          
//##  CREATED:   March 8, 2007                                              
//##  DEVELOPER: Travis Huber                                              
//##                                                                       


// This listen function is an easy way to add event handlers.
function listen(evt,func)
{
    if(document.addEventListener) {
        window.addEventListener(evt,func,true);
    } else if(document.attachEvent) {
        window.attachEvent("on"+evt,func);
    }
}

  
// xmlLoad handles our ajax requests.
// doc = the name of the file to request server-side
// elem = the element to update with the result.
function xmlLoad(doc,elem) {
  // xmlDoc is our global var for the ajax request.
  var xmlDoc = null ;
  if (typeof window.ActiveXObject != 'undefined' ) {
    xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else {
    xmlDoc = new XMLHttpRequest();
  }
  //alert('doc is ' + doc);
  xmlDoc.open( "GET", doc, false);
  xmlDoc.send( null );

  return(xmlDoc.responseText);
}

function processXML(data,elem) {

  if(typeof elem == 'string') {
    elem = document.getElementById(elem);
  }

  var regexp = new RegExp("\\w");

  if(data.match(regexp))
  {
    try {
      elem.innerHTML = data;
      elem.style.display='block';
    } catch (e) {
      //don't know how to handle this error yet.
      //problems arise when people use MSO html
      //and IE simply fails on setting innerHTML.
    };
  }
}

function processPricing(data) {
  
  var prices = data.split('|');

  document.getElementById('price_next_day_noon').innerHTML = prices[0] || "14.99";
  document.getElementById('price_next_day').innerHTML      = prices[1] || "11.99";
  document.getElementById('price_two_days').innerHTML      = prices[2] || "10.99";
  
}

function init_welcome()
{
   //processXML(xmlLoad('senditnow_welcome.epl'),'welcome_text');
   processPricing(xmlLoad('senditnow_prices.epl'));   
}

function init_prices()
{
    processXML(xmlLoad('senditnow_prices_whatwedo.epl'),'whatwedo_prices');   
}

function init_ship()
{
    document.getElementById("agree").checked = false;
    processXML(xmlLoad('senditnow_ship.epl'),'ship_content');
}

function goto(page) 
{
  if (page) {
    document.location.href=page; 
  }   

  return(false);
}

function proceedToShip() 
{
  
  if(!document.getElementById("agree").checked) {
    alert('You must agree to our terms and conditions before proceeding.');
    return(false);
  }       

  return goto('shipping.epl');

}

