
var xmlHttp;



function GetXmlHttpObject(){

    var objXMLHttp = null;
    
    if (window.XMLHttpRequest){
        try{
            objXMLHttp = new XMLHttpRequest();
        }catch (e){
            objXMLHttp = false;
        }
    }else if (window.createRequest){
        try{
            objXMLHttp = new window.createRequest();
        }catch (e){
            objXMLHttp = false;
        }
    }else if (window.ActiveXObject){
        try {
            objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            try {
                objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e){
                objXMLHttp = false;
            }
        }
    }
    
    return objXMLHttp;
}





function getNearest(pc, tod, res, val){
		
		if(pc!=''){ // Has anything been entered?
			
			document.getElementById("pcresults" + res).innerHTML = '<img src="images/loading.gif" align="center" name="loading" alt="Loading..." width="20" height="20" />';
		        		            	
            		xmlHttp = GetXmlHttpObject();
        
        		if(xmlHttp == null){
            			alert("Browser does not support HTTP Requests.");
            			return;
        		}
                                	
        		var url = "railsearch.php?option=38&pc=" + pc + "&tod=" + tod + "&sl_size=1&varname=query" + val;
        	        
        		xmlHttp.open("GET", url, true)
        		xmlHttp.onreadystatechange = function(){
            			if(xmlHttp.readyState == 4){
            				document.getElementById("pcresults" + res).innerHTML = xmlHttp.responseText;
            				
            				// if both station select boxes are on screen then make the variable 'both' = 1 else 'both' = 0
            				//if(document.getElementById("pcresultsA").innerHTML !='' && document.getElementById("pcresultsB").innerHTML !='') nextPart();
            				
            			}
        		};
        		
	    		xmlHttp.send(null);
    		}else{
    	   	 	//jQuery("#choices").jAlert('Please enter a postcode.', "warning", 'warningboxid', 299);
    	 	}
}

