// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// ------------control.js inPlaceCollectionEditor surcharge -----------------------
/*Object.extend(Ajax.InPlaceEditor, {
  DefaultOptions: {
    ajaxOptions: { },
    autoRows: 3,                                // Use when multi-line w/ rows == 1
    cancelControl: 'link',                      // 'link'|'button'|false
    cancelText: 'cancel',
    clickToEditText: 'Click to edit',
    externalControl: null,                      // id|elt
    externalControlOnly: false,
    fieldPostCreation: 'activate',              // 'activate'|'focus'|false
    formClassName: 'inplaceeditor-form',
    formId: null,                               // id|elt
    highlightColor: '#ffff99',
    highlightEndColor: '#ffffff',
    hoverClassName: '',
    htmlResponse: true,
    loadingClassName: 'inplaceeditor-loading',
    loadingText: 'Loading...',
    okControl: 'button',                        // 'link'|'button'|false
    okText: 'ok',
    paramName: 'value',
    rows: 1,                                    // If 1 and multi-line, uses autoRows
    savingClassName: 'inplaceeditor-saving',
    savingText: 'Saving...',
    size: 0,
    stripLoadedTextTags: false,
    submitOnBlur: false,
    textAfterControls: '',
    textBeforeControls: '',
    textBetweenControls: ''
		collectionIndex: null // add collectionIndex opion**yl
  }
}); 
*/
/* Ajax.InPlaceEditor = Class.create({
  getText: function() { // manage the index if it is set **yl
		return this.options.collectionIndex || this.element.innerHTML.unescapeHTML();
	}
}); */
// -----------/ end control.js inPlaceCollectionEditor surcharge ------------------

Event.observe(window, 'load', function() {
  /* highlight flashes automatically */
  $A(document.getElementsByClassName('flash_notice')).each(function(o) {
     //new Effect.Highlight(o, {startcolor:'#38DB38', duration: 5});
    new Effect.Fade(o, {duration: 5});
  });
});
Event.observe(window, 'load', function() {
  /* highlight flashes automatically */
  $A(document.getElementsByClassName('flash_error')).each(function(o) {
     //new Effect.Highlight(o, {startcolor:'#DB3838', duration: 5});
    new Effect.Fade(o, {duration: 5});
  });
});

function box_over(el){
	$(el).visualEffect('Opacity', {duration: 0.5, from:1, to:0.50});
	$(el).setStyle("border:1px solid #cc33cc;");
}

function box_out(el){
	$(el).visualEffect('Opacity', {duration: 0.5, from:0.5, to:1});
	$(el).setStyle("border:1px solid #000000;");
}

function checkFocus(div)
{
	var val = document.getElementById(div).value;
	
	if(val==div)
	//if (val.include(div))
	{
		document.getElementById(div).value='';
	}
	else if(val=='')
	{
		document.getElementById(div).value=div;
	}
		
}
	
function checkChange(div)
{
	var val = document.getElementById(div).value;
	if(val=='')
	{
		document.getElementById(div).value=div;
	}
		
}

function resetRange(id)
{
	document.getElementById('range_to_'+id).value='';
	document.getElementById('range_from_'+id).value=''; 
}

function resetSingle(id)
{
	document.getElementById('single_'+id).value='';
	
}


