//<![CDATA[

///////////////////////////////// FUNCTIONS ////////////////////////////////////

function random(n){
    var ranNum= Math.round(Math.random()*(n-1));
    return ranNum;
}
function trim(str){ 
  return String(str).replace(/^\s+|\s+$/g, '') 
};

function openWin(path,winW,winH) {
	var iMyWidth;
	var iMyHeight;
    iMyWidth = (window.screen.width/2) - ((winW/2)+ 10); 
	iMyHeight = (window.screen.height/2) - ((winH/2) + 50); 
	var win2 = window.open(path,'',"status,toolbar=0,height="+winH+",width="+winW+",resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=no");
    win2.opener=window;
    win2.focus();
    return false;
}
function isValidEmailAddress(addr) {
    var re;
    re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
    if (re.test(addr) == true)
       return true;
    else
      return false;
}
///////////////////////////////// editable /////////////////////////////////////

function pop(it,w,h){
	openWin(it.href,w+18,h+20);
	return false;
}

///////////////////////////////// onload ///////////////////////////////////////


function changeLinks(){
    aMod_popup() ;
    aMod_externalLink();
    imgMod_align();
}
function imgMod_align(){
    var img = document.getElementsByTagName('img');
    for(i=0;i<img.length;i++){
        var attr = img[i].getAttribute('align');
        if(attr){
            if(attr=="left"){
                if(!img[i].className) img[i].className = 'alignLeft'; 
                else img[i].className += ' alignLeft';
            }else if(attr=="right"){
                if(!img[i].className) img[i].className = 'alignRight'; 
                else img[i].className += ' alignRight';
            }    
        }
    }
}
function aMod_popup(){
	 var as,i,islink;
    // grab all links, loop over them;
    as=document.getElementsByTagName('a');
    for(i=0;i<as.length;i++){
        // check which link has a coord attribute, and send this one to popup
        var re = /\d[x]\d/;
        var coord = as[i].getAttribute('coords');         
        if(coord!='' && re.test(coord) == true){
            as[i].setAttribute('coords','');
            var split = coord.split('x');
            var w = split[0];
            var h = split[1];
            var link = as[i].getAttribute('href'); 
            as[i].setAttribute('onclick',"return openWin('"+link+"',"+w+","+h+")"); 
        }
    }
}

function aMod_externalLink(){    
    var as,i,islink;
    // grab all links, and loop over them
    as=document.getElementsByTagName('a');
    for(i=0;i<as.length;i++){
        // take the link's href
        islink=as[i].href; 
        // and check if it contains the current location 
        var host = new String(window.location.hostname);
        rExp = /www./gi;
        domain = host.replace(rExp, "");

        if(islink.indexOf(domain)==-1 && islink.indexOf('javascript:')==-1){
            if(!as[i].getAttribute('title'))as[i].setAttribute('title',islink);
            as[i].setAttribute("target","_blank"); 
        } 
    }
}
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}


///////////////////////////////// SCRIPTS //////////////////////////////////////

if(document.getElementById && document.createTextNode){
    window.onload=changeLinks; 
    //addEvent( 'window', 'load', changeLinks )
}  



//]]>
