
// Ver si el navegador es Firefox o no
// Uso : if (FF()) { ...
function FF() {
	if (typeof window.pageXOffset != 'undefined') {
		return true;
	} else {
		return false;
	}
}

// Ver cuanto avance tiene el Scroll (sirve para cuando quieres posicionar algo y quieres saber cuanto esta movida la ventana)
// Uso : alert(ScrollX());
function ScrollX() {
	if (typeof window.pageXOffset != 'undefined') {
		if (window.pageXOffset != 0) { 
			return window.pageXOffset + 9;
		} else {
			return window.pageXOffset;
		}
	} else {
		if (document.documentElement.scrollLeft != 0) {
			return document.documentElement.scrollLeft + 10;
		} else {
			return document.documentElement.scrollLeft;
		}
	}
}


// Ver cuanto avance tiene el Scroll (sirve para cuando quieres posicionar algo y quieres saber cuanto esta movida la ventana)
// Uso : alert(ScrollY());
function ScrollY() {
	if (typeof window.pageYOffset != 'undefined') {
	  return window.pageYOffset - 17;
	} else {
	  return document.documentElement.scrollTop;
	}
}
 
// Ver cuanto mide el Ancho dentro de la ventana
// Sirve para por ejemplo ver si el navegador lo hisieron mas pequeo y asi ajustar ciertas cosas como DIV's
function AnchoVentana() {
	if (FF()) {
		return window.innerWidth;
	}
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		return document.documentElement.clientWidth;
	}
	else {
		return document.getElementsByTagName('body')[0].clientWidth;
	}
}
 
// Ver cuanto mide el Alto dentro de la ventana
// Sirve para por ejemplo ver si el navegador lo hisieron mas pequeo y asi ajustar ciertas cosas como DIV's
function AltoVentana() {
	if (FF()) {
		return window.innerHeight;
	}
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		return document.documentElement.clientHeight;
	}
	else {
		return document.getElementsByTagName('body')[0].clientHeight;
	}
}


function obtener_ancho_win(){
	if (navigator.userAgent.indexOf("MSIE") > 0){
		return(document.body.clientWidth);
	}else{
		return window.outerWidth;
	}
}
function obtener_alto_win(){
	if (navigator.userAgent.indexOf("MSIE") > 0){
		return(document.body.clientHeight);
	}else{
		return(window.outerHeight);
	}
}
// Centrar Popups (del tipo window.open)
function CentrarAlto(valor)
{
//	Medida = ((screen.height / 2) - (valor / 2));}
	Medida = ((obtener_alto_win() / 2) - (valor / 2));
	return Medida - 30;
}
function CentrarAncho(valor) 
{
//	Medida = ((screen.width / 2) - (valor / 2));
	Medida = ((obtener_ancho_win() / 2) - (valor / 2));
	return Medida - 10;
}

/*-------------------abre una ventanita popup centrada---------------------------------------*/
function AbrePopUp(url, ancho, alto, opcs){
	if(opcs[0]!=',')
		opcs = ', '+opcs; //Ej: resizable=no, scrollbars=yes,
	var aleatorio = Math.round(Math.random()*100); 	
	window.open(url,'vent'+aleatorio,'width='+ancho+', height='+alto+', status=no, toolbar=no, menubar=no, left='+CentrarAncho(ancho)+', top='+CentrarAlto(alto)+opcs);
}

//---------------------------------------------------------------------------------------------------------

function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;
	if (str+"" == "undefined" || str == null)	
		return null;
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {	
		len = str.length;
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;
  		resultStr = str.substring(i, len);
  	}
  	return resultStr;
 }


function TrimRight( str ) {
	var resultStr = "";
	var i = 0;
	if (str+"" == "undefined" || str == null)	
		return null;
	str += "";
	if (str.length == 0) 
		resultStr = "";
	else {
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
  		resultStr = str.substring(0, i + 1);
  	}
  	return resultStr;  	
}

function Trim( str ) {
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}
  
//--para agregar maxlengt al text area
function ismaxlength(obj){
	var mlength = obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length > mlength)
	obj.value = obj.value.substring(0,mlength)
}


function Contiene(texto, cadena) {
	var Temp = cadena;
	if (Temp.indexOf(texto) != "-1") {
		return true;
	} else {
		return false;
	}
}  

function ContieneChar(texto, cadena) {
	var Temp = cadena;
	if (Temp.indexOf(texto) != "-1") {
		return true;
	} else {
		return false;
	}
}  


//===============================================================
function enviaFacebook(IdArt,Titulo){
	window.open('http://www.facebook.com/sharer.php?u=http://www.candidatosdelpan.com/index.php?v2=articulos&IdArt='+ IdArt +'&t='+Titulo);
}

function cambiaPagina(dir){
	document.location.href = dir;
}

function enviaAmigo(IdArt,Origen,IdCandi){
	window.open('envia_amigo.php?IdArt='+IdArt+'&Origen='+Origen+'&IdCand='+IdCandi,'envia','width=525, height=320, status=no, toolbar=no ,menubar=no, resizable=no, scrollbars=yes, left=' + CentrarAncho(525) + ', top=' + CentrarAlto(320));
}
function contactanos(){
	window.open('contactanos.php','contactanos','width=550, height=350, status=no, toolbar=no ,menubar=no, resizable=no, scrollbars=yes, left=' + CentrarAncho(550) + ', top=' + CentrarAlto(350));
}

