// JavaScript Document
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function PonerRojo(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="red";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
if (NombreCampo=="Email"){
  if (!nombre.value) alert("El campo "+NombreCampo+" esta vacio");
  else alert("Direccion de Email invalida");
} else if (NombreCampo=="Sexo" || NombreCampo=="Pais") {
  alert("Debe elegir una opcion del campo de seleccion "+NombreCampo);
} else {
  alert("El campo "+NombreCampo+" esta vacio");
}
nombre.focus();
}

function PonerRojoNOJS(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="red";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
nombre.focus();
}

function Normalizar(iD){
// var nombre = document.getElementById(iD);
// var nombre = iD;
iD.style.borderColor="";
iD.style.borderStyle="";
iD.style.borderWidth="";
}
//
//
// Validador de la Contacto
//
//
function Validar_contacto(){
  var empresa = document.getElementById("idempresa");
  var nombre = document.getElementById("idnombre");
  var telefono = document.getElementById("idtelefono");
  var email = document.getElementById("idemail");
  var comentarios = document.getElementById("idcomentarios");

Normalizar(empresa);
Normalizar(nombre);
Normalizar(telefono);
Normalizar(email);
Normalizar(comentarios);
  if (!empresa.value){
    PonerRojo('idempresa','Empresa');
    return false;
  }
  if (!nombre.value){
    PonerRojo('idnombre','Nombre');
    return false;
  }
  if (!telefono.value){
    PonerRojo('idtelefono','Telefono');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','email');
    return false;
  }
  if (!comentarios.value){
    PonerRojo('idcomentarios','Comentario');
    return false;
  }
}
// Valores
var valor1=120; // plan basico, Semestral
var valor2=240; // plan basico, Anual
var valor3=180; // plan avanzado, Semestral
var valor4=360; // plan avanzado, Anual

