/*****************
 * XmlHttpRequest *
 *****************/
// Renvoie le texte de l'objet ActiveXObject le plus récent depuis une liste
var IContactAjaxPickRecentProgID = function(idList){
    // found progID flag
    var bFound = false;
    for (var i = 0; i < idList.length && !bFound; i++) {
        try {
            var oDoc = new ActiveXObject(idList[i]);
            o2Store = idList[i];
            bFound = true;
        } 
        catch (objException) {
            // trap; try next progID
        };
            };
    if (!bFound) 
        throw ("Aucun ActiveXObject n'est valide sur votre ordinateur, pensez à mettre à jour votre navigateur");
    idList = null;
    return o2Store;
}

if (!IContactXmlHttpRequestHandler) {
    var IContactXmlHttpRequestHandler = new Array();
}

// Retourne un nouvel objet XmlHttpRequest
var IContactAjaxGetXmlHttpRequest_AXO = null;
var IContactAjaxGetXmlHttpRequest = function(){
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest()
    }
    else 
        if (window.ActiveXObject) {
            if (!IContactAjaxGetXmlHttpRequest_AXO) {
                IContactAjaxGetXmlHttpRequest_AXO = IContactAjaxPickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
            }
            return new ActiveXObject(IContactAjaxGetXmlHttpRequest_AXO)
        }
    return false;
}

function accountRecharg(){
    if (confirm("Vous allez interrompre le show en cours pour recharger votre compte. Etes vous sur de vouloir quitter ?")) {
        window.location = "/account/account_paiement.php";
    }
}

//Test si une chaine est alphanumerique
function commun_is_alphanum(value){
    re = /\W/
    return !re.test(value);
}

//Fonction qui ouvre la popup de diffusion
function diffuser(){
    window.open('../account/account_popup_diff.php', 'Diffusion', 'toolbar=no,menubar=no,statusbar=no,scrollbars=no,width=800,height=680,left=' + (screen.width - 900) / 2 + ',top=' + (screen.height - 800) / 2 + '');
}

//Fonction de changement de langue
function open_img(filename){
    window.open('../sommaire/photo_src.php?filename=' + filename, '', 'toolbar=no,menubar=no,statusbar=no,scrollbars=no,width=800,height=700,left=' + (screen.width - 800) / 2 + ',top=' + (screen.height - 700) / 2 + '');
}

function userDetailExpand(ID_user){
    /*
	$('detailUser_' + ID_user).appear({
        duration: 0.5
    });
    */
	$('detailUser_' + ID_user).style.display = 'inline';

}

function userDetailHide(ID_user){
    /*
	$('detailUser_' + ID_user).fade({
        duration: 0.5
    });
    */
	//userDetailPhotoSwapStop(ID_user);
	$('detailUser_' + ID_user).style.display = 'none';

}

var timeOutVignetteStart;
function userDetailPhotoSwapStart(ID_user, current_vignette_anim, max_vignette_anim) 
{
	if(userPhotoNb[ID_user] > 0 && userPhotoNb[ID_user] >= current_vignette_anim)
	{
		$('photoUser_' + ID_user).src = userPhoto[ID_user][current_vignette_anim];
	    //Preparation du prochain changement (2 sec)
	    if (current_vignette_anim >= max_vignette_anim) {
	        current_vignette_anim = 1;
	    }
	    else {
	        current_vignette_anim++;
	    }
	    timeOutVignetteStart = setTimeout("userDetailPhotoSwapStart ('" + ID_user + "', '" + current_vignette_anim + "', '" + max_vignette_anim + "')", 1000);
	}
}

function userDetailPhotoSwapStop(ID_user) {
    if(userPhotoNb[ID_user] > 0)
	{
		clearTimeout(timeOutVignetteStart);
	    $('photoUser_' + ID_user).src = userPhotoPrinc[ID_user];
	}
}

function userDetailVdoStart(divId, vdo_src, flvplayerPath, linkVal) {

		if($(divId).innerHTML == '' || $(divId).innerHTML == 'Chargement en cours...')
		{
			$(divId).update('<object type="application/x-shockwave-flash" data="'+flvplayerPath+'/swf/vdoModRead.swf?filename='+vdo_src+'&linkVal='+linkVal+'" width="150" height="150"><param name="movie" value="'+flvplayerPath+'/swf/vdoModRead.swf?filename='+vdo_src+'&linkVal='+linkVal+'" /><param name="wmode" value="transparent" /></object>');
		}
}

