$(document).ready(function(){initMenu();toggleBoxEnvie();toggleComposant();toggleBoxSecret()});
$(window).resize(initMenu);

var Nom = navigator.appName;
var ns = (Nom == 'Netscape') ? 1:0;
var ie = (Nom == 'Microsoft Internet Explorer') ? 1:0;

function post(repeater_node,url){
    if (ns) {   document.getElementById("uid_contact").value = repeater_node.childNodes[1].value;}
    if (ie) {   document.getElementById("uid_contact").value = repeater_node.childNodes[0].value;}
    var f=document.forms[0]; f.method="POST"; f.action=url; f.submit(); 
}
function postUIDAbonne(repeater_node,url){
    if (ns) {   document.getElementById("uid_abonne").value = repeater_node.childNodes[1].value;}
    if (ie) {   document.getElementById("uid_abonne").value = repeater_node.childNodes[0].value;}
    var f=document.forms[0]; f.method="POST"; f.action=url; f.submit(); 
}
function afficheDiv(node) {
    var a;
    if (ns) { a = node.childNodes[1].childNodes[1].firstChild.childNodes[4].firstChild.checked; }
    if (ie) { a = node.childNodes[0].childNodes[0].firstChild.childNodes[3].firstChild.checked; }
    if(a)
    {
        $(".dv_indentif").hide();
        $(".dv_upload").show()
    }
    else
    {
        $(".dv_indentif").show();
        $(".dv_upload").hide()
    }
}

function completer_pop(linkButton)
{
    var prenom;
    var nom;
    var index;
    if (ns) {   index = linkButton.parentNode.parentNode.childNodes[1].firstChild.childNodes[13].title;
                prenom = linkButton.parentNode.parentNode.childNodes[1].firstChild.childNodes[5].title;
                nom = linkButton.parentNode.parentNode.childNodes[1].firstChild.childNodes[9].title;
            }
    if (ie) {   index = linkButton.parentNode.parentNode.childNodes[0].firstChild.childNodes[9].title;
                prenom = linkButton.parentNode.parentNode.childNodes[0].firstChild.childNodes[3].title;
                nom = linkButton.parentNode.parentNode.childNodes[0].firstChild.childNodes[6].title;
    }
    /*alert(index);
    alert(prenom);
    alert(nom);*/
    $('.pop_index').val(index);
    $('.pop_prenom').val(prenom);
    $('.pop_nom').val(nom);
    $('#Confirmation').show();
}
function completer_pop_uid_contact(node)
{
    var uid_contact;
    var id_abonne;
    var prenom;

    if (ns) {
       uid_contact = node.childNodes[1].value;
       id_abonne = node.childNodes[3].value; 
       prenom = node.childNodes[5].value; 
    }
    if (ie) {
       uid_contact = node.childNodes[0].value;
       id_abonne = node.childNodes[2].value; 
       prenom = node.childNodes[4].value; 
    }
    /*alert(uid_contact);
    alert(id_abonne);
    alert(prenom);*/
    document.getElementById("uid_contact").value = uid_contact;
    $(".pop_photo").attr("src","http://dev.samesecret.com/photo_membre/" + id_abonne +".Jpeg");
    $(".pop_prenom").html(prenom);
    $('#popConfirmSecretFriends').show();
}
function toggleBoxEnvie(){
	$(".toggleBoxEnvie").each(function(i){
			   
		$(this).click(function(){
			if($(this).hasClass("reduit")){
				$(this).removeClass("reduit").addClass("agrandit");
				$(this).parent().parent().next().hide();
				//$(".separatorBoxEnvie:eq("+i+"),table:eq("+i+")").hide();
			}else
			{
				$(this).removeClass("agrandit").addClass("reduit");
				//$(".separatorBoxEnvie:eq("+i+"),table:eq("+i+")").show();
				$(this).parent().parent().next().show();
			}
			})
		}					  
	)
}

function toggleBoxSecret(){
	$(".toggleBoxSecret").each(function(i){			   
		$(this).click(function(){
			if($(this).hasClass("reduit")){
				$(this).removeClass("reduit").addClass("agrandit");
				$(".contentBoxEnvie:eq("+i+")").hide();
			}else
			{
				$(this).removeClass("agrandit").addClass("reduit");
				$(".contentBoxEnvie:eq("+i+")").show();
			}
			})
		}					  
	)
}

function BoxSecretAllHide(){
	$(".toggleBoxSecret").each(function(i){
		$(this).removeClass("reduit").addClass("agrandit");
		$(".contentBoxEnvie:eq("+i+")").hide();
	})
}

function BoxSecretAllShow(){
	$(".toggleBoxSecret").each(function(i){
		$(this).removeClass("agrandit").addClass("reduit");
		$(".contentBoxEnvie:eq("+i+")").show();
	})
}

