
var main_ext = "dr";
var xhttpobj;

function new_ajax() {
    try {
         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
       try {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (E) {
         xmlhttp = false;
       }
   }
   
   if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      xmlhttp = new XMLHttpRequest();
   }

   return xmlhttp
}

function get_data(xmlhttp, status, status2, text) {
   if(status2 != false)
     document.getElementById(status2).innerHTML=text;
 
   document.getElementById(status).innerHTML=xmlhttp.responseText
   status2 = document.getElementById('status_settings2');
   if( status2 )
   	  status2.innerHTML = document.getElementById(status).innerHTML;
}

function send_data(xmlhttp, url, string, status, status2, text)
{
   xmlhttp.open('POST', main_url + url, true);
   xmlhttp.onreadystatechange=function() {
     if (xmlhttp.readyState==4) {
        get_data(xmlhttp, status, status2, text)
     }
   }
 
   xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   xmlhttp.send(string) 
}

function encodeURLString(string) {
   var value;
		
   varArray = string.split('&');
   for (i = 0; i < varArray.length; i++)
   {
			evcont = 'value = document.getElementById(\''+varArray[i]+'\').value;';
			eval(evcont);
		    
		    varArray[i] = encVar(varArray[i], value);
	}
	
	return varArray.join('&');
}

function encVar(name, value) {
	var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
	return varString;
}
	
function submit_data(direct, inputs, span, span2, text) {
    var xmlhttpS = new_ajax();
    var string = encodeURLString(inputs);
    
	send_data(xmlhttpS, direct, string, span, span2, text)
}

function module(url) {
    xhttpobj = new_ajax();
    xhttpobj.open('GET', main_url + "modules.php?"+main_ext+"="+url, true);
    xhttpobj.onreadystatechange=function() {
       if (xhttpobj.readyState == 4) {
           get_data(xhttpobj, 'modules', false, false)
       }
    }
    
	xhttpobj.send(null)
}

function switch_img(element, value, path) {
    element.src = path + (value ? "h_" : "") + element.id + ".gif";
}

function seguridad(contrasena) { 
    var  filteralp=/[a-zA-Z]+/;
    var  filternum=/\d+/;
    var  filtercar=/\W+/;
    var  baja  = document.getElementById("baja");
    var  media = document.getElementById("media");
    var  alta  = document.getElementById("alta");
      
    longitud = contrasena.length;
    if(longitud > 5 && filteralp.test(contrasena) && filternum.test(contrasena) && filtercar.test(contrasena))
    {
       baja.className = "alta";
	   media.className = "alta";
	   alta.className = "alta";
    }
    else if(longitud > 5 && filteralp.test(contrasena) && filternum.test(contrasena) || longitud > 6 && filteralp.test(contrasena) && filtercar.test(contrasena) || longitud > 6 && filternum.test(contrasena) && filtercar.test(contrasena))
    {
       baja.className = "media"
	   media.className = "media"
	   alta.className = "des"
    }
    else if(longitud > 5)
    {
       baja.className = "baja";
	   media.className = "des";
	   alta.className = "des";
    }
    else
    {
       baja.className = "des";
	   media.className = "des";
	   alta.className = "des";
    }
}

function users_online() {
    var xmlhttpU = new_ajax();
	
    xmlhttpU.open('GET', "modules.php?users_online=true", true);
    xmlhttpU.onreadystatechange=function() {
       if(xmlhttpU.readyState==4) {
         try {  
           get_data(xmlhttpU, 'users_online', false, false)
         }
         catch ( e )
         {}
       }
    }
    
	xmlhttpU.send(null)
}

function shrink(capa) {
    var targetElement = document.getElementById(capa);
    var element_img = document.getElementById(capa+"_img");
	
    if (targetElement.style.display == "none") 
    {
	   targetElement.style.display = ""; 
	   if( element_img )  
	     element_img.src = './images/ba-up.gif';
	}
    else
	{
       targetElement.style.display = "none";
	   if( element_img )  
          element_img.src = './images/ra-down.gif';
	}
}

var checkeds = false;

function select_switch() {
	 checkeds = !checkeds;
	 for (i = 0; i < document.privf.length; i++)
	 {
		 document.privf.elements[i].checked = checkeds;
	 }
}

function stars(id, curr_rating) {
     var image = "rating_over.gif";
	 var img_id;
	   
	 for(i=1;i<=5;i++) {
	      if(i == (id+1) || image != "rating_over.gif" ) {
		    image = curr_rating >= i ? "rating_on.gif" : "rating_off.gif";
		  }
		  
	      img_id = document.getElementById("star_"+i);
		  img_id.src = "templates/default/images/"+image;   
	 }
}
   
function submit_data_stars(direct, value, span) {
     var xmlhttp_st = new_ajax();

     send_data(xmlhttp_st, direct, 'star='+value, span, false, false)
}   

