// JavaScript Document
 
var secondMenuHover = "none";
var mainMenuHover = "none";
 
function showSecondMenu() {
	// Show the second menu selected and hide the others
	 
	hideSecondMenu(mainMenuHover,secondMenuHover);
	
          
	
	// select mainMenu
	mainMenuHover = showSecondMenu.arguments[0];  
  	document.getElementById(showSecondMenu.arguments[0]).style.border='1px solid #004400';
	document.getElementById(showSecondMenu.arguments[0]).style.backgroundColor='#ffffff';
	document.getElementById(showSecondMenu.arguments[0]).style.padding='5px';
	
	// show the second menu selected
	if (document.getElementById(showSecondMenu.arguments[1])) {
		secondMenuHover = showSecondMenu.arguments[1];
		
  		document.getElementById(showSecondMenu.arguments[1]).style.display='block';
 	}
}

function hideSecondMenu() {
	// deselect mainMenu
	if (mainMenuHover!="none" && document.getElementById(mainMenuHover)) {
		document.getElementById(hideSecondMenu.arguments[0]).style.border='none';
		document.getElementById(hideSecondMenu.arguments[0]).style.backgroundColor='transparent';
		document.getElementById(hideSecondMenu.arguments[0]).style.padding='6px';
	}
	// hide th second menu
	for (i=1; i<hideSecondMenu.arguments.length; i++) {
		if (secondMenuHover!="none" && document.getElementById(secondMenuHover)) {
	  		document.getElementById(hideSecondMenu.arguments[i]).style.display='none';
	 	}
	}
}

function showFirstDiv() {
	/* hide all tabs */
	for (i=1; i<showFirstDiv.arguments.length; i++) {
		document.getElementById(showFirstDiv.arguments[i]).style.display='none';
		document.getElementById(showFirstDiv.arguments[i]+'_link').className='';
	}
	/* show first */
	document.getElementById(showFirstDiv.arguments[0]).style.display='block';
	document.getElementById(showFirstDiv.arguments[0]+'_link').className='selected';
}

function showSelectedDiv() {
	/* hide all tabs */
	for (i=1; i<showSelectedDiv.arguments.length; i++) {
		document.getElementById(showSelectedDiv.arguments[i]).style.display='none';
	}
	/* show first */
	document.getElementById(showSelectedDiv.arguments[0]).style.display='block';
}

/* Accéder au WEBMAIL */


function GotoWebmail() {
	var listValue= document.getElementById('ovh_interface').value;
	switch(listValue) {
		case "imp":
			document.getElementById('logon').action = "https://ssl0.ovh.net/horde/imp/redirect.php";
		document.getElementById('imapuser').value=document.getElementById('username').value;
		document.getElementById('pass').value=document.getElementById('password').value;
		document.getElementById('logon').submit();
		break;
		case "squirrelmail":
			document.getElementById('logon').action = "https://ssl0.ovh.net/squirrelmail/src/redirect.php";      
		document.getElementById('login_username').value=document.getElementById('username').value;
		document.getElementById('secretkey').value=document.getElementById('password').value;
		document.getElementById('logon').submit();
		break;
        case "ilohamail":
            document.getElementById('logon').action = "https://ssl0.ovh.net/IlohaMail/source/index.php";
        document.getElementById('user').value=document.getElementById('username').value;
        document.getElementById('password').value=document.getElementById('password').value;
        document.getElementById('logon').submit();    
        break;
        case "roundcube":
            document.getElementById('logon').action = "https://ssl0.ovh.net/roundcube/index.php";
        document.getElementById('rcmloginuser').value=document.getElementById('username').value;
        document.getElementById('rcmloginpwd').value=document.getElementById('password').value;
        document.getElementById('logon').submit();
        break;

	}
}


function choose_img() {
        deco = Math.round(Math.random()*(90-1)+1);
            if (deco <= 10)
                { name = "index_center.jpg"; }
            if (deco > 10 && deco <= 20)
                { name = "index_center_xeon.jpg"; }
            if (deco > 20 && deco <= 30)
                { name = "index_center_control.jpg"; }
            if (deco > 30 && deco <= 40)
                { name = "index_center_network.jpg"; }
            if (deco > 40 && deco <= 50)
                { name = "index_center_electro.jpg"; }
            if (deco > 50 && deco <= 60)
                { name = "index_center_apc.jpg"; }
            if (deco > 60 && deco <= 70)
                { name = "index_center_router.jpg"; }
            if (deco > 70 && deco <= 80)
                { name="index_center_serverandpolgo.jpg"; }
            if (deco > 80)
                { name="index_center_hall.jpg"; }
            
            if (name != "")
                {
                   document.getElementById("changingImages").style.backgroundImage = 'url(themes/default/images/home/index/'+name+')'; 
                }
}



// opens and display a popu^for the order. Quite hard to command.

function popup(url, cible, width, height,param)
                {
                         var settings="toolbar=0,location=0,directories=0,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height;
                         var zewindow;



                         if(cible=='adm'){
                                  url=url+"&nic="+document.saisie_infos.nic_adm.value;
                         }
                         else if (cible=='tec'){
                                  url=url+"&nic="+document.saisie_infos.nic_tec.value;
                         }
                         else if (cible=='bil'){
                                  url=url+"&nic="+document.saisie_infos.nic_bil.value;
                         }
                         else if (cible=='envoi_codes'){
                                  url=url+"?nic="+document.login_form.code_nichandle.value+"&email="+document.login_form.code_email.value;
                         }
                         else if (cible=='voir_commande_v1'){
                                  url=url + "." + document.forms[1].voir_bc[param].value;
                         }
                         else if (cible=='voir_commande_v2'){
                                  url=url + "." + document.forms[0].voir_bc[param].value;
                         }
                         else if (cible=='voir_bc'){
                                  url=url + "." + param;
                         }
                         zewindow=window.open(url,"nichandle",settings);
                }

function setSection()
{
    var uri = location.pathname;

    var section="";
    if (uri.match('/fr/particulier'))
    {
        section="particulier";
    }
    else if (uri.match('/fr/entreprise'))
    {
        section="entreprise";
    }
    else if (uri.match('/fr/revendeur'))
    {
        section="revendeur";
    }

    if (section.length>1)
    {
        // set domain to .ovh.com to keep the exact smae domain name as the one used by apache (see mod_rewrite)
        var date = new Date();
        date.setTime(date.getTime()+(144000*1000));
        document.cookie = "section="+section+";expires="+date.toGMTString()+"; domain=.ovh.com; path=/";
    }
}


//TODO: need to add a document.onload or equiv
setSection();
