// Change current language
function changeLanguage(elem,index){
	url = elem.options[index].value ;
	window.location = url;
}

function loadIframe(iframeName, url,bn) {
    if ( window.frames[iframeName] ) {
        window.frames[iframeName].location = url;
        return false;
    }
    else return true;
}

function loadIframeTestMain(iframeName, url,bn) {
    window.frames[iframeName].location = url;
}

// open de la boite de confirmation des coupons
//  e event
// id id du coupon  
function openConfirm(e,action,id,retour) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = event;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    document.getElementById('confirm').style.left=posx-150;
    document.getElementById('confirm').style.top=posy-150;
    document.getElementById('lien').innerHTML = '<a href=\"/Adelyamin/fidelity/resacoupon/processAction.jsp?action='+action+'&idevent='+id+'&retourRFID='+retour+'\" onclick=\"javascript:document.getElementById(\'confirm\').style.visibility=\'hidden\'\" >'+oui+'</a>';
    document.getElementById('confirm').style.visibility='visible';
} 

function souris_on2(contenu) {
    if (parent.document.getElementById('commentaire'))
        parent.document.getElementById('commentaire').innerHTML = contenu;
    else if(top.document.getElementById('commentaire'))
        top.document.getElementById('commentaire').innerHTML = contenu;
}
function souris_off2() { 
    if (parent.document.getElementById('commentaire'))
        parent.document.getElementById('commentaire').innerHTML = 'Adelya RFID System';
    else if(top.document.getElementById('commentaire')) 
        top.document.getElementById('commentaire').innerHTML = 'Adelya RFID System';
}
function putPTValue(v) {
    document.fpt.valhidden.value = v;
}
function putCRValue(v) {
    document.fcr.valhidden.value = v;
}

function sf() {
    if (parent.window.central.document.formCA!=null && parent.window.central.document.formCA.value != null)
        parent.window.central.document.formCA.value.focus();
}
function hf() {
    if (document.formCA != null)
        document.formCA.value.blur();
    document.getElementById('span').focus();
}


function showMess() {
    document.getElementById('messageBox').style.visibility='visible';
    if (document.formCA != null) document.formCA.value.blur();
}

function hideMess() {
    document.getElementById('messageBox').style.visibility='hidden';
    if (document.formCA != null) document.formCA.value.focus();
}


function showNote() {
    if (document.getElementById('selectCA')!=null) {
        document.getElementById('selectCA').style.visibility='hidden';
    }
    if (document.getElementById('selectssCA')!=null) {
        document.getElementById('selectssCA').style.visibility='hidden';
    }
    if (document.getElementById('selectCR')!=null) {
        document.getElementById('selectCR').style.visibility='hidden';
    }
    if (document.getElementById('selectPT')!=null) {
        document.getElementById('selectPT').style.visibility='hidden';
    }
    document.getElementById('note').style.visibility='visible';
    document.no.descr.focus();
}

function hideNote() {
    if (document.getElementById('selectCA')!=null) {
        document.getElementById('selectCA').style.visibility='visible';
    }
    if (document.getElementById('selectssCA')!=null) {
        document.getElementById('selectssCA').style.visibility='visible';
    }
    if (document.getElementById('selectCR')!=null) {
        document.getElementById('selectCR').style.visibility='visible';
    }
    if (document.getElementById('selectPT')!=null) {
        document.getElementById('selectPT').style.visibility='visible';
    }
    
    document.getElementById('note').style.visibility='hidden';
}


function showSMS() {
    if (document.getElementById('selectCA')!=null) {
        document.getElementById('selectCA').style.visibility='hidden';
    }
    if (document.getElementById('selectssCA')!=null) {
        document.getElementById('selectssCA').style.visibility='hidden';
    }
    if (document.getElementById('selectCR')!=null) {
        document.getElementById('selectCR').style.visibility='hidden';
    }
    if (document.getElementById('selectPT')!=null) {
        document.getElementById('selectPT').style.visibility='hidden';
    }
    document.getElementById('sms').style.visibility='visible';
}
function hideSMS() {
    if (document.getElementById('selectCA')!=null) {
        document.getElementById('selectCA').style.visibility='visible';
    }
    if (document.getElementById('selectssCA')!=null) {
        document.getElementById('selectssCA').style.visibility='visible';
    }
    if (document.getElementById('selectCR')!=null) {
        document.getElementById('selectCR').style.visibility='visible';
    }
    if (document.getElementById('selectPT')!=null) {
        document.getElementById('selectPT').style.visibility='visible';
    }
    document.getElementById('sms').style.visibility='hidden';
    sf();
}

function getPosition(element)
{
    var left = 0;
    var top = 0;

    var e = document.getElementById(element);
    /*Tant que l'on a un élément parent*/
    while (e.offsetParent != undefined && e.offsetParent != null)
    {
        left += e.offsetLeft + (e.clientLeft != null ? e.clientLeft : 0);
        top += e.offsetTop + (e.clientTop != null ? e.clientTop : 0);
        e = e.offsetParent;
    }
    return new Array(left,top);
}

var sa = false;
function showAdvance() {
    if (!sa) {
        if (central.document.getElementById('selectCA')!=null) {
            central.document.getElementById('selectCA').style.visibility='hidden';
        }
        if (central.document.getElementById('selectssCA')!=null) {
            central.document.getElementById('selectssCA').style.visibility='hidden';
        }
        if (central.document.getElementById('selectCR')!=null) {
            central.document.getElementById('selectCR').style.visibility='hidden';
        }
        if (central.document.getElementById('selectPT')!=null) {
            central.document.getElementById('selectPT').style.visibility='hidden';
        }
        document.getElementById('advance').style.visibility='visible';
        document.getElementById('advance').style.left=getPosition("advance_button")[0]-100+"px";
        document.getElementById('advname').focus();
        sa = true;
    } else {
        if (central.document.getElementById('selectCA')!=null) {
            central.document.getElementById('selectCA').style.visibility='visible';
        }
        if (central.document.getElementById('selectssCA')!=null) {
            central.document.getElementById('selectssCA').style.visibility='visible';
        }
        if (central.document.getElementById('selectCR')!=null) {
            central.document.getElementById('selectCR').style.visibility='visible';
        }
        if (central.document.getElementById('selectPT')!=null) {
            central.document.getElementById('selectPT').style.visibility='visible';
        }
        document.getElementById('advance').style.visibility='hidden';
        document.getElementById('name').focus();
        sa = false;
    }
}

function hideAdvance() {
    document.getElementById('advance').style.visibility='hidden';
}

function emptyControle(mess) {
    if (document.search.name.value=="" 
        && document.search.tel.value==""
        && document.search.coupon.value=="") {
        alert(mess);
        return(false);
    } else return(true);
}

