//////////////////////////////////////////// LANZAR VENTANA Dw
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
 
}
//////////////////////////////////////////// INTERCAMBIO DE IMAGEN Dw
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

/////////////////////////////////////////// FUNCIÓN PARA LANZAR MENSAJE Y CONFIRMAR

function confirma(msg) {
  
  if(confirm(msg)){
  
  	return true;
  
  }else{
  
 	 return false;
  
  }
  
}

// LANZAMIENTO DE VENTANA... DEPORTE OLIMPICO?

function fullwin(targeturl){
var h,w,l,t;
l=t=0;
h=screen.availHeight-30;
w=screen.availWidth;
var newwin = window.open(targeturl,"video","status=0,toolbar=0,location=0,menubar=0,scrollbars=0,resizable=1,width=" +w + ",height=" + h+",top="+(t)+",left="+(l));
newwin.focus();
}

//FUNCIONES PARA EL MANEJO DE CAPAS OCULTAS
var whichDom = "", styleObj = ""
var isNav4, isNav6, isIE, isMAC
var isBrand = navigator.appName
var agt = navigator.userAgent.toLowerCase()
var navVer = parseInt(navigator.appVersion)

isNav4 = (isBrand == "Netscape" && navVer < 5) ? true : false
isNav6 = (isBrand == "Netscape" && navVer >= 5) ? true : false

isNav46 = ((isBrand == "Netscape") && (parseFloat(navigator.appVersion) >=
parseFloat(4.6)) && (parseFloat(navigator.appVersion) < parseFloat(4.7))) ?
true : false
isNav47 = ((isBrand == "Netscape") && (parseFloat(navigator.appVersion) >=
parseFloat(4.7))) ? true : false

isIE = ((agt.indexOf("msie") != -1) && (parseInt(navVer) >= 4)) ? true :
false
isMAC = (agt.indexOf("mac") != -1) ? true : false
//construct object reference
var doc = document
var layers = doc.layers
var all = doc.all

if (layers)  {
  whichDom = '["'
  styleObj = '"]'
} else if (all)  {
  whichDom = ".all."
  styleObj = ".style"
} else {
  whichDom = '.getElementById("'
  styleObj = '").style'
}

function setObject(obj) {
var theObj
    if (typeof obj == "string")
        theObj = eval("document" + whichDom + obj + styleObj)
    else
        theObj = obj
        return theObj
}


if (isNav6) {
  visible = 'block';
  hidden = 'none';
} else if (document.all) {
  visible = '';
  hidden = 'none';
}

function showrec(id) {
	menu =  id;

	var theObj = setObject(menu);

	if (theObj.display == '' || theObj.display == 'block') {
	  theObj.display = hidden;

	} else {
	   theObj.display = visible;

	}
}

/////////////////////////////////////////////////////////FUNCIONES FORMULARIO CORTOMOVIL
function validate_frmTest(frm) {
  var value = '';
  var errFlag = new Array();
  var _qfGroups = {};
  mensaje = '';

 value = frm.elements['peli'].value;
  if (value == '' && !errFlag['peli']) {
    errFlag['peli'] = true;
    mensaje = mensaje + '\n ·Carga el CORTOMOVIL\n';
  }
  
 value = frm.elements['titulo'].value;
  if (value == '' && !errFlag['titulo']) {
    errFlag['titulo'] = true;
    mensaje = mensaje + '\n ·Introduce el TÍTULO de la obra';
  }
  
  value = frm.elements['username'].value;
  if (value == '' && !errFlag['username']) {
    errFlag['username'] = true;
    mensaje = mensaje + '\n ·Introduce tu NICK';
  }

  value = frm.elements['email'].value;
  var regex = /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/;
  if (value != '' && !regex.test(value) && !errFlag['email']) {
    errFlag['email'] = true;
    mensaje = mensaje + '\n ·El correo electronico NO es correcto';
  }

  value = frm.elements['email'].value;
  if (value == '' && !errFlag['email']) {
    errFlag['email'] = true;
    mensaje = mensaje + '\n ·Introduce tu EMAIL';
  }

  value = frm.elements['password1'].value;
  if (value == '' && !errFlag['password1']) {
    errFlag['password1'] = true;
    mensaje = mensaje + '\n ·Introduce una CONTRASEÑA';
  }

  value = new Array();

  value[0] = frm.elements['password1'].value;
  value[1] = frm.elements['password2'].value;
  if ('' != value[0] && !(value[0] == value[1]) && !errFlag['password1']) {
    errFlag['password1'] = true;
    mensaje = mensaje + '\n ·Las contraseñas introducidas no coinciden';
  }

  value = frm.elements['password2'].value;
  if (value == '' && !errFlag['password2']) {
    errFlag['password2'] = true;
    mensaje = mensaje + '\n ·REPITE tu contraseña';
  }

  value = frm.elements['nombre'].value;
  if (value == '' && !errFlag['nombre']) {
    errFlag['nombre'] = true;
    mensaje = mensaje + '\n ·Introduce tu NOMBRE';
  }
  value = frm.elements['fechanacimiento'].value;
  if (value == '' && !errFlag['fechanacimiento']) {
    errFlag['fechanacimiento'] = true;
    mensaje = mensaje + '\n ·Introduce tu FECHA DE NACIMIENTO';
  }

  value = frm.elements['aceptar'].checked? '1': '';

  if (value == '' && !errFlag['aceptar']) {
    errFlag['aceptar'] = true;
    mensaje = mensaje + '\n ·Acepta las BASES de participación';
  }

  if (mensaje != '') {
   	mensaje = 'Introduce los siguientes datos:\n' + mensaje;
    //mensaje = mensaje + '\nPlease correct these fields.';
    alert(mensaje);
    return false;
  }
  return true;
}

/////////////////////////////////////////////////////////FUNCIONES FORMULARIO INSCRIPCIÓN

function checkWholeForm(theForm) {
    var why = "";
    why += checkEmail(theForm.email.value);
    why += checkPhone(theForm.phone.value);
    why += checkPassword(theForm.password.value);
    why += checkUsername(theForm.username.value);
    why += isEmpty(theForm.notempty.value);
    why += isDifferent(theForm.different.value);
    for (i=0, n=theForm.radios.length; i<n; i++) {
        if (theForm.radios[i].checked) {
            var checkvalue = theForm.radios[i].value;
            break;
        } 
    }
    why += checkRadio(checkvalue);
    why += checkDropdown(theForm.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}


// phone number ·strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}


// password ·between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    


// username ·4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}    