var gs_cal_oldx=0;
var lastj;
var useCalendar = true;
var calendarvisible = false;
var defaulticonpath = "";
var shostname = location.hostname;
var isovercal=false;

function getcalendarlayers(aTargetframe)
{

	if (aTargetframe == null)
	{
	if (top.indhold)
		targetframe = top.indhold;
	else if (top.appcontent)
		targetframe = top.appcontent;
	}
	else
		targetframe = aTargetframe;

	if (top.framesetpath && top.brand)
		defaulticonpath = top.framesetpath + "images/" + top.brand;
	if (top.gsBrand)
		defaulticonpath = top.framesetpath + "images/" + top.gsBrand;
	if (top.logo.getBrand)
		defaulticonpath = "http://" + shostname + "/online/images/" + top.logo.getBrand();

	ret = ""
	if (useCalendar == true)
	{
		ret+="<div id=\"PopUpCalendar\" style=\"position:absolute; left:0px; top:0px; z-index:7; width:134px; height:77px; overflow: visible; visibility: hidden; border: 1px none #000000\" onMouseOver=\"if(top.logo.ppcTI){clearTimeout(top.logo.ppcTI);top.logo.ppcTI=false;}; top.isovercal=true;\" onMouseOut=\"top.logo.ppcTI=setTimeout(\'top.logo.hideCalendar()\',500); top.isovercal=false;\">";
		ret+="<div id=monthDays style=\"position:absolute; left: 0px; top: 25px; z-index:8; width:134px; overflow: visible; visibility:inherit; background-color:"+bgCol+"; border: 1px none #000000\"></div></div>";
	}
	return ret;
}

function getCalHTML() 
/****************************************************************************************/
/*  Kalender komponentfunktion lavet af Morten Schou Larsen E46729		*/
/*  											*/
/*  Funktion kaldes med document.write og indsætter korrekt ikon og <a href kald	*/
/****************************************************************************************/
{

if (getCalHTML.arguments.length<9) return "Kalender kaldt med for få argumenter";

var sFieldName 		=getCalHTML.arguments[0];
var sLanguage 		=getCalHTML.arguments[1];
var sDateFormat 	=getCalHTML.arguments[2];
var iLeft		=getCalHTML.arguments[3];
var iTop		=getCalHTML.arguments[4];
var bShowWeekNumbers	=getCalHTML.arguments[5];
var aMonths		=getCalHTML.arguments[6];
var aDays		=getCalHTML.arguments[7];
var sBlockedDays	=getCalHTML.arguments[8];
var sImagePath		=getCalHTML.arguments[9];
var bSelectBeforeToday	=getCalHTML.arguments[10];
var bSelectBlockedDays  =getCalHTML.arguments[11];
var sSelectCurrentDay	=getCalHTML.arguments[12];

var imgID=top.getgsUniqueID();

if (iLeft=="STANDARD") iLeft=0;
if (iTop=="STANDARD") iTop=-5;


	str  ="<a href='javascript:top.logo.showCalendar(\""
		+sFieldName 		+"\",\""
		+sLanguage		+"\",\""
		+ sDateFormat 	+"\","
		+ iLeft		+","
		+ iTop		+","
		+ bShowWeekNumbers	+","
		+ "new Array(";
		
		for (a=0;a<aMonths.length;a++) {
			if (a!=0) str+=","
			str+="\""+aMonths[a]+"\""
		}
		str +="),new Array(";
		for (a=0;a<aDays.length;a++) {
			if (a!=0) str+=","
			str+="\""+aDays[a]+"\""
		}
		str +="),\""
		+ sBlockedDays	+"\",\""
		+ sImagePath		+"\""
		
if(bSelectBeforeToday!=undefined)	 str +=","+ bSelectBeforeToday;
if(bSelectBlockedDays!=undefined)	 str +=","+ bSelectBlockedDays;
if(sSelectCurrentDay!=undefined)	 str +=","+ sSelectCurrentDay;
	
	str += ")'><img id=\""+imgID+"\" src=\"" + top.getgsImageURL('calendar')+"\" height=\"14\" width=\"14\" alt=\"Kalender\" border=\"0\">";
	str +="</a>"
	
return str
}




function getCalendarIcon(sFieldName,sLanguage,sDateFormat,iLeft,iTop,bShowWeekNumbers,bSelectBeforeToday,bSelectBlockedDays,sSelectCurrentDay,bUseUniqueId) {
	if (!bSelectBeforeToday){
		bSelectBeforeToday = null;
	}
  var kalID="kalenlink";
  if (bUseUniqueId){
    kalID = top.getgsUniqueID();
  }
	if (useCalendar == true){
		return "<span id='" + kalID +"'><a href='#' onClick='top.showCalendar(\"" + sFieldName + "\",\"" + sLanguage + "\",\"" + sDateFormat + "\"," + iLeft + "," + iTop + "," + bShowWeekNumbers + ",null,null,null,null," + bSelectBeforeToday + "," + bSelectBlockedDays + ",\"" + sSelectCurrentDay + "\");return false'><img src='" + top.getgsImageURL('calendar') + "' border=0></a></span>";
  }
	else {
		return "";
	}
}



