/* SARENA */
var isIE5=(window.navigator.appName=="Microsoft Internet Explorer"&&window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE")+5,window.navigator.appVersion.indexOf("MSIE")+8)==5.0);
if (isIE5) {
	var undefined = 'undefined';
}
/* SARENA */

function isArray(a){
    if ( a.constructor ) {
      return isObject(a) && a.constructor == Array;
    } else {
      try {
        return (a.length > 0);
      } catch(e) {
        return false;
      }
    }
}
  

/* Funciones para DialogModal */
function OpenDialogModal(URL,param,TargetForm,TargetField,DoSubmit) {
  // URL: ruta y nombre de la pagina popup
  // param: debe venir de la forma param1=valor1&param2=valor2...
  // TargetForm: nombre del form destino
  // TargetField: nombre del campo que está en TargetForm y se le asignará el resultValue
  // DoSubmit: 1: Hacer submit. 0: No hacer submit
  var URLFull = URL + "?" + param;
  arguments = window.showModalDialog(URLFull,"Mensaje","dialogHeight: 160px; dialogWidth: 450px; dialogTop: 100px; dialogLeft: 50px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");

  if ((arguments) && (arguments!="") && (TargetField) && (TargetForm)) {
    eval("document." + TargetForm + "." + TargetField).value = arguments;
    if (DoSubmit)
      eval("document." + TargetForm).submit();
  }
  return;
}

/* ----------------------------- */

function jsTrim(sf_string){
	if (sf_string!=undefined){
		sf_string=sf_string.replace(/ +/g," ");
		sf_string=sf_string.replace(/^ /,"");
		sf_string=sf_string.replace(/ $/,"");
	}
	return(sf_string);
}


function textCounter(field, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
}

/* Super trim de strings */
function replace(str,text,by) {
// Replaces text with by in string
    var strLength = str.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return str;

    var i = str.indexOf(text);
    if ((!i) && (text != str.substring(0,txtLength))) return str;
    if (i == -1) return str;

    var newstr = str.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(str.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function pString(sf_string){
	sf_string = sf_string.replace(/ +/g," ");
	sf_string = sf_string.replace(/^ /,"");
	sf_string = sf_string.replace(/ $/,"");
	sf_string = replace(sf_string,",","&#130;");
	sf_string = replace(sf_string,"\'","'");
	sf_string = replace(sf_string,"\"","&#148;");
	return(sf_string);
}

function unpString(sf_string) {
    sf_string = replace(sf_string,"&#148;","\"");
    sf_string = replace(sf_string,"&#130;",",");
    return sf_string;
}

//Popup Generico

function dopopup(url, title, tool, loc, dir, stat, menu, scroll, resize, w, h, l, t)
		{
		var NewWin = window.open(url,title,"toolbar="+tool+",location="+loc+",directories="+dir+",status="+stat+",menubar="+menu+",scrollbars="+scroll+",resizable="+resize+",width="+w+",height="+h+",left="+l+",top="+t);
		NewWin.focus();
		}

//Validacion de campo requerido
function dorequerir(f, v){
	if (jsTrim (f.value) == ''){
		alert(v + " " + ml_getNode("#xmlData_" + jsPageId,"error_require-field"));
        f.focus();
        return false;
	}else{
		return true;
	}
}

// valida si el string es un email
function isMail(string){
	if (string == ""){
		return(false);
	}else{
		valor = string;
		largo = valor.length;
		x = 0;
		y = 0;
		for(i=0; i<largo; i++){
			control = valor.substring(i,i+1);
			if (control == "@"){
				x = i;
			}
			if (control == " "){
				y = 1;
			}
		}
		if (x == 0 || y == 1){
			return(false);
		}else{
			valor1 = valor.substring(x + 1, valor.length);
			largo = valor1.length;
			x = 0;
			for (i=0; i<largo; i++){
				control = valor1.substring(i,i+1);
				if (control == "."){
					x = i;
				}
			}
			if (x == 0){
				return(false);
			}else{
				if ((x+1) == largo){
					return(false);
				}else{
					return(true);
				}
			}
		}
	}
}
function changespan(name, data){
	obj=eval(name);
	if (document.layers) {
		document.layers.obj.document.write(data);
		document.layers.obj.document.close();
	}
	else {
		if (document.all) {
			obj.innerHTML = data;
	    }
	}
}

function checkXML(){
   try{
		objDOM = new ActiveXObject("Msxml2.DOMDocument.3.0");
   }
   catch (e){
		document.write("<object id=\"MSXML3\" classid=\"clsid: f5078f32-c551-11d3-89b9-0000f81fe221\" codebase=\"msxml3.cab#version=8,10,8308,0\" type=\"application/x-oleobject\" STYLE=\"display: none\"></object>");
   }
}
