﻿var Timer;
var LastShowed;
var LastMain;

function getObject( obj ) {

  // step 1
  if ( document.getElementById ) {
    obj = document.getElementById( obj );

  // step 2
  } else if ( document.all ) {
    obj = document.all.item( obj );

  //step 3
  } else {
    obj = null;
  }

  //step 4
  return obj;
  }
  
  ////////////////////////////////////////////////////////////
  
  function displayObject( obj, show ) {

  // step 1
  obj = getObject( obj );
  if (obj==null) return;

  // step 2
  obj.style.display = show ? 'block' : 'none';
  obj.style.visibility = show ? 'visible' : 'hidden';
  
  }
  
function ShowMain( obj ) {

if (LastMain !=null) displayObject(LastMain,false);

displayObject( obj, true );
LastMain=obj;
LastShowed=obj;
window.clearTimeout(Timer);
}//function
  
function Show( obj,Container ) {

if ( obj==Container ) {
    window.clearTimeout(Timer);
    return;
    }
    
if (Container==LastShowed)
    {
    displayObject( obj, true );
    LastShowed=obj;
    window.clearTimeout(Timer);
    //alert(obj+' '+Container+' '+LastShowed);
    } else
    {
    //alert(obj+' '+Container+' '+LastShowed);
    window.clearTimeout(Timer);
    displayObject( LastShowed, false );
    LastShowed=obj;
    displayObject( obj, true );
    }    

}//function

function Hide( obj ) {
//if (obj!=LastShowed)return;

Timer=window.setTimeout('displayObject(\''+ obj+'\',false )',1000); 

}//function

function ShowList(CatID,tdFrame,DetailsPage,Year){

document.getElementById(tdFrame).innerHTML="<iframe src='"+DetailsPage + "?CatID="+CatID+"&year="+Year+"' width=100% height=700 frameBorder=0 scrolling=yes style=' border-width:0px'></iframe>";

}//function




RollIndex=0;
var oInterval ;

function RollContent(tdShow,Section,Count){

oInterval=window.setInterval('Roll(\''+tdShow+'\',\''+Section+'\','+Count+')',5500);
//oInterval = window.setInterval('alert("1")',2000);

}//function

function Roll(tdShow,Section,Count) {


//alert('a');
if (RollIndex==Count) RollIndex=0;

//objShow=getObject(tdShow);
document.getElementById(tdShow).innerHTML=document.getElementById("tdText"+Section+"_"+RollIndex).innerHTML;

RollIndex++;
}//function


var ClockInterval;
function RunClock(Hour,Minute,Second){

ClockInterval=window.setInterval('RunTheClock(\''+Hour+'\',\''+Minute+'\',\''+Second+'\')',1000);

}//function

function RunTheClock(Hour,Minute,Second){

var hh=parseInt(document.getElementById(Hour).innerHTML);
var mm=parseInt(document.getElementById(Minute).innerHTML);
var ss=parseInt(document.getElementById(Second).innerHTML);

ss++;
if (ss==60){ ss=0 ; mm++ ;
    if (mm==60){ mm=0 ; hh++ ;
        if (hh==24){ hh=0 ; }
    }    
}

document.getElementById(Hour).innerHTML=hh;
document.getElementById(Minute).innerHTML=mm;
document.getElementById(Second).innerHTML=ss;

}//function

function ChooseCat(CatID,txtCatID,txtRelatedCat,r){

if (document.getElementById('CatCheck'+r).checked){

    if (document.getElementById(txtCatID).value=='' ) document.getElementById(txtCatID).value=CatID;
    document.getElementById(txtRelatedCat).value=document.getElementById(txtRelatedCat).value+'#'+CatID+'#';
    
    }else{
    
    document.getElementById(txtRelatedCat).value=document.getElementById(txtRelatedCat).value.replace('#'+CatID+'#','');
    if (document.getElementById(txtRelatedCat).value == '##') document.getElementById(txtRelatedCat).value = '';
    }



}//function
////////////////////////////////////////////////////////////

function SwapInnerHtml(control,val1,val2){

obj=getObject(control);
if (obj==null) return;

if (obj.innerHTML==val1) {obj.innerHTML=val2;obj.style.color='orange';} else {obj.innerHTML=val1;obj.style.color='red';}

window.setTimeout('SwapInnerHtml(\''+control+'\',\''+val1+'\',\''+val2+'\')',2000);

}//function


var ClockDescInterval;
function RunClockDesc(Hour,Minute,Second){

ClockDescInterval=window.setInterval('RunTheClockDesc(\''+Hour+'\',\''+Minute+'\',\''+Second+'\')',1000);

}//function

function RunTheClockDesc(Hour,Minute,Second){

var hh=parseInt(document.getElementById(Hour).innerHTML);
var mm=parseInt(document.getElementById(Minute).innerHTML);
var ss=parseInt(document.getElementById(Second).innerHTML);

if (hh==0 && mm==0 && ss==0) {window.clearInterval(ClockDescInterval);return;}

if (mm==0) mm=60;
if (ss==0) ss=60;

ss--;
if (ss<=0){ ss=60 ; mm-- ;
    if (mm<=0){ mm=60 ; hh-- ;
        if (hh<=0){ hh=24 ; }
    }    
}

document.getElementById(Hour).innerHTML=hh;
document.getElementById(Minute).innerHTML=mm;
document.getElementById(Second).innerHTML=ss;

if (hh==24) document.getElementById(Hour).innerHTML=0;
if (mm==60) document.getElementById(Minute).innerHTML=0;
if (ss==60) document.getElementById(Second).innerHTML=0;


} //function

function ShowDiv(StartName, IDs) {

    window.clearTimeout(Timer);
    HideDivs(StartName);

    var arr = new Array;
    arr = IDs.split(" ");

    for (i = 0; i < arr.length; i++) {

        document.getElementById(StartName + arr[i]).className = document.getElementById(StartName + arr[i]).className.replace("Hidden", "Visible");
        if (document.getElementById(StartName + arr[i]).className.indexOf("Visible") < 0) document.getElementById(StartName + arr[i]).className = +" Visible";
    }



} //function

function HideDivs(NameStartWith) {

    var divs = document.getElementsByTagName('div');
    for (var i = 0; i < divs.length; i++) {
        var divname = divs[i].id;
        if (divname.indexOf(NameStartWith) > -1) {
            document.getElementById(divname).className = document.getElementById(divname).className.replace("Visible", "Hidden");
            if (document.getElementById(divname).className.indexOf("Hidden") < 0) document.getElementById(divname).className = +" Hidden";

        } //if
    } //for

} //function

function HideAll(Div, IDs) {

    Timer = window.setTimeout('HideDivs(\'' + Div + '\')', 1000);
} //function