bgCol="#999999";tabelBgCol="#999999";rowBgCol="#003366";grayCol="#CCCCCC"
var ppcMN = new Array(12);
var ppcWN = new Array("Mandag","Tirsdag","Onsdag","Torsdag","Fredag","Lørdag","Søndag");
var ppcER = new Array(4);
ppcER[0] = "Required DHTML functions are not supported in this browser.";
ppcER[1] = "Target form field is not assigned or not accessible.";
ppcER[2] = "Sorry, the chosen date is not acceptable. Please read instructions on the page.";
ppcER[3] = "Unknown error occured while executing this script.";
var ppcUC = false;
var ppcUX = 4;
var ppcUY = 4;
var showweeks = true
var calendarvisible = false
var ppcIE=((navigator.appName == "Microsoft Internet Explorer") || (document.getElementById));
var ppcNN=((navigator.appName == "Netscape")&&(document.layers));
var ppcTT="<table width=\"150\" cellspacing=\"0\" cellpadding=\"0\" border=\"1\" bordercolorlight=\"#000000\">\n";
var ppcCD=ppcTT;var ppcFT="<font style=\"font-size: 8pt\" lineHeight=\"8px\" face=\"Verdana\" color=\"#000000\">";var ppcFC=true;
var ppcTI=false;var ppcSV=null;var ppcRL=null;var ppcXC=null;var ppcYC=null;
var ppcML=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var ppcNow=new Date();var ppcPtr=new Date();
var x;
var hollidayArr  = new Array();
var blockHollidays = true;
var blockholman = null;
var ImagePath = null

function showCalendar(sFieldName,sLanguage,sDateFormat,iLeft,iTop,bShowWeekNumbers,aMonths,aDays,sBlockedDays,sImagePath,bSelectBeforeToday,bSelectBlockedDays,sSelectCurrentDay)
{
	
	if (iLeft==0) {  // Placer kalenderkomp korrekt i forhold til standard.
  var target;
 if (sFieldName.indexOf(".") > -1)  //Formnavn er med
		target = eval("targetframe.document." + sFieldName)
	else
		target = eval("targetframe.document.Form1." + sFieldName)  
	var calWidth=134;
	if (bShowWeekNumbers) {calWidth=153;}

  iLeft=-(calWidth-target.offsetWidth)+18;
}
  
	
	
	isovercal = false;
	ppcDF = sDateFormat.replace("YYYY", "Y").replace("YY", "y").replace("DD", "d").replace("MM", "m")
	if (aMonths == null)
		monthArr=targetframe.kalmaaneder
	else
		monthArr=aMonths
	if (aDays == null)
		dayArr=targetframe.kaldage
	else
		dayArr=aDays
	if (sBlockedDays == null)
		setHollidays(targetframe.kalejbankdage)
	else
		setHollidays(sBlockedDays)

	if (sFieldName.indexOf(".") > -1)  //Formnavn er med
		target = eval("targetframe.document." + sFieldName)
	else
		target = eval("targetframe.document.Form1." + sFieldName)

	if (bSelectBeforeToday == null)
		SelectBeforeToday = false
	else
		SelectBeforeToday = bSelectBeforeToday

	if (bSelectBlockedDays == null)
		SelectBlockedDays = false;
	else
		SelectBlockedDays = bSelectBlockedDays;

	if (sSelectCurrentDay == null || sSelectCurrentDay == "")
		SelectCurrentDay = true;
	else {
		if (targetframe.kalhosttime != null && targetframe.kalhosttime != "") {
			tmpNowTime = targetframe.kalhosttime.split(":");
			tmpNowHour = tmpNowTime[0];
			tmpNowMin = tmpNowTime[1];
		}
		else {
	  		dateNow = new Date();
			tmpNowHour = dateNow.getHours();
			tmpNowMin = dateNow.getMinutes();
		}
		tmpTime = sSelectCurrentDay.split(":");
  		if (tmpNowHour >= tmpTime[0] && tmpNowMin >= tmpTime[1])
  			SelectCurrentDay = false;
  		else
  			SelectCurrentDay = true;
	}

	ImagePath = sImagePath

	curcell = null
	targetyear = null
	targetmonth = null
	targetday = null

	var tv = target.value
	if (tv.length == sDateFormat.length)
	{
		yix = sDateFormat.indexOf("YYYY")
		if(yix > -1)
		{
			targetyear = tv.substring(yix, yix+4)
		}
		else
		{
			yix = sDateFormat.indexOf("YY")
			if (yix > -1)
			{
				targetyear = "20" + tv.substring(yix, yix+2)
			}
		}
		mix = sDateFormat.indexOf("MM")
		if(mix > -1)
		{
			targetmonth = tv.substring(mix, mix+2)
			if (targetmonth.substring(0,1) == "0")
				targetmonth = parseInt(targetmonth.substring(1,2))-1
			else
				targetmonth = parseInt(targetmonth)-1
		}
		dix = sDateFormat.indexOf("DD")
		if(dix > -1)
		{
			targetday = tv.substring(dix, dix+2)
		}
	}
	if(isNaN(targetyear) || isNaN(targetmonth) || isNaN(targetday))
	{
		targetyear = null
		targetmonth = null
		targetday = null
	}

	getCalendarFor(target,iLeft,iTop,true,bShowWeekNumbers)
	if (targetday != null)
	{
		if (targetday.substring(0,1) == "0")
			targetday = targetday.substring(1,2)
		datecell = eval("datecell"+targetday)
		eval('setBorder(targetframe.document.getElementById("' + datecell + '"))')
	}
	else{
		datecell = eval("datecell"+ppcNow.getDate())
		
		eval('setBorder(targetframe.document.getElementById("' + datecell + '"))')
 	}
}

