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

//======================== Function to check is javascript is activated. If it is the class js-active is assigned to html tag
var newclassname = 'js-active'; 				// define class 
var ob = document.getElementsByTagName('HTML');// get the html tag 
if (ob.length > 0){
  ob = ob[0];									// check if there is already a class applied to html tag
  if (ob.className == ''){
	  ob.className = newclassname;				// if there isn't then add class
  } else {
	 ob.className += ' ' + newclassname;		// if there is a class already present add class js-active after it
  }
}

//======================== antispam
function generate_address( username, subdomain, contacttxt ) {
	var domain = "meanttoshine.org";
	var atsign = "&#64;";
	var addr = username + atsign + subdomain + domain;
	document.write("<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" + contacttxt + "<\/a>");
}

//======================== W3C compliant Popup script
function popupLauncher()
{
  if( document && document.body && document.getElementById && document.getElementsByTagName ) //check to see if browser understands the methods
   {
     var alinks = document.getElementsByTagName('A'); // get all the links

     for( i=0; i < alinks.length; i++ ) // store then all one by one
     {
      if( alinks[i].rel == "external" ) // check each one to see if it has the rel attribute set to external
       {
         try
         {
          alinks[i].target = "_blank";  // if it does open new window
         }
         catch(e)
          {}
       }
     }
   }
}


//======================== search form
function resetFields() {
	var searcher = document.getElementById("searcher");
	if (searcher && searcher.defaultValue){

	var oldValue = searcher.defaultValue;
	
		
		searcher.onclick = function() {
			if (this.value == oldValue) {
				this.value = "";
				}
		
		searcher.onblur = function() {
			if (this.value == "") {
				this.value = oldValue;
				}
			}
		}
	}
}

//======================== IE6 antiflicker
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

addLoadEvent(resetFields);
addLoadEvent(popupLauncher);