var maxh = 0; var minh = 0; var posBot;
function setbot(el){ posBot = 0;
		//alert(posBot+' '+maxh);
 var mh = parseInt($('wp_content').getStyle('min-height'));
 var els=$('wp_content').getElementsByTagName("*");var i;
 $A(els).each( function(ele){ i++
	if (ele.id.split('_')[0] == 'box') {
		n = ele.id;
		var h = parseInt($(ele).getStyle('height')); 
		var o = ($(ele).offsetTop); //-parseInt($("banner_content").getStyle('height'));
		if (h+o > posBot ){posBot = h+o;};
		if(posBot < mh){posBot=mh} ; 
		//alert(h+' '+o+' '+(h+o)+' '+posBot+' '+n+' '+mh)
		//$('msga').update(n+' offset:'+o+' h:'+h+' - '+(h+o)+' '+posBot+' '+maxh+' '+minh);
	}
});
 //$A(els).each( function(one){ new Resize(one); });

 //var a = parseInt($(el).getStyle('top'));
	//$('msgb').update(n+' - '+posBot+' '+mh+' '+minh);
	//$('msg').update('offset:'+o+' h:'+h+' top:'+a+' - '+posBot+' '+mh+' '+minh);
 	$('wp_content').setStyle({height:posBot+'px'});
}
function updatepos(el){
	new Ajax.Request('/backend/wboxes/update_tag',{
		//onComplete: function(el){},
		parameters: { id:el.split("_")[1],
			x:parseInt($(el).getStyle('left')),
			y:parseInt($(el).getStyle('top')),
			w:parseInt($(el).getStyle('width')),
			h:parseInt($(el).getStyle('height')),
			posBot:posBot
		}
	});
}
function getpos(el){
	//var d = draggable.element.getDimensions(el);
	var l = $(el).getStyle('left');
	var t = $(el).getStyle('top');
	var w = $(el).getStyle('width');
	var h = $(el).getStyle('height');
	var b = $(el).getStyle('bottom'); //pas avec ie
	var r = $(el).getStyle('right'); //pas avec ie
	//$("msg").update('w:'+w+' h:'+h+' l:'+l+' t:'+t);
}
function resize_all(cont){
 Resizes.destroy();
 var els=$(cont).getElementsByTagName("*");
 $A(els).each( function(one){ new Resize(one); });
}
function resize_kill(box){
 Resizes.destroy(box);
}
function resize_init(cont){
 var els=$(cont).getElementsByTagName("*");
 $A(els).each( function(one){ new Resize(one); });
 //new Resize(box);
}
//function ImageBrowser(field_name, url, type, win) {
//	 window.open('http://www.google.com','mywindow','width=400,height=200');
// } 
 function ImageBrowser(field_name, url, type, win) {
   var fileBrowserWindow = new Array();
   fileBrowserWindow['title'] = 'Image Browser';
   fileBrowserWindow['file'] = "/backend/pics/listpics";
   fileBrowserWindow['width'] = '950';
   fileBrowserWindow['height'] = '350';
   fileBrowserWindow['close_previous'] = 'no';
   fileBrowserWindow['resizable'] = 'yes';
   fileBrowserWindow['inline'] = 'yes'; //js popup inside browser
   tinyMCE.activeEditor.windowManager.open(fileBrowserWindow, {
     window : win,
     input : field_name
   });
   return false;
}
function ed_on(edId) {
	var but1 = edId+"_on";var but2 = edId+"_off";
	tinyMCE.execCommand('mceAddControl', false, edId);
	$(but1).toggle();
	$(but2).toggle();
}
function ed_off(edId) {
	var but1 = edId+"_on";var but2 = edId+"_off";
	tinyMCE.execCommand('mceFocus', false, edId);                    
	tinyMCE.execCommand('mceRemoveControl', false, edId);
	$(but1).toggle();
	$(but2).toggle();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function show_image(name,id,type){
	
}
var Popup = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 600,
      height: 500,
      name:"_blank",
      location:"no",
      menubar:"no",
      toolbar:"no",
      status:"yes",
      scrollbars:"yes",
      resizable:"yes",
      left:"",
      top:"",
      normal:false
    }
    Object.extend(this.options, options || {});

    if (this.options.normal){
        this.options.menubar = "yes";
        this.options.status = "yes";
        this.options.toolbar = "yes";
        this.options.location = "yes";
    }

    this.options.width = this.options.width < screen.availWidth?this.options.width:screen.availWidth;
    this.options.height=this.options.height < screen.availHeight?this.options.height:screen.availHeight;
    var openoptions = 'width='+this.options.width+',height='+this.options.height+',location='+this.options.location+',menubar='+this.options.menubar+',toolbar='+this.options.toolbar+',scrollbars='+this.options.scrollbars+',resizable='+this.options.resizable+',status='+this.options.status
    if (this.options.top!="")openoptions+=",top="+this.options.top;
    if (this.options.left!="")openoptions+=",left="+this.options.left;
    window.open(this.options.url, this.options.name,openoptions );
    return false;
  }
}

