function validate_add_profile(theForm)
{
	if (!validRequired(theForm.nombre, "Name"))
		return false;
	
	return true;
}

function validate_userinfo(theForm)
{
	if (!validRequired(theForm.nombre, "Name"))
		return false;
		
	if (!validEmail(theForm.email, "E-mail", true))
		return false;
	
	if (!validRequired(theForm.login, "Login"))
		return false;
		
	if(!validRequired(theForm.contrasena, "Password"))
		return false;
	
	if(!validRequired(theForm.contrasena2, "Confirm Password"))
		return false;
		
	if(theForm.contrasena.value != theForm.contrasena2.value){
		alert("Confirm New Password");
		return false;
	}
	
	if (theForm.perfil.value == ''){ 
       alert("It must select a permission") 
       theForm.perfil.focus() 
       return false; 
	} 
	
    return true;
}

function validate_update_userinfo(theForm)
{
	if (!validRequired(theForm.nombre, "Name"))
		return false;
		
	if (!validEmail(theForm.email, "E-mail", true))
		return false;
	
	if (!validRequired(theForm.login, "Login"))
		return false;
	
	if(theForm.antigua_contrasena.value != ''){
		if(!validRequired(theForm.nueva_contrasena, "New Password"))
			return false;
		
		if(!validRequired(theForm.nueva_contrasena2, "Confirm Password"))
			return false;
		
		if(theForm.nueva_contrasena.value != theForm.nueva_contrasena2.value){
			alert("Confirm new Passworda");
			return false;
		}		
	}
	
	if (theForm.perfil.value == ''){ 
       alert("It must select a permission") 
       theForm.perfil.focus() 
       return false; 
	} 
	
    return true;
}

function validate_contact(theForm){	
	if (!validRequired(theForm.nombre, "Name"))
		return false;
		
	if (!validEmail(theForm.email, "E-mail", true))
 		return false;

    if (!validRequired(theForm.pais, "Country"))
		return false;
	
	if (!validarImagenes(theForm.ciudad, "City"))
		return false;
	
	if (!validRequired(theForm.empresa, "Company"))
 		return false;		
		
    return true;
}

function abrirgrande(imagen,ancho,alto){
	var anch=ancho;
	var alt=alto;
	var top = (screen.availHeight/2) - (alt/2);
	var left = (screen.availWidth/2) - (anch/2);
	abrir=window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,left='+ left +',top='+ top +',width='+ anch +',height='+ alt);
	abrir.focus();
	abrir.document.writeln("<html>");
	abrir.document.writeln("<body leftmargin='0' topmargin='0' onblur='this.focus();'>");
	abrir.document.writeln("<div style='text-align:center; min-height: 10em; display: table-cell; vertical-align: middle'><img src='thumbgenerator.php?image="+ imagen +"&w="+ancho+"&h="+alto+"'></div></body></html>");	
	abrir.document.close();
	abrir.document.title = "Image Viewer";
}

function abrirFoto(imagen,ancho,alto){
	var anch=ancho;
	var alt=alto;
	var top = (screen.availHeight/2) - (alt/2);
	var left = (screen.availWidth/2) - (anch/2);
	abrir=window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,left='+ left +',top='+ top +',width='+ anch +',height='+ alt);
	abrir.focus();
	abrir.document.writeln("<html>");
	abrir.document.writeln("<body leftmargin='0' topmargin='0' onblur='this.focus();'>");
	abrir.document.writeln("<div style='text-align:center; min-height: 10em; display: table-cell; vertical-align: middle'><img src='../admin/thumbgenerator.php?image="+ imagen +"&w="+ancho+"&h="+alto+"'></div></body></html>");	
	abrir.document.close();
	abrir.document.title = "Image Viewer";
}

function popnew(url,ancho,largo,status){
	x = (screen.width/2)-(ancho/2);
	y = (screen.height/2)-(largo/2);
	popup=window.open(url,"","width="+ancho+",height="+largo+",top="+y+",left="+x+",status="+status+",location=no,menu=no,scrollbars=no,toolbar=no");
	popup.focus();
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('"'+fieldLabel +'" field is required');
		formField.focus();
		result = false;
	}
	
	return result;
}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 2) || !isEmailAddr(formField.value)) )
	{
		alert("Invalid Email Address (check for user@domain.com format)");
		formField.focus();
		result = false;
	}
   
  return result;
}

