function borrar(mensaje)
{
       if(confirm(mensaje))
		    return true;
		else
		  return false;
}
   
function submitbutton(pressbutton) {
	submitform(pressbutton);
}
								
function previewImage( list, image, base_path ) {
	form = document.adminForm;
	srcList = eval( "form." + list );
	srcImage = eval( "document." + image );
	var fileName = srcList.options[srcList.selectedIndex].text;
	var fileName2 = srcList.options[srcList.selectedIndex].value;
	if (fileName.length == 0 || fileName2.length == 0) {
		srcImage.src = '../images/images/noimages.gif';
	} else {
		srcImage.src = base_path + fileName2;
		document.getElementById('fotoPath').value =srcImage.src ;
	}
}

	function FotoInicial( list, image, base_path ) {
	form = document.adminForm;
	srcList = eval( "form." + list );
	srcImage = eval( "document." + image );
//	srcList.selectedIndex=0;
    var i = 0;
	var seleccion =0;
    for (i = 0; i < srcList.length; i++) {
     if (srcList[i].selected) {
		 seleccion = i;
     }
    }
		var fileName = srcList.options[seleccion].text;
	var fileName2 = srcList.options[seleccion].value;
	if (fileName.length == 0 || fileName2.length == 0) {
		srcImage.src = '../images/images/noimages.gif';
		document.getElementById('fotoPath').value = '';
	} else {
		
		srcImage.src = base_path + fileName;
	}
}

function FotoDefault( list, image, base_path,imagenName ) {
	form = document.adminForm;
	srcList = eval( "form." + list );
	srcImage = eval( "document." + image );
//	srcList.selectedIndex=0;
    var i = 0;
	var seleccion =0;
    for (i = 0; i < srcList.length; i++) {
     if (srcList[i].text == imagenName) {
		 srcList[i].selected = true;
     }
    }
		srcImage.src = base_path + imagenName;
	
}

	function SinFoto(whichElement1,whichElement2,rootPath)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        document.getElementById(whichElement1).disabled = !(document.getElementById(whichElement1).disabled);
		 document.getElementById(whichElement2).disabled = !(document.getElementById(whichElement2).disabled);
		 if (document.getElementById(whichElement2).disabled)
		 {
		   document.getElementById('miImagen').src = '../images/images/noimages.gif';
		   document.getElementById('fotoPath').value = '';
		 }
         else
		  previewImage( 'imagefiles', 'view_imagefiles', rootPath )
    }
}
function checkForm()
{
    var gname, gemail, gurl, gmessage;
    with(window.document.gf)
    {
        gname    = user;
        gemail   = mail;
        gurl     = url;
        gmessage = p;
    }
    if(trim(gname.value) == '')
    {
        alert('Please enter your name');
        gname.focus();
        return false;
    }
    else if(trim(gemail.value) != '' && !isEmail(trim(gemail.value)))
    {
        alert('Please enter a valid email address or leave it blank');
        gemail.focus();
        return false;
    }
    else if(trim(gurl.value) !='' && !isUrl(trim(gurl.value)))
    {
        alert('Please enter a valid link or leave it blank.');
        gurl.focus();
        return false;
    }
    else if(trim(gmessage.value) == '')
    {
        alert('Please enter your message');
        gmessage.focus();
        return false;
    }
    else
    {
    return true;
    }
}
function trim(str)
{
    return str.replace(/^\s+|\s+$/g,'');
}
function isEmail(str)
{
    var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
    return regex.test(str);
}
function isUrl(str) {
        var regex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i;
        return regex.test(str);
}
function addemoticos(smilie)
{
    document.gf.p.value += ' ' + smilie + ' ';
}

function cargaLista(listname, source)
{
  
	var list = eval( 'document.adminForm.' + listname );
	// empty the list
	for (i in list.options.length) {
		list.options[i] = null;
	}
	i = 0;
	for (x in source) {
	   opt = new Option();
			 opt.value = source[x][0];
			 opt.text = source[x][1];
			 list.options[i++] = opt;
		}
		list.length = i;
}

function cargaListaSeleccionado(listname, source,seleccionado)
{
  
	var list = eval( 'document.adminForm.' + listname );
	// empty the list
	for (i in list.options.length) {
		list.options[i] = null;
	}
	i = 0;
	for (x in source) {
	   opt = new Option();
			 opt.value = source[x][0];
			 opt.text = source[x][1];
                         if(seleccionado == opt.value){
                              opt.selected = true;
			  } 			      
			 list.options[i++] = opt;
		}
		list.length = i;
}

