function deleteVideo(_vid, _layName) {
	if (confirm('Are you sure you want to delete this video?\n All related votes and comments associated with it will also be deleted.')) {
  	loading(410,280,-1,-1,_layName);
		getLayerHTML("/videos/deletevideo.php?vid="+_vid+"&lay="+_layName, null,null, "GET", _layName);
	}
}
function addFavouriteVideo(_vid, _layName) {
  	loading(410,280,-1,-1,_layName);
		getLayerHTML("/videos/addfavouritevideo.php?vid="+_vid+"&lay="+_layName, null,null, "GET", _layName);
}
function sendVideoFeedback(_form, _layName) {
  	loading(410,280,-1,-1,_layName);
		getLayerHTML("/videos/send_video_feedback.php", _form,null, "POST", _layName);
}
function addVoteVideo(_vid, _vote, _layName) {
  	loading(410,280,-1,-1,_layName);
		getLayerHTML("/videos/insert_video_vote.php?vid="+_vid+"&vote="+_vote+"&lay="+_layName, null,null, "GET", _layName);
}
function scroll_favourites_videos(dir,idvideo) {	
	getLayerHTML3("/videos/my_favourites.php?dir="+dir+"&idvideo="+idvideo+"&ajax=true",null,null, "GET");  
}
function report_video(location, form) {	
	  loading(410,280,-1,-1,"report");
	  if (form!=null) {  
	  	getLayerHTML("/videos/report_problems3.php",form,location, "POST", "report");
	  }
	  else {
	  	getLayerHTML("/videos/report_problems3.php",form,location, "GET", "report");
	  }
}

function report_video_checked() {	
  loading(410,280,-1,-1,"report");  
  getLayerHTML("/videos/revisado2.html",null,null, "GET", "report");
}
function editvideox(_vid, _layName, form) {	
  loading(410,280,-1,-1, _layName);
  if (form!=null) {
	getLayerHTML("/videos/editvideo.php",form,null, "POST",_layName);
  }
  else {
	getLayerHTML("/videos/editvideo.php?vid="+_vid,form,null, "GET",_layName);  
  }
}

function getLayerHTML3(url, formName, targetLocation, method)
{	
	createXMLHttpRequest();
	var queryString = url;
	
	if(targetLocation!=null)
	targetLocation=getLocationWithoutAmpersend(targetLocation);
	
	xmlHttp.onreadystatechange = handleLayerResponse2;

	var i=queryString.indexOf("?");
	if (i>=0)
	{
	queryString=queryString+"&randomString="+randomString();
	queryString = queryString+"&url=" + targetLocation;
	}
	else
	{
	queryString = queryString+"?url=" + targetLocation;
	queryString=queryString+"&randomString="+randomString();
	}
	xmlHttp.open(method, queryString, true);
  	xmlHttp.send(null);
}

function esEmailValido(location, form) 
  {
    var email = document.reportsong.email.value;
    var comentario = document.reportsong.comment.value;
    if (email == "") {
			alert("You must enter a valid email address.");
	    document.reportsong.email.focus();
	    return false;
	  }
    if (email.indexOf(" ")!=-1) { // Comprobamos que email no contenga espacios,tampoco en los laterales
			alert("You must enter a valid email address.");
	    document.reportsong.email.focus();
       return false;
    }
    if (email.indexOf("@")==-1) // Comprobamos que exista al menos un carácter @
    {
			alert("You must enter a valid email address.");
	    document.reportsong.email.focus();
       return false;
    }
    else
    {
      var posarroba=email.indexOf("@");
      var nombre=email.substring(0, posarroba);
      var dominio=email.substring(posarroba+1);

      // Comprobamos que nombre  tenga al menos un carácter
      if (nombre.length==0) {
				alert("You must enter a valid email address.");
		    document.reportsong.email.focus();
         return false;
      }

      // Comprobamos que nombre no sea un solo punto
      if (nombre==".") {
				alert("You must enter a valid email address.");
		    document.reportsong.email.focus();
         return false;
			}
			
      // Comprobamos que dominio tenga al menos un carácter
      if (dominio.length==0) {
				alert("You must enter a valid email address.");
	  	  document.reportsong.email.focus();
         return false;
       }

      // Comprobamos que dominio tenga al menos existe un punto
      if (dominio.indexOf(".")==-1) {
					alert("You must enter a valid email address.");
	  		  document.reportsong.email.focus();
         return false;
      }

      // Comprobamos que la ni la primera ni la última posición del dominio sea el punto
      len_dom=dominio.length - 1;
      if ((dominio.charAt(0)==".")||(dominio.charAt(len_dom)==".")) {
				alert("You must enter a valid email address.");
		    document.reportsong.email.focus();
         return false;
			}
      // Comprobamos que tanto nombre como dominio sólo cotengan carácteres válidos
      if (CharInCorrectos(nombre)) {
				alert("You must enter a valid email address.");
	  	  document.reportsong.email.focus();
      	return false;
      }
      if (CharInCorrectos(dominio)) {
				alert("You must enter a valid email address.");
		    document.reportsong.email.focus();
      	return false;
      }
    }
    if (comentario == "") {
			alert("You must enter a comment.");
	    document.reportsong.comment.focus();
	    return false;
	  }
    report_video(location, form);
}
function CharInCorrectos(cadena)
{
     validos="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";

     // Comprobamos que cadena no tenga algún carácter no contemplado
     // en el string validos y que no existan dos puntos contiguos
     for (i=0;i<cadena.length;i++)
     {
       if (validos.indexOf(cadena.charAt(i))==-1) return true;
       if (cadena.charAt(i)==".")
         if ((i!=cadena.length-1) && (cadena.charAt(i+1)=="."))
           return true;
     }
     return false; // No se ha encontrado ninguna irregularidad
}
