

function openTipEnVenPopup(pUrl)
{
    var winl = (screen.width-400)/2;
    var wint = (screen.height-300)/2;
    var settings = "width=450,height=450" + ",top=" + wint + ",left=" + winl;
    window.open(pUrl, null, settings);

}

function OpenHandbookChaptersPdf()
{
	var selectedChapters = "";
	var startUrl = "/layouts/HandbookChapterPDFCreator.aspx?lg=pdf&ids=";
	var chapters = document.getElementsByName("chapters");
	//debugger;
	if (chapters){
		for (i = 0; i < chapters.length; i++)
		{
			if (chapters[i].checked){
				selectedChapters += chapters[i].value + "|";
			}
		}
	}
	if (selectedChapters != "")
	{
		window.open(startUrl + selectedChapters,'handbookChapters','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
	}
	else
	{
		alert("Please select at least one handbook chapter");
	}
}


function toggleAdvancedSearch(i) {
    var el = document.getElementById("advancedSearch");
    
    var simple = document.getElementById('h2Simple');
    var advance = document.getElementById('h2Advance');
      
    var display = el.style.display;
    
    var isIE7 = (navigator.appVersion.indexOf("MSIE 7")==-1) ? false : true;
    
    if (i != "2"){
       if (isIE7)
       {      
        var search = document.getElementById("search");
        if (search != null)
            {          
                search.style.paddingBottom = "0px";       
            }
       }            
       
       el.style.display="none";             
       
       simple.className="h2Active";  
       advance.className="boxTitle1"; 
       
     }
    else
    {
        if (isIE7)
        {        
            var search = document.getElementById("search");
            if (search != null)
            {                                      
                search.style.paddingBottom = "1px";
            }   
        }
        
        el.style.display="block";
        advance.className="h2Active";
        simple.className="boxTitle1";        
     }
    
}
/* luc 081203 - verifying if any user is loggin or not */
function VerifyIfLogin(param)
{	
	//alert('yoyoyo');
	var startUrl = "/kurser/kursusTilmeldInfo.aspx";
	var loginPath = "/login.aspx";
	var camp ="/kurser/kursusTilmelding.aspx";
	
	//alert('param = ' + param);
	if(param=='true')
	{
		//alert('is login');
		document.location.href = camp;
		
		//alert('camp= ' + camp);
		return true;
	}
	else
	{
		//alert('param = ' + param);
		document.location.href = startUrl;
		//alert('not login');
		return false;
	} 
	alert('param = ' + param);
}
/* luc 081204 - subscribe functionality */
function PressingSubscribeTilmeld()
{
   var kursus = "/kurser/kursusTilmelding.aspx";
  
		document.location.href = kursus;
  
  
}
/* luc 081204 - redirect to login subscribe  */
function PressingLoginSubscribeTilmeld()
{
	var loginPath = "/login.aspx?item=/kurser/kursusTilmelding"; 
	//alert('login');
	document.location.href = loginPath;
	
}
/* luc 081204 - redirect to login unsubscribe  */
function PressingLoginUnSubscribeTilmeld()
{
	var loginPath = "/login.aspx?item=/MinProfil/MyMeetings"; 
	//alert('login');
	document.location.href = loginPath;
}
/* luc 081204 - unsubscribe functionality */
function PressingUnSubscribeTilmeld()
{
	var unsubRediredirect = "/kurser/kursusAfmeldForm.aspx";
	//alert('unsubscribe');
	document.location.href = unsubRediredirect;
	
}
function PressingArrangements()
{
var arrangementRedirect = "/MinProfil/MyMeetings.aspx";
	 //alert('Arrangements');
	 document.location.href = arrangementRedirect;
}

function doSearch(site, courseValue)
{
   var q = '?q=';
   if(qBox != null){
        q += encodeURI(qBox.value);
    }
   var url = '/search.aspx';

   var el = document.getElementById("advancedSearch");
   var display = el.style.display;
  
   
        var qBox = document.getElementById('searchf1Txt');
        if(qBox != null){
               q += encodeURI(qBox.value);
            }
        
  if(display == "none"){
        //simple search
        url += q;
        document.location = url;
        return;
  }
 //alert(Date.parse(document.getElementById('inputF1TextF').value));
  // alert(Date.parse(document.getElementById('inputF1TextT').value));
  if(document.getElementById('inputF1TextF').value!='' && document.getElementById('inputF1TextT').value!='' && Date.parse(document.getElementById('inputF1TextF').value)>Date.parse(document.getElementById('inputF1TextT').value))
  {
  
    alert('Insert correct dates');
  }
  else
  {
   var pf = '';
    pf = addFilterParam(pf, 'ddCategories', '.');
	
	var quax = '';
	
	/* gic 081127 - for different search in courses*/
	var startDate = '';
	var endDate = '';
	if(document.getElementById('inputF1TextF').value!='' && document.getElementById('inputF1TextT').value!='')
    {
		if (pf = courseValue)
		{
			startDate = document.getElementById('inputF1TextF').value;
			endDate = document.getElementById('inputF1TextT').value;
		}
		else{
              q+=" daterange:"+document.getElementById('inputF1TextF').value+".."+document.getElementById('inputF1TextT').value+" site:"+site;
			  q+="&datas="+document.getElementById('inputF1TextF').value+"&dataf="+document.getElementById('inputF1TextT').value;
		}
	}
	else
    {
		var qBox = document.getElementById('searchf1Txt');
		if(qBox != null && qBox.value=="")
		   {
			q+="site:"+site;
		   }
	}
	
/*
	if(document.getElementById('inputF1TextF').value!='' && document.getElementById('inputF1TextT').value!='')
            {
              q+=" daterange:"+document.getElementById('inputF1TextF').value+".."+document.getElementById('inputF1TextT').value+" site:"+site;
			  q+="&datas="+document.getElementById('inputF1TextF').value+"&dataf="+document.getElementById('inputF1TextT').value;
             }
			  else
			 {
				var qBox = document.getElementById('searchf1Txt');
				if(qBox != null && qBox.value=="")
				   {
				    q+="site:"+site;
				   }
            }
    */
	
	
	
    if(pf != '' && document.getElementById('ddCategories').selectedIndex>0){
       pf = '&cat=' + pf;
       q+=pf;
    }  
    
         url += q;
		 /* gic 081127 - add for search*/
		 var urlf = '';
		 urlf += url+"&isAdvace=true";
		 if (startDate != '')
			urlf += "&startDate="+startDate;
		 if (endDate != '')
			urlf += "&endDate="+endDate;
			
		document.location = urlf;
          return;
        }
        
        
}


function addFilterParam(qs, objId, separator){
    var obj = document.getElementById(objId);
    if(obj != null && obj.value != ''){
        if(qs != ''){
            qs += separator;
        }
        return qs + encodeURI(obj.value);
    }
    else{
        return qs;
    }
}


function quickSearch(cat){
    var query ='/search.aspx?q='+encodeURIComponent(document.getElementById('searchTxt').value);
    location.href =query;
    }
    
function checkEnter(e,caller) //e is event object passed from function invocation
{

	var characterCode //literal character code will be stored in this variable

	if(e && e.which ||e.which == 0)
	{ //if which property of event object is supported (NN4)
	
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{ 
	    if(document.all){
		    e.returnValue=false;
            e.cancel = true;
        }
        else{
         e.preventDefault();
        }
        var obj = document.getElementById(caller);
        if(obj){        
            
            if(obj.click){
		        obj.click();
		    }
		}
		return false
	}
	else
	{
		return true
	}
		
}

function openPopup(href,windowname,obj)
{

 win=window.open(href, windowname, 'width=189,height=182,scrollbars=no');
 win.moveTo(document.getElementById(obj).offsetLeft+100,document.getElementById(obj).offsetTop-80);
}


function doLocalSearch(page,cat,site)
{
   var q = '?q=';
   if(qBox != null){
        q += encodeURI(qBox.value);
    }
   var url = page;
   var qBox = document.getElementById('searchf1Txt');
   if(qBox != null){
              q += encodeURI(qBox.value);
            }
        
  //alert(Date.parse(document.getElementById('inputF1TextF').value));
  // alert(Date.parse(document.getElementById('inputF1TextT').value));
 
  if(document.getElementById('inputF1TextF'))
  {
  if(document.getElementById('inputF1TextF').value!='' && document.getElementById('inputF1TextT').value!='' && Date.parse(document.getElementById('inputF1TextF').value)>Date.parse(document.getElementById('inputF1TextT').value))
  {
  
    alert('Insert correct dates');
  }
  else
  {
     if(document.getElementById('inputF1TextF').value!='' && document.getElementById('inputF1TextT').value!='')
            {
              q+=" daterange:"+document.getElementById('inputF1TextF').value+".."+document.getElementById('inputF1TextT').value+" site:"+site;
			  q+="&datas="+document.getElementById('inputF1TextF').value+"&dataf="+document.getElementById('inputF1TextT').value;
             }
        else
			 {
				var qBox = document.getElementById('searchf1Txt');
				if(qBox != null && qBox.value=="")
				   {
				    q+="site:"+site;
				   }
            }      
    q+="&sort=date:D:S:d1&getfields=magazine";
       
    } 
}
else
{
 q+="&sort=date:D:S:d1";
}	
    
         url += q;
         document.location = url;
          return;
        }
        
function doHandbookSearch(page,cat)
{

   var q = '/HaandbogSearch.aspx?q=';
   if(qBox != null){
        q += encodeURI(qBox.value);
    }
   var url = page;
   var qBox = document.getElementById('searchf1Txt');
   if(qBox != null){
              q += encodeURI(qBox.value);
            }
  url+=q+'&partialfields=categories:' + cat+"&sort=date:D:S:d1&getfields=article";
  document.location = url;
  return;
  

}

function CourseFormSubmit(path)
{
	var categoryCtrl = document.getElementById('selCategory');
	var startDateCtrl = document.getElementById('inputF1TextF');
	var endDateCtrl = document.getElementById('inputF1TextT');
	var categoryId = categoryCtrl.options[categoryCtrl.selectedIndex].value;
	var startDate = startDateCtrl.value;
	var endDate = endDateCtrl.value;

	var qs = 'categoryId=' + categoryId + '&startdate=' + startDate + '&enddate=' + endDate;
	document.location.href = path + '&' + qs;
}

function jobBankQuickSearchSubmit() {
	var area = document.getElementById('area');
	location.href = "/JobOgKarriere/jobbank.aspx?categ=" + area.options[area.selectedIndex].value;
}

function next(pag,index)
{
  n=Number(index)+1;
  document.location=encodeURI(pag)+"&n="+n;
}

function prev(pag,index)
{
  if(Number(index)>0)
  {
  n=Number(index)-1;
  document.location=encodeURI(pag)+"&n="+n;
}
}

 function showHelp(navUrl, w, h, t, l, s) 
 {
   if (window.screenLeft) 
   {
     var parentX = window.screenLeft;
   } 
   else if (window.screenX) {
								var parentX = window.screenX;
							} else 
							{
								var parentX = 0;
							}


 if (document.body.clientWidth) {
							      var parentW = document.body.clientWidth;
								} 
								else 
								if (window.innerWidth) {
										var parentW = window.innerWidth;
														} 
														else {
															var parentW = screen.availWidth;
															}

if (window.screenTop) {
						var parentY = window.screenTop;
						} 
						else if (window.screenY) 
						{
							var parentY = window.screenY;
						} else {  var parentY = 0; }

 window.name='popwindow';
 t = parentY - 100;
 if (window != top) {
						l = (parentX + parentW) - w + 300;
					} else {
						l = (parentX + parentW) - w - 20;
					}
// overrule
 l = 20;
 t = 20;
 window.open(navUrl,'_blank','toolbar=0,width=' + w + ', height=' + h + ',marginwidth=0,resizable=no,marginheight=0,Scrollbars='+ s + ',left=' + l + ',top=' + t );
 }

function DoBlogSearch()
{
    var txtBox = document.getElementById('tbSearchBlog');
     var q = '?q=';
     var query = '' + document.location;
     query = query.substring(0, query.indexOf('?', 0));
     
     if(txtBox != null)
     {
        if (txtBox.value != '')
        {
          q += encodeURI(txtBox.value);          
          document.location = query + q;
          return;            
        }
     }
} 


function addEvent(obj, evType, fn) {
	// adds an eventListener for browsers which support it
	// Written by Scott Andrew: nice one, Scott
	if (obj.addEventListener){
		obj.addEventListener(evType,fn,true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType,fn);
		return r;
	} else {
		return false;
	}
}


function changeLocation(selectId)
{
	//debugger;
	var selectControl = document.getElementById(selectId);
	if(selectControl)
	{
		var selItemValue = selectControl.options[selectControl.selectedIndex].value;
		if(selItemValue != '')
		{
			//selItemValue = selItemValue.replace('/Home', '');
			//if(selItemValue != '') selItemValue += '.aspx';
			
	        document.location.href = selItemValue;
		}
	}
}
