//UTILITY
function PrintPage(){
    if(document.getElementById('PrintArea')==null) return;
    var printstr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>"+ document.title +"</title>"+
    "<link href='/App_Themes/layout.css' rel='stylesheet' type='text/css'>"+
    "</head><body>"+
    document.getElementById('PrintArea').innerHTML;
    "</body></html>";
    
    winPrint = open();
    winPrint.document.open();
    winPrint.document.write(printstr);
    winPrint.document.close();
}

function Alert(msg){
	window.status=msg;
}
function GetFileNameWithoutExtension(filename){
	idx = filename.lastIndexOf('.');
	return filename.substring(0,idx);
}
function GetFileName(filename){
	idx = filename.lastIndexOf('/');
	filename = filename.substring(idx+1);
	if(filename.indexOf('#')>-1) filename = filename.substring(0,filename.indexOf('#'));
	if(filename.indexOf('?')>-1) filename = filename.substring(0,filename.indexOf('?'));
	if(filename.indexOf('&')>-1) filename = filename.substring(0,filename.indexOf('&'));
	
	return filename;
}
function GetCMSPageFileName(filename){
	idx = filename.lastIndexOf('/');
	filename = filename.substring(idx+1);
	if(filename.toLowerCase().indexOf('default.aspx')==0){
	    if(filename.indexOf('#')>-1) filename = filename.substring(0,filename.indexOf('#'));
	    if(filename.indexOf('&')>-1) filename = filename.substring(0,filename.indexOf('&'));
	}
	else
	{
	    if(filename.indexOf('#')>-1) filename = filename.substring(0,filename.indexOf('#'));
	    if(filename.indexOf('?')>-1) filename = filename.substring(0,filename.indexOf('?'));
	    if(filename.indexOf('&')>-1) filename = filename.substring(0,filename.indexOf('&'));
	}
	
	return filename;
}
function GetFileExtension(filename){
	idx = filename.lastIndexOf('.');
	return filename.substring(idx);
}

function getSize( dimension) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
	if(dimension=="w")
		return myWidth;
	else
		return myHeight;
}
function pageY(element) {
	  var curTop = 0;
	  if (document.getElementById || document.all) {
		while (element.offsetParent) {
		  curTop += element.offsetTop;
		  element = element.offsetParent;
		}
	  }
	  return curTop;
}
function pageX(element) {
	  var curTop = 0;
	  if (document.getElementById || document.all) {
		while (element.offsetParent) {
		  curTop += element.offsetLeft;
		  element = element.offsetParent;
		}
	  }
	  return curTop;
}
function pageSize(arg) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if(arg=='w')  return myWidth;
  else          return myHeight;
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function getElementTopPosition(e){
    var y=0;
    while(e){
    y+=e.offsetTop+((e.clientTop!=null)?e.clientTop:0);
    e=e.offsetParent;
    }
    return y;
}

function selectAllCheckBox(checkboxListObject){
    if(checkboxListObject==null) return;
    var allCheck = checkboxListObject.getElementsByTagName('input');
    for (var i = 0; i < allCheck.length; i++) { 
        type = allCheck[i].getAttribute("type"); 
        if ( type == "checkbox") { 
            allCheck[i].checked = true;
        }
    }
    return false;
}

function PressButtonOnEnter(obj, e, buttonid)
{ 
  var evt = e ? e : window.event;
  var bt = document.getElementById(buttonid);

  if (bt)
  { 
    if (evt.keyCode == 13)
    { 
      bt.click(); 
      return false; 
    } 
  } 
}

// *** FINE UTILITY

var callBackControl = "";

function OpenDialog(currentCallBackControl, dialog, type) 
{
    callBackControl = currentCallBackControl;
    $find(dialog).open(type); 
}

