function toggle(id){
	with(document.getElementById(id).style)
	{
	if(display=='block') display='none';
	else display = 'block';
	}
}
function openWin(path,winW,winH) {
	var iMyWidth;
	var iMyHeight;
   // winH= 400;
    //winW= 700;
	//gets top and left positions based on user's resolution so hint window is centered.
	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=yes");
	win2.focus();
}

function SelectCountry(country,formMsg)
{
    if(country)
    {
	document.getElementById(country).selected=true;
	document.getElementById("media"+country).selected=true;
	document.getElementById("journalist"+country).selected=true;
    }
    if(formMsg != "")
	alert(formMsg);
}

function OnChangeCountry(lang, country)
{
    var loc = 'media.sub?lang='+lang;
    loc += '&country='+escape(country);
    location = loc;
}


// Search
function getTableColor(areaRef){
switch(areaRef){
    case "article":
        var cor="#CFE1A9";
    break; 
    case "pressRelease":
        var cor="#DEECF1";
    break; 
    case "jury":
        var cor="#F4E2C5";
    break; 
    case "publication": 
    case "pubArticle":
        var cor="#F2F2F2";
    break; 
    case "winner":
        var cor="#FCDD9A";
    break;
    case "medias":
    	var cor="#FFEFCB";
    break;	    
    default:
        var cor="#efefef";                               
}
return cor;
}
function doit(area,areaRef,country,countryRef,year,title,author,contentType,docId){
var cor = getTableColor(areaRef);
if(contentType.indexOf("image")!= -1){
    var imagem=true;
    if(title=="Picture")areaRef="winner";   
    linha = "<img src='libOpenDoc.av?docId="+docId+"' border=1 align=left style='margin-right:8px' />";
}else{ 
    var imagem=false;
    linha = "";
}
if(areaRef=="winner" || areaRef=="jury")title="";
if(areaRef.length>0)var link=areaRef+".sub";
else var link="sub.av";
link+="?c="+country+"&cRef="+countryRef+"&docId="+docId+"&year="+year;

if(areaRef=='medias'||areaRef=='journalists')link="currentItem=media&country="+escape(country);
if(country.length>0 &&  area.length>0)country= ", "+country;
if(year.length>0)year= " - "+year;
if(author.length>0 && title.length>0)linha += "<h4>"+title+" <small>- "+author+"</small></h4>";
else if(title.length>0)linha += "<h4>"+title+"</h4>";
else linha += "<h4>"+author+"</h4>";
document.write("<div class='searchBox' ");
if(!imagem)document.write("onMouseOver=\"className='searchBox hover'\" onMouseOut=\"className='searchBox'\" onMouseUp=\"getURL('"+link+"')\"");
document.writeln(" style='background-color:"+cor+"'>");
document.writeln(linha); 
document.writeln("<em>"+area+"</em>"+country+" "+year+" &nbsp;");
document.writeln("</div>");
}
function getURL(url){
    window.location.href=url;
}


function IsValidEmailAddress(addr) 
{
    var re;
    re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
    if (re.test(addr) == true)
       return true;
    else
      return false;
}

function CheckRegistry(form)
{
    with(form)
    {
	if(title.value=="")
	{
	    alert(msg[0]);
	    title.focus();
	    return false;
	}

	if(!IsValidEmailAddress(authors.value))
	{
	    alert(msg[1]);
	    authors.focus();
	    return false;
	}
	
	if(country.value=="")
	{
	    alert(msg[2]);
	    country.focus();
	    return false;
	}
	return true;
    }
}

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"); 
            if(as[i].className!='')as[i].className+=' ext-link';
            else as[i].className='ext-link';
        } 
    }
}

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

window.onload=function(){
	aMod_externalLink();
}