//Valores del contrato
// Plan Basico
function servicios_basico() {
	document.getElementById('idpago').disabled="";
	document.getElementById('idpago1').disabled="";
	document.getElementById('idamedida').value="";
	document.getElementById('idamedida').disabled="disabled";
	document.getElementById('idamedida').style.background="#F7F7F7";
	document.getElementById('idamedida').style.borderColor="#EEEEEE";
	document.getElementById('idplan_a').checked=0; 	
	document.getElementById('idplan_m').checked=0; 	
 	if (document.getElementById('idpago').checked) 
  {
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor').value=valor1;
	document.getElementById('idvalor_enviado').value=valor1;
	document.getElementById('idvalor').disabled="disabled";	  
  } 
   	if (document.getElementById('idpago1').checked)
  {
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor_enviado').value=valor2;
	document.getElementById('idvalor').value=valor2;
	document.getElementById('idvalor').disabled="disabled";
  }
}
// Plan Avanzado
function servicios_avanzado() {
	document.getElementById('idpago').disabled="";
	document.getElementById('idpago1').disabled="";
	document.getElementById('idamedida').value="";
	document.getElementById('idamedida').disabled="disabled";
	document.getElementById('idamedida').style.background="#F7F7F7";
	document.getElementById('idamedida').style.borderColor="#EEEEEE";
	document.getElementById('idplan_b').checked=0;
	document.getElementById('idplan_m').checked=0;
	if (document.getElementById('idpago').checked) 
  {
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor_enviado').value=valor3;
	document.getElementById('idvalor').value=valor3;
	document.getElementById('idvalor').disabled="disabled";	  
  } else {
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor_enviado').value=valor4;
	document.getElementById('idvalor').value=valor4;
	document.getElementById('idvalor').disabled="disabled";
	}
}
// Plan a Medida
function servicios_amedida() {
	document.getElementById('idplan_b').checked=0; 	
	document.getElementById('idplan_a').checked=0;
	document.getElementById('idvalor_enviado').value="Consultar";
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor').value="Plan a Medida";
	document.getElementById('idvalor').disabled="disabled";	  
	document.getElementById('idamedida').disabled="";
	document.getElementById('idpago').disabled="disabled";
	document.getElementById('idpago1').disabled="disabled";
	document.getElementById('idamedida').style.background="#EEEEEE";
	document.getElementById('idamedida').style.borderColor="#CCCCCC";
}
// Semestral
function servicios_semestral() {
 	  if (document.getElementById('idplan_b').checked) 
  {
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor_enviado').value=valor1;
	document.getElementById('idvalor').value=valor1;
	document.getElementById('idvalor').disabled="disabled";	  
  } 
 	  if (document.getElementById('idplan_a').checked)
  {
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor_enviado').value=valor3;
	document.getElementById('idvalor').value=valor3;
	document.getElementById('idvalor').disabled="disabled";	  
  }
}
function servicios_anual() {
 	  if (document.getElementById('idplan_b').checked) 
  {
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor_enviado').value=valor2;
	document.getElementById('idvalor').value=valor2;
	document.getElementById('idvalor').disabled="disabled";	  
  } 
 	  if (document.getElementById('idplan_a').checked)
  {
	document.getElementById('idvalor').disabled="";
	document.getElementById('idvalor_enviado').value=valor4;
	document.getElementById('idvalor').value=valor4;
	document.getElementById('idvalor').disabled="disabled";	  
  }
}
//
//
// Validador de la Contratar
//
//
function Validar_contratar(){

// Solicitante
  var nombre = document.getElementById("idnombre");
  var fecha = document.getElementById("idfecha");
  var tipo = document.getElementById("idtipo");
  var numero = document.getElementById("idnumero");
  var telefono = document.getElementById("idtelefono");
  var email = document.getElementById("idemail");
// Servicio
  var dominio = document.getElementById("iddominio");
// Facturacion
  var empresa = document.getElementById("idempresa");
  var direccion = document.getElementById("iddireccion");
  var localidad = document.getElementById("idlocalidad");
  var provincia = document.getElementById("idprovincia");
  var cp = document.getElementById("idcp");
  var telefono2 = document.getElementById("idtelefono2");
  var tipo2 = document.getElementById("idtipo2");
  var numero2 = document.getElementById("idnumero2");
  var condicioniva = document.getElementById("idcondicioniva");
  var terminos = document.getElementById("idterminos");

// Solicitante
Normalizar(nombre);
Normalizar(fecha);
Normalizar(tipo);
Normalizar(numero);
Normalizar(telefono);
Normalizar(email);
// Servicio
Normalizar(dominio);
// Facturacion
Normalizar(empresa);
Normalizar(direccion);
Normalizar(localidad);
Normalizar(provincia);
Normalizar(cp);
Normalizar(telefono2);
Normalizar(tipo2);
Normalizar(numero2);
Normalizar(condicioniva);
Normalizar(terminos);
// Solicitante
  if (!nombre.value){
    PonerRojo('idnombre','Nombre y Apellido');
    return false;
  }
    if (!fecha.value){
    PonerRojo('idfecha','Fecha de Nacimiento');
    return false;
  }
  if (tipo.value=="0"){
    PonerRojo('idtipo','Tipo de Documento');
    return false;
  }
  if (!telefono.value){
    PonerRojo('idtelefono','Telefono');
    return false;
  }
  if (!numero.value){
    PonerRojo('idnumero','Numero de Documento');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','email');
    return false;
  }
  // Servicio
  if (!dominio.value){
    PonerRojo('iddominio','Dominio');
    return false;
  }
  // Facturacion
  if (!empresa.value){
    PonerRojo('idempresa','Nombre o Razón Social');
    return false;
  }
    if (!direccion.value){
    PonerRojo('iddireccion','Dirección');
    return false;
  }
    if (!localidad.value){
    PonerRojo('idlocalidad','Localidad');
    return false;
  }
    if (!provincia.value){
    PonerRojo('idprovincia','Provincia');
    return false;
  }
    if (!direccion.value){
    PonerRojo('iddireccion','Dirección');
    return false;
  }
    if (!cp.value){
    PonerRojo('idcp','cp');
    return false;
  }
    if (!telefono2.value){
    PonerRojo('idtelefono2','Teléfono de la empresa');
    return false;
  }
  if (tipo2.value=="0"){
    PonerRojo('idtipo2','CUIT - CUIL');
    return false;
  }
  if (!numero2.value){
    PonerRojo('idnumero2','Numero de CUIT - CUIL');
    return false;
  }
  if (condicioniva.value=="0"){
    PonerRojo('idcondicioniva','IVA');
    return false;
  }
  if (!terminos.checked){
    alert ("Para contratar el servicio de Hosting\nDeberá Aceptar los Terminios y Condiciones");
    return false;
  }
}
