Team:UC Chile/js/myJSfile.js

From 2013.igem.org

Revision as of 18:38, 25 September 2013 by Fierices (Talk | contribs)

/*function that rotate the menu, takes as argument the object that invoke the method*/ function aux(num,Obj) {

   /*Selecting the proper browser*/
   var is_safari = navigator.userAgent.toLowerCase().indexOf('safari/') > -1;
   var is_chrome= navigator.userAgent.toLowerCase().indexOf('chrome/') > -1;
   var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox/') > -1;
   var is_ie = navigator.userAgent.toLowerCase().indexOf('msie ') > -1;
   var style = "";
   if(is_ie)
   {
       if(parseInt(navigator.userAgent.toLowerCase().split('msie ')[1])<=9)
       {style='msTransform';}
       else{style='transform';}
   }
   else if(is_firefox)
   {
       style='transform';
   }
   else
   {
       style='WebkitTransform';
   }
   
   /*Rotating the apropiate amount of degrees*/
   /*
       Positions on the menu
       
          | 2 | 3 |
        | 1 | 7 | 4 |
          | 6 | 5 |
       
       menu -> store the div containing the whole menu
       selected -> store the div containing the selected item, position 
       
   */
   
   var menu = document.getElementsByClassName("new_menu")[0];
   var Obj  = menu.getElementsByClassName("hexa")[num-1];
   var selected = menu.getElementsByClassName("sele")[0];
   var aux  = menu.style[style];    
   if(selected==Obj)
   {return;}
   selected.className=selected.className.split("sele")[0];
   if(aux==)
   {
       aux='rotate(0deg)';        
   }
   var grados   = parseInt((aux.split("(")[1]));
   var resto    = grados%360;
   var L = parseInt(Obj.className.split("h")[1]);
   var sele_L = parseInt(selected.className.split("h")[1]);
   var subMenu = Obj.getElementsByClassName("sub")[0];
   var sele_subMenu = selected.getElementsByClassName("sub")[0];
   if(sele_subMenu!=null){
       sele_subMenu.className='sub oculto';
       var sele_subs = sele_subMenu.getElementsByClassName("sub_item");
       for (var i=0;i<sele_subs.length;i++)
       { 
           sele_subs[i].className=sele_subs[i].className.split(" visible")[0] + " oculto";
       }
   }
   if(subMenu!=null){
       subMenu.className='sub visible';
       var subs = subMenu.getElementsByClassName("sub_item");
       for (var i=0;i<subs.length;i++)
       { 
           subs[i].className=subs[i].className.split(" oculto")[0] + " visible";
       }   
   }
   if(L==7)
   {
       selected.className="h7 hexa";
       Obj.className="h"+sele_L+" hexa";
       Obj.className += " sele";
       return;
   }
   Obj.className += " sele";    
   var Pos = (L+(resto/60)+6)%6;
   if(Pos==0){Pos=6;}
   grados=grados+60*(4-Pos);
   menu.style[style]='rotate('+grados+'deg)';
   var hs   = document.getElementsByClassName("text");
   for (var i=0;i<hs.length;i++)
   { 
       hs[i].style[style]='rotate('+(-1*grados)+'deg)';
   }
   var ss   = document.getElementsByClassName("sub");
   for (var i=0;i<ss.length;i++)
   { 
       ss[i].style[style]='rotate('+(-1*grados)+'deg)';
   }

}


function Opacar(num){

   var imgs   = document.getElementsByClassName("imgMenu_img");
   var objeto = imgs[num];
   var aux = objeto.className;    
   if(aux.indexOf("selected") == -1)
   {
       objeto.className = "imgMenu_img opaco_2";
   }

}

function Transparentar(num){

   var imgs   = document.getElementsByClassName("imgMenu_img");
   var objeto = imgs[num];
   var aux = objeto.className;
   if(aux.indexOf("selected") == -1)
       {
           objeto.className = "imgMenu_img transparente";
       }

}

