/**
 * DOM Functions to correct IE6 behavior
 */
function DOMappendElement( parent , child ) {
	try {
		parent.appendChild(child, null); // standards compliant; doesn't work in IE
	} catch(ex) {
		parent.appendChild(child); // IE only
	}
}
function DOMaddEventListener( el, ev, f ) {
	if( el.addEventListener ) {
		el.addEventListener(ev, f ,false);
	} else if( el.attachEvent ) {
		el.attachEvent('on'+ev, f );
	}
}
function DOMaddElement( parent , child ) {
	try {
		parent.add(child, null); // standards compliant; doesn't work in IE
	} catch(ex) {
		parent.add(child); // IE only
	}
}

/**
 * Function to load any file into any element
 */
var xmlhttp = null;
function loadFile( file , objid , params , callback ) {

	// Clear object first
	document.getElementById(objid).innerHTML = '';

	// Set loading animation in object
	document.getElementById(objid).innerHTML = '<img id="loading" src="/files/website/img/occasions/vehicle_loading.gif" />';

	// Create new object
	xmlhttp = getXmlHttp();

	// Open object
	xmlhttp.onreadystatechange = function() {
		if ( xmlhttp.readyState == 4 ) {
			if ( xmlhttp.status == 200 ) {
				// Load HTML into object
				document.getElementById(objid).innerHTML = xmlhttp.responseText;
				if ( typeof(callback) == 'function' ) callback();
			}
		}
	};
	//if(console) console.log( file + '&' + params );
	if( params == null || params == '' ) {
		xmlhttp.open( 'GET' , file , true );
		xmlhttp.send( null );
	} else {
		xmlhttp.open( 'POST' , file , true );
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send( params );
	}

}

/**
 * Function to create and return a new XMLHTTP object
 */
function getXmlHttp() {
	if ( window.XMLHttpRequest ) { // code for IE7+, Firefox, Chrome, Opera, Safari
		var xhr = new XMLHttpRequest();
	} else { // code for IE6, IE5
		var xhr = new ActiveXObject( 'Microsoft.XMLHTTP' );
	}
	return xhr;
}
