//Custom JavaScript Functions by Shawn Olson
//Copyright 2006-2008
//http://www.shawnolson.net
//If you copy any functions from this page into your scripts, you must provide credit to Shawn Olson & http://www.shawnolson.net
//*******************************************

	function stripCharacter(words,character) {
	//documentation for this script at http://www.shawnolson.net/a/499/
	  var spaces = words.length;
	  for(var x = 1; x<spaces; ++x){
	   words = words.replace(character, "");
	 }
	 return words;
    }

	function changecss(theClass,element,value) {
	//Last Updated on May 21, 2008
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 var added = false;
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    if(document.styleSheets[S][cssRules][R].style[element]){
	    document.styleSheets[S][cssRules][R].style[element] = value;
	    added=true;
		break;
	    }
	   }
	  }

	  if(!added){
	  if(document.styleSheets[S].insertRule){
			  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
			}
	  }
	 }
	}

	function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }

function checkUncheckSome(controller,theElements) {
	//Programmed by Shawn Olson
	//Copyright (c) 2006-2008
	//Updated on August 12, 2007
	//Permission to use this function provided that it always includes this credit text
	//  http://www.shawnolson.net
	//Find more JavaScripts at http://www.shawnolson.net/topics/Javascript/

	//theElements is an array of objects designated as a comma separated list of their IDs
	//If an element in theElements is not a checkbox, then it is assumed
	//that the function is recursive for that object and will check/uncheck
	//all checkboxes contained in that element

     var formElements = theElements.split(',');
	 var theController = document.getElementById(controller);
	 for(var z=0; z<formElements.length;z++){
	  theItem = document.getElementById(formElements[z]);
	  if(theItem.type){
	    if (theItem.type=='checkbox') {
	    	theItem.checked=theController.checked;
	    }
	  } else {
	  	  theInputs = theItem.getElementsByTagName('input');
	  for(var y=0; y<theInputs.length; y++){
	  if(theInputs[y].type == 'checkbox' && theInputs[y].id != theController.id){
	     theInputs[y].checked = theController.checked;
	    }
	  }
	  }
    }
}


	 //Miscellaneous JavaScript Functions Written by Shawn Olson
	 //Copyright 2005 by Shawn Olson
	 //Permission to use these scripts provided credit is provided to Shawn Olson
	 //Find more JavaScript resources at http://www.shawnolson.net/topics/JavaScript/


	  function insideHTML(cell){
	   eval('theCell = document.getElementById("'+cell+'").innerHTML');
	   return theCell;
	  }


	  function checkValueAgainst(objId,val1){
	   if(insideHTML(objId)==val1){verify=true;} else {verify=false;}
	   return verify;
	  }


//Webonizer Verification Script
//Copyright 2006-2008 by Shawn Olson
//All Rights Reserved.
//http://www.shawnolson.net
//Webonizer Website http://www.webonizer.com

var SMO_TEMPLATE_TOP=1;
var SMO_TEMPLATE_SUB=2;
var SMO_TEMPLATE_BOTTOM=4;
var SMO_TEMPLATE_RIGHT=8;
var SMO_TEMPLATE_LEFT=16;
var SMO_TEMPLATE_PIX=32;

var SMO_NAVIGATION_USE=1;
var SMO_NAVIGATION_DROP=2;
var SMO_NAVIGATION_CASCADE=4;
var inv = 'Invalid';
var restrictWord = new Array('vi@gra', 'viagr@', 'vi@gr@');
var extraDocTypes = null;
var Global_Errors = new Array();

function badWords(word){
//this function keeps new members from choosing inappropriate names

var badword = false;
var word = new String(word);
word = word.toLowerCase();

 for (var i = 0; i<restrictWord.length; i++){
  if (word.match(restrictWord[i])){

  badword = true;
  alert("A label you chose is inappropriate for this site. Please be considerate, as children often visit this site.");
  }
 }
 return badword;
}


function checkEmail(formObj){

  var email_pass = true;
  var email_val = new String(formObj.value);
  ok = "0987654321qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM[].@-_";

  for(i=0; i <= email_val.length ;i++){
   if(ok.indexOf(email_val.charAt(i))<0){
    email_pass = false;
    return email_pass;
   }
  }
  re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
  re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  if (!email_val.match(re) && !email_val.match(re_two)) {
   email_pass = false;
   formObj.style.color = "red";
  } else {formObj.style.color = "black";}
 return email_pass;

}