var d = false;
function showDesk(e) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = event;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    document.getElementById('desk').style.left=posx-60;
    document.getElementById('desk').style.top=posy+20;
    if (!d) {
        document.getElementById('desk').style.visibility='visible';
        d = true;
    } else {
        document.getElementById('desk').style.visibility='hidden';
        d = false;
    }
}

function hideDesk() {
    document.getElementById('desk').style.visibility='hidden';
    d = false;
}
function makeDis() {
    document.getElementById('button').disabled=true;
}

function controleFormByLink(formName,spanName,avg,emptyCA,avgCA,action) {
    var ca = document.forms[formName].elements['value'].value;
    if (ca=="") {
        alert(emptyCA);
        document.forms[formName].elements['value'].focus();
        return false;
    } else if (avg!='' && avg!=0.0 && ca>(avg*8)) {
        if (confirm(avgCA)) {
            return true;
        } else {
            document.forms[formName].elements['value'].focus();
            return false;
        }
    } else {
        return true;
    }
}

function controleFormMulti(action,number) {
    var fo = document.getElementById('formCA'+number);
    var ca = fo.value.value;
    document.getElementById('actionButton'+number).innerHTML=action+'...';
    fo.submit();
}

function protectForm(formName,spanName) {
    return protectForm(formName,spanName,'',null);
}

var change=false;
function protectForm(formName,spanName,mess,control) {
    change=false;
    if (control==null || (control!=null && control)) {
        if(document.getElementById(spanName)){
            document.getElementById(spanName).innerHTML=mess;
        }
        document.forms[formName].submit();
        return true;
    }
    return false;
}

function protectLink(elem) {
    //if(elem.disabled)
    //	return false;
    
    window.status = '+' + window.status;
    window.title = '+' + window.title;
    //elem.disabled = true;
    elem.style.visibility = 'hidden';
    setTimeout(function(){
        showLink(elem)
        },5000);
    return true;
}

function showLink(elem) {
    //elem.disabled = false;
    elem.style.visibility = 'visible';
}

function pressEnterKeyOnSearch(e,text,formName,spanName,mess) {
    if (e.keyCode==13) {
        protectForm(formName,spanName,mess,controleSearch(text,formName));
    }
}

function pressEnterKeyOnSearchMember(e,text1,text2,formName,spanName,mess) {
    if (e.keyCode==13) {
        protectForm(formName,spanName,mess,controlFormParrain(text1,text2));
    }
}

function controleSearch(text,formName) {
    var ok = true;
    if (formName=='search') {
        var resultName = window.document.getElementById(formName).nameortel.value;
        //	var resultTel = window.document.getElementById(formName).tel.value;
        var resultCoupon = window.document.getElementById(formName).coupon.value;
        if(resultName=='' && resultTel=='' && resultCoupon=='') {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultName!=null && resultName!='' && resultName.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        //	} else if (resultTel!=null && resultTel!='' && resultTel.length<3 && ok) {
        //	    document.getElementById('home').focus();
        //	    showMessageBox('',text,200,100);
        //	    ok = false
        } else if (resultCoupon!=null && resultCoupon!='' && resultCoupon.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        }
    } else {
        var resultIdext = window.document.getElementById(formName).idext.value;
        var resultCard = window.document.getElementById(formName).card.value;
        var resultName = window.document.getElementById(formName).advname.value;
        var resultTel = window.document.getElementById(formName).advtel.value;
        var resultEmail = window.document.getElementById(formName).advemail.value;
        var resultFirstname = window.document.getElementById(formName).firstname.value;
        var resultTown = window.document.getElementById(formName).town.value;
        var resultZip = window.document.getElementById(formName).zip.value;
        if (resultIdext=='' && resultCard=='' && resultName=='' && resultTel=='' && resultEmail=='' && resultFirstname=='' && resultTown=='' && resultZip=='') {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultIdext!=null && resultIdext!='' && resultIdext.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultCard!=null && resultCard!='' && resultCard.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultName!=null && resultName!='' && resultName.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultTel!=null && resultTel!='' && resultTel.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultEmail!=null && resultEmail!='' && resultEmail.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultFirstname!=null && resultFirstname!='' && resultFirstname.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultTown!=null && resultTown!='' && resultTown.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        } else if (resultZip!=null && resultZip!='' && resultZip.length<3 && ok) {
            document.getElementById('home').focus();
            showMessageBox('',text,200,100);
            ok = false;
        }
    }
    return ok;
}

function souris_on(contenu) {
    if(document.getElementById('commentaire'))
        document.getElementById('commentaire').innerHTML = contenu;
}
function souris_off() { 
    if(document.getElementById('commentaire'))
        document.getElementById('commentaire').innerHTML = 'Adelya RFID System';
}

var h = false;
function showHisto(e) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = event;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    document.getElementById('histo').style.left=posx-40;
    document.getElementById('histo').style.top=posy+20;
    if (!h) {
        document.getElementById('histo').style.visibility='visible';
        h = true;
    }
    else {
        document.getElementById('histo').style.visibility='hidden';
        h = false;
    }
}
function hideHisto() {
    document.getElementById('histo').style.visibility='hidden';
    h = false;
}


function deleteImage(id,trad) {
    var img = "img_"+id;
    var last = document.f.id.value;
    var last = document.getElementById(id).value;
    document.getElementById(img).style.visibility='hidden';
    document.getElementById(id).value = "deleted";
    document.getElementById('span_'+id).innerHTML = trad;
}

function putElement(id,nom,prenom,appli,type) {
    top.window.central.Content.document.getElementById('#{memb.'+type+'.id}').value = id;
    top.window.central.Content.document.getElementById(type+'Span').innerHTML = nom+" "+prenom;
}

function putNbDest(nb,appli) {
    if (top.parent.window.central.document.getElementById('nbGroupSelect')!=null)
        top.parent.window.central.document.getElementById('nbGroupSelect').innerHTML = nb;
}

function closeMessageBox() {
    top.GB_hide();
}

function closeMessageBoxMobiKoop(urlImg) {
    var imgToShow = '<img alt="" src="/Adelyamin/ImageProducer.do?filename='+urlImg+'">';
    window.top.document.getElementById('imgCampaign').innerHTML = imgToShow;
    window.top.document.getElementById('imgChange').style.display="block";
    closeMessageBox();
}

function closeMessageBoxMobiKoopCondition(cond){
    window.top.document.getElementById('messageCond').innerHTML = cond;
    closeMessageBox();
}

function closeSimpleMessageBox() {
    if(window.top.document != null && window.top.document.getElementById('messageBox')!=null){
        window.top.document.getElementById('messageBox').style.visibility='hidden';
        showSelectElementForGraybox();
    }
    sf();
}

