Team:UC Chile/js/myJSfile.js

From 2013.igem.org

Revision as of 01:35, 11 August 2013 by Fierices (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

///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 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);}

}