// Allows target blank links in XHTML 1.0 strict
function open_target_blank()
{
    var liens = document.getElementsByTagName('a');
    for (var i = 0 ; i < liens.length ; ++i) {
        if (liens[i].className == '_blank') {
            liens[i].onclick = function() {
                window.open(this.href);
                return false;
            };
        }
    }
}
window.onload = open_target_blank;


//UNDER MENU
var menuToHide=null;
var menuToShow=null;

function hideAll() {
	for(var x=0; x<listeMenu.length; x++) {
		document.getElementById(listeMenu[x]).style.display="none";
	}
}

function hideContent(menuToHide) {
	document.getElementById(menuToHide).style.display="none";
}

function showContent(menuToShow) {
	document.getElementById(menuToShow).style.display="block";
}


/*** Rotation de screenshots ***/
var pic_timer;
var clip_pics = new Array();

function play_slideshow(clip_id) {

stop_slideshow();

var html_obj = document.getElementById('clip_'+clip_id);
var clip_obj = clip_pics['clip_'+clip_id];

clip_obj.index = (clip_obj.index + 1) % clip_obj.images.length;
html_obj.src   = clip_obj.images[clip_obj.index].src;

pic_timer = setTimeout('play_slideshow('+clip_id+')', '750');
}


function stop_slideshow() {

	if (pic_timer) {
		clearTimeout(pic_timer);
	}
}


//DELETE FAVORITE CLIP, MOVIE, ACTOR
function delete_favorite(id, type) {
	if(type == 'clip' || type == 'dvd' || type == 'actor'){
		if(id == ''){
			alert(mess_err_form);
			return 0;
		}
	}
	else{
		alert(mess_err_form);
		return 0;
	}

	var del_url = "favorites.php?id="+id+"&type="+type+"&del_fav=1";

	if (confirm(mess_del_fav)) {
    	//alert(del_url);
    	document.location = del_url;
  	}
}

function add_input_form(myForm, name, value){
	var myInput = document.createElement("input") ;
	myInput.setAttribute("name", name) ;
	myInput.setAttribute("value", value);
	myForm.appendChild(myInput) ;
}

var mtimer=null;
var subMenuToHide=null;
var listeSubMenu=new Array("under-fanclub","under-about");

function show_under(menu, state) {
	if(state) {
		if(mtimer) {
			clearInterval(mtimer);
			mtimer=null;
		}
		hideAllSubMenus();
		document.getElementById(menu).style.visibility="visible";
	}
	else {
		subMenuToHide=menu;
		mtimer=setInterval(hideSubMenu,300);
	}
}

function hideAllSubMenus() {
	for(var x=0; x<listeSubMenu.length; x++) {
		document.getElementById(listeSubMenu[x]).style.visibility="hidden";
	}
}

function hideSubMenu() {
	document.getElementById(subMenuToHide).style.visibility="hidden";
	clearInterval(mtimer);
	mtimer=null;
}

function resetTimer() {
	clearInterval(mtimer);
	mtimer=null;
}


//encode a string passed in parameter
function urlencode( str ) {

    var hash_map = {}, unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The hash_map is identical to the one in urldecode.
    hash_map["'"]   = '%27';
    hash_map['(']   = '%28';
    hash_map[')']   = '%29';
    hash_map['*']   = '%2A';
    hash_map['~']   = '%7E';
    hash_map['!']   = '%21';
    hash_map['%20'] = '+';
    hash_map['\u00DC'] = '%DC';
    hash_map['\u00FC'] = '%FC';
    hash_map['\u00C4'] = '%D4';
    hash_map['\u00E4'] = '%E4';
    hash_map['\u00D6'] = '%D6';
    hash_map['\u00F6'] = '%F6';
    hash_map['\u00DF'] = '%DF';
    hash_map['\u20AC'] = '%80';
    hash_map['\u0081'] = '%81';
    hash_map['\u201A'] = '%82';
    hash_map['\u0192'] = '%83';
    hash_map['\u201E'] = '%84';
    hash_map['\u2026'] = '%85';
    hash_map['\u2020'] = '%86';
    hash_map['\u2021'] = '%87';
    hash_map['\u02C6'] = '%88';
    hash_map['\u2030'] = '%89';
    hash_map['\u0160'] = '%8A';
    hash_map['\u2039'] = '%8B';
    hash_map['\u0152'] = '%8C';
    hash_map['\u008D'] = '%8D';
    hash_map['\u017D'] = '%8E';
    hash_map['\u008F'] = '%8F';
    hash_map['\u0090'] = '%90';
    hash_map['\u2018'] = '%91';
    hash_map['\u2019'] = '%92';
    hash_map['\u201C'] = '%93';
    hash_map['\u201D'] = '%94';
    hash_map['\u2022'] = '%95';
    hash_map['\u2013'] = '%96';
    hash_map['\u2014'] = '%97';
    hash_map['\u02DC'] = '%98';
    hash_map['\u2122'] = '%99';
    hash_map['\u0161'] = '%9A';
    hash_map['\u203A'] = '%9B';
    hash_map['\u0153'] = '%9C';
    hash_map['\u009D'] = '%9D';
    hash_map['\u017E'] = '%9E';
    hash_map['\u0178'] = '%9F';

    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);

    for (unicodeStr in hash_map) {
        hexEscStr = hash_map[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }

	return ret;

    // Uppercase for full PHP compatibility
    /*return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });*/
}

//LOGOUT
function logout_site() {
	var lo_url = "logout.php?id=6gftttrs67";
	document.location = lo_url;
}