// ActionScript Document


function checkadded3d(){

	var nbchecked	=	0;

	$$('#listartwork-content input:checkbox').each(function(id){
			if(id.checked == true){
				nbchecked++;
			}
	});

	if(nbchecked == 0){
		alert('vous n avez selectionné aucune oeuvre ');
		window.location.href = '/?a=ControlPanel' ;
	}else{
		if(nbchecked > 25 ){
			alert(" vous n'avez pas le droit de selectionner plus de 25 oeuvres ");
		return false;
		}	
	}

	return true;
	
}


function confirmAction(theMessage)
{

    // TODO: Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(theMessage);

    return is_confirmed;
}

// Return Media
function callback_upload(file, completed, num_uploads)
{
	window.location= './?a=media';
}


function request_ajax(url, methode, id_dom)
{
	new Ajax.Request(url, {asynchronous:true, evalScripts:true, method:'post',  onSuccess:function(request){$('loading-mask').hide();}, onCreate:function(request){$('loading-mask').show();}, parameters:'is_ajax=1&methode='+methode+'&id_dom='+id_dom});
	return false;
}

function request_ajax_form(url, methode, id_dom, form)
{
	new Ajax.Request(url, {asynchronous:true, evalScripts:true, method:'post', onSuccess:function(request){$('loading-mask').hide();},onCreate:function(request){$('loading-mask').show();}, parameters:Form.serialize(form)+'&is_ajax=1&methode='+methode+'&id_dom='+id_dom});
	return false;
}


function request_ajax_auto(url, methode, id_dom, idfield)
{
	new Form.Element.Observer(idfield, 1, function(element, value) {
		new Ajax.Request(url, {asynchronous:true, evalScripts:true, onSuccess:function(request){$('loading-mask').hide();}, onCreate:function(request){$('loading-mask').show();}, parameters:'is_ajax=1&methode='+methode+'&id_dom='+id_dom+'&'+idfield+'='+value})
	});
	return false;
}

function translateGoogle(text, sl, tl, field){

	new Ajax.Request('./translate.php?text='+text+'&sl='+sl+'&tl='+tl+'&field='+field, {asynchronous:true, evalScripts:true, method:'post', onSuccess:function(request){$('loading-mask').hide();}, onCreate:function(request){$('loading-mask').show();}});

	return false;

}

function cadre(x) {
	if((x/10)<1) x="0"+x;
	var ids = new Array("imglh","imgch","imgrh","imglc","imgrc","imglb","imgcb","imgrb");
	for(i=0;i<ids.length;i++) {
		$(ids[i]).src = "./images/cadres/"+x+"_0"+(i+1)+".jpg";
	}
	return false;
}

function sizeCanva(l){
	var sizeCanva = $('sizeCanva');
	var v = (l) ? (parseInt(sizeCanva.value)+1) : (parseInt(sizeCanva.value)-1);
	if((v >= 0) && (v <= 3)){
		var g = (v*10);
		sizeCanva.value = v;
		$('imglh').width = g;
		$('imglh').height = g;
		$('imgch').height = g;
		$('imgrh').width = g;
		$('imgrh').height = g;
		$('imglc').width = g;
		$('imgrc').width = g;
		$('imglb').width = g;
		$('imglb').height = g;
		$('imgcb').height = g;
		$('imgrb').width = g;
		$('imgrb').height = g;
	}

	return false;
}

function printPage(obj, title)
{
      // Définit la zone à imprimer
      var zi = document.getElementById(obj).innerHTML;
      var Headers = '<!DOCTYPE HTML PUBLIC ><HTML><HEAD><link href="./styles/style.css" rel="stylesheet" type="text/css" /></HEAD><BODY style="background:#FFFFFF;color:black; background-color:#FFFFFF; padding:5px;" onload="window.print();window.close()">';
      var Footers = "</body></html>";
      // Ouvre une nouvelle fenetre
      var f = window.open("", title, "height=913, width=710,toolbar=0, menubar=0, scrollbars=1, resizable=1, status=0, location=0, left=10, top=10");

      // Définit le Style de la page
      f.document.body.style.color = '#000000';
      f.document.body.style.backgroundColor = '#FFFFFF';
      f.document.body.style.padding = "10px";

      // Ajoute les Données
      f.document.write ("" + Headers + zi +Footers);
      f.document.close();
      // Imprime et ferme la fenetre
      return false;
   }


/******* Disable Form **********/
function toggleTB(what){
	document.edit_user.user_password.disabled= (what.checked) ? 0 : 1;
	document.edit_user.user_password_conf.disabled= (what.checked) ? 0 : 1;
	document.edit_user.user_pwd.disabled= (what.checked) ? 0 : 1;
}


function checkHasGallerie2(_sid){

	var url	=	'/api.php?s=checkhasgallerie2&SID='+_sid;
	var reponse	=	false;

	new Ajax.Request(url, {
		asynchronous:false, 
		evalScripts:true, 
		method:'post', 
		onSuccess:function(request){
			reponse	=	request.responseText;
		}, 
	});
	


	if(reponse == 1){
		window.location.replace('./?a=ControlPanel&s=demo3D', 'Docs', 'divtwo');
	}else{
		alert("Vous devez d'abord enregistrer des oeuvres dans votre galerie ");
		return false;
	}

	return false;

}

function checkHasGallerie(_sid){

		var url	=	'/api.php?s=checkhasgallerie&SID='+_sid;
		var reponse	=	false;
		new Ajax.Request(url, {
							asynchronous:false, 
							evalScripts:true, 
							method:'post', 
							onSuccess:function(request){
								reponse	=	request.responseText;
							}, 
						});
		
		if(reponse == 1){
			var url	=	"/?a=ControlPanel&s=manage3D"; 
			
			window.location.replace(url);
			return false;
			
		}else{
			alert("Vous devez d'abord enregistrer des oeuvres dans votre galerie ");
			return false;
		}
}