function getCalendarFor(target,left,topxy,blockholman,bshowweeks) {
targetframe.document.onkeydown = top.kdown
targetframe.document.onmousedown = top.mdown

calendarvisible = true
showweeks = bshowweeks
if(blockholman==true)
	blockHollidays = true;
if(blockholman==false)
   	blockHollidays = false;
 ppcSV = target;
 if (left == null)
 {leftpl = 0;}
 else
 {leftpl = left}
 if (topxy == null)
 { toppl = 0;}
 else
 {toppl= topxy}
 if (ppcFC) {setCalendar(targetyear, targetmonth);ppcFC = true;}
 if ((ppcSV != null)&&(ppcSV)) {
  if (ppcIE) {
   var obj = targetframe.document.getElementById('PopUpCalendar');
   obj.style.left = document.body.scrollLeft + getOffsetLeft(target) + leftpl - getOffsetLeft(obj.offsetParent)
   obj.style.top  = document.body.scrollTop + getOffsetTop(target) + toppl - getOffsetTop(obj.offsetParent)
   obj.style.visibility = "visible";}
  else {showError(ppcER[0]);}}
 else {showError(ppcER[1]);}}

function switchMonth(param) {
 var tmp = param.split("|");
 setCalendar(tmp[0],tmp[1]);}

function moveMonth(dir) {
 var obj = null;
 var limit = false;
 var tmp,dptrYear,dptrMonth;
 if (ppcIE) {obj = targetframe.document.ppcMonthList.sItem;}
 else {showError(ppcER[0]);}
 if (obj != null) {
  if ((dir.toLowerCase() == "back")&&(obj.selectedIndex > 0)) {obj.selectedIndex--;}
  else if ((dir.toLowerCase() == "forward")&&(obj.selectedIndex < 12)) {obj.selectedIndex++;}
  else {limit = true;}}
 if (!limit) {
  tmp = obj.options[obj.selectedIndex].value.split("|");
  dptrYear  = tmp[0];
  dptrMonth = tmp[1];
  setCalendar(dptrYear,dptrMonth);}
 else {
  if (ppcIE) {
   obj.style.backgroundColor = "#FF0000";
   window.setTimeout("document.ppcMonthList.sItem.style.backgroundColor = '#FFFFFF'",50);}}}

function selectDate(param) {
 var arr   = param.split("|");
 var year  = arr[0];
 var month = arr[1];
 var date  = arr[2];
 var ptr = parseInt(date);
 ppcPtr.setDate(ptr);
 if ((ppcSV != null)&&(ppcSV)) {
  if (validDate(date)) {ppcSV.value = dateFormat(year,month,date);hideCalendar();}
  else {showError(ppcER[2]);if (ppcTI) {clearTimeout(ppcTI);ppcTI = false;}}}
 else {
  showError(ppcER[1]);
  hideCalendar();}}

function setCalendar(year,month) {
 if (year  == null) {year = getFullYear(ppcNow);}
 if (month == null) {month = ppcNow.getMonth();}
 if (month == 1) {ppcML[1]  = (isLeap(year)) ? 29 : 28;}
 ppcPtr.setYear(year);
 ppcPtr.setMonth(month);
 ppcPtr.setDate(1);
 updateContent();}

function updateContent() {
 generateContent();
 if (ppcIE) {targetframe.document.getElementById('monthDays').innerHTML = ppcCD;}
 else {showError(ppcER[0]);}
 ppcCD = ppcTT;
}

