
//Función para obtener el objeto XMLHttp
//dependiendo del navegador.
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		document.getElementById('msgLoad').innerHTML = 'Status: Cound not create XmlHttpRequest Object.  Consider upgrading your browser.';
	}
}

//Función para mostrar el div de loading en la esquina superior derecha
function showLoading(){
	var lyrMessage = document.getElementById('msgLoad');	
	lyrMessage.style.bottom=document.body.scrollTop;
	lyrMessage.style.left=0;
	lyrMessage.style.visibility='visible';
}
//Función para cerrar el div de loading
function hideLoading(){
	document.getElementById('msgLoad').style.visibility='hidden';
}

//Funcion que nos devuelve el top visible de la página
function getY(){
	if (window.pageYOffset){
		return window.pageYOffset;
	}
	if(document.documentElement && document.documentElement.scrollTop){
		return document.documentElement.scrollTop;
	}
	if(document.body){
		return document.body.scrollTop;
	}
	return 0;
}

function centerH(){
	if( document.body &&  document.body.clientWidth  ) 
    	w = document.body.clientWidth/2;
  	else
		w = window.innerWidth/2;

	return w;
}

function centerV(){
	if( document.body &&  document.body.clientHeight  ) 
        h = document.body.clientHeight/2;
	else
		h = window.innerHeight/2;
		
	return h;
}

//Función para eliminar los espacios en blanco 
function allTrim(s){
	s = s.replace(/^\s+|\s+$/gi,'');
	return s;
}

//Función para validar el email
function validaMail(email){
	if (recovery.email.value == '') {
		alert ('Escriba un Email!');
		recovery.email.focus();
		return false;
	}
	/*var valido = true;
	valido = email.search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/);
	return valido;*/
}

//show OR hide funtion depends on if element is shown or hidden
function show(id) { 
	if (document.getElementById) { // DOM3 = IE5, NS6
		//hideAllMessages();			
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = 'block';
		} else {
			document.getElementById(id).style.display = 'none';	
		}	
	} else { 
		if (document.layers) {	
			if (document.id.display == "none"){
				document.id.display = 'block';
			} else {
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = 'block';
			} else {
				document.all.id.style.display = 'none'; 
			}
		}
	}
}
function showIt(id) { 
	if (document.getElementById(id).style.display == "none"){
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'block';	
	};
};

function hide(id) { 
	if (document.getElementById(id).style.display == "block"){
		document.getElementById(id).style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'none';	
	};
};
/*
function copyThis(s){
	if( window.clipboardData && clipboardData.setData ){
		clipboardData.setData("Text", s);
	}else{
		// You have to sign the code to enable this or allow the action in about:config by changing
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);	   
	}
}*/

// main function to process the fade request //
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  //target.style.display = 'block';
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
	switch(element){
		case 'background':
		target.style.backgroundColor = color;
		break;
		case 'border':
		target.style.borderColor = color;
		break;
		case 'text':
		target.style.color = color;
		break;
	}
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
	
	switch(element){
		case 'background':
		target.style.backgroundColor = color;
		break;
		case 'border':
		target.style.borderColor = color;
		break;
		case 'text':
		target.style.color = color;
		break;
	}
  }
  target.inter = setInterval( function() { add(target); }, 100);
}
var counter = 0;
function add(id){
	if(counter>=2000){
		counter = 0;
		id.style.display = 'none';
		clearInterval(id.inter);
	}else{
		counter++
	}
}
// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}
var $ns = 0;
function pageScroll() {
    window.scrollBy(0,50); // horizontal and vertical scroll increments
    scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
	$ns++;
	if($ns>=30){
		//window.scroll(0,150); 
		$ns = 0;
		clearTimeout(scrolldelay);	
	}
}

function playRadio(theURL,winName,features) { //v2.0
  window.open(theURL,winName, "width=550,height=100,top=50,left=280,alwaysRaised=yes,toolbar=0,directories=0,menubar=0,status=0,resizable=no,location=0,scrollbars=0,copyhistory=0");
}

function switchPlus(img_name){
   if(document[img_name].src == 'http://static.viviendolavida.com/plus.png'){
	   document[img_name].src = 'http://static.viviendolavida.com/minus.png';
   }else{
	   document[img_name].src = 'http://static.viviendolavida.com/plus.png';
   }
}