function Seleccionar_imgMenu(num) {

   var divs   = document.getElementsByClassName("imgMenu_cont");
   var imgs   = document.getElementsByClassName("imgMenu_img");
   for (var i=0;i<divs.length;i++)
   { 
       divs[i].className = "imgMenu_cont off_the_flow";
   }
   for (var i=0;i<imgs.length;i++)
   { 
       imgs[i].className = "imgMenu_img transparente";
   }
   divs[num].className = "imgMenu_cont in_the_flow";
   imgs[num].className = "imgMenu_img opaco selected";

}

///Mostrar-Ocultar hijos de clases "SubMenu" function Mostrar_Submenu(Obj) {

   var a = Obj.getElementsByClassName("Sub_Menu");
   a[0].style.visibility="visible";

} function Ocultar_Submenu(Obj) {

   var a = Obj.getElementsByClassName("Sub_Menu");
   a[0].style.visibility="hidden";

}

///Motrar-Ocultar por id function Mostrar(id_name) {

   var a = document.getElementById(id_name);
   a.style.visibility="visible";

} function Ocultar(id_name) {

   var a = document.getElementById(id_name);
   a.style.visibility="hidden";

}

function destacar(obj,val) { var colors = new Array(); colors[0] = "#000000"; colors[1] = "#ffffff"; colors[2] = "#606060"; colors[3] = "#33ffff"; obj.style.backgroundColor=colors[val]; }

function Act(id_name,opc) {

   try{
   var a = document.getElementById(id_name);
   var b = document.getElementById('count');
   a.style.opacity = opc;
   b.innerHTML = opc;    
   }
   catch(exception)
   {alert("Error");}

}

function Modificar(obj) {

   if("Disp1"==obj.className)
   {return;}
   var ul_e = obj.parentNode;
   var lis = ul_e.getElementsByTagName("li");
   var num = 0;
   for(var i=0;i<lis.length;i++)
   {
       lis[i].className="";
       if(lis[i]==obj)
       {
           num = i;
           lis[i].className="Disp1"; 
       }      
       else
       {  
           lis[i].className="Disp2";    
       }
   }
   var divs = document.getElementsByClassName("subcont");
   for(var i=0;i<divs.length;i++)
   {
       if(i==num)
       {
           divs[i].style.display="block";
       }
       else
       {
           divs[i].style.display="none";
       }
   }
   return false;

}

function load(){

       var container = document.getElementById("container");
       var divs = document.getElementsByClassName("subcont");
       var l    = window.location;
       var loc  = window.location.pathname.split("/").pop().replace(".html","");
       var hash = window.location.hash.substr(1);
       
       if(loc=="Project")
       {aux(1);}
       else if(loc=="Methodology")
       {aux(2);}
       else if(loc=="Modelling")
       {aux(3);}
       else if(loc=="Team")
       {aux(4);}
       else if(loc=="Human%20practices")
       {
           aux(5);
           return;
       }
       else if(loc=="More")
       {aux(6);}
       else
       {aux(7);}
       
       if(hash=="")
       {hash=divs[0].id;}
       var div = document.getElementById(hash);
       for(var i=0;i<divs.length;i++)
       {                
           if(divs[i].id==hash)
               {
                   divs[i].style.display="block";
               }
           else
           {divs[i].style.display="none";}
       }

}


