// JavaScript Document

function popUp(url, w, h, option) {
  var w = (w=='') ? 600 : w;
  var h = (h=='') ? 500 : h;
  var winl = Math.round((screen.width - w) / 2);
  var wint = Math.round((screen.height - h) / 2);
  // toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes
  if (!option) option = 'status=no,scrollbars=yes,resizable=yes';
  option += ',width='+w+',height='+h+',top='+wint+',left='+winl+'';
  windowName = '';
  window.open(url, windowName, option);
}

function send (formid) {
	if (frm = document.getElementById('add'+formid))
		frm.submit();
	else 
		return false;
}

function formShow (what) {
	var Forms = Array ('login','register');
	var others = Array ();
	var x = 0;
	for (i=0;i<Forms.length;i++) {
		if (Forms[i] == what) var doc = document.getElementById ('form-'+Forms[i]);
		else {
			others[x] = document.getElementById ('form-'+Forms[i]);
			x ++;
		}
	}
	showElement(doc);
	for (j=0;j<others.length;j++) {
		hideElement(others[j]);
	}
}

function formSend (what) {
	if (frm = document.getElementById('form-'+what))
		frm.submit();
	else 
		return false;
}

function calcolaSpese (country) {
	var opts = Array ('it','eu','world');
	var targets = Array ('spese','tot','go','celwarning');
	if (!country) country = document.getElementById('fee-country').value;
	var spese = document.getElementById('spesesped').value;
	var elem = document.getElementById('cel-spese');
	elem = elem.getElementsByTagName('div');
	for (i=0;i<opts.length;i++) {
		for (j=0;j<targets.length;j++) {
			if (opts[i] == country)
				showElementById (targets[j]+'-'+opts[i]);
			else
				hideElementById (targets[j]+'-'+opts[i]);
		}
	}
}

function hideElement (elem) {
	if (elem)
		elem.className = elem.className.replace(/\s?shown/g,"")+' hidden';
}

function hideElementById (elem) {
	elem = document.getElementById(elem);
	hideElement(elem);
}

function showElement (elem) {
	if (elem)
		elem.className = elem.className.replace(/\s?hidden/g,"")+' shown';
}

function showElementById (elem) {
	elem = document.getElementById(elem);
	showElement(elem);
}
