// branch for native XMLHttpRequest object
var req;
function makeXMLHTTP(){
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} 
		catch(e) {
			req = false;
		}
	} 
	// branch for IE/Windows ActiveX version
	else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e) {
				req = false;
			}
		}
	}
}

function processReqGetInfo() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			//actions if any
			document.getElementById("info").innerHTML = req.responseText
			//alert(req.responseText);
		} 
	}
}

/***********************************************
* this function will process a form and submit
* the fields onto an AJAX results page GET method
* 
* you must include a hidden field <form onSubmit="getInfo(this);">
* and use this form tag <input type="hidden" id="ToForm" name="ToForm" value="FormStart.asp">
***********************************************/

function getInfo(f) {
	qString = getFormValues(f);
	//alert(qString);
	theForm = document.getElementById("ToForm").value;
	
	//alert(document.getElementById("ToForm").value);
	
	document.getElementById("info").innerHTML = '<br /><br /><blink>Processing... Please Wait....</blink><br /><br />';
	makeXMLHTTP();  
	url = theForm + '?' + qString;
	if(req) {
		//alert(url);
		req.onreadystatechange = processReqGetInfo;
		req.open("GET", url, true);
		req.send(null);
		
	}
}

/***********************************************
* this function will process a form and submit
* the fields onto an AJAX results page POST method
* 
* you must include a hidden field <form onSubmit="getInfo(this);">
* and use this form tag <input type="hidden" id="ToForm" name="ToForm" value="FormStart.asp">
*
* This function depends on you also includingthe prototype.js libraries
* <script type="text/javascript" src="/includes/prototype.js"></script>
***********************************************/

function postInfo(f) {
	qString = Form.serialize(f) + '&';
	
	theForm = document.getElementById("ToForm").value;	
	document.getElementById("info").innerHTML = '<br /><br /><blink>Processing... Please Wait....</blink><br /><br />';
	makeXMLHTTP();  
	
	url = theForm;
	if(req) {
		req.onreadystatechange = processReqGetInfo;
		req.open("POST", url, true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		req.send(qString);
		
	}
}

/***********************************************
* this function replaces hyper links use it to AJAX link the content with no page reload
* Example: <a href="JavaScript: getLink('Form.asp?ID=66');">
***********************************************/

function getLink(url) {
	makeXMLHTTP();  
	if(req) {
		//alert(url);
		req.onreadystatechange = processReqGetInfo;
		req.open("GET", url, true);
		req.send(null);
	}
}
			
			
/***********************************************
* This code scans a form for all fields
* It gathers them into a string ready to append
* to an URL for GET method submission
***********************************************/
	
function getFormValues(fobj){
    var str='';
    for(var i=0;i< fobj.elements.length;i++){
        str+=fobj.elements[i].name+'='+ escape(fobj.elements[i].value)+'&';
    }
    str=str.substr(0,(str.length-1));
    return str;
}



function getFormValuesSUSPISCIOUSVERSION(fobj,valFunc)
{
   var str = "";
   var valueArr = null;
   var val = "";
   var cmd = "";
   for(var i = 0;i < fobj.elements.length;i++)
   {
       switch(fobj.elements[i].type)
       {
           case "text":
                if(valFunc)
                {
                    //use single quotes for argument so that the value of
                    //fobj.elements[i].value is treated as a string not a literal
                    cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
                    val = eval(cmd)
                }
                str += fobj.elements[i].name +
                 "=" + escape(fobj.elements[i].value) + "&";
                 break;
           case "select-one":
                str += fobj.elements[i].name +
                "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
                break;
       }
   }
   str = str.substr(0,(str.length - 1));
   return str;
}


/***********************************************
* Ajax Includes script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//To include a page, invoke ajaxinclude("afile.htm") in the BODY of page
//Included file MUST be from the same domain as the page displaying it.

var rootdomain="http://"+window.location.hostname

function ajaxinclude(url) {
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
	try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
	} 
	catch (e){
	try{
		page_request = new ActiveXObject("Microsoft.XMLHTTP")
	}
	catch (e){}
	}
	}
else
	return false
	page_request.open('GET', url, false) //get page synchronously 
	page_request.send(null)
	writecontent(page_request)
}

function writecontent(page_request){
	if (window.location.href.indexOf("http")==-1 || page_request.status==200){
		document.write(page_request.responseText)
	}
}
