/**
 * @author user2
 */

function getImgSize(imgSrc){
    var newImg = new Image();
    newImg.src = imgSrc;
    var height = newImg.height;
    var width = newImg.width;
    var width_height = (newImg.width + 50) + ',' + (newImg.height + 250);
    return width_height;
}

function fnRestart(){
	location.hash='top';
	location.reload();
}

function fnMapNew(airportcode, airportname){
	var options = 'status=1,location=0,menubar=0,resizable=1,'+'width=' + 770 + ',height=' + 675;
    oMapWindow = window.open("/themes/aac_tropical_green/locationmap.html?"+airportcode+"&"+airportname, 'alohacargomap',options);
}

/* AJAX Functions */
function createRequestObject(){
    var ro;
    var browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer") {
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function post_form(form_id){
	transitionPage();
	var oForm = document.getElementById(form_id);
	var sBody = getRequestBody(oForm);
	//alert (sBody);
	var oXmlHttp = http; 
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				view(oXmlHttp.responseText);
			}
			else {
				view("An error occurred: " + oXmlHttp.statusText);
			}
		}
	};
	oXmlHttp.send(sBody);
}

function getRequestBody(oForm) {
	var aParams = new Array();
	//alert(oForm.elements.length);
	for (var i=0 ; i < oForm.elements.length; i++) {
		var sParam = encodeURIComponent(oForm.elements[i].name);
		sParam += "=";
		if((oForm.elements[i].type=="checkbox") && (!oForm.elements[i].checked)){
			sParam += "false";
		}
		else {
			sParam += encodeURIComponent(oForm.elements[i].value);
			aParams.push(sParam);
		}

	}
	return aParams.join("&");
}

function view(sText){
	if (sText.indexOf('id=SUCCESS') != -1) {
        var el = document.getElementById("mainprocessor");
    	el.innerHTML = sText;
    }
    else {
         var e2 = document.getElementById("mainerror");
    	 e2.innerHTML = sText;
    }
	document.getElementById("mainprocessor").style.display ="block";
	document.getElementById("transition").style.display ="none";
}

function transitionPage(){
		document.getElementById("mainprocessor").style.display ="none";
		document.getElementById("transition").style.display ="block";
}

function centerTransitionPage(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#transition").height();
	var popupWidth = $("#transition").width();
	    
	//centering
	$("#transition").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
}