﻿/*BFB, added 17-6/10: sets */
function supportTimeforbrugDatoInit(){

var d= new Date();
var theMonth= d.getMonth();
theMonth+=1;
var dagsDato = d.getDate()+'-'+theMonth+'-'+d.getFullYear();
var startDateInput = document.getElementById('list_filterMINUS1');
var endDateInput = document.getElementById('list_filterMINUS2');
  if (!startDateInput.value) {
    startDateInput.value = '01-01-1970';  
  }
  if (!endDateInput .value) {
    endDateInput.value = dagsDato;  
  }
  
}

/*BFB, added 18-5/10: tangora TV scripts */

//initiates dropdown external filter on page id 3793
function videoPageInit(){
	chooseVideoSeries();
	setCaptionsLanguageSelect();
	checkSeenVideoCookie();
	    
}


function chooseVideoSeries() {
	//adds handler to systems dropdown to choose video series (added because we've removed the 'show' button
	Tangora.Events.AddHandler(document.getElementById("list_filter5919"), 'onchange', submitTheVideoForm);
}

function setCaptionsLanguageSelect() {
	//ensures that selectedIndex of handmade select box is the same as the choosen language, as indicated by the URL parameter
	var selectedLanguage = window.location.toString();
	var languageParameter = "captions";
	var captionsIndex = selectedLanguage.indexOf(languageParameter);
	selectedLanguage = selectedLanguage.slice(captionsIndex+(languageParameter.length+1));
	var captionOptions = document.getElementById('captions');

	for (var i=0;i<captionOptions.length;i++){
		if (captionOptions.options[i].value == selectedLanguage){
			captionOptions.selectedIndex = captionOptions.options[i].index;
		}
	}
}

function submitTheVideoForm(){

	//there are 3 pages, each with their id, in partner-, friend- and customer centers

	if (document.rediger3793){
		document.rediger3793.submit();
	}
	
	if (document.rediger3799){
		document.rediger3799.submit();
	}
	
	if (document.rediger3800){
		document.rediger3800.submit();
	}
	

	
}

function setSeenVideoCookie(paramVideoId) {
	document.getElementById('yt-'+paramVideoId).className="inlinelink defaultlinkViewed";
	var expiredays = 7;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	Tangora.Cookies.SetCookie(paramVideoId, 'viewed', exdate);
}


function checkSeenVideoCookie(){
	var videoLinks = document.getElementById('modulelayout3793_11').getElementsByTagName('a');
	for (var i=0;i<videoLinks.length;i++){
		var linksID = videoLinks[i].id;
		linksID = linksID.slice(3);	
			if (Tangora.Cookies.GetCookie(linksID)){
				videoLinks[i].className="inlinelink defaultlinkViewed";
			}
	}
	    	
}

function deleteSeenVideosCookies(){
	var videoLinks = document.getElementById('modulelayout3793_11').getElementsByTagName('a');
	for (var i=0;i<videoLinks.length;i++){
		var linksID = videoLinks[i].id;
		linksID = linksID.slice(3);	
			if (Tangora.Cookies.GetCookie(linksID)){
				Tangora.Cookies.DeleteCookie(linksID);
				videoLinks[i].className="inlinelink defaultlink";
			}
	}
}

/* end tangora tv scripts */







/*BFB, added 1-9/09: chooseContigoTopBanner function, which switches banner out between 4 variations*/

function chooseContigoTopBanner(){
//if (document.location.href.indexOf('debug')>-1) {}
var topbanner = document.getElementById('contigotopbanner');
var randomnumber=Math.floor(Math.random()*4+1)
topbanner.src = "/media/cb"+randomnumber+".jpg"

}

/*end chooseContigoTopBanner */

var ts_images=new Array();

ts_images["english"]=new Array(
    "/html/websitelayout2004/top1_english.jpg",
    "/html/websitelayout2004/top2_english.jpg",
    "/html/websitelayout2004/top3_english.jpg",
    "/html/websitelayout2004/top4_english.jpg",
    "/html/websitelayout2004/top5_english.jpg"

);
ts_images["danish"]=new Array(
    "/html/websitelayout2004/top1.jpg",
    "/html/websitelayout2004/top2.jpg",
    "/html/websitelayout2004/top3.jpg"
);
ts_images["kundecenter"]=new Array(
    "/html/websitelayout2004/top1_kf.jpg",
    "/html/websitelayout2004/top2_kf.jpg"
);

function tdemo(theurl) {
  window.open("http://www.tangora.com/show.asp?id="+ theurl,"Eksempel","width=640,height=480,scrollbars=no"); 
}

