 

function setAction(action) {
		
		document.getElementById('action').value = action;
		try{
			document.applyForm.submit();
		}catch(err){
			alert("Bestandspad is onjuist!");
		}
}
/* 
	Author: b.ivanovic
	Version: 0.1
*/
function hideElement(id)
{
	var element = document.getElementById(id);
	if(element!=null)
		element.style.display ='none';
}
/* 
	Author: b.ivanovic
	Version: 0.1
*/
function showElement(id)
{
	var element = document.getElementById(id);
	if(element!=null)
		element.style.display ='block';
}

function setElementVisibility(elementId,visibility)
{    
    var elem = document.getElementById(elementId);
    if(null!=elem)
    {
        if("true" == visibility || visibility == true)
            elem.style.display = "";
        else if("false" == visibility || visibility == false)
            elem.style.display = "none";
    }       
}

/* 
	Author: b.ivanovic
	Version: 0.1
*/

function goToTarget(targetN, myForm) {
	
	/*var nextPage = myForm.elements['nextPage'];
	if(nextPage!=null)
		myForm.elements['nextPage'].setAttribute('value',targetN);*/
	myForm.elements['target'].setAttribute('name','_eventId_target' + targetN);
	myForm.submit();
}
/* 
	Author: b.ivanovic
	Version: 0.1
*/
function goToTargetOfWizard(targetN, myForm) {

	myForm.elements['target'].setAttribute('name','_target' + targetN);
	myForm.submit();
}
/* 
	Author: b.ivanovic
	Version: 0.1
*/
function goToFinish(myForm){
	myForm.elements['target'].setAttribute('name','_finish');
	myForm.submit();
}
/* 
	Author: b.ivanovic
	Version: 0.1
*/
function mySettingsOnLoad(myForm)
{
	//myForm.baseURI = myForm.baseURI.replace("?_target1","");
	enableDisableMagazineAddress();
}

function addLoadEvent(func) {
	if (typeof document.attachEvent!='undefined') {
		window.attachEvent('onload',func);
	} else {
		window.addEventListener('load',func,false);
	}
}

function addLoadEventNetwork(func) {
	jQuery.noConflict();
	if (typeof document.attachEvent!='undefined') {
		window.attachEvent('onload',func);
	} else {
		window.addEventListener('load',func,false);
	}
}


/* 
	Author: b.ivanovic
	Version: 0.1
*/
function enableDisableMagazineAddress()
{
	var receiveMagazinesOnWork = document.getElementById('receiveMagazinesOnWork1');
	if (receiveMagazinesOnWork == null)
		return;
	
	var receiveMagazines = document.getElementById('receiveMagazines1');
	if(receiveMagazines.checked)
	{
		receiveMagazinesOnWork.disabled = false;
		document.getElementById('receiveMagazinesAddressLabel').className = 'blackText';
	}
	else
	{
		receiveMagazinesOnWork.disabled = true;
		document.getElementById('receiveMagazinesAddressLabel').className = 'darkGrayText'; 
	}
}

/* 
	Author: b.ivanovic
	Version: 0.1
*/
function enableInformedByOther()
{
	var selectBox = document.getElementById('foundJobBy');
	if(selectBox != null)
	{
		var id = selectBox.options[selectBox.selectedIndex].value;
		var textarea = document.getElementById('foundJobByOther');
		var label = document.getElementById('findByOtherLabel');
		if (id==0)
		{
			textarea.disabled = false;
			label.className = 'blackText';
		}
		else
		{
			textarea.disabled = true;
			label.className = 'darkGrayText';
		}
	}
}


