//*************************************************************************
// *** funciones que permiten limitar los campos de texto de los artículos / cuentan palabras y letras
function LimitAttach(form, file, extArray) {
  allowSubmit = false;
  if (!file) return;
  while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);

  ext = file.slice(file.indexOf(".")).toLowerCase();
  for (var i = 0; i < extArray.length; i++) {
	if (extArray[i] == ext) { allowSubmit = true; break; }
  }
  if (!allowSubmit) {
	alert("Por favor suba solamente archivos con la extensión:  " 
	  + (extArray.join("  ")) + "\nIntente nuevamente "
	  + "con otro archivo.");
	return false;
  } else {
    return true;
  }
}

function wordCounter(field, countfield, maxlimit) {
wordcounter=0;
for (x=0;x<field.value.length;x++) {
      if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
      if (wordcounter > 250) {field.value = field.value.substring(0, x);}
      else {countfield.value = maxlimit - wordcounter;}
      }
   }

function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
      else
      {countfield.value = maxlimit - field.value.length;}
  }

function checkEmail(field) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value)){
    return (true)
  }
  alert("Correo Inválido. Intente de nuevo")
  return (false)
}

function validateText(field) {
  var valid = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789-_$¨'%# .:,¿?¡!áéíóúÁÉÍÓÚúÜü()\r\c\n\t\";"
  var ok = "yes";
  var temp;
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  if (ok == "no") {
    alert("No se permiten caracteres extraños");
    field.focus();
    field.select();
  }
  return ok;
}

