var req, req2;
var divID, divID2;
function loadXMLDoc( url, dID ) 
{
	divID = dID;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);

	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send();
			}
	}
}

function processReqChange() 
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
     			response  = req.responseText;
     			if( document.getElementById( divID).innerHTML )
	   				document.getElementById( divID ).innerHTML = response;
	   			else
	   				document.getElementById( divID ).value = response;
        } else {
            document.getElementById(divID).innerHTML = "Problem retrieving information: " + req.status + " " + req.statusText;
        }
    }
}

function loadXMLDoc2( url, dID, url2, dID2 ) 
{ 
	divID = dID;
	divID2 = dID2;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);

		req2 = new XMLHttpRequest();
		req2.onreadystatechange = processReqChange2;
		req2.open("GET", url2, true);
		req2.send(null);

	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send();
			}
			req2 = new ActiveXObject("Microsoft.XMLHTTP");
			if (req2) {
				req2.onreadystatechange = processReqChange2;
				req2.open("GET", url2, true);
				req2.send();
			}

	}
}


function processReqChange2() 
{
    // only if req shows "complete"
    if (req2.readyState == 4) {
        // only if "OK"
        if (req2.status == 200) {
     			var response  = req2.responseText;
     			if( document.getElementById( divID2).innerHTML )
	   				document.getElementById( divID2 ).innerHTML = response;
	   			else
	   				document.getElementById( divID2 ).value = response;
        } else {
            document.getElementById(divID2).innerHTML = "Problem retrieving information: " + req2.status + " " + req2.statusText;
        }
    }
}


/*
---------------------------------------------------------------------------

 * 	This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2, or (at your option)
 *      any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program (see the file COPYING); if not, write to the
 *      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *      Boston, MA  02111-1307, USA
 
 	This code is copyright 2003 by Matthew Eernisse
 
---------------------------------------------------------------------------	
*/ 

function formData2QueryString( docForm ) {

	if ( !docForm ) docForm = document.forms[0];
	var strSubmitContent = '';
	var formElem;
	var strLastElemName = '';
	
	for (i = 0; i < docForm.elements.length; i++) {
		
		formElem = docForm.elements[i];
		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
				strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				break;
				
			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				}
				break;
				
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == strLastElemName) {
						// Strip of end ampersand if there is one
						if (strSubmitContent.lastIndexOf('&') == strSubmitContent.length-1) {
							strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
						}
						// Append value as comma-delimited string
						strSubmitContent += ',' + escape(formElem.value);
					}
					else {
						strSubmitContent += formElem.name + '=' + escape(formElem.value);
					}
					strSubmitContent += '&';
				}
				break;
				
		}
		strLastElemName = formElem.name
	}
	
	// Remove trailing separator
	strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
	return strSubmitContent;
}


function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}

function load2XMLDocs( url, div, url2, div2 ) {
	return load2XmlDocs( url, div, url2, div2 );
}

function load3XMLDocs( url, div, url2, div2, url3, div3 ) {
	return  load3XmlDocs( url, div, url2, div2, url3, div3 );
}

function load2XmlDocs( url, div, url2, div2 ) {
// requires prototype.js
new Ajax.Updater( div, url,
	{
		evalScripts:true,
		asynchronous:true,
		onComplete: function( element ) {
			new Ajax.Updater( div2,
				url2,
				{
					evalScripts:true,
					asynchronous:true
				}
			)
		}
	}
 );
}

function load3XmlDocs( url, div, url2, div2, url3, div3 ) {
// requires prototype.js
new Ajax.Updater( div, url,
	{
		evalScripts:true,
		asynchronous:true,
		onComplete: function( element ) {
			new Ajax.Updater( div2,
				url2,
				{
					evalScripts:true,
					asynchronous:true,
					onComplete: function( element ) {
					new Ajax.Updater( div3,
						url3,
						{
							evalScripts:true,
							asynchronous:true
						}
					)
				}

				}
			)
		}
	}
 );
}

function replaceQuote(curLoc,state) {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        var addQuote = document.getElementById("addQuote");
        var removeQuote = document.getElementById("cancelQuote");
	      document.getElementById("quoteBox").innerHTML=xmlHttp.responseText;
        if (state == 1) {
        	addQuote.style.display = "none";
        	removeQuote.style.display = "block";
        } else {
        	addQuote.style.display = "block";
        	removeQuote.style.display = "none";
        }
        }
      }
    xmlHttp.open('GET','/?replaceQuoteWithEdit@@!loc=' + curLoc + '&state=' + state,true);
    xmlHttp.send(null);
  }

