var dateNewWebSite = new Date("September 26, 2005 09:00:00")
var ww = "";
var global_w = -1;
var global_h = -1;
var validWebLocationGA = "oiswww.eumetsat.org";

function openImageWindowGlobal(url)
{
  var winDescr  = "scrollbars=1,resizable=1,toolbar=1";
  openWindow(url, (global_w > 0 ? global_w:600), (global_h > 0 ? global_h:600), 'GlobalImage', winDescr, true);
}

function openWinFullResolution(url)
{
  var winDescr  = "scrollbars=1,resizable=1,toolbar=1";
  openWindow(url, 800, 600, 'Full', winDescr, true);
}

function openWindow(url, w, h, winName, winDescr, centered)
{
	//winDescr = dependent=
	if(!winName){
		winName = '';
	}
	if(!winDescr){
		winDescr = '';
	}
	else{
		winDescr = ',' + winDescr;
	}
	var availX = screen.availWidth;
	var availY = screen.availHeight;
	if(availX < w) w = availX;
	if(availY < h) h = availX;
	var x = Math.round((availX - w)/ 2);
	var y = 20;//Math.round((availY - h) / 2);
	if(centered)
	  winDescr = 'left=' + x + ',top=' + y + ',width=' + w + ',height=' + h + winDescr;
	else
	  winDescr = 'left=' + 0 + ',top=' + 0 + ',width=' + w + ',height=' + h + winDescr;

	ww = open (url, winName, winDescr);
	ww.focus();
	return ww;
}
function openWindowNormal(url, w, h, winName, winDescr)
{
  openWindow(url, w, h, winName, winDescr, false);
}


function openWinCenter(url, w, h, winName, winDescr)
{
  openWindow(url, w, h, winName, winDescr, true);
}

function getCleartime()
{
    var zeit = new Date();
    var ms = zeit.getTime();
    ms = prompt("Millisekunden:",ms);
    zeit.setTime(ms);

    day   = addZero(zeit.getDate());
    month = addZero(zeit.getMonth()+1);
    year  = (zeit.getFullYear());

    hour= addZero(zeit.getHours());
    min = addZero(zeit.getMinutes());
    sec = addZero(zeit.getSeconds());
    alert(day+"."+month+"."+year+" "+hour+":"+min+":"+sec);
}

function addZero(val )
{
    return val < 10 ? ("0"+val):val;
}

function hide(id)
{
  hideElement(document.getElementById(id));
}

function show(id)
{
  showElement(document.getElementById(id));
}

function hideElement(elt)
{
    elt.style.visibility = "hidden";
    elt.style.display    = "none";
}

function showElement(elt)
{
    elt.style.visibility = "visible";
    //elt.style.display    = "inline";
    elt.style.display    = "block";
}


function printPrintButtonIndex()
{
  printButton(0);
}

function printPrintButton()
{
  printButton(-1);
}

function printPrintButtonX()
{
  printButton(-1);
}

function printButton(currentLevel)
{
  var printThumbPath = currentLevel==-1 ? "../images/":"images/";
  var isLocal = location.href.indexOf("http://")==-1;
  document.write(
                ( isLocal && false ? "":"<img src=\""+printThumbPath+"printer.gif\" width=\"12\" height=\"12\" alt=\"Print\" border=\"0\" />&nbsp;")
                +"<a class=\"footer\" href=\"#\" onclick=\"window.print();return false;\">"
                +"Print</a>");
}

function getMSGIcon(satNo)
{
    var icon = (satNo > 7 ? "Msg_shd.jpg":"mfg.jpg");
    var linkMet = "<a href='/en/"+(satNo > 7 ? "area4/topic1.html":"mtp")+"' target='_parent'>";
    document.write("<table class='XMetIcon'><tr><td align='center'>"
    + linkMet
    +"<img src=\"../../../images/"
    + icon
    + "\" border=0 height=40></a></td></tr><tr><td class=\"XMetIcon\" id='XMetIcon"+satNo+"'>MET-"+satNo+"</td></tr></table> ");
}

function getNewTag(expiredays, currentDay, currentMonth, currentYear)
{
  return printTags(expiredays, currentDay, currentMonth, currentYear, "icon_new_by.gif", true);
}

function getUpdateTag(expiredays, currentDay, currentMonth, currentYear)
{
  return printTags(expiredays, currentDay, currentMonth, currentYear, "updated.gif", true);
}

function printTags(expiredays, currentDay, currentMonth, currentYear, grafic, asreturn)
{
  //Considered not new after x days
  var newPeriodDays = expiredays;
  //Set Date of Publish
  var publication = new Date();
  publication.setFullYear (currentYear);// (volles Jahr setzen)
  publication.setMonth    ((-1) + currentMonth);//    (Month starts with 0!! )
  publication.setDate     (currentDay);//     (Monatstag setzen)
  publication.setHours    (00);//    (Stunden der Uhrzeit setzen)
  publication.setMinutes  (00);//  (Minuten der Uhrzeit setzen)
  publication.setSeconds  (0);// (Sekunden der Uhrzeit setzen)

  var pastWindowDate = new Date(new Date().getTime()-(1000*60*60*24*newPeriodDays));
  //document.write("<br>Time-Line: "+pastWindowDate);
  var mouseoverText = "Updated: "+publication.getDate()+"/"+(publication.getMonth()+1)+"/"+(publication.getFullYear());
  if(publication.getTime() > pastWindowDate.getTime())
  {
    var str = "<img src='/images/"+grafic+"' alt='"+mouseoverText+"' border=0 title='"+mouseoverText+"'>";
    if(!asreturn) document.write(str);
    else return str;
 	}
  if(asreturn)return "";
}

function getContactUs()
{
  makeLink(getContactURL("http://www.eumetsat.int/feedback/"), "contact us");
}

function getContactOps()
{
  makeLink(getContactURL("http://www.eumetsat.int/feedback/form_ops_archive.html"), "contact us");
}

function getContactArchive()
{//
  makeLink(getContactURL("http://www.eumetsat.int/feedback/form_ops_archive.html"), "contact Archive Service");
}

function makeLink(linker, text)
{

  var prefix = location.href.indexOf("http:")==-1 ? "http://www.eumetsat.int":"";
  var target = location.href.indexOf("http:")==-1 ? " target='_blank' ":"";
  document.write("<a class='textLink' href='"+linker+"' "+target+">"+text+"</a>");
}

function getContactURL(oldURL)
{
  var dater = new Date();
  var nowTime = dater.getTime();
  //If no other solution is found, at least this way!
  var startNewWeb = dateNewWebSite.getTime();
  var isNewWebsite = nowTime > startNewWeb;

  var linkUrl = "http://www.eumetsat.int/idcplg?IdcService=SS_GET_PAGE&nodeId=CONTACT_US";

  return linkUrl;
}