function gotourl(url) {
    hideSelectElementForGraybox();
    top.window.location = url;
}

function showMessageBoxToConfirm(action,idcoupon,fromMember,mess,yes,no,confirm) {
    var link = confirm;
    link += '<p>'+mess+'</p>';
    if (fromMember) {
        link += '<a href="#" style="text-decoration:none;" onclick="protectLink(this);gotourl(\'/Adelyamin/fidelity/resacoupon/processAction.jsp?action='+action+'&idevent='+idcoupon+'&retourRFID=/Adelyamin/fidelity/rfid/showMember.jsp\');" >'+yes+'</a>';
    } else
        link += '<a href="#" style="text-decoration:none;" onclick="gotourl(\'/Adelyamin/fidelity/resacoupon/processAction.jsp?action='+action+'&idevent='+idcoupon+'&retourRFID=/Adelyamin/fidelity/rfid/showListFidelityMember.jsp\');" >'+yes+'</a>';
    link += '  <a href="#" style="text-decoration:none;" onclick="top.GB_hide()">'+no+'</a><p/><br/>';
    showMessageBox('',link,350,200);
}

function waitClosing() {
    setTimeOut(top.GB_hide(),2000);
}

function confirmOpenURL(action,message,yes,no) {
    var link = message+'<p/><br/>';
    link += '<a href=\'/Adelyamin/fidelity/resaCdx.jsp'+action+'\' >'+yes+'</a>';
    link += ' / <a href="#" onclick="top.GB_hide()">'+no+'</a><p/><br/>';
    showMessageBox('',link,500,200);
}

function showMessageBox(page,text,width,height,callback) {
    hideSelectElementForGraybox();
    var grayBoxElement = top.document.getElementById('GB_window');
    var w = 300;
    var h = 300;
    if (width!=null && width!='') w = width;
    if (height!=null && height!='') h = height;
    if (page!='') {
        if (callback!=null && callback!='' && grayBoxElement==null) {
            return top.GB_showCenter('',page,w,h,callback);
        }
        else if (grayBoxElement==null) {
            return top.GB_showCenter('',page,w,h,showSelectElementForGraybox);
        }
    } else if (text!='') {
        if (callback!=null && callback!='' && grayBoxElement==null) return top.GB_showCenter('','/Adelyamin/messageBoxText.jsp?txt='+escape(text),w,h,callback);
        else if (grayBoxElement==null) {
            return top.GB_showCenter('','/Adelyamin/messageBoxText.jsp?txt='+escape(text),w,h,showSelectElementForGraybox);
        }
    }
}

function showSimpleMessageBox(page,mode,text,width,height,topp,closecallback,closeValue, cancelcallback, cancelValue) {
    if (document.body) {
        var larg = (top.window.document.body.clientWidth);
        var haut = (top.window.document.body.clientHeight);
        var left = (larg-width)/2;
    }
    mBox = top.window.document.getElementById('messageBox');
    mBox.style.width = width+'px';
    mBox.style.left= left+'px';
    if (height!=null && height!='')
        mBox.style.height = height+'px';
    if (topp!=null && topp!='')
        mBox.style.top = topp+'px';
    else
        mBox.style.top = '150px';
    mBox.style.visibility='visible';
	if((text!='' && text!=null) || (page!='' && page!=null && mode == '')){
		top.window.document.getElementById('messageBox').innerHTML='<img src="/Adelyamin/img/wait.gif" />';
	} else{
		top.window.document.getElementById('messageBoxContent').innerHTML='<img src="/Adelyamin/img/wait.gif" />';
	}
    var clo = closeTrad;
    var cloAction = 'closeSimpleMessageBox();';
    if (closecallback!='' && closecallback!=null) cloAction = closecallback;
    if (closeValue!='' && closeValue!=null) clo = closeValue;
    bottomButton = '';
    if( (cloAction!='' && clo!=null ) || (cancelcallback!='' && cancelValue!=null )){
        bottomButton += '<table width="90%"><tr>';
        if (cloAction!='' && clo!=null ) {
            bottomButton += '<td align="center"><input id="cloAction" type="button" class="bouton" onclick="'+cloAction+';" value='+clo+' /></td>';
        }
        if (cancelcallback!='' && cancelValue!=null ) {
            bottomButton += '<td align="center"><input id="cancelcallback" type="button" class="bouton" onclick="'+cancelcallback+';" value='+cancelValue+' /></td>';
        }
        // print button for direct text
        //if (text!='' && text!=null)
            bottomButton += '<td align="center"><input id="printMessageBox" type="button" class="bouton" onclick="printDiv(\'messageBoxContent\',250,250);" value="print" /></td>';
        bottomButton += '</tr></table>';
    }

    if (text!='' && text!=null) {
        text = '<div id="messageBoxContent">'+text+'</div>';
        text += '<div id="messageBoxButton">'+bottomButton+'</div>';
        top.window.document.getElementById('messageBox').innerHTML = text;
        if (top.window.document.getElementById('sp')) top.window.document.getElementById('sp').focus();
        setMessageBoxFocus();
    }
    else if (page!='' && page!=null && mode == '') {
        top.window.document.getElementById('messageBox').innerHTML = '<iframe id="messageBoxIframId" width="95%" height="90%" frameborder="0" src="'+page+'"></iframe>'+bottomButton;
        setMessageBoxFocus();
    }
    else {
		top.window.document.getElementById('messageBoxButton').innerHTML = bottomButton;
		new Ajax.Updater(top.window.document.getElementById('messageBoxContent'),page, {evalScripts: true});
        /*var updtFunc = function(t) {
                        top.window.document.getElementById('messageBox').innerHTML = '<div id="messageBoxContent">'+t.responseText+'</div>'
                +'<div id="messageBoxButton">'+bottomButton+'</div>';
        }
        var errFunc = function(t) {
            top.window.document.getElementById('messageBox').innerHTML = 'Error';
        }
        new Ajax.Request(page, {
            onSuccess:updtFunc,
            onComplete:setMessageBoxFocus,
            onFailure:errFunc,
            evalScripts: true
        });*/
    }
}

function setMessageBoxFocus()
{
     // Setting focus on button
    if (cloAction!='' && clo!=null ) {
        var eltclo=top.window.document.getElementById('cloAction');
        if (eltclo!=null) eltclo.focus();
    }
    if (cancelcallback!='' && cancelValue!=null ) {
        var eltcancel = top.window.document.getElementById('cancelcallback');
        if (eltcancel!=null) eltcancel.focus();
    }        
}

function closeAndRefresh() {
    closeMessageBox();
    window.central.location.reload();
}

function closeAndRefreshAddUnique() {
    top.window.central.location.reload();
}

