﻿

function confirmAndGo(url){
	if(confirm('Etes vous sur?')){
		window.location = url
	}
	else{
		return
	}
}

function popitup(url,name,height,width) {
	newwindow=window.open(url,name,'height='+height+',width='+width+',scrollbars=1');
	if (window.focus) {newwindow.focus()}
	return false;
}

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

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

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

//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 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'
	}
}

function display_document(documentName){
	if(document.getElementById('document_'+documentName).style.display == 'none'){
		document.getElementById('document_'+documentName).style.display = ''
		document.getElementById('document_'+documentName).style.backgroundColor = "#F2FCF4";
	}
	else{
		document.getElementById('document_'+documentName).style.display = 'none'
		document.getElementById('document_'+documentName).style.backgroundColor = "";
	}
}

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 openEditUnit(uid){
	obj = _$('edit_unit_'+uid);
	if(obj.style.display==""){
		obj.style.display='none';
	}
	else{
		obj.style.display='';
	}
}

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 backPicLeft(picName){
	document.getElementById('intro_left').style.backgroundImage = 'url(images/home/'+picName+')';
}

function backPicRight(picName){
	document.getElementById('intro_right').style.backgroundImage = 'url(images/home/'+picName+')';
}

function restorePicLeft(){
	document.getElementById('intro_left').style.backgroundImage = 'url(images/index/home_intro_buttons_middle.gif)';
}
function restorePicRight(){
	document.getElementById('intro_right').style.backgroundImage = 'url(images/index/home_intro_buttons_middle.gif)';
}

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