// #######################################################################################
// ######  EL PRESENTE CODIGO PROPIEDAD DE TODOARQUITECTURA.COM                    #######
// ######  LA COPIA DE TODO O PARTE DEL MISMO SE ENCUENTRA EXPRESAMENTE PROHIBIDO  #######
// ######  SITIOS WEBS QUE UTILICEN EL CODIGO AQUI EXPUESTO SERAN SUJETOS A LAS    #######
// ######  ACCIONES LEGALES QUE CORRESPONDAN.          ©2002 TODOARQUITECTURA.COM  #######
// #######################################################################################


helpstat = false;
stprompt = false;
basic = false;

function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}


function storeCaret(ftext) {
	if (ftext.createTextRange) {
		ftext.caretPos = document.selection.createRange().duplicate();
	}
}

function getText() {
	var tarea = document.PostTopic.Message;
	if (tarea.createTextRange && tarea.caretPos) {
		return tarea.caretPos.text;
	} else if (typeof tarea.selectionStart != 'undefined'){
		return tarea.value.substr(tarea.selectionStart,tarea.selectionEnd-tarea.selectionStart)
	}
	return '';
}


function ltrim(s) {
	return s.replace( /^\s*/, "" );
}
function rtrim(s) {
	return s.replace( /\s*$/, "" );
}
function trim ( s ) {
	return rtrim(ltrim(s));
}
//function AddText(NewCode) {
//document.PostTopic.Message.value+=NewCode
//}

function AddTextVIEJA(NewCode) {
	if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
		var caretPos = document.PostTopic.Message.caretPos;
		caretPos.text = NewCode;
	} else {
		document.PostTopic.Message.value+=NewCode;
	}
	document.PostTopic.Message.focus();
}

function AddText(text) {
	var tarea = document.PostTopic.Message;
	if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
		start = tarea.selectionStart;
		end = tarea.selectionEnd;
		tarea.value = tarea.value.substr(0,tarea.selectionStart)
			+ text + tarea.value.substr(tarea.selectionEnd);
		tarea.focus();
		tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
		tarea.selectionEnd = start + text.length;
	} else {
		if (tarea.createTextRange && tarea.caretPos) {
			var caretPos = tarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?   text + ' ' : text;
		}
		else {
			tarea.value += text;
		}
		tarea.focus(caretPos);
	}
}

function email() {
	if (helpstat) {
		alert("El Tag de Email convierte una dirección de email en un Link mailto.\n\nUSO #1: [url]alguien\@dondesea.com[/url] \nUSE #2: [url=\"alguien\@dondesea.com\"]texto que se verá[/url]");
		}
//	else if (basic) {
//		AddTxt="[url][/url]";
//		AddText(AddTxt);
//		}
	else { 
		txt2=prompt("Email: Texto a mostrar en pantalla. Dejar en blanco si se quiere mostrar la dirección misma.",""); 
		if (txt2!=null) {
			txt=prompt("Dirección del link (URL).","mailto:");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url]";
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}         
			} 
		}
	}
}
function showsize(size) {
	var text = getText();
	if (helpstat) {
		alert("Setea el tamaño del texto. Los valores posibles van del 1 al 6.\n1 es being the smallest and 6 the largest.\n\nUSO: [size="+size+"]Este es texto de tamaño "+size+" [/size="+size+"]");
	} else if (basic) {
		AddTxt="[size="+size+"]" + text + "[/size="+size+"]";
		AddText(AddTxt);
	} else {                       
		txt=prompt("Texto a pasar a tamaño "+size,"Texto"); 
		if (txt!=null) {             
			AddTxt="[size="+size+"]"+txt+"[/size="+size+"]";
			AddText(AddTxt);
		}        
	}
}


function bold() {
	var text = getText();
	if (helpstat) {
		alert("Convierte el texto en Negrita.\n\nUSO: [b]Este texto está en negrita[/b]");
	} else if (basic) {
		AddTxt="[b]" + text + "[/b]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Texto a poner en negrita:",text);
		} else {
		txt=prompt("Texto a poner en negrita:","Texto");     
		}
		if (txt!=null) {
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}
	}
}

function underline() {
	var text = getText();
  	if (helpstat) {
		alert("Subraya el texto.\n\nUSO: [u]Este texto está subrayado[/u]");
	} else if (basic) {
		AddTxt="[u]" + text + "[/u]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Texto a subrayar:",text);
		} else {
			txt=prompt("Texto a subrayar:","Text");
		}
		if (txt!=null) {
			AddTxt="[u]"+txt+"[/u]";
			AddText(AddTxt);
		}
	}
}