function controleAddNumber(emptyNumber) {
    var number = document.formNumber.number.value;
    if (number.length<5 || isNaN(number)) {
        alert(emptyNumber);
        document.formNumber.number.focus();
    } else {
        document.formNumber.submit();
    }
}

function controleContact(errorContact,errorMess) {
    var mess = document.getElementById('message').value;
    if (document.getElementById('contact')) {
        var contact = document.getElementById('contact').value;
        if (contact=='') {
            alert(errorContact);
            return false;
        } else if (mess=='') {
            alert(errorMess);
            return false;
        }
        else return true;
    }
}

function controleSendSMS(optin,text) {
    if (optin=='false') {
        if (confirm(text)) {
            return true;
        } else return false;
    } else if (optin=='true' || optin=='null') return true;   
}

function ImageMax(chemin) {
    var html = '<html><head><title>ImageMax</title></head><body onBlur="top.close()">';
    html += '<IMG src="'+chemin+'" BORDER="0" NAME="ImageMax" onLoad="window.resizeTo(document.ImageMax.width+10, document.ImageMax.height+30)">';
    html += '</body></html>';
    popupImage =    window.open('','_blank','toolbar=0, location=0, directories=0, menuBar=0, scrollbars=0, resizable=1');
    popupImage.document.open();
    popupImage.document.write(html);
    popupImage.document.close();
}

function xmlhttpPost(strURL,fctUpdt,fctQS,chaine,id) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            fctUpdt(self.xmlHttpReq.responseText,id);
        }
    }
    self.xmlHttpReq.send(fctQS(chaine));
}

function getquerystring(step) {
    qstr = 'w=' + escape(step);
    return qstr;
}

function updatepage(str,id){
    document.getElementById(id).innerHTML = str;
}

function updatepageselect(str,id){
    select_innerHTML(document.getElementById(id),str);
}

function select_innerHTML(objeto,innerHTML){
    /******
     * select_innerHTML - corrige le bug de InnerHTML des select dans IE
     * Voir probleme ici : http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
     *******/
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se nï¿½o ï¿½ option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.toLowerCase().replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
    
    for(var i=0;i<selTemp.childNodes.length;i++){
        var spantemp = selTemp.childNodes[i];
	
        if(spantemp.tagName){
            opt = document.createElement("OPTION")
	    
            if(document.all){ //IE
                objeto.add(opt)
            }else{
                objeto.appendChild(opt)
            }
	    
            //getting attributes
            for(var j=0; j<spantemp.attributes.length ; j++){
                var attrName = spantemp.attributes[j].nodeName;
                var attrVal = spantemp.attributes[j].nodeValue;
                if(attrVal){
                    try{
                        opt.setAttribute(attrName,attrVal);
                        opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
                    }catch(e){}
                }
            }
            //getting styles
            if(spantemp.style){
                for(var y in spantemp.style){
                    try{
                        opt.style[y] = spantemp.style[y];
                    }catch(e){}
                }
            }
            //value and text
            opt.value = spantemp.getAttribute("value")
            opt.text = spantemp.innerHTML
            //IE
            opt.selected = spantemp.getAttribute('selected');
            opt.className = spantemp.className;
        }
    }    
    document.body.removeChild(selTemp)
    selTemp = null
}

function hideSelectElementForGraybox() {
    for(i=0; i < top.window.frames.length; ++i) {
        for(v=0; v < top.window.frames[i].frames.length; ++v) {
            for (t=0; t < top.window.frames[i].frames[v].document.forms.length; ++t) {
                for (u=0; u < top.window.frames[i].frames[v].document.forms[t].elements.length; ++u) {
                    if (top.window.frames[i].frames[v].document.forms[t].elements[u].type=='select-one')
                        top.window.frames[i].frames[v].document.forms[t].elements[u].style.visibility = 'hidden';
                }
            }
        }
    }
}

function showSelectElementForGraybox() {
    for(i=0; i < top.window.frames.length; ++i) {
        for(v=0; v < top.window.frames[i].frames.length; ++v) {
            for (t=0; t < top.window.frames[i].frames[v].document.forms.length; ++t) {
                for (u=0; u < top.window.frames[i].frames[v].document.forms[t].elements.length; ++u) {
                    if (top.window.frames[i].frames[v].document.forms[t].elements[u].type=='select-one')
                        top.window.frames[i].frames[v].document.forms[t].elements[u].style.visibility = 'visible';
                }
            }
        }
    }
}

function showSelectElementForGrayboxAndReload() {
    for(i=0; i < top.window.frames.length; ++i) {
        for(v=0; v < top.window.frames[i].frames.length; ++v) {
            for (t=0; t < top.window.frames[i].frames[v].document.forms.length; ++t) {
                for (u=0; u < top.window.frames[i].frames[v].document.forms[t].elements.length; ++u) {
                    if (top.window.frames[i].frames[v].document.forms[t].elements[u].type=='select-one')
                        top.window.frames[i].frames[v].document.forms[t].elements[u].style.visibility = 'visible';
                }
            }
        }
    }
    top.window.central.document.location.reload();
}

// Create TimeOut close page handle
var TimeOut_whereToGo = "";
var TimeOut_whereToGoTime = 0;
var TimeOut_timeoutID = 0;
var TimeOut_minuteConversion = 1000 * 60;

function initBeanFormTimeout( urlLocation, timeout, forOtherInput){
    
    return;
    
    // Init setting values
    TimeOut_whereToGo = urlLocation;
    TimeOut_whereToGoTime = timeout * TimeOut_minuteConversion;
    
    // First time launch
    inputFocus(null);
    
    // Do it for others input
    if(forOtherInput){
        var fr = document.forms;
        for(var j=0;j<fr.length;j++){
            var el = fr[j];
            for(var i=0;i<el.length;i++){
                elem = el[i];
                elem.onfocus=function(e){
                    inputFocus(this);
                };
            }
        }
    }
}

function inputFocus(input){
    
    // This input while be selected
    if(input!=null && input.select!=null ){
        input.select();
    }
    
    // Cancel previous timeOut
    if(TimeOut_timeoutID != 0){
        window.clearTimeout(TimeOut_timeoutID);
    }
    
    // Declare new TimeOut
    if(TimeOut_whereToGoTime != 0 && TimeOut_whereToGo != ""){
        TimeOut_timeoutID = setTimeout( TimeOut_whereToGo, TimeOut_whereToGoTime);
        var d = new Date();
        window.status = "Timeout : " + (TimeOut_whereToGoTime / TimeOut_minuteConversion) + " min after "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
    }
}

function refreshCalendar() {
    //top.window.central.location.reload();
    top.window.central.location.href='calendar.jsp';
}

