﻿

function confirmAndGo(url){
	if(confirm('Etes vous sur?')){
		window.location = url
	}
	else{
		return
	}
}
function popitup(url,name,height,width) {
	newwindow=window.open(url,'','height='+height+',width='+width+',scrollbars=1');
	if (window.focus) {newwindow.focus()}
	return false;
}



function loadProject(pid){
	window.location = "?page=event&p="+pid
}

function hide_text_edition(){
	obj = _$('texts_table');
	obj.style.display="none";
}

function show_text_edition(){
	obj = _$('texts_table');
	obj.style.display="";
}


function display_floor(floor){
	if(document.getElementById('floor_'+floor).style.display == 'none'){
		document.getElementById('floor_'+floor).style.display = ''
	}
	else{
		document.getElementById('floor_'+floor).style.display = 'none'
	}
	
}

//open and show image for lightshow form slideshow

function oifl(obj){

	if(obj.childNodes[1]){

		return obj.childNodes[1].src;

	}

	if(obj.childNodes[0]){

		return obj.childNodes[0].src;

	}

}



function projects_show(id){
	obj = _$(id);
	if(obj.style.display==""){
		obj.style.display='none';
	}
	else{
		obj.style.display='';
	}
}

function openUnit(uid){
	window.location = "?page=unit&uid="+uid
}

function saveTextsForm(){
	form = _$('texts_form');
	form.text_fr.value =  escape(WYSIWYG.getEditorWindow('text_editor_fr').document.body.innerHTML);
	form.text_en.value =  escape(WYSIWYG.getEditorWindow('text_editor_en').document.body.innerHTML);
	form.submit();
}

function translate(text,fromLang,toLang,container){
	if(confirm("Voulez vous vraiment traduire de "+fromLang+" à "+toLang)){
		length = text.length;
		
		end = 0;
		container.innerHTML = '';
		while(end < length){
			//get part of text
			charSub = text.substring(end+400,end+400+50);
			endCharPos =  charSub.search(' ')*1+end+400;
			
			part = text.substring(end,endCharPos);
			//alert(part);
			end = endCharPos;
			google.language.translate(part, fromLang, toLang, function(result) {
				if (!result.error) {
					container.innerHTML = container.innerHTML+' '+result.translation;
				}
				else{
					alert('Une erreur c\'est produite durant la traduction automatisée');
				}
			});
			
			
		}
		
	}
	else{
		return
	}
}


function _$(objId){
	return document.getElementById(objId);
}