function validarImagenes(campo, titu)
  {
	  var ext_arc = campo.value.substring(campo.value.lastIndexOf(".")+1);
	  
	  if (ext_arc == "jpg" || ext_arc == "JPG" || ext_arc == "gif" || ext_arc == "GIF")
	    {
			return true;
		}
	  else
	    {
			alert("Invalid image format on field \""+titu+"\", only \".jpg\" and \".gif\" are admited");
			return false;
		}
  }

function validate_login(theForm)
{
	if (!validRequired(theForm.login, "Login"))
		return false;
	
	if (!validRequired(theForm.password, "Password"))
		return false;
	
    return true;
}

function validate_userinfo(theForm)
{
	if (!validRequired(theForm.name, "Name"))
		return false;
		
	if (!validEmail(theForm.email, "Email", true))
		return false;
	
	if (!validRequired(theForm.login, "Login"))
		return false;
	
    return true;
}

function validate_changepass(theForm)
{
	if (!validRequired(theForm.old_password, "Old Password"))
		return false;
	
	if (!validRequired(theForm.new_password, "New Password"))
		return false;
		
	if (!validRequired(theForm.new_password2, "Confirm Password"))
		return false;
	
	if(theForm.new_password.value != theForm.new_password2.value){
		alert("Confirm new Password");
		return false;
	}
	
    return true;
}

function validate_bloque(theForm)
{	
	if(theForm.feat_image){
		if(theForm.feat_image.value != ""){
			if (!validarImagenes(theForm.feat_image, "Featured Image"))
			   return false;
		}
	}
	
    return true;
}

function validate_link(theForm){
	if(theForm.seccion.value == 0){
		alert("Please select a section for this link first");
		return false;
	}
	
	if (!validRequired(theForm.title, "Title"))
		return false;

    if (!validRequired(theForm.link_url, "Link"))
		return false;
	
    return true;
}

function validate_archivo(theForm){
	if(theForm.seccion.value == 0){
		alert("Please select a section for this file first");
		return false;
	}
	
	if (!validRequired(theForm.title, "Title"))
		return false;

    if (!validRequired(theForm.archivo, "File"))
		return false;
	
    return true;
}



function validate_archivo_edit(theForm){
	if(theForm.seccion.value == 0){
		alert("Please select a section for this file first");
		return false;
	}
	
	if (!validRequired(theForm.title, "Title"))
		return false;
	
    return true;
}


function validate_imagen(theForm){
	if(theForm.seccion.value == 0){
		alert("Please select a category for this image first");
		return false;
	}
	
	if (!validRequired(theForm.title, "Title"))
		return false;

    if (!validRequired(theForm.archivo, "Image"))
		return false;
	
	if (!validarImagenes(theForm.archivo, "Image"))
		return false;
	
    return true;
}

function validate_directorio_contactos(theForm){
	if(theForm.seccion.value == 0){
		alert("Please select a category for this image first");
		return false;
	}
	
	if (!validRequired(theForm.nombres, "Names"))
		return false;
		
	if (!validRequired(theForm.apellidos, "Last Names"))
		return false;

	if (!validEmail(theForm.email, "E-mail", true))
 		return false;
	
	if (!validRequired(theForm.celular, "Movil"))
 		return false;	
		
    return true;
}

function validate_directorio_empresas(theForm){
	if(theForm.seccion.value == 0){
		alert("Please select a category for this image first");
		return false;
	}
	
	if (!validRequired(theForm.nombre, "Name"))
		return false;
	
	if (!validRequired(theForm.telefono, "Telephono"))
 		return false;
	
	if (!validRequired(theForm.direccion, "Direccion"))
 		return false;
		
    return true;
}

function validate_directorio_edit_contactos(theForm){
	if(theForm.seccion.value == 0){
		alert("Please select a section for this file first");
		return false;
	}
	
	if (!validRequired(theForm.nombres, "Names"))
		return false;
		
	if (!validRequired(theForm.apellidos, "Last Names"))
		return false;

	if (!validEmail(theForm.email, "E-mail", true))
 		return false;
	
	if (!validRequired(theForm.telefono, "Telephono"))
 		return false;
	
	if (!validRequired(theForm.direccion, "Direccion"))
 		return false;
		
    return true;
}

function validate_faq(theForm){
	if (!validRequired(theForm.question, "Question"))
		return false;
	
	if (!validRequired(theForm.answer, "Answer"))
		return false;
	
    return true;
}