function italicize() {
	var text = getText();
	if (helpstat) {
		alert("Hace que el texto se vea en cursiva.\n\nUSO: [i]Este texto esta en cursiva[/i]");
	} else if (basic) {
		AddTxt="[i]" + text + "[/i]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Texto a poner en cursiva:",text);
		} else {
		txt=prompt("Texto a poner en cursiva:","Texto");     
		}
		if (txt!=null) {
			AddTxt="[i]"+txt+"[/i]";
			AddText(AddTxt);
		}
	}
}


function quote() {
	var text = getText();
	if (helpstat){
		alert("Pone el texto dentro de un comentario. Usado para hacer referencia a algo específico que otra persona escribió.\n\nUSO: [quote]Esto es un comentario[/quote]");
	} else if (basic) {
		AddTxt=" [quote]" + text + "[/quote]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Texto a comentar:",text);
		} else {
			txt=prompt("Texto a comentar:","Texto");
		}
		if(txt!=null) {
			AddTxt=" [quote] "+txt+" [/quote]";
			AddText(AddTxt);
		}
	}
}

function showcolor(color) {
	var text = getText();
	if (helpstat) {
		alert("Setea el color del texto. Se pueden usar los nombres de los colores mas comunes.\n\nUSO: ["+color+"]Este testo es de "+color+" color[/"+color+"]");
	} else if (basic) {
		AddTxt="["+color+"]" + text + "[/"+color+"]";
		AddText(AddTxt);
	} else {  
     	txt=prompt("A poner en color "+color,"Texto");
		if(txt!=null) {
			AddTxt="["+color+"]"+txt+"[/"+color+"]";
			AddText(AddTxt);        
		} 
	}
}

function strike() {
	var text = getText();
	if (helpstat) {
		alert("Tacja el texto encerrado en este marcador.\n\nUSA: [s]Este es un texto tachado[/s]");
	} else if (basic) {
		AddTxt="[s]" + text + "[/s]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Texto a tachar:",text);
		} else {
			txt=prompt("Texto a tachar:","Texto");
		}
		if (txt!=null) {
			AddTxt="[s]"+txt+"[/s]";
			AddText(AddTxt);
		}
	}
}

function left() {
	var text = getText();
 	if (helpstat) {
		alert("Coloca el texto a la izquierda.\n\nUSA: [left]Este texto esta a la izquierda[/left]");
	} else if (basic) {
		AddTxt="[left]" + text + "[/left]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Texto a colocar a la izquierda:",text);
		} else {
			txt=prompt("Texto a colocar a la izquierda:","Texto");
		}
		if (txt!=null) {
			AddTxt="[left]"+txt+"[/left]";
			AddText(AddTxt);
		}
	}
}

function center() {
	var text = getText();
 	if (helpstat) {
		alert("Centra el texto.\n\nUSA: [center]Este texto esta centrado[/center]");
	} else if (basic) {
		AddTxt="[center]" + text + "[/center]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Texto a centrar:",text);
		} else {
			txt=prompt("Texto a centrar:","Texto");
		}
		if (txt!=null) {
			AddTxt="[center]"+txt+"[/center]";
			AddText(AddTxt);
		}
	}
}

function right() {
	var text = getText();
 	if (helpstat) {
		alert("Coloca el texto a la derecha.\n\nUSA: [right]Este texto esta a la derecha[/right]");
	} else if (basic) {
		AddTxt="[right]" + text + "[/right]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Texto a colocar a la derecha:",text);
		} else {
			txt=prompt("Texto a colocar a la derecha:","Texto");
		}
		if (txt!=null) {
			AddTxt="[right]"+txt+"[/right]";
			AddText(AddTxt);
		}
	}
}

function hr() {
	var text = getText();
	if (helpstat) {
		alert("Crea una linea horizontal en el mensaje.\n\nUSA: [hr]");
	} else {
		AddTxt="[hr]" + text;
		AddText(AddTxt);
	}
}

function hyperlink() {
	var text = getText();
	if (helpstat) {
		alert("Links: \nConvierte una dirección (URL) en un hipervínculo.\n\nUSO: [url]http://www.unsitio.com[/url]\n\nUSO: [url=http://www.unsitio.com]texto que se verá en la pantalla[/url]");
//	} else if (basic) {
//		AddTxt="[url]" + text + "[/url]";
//		AddText(AddTxt);
	} else {
//		if (text!=null) {
		if ((text!=null) && (text!='')) {
			txt2=text;
		} else {
			txt2=prompt("Link: Pon el texto a mostrar a mostrar en pantalla.\nDejar en blanco si quieres que se muestre la dirección.","");
		}
		if (txt2!=null) {
			txt=prompt("Dirección (URL):","http://");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url]";
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}
			}
		}
	}
}


