var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // plus 1 year
function SetCookieAndRefresh(large,site) {
	document.cookie = "large" + "=" + escape(large) + "; expires=" + expiry.toGMTString();
	window.location = site;
}
function submit_form(object) {
	//object.target = "biblewindow"; 
	object.submit(); 
}
function submit_form2(object) {
    if(object.sitekey.value == "bibleref") { 
    	object.action = "http://www.biblegateway.com/bible";
    	object.passage.value = object.textfield.value; }
    else if(object.sitekey.value == "biblekeyword") { 
    	object.action = "http://www.biblegateway.com/cgi-bin/bible";
    	object.search.value = object.textfield.value; 
    	object.passage.value = ""; }
    else { 
    	object.action = "http://www.google.com/search";
    	if(object.sitekey.value == "google") { object.sitesearch.value = ""; }
    else if(object.sitekey.value != "") { object.sitesearch.value = object.sitekey.value; }
    	object.q.value = object.textfield.value;
    }
	//object.target = "newwindow"; 
	object.submit(); 
}
function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) { return getCookieVal (j); }
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
function CreateCSSTemplateLink (basedir,cssfile) {
	if(GetCookie("template") != null) {
		document.write("<link rel='stylesheet' href='");
		document.write(basedir+GetCookie("template")+"/"+cssfile);
		document.write("' type='text/css' >");
	}
}
function RedirectPage (pageURL) {
	window.location.href=pageURL;
}
function ConfirmSubmit(submittext) {
	if (confirm(submittext)) return true;
	else return false;
}

function showAdminPanel(adminpanelURL)
{
  if(parent.document.getElementById("adminpanel"))
  {
    parent.document.getElementById("adminpanel").cols="81%,19%";
    document.getElementById("showAdminPanel").style.display = "none";
    document.getElementById("hideAdminPanel").style.display = "block";
    return false;
  } else {
//    window.location.href = adminpanelURL;
    window.open(adminpanelURL);
    return false;
  }
}
function hideAdminPanel(adminpanelURL)
{
  if(parent.document.getElementById("adminpanel"))
  {
    parent.document.getElementById("adminpanel").cols="100%";
    document.getElementById("showAdminPanel").style.display = "block";
    document.getElementById("hideAdminPanel").style.display = "none";
    return false;
  } else {
//    window.location.href = adminpanelURL;
    window.open(adminpanelURL);
    return false;
  }
}
function superAdminPanel(superadminpanelURL)
{
    window.location.href = superadminpanelURL;
    return false;
}
function ChangeSelect( return_link, id, cat, options )
{
  if ( cat != '' ) {
    if ( options != '' ) {
      window.location.href = return_link + '?category=' + cat + options;
    } else {
      window.location.href = return_link + '?category=' + cat;
    }
  }
  else if ( options != '' ) {
    window.location.href = return_link + '?id=' + id + options;
  } 
  else {
    window.location.href = return_link + '?id=' + id;
  }
}
function ChangeSelectid( id, cat, options )
{
  if ( (cat != '') && (id == '' ) ) {
    window.location.href = '?category=' + cat;
  }
  else if ( options != '' ) {
    window.location.href = '?id=' + id + options;
  } 
  else {
    window.location.href = '?id=' + id;
  }
}
function getPosition(obj){
    var topValue= 0,leftValue= 0;
    var scrollleftValue= 0,scrolltopValue= 0;
         scrollleftValue+= document.documentElement.scrollLeft;
         scrolltopValue+= document.documentElement.scrollTop;

    while(obj) {
         leftValue+= obj.offsetLeft;
         topValue+= obj.offsetTop;
         obj= obj.offsetParent;
    }
     finalvalue = leftValue + "," + topValue + "," + scrollleftValue + "," + scrolltopValue;
     //alert (finalvalue);
     return finalvalue;
}
function ChangeOption(id,val)
{
//	Called from xajax_functions.php
    vlu = val;
    sel = xajax.$(id).options;
    for (i=0;i<sel.length;i++)
    {
        //alert (sel[i].innerHTML+" ?? "+vlu)
        if (sel[i].innerHTML == vlu)
            sel[i].selected = true;
        else 
            sel[i].selected = false;
    }
}
function LinkTarget(link,target,title) {
    if (link)
    {
      switch (target)
      {
        case '_blank' :
        	window.open(link,'title');
        break;
        case 'sitewindow' :
           var frame = document.getElementById("sitewindow");
           frame.innerHTML = link;
        break;
        default :
        	window.open(link,'title');
        break;
      }
    }
}    
/* getElementByClass
/**********************/


function getElementByClass(tag,theClass) {
var allHTMLTags = new Array();
var allClassTags = new Array();
allClassTags[0] = 'undefined';

//Create Array of All HTML Tags
allHTMLTags=parent.document.getElementsByTagName(tag);

if (allHTMLTags!='undefined')
{
var j=0;
//Loop through all tags using a for loop
for (i=0; i<allHTMLTags.length; i++) {

//Get all tags with the specified class name.
if (allHTMLTags[i].className==theClass) {
//Place any code you want to apply to all
//pages with the class specified.
//In this example is to “display:none;” them
//Making them all dissapear on the page.

//allHTMLTags[i].style.display=’none’;
allClassTags[j] = allHTMLTags[i];
j++;
}
}
} else {
  allClassTags[0] = 'undefined';
}
return allClassTags;
}

function $P(v) 
{ 
  return(v.style);
}
function setClassColor(ClassTags,color,type)
{
  if (ClassTags[0]!='undefined')
  {
    for (i=0; i<ClassTags.length; i++) 
    { 
      switch (type)
      {
        case 'b':
          $P(ClassTags[i]).background='#'+color;
          break;
        case 'c':
          $P(ClassTags[i]).color='#'+color;
          break;
      }
    }
  }
}
function getClassColor(ClassTag)
{
  var result = new Array();
  if (ClassTag[0]!='undefined')
  {
    for (i=0; i<ClassTag.length; i++) 
    { 
      result = ClassTag[i].style.backgroundColor; 
    }
  } else {
    result = '000000';
  }
  return result
}