function toggleByID(sender,id){
    if($(sender).hasClass("reduit")){
        $(sender).removeClass("reduit").addClass("agrandit");
        $("#"+id).hide();
    } else {
        $(sender).removeClass("agrandit").addClass("reduit");
        $("#"+id).show();
    }
}
        
function toggleComposant(){
	$(".toggleBoxComposant").each(function(i){
			   
		$(this).click(function(){
			if($(this).hasClass("reduit")){
				$(this).removeClass("reduit").addClass("agrandit");
				//$(".boxContentXL:eq("+i+")").hide();
				$(this).parent().next().hide();
			}else
			{
				$(this).removeClass("agrandit").addClass("reduit");
				//$(".boxContentXL:eq("+i+")").show();
				$(this).parent().next().show();
			}
			})
		}					  
	)
}

function initMenu(){
	if($.browser.msie && $.browser.version == '6.0'){
		$("#nav div.NavGrisBleu").each(function(){
			$(this).children("div").addClass("bgNavLeftGrisBleu")
				.next("a").addClass("bgNavGrisBleu")
				.next("div").addClass("bgNavRightGrisBleu");
		});
		$("#nav div.NavRose").each(function(){
			$(this).children("div").addClass("bgNavLeftRose")
				.next("a").addClass("bgNavRose")
				.next("div").addClass("bgNavRightRose");
		});
		$("#nav div.NavBleu").each(function(){
			$(this).children("div").addClass("bgNavLeftBleu")
				.next("a").addClass("bgNavBleu")
				.next("div").addClass("bgNavRightBleu");
		});
		$("#nav div.NavViolet").each(function(){
			$(this).children("div").addClass("bgNavLeftViolet")
				.next("a").addClass("bgNavViolet")
				.next("div").addClass("bgNavRightViolet");
		});
	}

$("#nav div").each(function(){		
		$(this).hover(
			function(){
			try{$(this).addClass("active").next("ul").show().css("left",$(this).children("div.bgNavLeft").position().left-40);}catch(e){}			
			$(this).siblings("ul").hover(function(){
					$(this).show().prev().addClass("active");
				},
				function(){
					$(this).hide().prev().removeClass("active");	
				})
			},
			function(){
			$(this).removeClass("active").next("ul").hide();
			}
		);
	})
}

function toggleBox_ContentAndFooter(sender){
    if($(sender).hasClass("reduit")){
        $(sender).removeClass("reduit").addClass("agrandit");
        $(sender).parent().next().hide();
        $(sender).parent().next().next().hide();
    } else {
        $(sender).removeClass("agrandit").addClass("reduit");
        $(sender).parent().next().show();
        $(sender).parent().next().next().show();
    }
}


function UpdateListDyn(list_name,list_clientID,id_child){
    var result=$.ajax({url:"../commun/GetList.aspx?list_name="+list_name+"&id_child="+id_child,
    cache: false,
    async:false}).responseText;
    //alert(result);
    if(result.match("<ChildList>")){
        var id=list_clientID;
        //alert(id);return;
        var text=result.substring(result.indexOf('<ChildList>',0)+11,result.indexOf('</ChildList>',0));
        var list=document.getElementById(id);
        //Vide l'ancienne liste
        var count=list.length;
        for(i=0;i<count;i++){
            list.remove(list.selectedIndex);
        }
        //Rempli la liste avec les donnes retournées
        count=result.substring(result.indexOf('<count>',0)+7,result.indexOf('</count>',0));
        var tableau=text.split('|');
        for(i=0;i<=count;i++){
            var y=document.createElement('option');
            var temp=tableau[i].split(','); 
            y.text=temp[1]; 
            y.value=temp[0];
            var x=document.getElementById(id);
            try{
                x.add(y,null); 
            } catch(ex){
                x.add(y); 
            }
        }
    }
}

function LimitTyping_Length(obj, maxLength, evt){
    var charCode=(evt.which) ? evt.which : event.keyCode
    var max = maxLength - 0;
    var text = obj.value;
    if(text.length > max){
        var ignoreKeys = [8,46,37,38,39,40,35,36];
        for(i=0;i<ignoreKeys.length;i++){
            if(charCode==ignoreKeys[i]){
                return true;
            }
        }
        return false;
    } else {
        return true;    
    }
}

function TopPositionLimited(objetClicked,moveTop,limit){
    //returns the top position of the click, with a limited minimum 
    var myTop;
    if(($(objetClicked).position().top - moveTop ) < limit){
        myTop = 0;
    } else {
        myTop = $(objetClicked).position().top - moveTop;
    } 
    return myTop
}   