// JavaScript Document
function nombreArchivo( obj ) {
    var lastSlashLocation = obj.value.lastIndexOf("\\");

    var fileName = obj.value.substr( lastSlashLocation + 1 );
    var fileNameLength = fileName.length;
	if (fileNameLength > 50 )
    	alert(fileName + " tiene " + fileNameLength + " caracteres, y el máximo són 50");
	document.form1.imagen.value = fileName
}
function setImageOfLayer(objName) { //v3.0
im=document.form1.archivo.value;
im2=im.replace("C:", "C|");
im3=im2.replace(/\\/gi,"/");
imSRC=im3.replace(/\s/gi,"%20");
imStr ="<img name='imBG' border='0' src=file:///"+imSRC+">";
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (navigator.appName=='Netscape') {document.write(imStr); document.close();}
    else innerHTML =(imStr);
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// Todo para el TextArea

function MakeLink() {
var LinkAddress;
//get selected text
var sel = document.selection;
var rng = sel.createRange();

//make sure the text area has focus
document.LinkForm.TheTextArea.focus;
rng.colapse;


if (sel.type == "Text") {
text = rng.text;
LinkAddress= window.prompt("Enter Link Address. Example: http://www.google.com","http://");
} else {
window.alert("To create a hyperlink, select the text to be made a link, then click the 'Make Hyperlink' button");
}

//find out where
if (LinkForm.TheTextArea.createTextRange){
LinkForm.TheTextArea.caretPos = rng.duplicate();
}

//make sure we have an address
if (text && LinkAddress.length > 0 && LinkAddress!="http://") {
AddTxt = '<a href="' + LinkAddress + '" target="_blank">' + text + '</a>';
AddText(AddTxt);
} else {
window.alert("You Didn't Enter a URL");
}

}

function AddText(NewCode) {
if (LinkForm.TheTextArea.createTextRange && LinkForm.TheTextArea.caretPos)
{
var caretPos = LinkForm.TheTextArea.caretPos;

caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
}
else
{
LinkForm.TheTextArea.value += NewCode;
}
AddTxt = "";
}
//Compatible with: IE6 PC
//Not Compatible with: Safari, IE6 Mac, Firefox PC, Firefox Mac


//WrapText();
function wrapText(el, openTag, closeTag) {
if (el.setSelectionRange) {
// W3C/Mozilla
el.value = el.value.substring(0,el.selectionStart) + openTag + el.value.substring(el.selectionStart,el.selectionEnd) + closeTag + el.value.substring(el.selectionEnd,el.value.length);
}
else if (document.selection && document.selection.createRange) {
// IE code goes here
el.focus(); //or else text is added to the activating control
var range = document.selection.createRange();
range.text = openTag + range.text + closeTag;
}
}