function changeVal(formObj,need,bad){

 var FnameTest = true;
 var errors;
 errors = 0;
 if(formObj){
 if(need==true){
 if(formObj.type){
   if(formObj.type=='checkbox'){
     if(!formObj.checked){
	   FnameTest = false;
	 }
   }
 }
  if (formObj.value==''){
   FnameTest = false;
  }
 }

 if(bad==true){
   badword = badWords(formObj.value);
  if (badword == true){
   FnameTest = false;
  }
 }

 if (FnameTest == false){
   formObj.style.color = "red";
   errors = 1;
 }
 if (FnameTest == true){
   formObj.style.color = "black";
 }
}
return errors;
}

function requiredFields(formObj){
 var bandMessage='';
 var errors = 0;


if (formObj.BIO){
  if (formObj.first_name) {
  	 formObj.saveName.value = formObj.first_name.value;
  }
   if(changeVal(formObj.ALIAS,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter a username.';
  }
}


 if (formObj.PASSWORD){
     errors = errors + changeVal(formObj.PASSWORD,true,false);
    if (formObj.PASSWORDR){
    errors = errors + changeVal(formObj.PASSWORDR,true,false);
    if (formObj.PASSWORD.value != formObj.PASSWORDR.value){
	 formObj.PASSWORD.style.color = "red";
	 //formObj.PASSWORD.value = inv;
	 formObj.PASSWORDR.style.color = "red";
	 //formObj.PASSWORDR.value = inv;
	 errors++;
	 bandMessage+='\n\nYou did not type in the same password in both password fields.';
  }
}
}

 if (formObj.EMAIL){
errors = errors + changeVal(formObj.EMAIL,true,false);
if(checkEmail(formObj.EMAIL)==false){
  bandMessage+='\n\nYou have not entered a valid email address.';
  errors++;
} else{
   formObj.EMAIL.style.color = "black";
  }
 }

if (formObj.article_id){
  if(changeVal(formObj.title,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter a title for your article.';
  }
  if(changeVal(formObj.article_about,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter a brief description of this article.';
  }
  if(changeVal(formObj.body,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter content for the article.';
  }

}
if (formObj.vaddress){

  if(changeVal(formObj.vaddress,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter the venue/host address.';
  }
  if(changeVal(formObj.venue,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter the venue/host Name.';
  }

  if(changeVal(formObj.info,true,false)){
    errors++;
	bandMessage+='\n\nYou must enter the event details.';
  }
  if(changeVal(formObj.state,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter the event state/province.';
  }

  if(changeVal(formObj.COUNTRY,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter the event country.';
  }
  if(changeVal(formObj.title,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter a Title for your event.';
  }
  if(changeVal(formObj.city,true,true)){
    errors++;
	bandMessage+='\n\nYou must enter the city/town where the event is located. If the event is not in a town, enter the closest town.';
  }
}

if (formObj.terms){
 if(formObj.terms.type=='checkbox'){
  if(! formObj.terms.checked){errors++; bandMessage+='\n\nYou must check that you have read and agree to our terms of service to continue.'; }
   }
}

if (formObj.web){formObj.web.value=stripCharacter(formObj.web.value,'http://');}
if (formObj.URL){formObj.URL.value=stripCharacter(formObj.URL.value,'http://');}
//
if(formObj.required){
  formArray= new Array();
  theFields  = formObj.required.value;
  formArray = theFields.split(',');
  for(x=0;x<formArray.length;x++){
   var theName = formArray[x];
   if(theName !=''){
    str = 'var tobj = formObj.'+theName+';';
    eval(str);
    if (tobj) {
    	if (changeVal(tobj,true,true)) {
    		errors++;
    		if (tobj.title) {
    			bandMessage+='\n\n'+tobj.title;
    		}

    	}
    }
   }
  }
}
  var theCustomErrors = customErrorChecking(formObj);
  errors = errors + (theCustomErrors['customError'] * 1);
  bandMessage+= theCustomErrors['customMessage'];
  if(Global_Errors.length > 0){
     for(var ge = 0; ge<=Global_Errors.length; ge++){
	   bandMessage+= "\n\n" + Global_Errors[ge];

	 }
  }
if(formObj.smoRememberMe){

  if(formObj.smoRememberMe.checked && getCookieValue('alias')==null){
  var smoRemember = confirm("You should only check the \"Remember Username\" option if this is a private computer.\n\nDo not check this option on a public computer.\n\nClick \"OK\" to continue login or \"Cancel\" to uncheck the remember option.");

  }
  if(smoRemember==false){formObj.smoRememberMe.checked = '';}
}

   if (errors==0){

      //formObj.submit();
      return true;
  }else{
    alert("There are errors on your form... please verify the information. Fields with red text or the word 'Invalid' must be filled out."+bandMessage+'\n\n**NOTE** If all required fields are filled, you may have entered certain "banned" words that are not appropriate for this page. Such words include vulgarity and spam-like keywords.');
    return false;
  }

}

function clearForm(formObj){
  if(formObj){
    if(formObj.clearfields){
	   formArray= new Array();
       theFields  = formObj.clearfields.value;
       formArray = theFields.split(',');
        for(x=0;x<formArray.length;x++){
	        string = 'if(formObj.'+formObj[x]+'.value){formObj.'+formArray[x]+'.value = "";}';
           eval(string);
        }

	} else {
           for(x=0;x<formObj.length;x++){
	          string = 'if(formObj.'+formObj[x]+'.value){formObj.'+formObj[x]+'.value = "";}';
              eval(string);
        }
	}
  }
}

function deleteConfirm(script,id){
 if((script != '') && (id !='')){
  switch(script){
    case 'usermod.php':
     comment = 'your account? Doing so will remove your account, all articles, events, photos, art, guestbook and music. You will no longer be able to access your control panel on this site.';
    break;
    case 'articlemod.php':
     comment = 'this article? Doing so will permanently remove this article.';
	 break;
	case 'publicationWizard.php':
	 comment = 'your publication?';
	 break;
	case 'shop.php':
	 comment = 'all the items from your shopping cart?';
	 break;
	default:
	 comment = 'this item?';
  }
  return confirm("Do you really want to delete " + comment);
 }

}

function showThumb(articleId,newImg,preId){
 if(preId==''){preId='Pic';}
 changeString = 'if(document.getElementById("Pic'+articleId+'")){document.getElementById("Pic'+articleId+'").src="'+newImg+'";}';
 eval(changeString);
}

function getRadioValue(radioObject){
 var value=null;
 if(radioObject){
 for (var i=0; i<radioObject.length; i++){
  if (radioObject[i].checked){
   value = radioObject[i].value;
   break;
  }
 }
 }
return value;
}


function changeSearchType(formObj){
     switch(formObj.searchtype.value){
	   case 'member':
	      formObj.action = '/directory/';
		  break;
	   case 'arts':
	      formObj.action = '/webonizer_core/search.php';
		  break;
	   case 'events':
	   formObj.action = '/webonizer_core/events.php';
	   default:
	   	  if(extraDocTypes){

   pluginDocTypes = extraDocTypes.split(';');

   for(x=0;x<=pluginDocTypes.length;x++){
      thisDoc =  pluginDocTypes[x].split(',');

      if(thisDoc[0]==formObj.searchtype.value){
          if (formObj.search.value * 1 > 0){document.location='/'+thisDoc[1]+'/'+formObj.search.value+'/';return;}
	  }
   }

}

     break;
	 }
}

function searchType(formObj,extraDocTypes){

  if(formObj.search.value != ''){
   if (formObj.search.value * 1 > 0){
     switch(formObj.searchtype.value){
	   case 'member':
	      if (formObj.search.value * 1 > 0){document.location='/'+SMO_MEMBERS_FILE+'/'+formObj.search.value+'/'; return;}
		  break;
	   case 'arts':
          if (formObj.search.value * 1 > 0){document.location='/'+SMO_ARTICLES_FILE+'/'+formObj.search.value+'/';return;}
		  break;
	   case 'events':
          if (formObj.search.value * 1 > 0){document.location='/webonizer_core/events.php?eid='+formObj.search.value;return;}

     break;

	 default:
	  if(extraDocTypes){

   pluginDocTypes = extraDocTypes.split(';');
   for(x=0;x<=pluginDocTypes.length;x++){
      thisDoc =  pluginDocTypes[x].split(',');
      if(thisDoc[2]){
          if (formObj.search.value * 1 > 0){ document.location='/'+thisDoc[2]+'/'+formObj.search.value+'/';return false;   }
	  }
   }

}
	 }

   } else {
     changeSearchType(formObj,extraDocTypes);
     formObj.submit();
	}
  } else {alert('Enter Search Terms'); return false;}

}

function showFile(id,width,height){
  if(window.picWIndow){picWIndow.close();}
  width = (width *1)+30;
  height = (height *1)+60;
  if(width > 830){
    width = 830;
  }
  picWIndow = window.open("/webonizer_core/show_image.php?id="+id,'imagewindow','toolbar=no,menubar=no,width='+width+',height='+height*1+',scrollbars=yes,status=yes,resizable=yes');
;
if(! window.picWIndow){
  alert('Your browser or security settings are set to block pop-ups; this is stopping the browser from showing you the image.');
}

}

function copyGbox(){
 document.getElementById("gbox2").innerHTML = document.getElementById("gbox").innerHTML;

}

function CreateBookmarkLink() {
   if (window.sidebar) {
     window.sidebar.addPanel(document.title, document.location,"");
   } else if( window.external ) {
	   window.external.AddFavorite( document.location, document.title);
   }
}

function showBookmark(){
		 if (window.external || window.sidebar) {
		   document.write('<button onclick="CreateBookmarkLink();" id="smoBookMark">Bookmark</button>');
		 }
}

function smo_layout(){

 if (SMO_LOGIN_LINKS & SMO_TEMPLATE_TOP){
    if (document.getElementById("atp_menu") && document.getElementById("smo_siteLinks")){

   var theSiteLinks = '<ul>'+ document.getElementById("smo_siteLinks").innerHTML+'</ul>';
      if(! document.getElementById("smoNavSiteLinksCore")){
	  document.getElementById("atp_menu").innerHTML += '<li><a href="/webonizer_core/siteLinks.php">Site Links</a>'+theSiteLinks+'</li>';
     } else {
	    document.getElementById("smoNavSiteLinksCore").innerHTML += theSiteLinks;

	 }
	}

}

 if (SMO_SITE_LINKS_NAV & SMO_TEMPLATE_TOP){
    if (document.getElementById("atp_menu") && document.getElementById("smo_externalLinks")){
	 if (document.getElementById("smo_externalLinks")){
	  document.getElementById("atp_menu").innerHTML += '<li><a href="/webonizer_core/externalLinks.php">Links</a><ul>'+document.getElementById("smo_externalLinks").innerHTML+'</ul></li>';
}
	}


 }


if(atp_browser.isIE){
 var loginl = 0;
 var exLinks = 1;
} else {
 var loginl = 1;
 var exLinks = 2;
}


if ((SMO_LOGIN_LINKS & SMO_TEMPLATE_RIGHT)==0){

	  document.getElementById("smo_rightLinks").childNodes[loginl].style.display = 'none';
     }

     if ((SMO_SITE_LINKS_NAV & SMO_TEMPLATE_RIGHT)==0 && document.getElementById("smo_rightLinks").childNodes[exLinks]){
	document.getElementById("smo_rightLinks").childNodes[exLinks].style.display = 'none';

	}

 if (((SMO_SITE_LINKS_NAV & SMO_TEMPLATE_RIGHT)==0) && ((SMO_LOGIN_LINKS & SMO_TEMPLATE_RIGHT)==0)){
  document.getElementById("smo_rightLinks").style.display = 'none';

 }


}

function smo_navWrite(writeArea){
 switch(writeArea){
  case 'topNav':
    document.write('<span style="text-decoration:blink">Loading Navigation...</span>');
	break;
 }

}

function getCookieValue(cookiename){
 var result = null;
 var myCookie = " "+document.cookie + ";";
 var searchName = " "+ cookiename+ "=";
 var startOfCookie = myCookie.indexOf(searchName);
 if(startOfCookie!=-1){
   startOfCookie += searchName.length;
   var endOfCookie = myCookie.indexOf(";",startOfCookie);
   result = unescape(myCookie.substring(startOfCookie,endOfCookie));

 }
 return result;

}

function runStartUpFuncs(){
 smo_layout();
 atp_initMenu();
}

	function switchHideDiv(target){
	 if(document.getElementById(target)){
	 switch (document.getElementById(target).style.display){
	 case 'none':
	  document.getElementById(target).style.display = 'block';
	  break;
	 case 'block':
	  document.getElementById(target).style.display = 'none';
	  break;
	  }
	 }
	}

function isPageSecure(){
var str = new String(document.location);
var strS = str.split('//');
str = strS[0];
  if (str.search('https')!=-1){
    return true;
  } else {
    return false;
  }
}

function handleError() {
	return true;
}

function smo_script_loadScript(url,opts){

   for (i in document.getElementsByTagName('script')){

     if(i.src){
	   if(i.src==url){
	    return;
	   }
	 }
   }
   if(!opts){opts={};}

   var s = document.createElement("script");
   //s.src = url;
   //s.type="text/javascript";
   //s.language="javascript"

   s.setAttribute('src',url);
   s.setAttribute('type','text/javascript');
   s.setAttribute('language','javascript');

   document.getElementsByTagName("head")[0].appendChild(s);

   var writeS = false;
   switch(navigator.appName){
     case 'Netscape':
       if(navigator.appVersion.indexOf('Safari')!== -1){
	    writeS = true;
	   }
       break;

     case 'Microsoft Internet Explorer':
        if(navigator.appVersion.indexOf('MSIE 7') == -1){
          writeS = true;
	    }
        break;
   }
    if(writeS==true){
	  document.write('<script language="javascript" type="text/javascript" src="'+url+'"></script>');
	}
}

window.onerror = handleError;
window.onload=runStartUpFuncs;