function userDetailVdoEnd(divId) {
		$(divId).update('Chargement en cours...');
}


//Fonction de changement de langue
function change_lang(page, lang){
    cd = page + "?LANG_CUR=" + lang;
    //window.location.href = cd;
    gotoPage(page + "?LANG_CUR=" + lang);
}

function validation_mail(){
    document.getElementById("ifr_submit").src = "../inscription/validation_account_process.php";
}

function ajax_refresh(urlPage, args, div){
    IContactAjaxDivLoadContent(div, urlPage + '?' + args);
}

function preloadImages(){
    var d = document;
    if (d.images) {
        if (!d.p) 
            d.p = new Array();
        var i, j = d.p.length, a = preloadImages.arguments;
        for (i = 0; i < a.length; i++) 
            if (a[i].indexOf("#") != 0) {
                d.p[j] = new Image;
                d.p[j++].src = a[i];
            }
    }
}

//Affichage du DIV d'avertissement page payante
function docProtectWarnShow(messageURL, cssClass, palCheckWidth, palCheckHeight){
    //docProtectMsgObj.setHtmlContent(messageContent);//Pas de message mais une recup d'URL
    docProtectMsgObj.setSize(palCheckWidth, palCheckHeight);
    docProtectMsgObj.setCssClassMessageBox(cssClass);
    docProtectMsgObj.setSource(messageURL);
    docProtectMsgObj.setShadowDivVisible(true); // Ombre disponible	
    docProtectMsgObj.display();
}

function docProtectWarnHide(){
    docProtectMsgObj.close();
}

//Gestion du DIV masquant la popup (avertissement avant reroutage)
/**
 * @constructor
 */
DHTML_modalMessage = function(){
    var url; // url of modal message
    var htmlOfModalMessage; // html of modal message
    var divs_transparentDiv; // Transparent div covering page content
    var divs_content; // Modal message div.
    var iframe; // Iframe used in ie
    //var layoutCss;							// Name of css file;
    var width; // Width of message box
    var height; // Height of message box
    var existingBodyOverFlowStyle; // Existing body overflow css
    var dynContentObj; // Reference to dynamic content object
    var cssClassOfMessageBox; // Alternative css class of message box - in case you want a different appearance on one of them
    var shadowDivVisible; // Shadow div visible ? 
    var shadowOffset; // X and Y offset of shadow(pixels from content box)
    var MSIE;
    
    this.url = ''; // Default url is blank
    this.htmlOfModalMessage = ''; // Default message is blank
    //this.layoutCss = 'modal-message.css';	// Default CSS file
    this.height = 200; // Default height of modal message
    this.width = 400; // Default width of modal message
    this.cssClassOfMessageBox = false; // Default alternative css class for the message box
    this.shadowDivVisible = true; // Shadow div is visible by default
    this.shadowOffset = 5; // Default shadow offset.
    this.MSIE = false;
    if (navigator.userAgent.indexOf('MSIE') >= 0) 
        this.MSIE = true;
    
    
}

