function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
externalLinks(); window.onload = externalLinks;

//for rollOvers *************************************************************************************
function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}
function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}
//***************************************************************************************************

//delete confirmation
function confirmMsg(msg) {
  document.returnValue = confirm(msg);
}

//pour color_pick
function popup(color,inputid) {
	var iMyWidth;
	var iMyHeight;
	iMyWidth = (window.screen.width/2) - (75 + 10);
	iMyHeight = (window.screen.height/2) - (100 + 50);
	var win2 = window.open("js/colorpicker/colorpicker.php?inputid=" + inputid + "&color=" + color,"Window2","status=no,height=290,width=225,resizable=1,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
	win2.focus();
}

//classic pop-up general uses
function popUp(URL,l,h) {
	id = 'popup';
	var iMyWidth;
	var iMyHeight;
	iMyWidth = (screen.width) ? (screen.width-l)/2 : 0;
	iMyHeight = (screen.height) ? (screen.height-h)/2 : 0;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width="+ l +",height="+ h +",left = "+ iMyWidth +",top = "+ iMyHeight +"');");
}

//chargement alléatoire des images top pour template "default"
function randomImg() {
	var j,d="",l="",m="",p="",q="",z="",list= new Array()
	
	list[list.length]='templates/alex/img/top1.jpg';
	list[list.length]='templates/alex/img/top2.jpg';
	list[list.length]='templates/alex/img/top3.jpg';
	list[list.length]='templates/alex/img/top4.jpg';
	list[list.length]='templates/alex/img/top5.jpg';
	list[list.length]='templates/alex/img/top6.jpg';
	
	j=parseInt(Math.random()*list.length);
	j=(isNaN(j))?0:j;
	document.write("<img src='"+list[j]+"'>");
}

//SHOW/HIDE DIV. Call with: onclick="showstuff('id_of_element_to_show');"
function showstuff(boxid){
   document.getElementById(boxid).style.display="block";
}
function hidestuff(boxid){
   document.getElementById(boxid).style.display="none";
}

//Clear input text on click
//credits: http://www.scriptygoddess.com/archives/2005/11/15/clear-default-text-onclick-restore-if-nothing-entered/
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
//usage: <input type="text" name="myfield" onclick="clickclear(this, 'default text')" onblur="clickrecall(this,'default text')" />
