function openForm(url,name) {
        window.open(url,name,'left=20,top=20,width=580,height=630,toolbar=no,resizable=no,scrollbar=yes');
}


function changeImage(element,path,img,action) {
	if (action == 'in') {
		element.src = path + "/images/" + img + "_2.gif";
	} else element.src = path + "/images/" + img + "_1.gif";
}

function openTargetBlank(e){
   
   var className = 'external';
   
   if (!e) var e = window.event;
   var clickedObj = e.target ? e.target : e.srcElement;
   
   if(clickedObj.nodeName == 'A' )
    {
      r=new RegExp("(^| )"+className+"($| )");
      if(r.test(clickedObj.className)){
         window.open(clickedObj.href);
         return false;
   
      }
    }
}
   
function osDetect() {
  if(navigator.platform.indexOf("Win") != -1) {
    return "Windows";
  }
  if(navigator.platform.indexOf("Mac") != -1) {
    return "Mac";
  }
  if(navigator.platform.indexOf("Linux") != -1) {
    return "Linux";
  }
  return "Desconocido";
}

function browserDetect() {
  if(navigator.userAgent.indexOf("MSIE") != -1) {
    return "Explorer";
  }
  if(navigator.vendor.indexOf("Apple") != -1) {
    return "Safari";
  }
  if(navigator.vendor.indexOf("KDE") != -1) {
    return "Konqueror";
  }
  if(navigator.userAgent.indexOf("Firefox") != -1) {
    return "Firefox";
  }
  if(navigator.userAgent.indexOf("Gecko") != -1) {
    return "Mozilla";
  }
  if(navigator.userAgent.indexOf("Netscape") != -1 || navigator.userAgent.indexOf("Mozilla") != -1) {
    return "Netscape";
  }
  return "Desconocido";
}

function writeElement(id, text) {
  if (document.getElementById) {
    element = document.getElementById(id);
    element.innerHTML = '';
    element.innerHTML = text;
  } else if (document.all) {
    element = document.all[id];
    element.innerHTML = text;
  } else if (document.layers) {
    element = document.layers[id];
    text_alt = "<p>" + text + "</p>";
    element.document.open();
    element.document.write(text2);
    element.document.close();
  }
}

function videoObject(browser) {
  var text = "";
  if(browser == "Explorer") {
    text = "<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\"320\" height=\"260\">";
    text += "video","  <param name=\"src\" value=\"rtsp://rtsp.whitebearsolutions.com/default/diving_buceo_256kbps.mp4\"/>";
    text += "video","<param name=\"controller\" value=\"true\"/>";
    text += "<param name=\"autoplay\" value=\"true\"/>";
    text += "<param name=\"loop\" value=\"false\"/>";
    text += "</object>";
  } else {
    text = "<object type=\"video/quicktime\" pluginspage=\"http://www.apple.com/quicktime/download/\" src=\"rtsp://rtsp.whitebearsolutions.com/default/diving_buceo_256kbps.mp4\" width=\"320\" height=\"260\" autoplay=\"true\" controller=\"true\" loop=\"false\">";
    text += "</object>";
  }
  writeElement("video", text);
}

/*************** Validación de Formularios **************/


function validateFields () {
  var opcionElegida = false;
  for (var i=0;i<14;i++) {
    if (document.getElementById('CSECTOR'+i).checked)
       opcionElegida=true;
  }
  if ((document.getElementById('email').value=='')||(document.getElementById('nombre').value=='')||(document.getElementById('apellidos').value=='')) {
    alert("Los campos marcados con el símbolo * son obligatorios");
  }
  else {
    if (!opcionElegida) {
      alert("Debe seleccionar al menos un sector");
    }
    else {
      if ((document.getElementById('telfijo').value != '')&&(document.getElementById('telfijo').value.length<9)) {
        alert("El teléfono debe tener al menos 9 dígitos");
      } else {
          if (!EsNumero(document.getElementById('telfijo').value)) {
            alert("El teléfono sólo puede contener números");
          }
	  else {
	    if ((document.getElementById('telmovil').value != '')&&(document.getElementById('telmovil').value.length<9)) {
	      alert("El teléfono debe tener al menos 9 dígitos");
	    }
	    else {
	      if (!EsNumero(document.getElementById('telmovil').value)) {
	        alert("El teléfono sólo puede contener números");
	      }
	      else {
	        if ((document.getElementById('cpostal').value != '')&&(document.getElementById('cpostal').value.length<5)) {
		  alert("El código postal debe tener al menos 5 dígitos");
	        }
	        else {
		  if (!EsNumero(document.getElementById('cpostal').value)) {
              	    alert("El código postal sólo puede contener números");
            	  }
		  else {
		    if ((document.getElementById('email').value != '')&&((!containChar(document.getElementById('email').value)) || (!containArroba(document.getElementById('email').value)))) {
		      alert("La dirección de correo es inválida");
		    }
		    else {
		      if (jcap())
		        document.somaForm.submit();
		    }
		  }
	        }
	      }
	    }
	  }
      }
    }
  }
}

function EsNumero(strValor) {
  for (var i=0; i < strValor.length; i++)
    {
    if (strValor.charAt(i) < '0' || strValor.charAt(i) > '9')
      return false;
    }
  return true;
}

function containChar(strValor) {
  var j=0;
  for (var i=0; i < strValor.length; i++) {
    if (strValor.charAt(i) == '.')
      j++;
  }
  if (j>=1)
    return true;
  return false;
}


function containArroba(strValor) {
  var j=0;
  for (var i=0; i < strValor.length; i++) {
    if (strValor.charAt(i) == '@')
      j++;
  }
  if (j==1)
    return true;
  return false;
}

function activarChecks(option) {
	if (document.getElementById('CSECTOR'+option).checked) {
	   document.getElementById('CCOMPRA'+option).checked=true;
	   document.getElementById('CVENTA'+option).checked=true;
	}
	else {
	   document.getElementById('CCOMPRA'+option).checked=false;
	   document.getElementById('CVENTA'+option).checked=false;
	}
}

function desactivarChecks(option) {
	if (!(document.getElementById('CCOMPRA'+option).checked)&&!(document.getElementById('CVENTA'+option).checked)) {
	   document.getElementById('CSECTOR'+option).checked=false;
	}
	else {
	   document.getElementById('CSECTOR'+option).checked=true; 
	}
}

function validateOption() {
	if (document.getElementById('formapago').value == "Domiciliacion bancaria") 
	   document.getElementById('domiciliacion').disabled = false;
	else
	   document.getElementById('domiciliacion').disabled = true;
}

function validateFieldsSuscript () {
  if ((document.getElementById('email').value=='')||(document.getElementById('nombre').value=='')||(document.getElementById('apellidos').value=='')||(document.getElementById('cifnif').value=='')) {
    alert("Los campos marcados con el símbolo * son obligatorios");
  }
  else {
    if ((document.getElementById('telefono').value != '')&&(document.getElementById('telefono').value.length<9)) {
      alert("El teléfono debe tener al menos 9 dígitos");
    } 
    else {
      if (!EsNumero(document.getElementById('telefono').value)) {
        alert("El teléfono sólo puede contener números");
      }
      else {
	if ((document.getElementById('cifnif').value.length<9))
	  alert("El DNI tiene que tener un tamaño de 9 caracteres");
	else {
	  if ((document.getElementById('email').value != '')&&((!containChar(document.getElementById('email').value)) || (!containArroba(document.getElementById('email').value))))
             alert("La dirección de correo es inválida");
	  else {
	    if (jcap())
	      document.cotizForm.submit();
	  }
	}
      }
    }
  }
}