DHTML_modalMessage.prototype = {
    setSource: function(urlOfSource){
        this.url = urlOfSource;
    },
    setHtmlContent: function(newHtmlContent){
        this.htmlOfModalMessage = newHtmlContent;
    },
    setSize: function(width, height){
        if (width) 
            this.width = width;
        if (height) 
            this.height = height;
    },
    setCssClassMessageBox: function(newCssClass){
        this.cssClassOfMessageBox = newCssClass;
        if (this.divs_content) {
            if (this.cssClassOfMessageBox) 
                this.divs_content.className = this.cssClassOfMessageBox;
            else 
                this.divs_content.className = 'modalDialog_contentDiv';
        }
        
    },
    setShadowOffset: function(newShadowOffset){
        this.shadowOffset = newShadowOffset
        
    },
    display: function(){
        if (!this.divs_transparentDiv) {
            this.__createDivs();
        }
        
        // Redisplaying divs
        this.divs_transparentDiv.style.display = 'block';
        this.divs_content.style.display = 'block';
        this.divs_shadow.style.display = 'block';
        if (this.MSIE) 
            this.iframe.style.display = 'block';
        this.__resizeDivs();
        
        /* Call the __resizeDivs method twice in case the css file has changed. The first execution of this method may not catch these changes */
        window.refToThisModalBoxObj = this;
        setTimeout('window.refToThisModalBoxObj.__resizeDivs()', 150);
        
        this.__insertContent(); // Calling method which inserts content into the message div.
    },
    setShadowDivVisible: function(visible){
        this.shadowDivVisible = visible;
    },
    close: function(){
        //document.documentElement.style.overflow = '';	// Setting the CSS overflow attribute of the <html> tag back to default.
        
        /* Hiding divs */
        this.divs_transparentDiv.style.display = 'none';
        this.divs_content.style.display = 'none';
        this.divs_shadow.style.display = 'none';
        if (this.MSIE) 
            this.iframe.style.display = 'none';
        
    },
    addEvent: function(whichObject, eventType, functionName, suffix){
        if (!suffix) 
            suffix = '';
        if (whichObject.attachEvent) {
            whichObject['e' + eventType + functionName + suffix] = functionName;
            whichObject[eventType + functionName + suffix] = function(){
                whichObject['e' + eventType + functionName + suffix](window.event);
            }
            whichObject.attachEvent('on' + eventType, whichObject[eventType + functionName + suffix]);
        }
        else 
            whichObject.addEventListener(eventType, functionName, false);
    },
    __createDivs: function(){
        // Creating transparent div
        this.divs_transparentDiv = document.createElement('DIV');
        this.divs_transparentDiv.className = 'modalDialog_transparentDivs';
        this.divs_transparentDiv.style.left = '0px';
        this.divs_transparentDiv.style.top = '0px';
        
        document.body.appendChild(this.divs_transparentDiv);
        // Creating content div
        this.divs_content = document.createElement('DIV');
        this.divs_content.className = 'modalDialog_contentDiv';
        this.divs_content.id = 'DHTMLSuite_modalBox_contentDiv';
        this.divs_content.style.zIndex = 100000;
        
        if (this.MSIE) {
            this.iframe = document.createElement('<IFRAME src="about:blank" frameborder=0>');
            this.iframe.style.zIndex = 90000;
            this.iframe.style.position = 'absolute';
            document.body.appendChild(this.iframe);
        }
        
        document.body.appendChild(this.divs_content);
        // Creating shadow div
        this.divs_shadow = document.createElement('DIV');
        this.divs_shadow.className = 'modalDialog_contentDiv_shadow';
        this.divs_shadow.style.zIndex = 95000;
        document.body.appendChild(this.divs_shadow);
        window.refToModMessage = this;
        this.addEvent(window, 'scroll', function(e){
            window.refToModMessage.__repositionTransparentDiv()
        });
        this.addEvent(window, 'resize', function(e){
            window.refToModMessage.__repositionTransparentDiv()
        });
        
        
    },
    __getBrowserSize: function(){
        var bodyWidth = document.documentElement.clientWidth;
        var bodyHeight = document.documentElement.clientHeight;
        
        var bodyWidth, bodyHeight;
        if (self.innerHeight) { // all except Explorer 
            bodyWidth = self.innerWidth;
            bodyHeight = self.innerHeight;
        }
        else 
            if (document.documentElement && document.documentElement.clientHeight) {
                // Explorer 6 Strict Mode 		 
                bodyWidth = document.documentElement.clientWidth;
                bodyHeight = document.documentElement.clientHeight;
            }
            else 
                if (document.body) {// other Explorers 		 
                    bodyWidth = document.body.clientWidth;
                    bodyHeight = document.body.clientHeight;
                }
        return [bodyWidth, bodyHeight];
        
    },
    __resizeDivs: function(){
    
        var topOffset = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
        
        if (this.cssClassOfMessageBox) 
            this.divs_content.className = this.cssClassOfMessageBox;
        else 
            this.divs_content.className = 'modalDialog_contentDiv';
        
        if (!this.divs_transparentDiv) 
            return;
        
        // Preserve scroll position
        var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
        var sl = Math.max(document.body.scrollLeft, document.documentElement.scrollLeft);
        
        window.scrollTo(sl, st);
        setTimeout('window.scrollTo(' + sl + ',' + st + ');', 10);
        
        this.__repositionTransparentDiv();
        
        
        var brSize = this.__getBrowserSize();
        var bodyWidth = brSize[0];
        var bodyHeight = brSize[1];
        
        // Setting width and height of content div
        this.divs_content.style.width = this.width + 'px';
        this.divs_content.style.height = this.height + 'px';
        
        // Creating temporary width variables since the actual width of the content div could be larger than this.width and this.height(i.e. padding and border)
        var tmpWidth = this.divs_content.offsetWidth;
        var tmpHeight = this.divs_content.offsetHeight;
        
        this.divs_content.style.left = Math.ceil((bodyWidth - tmpWidth) / 2) + 'px';
        ;
        this.divs_content.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) + topOffset) + 'px';
        
        if (this.MSIE) {
            this.iframe.style.left = this.divs_content.style.left;
            this.iframe.style.top = this.divs_content.style.top;
            this.iframe.style.width = this.divs_content.style.width;
            this.iframe.style.height = this.divs_content.style.height;
        }
        
        this.divs_shadow.style.left = (this.divs_content.style.left.replace('px', '') / 1 + this.shadowOffset) + 'px';
        this.divs_shadow.style.top = (this.divs_content.style.top.replace('px', '') / 1 + this.shadowOffset) + 'px';
        this.divs_shadow.style.height = tmpHeight + 'px';
        this.divs_shadow.style.width = tmpWidth + 'px';
        
        
        
        if (!this.shadowDivVisible) 
            this.divs_shadow.style.display = 'none'; // Hiding shadow if it has been disabled
    },
    __repositionTransparentDiv: function(){
        this.divs_transparentDiv.style.top = Math.max(document.body.scrollTop, document.documentElement.scrollTop) + 'px';
        this.divs_transparentDiv.style.left = Math.max(document.body.scrollLeft, document.documentElement.scrollLeft) + 'px';
        var brSize = this.__getBrowserSize();
        var bodyWidth = brSize[0];
        var bodyHeight = brSize[1];
        this.divs_transparentDiv.style.width = bodyWidth + 'px';
        this.divs_transparentDiv.style.height = bodyHeight + 'px';
        
    },
    __insertContent: function(){
        if (this.url) { // url specified - load content dynamically
            IContactAjaxDivLoadContent('DHTMLSuite_modalBox_contentDiv', this.url);
        }
        else { // no url set, put static content inside the message box
            this.divs_content.innerHTML = this.htmlOfModalMessage;
        }
    }
}