function make_popup(linkurl, name, width, height) {
     window.open(linkurl, name, 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width='+width+',height='+height+',directories=no,location=no');	
}

/* -- (C) www.dhtmlgoodies.com, October 2005 --*/

var progressbar_steps = 10;	// Total number of progress bar steps.
	
var progressPane = false;
var progressBar_bg = false;
var progressBar_outer = false;
var progressBar_txt = false;
var progressbarWidth;
var currentStep = 0;

function moveProgressBar(steps){
	 if(!progressBar_bg){
			progressPane = document.getElementById('progressPane');
			progressBar_bg = document.getElementById('progressBar_bg');
			progressBar_outer = document.getElementById('progressBar_outer');
			progressBar_txt = document.getElementById('progressBar_txt');
			progressbarWidth = progressBar_bg.clientWidth;
	 }
	 
	 if(!steps){
			progressBar_outer.style.width = progressbarWidth + 'px';
			progressBar_txt.innerHTML = '100%';
		//	setTimeout('document.getElementById("progressPane").style.display="none"', 2);
                setTimeout('document.getElementById("progressPane").style.visibility="hidden"', 2);
	 }else{
			currentStep+=steps;
			if(currentStep>progressbar_steps)currentStep = progressbar_steps;
			var width = Math.ceil(progressbarWidth * (currentStep / progressbar_steps));
			progressBar_outer.style.width = width + 'px';
			var percent = Math.ceil((currentStep / progressbar_steps)*100);
			progressBar_txt.innerHTML = percent + '%';
			if(currentStep==progressbar_steps){
			//	setTimeout('document.getElementById("progressPane").style.display="none"', 2);
                setTimeout('document.getElementById("progressPane").style.visibility="hidden"', 2);
            }
	 }		
}

function ProgressBar()
{		
     if(progressBar_txt.innerHTML != '100%') {
		//  document.getElementById("progressPane").style.display="inherit";
		  document.getElementById("progressPane").style.visibility="visible";
	 }
	 else {
           progressbar_steps = 10;
           progressPane = false;
           progressBar_bg = false;
           progressBar_outer = false;
           progressBar_txt = false;
           progressbarWidth;
           currentStep = 0;
           
		   return;
	 }
		
	 if(currentStep<progressbar_steps){
			moveProgressBar(1);
			setTimeout('ProgressBar()', 5);
	 }
}

//-- End dhtmlgoodies --//

var LCounter = 0;

function LoadProcedure()
{
      var oElem = document.getElementById("cLoadingIndicator");
	  oElem.style.visibility="visible";
	  LCounter = 2;
	  
	  setTimeout('LoadCounter()', 1000);
}

function LoadCounter() 
{  
      if( LCounter <= 0 && xhttpobj.readyState == 4) 
	  {
            document.getElementById("cLoadingIndicator").style.visibility="hidden";
	        LCounter = 0;
			
			return 0;
	  }
	  else
	  { 
	    setTimeout('LoadCounter()', 1000);
		LCounter--;
	  }
}


//------------ BBcode Form -------------//


// bbCode control by
// subBlue design
// www.subBlue.com

// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

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_moz = 0;

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

// Helpline messages
b_help = "Negrita: [b]texto[/b]  (alt+b)";
i_help = "Cursiva: [i]texto[/i]  (alt+i)";
u_help = "Subrayado: [u]texto[/u]  (alt+u)";
q_help = "Cita: [quote]texto[/quote]  (alt+q)";
c_help = "Codigo: [code]codigo[/code]  (alt+c)";
l_help = "Lista: [list]texto[/list] (alt+l)";
o_help = "Lista ordenada: [list=]texto[/list]  (alt+o)";
p_help = "Insertar imagen: [img]http://url_imagen[/img]  (alt+p)";
w_help = "Insertar URL: [url]http://url[/url] o [url=http://url]texto URL[/url]  (alt+w)";
a_help = "Cerrar todos los marcadores de bbCode abiertos";
s_help = "Color: [color=red]texto[/color]  Nota: Puede usar color=#FF0000";
f_help = "Tamaño: [size=x-small]texto pequeño[/size]";

// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]');
imageTag = false;

// Shows the help messages in the helpline window
function helpline(help) {
     document.getElementById("helpbox").value = eval(help + "_help");
}


// Replacement for arrayname.length property
function getarraysize(thearray) {
	 for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
	 }
	 return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	 thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	 thearraysize = getarraysize(thearray);
	 retval = thearray[thearraysize - 1];
	 delete thearray[thearraysize - 1];
	 return retval;
}

function emoticon(text) {
	
	 var txtarea = document.getElementById("message");
	 text = ' ' + text + ' ';
	 if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
 	 } else {
		txtarea.value  += text;
		txtarea.focus();
	 }
}

function bbfontstyle(bbopen, bbclose) {
	 var txtarea = document.getElementById("message");

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

function bbstyle(bbnumber) {
	 var txtarea = document.getElementById("message");

	 txtarea.focus();
	 donotinsert = false;
	 theSelection = false;
	 bblast = 0;

	 if (bbnumber == -1) { // Close all open tags & default button names
 		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = eval('document.getElementById("addbbcode' + butnumber + '").value');
			eval('document.getElementById("addbbcode' + butnumber + '").value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	 }

	 if ((clientVer >= 4) && is_ie && is_win)
	 {
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	 }
	 else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	 {
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	 }
	
	 // Find last occurance of an open tag the same as the one just clicked
	 for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	 } 

	 if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				buttext = eval('document.getElementById("addbbcode' + butnumber + '").value');
				eval('document.getElementById("addbbcode' + butnumber + '").value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			txtarea.focus();
			return;
	 } else { // Open tags
	
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.post.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}
		
		// Open tag
		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		eval('document.getElementById("addbbcode'+bbnumber+'").value += "*"');
		txtarea.focus();
		return;
	 }
	 storeCaret(txtarea);
}

// From http://www.massless.org/mozedit/
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;
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	 if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function showimage(mode)
{
	 if(mode == 1) {
		   item_id = 'image';
		   path    = 'images/news/';
	 }
	 else
	 {
		   item_id = 'gallery_avatar';
		   path    = 'images/avatar/gallery/';
	 }
     
	 document.getElementById('rotate_image').src = path + document.getElementById(item_id).value;
} 

function change_dname(name, domain)
{
	document.getElementById('dname').innerHTML = 'Su blog se llama ahora: ' + name.toLowerCase() + '.' + domain;
}