function deleteEvent(id) {
    closeMessageBox();
    top.window.central.Content.location="/Adelyamin/fidelity/showHisto.jsp?action=deleteEvent&idEvent="+id;
}

function fct2() {
    closeMessageBox();
    top.window.central.treefolder.location="docFolder.jsp";
}
function fct1() {
    closeMessageBox();
    top.window.central.treefolder.location="docFolder.jsp";
    top.window.central.docfile.location.href='docFile.jsp?folder=Default'
}

function defineRows(id, minRows, rows, maxRows){
    
    var select = document.getElementsByName(id)[0];
    select.options[0].innerHTML = minRows;
    select.options[0].value = minRows;
    select.options[1].innerHTML = rows;
    select.options[1].value = rows;
    select.options[1].selected = true;
    select.options[2].innerHTML = maxRows;
    select.options[2].value = maxRows;
}

function openLink(url){
    if(document.getElementById('Content') != null){
        new Ajax.Updater('Content', url);
    }
    else{
        document.location = url;
    }
}

function openLinkProtec(pro, url){
    if(protectLink(pro))
        openLink(url);
}

function getElementsByClassName(className, tag, elm){
    var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
    for(var i=0; i<length; i++){
        current = elements[i];
        if(testClass.test(current.className)){
            returnElements.push(current);
        }
    }
    return returnElements;
}


/** print any Div content  in a new Window, call the printer, then close the window
 * Test OK FF3, IE8
**/
function printDiv(divid, h,w)
{
    printw = window.open('printw','printw','height='+h+', width='+w+',toolbar=no,scrollbars=no,menubar=no');
    printw.document.write(document.getElementById(divid).innerHTML);
    printw.document.close(); // dont do that an nothing happen on IE
    printw.print();
    printw.close();
    return;
}
function showhideTree(var1){
	// we change the css class of the current node
	var nparent = document.getElementById('parent_' + var1);
	var nchild = document.getElementById('tree_' + var1);

	if (nparent.className.indexOf('active') == -1) {
		nparent.className = nparent.className + " active";
	} else {
		nparent.className = nparent.className.replace(" active", "");
	}
	// we set the next div of the tree visible
	if (nchild!=null) {
		if (nchild.style.display=="none"){
			nchild.style.display="";
		} else {
			nchild.style.display="none";
		}
	}
}

function savePubl(param) {
    self.window.location="changeOrderPubl.jsp?"+param;
}
function savePriv(param) {
    self.window.location="changeOrderPriv.jsp?"+param;
}        
function saveTotal(param1,param2) {
    self.window.location="saveOrder.jsp?"+param1+"&"+param2;
}


// --------------------------
// visibility management
// --------------------------

function doVisible(id) {
    var listOfId = id.split(',');
    for (var i = 0, len = listOfId.length; i < len; i++) {
        var oid = document.getElementById(listOfId[i]);
		if(oid==null) oid = top.window.document.getElementById(listOfId[i]);
        if (oid!=null) {
            oid.style.visibility='visible';
            oid.style.display='block';
        }
    }
}

function doHidden(id) {
    var listOfId = id.split(',');
    for (var i = 0, len = listOfId.length; i < len; i++) {
        var oid = document.getElementById(listOfId[i]);
		if(oid==null) oid = top.window.document.getElementById(listOfId[i]);
        if (oid!=null) {
            oid.style.visibility='hidden';
            oid.style.display='none';
        }
    }
}

function switchVisible(id) {
    var listOfId = id.split(',');
    for (var i = 0, len = listOfId.length; i < len; i++) {
        var oid = document.getElementById(listOfId[i]);
		if(oid==null) top.window.document.getElementById(listOfId[i]);
        if (oid!=null) {
            if (oid.style.visibility=='hidden') {
                doVisible(id);
            }
            else {
                doHidden(id);
            }
        }
    }
}

// ------------------------------
//              tab management 
// ------------------------------

var actif = 0;
function TabClickEx( nTab, locUrl ){
    actif = nTab;
    for (i = 0; i < document.getElementsByName("tabs").length; i++)
    {
        document.getElementsByName("tabs")[i].className = "linkOff";
    }
    document.getElementsByName("tabs")[nTab].className = "linkOn";
    frames['Content'].location.href = locUrl;
}

function TabClickExAjax( nTab, locUrl){
    actif = nTab;
    for (i = 0; i < document.getElementsByName("tabs").length; i++)
    {
        document.getElementsByName("tabs")[i].className = "linkOff";
    }
    document.getElementsByName("tabs")[nTab].className = "linkOn";
    new Ajax.Updater("Content", locUrl,{
        onLoading: loading,
        onFailure: failure,
        evalScripts: true
    });
}

function loading(){ 
    $('Content').innerHTML = "<center><img id=\"img_loading\" src=\"/Adelyamin/js/greybox/indicator.gif\" alt=\"Chargement...\"/></center>";
}

function failure(){
    $('Content').innerHTML = "Erreur de chargement, veuillez actualiser la page.";
}

function outTabs(nTab) {
    if (nTab!=actif) {
        document.getElementById('d').className = "ongletOff";
        document.getElementsByName("tabs")[nTab].className = "linkOff";
    }
}

function onTabs(nTab) {
    document.getElementById('d').className = "ongletOff";
    for (i = 0; i < document.getElementsByName("tabs").length; i++)
    {
        if (i!=actif) document.getElementsByName("tabs")[i].className = "linkOff";
    }
    document.getElementsByName("tabs")[nTab].className = "linkOn";
}

// ---------------------------
// manage help 
// ---------------------------

function openHelptemp(topic) {
    parent.open("/Adelyamin/help/help"+topic+".html","help","directories=no,scrolling=yes,location=no,menubar=no,status=no,width=500,height=500").focus();
}


function openHelp(topic) {
    parent.open("/Adelyamin/help/"+local+"/help"+topic+".jsp","help","width=600,height=500,scrollbars=yes,resizable=yes").focus();
}

// -------------------------------
//    key shortcuts
// ------------------------------


// Renseignement des raccourcis URL programmes :
var shortcutsURL = new Object();
shortcutsURL[112] = '/Adelyamin/fidelity/rfid/showListFidelityMember.jsp';
shortcutsURL[113] = '/Adelyamin/fidelity/frame.jsp?id=new';

// Renseignement des raccourcis JS programmes :
var shortcutsJS = new Object();
shortcutsJS[114] = 'window.top.document.getElementById("searchName").focus();';
//shortcutsJS[144] = 'alert("Coucou");';