//Creation de la fenetre d'alerte
docProtectMsgObj = new DHTML_modalMessage(); // We only create one object of this class
docProtectMsgObj.setShadowOffset(4); // Gere la disposition de l'ombre
//Recuperation du statut actuel du salon en cours
function show_get_cur_status(){
    var dataURL = '/animations/spectateur_cur_showstatus.php?date=' + new Date();
    //Creation du flux
    var requestId = IContactXmlHttpRequestHandler.length;
    IContactXmlHttpRequestHandler[requestId] = IContactAjaxGetXmlHttpRequest();
    
    // Ici on va voir comment faire du post
    IContactXmlHttpRequestHandler[requestId].open("GET", dataURL, false);
    IContactXmlHttpRequestHandler[requestId].send(null);
    
    return (IContactXmlHttpRequestHandler[requestId].responseText);
}

//Recuperation de contenu AJAX dans un DIV
function IContactAjaxDivLoadContent(divId, dataURL){
    //Creation du flux
    var requestId = IContactXmlHttpRequestHandler.length;
    IContactXmlHttpRequestHandler[requestId] = IContactAjaxGetXmlHttpRequest();
    
    // On défini ce qu'on va faire quand on aura la réponse
    IContactXmlHttpRequestHandler[requestId].onreadystatechange = function(){
        IContactAjaxDivLoadContentProcess(requestId, divId);

    }
    
    // Ici on va voir comment faire du post
    IContactXmlHttpRequestHandler[requestId].open("GET", dataURL, true);
    IContactXmlHttpRequestHandler[requestId].send(null);
}

function IContactAjaxDivLoadContentProcess(httpRequest, divId){
    // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
    if (IContactXmlHttpRequestHandler[httpRequest].readyState == 4 && IContactXmlHttpRequestHandler[httpRequest].status == 200) {
		var msgLst = IContactXmlHttpRequestHandler[httpRequest].responseText;
        document.getElementById(divId).innerHTML = msgLst;
    }
}

/*FIN GENERIQUE*/


function aff_etoile(ID, srcimg){
    for (i = 1; i < ID; i++) {
        document.getElementById("note_" + i).src = srcimg + '/etoile_jaune.gif';
    }
    while (i != 6) {
        document.getElementById("note_" + i).src = srcimg + '/etoile_grise.gif';
        i++
    }
}

function valid_note(note, ID_show){
    document.getElementById("ifr_submit").src = "../sommaire/note_process.php?note=" + note + "&ID_show=" + ID_show;
}

//Vérif validité email par REGEXP
function verif(email){
    var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/
    return (reg.exec(email) != null)
}
