﻿function openPopUp(pUrl,w,h) {	
	var l= getWindowPosition("width")-(w/2);
	var t= getWindowPosition("height")-(h/2);
	window.open(pUrl, 'popUp', 'width='+w+',height='+h+',left='+l+',top='+t+',resizable=yes');
}

function getWindowPosition(dim){
  var myWidth = 0, myHeight = 0;
// a little check cos IE doens't support window innerWidth

  if(typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
 
    theTop = document.documentElement.scrollTop;
    theHeight = window.innerHeight/2;
  
	theLeft = document.documentElement.scrollLeft;
    theWidth  = window.innerWidth/2;
    
    myWidth = theLeft+theWidth;
    myHeight = theTop+theHeight;

  }
  else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight )) {
    //IE 6+ in 'standards compliant mode'
    theTop = document.documentElement.scrollTop;
    theHeight = document.documentElement.clientHeight/2;
  
	theLeft = document.documentElement.scrollLeft;
    theWidth  = document.documentElement.clientWidth/2;
       
    myWidth = theLeft+theWidth;
    myHeight = theHeight+theTop;

  } else if( document.body && (document.body.clientWidth || document.body.clientHeight )) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  if(dim == 'width'){
	return myWidth;
  }
  else{
	return myHeight;
  }

}

function changeJobSelection()
{
	//document.location.href =document.getElementById("selectBranch").options[document.getElementById("selectBranch").selectedIndex].value;
	var newid = document.getElementById("findJobCenter").options[document.getElementById("findJobCenter").selectedIndex].value;
	
	var oldlocation = new String(document.location);
	//alert(oldlocation);
	
	var arrayloc = oldlocation.split("?");
	//alert(arrayloc[0]);
	
	var newloc;
	if (newid != ''){
		newloc = arrayloc[0] + "?jobid=" + newid;
	}
	else{
		newloc = arrayloc[0];
	}
	//alert(newloc);
	document.location.href = newloc;
}


// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}


function doSearch()
{

	var query = location.href;
	var urlarray = query.split('?');
	var urlf = urlarray[0];
	
	var txtSearch = document.getElementById("txtPageSearch");
	if (txtSearch != null )
	{
		txtSearchValue = txtSearch.value;
	}
	var searchCategoryValue="";
	var searchSubCategoryValue="";
	if (trim(txtSearchValue)!='')
	{
		query = urlf + "?q=" +txtSearchValue+'&l=1';
		 
		var searchCategory = document.getElementById("searchCategory");
		if (searchCategory != null ) 
		{
			searchCategoryValue = searchCategory.value;
			query+='&categ='+searchCategoryValue;
			
			if (trim(searchCategoryValue) !='0')
			{
				query+='&mc=scCategory=:'+searchCategoryValue;
			}	
		}
		var searchSubCategory = document.getElementById("searchSubCategory");
		if ((searchSubCategory != null)  && (trim(searchSubCategoryValue) !='0'))
		{
			searchSubCategoryValue = searchSubCategory.value;
			query+='&subCateg='+searchSubCategoryValue;
			
			if (trim(searchSubCategoryValue) !='0')
			{
				query+='&mc=scSubCategory=:'+searchSubCategoryValue;
			}
			
		}
	}	
	
	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;
	}
		
}
// ** IMAGE ZOOM FRA SAMSPIL ** //
function make_image_onclick(){
//	$(".image-zoom").wrap('<div class="image-zoom-wrapper" style="text-align:center"/>');
//      $(".image-zoom").after('<a href="#error" class="image-zoom-link">Forstør</a>');
	$(".image-zoom").css({'cursor':'pointer','width':'150px','height':'auto','display':'block','margin':'auto'});
	$(".image-zoom").click(function(){
		show_image(this);
	});
}
function show_image(obj){
	var url = obj.src;
//        var url = obj;
	var imgbg = document.createElement("div");
	imgbg.setAttribute("id","showbigimagebg");
	imgbg.style.height = document.body.scrollHeight + "px";
	imgbg.style.width = document.body.scrollWidth + "px";
	imgbg.title = "Luk";
	document.body.appendChild(imgbg);
	imgbg.setAttribute("onclick","hide_image()");
	imgbg.onclick = function(){hide_image();};
	var img = document.createElement("img");
	img.src = url;
	img.setAttribute("id","showbigimage");
	img.setAttribute("onclick","hide_image()");
	img.title = "Luk";
	img.onclick = function(){hide_image();};
	img.style.top = (get_scroll_top()+10) + "px";
	img.style.left = (get_scroll_left()+10) + "px";
	document.body.appendChild(img);
}
function hide_image(){
	var img = document.getElementById("showbigimage");
	var imgbg = document.getElementById("showbigimagebg");
	document.body.removeChild(img);
	document.body.removeChild(imgbg);
}
function get_scroll_top(){
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0){
		if (window.pageYOffset){
			ScrollTop = window.pageYOffset;
		}
		else{
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
	return ScrollTop;
}
function get_scroll_left(){
	var ScrollLeft = document.body.scrollLeft;
	if (ScrollLeft == 0){
		if (window.pageXOffset){
			ScrollLeft = window.pageXOffset;
		}
		else{
			ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
		}
	}
	return ScrollLeft;
}

// IMAGE ZOOM SLUT ** //