function SetCalendar(month) {

   var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
   var month_span = document.getElementsByClassName("month")[0];
   month_span.innerHTML=months[month];
   month_span.className="month "+month;
   var weekdiv = document.getElementById('Week-div');
   weekdiv.innerHTML="";
   var days_list = new Array("Mon","Tue","Wed","Thur","Fri","Sat","Sun");
   var days_this_month = new Date(2013,month+1,0).getDate();
   var past_month;
   if(month-1<0){past_month=11;}
   else{past_month=month-1;}
   var days_past_month = new Date(2013,past_month+1,0).getDate();
   var first_day = ((new Date(2013,month,1)).getDay()+6)%7;
   var last_day = days_this_month - ((days_this_month-7+first_day)%7);
   var day_of_week = 0;
   var day = 1;
   var day_past_month = days_past_month - first_day + 1;
   var week = document.createElement("DIV");
   var days = document.createElement("DIV");
   week.className="week";
   var s = document.createElement("SPAN");
   s.className = "calendar_span week_resume";
   var id_week = "text_";
   if(first_day==0){
       id_week=id_week+"1-7"+"_"+(month+1);
       s.innerHTML=" Week: 1-7 ";
   } /* id del texto resumen de la semana ("text_dia de inicio-dia final_mes")*/
   else{
       id_week=id_week+day_past_month+"-"+(7-first_day)+"_"+(month+1);
       s.innerHTML=" Week: "+day_past_month+"-"+(7-first_day)+" ";
   }
   var displayed = document.getElementsByClassName("disp")[0];    
   if(displayed!=null){
   displayed.className = (displayed.className.split(" ")[0])+" "+"notdisp";
   }
   var to_disp = document.getElementById(id_week);
   if(to_disp!=null){
   to_disp.className = (to_disp.className.split(" ")[0]) +" "+"disp";
   }    
   s.onclick = (function() {var cID= id_week;return function() { setSelected(cID);}})();
   week.appendChild(s);
   
   var s2 = document.createElement("SPAN");
   s2.className = "next";
   s2.innerHTML=">";
   s2.onclick = (function() {var cD= days; var cW= week;return function() { DispDays(cD,cW);}})();
   week.appendChild(s2);
   days.className="days";
   var s3 = document.createElement("SPAN");
   s3.className = "back";
   s3.innerHTML="<";
   s3.onclick = (function() {var cD= days; var cW= week;return function() { DispWeek(cD,cW);}})();
   days.appendChild(s3);
   while(day_past_month <= days_past_month)
   {
       var id = "text_"+day_past_month+"_"+(month); /* id del texto resumen del dia("text_dia_mes")*/
       var d = document.createElement("SPAN");
       d.innerHTML=" "+days_list[day_of_week]+"
"+(day_past_month); if(day_of_week<6){ d.className="calendar_span day"; d.onclick = (function() {var cID= id;return function() { setSelected(cID);}})(); } else{ d.className="calendar_span day invalid"; d.onclick = function(){}; } days.appendChild(d); day_past_month=day_past_month+1; day_of_week = (day_of_week+1)%7; } while(day<=last_day) { var id = "text_"+day+"_"+(month+1); var d = document.createElement("SPAN"); d.innerHTML=" "+days_list[day_of_week]+"
"+(day); if(day_of_week<6){ d.className="calendar_span day"; d.onclick = (function() {var cID= id;return function() { setSelected(cID);}})(); } else{ d.className="calendar_span day invalid"; d.onclick = function(){}; } days.appendChild(d); if(day_of_week == 6 ) { var div_aux = document.createElement("DIV"); div_aux.appendChild(week); div_aux.appendChild(days); weekdiv.appendChild(div_aux); if(day<last_day){ var week = document.createElement("DIV"); var days = document.createElement("DIV"); week.className="week"; var s = document.createElement("SPAN"); var id_week = "text_"+(day+1)+"-"+(day+7)+"_"+(month+1); s.innerHTML=" Week: "+(day+1)+"-"+(day+7)+" "; s.onclick = (function() {var cID= id_week;return function() { setSelected(cID);}})(); s.className = "calendar_span week_resume"; week.appendChild(s); var s2 = document.createElement("SPAN"); s2.className = "next"; s2.innerHTML=">"; s2.onclick = (function() {var cD= days; var cW= week;return function() { DispDays(cD,cW);}})(); week.appendChild(s2); days.className="days"; var s3 = document.createElement("SPAN"); s3.className = "back"; s3.innerHTML="<"; s3.onclick = (function() {var cD= days; var cW= week;return function() { DispWeek(cD,cW);}})(); days.appendChild(s3); } } day=day+1; day_of_week = (day_of_week+1)%7; }

}

function setSelected(id){

   var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
   var displayed = document.getElementsByClassName("disp")[0];    
   var to_disp = document.getElementById(id);
   if(displayed!=null){
       displayed.className = (displayed.className.split(" ")[0])+" "+"notdisp";
   }
   if(to_disp!=null){
       to_disp.className = (to_disp.className.split(" ")[0]) +" "+"disp";
   }
   else{
       to_disp      = document.getElementById("text_day_off");
       var text_day = to_disp.getElementsByClassName("title")[0];
       var day      = parseInt(id.split("_")[1]);
       var month    = parseInt(id.split("_")[2])-1;
       var aux      ="";
       if( day == 1 || day == 21 || day == 31 )
       {aux="st";}
       else if( day == 2 )
       {aux="nd";}
       else if( day == 3 )
       {aux="rd";}
       else
       {aux="th";}
       text_day.innerHTML = months[month]+" "+day+aux;
       to_disp.className = (to_disp.className.split(" ")[0]) +" "+"disp";
   }

}

function DispWeek(days,week) {

   days.style.display="none";
   week.style.display="inline-block";

}

function DispDays(days,week) {

   days.style.display="inline-block";
   week.style.display="none";

}

function newMonth(i){ var min_month = 3; var max_month = 5; var month = document.getElementsByClassName("month")[0]; var new_month = parseInt(month.className.split(" ")[1])+i; if(new_month<min_month || new_month>max_month){return;} SetCalendar(new_month); }

function img(obj) {

   try{
   var body = document.getElementsByTagName('body');
   var v1 = document.getElementById('V1');
   var i = document.getElementById('imagen');
   var lis = document.getElementsByName('imgs_li');
   var imgs  = document.getElementsByName('imgs');
   for(var x=0;x<lis.length;x++)
   {
       if(lis[x]==obj)
       {
           i.src=imgs[x].src;
           break;
       }
   }
   v1.style.visibility="visible";
   }
   catch(e)
   {alert("Error: "+e.description);}

}

function next() {

   try{
   var i = document.getElementById('imagen');
   var imgs  = document.getElementsByName('imgs');
   for(var x=0;x<imgs.length;x++)
   {
       if(imgs[x].src==i.src)
       {
           i.src=imgs[(x+1)%imgs.length].src;
           break;
       }
   }
   }
   catch(e)
   {alert("Error: "+e.description);}

}

function prev() {

   try{
   var i = document.getElementById('imagen');
   var imgs  = document.getElementsByName('imgs');
   for(var x=0;x<imgs.length;x++)
   {
       if(imgs[x].src==i.src)
       {
           i.src=imgs[(x-1+imgs.length)%imgs.length].src;
           break;
       }
   }
   }
   catch(e)
   {alert("Error: "+e.description);}

}

function img_out() {

   try{
   var v1 = document.getElementById('V1');
   var i = document.getElementById('imagen');
   i.src="";
   v1.style.visibility="hidden";
   }
   catch(e)
   {alert("Error: "+e.description);}

}

function drop(obj) {

   dropdowninfo = obj.parentNode;
   up           = dropdowninfo.getElementsByClassName("DropDown_info_up")[0];
   down         = dropdowninfo.getElementsByClassName("DropDown_info_down")[0];
   content      = dropdowninfo.getElementsByClassName("DropDown_info_content")[0];    
   if(down.className.indexOf('in_the_flow') > -1)
   {
       down.className="DropDown_info_down off_the_flow";
       up.className  ="DropDown_info_up in_the_flow";
       content.className="DropDown_info_content in_the_flow";
   }
   else
   {
       down.className="DropDown_info_down in_the_flow";
       up.className  ="DropDown_info_up off_the_flow";
       content.className="DropDown_info_content off_the_flow";
   }    

}