﻿$(document).ready(function(){
	checkIcons();
	bottomMenu();	
	checkHref();
	$('.search input[type=text]').focus(function(){ clearValue($(this));});            
 $('.search-results input[type=text]').focus(function(){clearValue($(this));});
 
 $('input[type="file"]').addClass('file_field');        
	//if(pfConfigurator)runPf('AnimatedPictureFrame', pfConfigurator);
});

function checkIcons(){        
    $('.icons a,.footer-left a').each(function(index){        
        var currHref = location.href;
        var href = $(this).attr('href');        
        if (currHref.indexOf('_fr.html') != -1) lang = 'fr';
        else  lang = 'nl';          
        
        if(currHref.indexOf('index_') != '-1')            
            $('#home-conteiner').html('<img src="/site/core/images/home-passive.gif" alt="Home" />');            
        else{
            if(lang == 'fr')
                $('#home-conteiner').html('<a href="index_fr.html" title="Home"><img src="/site/core/images/home.gif" alt="Home" /></a>');                            
            else
                $('#home-conteiner').html('<a href="index_nl.html" title="Home"><img src="/site/core/images/home.gif" alt="Home" /></a>');                            
        }        
        
        if (lang == 'fr') 
            href = href.replace('_nl.html','_fr.html');
        else 
            href = href.replace('_fr.html','_nl.html');                    
        $(this).attr('href',href);
    });
}

function bottomMenu(){    
    var maxHeight = 0;
    var padding = 15;        
    $('#bottomMenu >li').each(function(){
        if($(this).attr('clientHeight') > maxHeight)
            maxHeight = $(this).attr('clientHeight');
    });    
    
    $('#bottomMenu >li').each(function(){        
        $(this).css('height',maxHeight -padding + 'px');
    });
}

function clearValue(obj)
{
    $(obj).attr('value','');
}

function checkHref(){            
    var currHref = location.href.toString();        
    var miId = '';
    if (currHref.indexOf('miId=') != -1){
        miId = currHref.substring(currHref.indexOf('miId='), currHref.length);
        $('a').each(function(){            
            if($(this).attr('needMiId') !== undefined){     
                var linkParams = '';                
                if($(this).attr('href').indexOf('?')!= -1)
                    linkParams = '&'+miId;
                else linkParams = '?'+miId;                
                
                $(this).attr('href',$(this).attr('href')+linkParams);
            }
        });
    }    
}

function runPf(name, conf){
	try{
		if (document.getElementsByName(name).length>1){
			/* Give  params to embed for FF */
			document.getElementsByName(name)[1].init(conf);
		}else{
			/* Give  params to object for IE */
			document.getElementsByName(name)[0].init(conf);
		}
	}
	catch(e){
		setTimeout(function(){runPf(name, conf)}, 200);
	}
}


function openDialog(params){
	params = params||{};
	
	var dialog = window.showModalDialog('/dialogs/commonPopupWindow.html',
		params, 'center:yes; dialogHeight:550px;resizable:yes;dialogWidth:550px ')

	if(params.answer.resCode == 'OK')
	{
		return params.answer;
	}	
}