function generateContent() {
 var year  = getFullYear(ppcPtr);
 var month = ppcPtr.getMonth();
 var date  = 1;
 var day   = ppcPtr.getDay();
 ppcCD = generateMonth(year,month)
 ppcCD += generateWeekdays()
 if (day == 0) {day = 6}
 else (day = day-1);
 var len   = ppcML[month];
 var bgr,cnt,tmp = "";
 var j,i,d = 0;
  for (j = 0; j < 7; ++j) {
  if (date > len) {lastj = j-1; break;}
   if (showweeks) tmp += "<td bgcolor=\"#CCCCCC\" style='padding-right:2px;border-left:1px solid #999999;border-bottom:1px solid #999999; font-size: 10px; font-family: Verdana'><b>" + getWeek(year,month,date) + "</b></td>"

   for (i = 0; i < 7; ++i) {

   	realdate = date;
   	realmonth = month
   	realyear = year
   	
   	
   	if ((j == 0)&&(i < day)) {
   		if (month>0)
   			realmonth = month-1
   		if (month == 0){
 			  realmonth = 11
 			  realyear = year - 1
      }
		  realdate = ppcML[lmonth] - (day-i-1)
   	}
   	if (date > len) {
   		if (month<11)
		   	realmonth = month+1
   		if (month == 11) {
		   	realmonth = 0
 			  realyear = year + 1
 		  }
		  realdate = date-ppcML[month]
    }

  
  
	if (!SelectBlockedDays && ((i==5) || (i==6) ||(holliday(realdate,realmonth,realyear)))||(!SelectBeforeToday && ((date < ppcNow.getDate() && month <= ppcNow.getMonth() && year <= ppcNow.getUTCFullYear()) || (month < ppcNow.getMonth() && year <= ppcNow.getUTCFullYear()) || year < ppcNow.getUTCFullYear())))
	{
		bgr = "#E1E1E1";
	}
	else {
		bgr = "#FFFFFF";
	}


var greyColor="#E1E1E1";
var whiteColor="#FFFFFF";
var cellBgColor=whiteColor;


	if(SelectBlockedDays) {
		cellBgColor=whiteColor;
	}
	else { // Else #1
		if ((i==5)||(i==6)) {
		  //Check for weekend 
			cellBgColor=greyColor;
		}
	 	else { // Else #2
		 // Check for holiday
		 if (holliday(realdate,realmonth,realyear)) {
		 	cellBgColor=greyColor;
		 }
		 else { // Else #3
		 	// Check if old dates should be displayed
		 	if (SelectBeforeToday) {
		 		cellBgColor=whiteColor;
		 	}
		 	else { // Else #4
		 		// Check if date has expired in current month and year
		 		if (date < ppcNow.getDate() && month <= ppcNow.getMonth() && year <= ppcNow.getUTCFullYear()) {
		 			cellBgColor=greyColor;		 		
		 		}
		 		else {// Else #5
		 			// Check if expired month and year
		 			if (month < ppcNow.getMonth() && year <= ppcNow.getUTCFullYear()) {
		 				cellBgColor=greyColor;
		 			}
		 			else {// Else #6
		 				// Check for expired year
		 				if (year < ppcNow.getUTCFullYear()) {
		 					cellBgColor=greyColor;
		 				}
		 			}// End Else #6
		 		}// End Else #5
		 	}// End Else #4
		 }// End Else #3
	 	}// End else #2
	}// End else #1


bgr=cellBgColor;

	
	bolded=false
	
   	if ((j == 0)&&(i < day)) {
   	
   		if (month>0)
   		{
   			lyear = year
   			lmonth = month-1
   		}
   		if (month == 0)
   		{
   			lyear = year-1
   			lmonth = 11
   		}
		ldate = ppcML[lmonth] - (day-i-1)
   		tmp += makeCell(bgr,lyear,lmonth,ldate,i,j,bolded, "#999999");
   		
   	}
   	else if (date > len) {
 
 	  	if (month<11)
   		{
   			nyear = year
   			nmonth = month+1
   		}
   		if (month == 11)
   		{
   			nyear = year+1
   			nmonth = 0
   		}
		ndate = date-ppcML[month]
   		tmp += makeCell(bgr,nyear,nmonth,ndate,i,j,bolded, "#999999");++date
   	}
   	else {
   	
   		if ((ppcNow.getDate() == date)&&(ppcNow.getMonth() == month)&&(getFullYear(ppcNow) == year)) {
  			bolded = true
  			if (!SelectCurrentDay)
				bgr = "#E1E1E1";
		}
   		tmp  +=makeCell(bgr,year,month,date,i,j,bolded);++date;
   	}
   }
  ppcCD += "<tr align=\"right\">\n" + tmp + "</tr>\n";tmp = "";
  }
 ppcCD += "</table>\n"
}

function eventtest(){
	}