/* 
	Author: b.ivanovic
	Version: 0.1
*/
function displayMockEmail()
{
	var receiveMagazine = document.getElementById('receiveMagazines');
	if(receiveMagazine.checked)
	{
		hideElement('privateEmailMock');
		showElement('privateEmailReal');
	}
	else
	{
		var email = document.getElementById('person.privateContactInformation.email');
		var emailUsername ="";
		if (email.disabled)  //  ako je privatni email disableovan, znaci da je on ujedno i username
		{
			emailUsername = email.value;
		}
		else
		{
			email = document.getElementById('person.workContactInformation.email');
			emailUsername = email.value;
		}
		
		hideElement('privateEmailReal');
		showElement('privateEmailMock');
		document.getElementById('inputMockEmail').value = emailUsername;
	}	
}


function redir(url){
 	location.href = url;
}
/* 
	Author: b.ivanovic
	Version: 0.1
*/
function openPopup(popupUrl){

	var width = 460;
	var height = 220;	
	var left = Math.floor( (screen.width - width) / 2);
   	var top = Math.floor( (screen.height - height) / 2);
   	var winParms = "menubar=no, toolbar=no, top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;

	newwindow=window.open(popupUrl,"popup", winParms);
	if (window.focus) 
	{
		newwindow.focus()
	}
}

function openInNewWindow(url){
	
	newwindow=window.open(url,'name','');
	if (window.focus) 
	{
		newwindow.focus()
	}
}

/* 
	Author: b.ivanovic
	Version: 0.1
*/      
function refreshImage(imageDivId){
	document.getElementById(imageDivId).src = document.getElementById(imageDivId).src + '#';
}

function fillField(source, field)
{
	if (field != null)
	{
		field.value = source.value;
	}
}

/* 
	Author: a.stoisavljevic
	Date: April 2008.
	Version: 0.1
	
	functions for comments on one article
*/

var returnValue = "status";

function showCommentForm(divId, contentItemId) {
	document.getElementById("news_vertical_menu_container").style.height = null;
	document.getElementById("news_center_column").style.height = null;
	document.getElementById("news_right_column").style.height = null;
	if ( $(divId+"_"+contentItemId).visible() ) {
		$(divId+"_"+contentItemId).toggle();
	} else {
		$("reageerDiv_123").hide();
		clearCommentForm(123);
		$(divId + "_" + contentItemId).show();
	}
	adjustSizes();
	return false;		
}

function clearCommentForm(contentItemId) {
	commentText = $("comment_text_"+contentItemId);
	commentText.update("");
	commentText.className = "";
}


function toggleSubmitButton() {
	frm = document.commentForm;
	if ( frm.agreeTerms.checked ) {
		frm[4].disabled = false;
	} else {
		frm[4].disabled = true;
	}	
}

function showLogin() {
	if (window.location.href.search("#login") != -1) {
		window.location.href = "#";
	}
	
	var elem = document.getElementById("popupContainer");
	
	if (typeof elem == 'undefined' || elem == null) {
		initPopUp();
	}
	showPopWin('/login.htm', 564, 285, null);
}

// jos ne radi
function loginAndSubmit(submitForm) {
	if (window.location.href.search("#login") != -1) {
		window.location.href = "#";
	}
	
	var elem = document.getElementById("popupContainer");
	
	if (typeof elem == 'undefined' || elem == null) {
		initPopUp();
	}
	showPopWin('/login.htm?', 564, 285, null);
}

function showLoginCallback(returnVal) {
	if (typeof returnVal != 'undefined' && returnVal == true) {
		window.top.showPopWin('/login.htm', 564, 310, null);
	} else {
		window.top.showPopWin('/login.htm', 564, 285, null);
	}
	window.top.returnVal = returnVal;
}

function showPasswordForgot() {
	window.top.hidePopWin();
	window.top.showPopWin('/passwordForgot.htm', 564, 260, window.top.showLoginCallback);	
}

function showPasswordForgot2() {
	window.top.showPopWin('/passwordForgot.htm', 564, 260, null);	
}

