// JavaScript Document
function valextend(campo){
	var val1=new String(campo.value);
	var extension=val1.substring(val1.lastIndexOf(".")+1,val1.length);
	if(extension=="pgn")
	{
		document.form.submit();	
	}
	else
	{
	alert("el archivo debe ser tipo pgn")
	campo.focus();
	}
}
function validate_int(campo)
{
	if(campo.value.length == 0)
  	{
    alert("no se permite este campo vacio");
	return (campo.value);
	}
	if(isNaN(campo.value))
	{
    	alert("Debe digitar un valor numérico ");
      	campo.focus();
      	return (campo.value="");
	}
	else
	{
		document.form.submit();
	}
}

function validate_string(campo)
{
  if(campo.value.length == 0)
  {
    alert("no se permite este campo vacio");
	campo.focus();
  }
  else
  {
  	document.form.submit();
  }
}

function validate_date(campo)
{
  var meses = new Array("\0","Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
  var diasmes = new Array(0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  var ver;
  if(campo.value.length < 8 || isNaN(campo.value))
  {
    alert("La fecha ingresada es incorrecta");
	
    return (false);
  }
  var ano = Math.round(campo.value/10000);
  var mes = Math.round((campo.value-(ano)*10000)/100);
  var dia = Math.round(campo.value-10000*(ano)-100*(mes));
  var diax = diasmes[mes];
  ver=0;
  if(dia == 29 && mes == 2 && dia<30)
    if ((ano%4) != 0)
	{
      alert("Fecha incorrecta el año "+ano+" no es bisiesto");
      ver = 1;
      return(campo.value="");
	}
    else
	{
      return (campo.value="");
	}
    if(mes>12)
	{
      alert("Un año solo tiene 12 meses");
      return(campo.value);
	}
    if(dia != diax && dia > diax && ver == 0)
	{
      alert("El mes de "+meses[mes]+" solo tiene "+diax+" dias ");
  	  return(campo.value);
	}
  return (campo.value);
}

function validate_date_actual(campo)
{
	var meses = new Array("\0","Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
  	var diasmes = new Array(0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  	var ver;
	now = new Date();
	d = now.getDate();
	m = now.getMonth();
	h = now.getTime();
	y = now.getYear();
	if(campo.value.length < 8 || isNaN(campo.value))
  	{
    alert("La fecha ingresada es incorrecta");
	campo.focus();
	return (false);
  	}
	if(d<10)
	{
		d="0"+d;
	}
	if(m<10)
	{
	 	m="0"+m;
	}
  cdate=y+m+d;
  if(parseInt(campo.value)<cdate)
    {
    alert("La fecha ingresada debe ser mayor a la actual "+cdate);
	return (false);
  }
 var ano = Math.round(campo.value/10000);
  var mes = Math.round((campo.value-(ano)*10000)/100);
  var dia = Math.round(campo.value-10000*(ano)-100*(mes));
  var diax = diasmes[mes];
  ver=0;
  if(dia == 29 && mes == 2 && dia<30)
    if ((ano%4) != 0)
	{
      alert("Fecha incorrecta el año "+ano+" no es bisiesto");
      ver = 1;
	  return(false);
	 }
    else
	{
      return (campo.value);
	}
    if(mes>12)
	{
      alert("Un año solo tiene 12 meses");
	  return(false);
	}
    if(dia != diax && dia > diax && ver == 0)
	{
      alert("El mes de "+meses[mes]+" solo tiene "+diax+" dias ");
	  return(false);
	}
  return (campo.value);
}

function validate_char(campo)
{
  if(campo.value.length == 0)
  {
    alert("no se permite este campo vacio");
    campo.focus();
	return (campo.value);
  }
	 return (campo.value); 
}

function validate_email(campo)
{
 
                     if((campo.value.indexOf("@")==-1 ||
     campo.value.indexOf(".")==-1 ||
	 campo.value.indexOf(" ")!=-1 ||
	 campo.value.length < 6) && campo.value.length != 0)
  {
    alert("Direccion de correo es incorrecta");
	campo.focus();
 } 
}
function validar_contrasena(contranew, contragain)
{
  if(contranew.value != contragain.value)
  {
    contragain.value = "";
	contranew.focus();
  }
}

function validate_vacio(campo){
  if(campo.value.length == 0)
  {
    alert("Por favor llene todos los campos");
    campo.focus();
		return false;
  }
	return true;
	alert(campo.value);
}

function openAdmin(page,width,height){
	window.open(page,'Admin','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=495,height=500');
}
function openHelp(page,width,height){
	newWindow = window.open(page,'Help','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=400,height=300');
	newWindow.focus();
}
function repSel(fValue,myTxt,myRepTxt)
{
	fValue=fValue.replace(myTxt,myRepTxt);	
	return fValue;
}	
function ej_sel(label)
{
var myRange = document.selection.createRange();
myTextRange = document.form.p_text.createTextRange();
myTextRange = myRange;
var myText = myTextRange.text;
var myTextReplace="<" + label + ">" + myText + "</" + label + ">";
document.form.p_text.value=repSel(document.form.p_text.value,myText,myTextReplace);
//document.write(document.form1.textprueba.value);
}
function selValue(sel)
{
	ej_sel("font size="+sel.value+"");
}
function colorval(colorvalue)
{
 document.form.hidden_colortext.value = colorvalue;
 document.form.hidden_button_color.style.backgroundColor = colorvalue;
}
function colorval2(colorvalue)
{
 document.form.p_color.value = colorvalue;
 document.form.hidden_button_color1.style.backgroundColor = colorvalue;
}

//función para reemplazar los saltos de linea ingresados en le textarea con la etiqueta <br>
function n12br(str)
{
	str=str.replace(/\n/gi,"<br/>");
	return str;
}
//recibe el texto ingresado en el textarea y se lo pasa a n1br para ser reemplazado.
function reformat()
{
	document.form.p_text.value=n12br(document.form.p_text.value);
	document.form.submit();
}
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}
function setVisibility(objName,visiblility) 
{
	obj = findObj(objName);
    obj.style.visibility = visiblility;
}
function setColor(objName,bg)
{
  obj = findObj(objName);
  if (obj.style)
  {
    obj.style.backgroundColor = bg;
  }
}

function setValue(objName,value)
{
  obj = findObj(objName);
  obj.value = value;
}

function over(object,color)
{
	object.style.color = color;
}
function out(object)
{
	object.style.color = "";
}
function click_link(object,url)
{
	object.style.color = 'FFCC00';
	location.href=url;
}
function addcontent(advalue,object)
{
	object.value = advalue+object.value;
}
function changevis(check,object)
{
	obj = findObj(check);
	obj_vis = findObj(object);
	if(obj.checked)
	{
		obj_vis.style.display='';	
	}
	else
	{
		obj_vis.style.display='none';	
	}
}
function makeDir(cadena){
	var direccion = "http://www.google.com.br/search?q="+cadena;
	window.open(direccion, "Titulo");
}
	