function makeCell(bgr,year,month,date,i,j,bolded,txtcolor) {
 var param = "\'"+year+"|"+month+"|"+date+"\'";
 lb = ""
 bstart="";bend="";
 if (bolded) {bstart="<b>";bend="</b>";}
 txtc = "#000000"
 if (txtcolor)
 	txtc = txtcolor
 if (i==0)
 	lb = "border-left:1px solid #999999;"
 if (date>9 || j<3)
	 eval("datecell"+date+"='c"+i+j+"'")
 
 var td1 = "<td id=c" + i + j + " style='border-style:solid;border-width:1px;border-color:#999999;"
 + "font-size: 11px; font-family: Verdana;color:"+txtc+";background-color:"+bgr+";' width=\"18\" height=\"15\"  ";
 

 var td2 = (ppcIE) ? "</font></span></td>\n" : "</font></a></td>\n";
 var evt = "onMouseOver=\"top.logo.setBorder(this)\" onmouseout=\"top.logo.clearBorder(this)\" onClick=\"top.logo.selectDate("+param+")\" ";
 var ext = "<span Style=\"cursor: pointer\">";
 var lck = "<span Style=\"cursor: default\">";
 var lnk = "<a href=\"javascript:top.logo.selectDate("+param+")\" onMouseOver=\"window.status=\' \';return true;\">";
 var cellValue = (date != 0) ? date+"" : "&nbsp;";
 cellValue = "<table id=t" + i + j + " cellspacing=0 cellpadding=0  width=100% height=100% style='border:1px solid " + bgr + "'><tr><td align=right style='padding-right:1px;color:"+txtc+";background-color:"+bgr+"'>"+bstart+cellValue+bend+"</td></tr></table>";
 var cellCode = "";
  if ((date == 0) || (bgr=="#E1E1E1" && blockHollidays)) {
  if (ppcIE) {cellCode = td1+"Style=\"cursor: default\">"+lck+ppcFT+cellValue+td2;}
  else {cellCode = td1+">"+ppcFT+cellValue+td2;}}
 else {
  if (ppcIE) {cellCode = td1+evt+">"+ext+ppcFT+cellValue+td2;}
  else {
   if (date < 10) {cellValue = "&nbsp;" + cellValue + "&nbsp;";}
   cellCode = td1+">"+lnk+ppcFT+cellValue+td2;}}
 
 return cellCode;
}

function setBorder(cell) {

 	if (curcell != null) {
		clearBorder(curcell);
	}	
  curcell = cell
	cell.style.borderColor="#CC0000";
}

function clearBorder(cell) {
  if (cell.id=="gs_cal_monthTD") {
    cell.style.borderColor="#CCCCCC";
  }
  else {
  cell.style.borderColor="#999999";
  }
}

/* Udkommenteret for at teste om kan slettes, benyttes ikke længere af komponenten men muligvis af andre.. MLAR 13/07-2004
function getgfxpath()
{
	if (ImagePath!=null && ImagePath!="")
		return ImagePath
	else
		return defaulticonpath
}
*/
function generateMonth(year,month)
{
	lyear = year
	nyear = year
	lmonth = month - 1
	nmonth = month + 1
   	if (month == 0)
   	{
   		lyear = year-1
   		lmonth = 11
   	}
   	else if (month == 11)
   	{
   		nyear = year+1
   		nmonth = 0
	}

	csp = 7
	wdth = 134
	arrcellwtdh = 14

	if (showweeks) {csp=8;wdth=153;arrcellwtdh=20}

	var tmp = "";
	tmp += "<table bgcolor=\""+tabelBgCol+"\" border=0 cellspacing=0 cellpadding=0 vspace=0 hspace=0  style='border-top:1px solid #999999;width:" + wdth + "'>";
	tmp += "<tr align=center bgcolor=\"#CCCCCC\" >"
  tmp += "<td colspan=" + csp + " align=center height=20 style='border-right:1px solid #999999;border-left:1px solid #999999; font-size: 11px; font-family: Verdana'><table cellspacing=0 cellpadding=0 border=0 width=100%><tr><td width=" + arrcellwtdh + " align=right valign=middle><a href='javascript:top.logo.switchMonth(\"" + lyear + "|" + lmonth + "\")'><img src='" + top.getgsCompImageURL('calender','left_arrow')+"' border=0 style=\"margin-right:2px\"></a></td><td style=\"border-width:2px;border-style:solid;border-color:#CCCCCC;padding-left:2px;padding-right:2px;\" align=center id=\"gs_cal_monthTD\"><b>" + monthArr[ppcPtr.getMonth()] + "&nbsp;" + getFullYear(ppcPtr) + "</b></td><td width=" + arrcellwtdh + " align=left valign=middle><a href='javascript:top.logo.switchMonth(\"" + nyear + "|" + nmonth + "\")'><img src='" + top.getgsCompImageURL('calender','right_arrow')+"' border=0 style=\"margin-left:2px\"></a></td></tr></table></td>"
	tmp += "</tr>"
	tmp += "<tr align=center bgcolor=\"#FFFFFF\" >"
	tmp += "<td colspan=" + csp + " height=3 align=center style='border-right:1px solid #999999;border-left:1px solid #999999;'> </td>"
	tmp += "</tr>"

	return tmp;
}