////////////////////////////////////////////////////////////
// Gestion des raccroucis
function manageShortcut(e){
    // alert('Code=' + e.keyCode + ':' + shortcutsURL[e.keyCode]);

    // On lance le JS associe
    if(shortcutsJS[e.keyCode]){
        eval(shortcutsJS[e.keyCode]);
    }

    // Une fois ces actions JS effectuees,
    // on se forward vers le lien renseigne dans le tableau des shortcut
    if(shortcutsURL[e.keyCode]){
        if(window.frames['central']){
            window.frames['central'].location = shortcutsURL[e.keyCode];
        }
        else{
            window.location = shortcutsURL[e.keyCode];
        }

        e.cancelBubble = true;
        window.cancelBubble = true;

        // On annule les raccourcis du browser
        if (e.preventDefault) {
            e.preventDefault();
        }
        stopPropagation(e);
    }

    return false;
}

function stopPropagation(e){
    e = e || event;/* get IE event ( not passed ) */
    e.stoppropagation? e.stoppropagation() : e.cancelBubble = true;
}


function resetShortCut(){
    shortcutsURL = new Object();
    shortcutsJS = new Object();
}

// --------------------------------------


function selectLogo() {
    document.getElementById('backcheck').checked='';
    document.getElementById('inputback').disabled=true;
    document.getElementById('inputlogo').disabled=false;
}

function selectBack() {
    document.getElementById('logocheck').checked='';
    document.getElementById('inputlogo').disabled=true;
    document.getElementById('inputback').disabled=false;
}

function goImgWinZoomLess(myImage,myWidth,myHeight,sessionid) {
    goImgWin(myImage,myWidth,myHeight-80,'no',sessionid);
}

function _goImgWinZoomLess(myImage,myWidth,myHeight) {
    myHeight += 24;
    myWidth += 24;
    TheImgWin = window.open('/Adelyamin/fidelity/analyse/drawGraphWithZoom.jsp?graphname='+myImage+'&zoom=no','image','height=' +
        myHeight + ',width=' + myWidth +
        ',toolbar=no,directories=no,status=no,' +
        'menubar=no,scrollbars=no,resizable=no');
    TheImgWin.moveTo(top.innerWidth/2-myWidth/2,top.innerHeight/2-myHeight/2);
    TheImgWin.focus();
}

function goImgWin(myImage,myWidth,myHeight,actualZoom,sessionid) {
    myHeight += 50;
    myWidth += 24;
    TheImgWin = window.open('/Adelyamin/fidelity/analyse/drawGraphWithZoom.jsp;jsessionid='+sessionid+'?graphname='+myImage+'&zoom='+actualZoom,'image','height=' +
        myHeight + ',width=' + myWidth +
        ',toolbar=no,directories=no,status=no,' +
        'menubar=no,scrollbars=no,resizable=no');
    TheImgWin.moveTo(top.innerWidth/2-myWidth/2,top.innerHeight/2-myHeight/2);
    TheImgWin.focus();
}

function _goImgWin(myImage,myWidth,myHeight,actualZoom) {
    if(!actualZoom) var actualZoom='';
    var actualZoomOut='';
    if(actualZoom.length>1){
        if(actualZoom.substring(0, 1)==";"){
            actualZoom = actualZoom.substring(1, actualZoom.length);
        }
        actualZoomOut = actualZoom.substring(0, actualZoom.length-2);
    }
    TheImgWin=window.open('','name','height='+(Number(myHeight)+64)+',width='+(Number(myWidth)+24));
    
    TheImgWin.document.write('\
    <html>\n\
    <head>\n\
    <title>Graph</title>\n\
    <script language="javascript" type="text/javascript" src="/Adelyamin/js/adelyamin.js"></script>\n\
    </head>\n\
    <body>\n\
    <map name="map">\n\
    ');
    if(actualZoom!=''){
        TheImgWin.document.write('\
        <area shape="rect" coords="0,0,'+myWidth+',30" href="javascript:goImgWin(\''+myImage+'\','+myWidth+','+myHeight+', \''+actualZoomOut+'" alt="Zoom Out" style="CURSOR:col-resize" />\n\
        ');
    }
    
    TheImgWin.document.write('\
    <area shape="rect" coords="0,30,'+(Number(myWidth)/2)+','+myHeight+'" href="javascript:goImgWin(\''+myImage+'\','+myWidth+','+myHeight+', \''+actualZoom+';L\');" alt="Zoom in left" style="CURSOR:crosshair" />\n\
    <area shape="rect" coords="'+(Number(myWidth)/2)+',30,'+myWidth+','+myHeight+'" href="javascript:goImgWin(\''+myImage+'\','+myWidth+','+myHeight+', \''+actualZoom+';R\');" alt="Zoom in right" style="CURSOR:crosshair" />\n\
    </map>\n\
    <center>\n\
    <table width="100%" >\n\
    <tr align="center" >\n\
/*									<td><a align="left" href="#" onclick="javascript:goImgWin(\''+myImage+'\','+myWidth+','+myHeight+',\''+actualZoom+';L\');return false;"><img border="0" src="/Adelyamin/img/loupeplus.png" alt="(+)" /></a></td>\n\
 */			');
    if(actualZoom!=''){
        TheImgWin.document.write('\
     <td><a href="#" onclick="javascript:goImgWin(\''+myImage+'\','+myWidth+','+myHeight+',\''+actualZoomOut+'\');return false;"><img border="0" src="/Adelyamin/img/loupemoins.png" alt="(-)" /></a></td>\n\
     ');
    }
    TheImgWin.document.write('\
/*									<td><a href="#" onclick="javascript:goImgWin(\''+myImage+'\','+myWidth+','+myHeight+',\''+actualZoom+';R\');return false;"><img border="0" src="/Adelyamin/img/loupeplus.png" alt="(+)" /></a></td>\n\
 */								</tr>\n\
 </table>\n\
 <img usemap="#map" src="'+myImage+'&zoom='+actualZoom+'" alt=" " border="0" />\n\
 <p />\n\
 </center>\n\
 </body>\n\
 </html>\n\
 ');
    TheImgWin.document.close();
    return false;
 
}


// ---------------------------------------------
// --- Name:    Easy DHTML Treeview           --
// --- Author:  D.D. de Kerf                  --
// --- Modif mv : attention trï¿½s senseible ï¿½ la place des div (usage de nextSibling --
// --- Version: 0.2          Date: 13-6-2001  --
// ---------------------------------------------
function Toggle(node) {
    // Unfold the branch if it isn't visible
    if (node.nextSibling.style.display == 'none') {
        // Change the image (if there is an image)
        if (node.childNodes.length > 0) {
            if (node.childNodes.item(0).nodeName == "IMG") {
                node.childNodes.item(0).src = "/Adelyamin/img/tree/minus.gif";
            }
        }
        
        node.nextSibling.style.display = 'block';
    }
    // Collapse the branch if it IS visible
    else {
        // Change the image (if there is an image)
        if (node.childNodes.length > 0) {
            if (node.childNodes.item(0).nodeName == "IMG") {
                node.childNodes.item(0).src = "/Adelyamin/img/tree/plus.gif";
            }
        }
        
        node.nextSibling.style.display = 'none';
    }
}

