//function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}

/* Mailer Code to prevent email spam */
function mailer(oName,oDomain) {
 email="mailto:" + oName + "@" + oDomain;
 window.location=email;
}

/* This is our current popup function - parts of the site still use it, so I need to keep it */ 
function popUp(strURL,strType,strHeight,strWidth)	{
	var strOptions="";
	strHeight = "650";
	strWidth = "1024";
	if (strType=="console") strOptions="status,scrollbars,resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	window.open(strURL, 'newWin', strOptions);
}

function changeCommentSize(d) {
	var el = document.getElementById("comment");
	var height = parseInt(el.style.height);
	if(!height && el.offsetHeight)
		height = el.offsetHeight;
	height += d;
	if(height < 20) 
		height = 20;
	el.style.height = height+"px";
}

/* new accessible, unobtrusive popup code */
function windowLinks()	{					// create a new function called windowLink();
	if(!document.getElementsByTagName)	{	// Only run the function on browsers that 
		return;								// understand 'getElementsByTagName' - new browsers
	}
	var anchors = document.getElementsByTagName("a"); // grab all links and pop them in an array called 'anchors' 
    for (var i = 0; i < anchors.length; i++) {        // start a loop to work our way through  
         var anchor = anchors[i];                     // grab the next link & copy it to 'anchor' for working 
         var relIndex = anchor.rel;                   // get the value of it's 'REL' attribute 
         if (relIndex){                               // does it have a value for REL?... 
         var relSplit = relIndex.split("|");           
         /* if it does, look for '|' to use to split the value into an 
         array - relSplit[0], relSplit[1], relSplit[2], etc . If it doesn't 
         find any '|', the whole value gets transferred to relSplit[0] */ 
/* XHTML compliant target attribute */ 
         if (relSplit[0] == "external") {       // If the relSplit[0] is 'external'... 
            anchor.target = "_blank";           // then set it's 'target' attribute to '_blank' 
            anchor.className = "external";      // then attach a CSS class to it  
            anchor.title = "Load in new window: "+ anchor.href;   
            // And give it a new title attribute to warn users a new window is launching 
/* Elegantly degrading window code */ 
            } else if (relSplit[0] == "popup") {      // else if relSplit[0] is 'popup'... 
            anchor.className = "popup";               // attach a CSS class to it  
            anchor.title = "Loads in a Popup Window"; // Give it a helpful title attribute 
            anchor.popupWidth = relSplit[1];          // set the popup's width 
            anchor.popupHeight = relSplit[2];          // set the popup's height
            
            /*if (anchor.popupWidth == "") anchor.popupWidth = "1024";
            if (anchor.popupHeight == "") anchor.popupHeight = "650";*/
            
            anchor.onclick = function() {popUp(this.href,'console',this.popupWidth,this.popupHeight);return false;}; 
            // plug all this information into our origainl window launch function (acpopup)  
            } 
        } 
      } 
}

function togglediv(showHideDiv, switchTextDiv) {
	var ele = document.getElementById(showHideDiv);
	var text = document.getElementById(switchTextDiv);
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		text.innerHTML = "[+]";
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = "[-]";
	}
} 

function update_badge(badge) {
    document.getElementById('selected-badge').src = '/badges/exam-papers-'+badge+'.gif';
  
    document.getElementById('badge-code').value = '<a href="http://www.exampaper.com.sg"><img src="http://www.exampaper.com.sg/badges/exam-papers-'+badge+'.gif" alt="J&phi;ss Sticks - For Effective Prevention of Last-Minute Buddha Foot Hugging Syndrome" title="J&phi;ss Sticks - For Effective Prevention of Last-Minute Buddha Foot Hugging Syndrome" /></a>';
}
