var imagenAjax = 'images/ajax.gif';
var myclose = false;
var isNS4 = (navigator.appName=="Netscape")?true:false;

function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie;             
	if (dc.length > 0) {        
		begin = dc.indexOf(cname);       
		if (begin != -1) {           
			begin += cname.length;       
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
			return unescape(dc.substring(begin, end));
		} 
	}
	return null;
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function eraseCookie(name){ Set_Cookie(name,"",-1); }

function isdefined(objToTest) {
	if (null == objToTest) return false;
	if ("undefined" == typeof(objToTest)) return false;
	return true;
}

function isFunction(a){ return typeof a == 'function'; }

function hss(objToProcess, status){ 
	try { document.getElementById(objToProcess).style.display=status;} 
	catch(err){	alert("EXHSS: "+objToProcess);}
}

function gvv(objToProcess){ 
	try { return document.getElementById(objToProcess).value;} 
	catch(err){	alert("EXGVV: "+objToProcess);}
}

function goo(objToProcess){ 
	try { return document.getElementById(objToProcess);} 
	catch(err){	alert("EXGOO: "+objToProcess);}
}

function svv(objToProcess, strValue){ 
	try { document.getElementById(objToProcess).value = strValue;} 
	catch(err){	alert("EXSVV: "+objToProcess);}
}

function sii(objToProcess, strValue){ 
	try { document.getElementById(objToProcess).innerHTML = strValue; } 
	catch(err){	alert("EXSII: "+objToProcess);}
}

function gii(objToProcess){ 
	try { return document.getElementById(objToProcess).innerHTML; } 
	catch(err){	alert("EXGII: "+objToProcess);}
}

function cambiaIdioma(lang) {
	Set_Cookie("idioma",lang,3)
	window.parent.location.reload();
}

function pm(name, enlace){
	if (!isdefined(enlace)) enlace='marketext.com';
	document.write('<a href=mailto:' + name + '@' + enlace + '>' + name + '@' + enlace + '</a>');
}

function left(str, n){
	if (n <= 0) 
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function ltrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function rtrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim( value ) {
	return ltrim(rtrim(value));
}

function ajaxLoader(programa, id, parametros, displaytext, displayid) {
	loadingData = "<img border='0' src='"+imagenAjax+"'>&nbsp;&nbsp;<font face='Verdana' size='1'>"
	if (isdefined(displaytext)) loadingData+= displaytext; else loadingData+="Loading . . ."; loadingData+= "<\/font>";
	if (isdefined(displayid)) sii(displayid,loadingData); else sii(id,loadingData);
	if (document.getElementById) { var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); }
	if (x) { x.onreadystatechange = function() { if (x.readyState == 4 && x.status == 200) { sii(id, x.responseText); }}
		if(parametros!='') url=programa+'?id=' + parametros; else url=programa;
		x.open("GET", url, true); x.send(null);
	}
}

function addLoadEvent(func){	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}

function checkselected(ctrl,cual) { 
	ctrl = document.getElementsByName(ctrl); 
	for(i=0;i<ctrl.length;i++){ 
		if(ctrl[i].checked) { 
			if (isdefined(cual)) svv(cual, ctrl[i].value); 
			return ctrl[i].value; 
		} 
	} 
	if (isdefined(cual)) svv(cual, -1); 
	return -1;
}

function emailCheck (emailStr) { 
	var emailPat=/^(.+)@(.+)$/; 
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; 
	var validChars="\[^\\s" + specialChars + "\]"; 
	var quotedUser="(\"[^\"]*\")"; 
	var ipDomainPat=/^[(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})]$/; 
	var atom=validChars + '+'; 
	var word="(" + atom + "|" + quotedUser + ")"; 
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); 
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); 
	var matchArray=emailStr.match(emailPat); 
	if (matchArray==null) return false;
	var user=matchArray[1] ;
	var domain=matchArray[2] ;
	if (user.match(userPat)==null) return false ;
	var IPArray=domain.match(ipDomainPat) 
	if (IPArray!=null) { 
	    for (var i=1;i<=4;i++) if (IPArray[i]>255) return false ;
	    return true ;
	} 
	var domainArray=domain.match(domainPat) ;
	if (domainArray==null) return false; 
	var atomPat=new RegExp(atom,"g") ;
	var domArr=domain.match(atomPat) ;
	var len=domArr.length ;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) return false ;
	if (len<2) return false; 
	return true; 
} 