function generateWeekdays()
{
	var tmp = "";
	tmp += "<tr align=center bgcolor=\"#CCCCCC\" >"
	if (showweeks)
		tmp += "<td width=18 height=15 style='border-left:1px solid #999999;border-top:1px solid #999999;border-bottom:1px solid #999999; font-size: 10px; font-family: Verdana' align=center>&nbsp;</td>"

	for (i=0; i<dayArr.length; i++)
	{
		leftb = ""
		if (i==0)
			leftb = "border-left:1px solid #999999;"

		tmp += "<td id=t" + i + " width=18 height=15 style='" + leftb + "border-right:1px solid #999999;border-top:1px solid #999999;border-bottom:1px solid #999999; font-size: 10px; font-family: Verdana' align=center><b>" + dayArr[i] + "</b></td>"
	}
	tmp += "</tr>"
	return tmp;
}

function hideCalendar() {
if (calendarvisible)
{
 calendarvisible = false
 if (ppcIE) {ppcSV.focus();}
  if (ppcIE) {targetframe.document.getElementById('PopUpCalendar').style.visibility = "hidden";}
  ppcTI = false;
  setCalendar(null, null);
  ppcSV = null;
}
}

function showError(message) {
 window.alert("[ PopUp Calendar ]\n\n" + message);}

function isLeap(year) {
 if ((year%400==0)||((year%4==0)&&(year%100!=0))) {return true;}
 else {return false;}}

function getFullYear(obj) {
 return obj.getFullYear();}

function validDate(date) {
 var reply = true;
 if ((ppcRL == null) || (!ppcRL)) { /* NOP */}
 else {
  var arr = ppcRL.split(":");
  var mode = arr[0];
  var arg  = arr[1];
  var key  = arr[2].charAt(0).toLowerCase();
  if (key != "d") {
   var day = ppcPtr.getDay();
   var orn = isEvenOrOdd(date);
   reply = (mode == "[^]") ? !((day == arg)&&((orn == key)||(key == "a"))) : ((day == arg)&&((orn == key)||(key == "a")));}
  else {reply = (mode == "[^]") ? (date != arg) : (date == arg);}}
 return reply;}

function isEvenOrOdd(date) {
 if (date - 21 > 0) {return "e";}
 else if (date - 14 > 0) {return "o";}
 else if (date - 7 > 0) {return "e";}
 else {return "o";}}

function dateFormat(year,month,date) {
 if (ppcDF == null) {ppcDF = "d.m.Y";}
 var day = ppcPtr.getDay();
 var crt = "";
 var str = "";
 var chars = ppcDF.length;
 for (var i = 0; i < chars; ++i) {
  crt = ppcDF.charAt(i);
  switch (crt) {
   case "M": str += ppcMN[month]; break;
   case "m": str += (month<9) ? ("0"+(++month)) : ++month; break;
   case "Y": str += year; break;
   case "y": str += year.substring(2); break;
   case "d": str += ((ppcDF.indexOf("m")!=-1)&&(date<10)) ? ("0"+date) : date; break;
   case "W": str += ppcWN[day]; break;
    default: str += crt;}}
 return unescape(str);}

function setMonths(parm) {
 ppcMN = parm;
}

function setHollidays(arr) {
 hollidayArr  = arr.split("|");
 for ( x = 0; hollidayArr[x]!="" && hollidayArr[x]!=null; ++x){}
}

function setBlockHolliday(parm) {
	if (parm=="N")
   		{blockHollidays = false;}
	else
   		{blockHollidays = true;}


}

function holliday(date,month,year){
 month=month+1;
 var dateStr= "";
 if (date<10) {dateStr += "0"+date;}
 else {dateStr += date;}
 if (month<10) {dateStr += "0"+month;}
 else {dateStr += month;}
 dateStr += year;
 var holliday=false;
 for (var i=0; i < x ; ++i){
   if (dateStr==hollidayArr[i]) {holliday=true;}}
 return holliday;}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function getWeek(year,month,day) {
    var when = new Date(year,month,day);
    var newYear = new Date(year,0,1);
    var modDay = newYear.getDay();
    if (modDay == 0) modDay=6; else modDay--;

    var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) -
                 Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;

    if (modDay < 4 ) {
        var weeknum = Math.floor((daynum+modDay-1)/7)+1;
    }
    else {
        var weeknum = Math.floor((daynum+modDay-1)/7);
        if (weeknum == 0) {
            year--;
            var prevNewYear = new Date(year,0,1);
            var prevmodDay = prevNewYear.getDay();
            if (prevmodDay == 0) prevmodDay = 6; else prevmodDay--;
            if (prevmodDay < 4) weeknum = 53; else weeknum = 52;
        }
    }
    return weeknum;
}

function mdown()
{
	if (calendarvisible && !isovercal)
	{
		hideCalendar();
	}
}

var curcell = null;