function validateConsonante(field) {
  var valid = "bcdfghjklmnñpqrstvwxyzBCDFGHJKLMNÑPQRSTVWXYZ"
  var ok = "yes";
  var temp;
  for (var i=0; i<3; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  if (ok == "yes") {
    alert("Se ha detectado que ha escrito una cadena de caracteres no válida\nPor favor, verifíquela");
    field.focus();
    field.select();
  }
  return ok;
}

function validate3Num(field) {
  var valid = "0123456789"
  var ok = "yes";
  var temp;
  for (var i=0; i<3; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  if (ok == "yes") {
    alert("Se ha detectado que ha escrito una cadena de números no válida en este campo\nPor favor, verifíquela");
    field.focus();
    field.select();
  }
  return ok;
}

function validateNum(field) {
  var valid = "0123456789"
  var ok = "yes";
  var temp;
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  if (ok == "no") {
    alert("Solo se permite utilizar números");
    field.focus();
    field.select();
  }
  return ok;
}

function validateTel(field) {
  var valid = "0123456789()- "
  var ok = "yes";
  var temp;
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  if (ok == "no") {
    alert("Solo se permite utilizar números, paréntesis, guiones o espacio en blanco");
    field.focus();
    field.select();
  }
  return ok;
}

function grosery(this_field) {
  var palabrotas = "puto,pito,puta,cabrón,cabron,culero,culo,oyito,ollito,putito,jotito,culito,putita,joto,verga,vergita,vergudo,puñal,pucha,panocha,panochita,vagina,pelos,oyitochiquito,miputito,chingar,chingón,chingon,chingonera,chingoneria,huevo,huevos,huevón,huevon,pene,fundillo,fundillón,fundillon,fundillito,pendejo,pendejeando,pendejito,culiar,follada,culear,pedorro,chingadera,chingaderita,falo,pedote,pedito,maricón,maricon,mariconsito,marica,cola,colita,colota,trasero,traserito,traserote,nachas,misnachas,nachitas,nachotas,ano,anón,anin,anito,anote,culote,pinche,buey,guey,baboso,babosa,culiadora,culeador,cojer,cojida,cojidona,teta,tetita,tetona,chichi,chichona,pezón,pezon,mariquita,mierda,caca,pedo,moco,gargajo,enculada,putazo,chiludo,cagar,cagado,enculado,bueyes";
  var fullStr = this_field.value + " ";
  fullStr = fullStr.toLowerCase();
  var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
  var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
  var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
  var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
  var splitString = cleanedStr.split(" ");
  var palabrotasString = palabrotas.split(",");
  var word_count = splitString.length -1;
  var respuesta = "no";
  for (x = 0; x <= splitString.length -2; x++) {
    for (y = 0; y <= palabrotasString.length-1; y++) {
	  if (palabrotasString[y] == splitString[x]) {
        respuesta = "si";
	  }
	}
  }
  return respuesta;
}

function checkRadios() {
 var el = document.forms[0].elements;
 for(var i = 0 ; i < el.length ; ++i) {
  if(el[i].type == "radio") {
   var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   var itemchecked = false;
   for(var j = 0 ; j < radiogroup.length ; ++j) {
    if(radiogroup[j].checked) {
	 itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
    alert("Please choose an answer for "+el[i].name+".");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
 }
 return true;
} 


<!--
//	Add or remove characters to 'alphabet' in the same way as shown.
//	Any characters not in alphabet will be ignored when encrypting.
alphabet = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','á','é','í','ó','ú','Á','É','Í','Ó','Ú','(',')','~','!','@','#','$','%','^','&','*','-','=','+','_','.',',','`','{','}','[',']','|','\'','\\','\"','/','?',':',';','>','<',' ','\n');

//	Temporary array for when producing binary numbers. Longer length = better encryption.
//	Note:	the max binary number must be more than the alphabet length.
//		there must be an 'a' at the end of the array.
tempbin = new Array("0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","a");

//	Binary numbers stored here and refer to original alphabet.
binary = new Array();

//	Variables for the jumbled(encrypted) alphabet, decrypted text, and encrypted text.
var encalphabet;
var decrypted;
var encrypted;

//	function to make the binary numbers
//	l = current position
//	len = binary number length
//	z = current number
//	The rest is straight forward - figure it out for your self.

function makebinary(l,start,z) {
	if (l < 0)
		return;
	if (tempbin[l] == "1") {
		tempbin[l] = "0";
		x = makebinary(l-1,start,z);
	}else if (tempbin[l] == "0"){
		tempbin[l] = "1";
	}else if (tempbin[l] == "a"){
		tempbin[l] = "0";
	}

	if (l == start) {
		binary[z] = "";
		for (i = 0; i <= l; i++)
			binary[z] += tempbin[i];
	}
	return;
}


//	Calls makebinary() to make enough numbers for all of alphabet.
for (z = 0; z < alphabet.length; z++) {
	makebinary(tempbin.length-1,tempbin.length-1,z);
}

//	Checks to see if a letter (alphabet[x]) is in encalphabet so there are no duplicates in encalphabet.
function in_encalphabet(x) {
	if (x == -1)
		return 0;

	z = alphabet[x];

	for (i = 0; i < encalphabet.length; i++) {
		if (z == encalphabet.substr(i,1))
			return 0;
	}
	return 1;
}



//	Encrypt function (well duh!!)
function encrypt(text) {
//	Set start values
	//decrypted = document.enc_form.decrypted.value;
	decrypted = text;
	encalphabet = "";
	encrypted = "";

//	Make encalphabet (ie. jumble alphabet)
	for (i = 0; i < alphabet.length; i++) {
		x = -1;
		while (in_encalphabet(x) == 0)
			x = Math.floor(alphabet.length*Math.random());

		encalphabet += alphabet[x];
	}

	temp = encalphabet;

//	First level of encryption.
//	Uses encalphabet's order to jumble text.
	for (i = 0; i < decrypted.length; i++) {
		for (z = 0; z < encalphabet.length; z++) {
			if (decrypted.substr(i,1) == alphabet[z]) {
				temp += encalphabet.substr(z,1);
				break;
			}
		}
	}

//	Second level of encryption.
//	Sets everything into binary.
	for (i = 0; i < temp.length; i++) {
		for (z = 0; z < alphabet.length; z++) {
			if (temp.substr(i,1) == alphabet[z]) {
				encrypted += binary[z];
				break;
			}
		}
	}

//	Display encrypted text.
	//document.enc_form.encrypted.value = encrypted;
}

//	This is obviously the decryption function.

function decrypt(text) {
//	Set initial values.
	//encrypted = document.enc_form.encrypted.value;
	encrypted = text;

	encalphabet = "";
	temp = "";
	decrypted = "";

//	Go from binary to first level encryption (ie. Still jumbled).
	for (i = 0; i < encrypted.length; i+=tempbin.length) {
		for (z = 0; z < alphabet.length; z++) {
			if (encrypted.substr(i,tempbin.length) == binary[z]) {
				temp += alphabet[z];
				break;
			}
		}
	}

//	Set the order of the alphabet (into encalphabet) from jumbled text.
	for (i = 0; i < alphabet.length; i++)
		encalphabet += temp.substr(i,1);

//	Unjumble the text.
	while (i < encrypted.length) {
		for (z = 0; z < encalphabet.length; z++) {
			if (temp.substr(i,1) == encalphabet.substr(z,1)) {
				decrypted += alphabet[z];
				break;
			}
		}
		i++;
	}

//	Display the decrypted text.
	//document.enc_form.decrypted.value = decrypted;
}


function capsLc(text){
  if (navigator.appVersion.substring(0,1)=="2"){
    navOld(text);
  }
    else navNew(text);
}

function navOld(Ntext){
  txt=Ntext.value+" ";
  txt=txt.toLowerCase();
  txtl="";
  while ((txt.length>0)&&(txt.indexOf(" ")>-1)){
    pos=txt.indexOf(" ");
    wrd=txt.substring(0,pos);
    cmp=" "+wrd+" ";
    if (tst.indexOf(cmp)<0){
      ltr=wrd.substring(0,1);
      ltr=ltr.toUpperCase();
      wrd=ltr+wrd.substring(1,wrd.length);
    }
    txtl+=wrd+" "; 
    txt=txt.substring((pos+1),txt.length);
  }
  ltr=txtl.substring(0,1);
  ltr=ltr.toUpperCase();
  txtl=ltr+txtl.substring(1,txtl.length-1);
  Ntext.value=txtl;
}

function navNew(Ntext){
  txt=Ntext.value+" ";
  txt=txt.toLowerCase();
  txtl="";
  punc=",.?!:;)'";
  punc+='"';
    while ((txt.length>0)&&(txt.indexOf(" ")>-1)){
      pos=txt.indexOf(" ");
      wrd=txt.substring(0,pos);
      wrdpre="";
      if (punc.indexOf(wrd.substring(0,1))>-1){
	wrdpre=wrd.substring(0,1);
	wrd=wrd.substring(1,wrd.length);
      }
      cmp=" "+wrd+" ";
      for (var i=0;i<9;i++){
	p=wrd.indexOf(punc.substring(i,i+1));
	if (p==wrd.length-1){
	  cmp=" "+wrd.substring(0,wrd.length-1)+" ";
	  i=9;
	}
      }
      if (cmp.indexOf(cmp)<0){
        ltr=wrd.substring(0,1);
        ltr=ltr.toUpperCase();
        wrd=ltr+wrd.substring(1,wrd.length);
      }
      txtl+=wrdpre+wrd+" "; 
      txt=txt.substring((pos+1),txt.length);
    }
  ltr=txtl.substring(0,1);
  ltr=ltr.toUpperCase();
  txtl=ltr+txtl.substring(1,txtl.length-1);
  Ntext.value=txtl;
}


function remove_XS_whitespace(item)

{

  item.value = item.value.replace(/\r/g, " ");

  //There are regex switchs for printing /nonprinting characters 

  //but they stripped some characters either needed or left some not wanted,

  //thats why the following replacement exists.

  //item.value = item.value.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");

  item.value = item.value.replace(/'/g, "");

  item.value = item.value.replace(/ +/g, " ");  
	
  item.value = item.value.replace(/^\s/g, "");

  item.value = item.value.replace(/\s$/g, "");	


  if (item.value == ' '){item.value = ''};

}


function ToggleCheckAll( state ) {
        var f = document.form1.elements;
        for (var ii=0; ii < document.form1.elements.length; ii++) {
                if (state == 'true')
                        document.form1.elements[ii].checked = true;
                else
                        document.form1.elements[ii].checked = false;
        }
        return false;
}