selected	
/**
* Changes a dynamically generated list
* @param string The name of the list to change
* @param array A javascript array of list options in the form [key,value,text]
* @param string The key to display
* @param string The original key that was selected
* @param string The original item value that was selected
*/
function changeDynaList( listname, source, key, orig_key, orig_val ) {
	var list = eval( 'document.adminForm.' + listname );
	// empty the list
	for (i in list.options.length) {
		list.options[i] = null;
		
	}
	i = 0;
	for (x in source) {
		if (source[x][0] == key) {
			opt = new Option();
			opt.value = source[x][1];
			opt.text = source[x][2];

			if ((orig_key == key && orig_val == opt.value) || i == 0) {
				opt.selected = true;
			}
			list.options[i++] = opt;
		}
	}
	list.length = i;
	if (i==0)
	{document.getElementById('miImagen').src = '../images/images/noimages.gif';}
}
function changeDynaList2( listname, source, key, orig_key, orig_val ) {
	var list = eval( 'document.adminForm.' + listname );
	// empty the list
	for (i in list.options.length) {
		list.options[i] = null;
		
	}
	i = 0;
	for (x in source) {
		if (source[x][0] == key) {
			opt = new Option();
			opt.value = source[x][1];
			opt.text = source[x][2];
			list.options[i++] = opt;
		}
	}
	list.length = i;
	if (i==0)
	{document.getElementById('miImagen').src = '../images/images/noimages.gif';}
}
/**
* Submit the admin form
*/
function submitform(pressbutton){

	document.adminForm.task.value=pressbutton;
	try {
		document.adminForm.onsubmit();
		}
	catch(e){}
	document.adminForm.submit();
}

	function dirup(){
		var urlquery=frames['imgManager'].location.search.substring(1);
		var curdir= urlquery.substring(urlquery.indexOf('listdir=')+8);
		var listdir=curdir.substring(0,curdir.lastIndexOf('/'));
		frames['imgManager'].location.href='<?php echo $dogConfig_live_site ?>/adminModules/index2.php?opcion=com_imagenes&task=list&listdir=' + listdir;
	}


	function goUpDir()
	{
		var selection = document.forms[0].dirPath;
		var dir = selection.options[selection.selectedIndex].value;
		frames['imgManager'].location.href='<?php echo $dogConfig_live_site ?>/adminModules/index2.php?opcion=com_imagenes&task=list&listdir=' + dir;
	}
	
	
	function disableElement(whichElement)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        document.getElementById(whichElement).disabled = !(document.getElementById(whichElement).disabled);
    }
    else if (document.all)
    {
        // this is the way old msie versions work
        document.all[whichElement].disabled = true;
    }
    else if (document.layers)
    {
        // this is the way nn4 works
        document.layers[whichElement].disabled = true;
    }   
}

function checkForm()
{
    var gname, gemail, gurl, gmessage;
    with(window.document.gf)
    {
        gname    = user;
        gemail   = mail;
        gurl     = url;
        gmessage = p;
    }
    if(trim(gname.value) == '')
    {
        alert('Introduce tu nombre por favor');
        gname.focus();
        return false;
    }
    else if(trim(gemail.value) != '' && !isEmail(trim(gemail.value)))
    {
        alert('Por favor introduce un email valido o dejalo en blanco');
        gemail.focus();
        return false;
    }
    else if(trim(gurl.value) !='' && !isUrl(trim(gurl.value)))
    {
        alert('Por favor introduce una direccion web correcta  o deja en blanco.');
        gurl.focus();
        return false;
    }
    else if(trim(gmessage.value) == '')
    {
        alert('Por favor escribe tu mensaje');
        gmessage.focus();
        return false;
    }
    else
    {
    return true;
    }
}
function trim(str)
{
    return str.replace(/^\s+|\s+$/g,'');
}
function isEmail(str)
{
    var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
    return regex.test(str);
}
function isUrl(str) {
        var regex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i;
        return regex.test(str);
}
function addemoticos(smilie)
{
    document.gf.p.value += ' ' + smilie + ' ';
}


function openwindow(url)
{
	window.open(url,"mywindow","menubar=0,resizable=1,width=600,height=430");
}


