/**
 *  --------------------------------------------------------------------------------------
 *  Navigator Scripts
 *  ----------------------------------------------------
 *  Modified	April 12, 2010
 *  @version	1.0.0
 *  @author	Chris Donalds <chrisd@navigatormm.com>
 *  ----------------------------------------------------
 *  --------------------------------------------------------------------------------------
 */

function ajaxfunction(pageid){
	var ajaxRequest;  // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	}catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e) {
			try{
		 		ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
		 		// Something went wrong
		 		alert("Your browser failed to handle the AJAX code!");
		 		return false;
			}
		}
	}

	// Create a function that will receive data
	// sent from the server and will update
	// element in the same page.
	ajaxRequest.onreadystatechange = function(){
        //alert(ajaxRequest.readyState);
		if(ajaxRequest.readyState == 4){
            var response = ajaxRequest.responseText;
            var content = response.split("||");

            // content[0] = img
            // content[1] = title
            // content[2] = excerpt
            // content[3] = brands
            //alert(response);
            var imgdiv = document.getElementById('ajax-image');
            imgdiv.innerHTML = content[0];
            var titlediv = document.getElementById('ajax-title');
            titlediv.innerHTML = content[1];
            var excerptpara = document.getElementById('ajax-excerpt');
            excerptpara.innerHTML = content[2];
            var branddiv = document.getElementById('ajax-brands');
            branddiv.innerHTML = content[3];
			return;
		}
	}

	// Now get the value from user and pass it to the server ajaxprocessor.
	var host = window.location.hostname;
    if(host == 'macdermottsonbernard.nav' || host == 'stonehenge' || host == 'badger' || host == 'www.navigatordns.com' || host == 'www.navigatormultimedia.com'){
        var fpath = window.location.pathname;
        var parts = fpath.split('/');
        var dir  = 'http://'+host+'/'+parts[1];
    }else{
        dir = '';
    }
	//var srcval = document.getElementById(srcobj).value;
	var queryString = "?pageid=" + pageid;
    //alert(dir+"wp-content/themes/macdermotts/ajaxprocessor.php"+queryString);

	try {
		ajaxRequest.open("GET", dir + "wp-content/themes/macdermotts/ajaxprocessor.php" + queryString, true);
		ajaxRequest.send(null);
	}
	catch (e) {
		alert("There was a problem accessing the AJAX processor.");
	}
}