function kdown(e) {
	var code;
	if (!e) var e = targetframe.window.event;
	
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

	if (calendarvisible)	{
	curyear = ppcPtr.getUTCFullYear()
	curmonth = ppcPtr.getMonth()
	if (curcell == null) 	{
		curcell = targetframe.document.getElementById("c33");
	}
	if (curcell.id=="gs_cal_monthTD") {
	  i=0;
	  j=-1;
	}
	else {
	  i = parseInt(curcell.id.substring(1,2))
	  j = parseInt(curcell.id.substring(2,3))
	}
	curi = i
	curj = j
  
  if (code==39) {
    // Der er blevet trykket på højrepil
    var nextX="";
    var nextY="";
    if(curj<0) {
      // Cursor er i måned
      gsSwitchNextMonth();
      nextcell= targetframe.document.getElementById("gs_cal_monthTD");
    }
    else {    
      if (curi==6) { 
        nextX=0;
        if (curj==lastj) {
          // switchMonth
          gsSwitchNextMonth();
          nextY=0;
        }
        else {
          nextY=curj+1;
        }
      }
      else {
        nextX=curi+1;
        nextY=curj; 
      }
      nextcell = targetframe.document.getElementById("c"+nextX+nextY);
      if (nextcell.onclick==null) {
        // Næste dato kan ikke vælges, find næste ledige
        nextcell=gsCalfindNextDate(nextcell,0)
        if (nextcell==null) nextcell= targetframe.document.getElementById("gs_cal_monthTD"); 
      }
    }
    
    
    setBorder(nextcell);
    e.cancelBubble=true;
    return false;
  }

// venstre pil code==37  
  if (code==37) {
    // Der er blevet trykket på venstrepil
    
   
    var nextX="";
    var nextY="";
    
    if(curj<0) {
    // Cursor er i måned
    gsSwitchPrevMonth();
    nextcell= targetframe.document.getElementById("gs_cal_monthTD");
    }
    else {    
      if (curi==0) { 
        nextX=6;
        if (curj==0) {
          // SwitchMonth
          gsSwitchPrevMonth()
          nextY=lastj;
        }
        else {
          nextY=curj-1;
        }
      }
      else {
        nextX=curi-1;
        nextY=curj; 
      }
      nextcell = targetframe.document.getElementById("c"+nextX+nextY);

      if (nextcell.onclick==null) {
        // Næste dato kan ikke vælges, find næste ledige
        nextcell=gsCalfindPrevDate(nextcell,0)
        if (nextcell==null) nextcell= targetframe.document.getElementById("gs_cal_monthTD");; 
      }    
    }
   
    setBorder(nextcell);
    e.cancelBubble=true;
    return false
  }


  if (code==38) {
    // Der er blevet trykket på op-pil

    var nextX="";
    var nextY="";
    
    if (curj<0) {
      nextY=lastj;
      nextX=gs_cal_oldx;
    }
    if (curj==0)  {
        nextY=-1;
        gs_cal_oldx=curi;
    }
    if (curj>0) {
      nextY=curj-1; 
      nextX=curi;
    }
      
    if (nextY < 0) {
      nextcell= targetframe.document.getElementById("gs_cal_monthTD")
    }
    else {
      nextcell = targetframe.document.getElementById("c"+nextX+nextY);
      if (nextcell.onclick==null) {
        // Næste dato kan ikke vælges, find næste ledige
        nextcell=gsCalfindPrevDate(nextcell,0)
        if (nextcell==null) nextcell= targetframe.document.getElementById("gs_cal_monthTD");
      }
    }

    
    setBorder(nextcell);
    e.cancelBubble=true;
    return false
  }
  if (code==40) {
  // Der er blevet trykket på ned-pil
  
  var nextX="";
  var nextY="";
    if (curj<0) {
      nextY=0;
      nextX=gs_cal_oldx;
    }
    else {
      if (curj==lastj)  {
        nextY=-1;
        gs_cal_oldx=curi;      
      }

      if ((curj<lastj) &&(curj>=0)) {
        nextY=curj+1; 
        nextX=curi;
      }
      }
    if (nextY < 0) {
      nextcell= targetframe.document.getElementById("gs_cal_monthTD")
    }
    else {
      nextcell = targetframe.document.getElementById("c"+nextX+nextY);
      if (nextcell.onclick==null) {
        // Næste dato kan ikke vælges, find næste ledige
        nextcell=gsCalfindNextDate(nextcell,0)
        if (nextcell==null) nextcell= targetframe.document.getElementById("gs_cal_monthTD"); 
      }
    }
    
    setBorder(nextcell);
    e.cancelBubble=true;
    return false
  }

  if (code == 13) 	{
	  // Enter

  // Skodkode der selv finder ud af hvilken funktion der burde kaldes ved onclick, da man ikke kan emulere et obj.click() med Netscape
	var onclickFunction=""+curcell.onclick
	if (onclickFunction!="null") {
	onclickFunction=onclickFunction.substring(onclickFunction.indexOf("{")+1,onclickFunction.length-2);
	eval(onclickFunction);
	}
	e.cancelBubble=true;
  return false
	}

	if (code == 27)    	{
	// ESC
		hideCalendar();
	}
	}
	
}
function gsCalfindPrevDate(cell,count) {
  count++;
  
  if (count==31) return null;  // forhindrer loop, dvs der checkes kun 31 dage tilbage
	var curi = parseInt(cell.id.substring(1,2))
	var curj = parseInt(cell.id.substring(2,3))
	var nextX;
	var nextY;
	var nextcell;
	
	if (curi==0) { 
        nextX=6;
        if (curj==0) {
          // SwitchMonth
          gsSwitchPrevMonth()
          nextY=lastj;
        }
        else {
          nextY=curj-1;
        }
      }
      else {
        nextX=curi-1;
        nextY=curj; 
      }
      nextcell = targetframe.document.getElementById("c"+nextX+nextY);
	if (nextcell.onclick==null) nextcell=gsCalfindPrevDate(nextcell,count);
  return nextcell;
}
function gsCalfindNextDate(cell,count) {
  count++;
  if (count==31) return null;  // forhindrer loop, dvs der checkes kun 31 dage tilbage
	var curi = parseInt(cell.id.substring(1,2))
	var curj = parseInt(cell.id.substring(2,3))
	var nextX;
	var nextY;
	var nextcell;
	if (curi==6) { 
        nextX=0;
        if (curj==lastj) {
          // switchMonth

          gsSwitchNextMonth();
          nextY=0;
        }
        else {
          nextY=curj+1;
        }
      }
      else {
        nextX=curi+1;
        nextY=curj; 
      }
      nextcell = targetframe.document.getElementById("c"+nextX+nextY);

	if (nextcell.onclick==null) nextcell=gsCalfindNextDate(nextcell,count);
  return nextcell;
}
function gsSwitchNextMonth() {
        var nyear = ppcPtr.getUTCFullYear()
				var nmonth = ppcPtr.getMonth() + 1
				if (nmonth == 12)
				{
					nmonth = 0;
					nyear++;
				}
				switchMonth(nyear + "|" + nmonth)
}
function gsSwitchPrevMonth() {
        var nyear = ppcPtr.getUTCFullYear()
				var nmonth = ppcPtr.getMonth() - 1
				if (nmonth == -1)
				{
					nmonth = 11;
					nyear--;
				}
				switchMonth(nyear + "|" + nmonth)
}



