//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext) {
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) { 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<param name="wmode" value="transparent" /><embed wmode="transparent" ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent() {
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent() {
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType) {
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function escribeCorreo(name, clase, br) {
	var domain = "mcvinvestigacion.com"; 
	document.write('<a class='+clase+' href=\"mailto:' + name + '@' + domain + '\">'); 
	document.write(name + '@' + domain + '</a>');
	if (br != '') {
		document.write('<br />');
	}
}

function validar(pos, camposObligatorios) {
	aMayusculas(pos);	
	for (i=0; i<camposObligatorios.length; i++) {
		var campo    = eval("document.forms[pos]."+camposObligatorios[i]);
		var newCampo = sustituye(camposObligatorios[i], '_', ' ');
		
		if (campo.value=="") {
			alert("El campo \""+newCampo +"\" es obligatorio");
			campo.focus();
			return;
		} // if
		
		// campos especiales
		if (camposObligatorios[i]=="email") {
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo.value))) {
				alert("El campo \""+newCampo +"\" es incorrecto");
				campo.focus();
				return;
			} // if
		} // if
		if (camposObligatorios[i]=="código_postal") {
			if (campo.value.length!=5 || isNaN(campo.value)) {
				alert("El campo \""+newCampo +"\" es incorrecto");
				campo.focus();
				return;
			} // if
		} // if
		if (campo.name.substring(0,5)=="fecha") {
			if (!isDate(eval("document.forms[pos]."+camposObligatorios[i]))) {
				alert("El campo \""+newCampo +"\" es incorrecto");
				campo.focus();
				return;
			} // if
		} // if
	} // for
	document.forms[pos].realname.value = document.forms[pos].nombre.value;
	document.forms[pos].submit();	
}

function esDigito(sChr){
	var sCod = sChr.charCodeAt(0);
	return ((sCod > 47) && (sCod < 58));
}

function valSep(oTxt){
	var bOk = false;
	bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-"));
	bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
	return bOk;
}

function finMes(oTxt){
	var nMes = parseInt(oTxt.value.substr(3, 2), 10);
	var nRes = 0;
	switch (nMes){
		case 1:  nRes = 31; break;
		case 2:  nRes = 29; break;
		case 3:  nRes = 31; break;
		case 4:  nRes = 30; break;
		case 5:  nRes = 31; break;
		case 6:  nRes = 30; break;
		case 7:  nRes = 31; break;
		case 8:  nRes = 31; break;
		case 9:  nRes = 30; break;
		case 10: nRes = 31; break;
		case 11: nRes = 30; break;
		case 12: nRes = 31; break;
	}
	return nRes;
}

function valDia(oTxt){
	var bOk = false;
	var nDia = parseInt(oTxt.value.substr(0, 2), 10);
	bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
	return bOk;
}

function valMes(oTxt){
	var bOk = false;
	var nMes = parseInt(oTxt.value.substr(3, 2), 10);
	bOk = bOk || ((nMes >= 1) && (nMes <= 12));
	return bOk;
}

function valAno(oTxt){
	var bOk = true;
	var nAno = oTxt.value.substr(6);
	bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
	if (bOk) {
		for (var i = 0; i < nAno.length; i++) {
			bOk = bOk && esDigito(nAno.charAt(i));
 	  }
	}
	return bOk;
}

function isDate(oTxt){
		var bOk = true;
		if (oTxt.value != ""){
			bOk = bOk && (valAno(oTxt));
			bOk = bOk && (valMes(oTxt));
			bOk = bOk && (valDia(oTxt));
			bOk = bOk && (valSep(oTxt));
		}
		return bOk;
}

function sustituye(cadena, car1, car2) {
	var nCadena = "";
	for (k=0; k<cadena.length; k++) {
		var car = cadena.charAt(k);
		if (cadena.charAt(k)==car1) {
			nCadena = nCadena+car2;
		} else {
			nCadena = nCadena+cadena.charAt(k);
		} // if
	} // for
	return nCadena;
}

function aMayusculas(pos) {
	var elementos = document.forms[pos].elements;
	for (p=0; p<elementos.length; p++) {
		if (elementos[p].type=="text" || elementos[p].type=="textarea") {
			elementos[p].value = elementos[p].value.toUpperCase();
		} //if
	} // for
} // aMayusculas

function cerrar() {
	window.close();
} // cerrar

function abrirVentana(nombre,ancho,alto,escroll,resice) {
	LeftPosition = (screen.width) ? (screen.width-ancho)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-alto)/2 : 0;
	dat = 'width=' + ancho + ',height=' + alto + ',left='+ LeftPosition +
				',top=' + TopPosition + ',scrollbars='+ escroll +',resize='+ resice +'';
	window.open(nombre,'',dat)
} // abrirVentana

function mensaje() {
	alert("Su mensaje ha sido recibido. En breve nos pondremos en contacto con ustad. Gracias.");
} // mensaje

function mensajeError() {
	alert("Ha ocurrido un problema en el envío de su mensaje. Si lo desea puede contactar con nosotros enviando un email a info@mcvinvestigacion.com. Gracias.");
} // mensaje


function capturaTeclas(e) { 
	// Inicio -> I (73) 
	// Conocenos -> O (79) 
	// Productos -> D (68) 
	// Pide un presupuesto -> N (78) 
	// Trabaja con nosotros -> R (82) 
	// Network -> K (75) 
	// Trabajos realizados -> J (74) 
	// Contacto -> A (65) 
	
	var altK = e.altKey; 
	var shiftK = e.shiftKey; 
	var tecla; 
	if (altK && shiftK) { 
		if (window.event) { // IE 
			tecla = e.keyCode;
		} else if (e.which) { // Netscape / Firefox / Opera 
			tecla = e.which; 
		} // if
		switch(tecla) { 
			case 73: // tecla I 
				window.location.href="../inicio/"; 
				break; 
			case 79: // tecla O
				window.location.href="../conocenos/"; 
				break; 
			case 68: // tecla D
				window.location.href="../productos/"; 
				break; 
			case 85: // tecla U
				window.location.href="../pideunpresupuesto/"; 
				break; 
			case 82: // tecla R 
				window.location.href="../trabajaconnosotros/"; 
				break; 
			case 75: // tecla K 
				window.location.href="../network/"; 
				break; 
			case 74: // tecla J
				window.location.href="../trabajosrealizados/"; 
				break; 
			case 65: // tecla A 
				window.location.href="../contacto/"; 
				break; 
			default: 
				break; 
		} // switch 
	} // if 
} // capturaTeclas 