function quitaespacios(texto){ return texto.replace(/ /gi,''); }

function openPopup(url,name,w,h,props,center){
	l=18;t=18
	if(center){l=(screen.availWidth-w)/2;t=(screen.availHeight-h)/2}
	url=url.replace(/[ ]/g,'%20')
	popup=window.open(url,name,'left='+l+',top='+t+',width='+w+',height='+h+',scrollbars=1'+((props)?','+props:'')); props=props||''
	if(props.indexOf('fullscreen')!=-1){popup.moveTo(0,0);popup.resizeTo(screen.width,screen.height)}
	popup.focus()
}

function openPaises(url){
	if (!isdefined(url)) url = "";
	openPopup(url+'./listapaises.php','listaPaises',420,380,'status=no,resizable=yes,toolbar=no,scrollbars=yes,menubar=no',true);
}
function valalfa(e){
	tecla = (document.all) ? e.keyCode : e.which;  if (tecla == 8) return true;
    patron = /[A-Za-z0-9 ]/; te = String.fromCharCode(tecla);
    return patron.test(te);
}

function valnum(e){
    tecla = (document.all) ? e.keyCode : e.which;  if (tecla == 8) return true;
    patron = /[0-9]/;  te = String.fromCharCode(tecla);
    return patron.test(te);
}

function valfloat(e){
    tecla = (document.all) ? e.keyCode : e.which;  if (tecla == 8) return true;
    patron = /[0-9.]/;  te = String.fromCharCode(tecla);
    return patron.test(te);
}

function bl_enter(e) {
    tecla = (document.all) ? e.keyCode : e.which;  
	if (tecla == 13) return false;
}

function bl_space(e) {
    tecla = (document.all) ? e.keyCode : e.which;  
	if (tecla == 32) return false;
}

function focused(objElement,focusclass,blurclass){
  if (objElement.className==blurclass)
    objElement.className=focusclass;
  else
    objElement.className=blurclass;
}

function sobre(obj, color) {
	obj.style.backgroundColor= color ;
}

function getFormData(formName){
	var frmData = ""; l=goo(formName).elements.length;
	for (i=0; i<l; i++) { 
		objeto = goo(formName).elements[i];
		if (isdefined(objeto.id)){
			if (objeto.type=="checkbox" || objeto.type=="radio" ){
				valor=(objeto.checked)?1:0;
				frmData+="&"+objeto.id+"="+valor;
			}else
				frmData+="&"+objeto.id+"="+objeto.value;
		}
	}
	return frmData;
}

function conSelects(action){
	for (i=0; i<document.forms[0].elements.length; i++) {
		objeto = document.forms[0].elements[i] ;
		if (objeto.type=="select-one") hss(objeto.id,action);
	}
	hss("idioma",action);
}

function changeTxtSize(direction){
	var textIncrement=10;
	if(document.body.style.fontSize==''){document.body.style.fontSize='100%';}
	if(direction=='dec'){textIncrement=-textIncrement;}
	newFs=parseInt(document.body.style.fontSize)+textIncrement;
	document.body.style.fontSize=newFs+'%';
}

Array.prototype.inArray = function (value) {
  var i = this.length;
  if (i > 0) {
	 do {
		if (this[i] === value) return true;
	 } while (i--);
  }
  return false;
}

function buscaList(textoSearch,queCombo,arrNombres,arrClaves) {
	objLista = goo(queCombo);
	limpiarLista(queCombo);
	expr = new RegExp("^" + textoSearch,"i"); y = 0;
	for (x=0;x<arrNombres.length;x++) {
		if (expr.test(arrNombres[x])) {
			objLista[y] = new Option(arrNombres[x], arrClaves[x]); y++;
		}
	}
}
			 
function limpiarLista(queCombo) {
	objLista = goo(queCombo);
	for (x=objLista.length;x>=0;x--) objLista[x] = null; 
}

function updImgInbox(msgID){}

function updInbox(access,msgID){
	ajaxLoader("inbox.php", "txtInbox", "1&ac=3&access="+access, "", "divInbox");
	updImgInbox(msgID);
}

function exportar(format){ DG_Do("ew",format,'',1); }

function sList(activo){
	switch (activo){
		case 1:	activo = 'divcontacto'; break;
		case 2:	activo = 'divgrupo'; break;
		case 3:	activo = 'divmsg'; break;
		case 4:	activo = 'divpre'; break;
	}
	lo = DG_gvv('lopen'); if (lo==activo) return;
	if (lo!='') Slide(lo).swap();
	Slide(activo).swap();
	DG_svv('lopen',activo);
}


