﻿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){

document.getElementById(tdFrame).innerHTML="<iframe src='"+DetailsPage + "?CatID="+CatID+"' 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,Step) {
    //alert(RollIndex);
    RollIndex = RollIndex + Step;
if (RollIndex>Count ) RollIndex=0;
if (RollIndex < 0) RollIndex =Count ;

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+'#','');
    
    }



}//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,tdTil){

ClockDescInterval=window.setInterval('RunTheClockDesc(\''+Hour+'\',\''+Minute+'\',\''+Second+'\',\''+tdTil+'\')',1000);

}//function

function RunTheClockDesc(Hour,Minute,Second,tdTil){

var hh=parseInt(document.getElementById(Hour).innerHTML);
var mm=parseInt(document.getElementById(Minute).innerHTML);
var ss=parseInt(document.getElementById(Second).innerHTML);
//alert(tdTil);
if (hh==0 && mm==0 && ss==0) {window.clearInterval(ClockDescInterval);document.getElementById(tdTil).innerHTML="<iframe src='/Athan.aspx' width=1 height=1 frameBorder=0 scrolling=no style=' border-width:0px'></iframe>";return;}

ss--;
if (ss<=0){ 
    if (mm>0){
        ss=60 ; mm-- ;

    }else{
    if (hh>0){hh--;mm=59;ss=60;} else {window.clearInterval(ClockDescInterval);document.getElementById(tdTil).innerHTML="<iframe src='/Athan.aspx' width=1 height=1 frameBorder=0 scrolling=no style=' border-width:0px'></iframe>";return;}
    }    
}


document.getElementById(Hour).innerHTML=hh;
document.getElementById(Minute).innerHTML=mm;
document.getElementById(Second).innerHTML=ss;

}//function

//////////////////////////////////////////////////////////////////////////////////
function LimitCount(txt,Counter){

document.getElementById(Counter).innerHTML=document.getElementById(txt).value.length;

if (document.getElementById(txt).innerHTML.length>800) {
    document.getElementById(txt).style.color='orange';
    }
    
if (document.getElementById(txt).innerHTML.length>990) {
    document.getElementById(txt).innerHTML=document.getElementById(txt).innerHTML.substr(0,1000);
    document.getElementById(txt).style.color='red';
    }

}//function