function showPicker(type, date) {
// date is expected in YYYY-MM-DD format
	var URL;
	var stats;
	URL = "picker.php?type=" + type + "&date=" + date;

	if (type.indexOf("parent") != -1) {
		stats = "height=500, width=450, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	else if (type.indexOf("date") != -1) {
		stats = "height=565, width=315, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	else {
		stats = "height=500, width=500, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	window.open(URL, "picker", stats);
}

function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



 function conid(cid) {
   document.contselect.conid.value=cid;
   document.contselect.submit();
   return false;
	 
 }
 
 function articleid(aid) {
   document.aselect.articleid.value=aid;
   document.aselect.submit();
   return false;
	 
 }
 
 function actionadd() {
   document.actionselect.submit();
   return false;
	 
 }
 
 function deletea(aid) {
 
  if (confirm('Are you sure you want to delete this?\nPlease Note: It will be permantently deleted.'))
    {
   document.deletearticle.articleid.value=aid;
   document.deletearticle.submit();
   return false;
   } else {
   return false;
   }
	 
 }
 
 
 function pageHide(pid) {
 
  if (confirm('Are you sure you want to hide this page'))
    {
   document.pdh.conid.value=pid;
   document.pdh.submit();
   return false;
   } else {
   return false;
   }
	 
 }
 
 function pageLive(pid) {
 
  if (confirm('Are you sure you want to make this page live?'))
    {
   document.pdl.conid.value=pid;
   document.pdl.submit();
   return false;
   } else {
   return false;
   }
	 
 }
 
 function pageDelete(pid) {
 
  if (confirm('Are you sure you want to permantently delete this page?\nPlease Note: All page elements will also be deleted.'))
    {
   document.pdd.conid.value=pid;
   document.pdd.submit();
   return false;
   } else {
   return false;
   }
	 
 }

function pageEdit(pid) {
document.pde.conid.value=pid;
document.pde.submit();
return false;	
	
}



/* functions for navigation */

function choosenavgroup(nid) {
   document.navgroup.navid.value=nid;
   document.navgroup.submit();
   return false;
	 
 } 
 
 function rmfromnav(pgid,nid) {
 if (confirm('Are you sure you want to remove this page from the navigation?'))
    {
   document.rmfromn.pid.value=pgid;
   document.rmfromn.navid.value=nid;
   document.rmfromn.submit();
   return false;
   } else {
   return false;
   }
	 
 } 
 
// news

function editnews(nid) {
   document.edn.newsid.value=nid;
   document.edn.submit();
   return false;
	 
 } 

function deletenews(nid) {
 
  if (confirm('Are you sure you want to permantently delete this news?'))
    {
   document.deln.newsid.value=nid;
   document.deln.submit();
   return false;
   } else {
   return false;
   }
	 
 }


function texttile() {
document.editcontent.submit();
}
 
 
function changeorder(val) {
   document.change_order.orderby.value=val;
   document.change_order.submit();
   return false;
 } 
 
function selectuser(uid) {
   document.select_user.userid.value=uid;
   document.select_user.submit();
   return false;
} 
 
 
function outputList(ar, name, size) { 
    var strIDs = "<select class=\"orderdrop\" size=\"" + size + "\" name=\"ro_lst" + name + "\">" 
    var sel = " selected" 
    for (var i=0;i<ar.length;i++) { 
        strIDs += "<option " + sel + " value=\"" + ar[i][0] + "\">" + ar[i][1] 
        sel = "" 
    } 
    strIDs+="</select>" 
    strIDs+="<input name=\"" + name + "\" type=hidden>" 
    return strIDs 
} 

function outputButton(bDir,name,val) { 
    return "<input class=\"orderbutton\" type=button value=\"" + val + "\" onclick=\"move(this.form," + bDir + ",'" + name + "')\">" 
} 

function move(f,bDir,sName) { 
    var el = f.elements["ro_lst" + sName] 
    var idx = el.selectedIndex 
    if (idx==-1) 
        alert("You must first select the item to reorder.") 
    else { 
        var nxidx = idx+( bDir? -1 : 1) 
        if (nxidx<0) 
            nxidx=el.length-1 
        if (nxidx>=el.length) 
            nxidx=0 
        var oldVal = el[idx].value 
        var oldText = el[idx].text 
        el[idx].value = el[nxidx].value 
        el[idx].text = el[nxidx].text 
        el[nxidx].value = oldVal 
        el[nxidx].text = oldText 
        el.selectedIndex = nxidx 
    } 
} 

function processForm(f) { 
    for (var i=0;i<f.length;i++) {     
        var el = f[i] 
        if (el.name.substring(0,6)=="ro_lst") { 
            var strIDs = "" 
            for (var j=0;j<f[i].options.length;j++) 
                strIDs += f[i].options[j].value + ", " 
                f.elements[f.elements[i].name.substring(6)].value = strIDs.substring(0,strIDs.length-2) 
        } 
    } 
} 


startList = function() {
	if (document.all&&document.getElementById) {
		if (!document.getElementById("nav")) return false;
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function popUpsSetUp() {
  if (!document.getElementsByTagName) return false;
  var lnks = document.getElementsByTagName("a");
  for (var i=0; i<lnks.length; i++) {
    if (lnks[i].getAttribute("class") == "popup") {
      lnks[i].onclick = function() {
        popUp(this.getAttribute("href"));
        return false;
      }
    }
  }
}

function popUp(winURL) {
  window.open(winURL,"popup","width=600,height=480,scrollbars=yes");
}

addLoadEvent(startList);
addLoadEvent(popUpsSetUp);


Effect.OpenUp = function(element) {
    element = $(element);
    new Effect.BlindDown(element, arguments[1] || {});
}

Effect.CloseDown = function(element) {
    element = $(element);
    new Effect.BlindUp(element, arguments[1] || {});
}

Effect.Combo = function(element) {
    element = $(element);
    if (element.style.display == 'none') { 
         new Effect.OpenUp(element, arguments[1] || {}); 
    } else { 
         new Effect.CloseDown(element, arguments[1] || {}); 
    }
}

function update_div_message (div, message) {
    document.getElementById(div).style.display = 'block';
    document.getElementById(div).innerHTML = message;
}