function sitemap(sideid) {
  var h=0
  var theurl='http://www.tangora.com/show.asp?id=' + sideid 
  if (screen.height >= 700) { h=665 } 
  else { h=screen.height-150 }
  window.open(theurl,'Sitemap','width=290,height=' + h + ',scrollbars=yes');
}

function saetHoejde() {
  h=screen.height;
  if (h > 600) { h=445; } 
  else { h=h-297 }
  themain.style.height=h; 
}

function GetByRegExp (re, tmpStr) {  
  regex = new RegExp (re);
  regex.global = true;
  regex.ignoreCase=true;
  match = regex.exec (tmpStr);
  if (match) {
    return match[1];
  } else {
    return 0;
  }
}

function GetAspPageName () {
  var tmpStr = window.location.toString();    
  re = /\/(\w+\.asp)/gi  
  aspname=GetByRegExp (re, tmpStr);    
  return aspname;
}

function IsDetailPage () {
  aspname = GetAspPageName();
  switch (aspname) {	  
    case "showlistrecord.asp" :
	isDetail = true;
	break;
    default :
	isDetail = false;    
  }  
  return isDetail;
} 

function testfunc () {
  alert (IsDetailPage());
}

function GetPageId () {
  var tmpStr = window.location.toString();    
  re = /[\?|\&]id=(\d+)/gi  
  pageid=GetByRegExp (re, tmpStr);  
if (pageid==0) {
re = /page(\d+)\.aspx/gi
pageid=GetByRegExp (re, tmpStr);
}
  return pageid;
}

function commentPage () {  
  pageid=GetPageId();
  if (pageid!=0) {    
    window.open ("/showformex.asp?id=770&urlsideid="+pageid, 'comment', "dependent=yes,width=486,height=440,scrollbars=no,resizable=no");
  }  
} 

function viewcommentPage () {
  pageid=GetPageId();
  if (pageid!=0) {	  
    window.open ("/showlist.asp?id=771&check1="+pageid, 'comments', "dependent=yes,width=486,height=440,scrollbars=no,resizable=no");
  }  
}

function viewcommentPageEx (pageid) {  
    location.href = "/showlist.asp?id=771&check1="+pageid;  
}  

function TipAFriend () {
  pageid=GetPageId();  
  url = escape (window.location.toString());
  pagetitle = escape (window.document.title);    
  headertext = escape ("Et tip: ")+escape (window.document.title);
  if (pageid!=0) {
    window.open ("/showformex.asp?id=772&urlsideid="+pageid+"&urllink="+url+"&urlsidetitel="+pagetitle+"&urloverskrift="+headertext, 'tipafriend', "dependent=yes,width=486,height=440,scrollbars=no,resizable=no");
  }
}

function doopenPopup (url, name) {  
  window.open (url, name, "dependent=yes,width=480,height=440,scrollbars=no,resizable=no");
}

function FrontpageForgottenPassword() {
    location='/login?validating=1&language=30&username='+URLEncode (document.navlogin.username.value)+'&action=forgotten';
}

function funcSwitchPasswordFields(obj) {
if (obj && obj.form) {
  var obj2=obj.form.password;
  if (obj2) {
    obj.style.display="none";
    obj2.style.display="inline";
    obj2.focus();
  }
}
}

function funcFocus(obj, defaultText) {
  if (obj && obj.value && obj.value == defaultText) { 
    obj.value=""; 
  }
}

function FrontpageRandomImage(area) {
  if (!area) { area="danish"; }
  if (ts_images && area && ts_images[area] && ts_images[area].length) {
  var num=Math.round(Math.random()*(ts_images[area].length-1));
  document.write('<img src="'+ts_images[area][num]+'" width="736" height="174" alt="" usemap="#toppictmap" border=0>');
  }
}

function FrontpageRandomBanner(area) {
  if (!area) { area="danish"; }
  if (ts_images && area && ts_images[area] && ts_images[area].length) {
  var num=Math.round(Math.random()*(ts_images[area].length-1));
  document.getElementById('header').innerHTML = '<img src="'+ts_images[area][num]+'" width="736" height="174" alt="" usemap="#toppictmap" border=0>';
  }
}

var NewsletterLoginGroups = new Array();
var NewsletterLoginTexts = new Array();
NewsletterLoginGroups["1133"]="2";
NewsletterLoginTexts["1133"]="Contigo CMS";

