function openNewWindow(url, w, h)
{
	// open a blank window
	w = (w==null) ? 400 : w;
	h = (h==null) ? 450 : h;
	var aWindow = makePopup(url, '_blank', w, h, 'yes', 'yes');
};

function makePopup(pageURL, pageName, w, h, pageScroll, pageCenter)
{
	if(pageCenter == 'no')	{
		LeftPosition = 10;
		TopPosition = 10;
	} else {
		LeftPosition = (screen.width) ? (screen.width-w) / 2 : 0;
		TopPosition = (screen.height) ? (screen.height-h) / 2 : 0;
	};
	w = parseInt(w) + 18;
	h = parseInt(h) + 18;

	var pageConfig = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=' + pageScroll + ', resizable=yes, width=' + w + ', height=' + h + ', left=' + LeftPosition + ', top=' + TopPosition;
	var popup = window.open(pageURL, pageName, pageConfig);
	popup.focus();
	return popup;
};

function runPage(section, page, cmd, id, formName)
{
	
	$("#alert").hide();
	$("#loader-bg").show();
	$("#middle").fadeOut();
	$('#backtobox').hide();

	var postData = '';
	if(typeof formName == "string") {
		postData = $('#'+formName).serialize();
	}
	$.post('index.php?section='+section+'&page='+page+'&cmd='+cmd+'&id='+id, postData, function(data)
	{
		if(data.length > 140){
			$('#loader-bg').hide();
			$("#middle").html(data);
		}else {
			data = '<img src=images/en/alert.png align=left style=vertical-align:super />' + data;
			$('#alert-content').html(data);
			$('#alert').fadeIn();
			
			alertHeight = parseInt($('#alert').height()) + 26;
			alertTop = parseInt($('#alert').css("top"));
			$('#backtobox').css({top : alertTop+'px', height : alertHeight+'px'});
			$('#backtobox').show();
		}
		$('#loader-bg').hide();
		$("#middle").fadeIn();
	});
	return false;
}

function closeBox(boxId)
{
	$("#"+boxId).fadeOut();
	$("#backtobox").hide();
}

function showHelp(boxId, topPos)
{
	var date;
	$('#help').fadeOut();
	data = '<img src=images/en/help.jpg width=68 height=68 align=left style=vertical-align:super />' + help[boxId];
	$('#help-content').html(data);
	$('#help').css({ top: topPos+'px'});
	$('#help').fadeIn();
	
	helpHeight = parseInt($('#help').height()) + 26;
	$('#backtobox').css({top : topPos+'px', height : helpHeight+'px'});
	$('#backtobox').show();
}


//help's content
var help = {};

var stepInfo = {
	'f_step1' : 'Login and Contributor Information',
	'f_step2' : 'General Information',
	'f_step3' : 'Seismic Assessment and Rehabilitation Information',
	'f_step4' : 'Construction Cost Information',
	'f_step5' : 'Complementary Cost Information',
	's_step1' : 'General Information',
	's_step2' : 'Structural and geotechnical Information',
	's_step3' : 'Complementary information and documents'
};

function showStepInfo(step, leftPos)
{
	var data;
	data = stepInfo[step];

	$('#comment-content').html(data);
	$('#comment-box').css({ left: leftPos+'px'});
	$('#comment-box').show();
	
};

function getSubOption(superopt, optionName, ajaxeventBox, contentBox, loadingbox)
{
	if(typeof(superopt) != "undefined"){
		$('#alert').hide();
		$('#'+contentBox).hide();
		$('#'+loadingbox).show();

		$.get('index.php?section=guest&page=options&cmd='+optionName+'&superopt='+superopt,
			function(data){
				$('#'+loadingbox).hide();
				$('#'+contentBox).html(data);
				$('#'+contentBox).show();
			});
	}
};


$(document).ready(function(){
	
	document.offset = {};
	if(document.getElementById("stepnum1")) {
		document.offset[1] = $("#stepnum1").offset().left - 50;
		document.offset[2] = $('#stepnum2').offset().left - 50;
		document.offset[3] = $('#stepnum3').offset().left - 50;
	}
	if(document.getElementById("stepnum4")) {
		document.offset[4] = $('#stepnum4').offset().left - 50;
		document.offset[5] = $('#stepnum5').offset().left - 50;
	}
	if(jQuery.browser.msie && jQuery.browser.version)
		$(document.body).append("<iframe id='backtobox' src='' frameborder='0' style='position:absolute; z-index:100;top:200px; left:300px;height:500px;width:526px;display:none'></iframe>");

});

function check_earthquake(selectedBox)
{
	switch(selectedBox) {
		case "One":
			$('#earthquake_two').hide();
			$('#earthquake_three').hide();
			$('#earthquake_one').show();
			break;
		case "Two":
			$('#earthquake_three').hide();
			$('#earthquake_one').show();
			$('#earthquake_two').show();
			break;
		case "Three":
			$('#earthquake_one').show();
			$('#earthquake_two').show();
			$('#earthquake_three').show();
			break;
		case "Not sure":
			$('#earthquake_one').hide();
			$('#earthquake_two').hide();
			$('#earthquake_three').hide();
			break;
		default:
			$('#earthquake_one').hide();
			$('#earthquake_two').hide();
			$('#earthquake_three').hide();
	};
};