// =================================
// Author: a.stoisavljevic
// check if cookies are enabled
// =================================
/* this code is not necessery
function SetCookie(name,value,expires,path,domain,secure) {
	var strDNS = GetDNS();
	document.cookie = name + "=" +escape(value) +
		( (expires) ? ";expires=" + expires.toGMTString() + 1000*60*20 : "") +
		( (path) ? ";path=" + path : "") +
		( (domain) ? ";domain=" + strDNS : "") +
		( (secure) ? ";secure" : "");
		return true
}

function GetDNS() {
	cookieDomain = document.location.hostname;
}

function GetCookie() {
	var strName = "varCook";
	if (document.cookie.indexOf(strName) == -1) {
		alert("Cookies ARE NOT currently enabled!\nPlease read below on this page for information on how to enable cookies.");
		return false;
	}
	else {
		cookieStart = document.cookie.indexOf(strName);
		alert("CookieStart" + cookieStart);
	        cookieValStart = (document.cookie.indexOf("=", cookieStart) + 1);
		alert("CookieValStart: " + cookieValStart);
	        cookieValEnd = document.cookie.indexOf(";", cookieStart);
		alert("CookieValEnd: " + cookieValEnd);
        	if (cookieValEnd == -1) {
        		cookieValEnd = document.cookie.length;
			alert("CookieValEnd: " + cookieValEnd);
	        }
		cookieValue = document.cookie.substring(cookieValStart, cookieValEnd);
		alert("CookieValue: " + cookieValue);
	    }
	    if (cookieValue = "True") {
    		return true;
	    }
}
*/
function CheckCookiesEnabled()        
{           
		/*
        SetCookie('varCook','True','','/','','');
        if ( GetCookie() ){
            alert('Cookies are enabled and you can properly use this website!');
        } else {        
            alert('Cookies ARE NOT  enabled and you CAN NOT properly use this website!');
        }
        */
        if (navigator.cookieEnabled) {
        	// alert("Cookie enabled!");
        } else {
        	// alert("Disabled!");
        	document.location.href='/nocookies.htm';
        }       
}      
// ================
// = Form Helpers =
// ================

// Clears previously filled in form fields
function clearFields( _id ) {
	var form = $( _id );
	var fields = form.getElements();
	for ( i=0; i<fields.length; i++ ) { fields[i].value = ""; }	
}

// Zeros drop-down form field
function zeroField( _id ) {
	var form = $( _id );
	var fields = form.getElements();
	for ( i=0; i<fields.length; i++ ) { fields[i].value = 0; }	
}

// This still sucks
function is_valid_email_address(_str) {
    var r = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
    if (r.test(_str)) {
        return true;
    }
    return false;
}
function is_not_blank(_str) {
    if (_str.length > 0) {
        return true;
    }
    return false;
}

/* 
	Author: b.ivanovic
	Version: 0.1
*/
function getAllSubLevelOrganizations(organizationId, emptyText) 
{
	var selectBox = document.getElementById('currentEmployingSubLevelCompanyId');
	selectBox.disabled = true;
	if (organizationId == 5){
		selectBox.selectedIndex = -1;
	 	selectBox.options.length = 0;
	 	return;
	}
	OrganizationsDWR.getAllSubLevelOrganizations(organizationId, {
		callback:function(organizations) { getOrganizationsCallback(organizations, emptyText); } 
	});
}

/* 
	Author: b.ivanovic
	Version: 0.1
*/
function getOrganizationsCallback(organizations, emptyText)
{
	var selectBox = document.getElementById('currentEmployingSubLevelCompanyId');
	selectBox.options.length = 0;
	if (organizations!=null)
	{
		var dropDownIndex = 0;
		if (emptyText != null){
			selectBox.options[dropDownIndex] = new Option(emptyText, "-1");
			dropDownIndex++;
		}
		for(i=0; i<organizations.length; i++)
		{
			selectBox.options[dropDownIndex] = new Option(organizations[i].tagName, organizations[i].tagId);
			dropDownIndex++;
		}
	}else{
		selectBox.options[0] = new Option(emptyText, "-1");
	}
	document.getElementById('currentEmployingSubLevelCompanyId').disabled = false;
}