function hideStatus() {
    document.getElementById('status').style.visibility = 'hidden';
}

function showStatus(e) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = event;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    var x = posx -100;
    var y = posy +10;
    document.getElementById('status').style.top = y;
    document.getElementById('status').style.left = x;
    document.getElementById('status').style.visibility = 'visible';
}

function showlink(id) {
    var i = 1;
    for (i=1;i<30;i++) {
        if (i!=id && document.getElementById(i)!=null) document.getElementById(i).style.color='#626262';
    }
    document.getElementById(id).style.color='blue';
}

var i = 1;
function showCal() {
    if (document.getElementById('#{mess.mode}')) {
        if (i==0) {
            document.getElementById('cal_#{mess.dateStart}').style.visibility='hidden';
            document.getElementById('cal_#{mess.dateEnd}').style.visibility='hidden';
            document.getElementById('descr_#{mess.dateStart}').style.visibility='hidden';
            document.getElementById('descr_#{mess.dateEnd}').style.visibility='hidden';
            document.getElementById('#{mess.dateStart}').value='';
            document.getElementById('#{mess.dateEnd}').value='';
            document.getElementById('__mess_dateStart_').value='';
            document.getElementById('__mess_dateEnd_').value='';
            i = 1;
        } else {
            document.getElementById('cal_#{mess.dateStart}').style.visibility='visible';
            document.getElementById('cal_#{mess.dateEnd}').style.visibility='visible';
            document.getElementById('descr_#{mess.dateStart}').style.visibility='visible';
            document.getElementById('descr_#{mess.dateEnd}').style.visibility='visible';
            i = 0;
        }
    }
}
function controleMode() {
    if (document.getElementById('#{mess.mode}')) {
        if (document.getElementById('#{mess.mode}').value='NORMAL') {
            document.getElementById('cal_#{mess.dateStart}').style.visibility='hidden';
            document.getElementById('cal_#{mess.dateEnd}').style.visibility='hidden';
            document.getElementById('descr_#{mess.dateStart}').style.visibility='hidden';
            document.getElementById('descr_#{mess.dateEnd}').style.visibility='hidden';
        }
    }
}

function controlDate(id) {
    var exp = new RegExp("^[0123]?[0-9]\-[01]?[0-9]\-[0-9]{4}$","g");
    var doc = document.getElementById(id);
    if (!exp.test(doc.value) && doc.value!='') {
        alert(alertDate);
        doc.value = '';
    }
}

function controlFormParrain(alertEmpty,alertMin) {
    var minSize = 3;
    if (document.getElementById('idext').value=='' && document.getElementById('card').value=='' && document.getElementById('advname').value=='' 
        && document.getElementById('firstname').value=='' && document.getElementById('advtel').value=='' && document.getElementById('advemail').value==''  
	&& document.getElementById('town').value=='' && document.getElementById('zip').value=='') {
        alert(alertEmpty+'...');
        return false;
    } else if ( 
        (document.getElementById('idext').value!='' && document.getElementById('idext').value.length < minSize ) ||
        (document.getElementById('card').value!='' && document.getElementById('card').value.length < minSize ) ||
        (document.getElementById('advname').value!='' && document.getElementById('advname').value.length < minSize ) ||
        (document.getElementById('advtel').value!='' && document.getElementById('advtel').value.length < minSize ) ||
	(document.getElementById('advemail').value!='' && document.getElementById('advemail').value.length < minSize )
        ) {
        alert(alertMin);
        return false;
    } else if (
        ( (document.getElementById('firstname').value!='' && document.getElementById('firstname').value.length < minSize ) ||
            (document.getElementById('zip').value!='' && document.getElementById('zip').value.length < minSize ) ||
            (document.getElementById('town').value!='' && document.getElementById('town').value.length < minSize ) ) && (
            (document.getElementById('idext').value!='' && document.getElementById('idext').value.length < minSize ) || (document.getElementById('advtel').value!='' && document.getElementById('advtel').value.length < minSize) ||
            (document.getElementById('advname').value!='' && document.getElementById('advname').value.length < minSize ) || (document.getElementById('card').value!='' && document.getElementById('card').value.length < minSize) )
        ) {
        alert(alertMin);
        return false;
    } else if (
        ( (document.getElementById('firstname').value!='' && document.getElementById('firstname').value.length < minSize ) ||
            (document.getElementById('zip').value!='' && document.getElementById('zip').value.length < minSize ) ||
            (document.getElementById('town').value!='' && document.getElementById('town').value.length < minSize ) ) && (
            document.getElementById('idext').value=='' && document.getElementById('advtel').value=='' &&
            document.getElementById('advname').value=='' && document.getElementById('card').value=='' )
        ) {
        alert(alertMin);
        return false;
    } else {
        return true;
    }
}

function changeImgDesk() {
    if (top.window.document.getElementById('imgdesk')) {
        top.window.document.getElementById('imgdesk').src = '/Adelyamin/img/bureau.png';
    }
}

function closeAndRefreshMobile() {
    top.window.central.document.location.reload();
}

function loadScript(source) {
    var head= document.getElementsByTagName('head')[0];
    var script= document.createElement('script');
    script.type= 'text/javascript';
    script.src= source;
    head.appendChild(script);
}

// enable the element with id elId
// and all sub element (ex, div and children)
function enable(elId) {
    var el =  document.getElementById(elId);
    if (el!=null) setDisable(el,false);
}

// disable the element with id elId
// and all sub element (ex, div and children)
function disable(elId) {
    var el =  document.getElementById(elId);
    if (el!=null) setDisable(el,true);
}

