

//Función para obtener el objeto XMLHttp

//dependiendo del navegador.

function getXmlHttpRequestObject() {

	/*if (window.XDomainRequest) { //IE8

	return new XDomainRequest();

	} else */ 

	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';	

	};

};



// 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;

}



function deleteMsg(p,id,d,t) {	

	if(confirm('Desea eliminar este mensaje?')){

		getData(p,id,d,t);

	}

	return false;

};



//IMPRIMIR SELECCION

function fnSelect(objId){

   fnDeSelect();

   if (document.selection){

      var range = document.body.createTextRange();

      range.moveToElementText(document.getElementById(objId));

      range.select();

   }

   else if (window.getSelection){

      var range = document.createRange();

      range.selectNode(document.getElementById(objId));

      window.getSelection().addRange(range);

   }

}

function fnDeSelect(){

   if (document.selection)

             document.selection.empty();

   else if (window.getSelection)

              window.getSelection().removeAllRanges();

} 



function checkForm(form) {	

	if (form.uname.value == '') {

		alert ('Por favor, ingrese su Nombre');

		form.uname.focus();

		return false;

	}

	if (form.uemail.value == '') {

		alert ('Por favor, ingrese su email' );

		form.uemail.focus();

		return false;

	}

	if (form.message.value == '') {

		alert ('Por favor, ingrese su mensaje');

		form.message.focus();

		return false;

	}

	if (form.security_code.value == '') {

		alert ('Por favor, ingrese el codigo de seguridad!');

		form.security_code.focus();

		return false;

	}



	postComment();

};