function PintaFondo(elemento,color){ if (color == 0){ color="#FD9893"; }else{ color="#FFFFFF";} goo(elemento).style.backgroundColor = color; goo(elemento).focus();}

function repeat(strInput, intCount) {
	var arrTmp = new Array(intCount+1);
	return arrTmp.join(strInput);
}

function clean(){
	try { globalTooltipObj.__hideTooltip(); } 
	catch(err){}
	return true;
}

function oNumero(numero){
	this.valor = numero || 0
	this.dec = -1;
	this.formato = numFormat;
	this.ponValor = ponValor;

	function ponValor(cad){
		if (cad =='-' || cad=='+') return
		if (cad.length ==0) return
		this.valor = (cad.indexOf('.') >=0)?parseFloat(cad):parseInt(cad);
	};

	function numFormat(dec, miles){
		var num = this.valor, signo=3, expr;
		var cad = ""+this.valor;
		var ceros = "", pos, pdec, i;
		for (i=0; i < dec; i++)
		ceros += '0';
		pos = cad.indexOf('.')
		if (pos < 0){
			cad = cad+"."+ceros;
		}else{
			pdec = cad.length - pos -1;
			if (pdec <= dec){
				for (i=0; i< (dec-pdec); i++) cad += '0';
			}else{
				num = num*Math.pow(10, dec);
				num = Math.round(num);
				num = num/Math.pow(10, dec);
				cad = new String(num);
			};
		};
		pos = cad.indexOf('.');
		if (pos < 0) pos = cad.lentgh;
		if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') signo = 4;
		if (miles && pos > signo){
			do{
				expr = /([+-]?\d)(\d{3}[\.\,]\d*)/;
				cad.match(expr);
				cad=cad.replace(expr, RegExp.$1+','+RegExp.$2);
			}while (cad.indexOf(',') > signo);
		};
		if (dec<0) cad = cad.replace(/\./,'');
		return cad;
	};
};//Fin del objeto oNumero:

var R=G=B=x=0;
function fadetext(id,r,g,b,z){ fade(id,r,g,b,R,G,B,x,z); }
function fade(id,r,g,b,R,G,B,x,z){
	if (!isdefined(z)) z=30;
	if (x<255){
		x+=4; R=(R<r)?(R+x):r; G=(G<g)?(G+x):g; B=(B<b)?(B+x):b; R=(R>255)?255:R; G=(G>255)?255:G; B=(B>255)?255:B;
    	document.getElementById(id).style.color= "rgb("+R+","+G+","+B+")";
		setTimeout("fade('"+id+"',"+r+","+g+","+b+","+R+","+G+","+B+","+x+")",z);
	}else var R=G=B=x=0;
}

function pause(seconds){
	var currentTime = new Date()
	var secOriginal=secActual=currentTime.getSeconds();
	for (var cuantos=0; cuantos<seconds; cuantos++){
		var currentTime = new Date()
		if (secOriginal==secActual){
			cuantos--; 
			secActual=currentTime.getSeconds();
		}else{
			secOriginal=secActual=currentTime.getSeconds();
		}
	}
}

function imposeMaxLength(objField, txtMaxLen){ 
	if (objField.value.length > txtMaxLen) objField.value=objField.value.substr(0,txtMaxLen); return true;
};

function ventanaInfoMaster()
{
	window.open("http://www.mastercardbusiness.com/mcbiz/index.jsp?template=/orphans&content=securecodepopup", "Info","width=550,height=500");	
};

function ventanaInfoVisa()
{
	window.open("verifiedByVisa-"+getCookie("idioma")+".html","Info","width=500,height=500");	
}
/* Muestra la ventana para realizar el Login */
function showLogin(){
	$('#modalContentTest').modal({onOpen: modalOpen, onClose: modalClose, close: true});
}

function modalOpen (dialog){
	dialog.overlay.slideDown('slow', function () {
		dialog.container.show('slow', function () {
			dialog.data.show('fast');
			xajaxLoader("acceder.php", 'loginx', '', ''); 
		});
	});
}

function modalClose (dialog) {
	dialog.data.hide('fast', function () {
		dialog.container.hide('fast', function () {
			dialog.overlay.slideUp('slow', function () {
				$.modal.close();
			});
		});
	});
}