// set the disable status of el and children to val
// used by enable(id) and disable(id)
function setDisable(el,val) {
    try {
        el.disabled = val;
    }
    catch(E){}
                
    if (el.childNodes && el.childNodes.length > 0) {
        for (var x = 0; x < el.childNodes.length; x++) {
            setDisable(el.childNodes[x],val);
        }
    }
}
function show_calendar(str_target, str_datetime) {
	//var arr_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	var arr_months = ["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre"];
        //var week_days = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
        var week_days = ["Di","Lu","Ma","Me","Je","Ve","Sa"];
	var n_weekstart = 1; 
	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));
	var dt_prev_month = new Date(dt_datetime);
	dt_prev_month.setMonth(dt_datetime.getMonth()-1);
	var dt_next_month = new Date(dt_datetime);
	dt_next_month.setMonth(dt_datetime.getMonth()+1);
	var dt_firstday = new Date(dt_datetime);
	dt_firstday.setDate(1);
	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
	var dt_lastday = new Date(dt_next_month);
	dt_lastday.setDate(0);

        var dt_prev_year = new Date(dt_datetime);
        dt_prev_year.setFullYear(dt_datetime.getFullYear()-1);
        var dt_next_year = new Date(dt_datetime);
        dt_next_year.setFullYear(dt_datetime.getFullYear()+1);

        var d = dt_datetime.getDate()+"-"+dt_datetime.getMonth()+"-"+dt_datetime.getFullYear();
	var year = dt_datetime.getFullYear();

	var str_buffer = new String (
		"<html>\n"+
		"<head>\n"+
		"	<title>Calendar</title>\n"+
		"</head>\n"+
		"<body bgcolor=\"White\" onload=\"self.focus()\">\n"+
		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+
		"<tr><td bgcolor=\"#4682B4\">\n"+
		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+
		"<tr>\n	<td bgcolor=\"#4682B4\" colspan=\"2\"><a href=\"javascript:window.opener.show_calendar('"+
                str_target+"', '"+ dt2dtstr(dt_prev_year)+"'+'');\">"+
                "<img src=\"/Adelyamin/img/prev.gif\" width=\"16\" height=\"16\" border=\"0\" /></a> "+
                "<a href=\"javascript:window.opener.show_calendar('"+
		str_target+"', '"+ dt2dtstr(dt_prev_month)+"'+'');\">"+
		"<img src=\"/Adelyamin/img/prev.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"previous month\"></a>"+
                "</td>\n"+
		"<td bgcolor=\"#4682B4\" colspan=\"3\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
		arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</font></td>\n"+
		"<td bgcolor=\"#4682B4\" colspan=\"2\"><a href=\"javascript:window.opener.show_calendar('"+
		str_target+"', '"+dt2dtstr(dt_next_month)+"'+'');\">"+
		"<img src=\"/Adelyamin/img/next.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"next month\"></a> "+
                "<a href=\"javascript:window.opener.show_calendar('"+
                str_target+"', '"+ dt2dtstr(dt_next_year)+"'+'');\">"+
                "<img src=\"/Adelyamin/img/next.gif\" width=\"16\" height=\"16\" border=\"0\" /></a> "+
                "</td>\n</tr>\n"
	);

	var dt_current_day = new Date(dt_firstday);
	str_buffer += "<tr>\n";
	for (var n=0; n<7; n++)
		str_buffer += "	<td bgcolor=\"#87CEFA\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
		week_days[(n_weekstart+n)%7]+"</font></td>\n";
	str_buffer += "</tr>\n";
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		// print row heder
		str_buffer += "<tr>\n";
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if (dt_current_day.getDate() == dt_datetime.getDate() &&
					dt_current_day.getMonth() == dt_datetime.getMonth())
					// print current date
					str_buffer += "	<td bgcolor=\"#FFB6C1\" align=\"right\">";
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#DBEAF5\" align=\"right\">";
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\">";

				if (dt_current_day.getMonth() == dt_datetime.getMonth())
					// print days of current month
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr(dt_current_day)+"';window.close();\">"+
					"<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">";
				else 
					// print days of other months
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr(dt_current_day)+"';window.close();\">"+
					"<font color=\"gray\" face=\"tahoma, verdana\" size=\"2\">";
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		str_buffer += "</tr>\n";
	}
	str_buffer +=
		"</table>\n" +
		"</tr>\n</td>\n</table>\n" +
		"</body>\n" +
		"</html>\n";
                
	var vWinCal = window.open("", "Calendar", 
		"width=200,height=220,status=no,resizable=yes,top=200,left=200");
        //Calendar.window.focus();
	vWinCal.opener = self;
        //vWinCal.document.close();
        //vWinCal.focus();
        //if(vWinCal.window.focus){vWinCal.window.focus();}
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}


//function inputValue(dt_datetime) {
//    var v = new String (document.getElementById('year').value);
//    dt_datetime.setFullYear(v);
 //   var t = dt2dtstr(dt_datetime);
 //   return t;
//}

// datetime parsing and formatting routimes. modify them if you wish other datetime format
function str2dt (str_datetime) {
//	var re_date = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
	var re_date = /^(\d+)\-(\d+)\-(\d+)$/;
	if (!re_date.exec(str_datetime)) {
            return (new Date());
            }
//		return alert("Invalid Datetime format: "+ str_datetime);
//	return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4, RegExp.$5, RegExp.$6));
//        return (new Date (RegExp.$3, ((RegExp.$2)-1) , RegExp.$1

        var sp = str_datetime.split("-");
        var an = sp[2]; var m = sp[1]; var j = sp[0];
        return (new Date (an, m-1 , j));
}
function dt2dtstr (dt_datetime) {
	return (new String (
//			dt_datetime.getDate()+"-"+(dt_datetime.getMonth()+1)+"-"+dt_datetime.getFullYear()+" "));
			dt_datetime.getDate()+"-"+(dt_datetime.getMonth()+1)+"-"+dt_datetime.getFullYear()));
}
function dt2tmstr (dt_datetime) {
	return (new String (
			dt_datetime.getHours()+":"+dt_datetime.getMinutes()+":"+dt_datetime.getSeconds()));
}/***********************************************
* Show Hint script- ï¿½ Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function getMouseX(e){
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX ) 	{
		posx = e.pageX;
	}
	else if (e.clientX) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
	}
	return posx;
}

function getMouseY(e){
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageY) 	{
		posy = e.pageY;
	}
	else if (e.clientY) 	{
		posy = e.clientY + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
	}
	return posy;
}
function showhint(menucontents, obj, e, tipwidth){
	if ((ie||ns6) && document.getElementById("hintbox")){
		dropmenuobj=document.getElementById("hintbox")
		dropmenuobj.innerHTML=menucontents
		dropmenuobj.style.left=dropmenuobj.style.top=-500
		if (tipwidth!=""){
			dropmenuobj.widthobj=dropmenuobj.style
			dropmenuobj.widthobj.width=tipwidth
		}

		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=getMouseX(e)-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
		dropmenuobj.style.visibility="visible"
		dropmenuobj.style.zIndex=10
		obj.onmouseout=hidetip
	}
}

function ajaxCall(url, params, onsuccess, onerror) {
	if (top.window.location.href.indexOf("/card/") > -1) {
		$.ajax({
			type: "POST",
			url: url,
			data: params,
			success: function() {
				eval(onsuccess);
			},
			error: function () {
				eval(onerror);
			}
		});
	} else {
		new Ajax.Request(url, {
			parameters: params,
			onSuccess: function() {
				eval(onsuccess);
			},
			onFailure: function () {
				eval(onerror);
			}
		});
	}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox

