function str2dt (str_datetime,dotime) {
  if (dotime == true)
  	var re_date = /^(\d{4})\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
	else
		var re_date = /^(\d{4})\-(\d+)\-(\d+)$/;

	if (!re_date.exec(str_datetime) || str_datetime == "0000-00-00" || str_datetime == "0000-00-00 00:00:00") {
		alert("Formato invalido para presentar la Fecha");
		return (new Date());
	}

	if (dotime == true)
		return (new Date (RegExp.$1, RegExp.$2-1, RegExp.$3, RegExp.$4, RegExp.$5, RegExp.$6));
	else
		return (new Date (RegExp.$1, RegExp.$2-1, RegExp.$3));
}


function ComprobarVacios(formulario){
	
	todos_vacios = true;
	for(i = 0;i< formulario.elements.length; i++){
		//if(document.forms[0].elements[i].type == "text")
		if((formulario.elements[i].type == "text") || (formulario.elements[i].type == "textarea"))
		
				if(formulario.elements[i].value.length != 0){
					//alert(formulario.elements[i].value);
					todos_vacios = todos_vacios && false;
					break;
   					}
	}				
	if (todos_vacios){
		alert ("No se permiten inserciones con todos los campos vacíos");
		return false;
		}
		
	else{
		
		return true;
		}
	}		



function CreaListaIns(formulario){

	var insert,pares;
	insert="";
	
	if (!ComprobarVacios(formulario)){
		//alert ("!!!!");
		return false;
	}
	
	else{
		//alert("fff");
		for(i = 0;i< formulario.elements.length; i++){
			if(formulario.elements[i].type == "text" && formulario.elements[i].name != "resultado"){
				   if (insert =="")
						pares = formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					else
						pares ="#"+formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					insert = insert + pares;
					
			}
			if(formulario.elements[i].type == "textarea" && formulario.elements[i].name != "resultado"){
				   if (insert =="")
						pares = formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					else
						pares ="#"+formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					insert = insert + pares;
			}
			if(formulario.elements[i].type == "checkbox" && formulario.elements[i].name != "resultado"){
				if (insert =="") {
					if(formulario.elements[i].checked)
						pares = formulario.elements[i].name+",1";
					else 
						pares = formulario.elements[i].name+",0";
				}else {
					if(formulario.elements[i].checked)
						pares = "#"+formulario.elements[i].name+",1";
					else 
						pares = "#"+formulario.elements[i].name+",0";
				}
				insert = insert + pares;
			}
			if(formulario.elements[i].type == "select-one" && formulario.elements[i].name != "resultado"){
				for(var j=0;j< formulario.elements[i].length; j++){
					if(formulario.elements[i].options[j].selected) {
						if (insert =="")
							pares = formulario.elements[i].name+",'"+formulario.elements[i].options[j].value+"'";
						else
							pares ="#"+formulario.elements[i].name+",'"+formulario.elements[i].options[j].value+"'";
						insert = insert + pares;
					}
				}
			}
			if(formulario.elements[i].type == "radio" && formulario.elements[i].name != "resultado"){
					if(formulario.elements[i].checked) {
						if (insert =="")
							pares = formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
						else
							pares ="#"+formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
						insert = insert + pares;
					}
			}
			if(formulario.elements[i].type == "hidden" && formulario.elements[i].name == "seleccion"){
						if (insert =="")
							pares = formulario.elements[i].value;
						else
							pares ="#"+formulario.elements[i].value;
						insert = insert + pares;
			}
			
			if(formulario.elements[i].type == "hidden" && formulario.elements[i].name == "not_fecha"){
				   if (insert =="")
						pares = formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					else
						pares ="#"+formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					insert = insert + pares;
			}
			if(formulario.elements[i].type == "hidden" && formulario.elements[i].name == "fk_peenlaces_peinformacion"){
				   if (insert =="")
						pares = formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					else
						pares ="#"+formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					insert = insert + pares;
			}
			if(formulario.elements[i].type == "hidden" && formulario.elements[i].name == "enl_fecha_alta"){
				   if (insert =="")
						pares = formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					else
						pares ="#"+formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					insert = insert + pares;
			}			
		}	
		
		formulario.resultado.value=insert;
		
		return  true
	  }
}

function ComprobarVacios_login(formulario){
	//alert("ComprobarVacios_login")
	todos_vacios = true;
	for(i = 0;i< formulario.elements.length; i++){
		
		if(formulario.elements[i].value.length != 0){
					//alert("valor"+formulario.elements[i].value);
					todos_vacios = todos_vacios & false;
					
   					}
		
				
	}				
	if (todos_vacios){
		alert ("No se permiten inserciones con todos los campos vacíos");
		return true;
		}
		
	else{
		
		return false;
		}
	}

function CreaListaIns_login(formulario){
	
	var insert,pares;
	insert="";
	//if (ComprobarVacios_login(formulario))
	//	return "";
	//else{
		for(i = 0;i< formulario.elements.length; i++){
		
			
				   if (insert =="")
						pares = formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					else
						pares ="#"+formulario.elements[i].name+",'"+formulario.elements[i].value+"'";
					insert = insert + pares;
			
		}	
		
		return  insert
	//  }
}
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object   the table row
 * @param   string   the action calling this script (over, out or click)
 * @param   string   the default background color
 * @param   string   the color to use for mouseover
 * @param   string   the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function





function abreVentanaAyuda() {
	
	var vWinCal = window.open("ayuda/indice.php", "Ayuda Voluntariado", 
		"width=700,height=500,status=no");
	vWinCal.opener = self;
	vWinCal.focus();
	

}
function Salta_Menu(targ,selObj){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  //if (restore) selObj.selectedIndex=0;
}
// funcion de comprobar los campos obligatorios de un formulario
function existe_en_lista(lista,nombre){
	var result = new Array(); 
	result = lista.match(/\b\w*\b/gi);
	var i=0;
	for(i=0;i< result.length; i++){
		if (i % 2 == 0){
			if (result[i] == nombre) // si  esta devuelvo true
				return true;
		}
	}
	return false;  // si no esta devuelvo false	
}
function comprobarFormulario(formulario,lista){
	
	var valido = true;
	var campo = new String();
	
	for(i = 0;i< formulario.elements.length; i++){
		if (existe_en_lista(lista,formulario.elements[i].name)){
			if (formulario.elements[i].value == ""){
				alert("El campo '"+ formulario.elements[i].name.substr(4) +"' no puede ser vacio");
				valido = valido && false;
			} // fin  if (formulario.elements[i].value == ""){
		} // Fin if (existe_en_lista($lista,formulario.elements[i].name)){
	} // fin for 
	if (valido)
		valido = valido && CreaListaIns(formulario);
	
	return valido;					
}
