
//validacao do login
function validate(obj){
	if(obj.fakeUser.value == "" || obj.password.value == ""){
		if(obj.fakeUser.value == ""){
			alert('Debes informar tu usuario')
			obj.fakeUser.focus();
			return false
		}
		if(obj.password.value == ""){
			alert('Debes informar tu contraseña')
			obj.password.focus();
			return false
		}
	}
	return true
}

var hex_digits = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
		'A', 'B', 'C', 'D', 'E', 'F');
function chars_from_hex_title(theForm)
{
	var char_str = theForm.value;
	var hex_str = "";
	var i, n;
	for(i=0; i < char_str.length; i++) {
		n = char_str.charCodeAt(i);
		if(n != 0) {
			hex_str += byteToHex(n);
		}
	}
	document.getElementById("convTitle").value = hex_str;
}
function chars_from_hex_desc(theForm)
{
	var char_str = theForm.value;
	var hex_str = "";
	var i, n;
	for(i=0; i < char_str.length; i++) {
		n = char_str.charCodeAt(i);
		if(n != 0) {
			hex_str += byteToHex(n);
		}
	}
	document.getElementById("convDesc").value = hex_str;
}

function byteToHex(n)
{
	return hex_digits[(n >> 4) & 0xf] + hex_digits[n & 0xf];
}
function Cancel()
{
	window.location.href='videoMostRecent.aspx?idCountry=0';
}

function UploadComplete()
{
	
	window.location.href='uploadVideo.aspx?sucess=true';
}
function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value=="")
		{
			alert(alerttxt);
			return false
		}
		else
		{
			return true
		}
	}
}

function validate_form_login(thisform)	
{
	with (thisform)
	{
		if (validate_required(user,"¡Usuario inválido !")==false)
		{
			user.focus();
			return false
		}
		if (validate_required(password,"¡ Contraseña inválida!")==false)
		{
			password.focus();
			return false
		}
	}
}

function validate_form_search(thisform)
{
	with (thisform)
	{
		if (validate_required(searchString,"Busca inválida!")==false)
		{
			searchString.focus();
			return false
		}
	}
}

function validate_form_upload_filetype( field, alerttxt )
{
	///// Extensões dos arquivos permitidos
	var validExtensions = new Array(".wmv", ".mov", ".qt", ".rm", ".3gp", ".mpg", ".mpeg" );
	var isValid = false;
	
	with( field )
	{
		var extensao = value.substring(value.lastIndexOf( "." ))
				
		for( i in validExtensions )
		{
			if( extensao == validExtensions[i] )
			{
				isValid = true;
				return true;
			}
		}
		if( isValid == false )
		{
			alert(alerttxt);
			return false;
		}
	}		
}

function validate_form_upload(thisform)
{
	with (thisform)
	{
		if (validate_required(fileVideo,"Seleccione un video")==false)
		{
			fileVideo.focus();
			return false
		}
		if( validate_form_upload_filetype(fileVideo,"¡ Formato de archivo inválido!")==false )
		{
			fileVideo.focus();
			return false;
		}
		if (validate_required(textTitle,"Coloques un título para el video")==false)
		{
			textTitle.focus();
			return false
		}
		if (validate_required(textDescription,"Coloques una descripción para el video")==false)
		{
			textDescription.focus();
			return false
		}
	}
}

function validateFields() 
{
	var descr = document.getElementById('textDescription').value;
	var title = document.getElementById('textTitle').value;
	if(title=='' || title==null)
	{
		alert('Por favor informes el título del video');
		return;
	}
	else if(descr=='' || descr==null)
	{
		alert('Por favor informes la descripción del video');
		return;
	}
	else 
	{
		document.editForm.submit();
	}
}

//limita o número de caracteres da descricao, na edicao do video
function textLimit(field) 
{
	if (field.value.length > 500)
	{ 
		alert("Atención: has atingigo el límite de carctéres permitidos para el comentario.");
		field.value = field.value.substring(0, 500);
	}
}

//limita o número de caracteres
function textCounter(field, countfield, maxlimit){
	if(field.value.length > maxlimit) { // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		document.getElementById('erroUpload').innerHTML = "<p class='erro'>Excediste el limite de caracteres en la descripcion de tu video.</p>"
	}else{ // otherwise, update 'characters left' counter
		countfield.value = maxlimit - field.value.length;
	}
}

//limita o número de caracteres do comentário			
function commentLimit(field)
{
	if (field.value.length > 500)
	{ 
		alert("Excediste el limite de caracteres");
		field.value = field.value.substring(0, 500);
	}
}

function Mensage(str){
	alert(str);
}