var DisabledNewsletterCategory;
function DisableNewsletterCategory(logingroup) {
  if (logingroup && NewsletterLoginGroups[logingroup]) {
    var ctrlid=NewsletterLoginGroups[logingroup];
    var obj=document.getElementById("newsletter_category"+ctrlid);
    if (ctrlid && obj) {
	// append text after label (has to be done before checking the checkbox due to a FireFox issue)
	var p=obj.parentNode ? obj.parentNode : obj.parentElement;
	if (p && p.innerHTML) {
	  var str="obligatorisk";
	  if (NewsletterLoginTexts["1133"]) {
	    str+=" for "+NewsletterLoginTexts["1133"]+" kunder";
	  }
	  p.innerHTML+=" ("+str+")";
	}
	// make sure checkbox is checked (and get a new reference to the checkbox obj due to a FireFox issue)
	var obj=document.getElementById("newsletter_category"+ctrlid);
	obj.checked=true;
	obj.disabled=true;
	DisabledNewsletterCategory=obj;
	// set onsubmit handler for the form
	if (obj.form) {
	  obj.form.onsubmit=function() { if (DisabledNewsletterCategory) { DisabledNewsletterCategory.disabled=false; DisabledNewsletterCategory.checked=true; } }
	}
    }
  }
}

function ParseDate(s) {
  // Parse a string in the format "dd-mm-yy[yy]" and return a date object
  var da=s.split('-');
  var y=parseInt(da[2],10);
  if (y < 100) {
    // handle two-digit years
    y += 2000;
/*
    if (y > 95) {
	// 
	y = y+1900;
    } else {
    }
*/
  }
  var d=new Date (y, parseInt(da[1],10)-1, parseInt(da[0],10));
  return d;
}

function FormatDate(d) {
  // return date as string (dd-mm-yyyy)
  return d.getDate()+'-'+(d.getMonth()+1)+'-'+d.getFullYear()
}

function UpdateTrafficImages(frm, fromdatectrl, todatectrl, link) {
  if (frm && frm[fromdatectrl] && frm[todatectrl]) {
    // firstdatestr indicates the first date that we have collected traffic for
    var firstdatestr='01-10-04';
    var firstdate=ParseDate(firstdatestr);
    var startdate=ParseDate(frm[fromdatectrl].value);
    var enddate=ParseDate(frm[todatectrl].value);
    if (enddate < startdate) {
	// switch dates
	var tmp=enddate;
	enddate=startdate;
	startdate=tmp;
	// switch text in date controls
	tmp=frm[fromdatectrl].value;
	frm[fromdatectrl].value=frm[todatectrl].value;
	frm[todatectrl].value=tmp;
    }
    if (startdate < firstdate) {
	// set startdate to firstdate
	startdate = firstdate;
	frm[fromdatectrl].value=firstdatestr;
    }
    var startdatestr=FormatDate(startdate);
    var enddatestr=FormatDate(enddate);
    UpdateTrafficImageSrc("imgtraffic", link, startdatestr, enddatestr, 1)
    UpdateTrafficImageSrc("imgtraffictype", link, startdatestr, enddatestr, 2)
  }
}

function UpdateTrafficImageSrc(id, link, startdate, enddate, type) {
  var obj=document.getElementById(id);
  if (obj) {
    var imgsrc="http://sys.tangora.net/TangoraConfig2/img.aspx?type="+type+"&url="+link+"&startdate="+startdate+"&enddate="+enddate;
    obj.src=imgsrc;
  }
}

function GetRndKey()
{
	 return Math.random()*10000;
}

function OpenReplyWindow(page, reportid)
{
   window.open("/" + page+ "?reportid=" + reportid,"Suprap_reply_window","width=600,height=400,toolbars=no,resizeable=no");
}

function CloseAndRefresh()
{
	var loc = window.opener.location.href;

	if(loc.indexOf("#bottom")>-1)
	{
		loc = loc.replace("#bottom","");
		loc = loc.replace(/&rndkey=[\d+|\.]*/gi,"");
	}
	
	window.opener.location.href = loc + "&rndkey=" + GetRndKey() + "#bottom";
	this.close();
}

function DoCustomerSwitch(b)
{
	var customer = document.getElementById("idCustomer");
	var pCustomer = document.getElementById("idpossible_customer");

	if(b)
	{
		pCustomer.disabled = false;
		customer.disabled = true;
		customer.selectedIndex = 0;	
	}
	else
	{
		customer.disabled = false;
		pCustomer.disabled = true;
		pCustomer.value = "";
	}
}


//insert dynamic help text in forms
function PlaceInputHelpText(elmID,text)
{
	var elm = document.getElementById(elmID);

	SetHelpText(elm,text);
	Tangora.Events.AddHandler(elm,"onfocus",function() {RemoveHelpText(elm,text);});
	Tangora.Events.AddHandler(elm,"onblur",function() {SetHelpText(elm,text);});
}

function SetHelpText(elm,text)
{
	if(elm.value == '')
	{
		elm.value = text;
	}
}

function RemoveHelpText(elm,text)
{
	if(elm.value == text)
	{
		elm.value = '';
	}
}