﻿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


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 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





var NewsInterval;
function ShowNews(name, id, count, Roll,Rollable) {
    for (i = 1; i <= count; i++) {

        document.getElementById(name + i).className = "Hidden";
        document.getElementById(name + "Img" + i).src = "/App_Themes/Default/Images/bt" + name + "Off.png";

    } //for
    document.getElementById(name + id).className = name;
    document.getElementById(name + "Img" + id).src = "/App_Themes/Default/Images/bt" + name + "On.png";

   if (Rollable==true) window.clearTimeout(NewsInterval);

    if (Roll == true) {
        if (id == count) id = 1; else id = id + 1;
        
        NewsInterval=window.setTimeout("ShowNews('" + name + "'," + id + "," + count + "," + Roll + ","+Rollable+")", 2000);
    }
}
