
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function Popup(url,name,width,height,left,top)
{	
  return(window.open(url,name,'width='+width+',height='+height+',left='+left+',top='+top));
}

function openChromelessWindow(url) {
	oWin = window.open(url, '_blank', 'location=no,menubar=no,toolbar=no,titlebar=no');
}	


function Popup2(url,name,width,height,left,top,param)
{
   var s;
   s="width="+width+",height="+height+",left="+left+",top="+top;
   if (param!="") s+=","+param	
   return (window.open(url,name,s));
}

function footerRepos() {
  var oFoot = document.getElementById('footer');
  if (oFoot)
    oFoot.style.bottom = '0pt';
  if (document.forms.NC_EditForm) {
	// Hack for validating date of WebInfo
	if (document.forms.NC_EditForm.NCPH_EventDate) {
		document.forms.NC_EditForm.NCPH_EventDate.onchange = function () {checkWebInfoDates(this, true)};
	}
	if (document.forms.NC_EditForm.NCPH_EventExpirationDate) {
		document.forms.NC_EditForm.NCPH_EventExpirationDate.onchange = function () {checkWebInfoDates(this, false)};
	}
  }
}

function checkWebInfoDates(o, notEmpty) {
	var aDd, s, d;
	var mode = 's';
	var cD = '';
	d = o.value.replace(/$\s/);
	if (d.search(/^\s*$/) == 0) { 
		// Empty Field
		if (notEmpty) {
			alert("A Date must be specified");
			return false;
		} else {
			return true;
		}
	}
	
	if (d.search(/\,/) >= 0) mode = 'e';  // comma separated: m d y (English format)
	if (d.search(/\//) >= 0) mode = 'e';  // Slash separated: m d y (American format)
	if (d.search(/\./) >= 0) mode = 'd';  // Dot separated: d m y (European format)

	d = d.replace( /[ \/\,\.]/g, "-");
	d = d.replace( /--/, "-");
	aDd = d.split('-');
	if (aDd.length != 3) {
		alert("Invalid Date");
		return false;
	}
	s = chgMonth(aDd[0])
	if (s != aDd[0]) {
		mode='e';
		aDd[0] = s;
	}
	s = chgMonth(aDd[1]);
	if (s != aDd[1]) {
		mode = 'd';
		aDd[1] = s;
	}
	switch (mode) {
		case 'e':
			// english: m d y
			cD = lZ(aDd[1], 2)+' '+mon(aDd[0])+', '+fY(aDd[2]);
			break;
		case 'd':
			// European: d m y
			cD = lZ(aDd[0], 2)+' '+mon(aDd[1])+', '+fY(aDd[2]);
			break;
		default:
			// System: y m d
			cD = lZ(aDd[1],2)+' '+mon(aDd[2])+', '+fY(aDd[0]);
	}
	o.value = cD;
	
	return true;
}

function lZ(pS, pLen) {
	var cR, nN, i;
	cR = String(pS);
	nN = pLen-cR.length;
	for (i=0; i<nN; i++)
		cR = String(0)+cR;
	return cR;
}

function fY(pY) {
	if (pY < 100) {
		if (pY < 50) {
			pY = pY * 1 + 2000;
		} else {
			pY = pY * 1 + 1900;
		}
	}
	return pY;
}

function mon(pM) {
	aMon = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
	return aMon[pM-1];
}

function chgMonth(pS) {
	pS = pS.toLowerCase();
	if (pS.search(/^jan|gen|ene/i)>=0) return 1;
	if (pS.search(/^feb|f.v/i)>=0) return 2;
	if (pS.search(/^mar/i)>=0) return 3;
	if (pS.search(/^apr|avr|abr/i)>=0) return 4;
	if (pS.search(/^mai|may/i)>=0) return 5;
	if (pS.search(/^jun|giu/i)>=0) return 6;
	if (pS.search(/^jul|lug/i)>=0) return 7;
	if (pS.search(/^aug|ago|ao/i)>=0) return 8;
	if (pS.search(/^s.p|set/i)>=0) return 9;
	if (pS.search(/^okt|oct|ott|out/i)>=0) return 10;
	if (pS.search(/^nov/i)>=0) return 11;
	if (pS.search(/^dez|d.c/i)>=0) return 12;
	return pS;
}
//
// synchronous : synch=true
//
function GetXML(url,synch,HandlerOnReadyStateChange)
{
  if (window.ActiveXObject)
  { 
    xhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
  } 
  else // Mozilla - based browser 
  { 
    xhttp = new XMLHttpRequest(); 
  }
  if(HandlerOnReadyStateChange!=null) xhttp.onreadystatechange = HandlerOnReadyStateChange;
  xhttp.open("GET", url, synch);  //false=asynchronous call
  xhttp.send(null); 
  return (xhttp);         
}
