//  Expanding left Nav menu Functions

var majors = new Array('cmp_rlgn', 'exst_god', 'bibl_cntr', 'phil_qstn', 'theo_issues', 'soc_culture', 'sci_bible');
function toggle(a, b) {
	if (!document.getElementById) return true;
	if (b==1) for (var i=majors.length-1; i>=0; i--) if (majors[i] != a) document.getElementById(majors[i]).style.display='none';
	a=document.getElementById(a);
	a.style.display=(a.style.display=='block')?'none':'block';
	return false;
}

/* Restrict growth of element on very-wide displays  

function resizeBox(){
 sObj = document.getElementById("container")
  if ( sObj ) {
   if(document.body.clientWidth) (document.body.clientWidth>1024) ?
 sObj.style.width = "975px" :  sObj.style.width = "100%"
  }
 }

   window.onload = resizeBox;
   window.onresize = resizeBox;



if (document.ids && document.ids.container) {
   document.ids.container.width = (window.innerWidth >1024) ? '975px' :
'100%';
   window.onload = function() {}
   originalWindowWidth = innerWidth;
   originalWindowHeight = innerHeight;
   window.onresize = function() { if(innerWidth != originalWindowWidth ||
innerHeight != originalWindowHeight) location.reload(); };
} */

// Printer Page Functions


function printpage(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=600,height=500,left = 212,top = 134');");
}



// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// username - 2-50 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your name.\n";
}


    //var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 2) || (strng.length > 50)) {
       error = "The name entered for you is the wrong length.\n";
    }
    //else if (illegalChars.test(strng)) {
    //error = "Your name contains illegal characters.\n";
    //} 
return error;
}       


function ValidateData(emailform) {
    var why = "";
    why += checkEmail(emailform.emailAddress.value);
    why += checkUsername(emailform.emailName.value);
    
if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkemailname (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a friend's name to forward this article.\n";
}


    //var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 2) || (strng.length > 50)) {
       error = "The friend's name entered is the wrong length.\n";
    }
return error;
}       



function submitonce(emailform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}


function ValidateForward(article_forward) {
    var why = "";
    why += checkemailname(article_forward.to_name.value);
    why += checkEmail(article_forward.to_email.value);
    why += checkUsername(article_forward.sender_name.value);
    why += checkEmail(article_forward.sender_email.value);

    
if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function submitforward(article_forward){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}


function externalLinks() { 
	if (!document.getElementsByTagName) return; 
		   var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { 
	       var anchor = anchors[i]; if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; 
	     } 
	  } 
	  window.onload = externalLinks;
