var ajaxObjects = new Array();
function getDataFromForm(Form, ajaxObj) {
    var data= new Array();
    var key=0;
    for (key=0;key<Form.elements.length;key++) {
        switch(Form.elements[key].type){
            case 'checkbox': var currentValue = getValueFromChk(Form.elements[key]);
                break;
            case 'radio': var currentValue = getValueFromChk(Form.elements[key]);
                break;
            default: var currentValue = (Form.elements[key].tagName.toLowerCase()=="select")?getSelectValue(Form.elements[key]): Form.elements[key].value;
                break;
        }

        if(currentValue != undefined && currentValue != ''){
            ajaxObj.setVar (Form.elements[key].name, currentValue);
        }
    }  
} 
function getValueFromChk(obj) {  
   if(obj.checked){
        return obj.value;
   }else{
        return '';
   }
}  
function getSelectValue(select) {  
   var value="";
    for (var i=0; true; i++) {
        if (select[i]) {
            if (select[i].selected) {
                value += select[i].value + ",";
            }
        } else {
            return value.substr(0, value.length-1); 
        }  
    } 
}

function noaccent(obj, target) {
		  chaine = obj.value;
		  chaine = chaine.toLowerCase();
		  temp = chaine.replace(/[àâä]/gi,"a");
		  temp= trim(temp);
		  temp = temp.replace(/[éèêë]/gi,"e");
		  temp = temp.replace(/[îï]/gi,"i");
		  temp = temp.replace(/[ôö]/gi,"o");
		  temp = temp.replace(/[ùûü]/gi,"u");
		  temp = temp.replace(/[ç]/gi,"c");
		  temp = temp.replace(/[ ]/gi,"-");
		  temp = temp.replace(/[\/]/gi,"-");
		  temp = temp.replace(/[']/gi,"-");
		  temp = temp.replace(/[’]/gi,"-");
		  temp = temp.replace(/[(]/gi,"-");
		  temp = temp.replace(/[\[]/gi,"-");
		  temp = temp.replace(/[\]]/gi,"-");
		  temp = temp.replace(/[)]/gi,"-");
		  temp = temp.replace(/[:]/gi,"-");
		  temp = temp.replace(/[,]/gi,"-");
		  temp = temp.replace(/[;]/gi,"-");
		  temp = temp.replace(/[\.]/gi,"-");
		  temp = temp.replace(/["]/gi,"-");
		  temp = temp.replace(/-----/gi,"-");
		  temp = temp.replace(/----/gi,"-");
		  temp = temp.replace(/---/gi,"-");
		  temp = temp.replace(/--/gi,"-");
		  //temp = temp.trimtiret();
		  document.getElementById(target).value = temp;
		}

function trim(s) {
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
}

function isEmail(strSaisie) {  
    var verif = /^[^@]+@(([\w\-]+\.){1,4}[a-zA-Z]{2,4}|(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5]))$/  
    return ( verif.test(strSaisie) );  
}

/*
    domEl() function - painless DOM manipulation
    written by Pawel Knapik  //  pawel.saikko.com
*/
var domEl = function(e,c,a,p,x) {

    if (!c) c='';
    if(e||c) {
        //c=(typeof c=='string'||(typeof c=='object'&&!c.length))?[c]:c;
        
        //commentaire 84 sur pawel.saikko.com
       if (typeof c=='string') {
             c = c.length ? [c] : [];
            } else if (typeof c=='object' && !c.length) {
             c = [c];
        }
        //fin commentaire 84
        
        e=(!e&&c.length==1)?document.createTextNode(c[0]):e;
        var n = (typeof e=='string')?document.createElement(e) :
        !(e&&e===c[0])?e.cloneNode(false):e.cloneNode(true);
        if(typeof e=='string' || e.nodeType!=3) {
            c[0]===e?c[0]='':'';
            for(var i=0,j=c.length;i<j;i++) typeof c[i]=='string'?n.appendChild(document.createTextNode(c[i])):n.appendChild(c[i].cloneNode(true));
            
            //if(a){for (i in a) i=='class'?n.className=a[i]:n.setAttribute(a[i][0], a[i][1]);}
            if(a){
                for (var i = 0; i < a.length; i++){ 
                    a[i][0]=='class'?n.className=a[i][1]:n.setAttribute(a[i][0], a[i][1]);
                }
            }
        }
    }
    if(!p) { return n; }
    p=(typeof p=='object'&&!p.length)?[p]:p;
    for(var k=(p.length-1);k>=0;k--) {
        if(x){while(p[k].firstChild)p[k].removeChild(p[k].firstChild);
            if(!e&&!c&&p[k].parentNode)p[k].parentNode.removeChild(p[k]);}
        if(n) p[k].appendChild(n.cloneNode(true));
    }
    return true;
}


/*
	getElementsByClass - algorithm by Dustin Diaz, shortened by Pawel Knapik
	s = searchClass la class recherché
    n = node le noeud dans lequel la class d'oit être cherché
    t = tag le type d'élément html (div, span, a,...)
*/
function getElementsByClass(s,n,t) {
	var c=[], e=(n?n:document).getElementsByTagName(t?t:'*'),r=new RegExp("(^|\\s)"+s+"(\\s|$)");
	for (var i=0,j=e.length;i<j;i++) r.test(e[i].className)?c.push(e[i]):''; return c }
	
/*
	$() based on prototype.js dollar function idea, optimized by Pawel Knapik.
*/
function $g(){var r=[],a=arguments;for(var i=0,j=a.length;i<j;i++){(typeof a[i]=='string')?(r.push(document.getElementById(a[i]))):(r.push(a[i]))}
return(r.length==1)?r[0]:r}



function getAncestorByTagName( node, tag ) {

    var ancestor = node.parentNode;
    if ( ancestor == null ) return null;
    if ( ancestor.nodeName == tag.toUpperCase() ) return ancestor;
    else return getAncestorByTagName(ancestor, tag);

} // end of 'getAncestorByTagName()'

function getPreviousSiblingByTagName( node, tag ) {

    var sibling = node.previousSibling;
    if ( sibling == null ) return null;
    if ( sibling.nodeName == tag.toUpperCase() ) return sibling;
    else return getPreviousSiblingByTagName(sibling, tag);

} // end of 'getPreviousSiblingByTagName()'


function getNextSiblingByTagName( node, tag ) {

    var sibling = node.nextSibling;
    if ( sibling == null ) return null;
    if ( sibling.nodeName == tag.toUpperCase() ) return sibling;
    else return getNextSiblingByTagName(sibling, tag);

} // end of 'getNextSiblingByTagName()'


/**** positionne un élément au centre de la fenètre *****/
function elCenter(el){
    if(el){
        el.style.position = 'absolute';
        var bdy_st = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
        windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
        windowWidth  = window.innerHeight ? window.innerWidth : document.documentElement.clientWidth;
        windowHeight = windowHeight - el.offsetHeight;
        windowWidth =  windowWidth - el.offsetWidth;
        el.style.marginTop = ((windowHeight /2) + bdy_st) + 'px';
        el.style.marginLeft = (windowWidth /2)  + 'px';
        el.style.visibility = "visible";
    } 
}

function onChangeWindowWH(w, h){
    windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
    windowWidth  = window.innerHeight ? window.innerWidth : document.documentElement.clientWidth;
    if(w != windowWidth || h != windowHeight){
        elCenter(document.getElementById('light-box-modif'));
    }
    
    if(document.getElementById('light-box-modif')){
            window.setTimeout(function() {
                    onChangeWindowWH(windowWidth, windowHeight);
                }, 300);
        }
}    

function getTopPos(inputObj)
{
  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
  return returnValue;
}

function getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
  return returnValue;
}

function trim(str) {
    var regExpEnd       = /\s+$/;
    var regExpBeginning = /^\s+/;
    str = str.replace(regExpBeginning, "").replace(regExpEnd, "");
    str = str.replace(regExpEnd, "");
    return str;
}

/**
 *  dynamiCssLoad(path)
 * Chargement dynamique d'une feuille de styles
 * String path :: url de la feuille de styles
 **/  
function dynamiCssLoad(path){
    var cssNode = document.createElement('link');
    cssNode.type = 'text/css';
    cssNode.rel = 'stylesheet';
    cssNode.href = path;
    document.getElementsByTagName("head")[0].appendChild(cssNode);    
}



function openLangSelection(path){
    if(!document.getElementById('light-box-modif')){
        dynamiCssLoad(path+'_administration/_general_css/crea_light_box.css');
      
        im = domEl('img','',[['id', 'waitDuringTheLoading'],['class', 'loading_property'] , ['src',path+'_images/_icones/loader-fond-noir.gif']], '');
        background = domEl('div', im,[['id','background_property'],['class','LB_overlay']],document.getElementsByTagName('body')[0]);
        
        elCenter(document.getElementById('waitDuringTheLoading'));
        document.getElementById('background_property').style.height = (document.body.clientHeight + 70) + 'px';
      
        // récupération des données relative à la catégorie sélectionné ainsi que template
        var ajaxIndex = ajaxObjects.length;
        ajaxObjects[ajaxIndex] = new sack();
        var url = path+'_administration/modules/choix_langue/public/choix_langue.php';
        ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
        ajaxObjects[ajaxIndex].onCompletion = function() { CompleteLangSelection(ajaxIndex); }; 	// Specify function that will be executed after file has been found
        ajaxObjects[ajaxIndex].runAJAX();
    }
}

function CompleteLangSelection(index){
    domEl('div',' ',[['id','light-box-modif']],document.getElementsByTagName('body')[0]);
    document.getElementById('light-box-modif').innerHTML = ajaxObjects[index].response;
    document.getElementById('background_property').removeChild(document.getElementById('waitDuringTheLoading'));
    document.getElementById('background_property').onclick = function(){closeLinkList();};
    elCenter(document.getElementById('light-box-modif'));
    window.onresize =  function() {
                            elCenter(document.getElementById('light-box-modif'));
                       }
    window.onscroll =  function() {
                            elCenter(document.getElementById('light-box-modif'));
                       }
    
    onChangeWindowWH(0,0);
}

function CloseLightBox(){
    document.getElementById('background_property').parentNode.removeChild(document.getElementById('background_property'));
    document.getElementById('light-box-modif').parentNode.removeChild(document.getElementById('light-box-modif'));
}

function get_type_navigateur(){
    if(navigator.appName == "Microsoft Internet Explorer") return "ie";
    return "ff";
}
function get_num_version_navigateur(){
    return navigator.appVersion.substring(navigator.appVersion.indexOf('MSIE', 1)+4, navigator.appVersion.indexOf('MSIE', 1)+6);
}
// supprime tout les noeud enfant d'un élément
function removeChildNodes(ctrl)
{
  while (ctrl.childNodes[0])
  {
    ctrl.removeChild(ctrl.childNodes[0]);
  }
}

function loadFunkyBubble(){
	els = document.getElementById('main').getElementsByTagName('div');
	for(var x=0; x < els.length; x++){
		if(els[x].className == 'item-annonce-premium'){
			elss = els[x].getElementsByTagName('div');
			for(var y=0; y < elss.length; y++){
				if(elss[y].className == 'description-premium'){
					els[x].title = elss[y].innerHTML;
				}	
			}
		}	
	}
var Tips1 = new Tips($$('.item-annonce-premium'), {
	initialize:function(){
		this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
	},
	onShow: function(toolTip) {
		this.fx.start(1);
	},
	onHide: function(toolTip) {
		this.fx.start(0);
	}
});

}
