// -----------------------
// Banwire.com.mx
// -----------------------
// Modulo: 		main.js
// Modificado: 	julio 08
// -----------------------
function showMsg(opener,nombreMsg,titulo,mensaje){
	html="<div class='msgBoxTitulo'>"+titulo+"</div>";
	html+="<div class='msgBoxMensaje'>"+mensaje+"</div>";
	ocl = "ocultarMsg('cajaM')";
	caja=document.getElementById(nombreMsg);
	caja.innerHTML = html;
	caja.style.left=(getElementLeft(opener)+40)+'px';
	caja.style.top=(getElementTop(opener)+16)+'px';
	//$("#cajaM").animate({opacity: "show"},"fast");
	$("#cajaM").show("fast");
}
function ocultarMsg(){
	//document.getElementById("cajaM").style.visibility="hidden";
	$("#cajaM").hide("fast");
	//$("#cajaM").animate({opacity: "hide"},"slow");
}
function toolTip(obj,tip){
	opener=obj.id;
	tt=document.getElementById("tooltip");
	$("#tooltip").toggle("fast");
	if(tip!=''){
		tt.style.left=(getElementLeft(opener)+30)+'px';
		tt.style.top=(getElementTop(opener)+getElementHeight(opener)+5)+'px';
		tt.innerHTML=tip; 
		$("#tooltip").animate({opacity: "show", top: "+=10"},"fast");
	}else{
		$("#tooltip").animate({opacity: "hide", top: "-=10"},"fast");
	}
}
function toggleHand(op){
	if(op==true){
		document.body.style.cursor="hand";
	}else{
		document.body.style.cursor="default";
	}
}
function validarEmail(email){
	if(email.indexOf("@")==-1){
		return false;
	}else{
		if(email.indexOf(".")==-1){
			return false;
		}else{
			return true;
		}
	}
}
function requestUrlVar(variable){
	var url=""+window.location;
	var urlP=url.split("?");
	var vars=urlP[1];
	if((vars=="")||(vars==null)){
		return false;
	} else {
		var varsP=vars.split("&");
		for(i=0;i<=varsP.length-1;i++){
			var valores=varsP[i].split("=");
			if(valores[0]==variable){ // tenemos un match
				return valores[1];
			}
		}
	}
}
function toggleTab(obj,st,id){
	if(id!=requestUrlVar("p")){
		if(st==1){
			obj.style.backgroundImage="url(/content/templates/default/images/tab_hover.gif)";
		}else{
			obj.style.backgroundImage="url(/content/templates/default/images/tab_normal.gif)";
		}
	}
}
function boxHover(box){
	box.style.borderColor="#3dabd4";
	document.body.style.cursor="hand";
	document.body.style.cursor="pointer";
}
function boxOut(box){
	box.style.borderColor="#b3b3b3";
	document.body.style.cursor="default";
}
function specialChars(texto){
	var textoEscapado=escape(texto);
	var textoUriEncoded=encodeURIComponent(texto);
	if((texto!=textoEscapado)||(textoUriEncoded!=texto)){
		return true;
	}else{
		return false;
	}
}
function strToTitle(texto,delimiter){
	if(delimiter==null){
		delimiter="_";
	}
	var partes=texto.split(delimiter);
	for(var i in partes){
		partes[i]=partes[i].substr(0,1).toUpperCase()+partes[i].substr(1).toLowerCase();
	}
	return partes.join(" ");
}
function validarCampo(campo){
	var objeto=document.getElementById(campo);
	if(objeto.value==""){
		showMsg(campo,"cajaM",strToTitle(campo),"Favor de llenar el campo "+strToTitle(campo));
		objeto.focus();
		return false;
	}else{
		return true;
	}
}
// --------------------
// Funciones AJAX
// --------------------
function getXmlHttpObject()
{
var xmlHttp=null;try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
// Funcion para enviar datos via ajax
// mediante el metodo POST, recibe la url
// a la que se realiza la peticion, las variables
// con formato:
// { 'var1':valor1, 'var2':valor2 } o variable array
// respuesta a la funcion en retFuncion
function sendRequest(url,vars,retFunction){
	var parameters="";
	for(var key in vars){
		parameters+=key+"="+encodeURIComponent(vars[key])+"&";
	}
	parameters=parameters.substr(0,parameters.length-1);
	ajaxReq=getXmlHttpObject();
	if(ajaxReq==null){
		alert("Tu navegador no es compatible con AJAX, por favor actual�zalo!");
	}
	ajaxReq.onreadystatechange=function(){
		if((ajaxReq.readyState==4)||(ajaxReq.readyState=="complete")){
			response=ajaxReq.responseText;
			document.body.style.cursor="default";
			retFunction(response);
		}else{
			document.body.style.cursor="wait";
		}
	}
	ajaxReq.open("POST",url,true);
	ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxReq.setRequestHeader("Content-length", parameters.length);
    ajaxReq.setRequestHeader("Connection", "close");
	ajaxReq.send(parameters);
}
// Evalua y devuelve objeto
function parseJSON( response ) {
	return eval( '(' + response + ')' );
}

// Evalua que la tecla seleccionada sea un numero o se encuentre en las excepciones. 
String.prototype.numeros = function(e,excepciones){
	excepciones = excepciones.split(',');
	charCode = (document.all) ? e.keyCode : e.which;
	if (jQuery.inArray(charCode.toString(),excepciones) != -1) return true
	return ( /^[\d]*[.]?$/.test( String.fromCharCode( charCode ) ) ) ? true : false
}

// Evalua que el formato del porcentaje este correcto.
function valida_porcentaje(elm){
	if ((/^(([.]?\d+)|([\d]+([.]?\d+)))$/.test(elm.value) == false) && elm.value != ''){
		alert("[Error]\tEl porcentaje " + elm.value + " no es correcto.");
		elm.value = '';
	}
}
