function ajaxRequest() {
	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;
			}
		}
	}
	return xmlHttp;
}

function createQuery() {
    var elms, elm, Qstring = '', k = 0;
    elms = document.forms[0].elements;
    while( elm = elms[k++] ) {
        if( elm.name && elm.value ) {
            Qstring += elm.name + '=' + escape( elm.value ) + '&';
		}
	}
    return Qstring.replace( /&$/, '' );
}

function sendPost( con, action ) {
	if( con != null )
		var container = document.getElementById( con );
	var xmlHttp = ajaxRequest();
	showElement( 'ajaxLoading' );
	xmlHttp.onreadystatechange = function() {
		if( xmlHttp.readyState == 4 ) {
			showElement( con );
			if( container )
				container.innerHTML = xmlHttp.responseText;
			hideElement( 'ajaxLoading' );
		}
	}
	xmlHttp.open( "POST", action, true );
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	var querySTR = createQuery();
	xmlHttp.send( querySTR );
}

function getData( con, source ) {
	var xmlHttp = ajaxRequest();
	if( con != null )
		var container = document.getElementById( con );
	showElement( 'ajaxLoading' );
	xmlHttp.onreadystatechange = function() {
		if( xmlHttp.readyState == 4 ) {
			showElement( con );
			if( container )
				container.innerHTML = xmlHttp.responseText;
			hideElement( 'ajaxLoading' );
		}
	}
	xmlHttp.open( "GET", source, true );
	xmlHttp.send( null );
}

function showElement( id ) {
	document.getElementById( id ).style.display = 'block';
}

function hideElement( id ) {
	document.getElementById( id ).style.display = 'none';
}

function opacity( id, opacStart, opacEnd, millisec ) {
    //speed for each frame
    var speed = Math.round( millisec / 100 );
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if( opacStart > opacEnd ) {
        for( i = opacStart; i >= opacEnd; i-- ) {
            setTimeout( "changeOpac( " + i + ",'" + id + "' )",( timer * speed ) );
            timer++;
        }
    } else if( opacStart < opacEnd ) {
        for( i = opacStart; i <= opacEnd; i++ ) {
            setTimeout( "changeOpac( " + i + ",'" + id + "' )",( timer * speed ) );
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac( opacity, id ) {
    var object = document.getElementById( id ).style;
    object.opacity = ( opacity / 100 );
    object.MozOpacity = ( opacity / 100 );
    object.KhtmlOpacity = ( opacity / 100 );
    object.filter = "alpha( opacity=" + opacity + " )";
}