function ImageManagerFunction(sender, args) 
{
    var selectedItem = args.SelectedItem;
    var resultImageObject = args.Result;

    var txt = $get(callBackControl);
    if (document.all) 
    {
        txt.value = selectedItem.getPath();
    }
    else 
    {
        txt.value = selectedItem.getPath();
    }
}
function DocumentManagerFunction(sender, args) 
{
    var selectedItem = args.SelectedItem;
    var resultDocumentObject = args.Result;

    var txt = $get(callBackControl);
    if (document.all) 
    {
        txt.value = selectedItem.getPath(); ;
    }
    else 
    {
        txt.value = selectedItem.getPath();
    }
}
function FlashManagerFunction(sender, args) 
{
    var selectedItem = args.SelectedItem;
    var resultDocumentObject = args.Result;
    var txt = $get(callBackControl);

    if (document.all) 
    {
        txt.value = selectedItem.getPath();
    }
    else 
    {
        txt.value = selectedItem.getPath();
    }
}
function rollover(name, filename)
{
  var fullpath = '../App_Themes/Jesus/' + filename;
  document.images[name].src = fullpath;
  
  if( navigator.userAgent.toLowerCase().indexOf("msie") > -1 &&
    ( /msie\s(\d\.\d)/.exec( navigator.userAgent.toLowerCase() )[1] ) < 7)
    {
        if(name == 'jesusStory')
        {
        if (filename.indexOf('_on') > -1){
            showdiv('storyGroup');
        }
        else
            hidediv('storyGroup');
        }
        if(name == 'jesusToday')
        {
        if (filename.indexOf('_on') > -1){
            showdiv('todayGroup');
        }
        else
            hidediv('todayGroup');
        }
  }
}
function showdiv(objName) {
     if (document.getElementById) { // DOM3 = IE5, NS6
         document.getElementById(objName).style.visibility = 'visible';
     }
     else {
         if (document.layers) { // Netscape 4
             document.objName.visibility = 'visible';
         }
         else { // IE 4
             document.all.objName.style.visibility = 'visible';
         }
     }
 }
function hidediv(objName) {
     if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(objName).style.visibility = 'hidden';
     }
     else {
         if (document.layers) { // Netscape 4
             document.objName.visibility = 'hidden';
         }
         else { // IE 4
             document.all.objName.style.visibility = 'hidden';
         }
     }
 }

/* SLIDER ACCORDION */
var slider=function(){
	var array=[]; var speed=10; var timer=10;
	return{
		init:function(t,c){
			var s,ds,l,i,y;
			s=document.getElementById(t); ds=s.getElementsByTagName('div'); l=ds.length; i=y=0;
			for(i=0;i<l;i++){
				var d,did; d=ds[i]; did=d.id;
				if(did.indexOf("header")!=-1){
					y++; d.onclick=new Function("slider.process(this)");
				}else if(did.indexOf("content")!=-1){
					array.push(did.replace('-content','')); d.maxh=d.offsetHeight;
					if(c!=y){d.style.height='0px'; d.style.display='none'}
					else{d.style.display='block'}
				} 
			}
		},
		process:function(d){
			var cl,i; cl=array.length; i=0;
			for(i;i<cl;i++){
				var s,h,c,cd,img;
				s=array[i]; h=document.getElementById(s+'-header');
				img = document.getElementById(s+'-img');
				c=s+'-content'; cd=document.getElementById(c); clearInterval(cd.timer);
				if(h==d&&cd.style.display=='none'){
					cd.style.display='block'; this.islide(c,1);
					if(img.src.indexOf('Doctor') > -1)
					    img.src = '../Contents/Images/Buttons/btnDownDoctor.png';
					else
					    img.src = '../Contents/Images/Buttons/btnDown.png';
				}
				else if(cd.style.display=='block')
				{
				    this.islide(c,-1);
				    if(img.src.indexOf('Doctor') > -1)
					    img.src = '../Contents/Images/Buttons/btnLeftDoctor.png';
					else
					    img.src = '../Contents/Images/Buttons/btnLeft.png';
				}
			}
		},
		islide:function(i,d){var c,m; c=document.getElementById(i); m=c.maxh; c.direction=d; c.timer=setInterval("slider.slide('"+i +"')",timer)},
		slide:function(i){
			var c,m,h,dist; c=document.getElementById(i); m=c.maxh; h=c.offsetHeight;
			dist=(c.direction==1)?Math.round((m-h)/speed):Math.round(h/speed);
			if(dist<=1){dist=1}
			c.style.height=h+(dist*c.direction)+'px'; c.style.opacity=h/c.maxh; c.style.filter='alpha(opacity='+(h*100/c.maxh)+')';
			if(h<2&&c.direction!=1){
				c.style.display='none'; clearInterval(c.timer);
			}else if(h>(m-2)&&c.direction==1){clearInterval(c.timer)}
		}
};}();