

function handleResponseSelect(selectName,doc) {

	// Rebuilds a STATE/PROVINCE/TERRITORY select list on the element named by selectName wkithin a form named 'address'

	// List is rebuilt using the contents in a <div> supplied in the passed in doc

	

	// Get a reference to the target selectName select list, which we will populate

	// with the data from the document loaded in the doc

	var selectNameEl = document.forms['address'].elements[selectName];



	// clear earlier records from the thing select list

	selectNameEl.length = 0

	

	// Get a reference to the DIV containing the data for this state

	//var dataEl = doc.getElementById('selectName')

	if (!doc.getElementById(selectName)) {return false}; // not fatal, just means the for some reason no state data was returned

	var dataEl = doc.getElementById(selectName)

	//alert('selectName: '+selectName)

		

	// Get a reference to the collection of the children elements of

	// our DIV containing the data (this collection is the DIVs containing

	// the STATE names)

	

	var namesColl = dataEl.childNodes

	

	// For easy scripting, assign the number of things for this type

	// to a variable

	var numNames = namesColl.length

	//alert('number of things ' + numNames)

	

	// Iterate through the collection of STATE abreviations and

	// create an option element for each one, marking the first one as selected in the pulldown

	var first = true;

	for (var q=0; q<numNames; q++) {

		if (namesColl[q].nodeType!=1) continue; // it's not an element node, let's skedaddle

		var stateAbrev = '' // used to store the text we'll use in the new option

		stateAbrev += namesColl[q].id

		//alert ("type stateAbrev: "+stateAbrev)

		

		// Create a new option element and add it to the STATE form element

		//selectNameEl.options[selectNameEl.length] = new Option(stateAbrev,stateAbrev)

		// Make sure to mark the first in the list as "selected" so that the form carries

		// a pre-selected option.

		if (first) {

			selectNameEl.options[selectNameEl.length] = new Option(stateAbrev,stateAbrev,false,true);

			first = false;

		} else {

			selectNameEl.options[selectNameEl.length] = new Option(stateAbrev,stateAbrev,false,false);

		}

	}

}



function handleResponseLabel(labelName,doc) {

	// Sets or resets a label on a form whose name is 'labelName'

	//alert("client: handling type: "+labelName);

	if (!document.getElementById(labelName)) {return false}; // not fatal, just means the form doesn't use this lable



	var theLabelDiv = document.getElementById(labelName);

	//var label = document.forms['address'].elements[labelName];

	//alert("target for label update: "+theLabelDiv.innerHTML)



	// get a reference to the DIV containing the data for this label

	var dataEl = doc.getElementById(labelName);

	//alert('Label: '+dataEl.innerHTML);

	theLabelDiv.innerHTML = dataEl.innerHTML;

	//alert ('type: ' + labelName);

}



var IFrameObj; // our IFrame object

function callToServer(theFormName, theFormSourceType, theFormAddressType, urlPrefix, filter, includeANY) {

	// Refer to push_address_elements.php for more information.

	 if (!document.createElement) {return true};

	 var IFrameDoc;

	//alert(urlPrefix);

	// Make a call to a PHP script by creating a URL which contains various required values,

	// including the ID number of the country selected in the country pull down

	// (contained in the passed-in 'theFormSourceType' element).

	var sourceTypeEl = document.forms[theFormName].elements[theFormSourceType];

	//alert (sourceTypeEl);

	var theSource = sourceTypeEl.options[sourceTypeEl.selectedIndex].value



	if (theSource=='') {return false}; // no thing has been selected

	// Prepare the call to the PHP script via a carefully formatted URL

	//Example: 

	// If the SELECT element which was onChange'd was NAMEd 'countryID', and the underlying value

	// associated with the newly selected country was 840, and we are working on a billing-type address,

	// and we want to restrict the STATE select elements to include

	// only those states which are enabled for retailers, the we are looking at:

	// URL = push_address_elements.php?countryID=840&type=bill&filter=2

	var URL = urlPrefix + "push_address_elements.php?"+theFormSourceType+"="+theSource+"&type="+theFormAddressType+"&filter="+filter+"&includeANY="+includeANY;

	//alert(URL);



  if (!IFrameObj && document.createElement) {

    // create the IFrame and assign a reference to the

    // object to our global variable IFrameObj.

    // this will only happen the first time 

    // callToServer() is called

   try {

      var tempIFrame=document.createElement('iframe');

      tempIFrame.setAttribute('id','RSIFrame');

      tempIFrame.style.border='0px';

      tempIFrame.style.width='0px';

      tempIFrame.style.height='0px';

	  // rjs: set the source to the passed in urlPrefix so we don't see the "This page contains both secure and nonsecure items." message in IE6

	  tempIFrame.src = urlPrefix;

      IFrameObj = document.body.appendChild(tempIFrame);

      

      if (document.frames) {

        // this is for IE5 Mac, because it will only

        // allow access to the document object

        // of the IFrame if we access it through

        // the document.frames array

        IFrameObj = document.frames['RSIFrame'];

      }

    } catch(exception) {

      // This is for IE5 PC, which does not allow dynamic creation

      // and manipulation of an iframe object. Instead, we'll fake

      // it up by creating our own objects.

      iframeHTML='\<iframe id="RSIFrame" style="';

      iframeHTML+='border:0px;';

      iframeHTML+='width:0px;';

      iframeHTML+='height:0px;';

      iframeHTML+='"><\/iframe>';

      document.body.innerHTML+=iframeHTML;

      IFrameObj = new Object();

      IFrameObj.document = new Object();

      IFrameObj.document.location = new Object();

      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');

      IFrameObj.document.location.replace = function(location) {

        this.iframe.src = location;

      }

    }

  }

  

  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {

    // we have to give NS6 a fraction of a second

    // to recognize the new IFrame

    setTimeout('callToServer()',10);

    return false;

  }

  

  if (IFrameObj.contentDocument) {

    // For NS6

    IFrameDoc = IFrameObj.contentDocument; 

  } else if (IFrameObj.contentWindow) {

    // For IE5.5 and IE6

    IFrameDoc = IFrameObj.contentWindow.document;

  } else if (IFrameObj.document) {

    // For IE5

    IFrameDoc = IFrameObj.document;

  } else {

    return true;

  }



  document.body.style.cursor = 'wait' 

	//alert (URL);

  IFrameDoc.location.replace(URL);

  return false;

}



function clearCursor() {

	// Turn cursor back to pointer. It was set to hourglass in the originatating callToServer.	

	document.body.style.cursor = 'default' 

}



/* Not used

function buildQueryString(theFormName) {

  theForm = document.forms[theFormName];

  var qs = ''

  for (e=0;e<theForm.elements.length;e++) {

    if (theForm.elements[e].name!='') {

      qs+=(qs=='')?'?':'&'

      qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value)

      }

    }

  return qs

}

*/

