//added by anton 06/30/04: checking all script
function checkAll(checkboxControl, toCheckedElementName)
{
  var elements = checkboxControl.form.elements;
  for(i=0; i < elements.length; i++)
  {
    if( elements[i].type == "checkbox" && elements[i].name == toCheckedElementName )
      elements[i].checked = checkboxControl.checked;
  }
  return false;
}

/*Browsercheck object*/
function bwcheck(){
        //In theory we should use object detection, but this script needs work-arounds for almost every browser...
        this.ver=navigator.appVersion
        this.agent=navigator.userAgent.toLowerCase()
        this.dom=document.getElementById?1:0
        this.ns4=(!this.dom && document.layers)?1:0;
        this.op=window.opera
        this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
        this.ie=this.agent.indexOf("msie")>-1 && !this.op
        if(this.op){
                this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
                this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
                this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
        }else if(this.moz) this.ns6 = 1
        else if(this.ie){
                this.ie4 = !this.dom && document.all
        this.ie5 = (this.agent.indexOf("msie 5")>-1)
        this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
        this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
        }
        this.mac=(this.agent.indexOf("mac")>-1)
        this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
  this.usedom= this.ns6||this.op7//Use dom creation
  this.reuse = this.ie||this.op7||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""

  this.idBug = false;
  this.idBug = (this.ns4 || this.ns6 || this.moz)

        return this
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//-------
function confirmDelete(){
  return window.confirm('Are you sure that you want to DELETE this item?');
//'Do you really want to delete this item?'
}
function openCategoryWindow(url)
{
  window.open(url,"_blank", "toolbar=no,status=no,resizable=no,scrollbars=yes,width=350,height=200");
}
/** Function to resize popup window to fit the real size of content
 * param nullImageSrc - the pathto null image - may be drop out it?
 * param isScrolable - indicates whether this window will be scrollable
 * dependency - in the html document should be define 2 images with ids MM_wSize and MM_hSize which would indicate the real content's sizes
 */
function MM_resizePopUpWindow(nullImageSrc,isScrolable){
    //img_preload = new Image();
    //img_preload.src = nullImageSrc;//MM_resizePopUpWindow('<%=request.getContextPath()%>/img/no.gif');
    if(isScrolable) window.resizeTo(document.getElementById('MM_wSize').width+26, document.getElementById('MM_hSize').height+32);
    else{
        if(document.all) window.resizeTo(document.getElementById('MM_wSize').width+9, document.getElementById('MM_hSize').height+29);
        else window.resizeTo(document.getElementById('MM_wSize').width+26, document.getElementById('MM_hSize').height+31);
    }
}

/** Function for disable form item
* param item - form element that must be disabled
*/
function disableItem(item)
{
  item.disabled='disabled';
  item.style.background='#DDDDDD';
}

/** Function for enable form item
* param item - form element that must be enabled
*/
function enableItem(item)
{
  item.disabled='';
  item.style.background='#FFFFFF';
}
/****************************************************************************************************
* Set of functions for hidinhg - restoring of objects.
*/
//Service array to save the state of objects
var htmlVals=new Array('','','','','','','','','','','','','','','','','','','','');
var panelStates=new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
MM_preloadImages('/abc/img/collapse.gif','/abc/img/expand.gif');
var cookieName=window.location+'hpanels';
qpos=cookieName.lastIndexOf("?");
if(qpos>0) cookieName=cookieName.substring(0,qpos)+'hpanels';

var cookieNotExpired=1000 * 60 * 60 * 24 * 3;//!!! Defines time in millisec., during which cookie does not expire. Now It sets to 1 year
var isSaved=false;
window.onload=loadPanels;
window.onunload=saveState;
function loadPanels()
{
    var states=getCookie(cookieName);
    if(states && states.length>1)
    {
        panelStates=getCookie(cookieName).split("-");
        for(i=1;i<panelStates.length;i++) hideTab(i,panelStates[i]==0?true:false);
    }
}
function saveState()
{
    //  if(!isSaved) setCookie(cookieName,panelStates.join("-"),new Date(new Date().getTime() + cookieNotExpired));
}
//To get cookie with name name
function getCookie(name) {
    var prefix = name + "="
    var cookieStartIndex = document.cookie.indexOf(prefix)
    if (cookieStartIndex == -1)
        return null
    var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
    if (cookieEndIndex == -1)
        cookieEndIndex = document.cookie.length
    return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
//To set cookie with name, value, expiration data for a domain with secure
function setCookie(name, value, expires, path, domain, secure) {
//    var curCookie = name + "=" + escape(value) +
//        ((expires) ? "; expires=" + expires.toGMTString() : "") +
//        ((path) ? "; path=" + path : "") +
//        ((domain) ? "; domain=" + domain : "") +
//        ((secure) ? "; secure" : "")
//        document.cookie = curCookie
}
/*
* To hide multy objects
* param the first - to hide - set to true, to show set to false, the second - varList - list of numbers of hided objects
*/
function multyHide() { //v3.0
  var bw=new bwcheck();
  if(bw.ie) {
    var i,a=multyHide.arguments;
    if(a[0])
    {
        var states=getCookie(cookieName);
        if(states && states.length>1) return;
    } else
    {
        saveState();
        isSaved=true;
    }
    for(i=1; i<a.length; i++)  hideTab(a[i],a[0]);
  }
}
/**
* Set of functions for hidinhg - restoring of objects.
* param id - number of object
* param mode - true to hide, false to show
*/
function hideTab(id,mode)
{
    var element=document.getElementById("m_tab"+id);
    if(!element) return;
    tmpHtml=element.innerHTML;
    if(mode)
    {
        if(tmpHtml!="")
        {
            element.innerHTML=htmlVals[id];
            htmlVals[id]=tmpHtml;
            panelStates[id]=0;
        }
        else return;
    }
    else
    {
        if(tmpHtml=="")
        {
            element.innerHTML=htmlVals[id];
            htmlVals[id]=tmpHtml;
            panelStates[id]=1;
        }
        else return;
    }
    var img=document.getElementById("m_tabimg"+id);
    if(img)
    {
        if(img.src.indexOf('/abc/img/collapse.gif')>-1)
        {
            img.src='/abc/img/expand.gif';
            img.alt='EXPAND';
        }
        else
        {
            img.src='/abc/img/collapse.gif';
            img.alt='COLLAPSE';
        }
    }
}
/*
* To hide/restore a tab
* param img - image to change state
* param id - object number
*/
function hideRestore(img,id)
{
  var bw=new bwcheck();
  if(bw.ie) {
    var element=document.getElementById("m_tab"+id);
    tmpHtml=element.innerHTML;
    element.innerHTML=htmlVals[id];
    htmlVals[id]=tmpHtml;
    if(img)
    {
        if(img.src.indexOf('/abc/img/collapse.gif')>-1)
        {
            img.src='/abc/img/expand.gif';
            img.alt='EXPAND';
            panelStates[id]=0;
        }
        else
        {
            img.src='/abc/img/collapse.gif';
            img.alt='COLLAPSE';
            panelStates[id]=1;
        }
    }
  }
}
/*
* End of Set of functions for hidinhg - restoring of objects.
****************************************************************************************************/

function popUp( daLink, daTarget, daProp )
{
  var comwin = window.open(daLink,daTarget,daProp);
  comwin.focus() ;
}

function openAWindow( pageToLoad, winName, width, height, center) {
  xposition=0; yposition=0;
  if ((parseInt(navigator.appVersion) >= 4 ) &&(center)) {
   xposition = (screen.width - width) / 2;
   yposition = (screen.height - height) / 2;
  }
  args = "width=" + width + ","
  + "height=" + height + ","
  + "location=0,"
  + "menubar=0,"
  + "resizable=0,"
  + "scrollbars=0,"
  + "status=0,"
  + "titlebar=0,"
  + "toolbar=0,"
  + "hotkeys=0,"
  + "screenx=" + xposition + "," //NN Only
  + "screeny=" + yposition + "," //NN Only
  + "left=" + xposition + "," //IE Only
  + "top=" + yposition; //IE Only
  window.open( pageToLoad, winName, args );
}
function openAWindowprint( pageToLoad, winName, width, height, center) {
  xposition=0; yposition=0;
  if ((parseInt(navigator.appVersion) >= 4 ) &&(center)) {
   xposition = (screen.width - width) / 2;
   yposition = (screen.height - height) / 2;
  }
  args = "width=" + width + ","
  + "height=" + height + ","
  + "location=0,"
  + "menubar=0,"
  + "resizable=0,"
  + "scrollbars=1,"
  + "status=0,"
  + "titlebar=0,"
  + "toolbar=1,"
  + "hotkeys=0,"
  + "screenx=" + xposition + "," //NN Only
  + "screeny=" + yposition + "," //NN Only
  + "left=" + xposition + "," //IE Only
  + "top=" + yposition; //IE Only
  window.open( pageToLoad, winName, args );
}
function showAdv(){
MM_openBrWindow('/abc/alert/alert.jsp','selectObjTypeWnd','status=no,resizable=no,scrollbars=no,width=385,height=155');
}

/** call RO insert or generate url for menu. */
function insertRO(objectType, objectId, relatedObjectType, relatedObjectId )
{
    if( objectType == 101 )//menu item
    {
        if( window.opener )
        {
            var wnd = window.opener.opener;
            window.opener.close();
            window.close();
        }else{
            window.history.back();
        }
        if( wnd )
        {
            var typesUrls = new Array();
            typesUrls[1] = null;
            typesUrls[2] = null;
            typesUrls[3] = "/news/newsDetails.do?newsId=";
            typesUrls[4] = "/news/announcementsList.do?announcementId=";
            typesUrls[5] = "/news/pressDetails.do?pressId=";
            typesUrls[6] = "/shop/product.do?productId=";
            typesUrls[7] = "/adc/adcDetails.do?adcId=";
            typesUrls[8] = "/course/courseOverview.do?courseId=";
            typesUrls[9] = "/event/eventDetails.do?eventId=";
            typesUrls[10] = "/volunteer/viewjob.do?jobId=";
            typesUrls[11] = "/scholarship/scholarship/view.do?scholarshipId=";
            typesUrls[12] = null;
            typesUrls[13] = "http://www.abyssinian.org/abc/template/album.do?ministryId=&galleryId=";
            var element = wnd.document.getElementById("urlID");
            if( element && typesUrls[relatedObjectType])
                element.value = typesUrls[relatedObjectType]+relatedObjectId;
            else
              element.value = "";
        }
    }
    else//insert object
    {
        window.location = "/abc/r_objects/objects.do?spaction=add&objectType="+objectType+"&objectId="+objectId+"&relatedObjectType="+relatedObjectType+"&relatedObjectId="+relatedObjectId;
    }
}

function showPhotoGallery(objType, objId)
{
  var url = "/abc/r_objects/front_gallery2.do?spaction=view&objectType="+objType+"&objectId="+objId;
  if(typeof(jss) != "undefined")
    url+="&n="+jss;
  popUp( url, 'viewgalerynwnd','status=no,scrollbars=no,width=380,height=205' );
}