function checkAuthBeforeGoingToMySettings()
{
	checkAuthBeforeGoingToUrl('myAccount.htm?pageIndex=1');
	
	return false;
}

function checkAuthBeforeGoingToUrl(url)
{
	UserDWR.isAuthenticatedRegisteredUser({
		callback:function(result) { checkAuthBeforeGoingToUrlCallback(result, url); } 
	});
	
	return false;
}

function checkAuthBeforeGoingToUrlCallback(result, url)
{
	if (result) {
		redir(url);
	} else {
		showLogin();
	}
}

/* 
	Author: b.ivanovic
	Version: 0.1
*/
function finishMyAccountWizard()
{
	var myForm = document.registrationForm;
	if (myForm != null)
		goToFinish(myForm);
	else
	{
		myForm = document.mySettingsForm;
		if (myForm!=null)
			goToFinish(myForm);
	}
}

function showReactionBoxIfNotExpired(){
	UserDWR.hasAuthenticationExpiredForKnownUser({
		callback:function(expired) {showReactionBoxIfNotExpiredCallback(expired);} 
	});
}

function showReactionBoxIfNotExpiredCallback(expired){
	if (expired){
		showLoginForReaction();
	}else{
		return showCommentForm('reageerDiv', 123);
	}
}

function showLoginForReaction() {
	window.location.href = "#commentForm"
	var elem = document.getElementById("popupContainer");
	
	if (typeof elem == 'undefined' || elem == null) {
		initPopUp();
	}
	showPopWin('/login.htm', 564, 285, null);
}

function showAutocompleteForAdvancedSearch(organizationId, textToSearch, displayList) 
{
	OrganizationsDWR.getAllSubLevelOrganizationsForName(organizationId, textToSearch, {
		callback:function(organizations) {showAutocompleteForAdvancedSearchCallback(organizations, displayList);} 
	});
}


function showAutocompleteForAdvancedSearchCallback(organisations, displayList)
{
	var selectElement = document.getElementById("autocompleteSelect");
	selectElement.options.length = 0;
	if (organisations != null && organisations.length > 0)
	{
		for(i=0; i<organisations.length; i++)
		{	
			selectElement.options[i] = new Option(organisations[i].tagName, organisations[i].tagId);
		}
		if (displayList){
			document.getElementById("autocompleteDiv").style.display = "block";
		}else{
			document.getElementById("autocompleteDiv").style.display = "none";
		}
	}
}

/* 
	Author: s.bogdanovic
	Version: 0.2
*/
function adjustSizes(){
	var contentDiv;
	//Sometimes there is a div with class 'content' under 'main_content' div.
	var contentDivArray = $('main_content').getElementsByClassName('content');
	
	//if there 'content' div exists under 'main_content' use it as container
	if(contentDivArray.length > 0){ 
		contentDiv = contentDivArray[contentDivArray.length-1];
	}else{
		//'main_content' is container
		contentDiv = $('main_content');
	}
	
	//get container children
	var childrenList = $(contentDiv).childNodes;
	var nodes = $A(childrenList);
	
	var height = $(contentDiv).getDimensions().height+'px';
	//adjust heights of container first level children
	nodes.each(function(node){
		if(node.nodeName=='DIV' && node.className!='SDU_navigator' && node.className!='clear'){
			$(node).top = contentDiv.offsetTop;
			
			node.style.height = height;
		}
	});
	
	//debug
	/*
	nodes.each(function(node){
		if(node.nodeName=='DIV' && node){
			alert($(node).getHeight() );
		}
	});*/
}

