// JavaScript Document
function ValidaURL(url){
var re = /^(http:|https:|ftp:)\/\/\w+(\.\w+)*(\-\w+)?\.\w{2,3}(\:\d{2,6})?(\/{1,2}(\:|\-|\w|\.|\?|\/|\=|\&|\%|\@|\\|\,)*)?$/
return re.test(url);
}

function vacio(q) { 
	for ( i = 0; i < q.length; i++ ) { 	
		if ( q.charAt(i) != " " ) {
		return true;
		}
	}
	return false;
}

function validar(F){
	
	 if( vacio(F.nombre.value) == false){
	  alert("Ingrese su NOMBRE.");
	  F.nombre.focus();
	  return false;
	 }	 
	 if (vacio(F.telefono.value) == false){
	  alert("Ingrese su Nro. de TELEFONO.");
	  F.telefono.focus();
	  return false;
	 }
	 if (vacio(F.email.value) == false){
	  alert("Ingrese su EMAIL.");
	  F.email.focus();
	  return false;
	 }
	 var er_email = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	 if(!er_email.test(F.email.value)) {    
	  alert("Contenido del campo E-MAIL no valido.")
	  F.email.focus();
	  return false;
	 } 
	 if (F.diseno.value==0){
	  alert("Seleccione su tipo de DISENO.");
	  F.diseno.focus();
	  return false;
	 } 
	 if (vacio(F.clink.value) == false){
	  alert("Ingrese la cantidad de link.");
	  F.clink.focus();
	  return false;
	 }
	 if (vacio(F.ilink.value) == false){
	  alert("Ingrese la cantidad de imagenes por link.");
	  F.ilink.focus();
	  return false;
	 }	 
	 if(F.check1.checked == true){
		if (!ValidaURL (F.url1.value) ){
		alert("La direccion URL es Incorrecta");
		F.url1.focus();
		return false;
		} 
	 }
	 if(F.check2.checked == true){
		if (!ValidaURL (F.url2.value) ){
		alert("La direccion URL es Incorrecta");
		F.url2.focus();
		return false;
		} 
	 }  
	 if (vacio(F.uword.value) == false){
	  alert("Ingrese el CODIGO visualizado.");
	  F.uword.focus();
	  return false;
	 }  
	 else{
		 var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ\" + \"abcdefghijklmnñopqrstuvwxyzáéíóú\"";
		 var checkStr = form1.name.value;
		 var allValid = true;
		 var uword = hex_md5(document.getElementById('uword').value);
	  
		 for (i = 0; i < checkStr.length; i++) {
			  ch = checkStr.charAt(i);
			  for (j = 0; j < checkOK.length; j++)
				  if (ch == checkOK.charAt(j))
					  break;
				  if (j == checkOK.length) {
					  allValid = false;
					  break;}  
		 }
		   
		 if (!allValid) {
			  alert("inserte el nombre");
			  form1.name.focus();
			  return false;
		 }   
		   
		 if (uword==cword[anum-1]) {
			  return true;}
		 else {
			 alert("Codigo de imagen INCORRECTO, si no logra ver la imagen presione la tecla F5");
			 document.getElementById('uword').focus();
			 return false;}   
	  } 
	
	 
 return true;
}

function num_telf(evento){
// Algunos caracteres: backspace = 8, enter = 13, '0' = 48, '9' = 57, '-' = 45
  var nav4 = window.Event ? true : false;
  var key = nav4 ? evento.which : evento.keyCode;
  return (key <= 13 || (key >= 48 && key <= 57) || key == 45);	
}

function solo_num(evento){
// Algunos caracteres: backspace = 8, enter = 13, '0' = 48, '9' = 57
  var nav4 = window.Event ? true : false;
  var key = nav4 ? evento.which : evento.keyCode;
  return (key <= 13 || (key >= 48 && key <= 57));	
}

function buscar() {  
    var p = "href"
	var texto = document.form1.detalle.value;		
	var patron = new RegExp('('+p+')','gi'); 
		
	textoNuevo = texto.replace(patron,' * XXXXX * ');  
	document.form1.detalle.value = textoNuevo; 	
	
	if ( texto!=textoNuevo ) {  
	alert("EL SIGNO ' href ' NO ES ADMITIDO EN ESTA AREA");	
	document.form1.detalle.focus();	
	}   
}

function referencia(variable){

if(variable == "bien"){
   alert("Su solicitud fue enviado correctamente");  
   var pagina="http://www.inkawebdesign.com/diseno.html"
   location.href=pagina 
   setTimeout ("location.href=pagina", 1000);   
}
if(variable == "mal"){
   alert("Hubo un error en el envio, Intentelo nuevamente");
   history.back();
   return false;
}
return true;
}