function image() {
	var text = getText();
	if (helpstat){
		alert("Inserta una imagen en el mensaje.\n\nUSO: [img]http://www.unsitio.com/imagen.gif[/img]");
//	} else if (basic) {
//		AddTxt="[img]" + text + "[/img]";
//		AddText(AddTxt);
	} else {  
		txt=prompt("Dirección (URL) del gráfico:","http://");    
		if(txt!=null) {            
			AddTxt="[img]"+txt+"[/img]";
			AddText(AddTxt);
		}	
	}
}

function showcode() {
	var text = getText();
	if (helpstat) {
		alert("Pone el texto como comentario con formato especial.\nUtil cuando se quiere mostrar código de programación, etc.\n\nUSO: [code]Este es texto con formato[/code]");
	} else if (basic) {
		AddTxt=" [code]" + text + "[/code]";
		AddText(AddTxt);
	} else {   
		txt=prompt("Texto con formato de código:","");     
		if (txt!=null) {          
			AddTxt="[code]"+txt+"[/code]";
			AddText(AddTxt);
		}	       
	}
}

function list() {
	if (helpstat) {
		alert("Crea una lista numerada, con letras, o circulos.\n\nUSO: [list] [*]item1[/*] [*]item2[/*] [*]item3[/*] [/list]");
	} else if (basic) {
		AddTxt=" [list][*]  [/*][*]  [/*][*]  [/*][/list]";
		AddText(AddTxt);
	} else {  
		type=prompt("Lista: Ingresa el tipo de lista \'A\' para alfabetica, \'1\' para que sea con números, dejar en blanco para que sea con círculos.","");               
		while ((type!="") && (type!="A") && (type!="a") && (type!="1") && (type!=null)) {
			type=prompt("ERROR! Los valores posibles son: en blanco, 'A' y '1'.","");               
		}
		if (type!=null) {
			if (type=="") {
				AddTxt="[list]";
			} else {
				AddTxt="[list="+type+"]";
			} 
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("Ingresa un item a la lista o deja en blanco para terminar la lista",""); 
				if (txt!="") {             
					AddTxt+="[*]"+txt+"[/*]"; 
				}                   
			} 
			if (type=="") {
				AddTxt+="[/list] ";
			} else {
				AddTxt+="[/list="+type+"]";
			} 
			AddText(AddTxt); 
		}
	}
}

function showfont(font) {
	var text = getText();
 	if (helpstat){
		alert("Cambia la tipografía usada en el texto.\n\nUSO: [font="+font+"]Este texto es "+font+"[/font]");
	} else if (basic) {
		AddTxt="[font="+font+"]" + text + "[/font="+font+"]";
		AddText(AddTxt);
	} else {                  
		txt=prompt("Texto a poner en "+font,"Texto");
		if (txt!=null) {             
			AddTxt="[font="+font+"]"+txt+"[/font="+font+"]";
			AddText(AddTxt);
		}        
	}  
}


function checkearCaps( e ) {
  //if the browser did not pass event information to the handler, check in window.event
  if( !e ) { e = window.event; } if( !e ) { return; }
  //what (case sensitive in good browsers) key was pressed
  //this uses all three techniques for checking, just in case
  var theKey = 0;
  if( e.which ) { theKey = e.which; } //Netscape 4+, etc.
  else if( e.keyCode ) { theKey = e.keyCode; } //Internet Explorer, etc.
  else if( e.charCode ) { theKey = e.charCode } //Gecko - probably not needed
  //was the shift key was pressed
  var theShift = false;
  if( e.shiftKey ) { theShift = e.shiftKey; } //Internet Explorer, etc.
  else if( e.modifiers ) { //Netscape 4
    //check the third bit of the modifiers value (says if SHIFT is pressed)
    if( e.modifiers & 4 ) { //bitwise AND
      theShift = true;
    }
  }
  //if upper case, check if shift is not pressed
  if( theKey > 64 && theKey < 91 && !theShift ) {
//    ap_showWaitMessage('DivCaps', 1);
	alert( 'Atención: Tienes activada la tecla MAYUSCULAS (CAPS LOCK)\n\nPor favor desactivala y NO ESCRIBAS TU MENSAJE ENTERAMENTE EN MAYUSCULAS ya que es de mal gusto.' );
  }
  //if lower case, check if shift is pressed
  else if( theKey > 96 && theKey < 123 && theShift ) {
//    ap_showWaitMessage('DivCaps', 1);
	alert( 'Atención: Tienes activada la tecla MAYUSCULAS (CAPS LOCK)\n\nPor favor desactivala y NO ESCRIBAS TU MENSAJE ENTERAMENTE EN MAYUSCULAS ya que es de mal gusto.' );


  }
}