function md(mvurl, sid, title, mvh, mvb, fokusname, type, info){
	// Komponent til modale vinduer
	// mvurl - url på den side applikationen vil vise. Udelades den, er default en standard side fra os
	// sid - span id. Objektet som skal sættes ind i span'et i det modale vindue.
	// title - titel på det modale vindue.
	// mvh - vinduets højde. Max. værdi/default værdi = 200px
	// mvb - vinduets bredde. Max. værdi/default værdi = 392px
	// fokusname - name på den kontrol som skal have fokus ved opstart af det modale vindue
	// type - typen på fejlvinduet. 0 - Information, 1 - Handlingsmeddelelse, 2 - Fejlmeddelelser, 3 - Advarselsmeddelelser.
	// info - fejlteksten som vises i fejlvinduet.
	if (type > 3){
		alert("Ikke eksistererende type. Vælg en type mellem 0-3 (se dokumentation)")
		return;
	}


	if ((type == null) || (type == '') && (type != 0)){
	  if ((mvh > 250) || (mvh=='') || (mvh==null)) mvh = 250;
	  if ((mvb > 392) || (mvb=='') || (mvb==null)) mvb = 392;
	}
	else{
	  mvh = 200;
	  mvb = 301;
	}

	f = '';
	f += 'dialogHeight:'+ mvh +'px;';
	f += 'dialogWidth:'+ mvb +'px;';
	f += 'scroll:no;';
	f += 'help:no;';
	f += 'status:no;';

	if (top.logo.appcontent){
		mvpath = top.logo.HttpServer + "/smd_target.htm"
		mfpath = top.logo.HttpServer + "/fejl_target.htm"
	}
	else{
		mvpath = "smd_target.htm"
		mfpath = "fejl_target.htm"
	}

	if (sid != null && sid != ''){
		sid.ovskr = title;
		sid.infotype = type;
		sid.msg = info;
		sid.fonam = fokusname;
	}
	else{
		sid = new Array(info, title, type);
		sid.msg = info;
		sid.ovskr = title;
		sid.infotype = type;
		sid.fonam = fokusname;
	}

	if ((type == null) || (type == '') && (type != 0)){
	  if ((mvurl != null) && (mvurl != ""))
	  	RV = window.showModalDialog(mvurl, sid, f);
	  else{
	  	RV = window.showModalDialog(mvpath, sid, f);
	   	// Har formen window.showModalDialog(sURL [, vArguments] [, sFeatures]);
	   }
	}
	else{
	  if ((mvurl != null) && (mvurl != ""))
	  	RV = window.showModalDialog(mvurl, sid, f);
	  else
 		RV = window.showModalDialog(mfpath, sid, f);

	}
	return RV;

}

