var clientPC = navigator.userAgent.toLowerCase();
var clientVer = parseInt(navigator.appVersion);

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

var is_moz = 0;


function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

function tfontstyle(topen, tclose) {
	var txtarea = document.newpost.cuerpo;

	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += topen + tclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = topen + theSelection + tclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, topen, tclose);
		return;
	}
	else
	{
		txtarea.value += topen + tclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}


function buttomPrompt(tipo)
{
	if(tipo=="vyoutube")
	{
		var dftemp = prompt("Ingrese el ID del video de YouTube: \n\nEjemplo: \nSi la URL de su video es: \nhttp://www.youtube.com/watch?v=7lEsXON3Aus \nEl ID es: 7lEsXON3Aus");
		df = "[swf=http://www.youtube.com/v/" + dftemp + "]\nlink: [url]http://www.videos-star.com/watch.php?video="+ dftemp + "[/url]\n";
	}
	else if(tipo=="vgoogle")
	{
		var dftemp = prompt("Ingrese el ID del video de Google: \n\nEjemplo: \nSi la URL de su video es: \nhttp://video.google.com/videoplay?docid=1162021190774713438 \nEl ID es: 1162021190774713438");
		df = "[swf=http://video.google.com/googleplayer.swf?docId=" + dftemp + "]\nlink: [url]http://video.google.com/videoplay?docid="+ dftemp + "[/url]";
	}
	else if(tipo=="swf")
	{
		var dftemp = prompt("Ingrese la URL del archivo swf");
		df = "[swf=" + dftemp + "]\n";
	}
	else if(tipo=="image")
	{
		var dftemp = prompt("Ingrese la URL de la imagen");
		df = "[img=" + dftemp + "]\n";
	}
	else if(tipo=="link")
	{
		var dftemp = prompt("Ingrese la URL que desea postear");
		df = "[url]" + dftemp + "[/url]\n";
	}
	else if(tipo=="quote")
	{
		var dftemp = prompt("Ingrese el texto a citar");
		df = "[quote]" + dftemp + "[/quote]\n";
	}
	if(df !== null)
	{
		document.newpost.cuerpo.value += df;
	}
}

function smile_comment(text)
{
	document.comentario_form.comentario.focus();
	document.comentario_form.comentario.value=document.comentario_form.comentario.value +" "+ text; document.comentario_form.comentario.focus();
}

function insertext(text)
{
	document.newpost.cuerpo.focus();
	document.newpost.cuerpo.value=document.newpost.cuerpo.value +" "+ text; document.newpost.cuerpo.focus();
}

function hidediv(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}


function correctPNG()
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
if (window.attachEvent)
window.attachEvent("onload", correctPNG);