/*
	Author: s.bogdanovic
	Version: 0.2
*/
function checkImages()
{
	var Imgs = document.getElementsByTagName("img");
	var intNumofImgs = Imgs.length;
	for ( var i = 0 ; i < intNumofImgs ; i++ )
	{
		if (Imgs[i].complete == false)
		Imgs[i].style.display='none';
	}
	
	var articleItems = $('main_content').getElementsByClassName('homepage_article_item');
	var nodes = $A(articleItems);
	nodes.each(function(node){
		var imgs = $A($(node).getElementsBySelector('img'));
		imgs.each(function(img){
			if(!isImageOk(img)){
				//alert('notOk');
				var article = $(img.parentNode.parentNode).getElementsByClassName('news_first_article')[0];
				if(article){
					$(article).className='';
					img.parentNode.style.display='none';
				}
				article = $(img.parentNode.parentNode).getElementsByClassName('homepage_first_article')[0];
				if(article){
					$(article).className='';
					img.parentNode.style.display='none';
				}
			}
			//else alert('ok');
		});
	});
}

/*
	Author: s.bogdanovic
	Version: 0.1
*/
function isImageOk(img) {
    // During the onload event, IE correctly identifies any images that
    // weren't downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.
    if (!img.complete) {
        return false;
    }
    // However, they do have two very useful properties: naturalWidth and
    // naturalHeight. These give the true size of the image. If it failed
    // to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }
    // No other way of checking: assume it's ok.
    return true;
}

function checkMenuItems(activeMainNavItem, activeSubNavItem){
	try{
		//alert(activeMainNavItem);
		if(activeMainNavItem){
			var activeItem = $(activeMainNavItem);
			//alert(activeItem);
			$(activeItem).className=$(activeItem).className+'Selected';
		}
		if(activeSubNavItem){
			//alert(activeSubNavItem);
			if(activeMainNavItem == 'mn_netwerk')
			{
				$(activeSubNavItem).className=$(activeSubNavItem).className + 'Selected'
			}
			else
				$(activeSubNavItem).className='snActive';
		}
	}catch(error){}
}

function checkinput()
{	
	
		var textentered = document.getElementById('keywordsForSearchUnique').value;
		textentered = textentered.replace(/^\s*/, "").replace(/\s*$/, "");
			
		if ((textentered.length > 0 )){
			document.getElementById('newsSmallSearchFormHeader').submit();
		}
	 
}

function handleKeypressEvent(event) {
 if (!event) { // IE comaptibility
  event = widow.event;
 }
 if (event.keyCode == '13') {
    	var textentered = document.getElementById('keywordsForSearchUnique').value;
		textentered = textentered.replace(/^\s*/, "").replace(/\s*$/, "");
			
		if ((textentered.length > 0 )){
		 	document.getElementById('newsSmallSearchFormHeader').submit();
	  	}
    
 }
}

function changeURL(choosen){

	switch(choosen){
		case "1" : document.getElementById('a1').setAttribute('href','/newssearch.htm')
			break;
		case "2" : document.getElementById('a1').setAttribute('href','/vacatureszoeken.htm')
			break;
		case "3" : document.getElementById('a1').setAttribute('href','/networkSearchResults.htm')
			break;
	}
}

/**  
 * a.stoisavljevic changed these pages to be modal
 */
function showRegisterBenefits() {
	showPopWin('/registerBenefits.htm', 500, 300);
}

function showRegistrationConditions() {
	showPopWin('/registrationConditions.htm', 500, 300);
}

function showPrivacyPolicy() {
	showPopWin('/privacy.htm', 550, 300);
}

function goToHomeFromSubmodal() {
	window.top.hidePopWin();
	window.top.location = "home.htm";
}

function goToRegistrationConditionsFromSubmodal() {
	window.top.hidePopWin();
	window.top.showPopWin('/registrationConditions.htm', 500, 300);
}

function goToRegisterFromSubmodal() {
	window.top.hidePopWin();
	window.top.location = "register.htm";
}

function clearTextFromField(field) {
	if(field.defaultValue == field.value ){
		field.value = "";
	}else if(field.value == ""){
		field.value = field.defaultValue;
	}
}
