/*
 * Image preloader per controllo stato server	
 * 
 */
//var remoteURI = "http://212.239.25.41/fideuram_test/";
//var remoteURI = "http://fideuram.ogilvy.it/FIDhomepage/";
//var remoteURI = "http://dev.fideuram.it/FIDhomepage/";
var remoteURI = "http://info.bancafideuram.it/FIDhomepage/";


var attemptCount = 0;

checkServerStatusAndLoadFrame = function(){
	var noCache = "?"+(new Date()).getTime();
	window.status='Checking Fideuram website...';
	image = new Image();
	image.src = remoteURI + "status.jpg"+noCache;
	imageIsLoaded(image);
}

loadErrorPages = function(){
	window.status='Check failed.';
	//alert('Il server non risponde correttamente');	
	$("header_frame").src ='./pages/courtesy_page.html';
	$("middle_frame").src ='./pages/courtesy_page_middle.html';
	$("middle_frame").appear();
	//$("ajax-loader").hide();
	$("header_frame").appear();
	$("footer").hide()
			$('phiLinkOn').hide()
	$('phiLinkOff').show()
	$('servLinkOn').hide()
	$('servLinkOff').show()
}

imageIsLoaded = function(image){
	if(image.complete){
		if(serverHealtIsGood(image)){
			window.status='Loading Fideuram iframes';
			loadFrames();
		}else{
			loadErrorPages();
		}		
	}else{
		if(attemptCount++ < 3)
			setTimeout("imageIsLoaded(image)", 1000);
		else
			loadErrorPages();
	}
		
}

var timeout = 0;

loadHeader = function() {
	$("header_frame").src = remoteURI + "remote_header.cfm";
	$("header_frame").appear();
	setTimeout('loadMiddle()',timeout);
}

loadMiddle = function() {
	$("middle_frame").src = remoteURI + "remote_middle.cfm";
	$("middle_frame").appear();
	setTimeout('loadCommunication()',timeout);
}

loadCommunication = function() {
	$("comunication_frame").src = remoteURI + "remote_comunication.cfm";
	$("comunication_frame").appear();
	$("headerTopMenu").appear();

}

loadFrames = function(){
	/*
	$("header_frame").src = remoteURI + "remote_header.cfm";
	$("middle_frame").src = remoteURI + "remote_middle.cfm";
	$("comunication_frame").src = remoteURI + "remote_comunication.cfm";
	//$("ajax-loader").hide(); //({ queue: 'front' });
	$("header_frame").appear();
	$("middle_frame").appear();
	$("comunication_frame").appear();
	*/
	setTimeout('loadHeader()',timeout);
}


/*
 * null            =   sqlserver and coldfusion are down
 * 01 (1x1 image)  =   sqlserver is down and coldfusion is running
 * 10 (1x2 image)  =   sqlserver is running but coldfusion is down (it's impossible get this image...)
 * 11 (1x3 image)  =   sqlserver and coldfusion are up and running
 */

serverHealtIsGood = function(image){
	if(image.width == 3)
		return true;
	return false;
}
