function isWhitespace (s)
{   
	var i;

    if (isEmpty(s)) return true;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }
	
    return true;
}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}

/* Member Preferences */ 
/*--------------------*/
var whitespace = " \t\n\r";

function checkform_change_password(){
var frm = document.formulario;
id_valida = true;

	if ( isWhitespace(frm.txt_clave_actual.value) )
	{
		if(frm.idioma.value=='E'){
			alert ( "Por favor, escribe tu clave actual." );
		}
		else{
			alert ( "Input old Password." );
		}	
		frm.txt_clave_actual.focus ();
		id_valida = false;
	}

	if ( isWhitespace(frm.txt_clave_nueva.value) ){
            if(frm.idioma.value=='E'){
		alert ( "Por favor, escribe tu nueva clave." );
            }
            else{
		alert ( "Input new password." );
            }	
            frm.txt_clave_nueva.focus ();
            id_valida = false;
	}

	if ( isWhitespace(frm.txt_clave_confirmada.value) )
	{
		if(frm.idioma.value=='E'){
			alert ( "Por favor, confirma tú nueva clave." );
		}
		else{
			alert ( "Input confirm new password." );
		}	
		frm.txt_clave_confirmada.focus ();
		id_valida = false;
	}

	if (id_valida){

	    if (frm.txt_clave_nueva.value == frm.txt_clave_confirmada.value) {
		if (frm.txt_clave_actual.value != frm.txt_clave_confirmada.value) {
                    id_valida = true;
		}
		else{
                    if(frm.idioma.value=='E'){
                        alert ( "Clave actual y nueva debe ser distintas." );
                    }
		else{
                    alert ( "Old and New password deben ser distinct." );
		}	
                    frm.txt_clave_nueva.value = "";
                    frm.txt_clave_confirmada.value = "";
                    frm.txt_clave_nueva.focus ();
                    id_valida = false;
		}				 
	    }
		else{
			if(frm.idioma.value=='E'){
				alert ( "nueva clave y confirmada no son iguales." );
			}
			else{
				alert ( "Input new and confirm password." );
			}	
			frm.txt_clave_nueva.value = "";
			frm.txt_clave_confirmada.value = "";
			frm.txt_clave_nueva.focus ();
			id_valida = false;
		}
	}

	if (id_valida){
		frm.save.value = 'S1'
                protoSend(); // ----> funcion en functions.js: envia formulario mediante prototype 
		//frm.action = "member_preferences.jsp"
		//frm.submit()
	}
}


        function checkform_update(){
            var frm = document.formulario;
            var id_valida;
            id_valida = true;
            if (isWhitespace(frm.txt_nombre.value))
                {
                    if(frm.idioma.value=='E'){
                        alert ( "Por favor, escribe tu nombre." );
                    }
                    else{
			alert ( "Input first name." );
                    }	
                    document.formulario.txt_nombre.focus ();
                    id_valida = false;
                }
            else if ( isWhitespace(frm.txt_apellido.value) ){
                        if(frm.idioma.value=='E'){
                            alert ( "Por favor, escribe tus apellidos." );
                        }
                        else{
                            alert ( "Input last name." );
                        }
                        frm.txt_apellido.focus ();
                        id_valida = false;
                }
            else if ( isWhitespace(frm.txt_empresa.value ) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, escribe el nombre de la empresa." );
		}
		else{
			alert ( "Input Company." );
		}
		frm.txt_empresa.focus ();
		id_valida = false;
            }
            else if ( isWhitespace (frm.txt_direccion.value) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, escribe tu dirección." );
		}
		else{
			alert ( "Input Address." );
		}	
		frm.txt_direccion.focus ();
		id_valida = false;
            }
            else if ( isWhitespace (frm.txt_ciudad.value) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, escribe tu ciudad." );
		}
		else{
			alert ( "Input City." );
		}	
		frm.txt_ciudad.focus ();
		id_valida = false;
            }
            else if ( isWhitespace (frm.txt_codigo_zip.value) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, escribe tu Código Zip." );
		}
		else{
			alert ( "Input Zip Code." );
		}	
		frm.txt_codigo_zip.focus ();
		id_valida = false;
            }
            else if ( isWhitespace (frm.txt_estado.value) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, escribe tu estado." );
		}
		else{
			alert ( "Input State." );
		}	
		frm.txt_estado.focus ();
		id_valida = false;
            }
            else if ( isWhitespace(frm.txt_telefono.value ) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, escribe el Teléfono." );
		}
		else{
			alert ( "Input telephone number." );
		}	
		frm.txt_telefono.focus ();
		id_valida = false;
            }
            else if ( isWhitespace(frm.txt_fax.value ) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, escribe el Fax." );
		}
		else{
			alert ( "Input Fax number." );
		}	
		frm.txt_fax.focus ();
		id_valida = false;
            }
            else if (frm.CB_cargo.options[frm.CB_cargo.selectedIndex].value==0 && isWhitespace(frm.other_position.value) )
            {
		if ( isWhitespace(frm.other_position.value ) )
		{
			if(frm.idioma.value=='E'){
				alert ( "Por favor, escribe el cargo nuevo." );
			}
			else{
				alert ( "Input Other Position." );
			}	
			frm.other_position.focus ();
			id_valida = false;
		}
            }
            else if (frm.CB_pais.options[frm.CB_pais.selectedIndex].value==0 )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, selecciona el País." );
		}
		else{
			alert ( "Input Country." );
		}	
		frm.CB_pais.focus ();
		id_valida = false;
            }
            else if (frm.CB_sector.options[frm.CB_sector.selectedIndex].value==0 && isWhitespace(frm.other_sector.value))
            {
		if ( isWhitespace(frm.other_sector.value ) )
		{
			if(frm.idioma.value=='E'){
				alert ( "Por favor, escribe el sector nuevo." );
			}
			else{
				alert ( "Input Other Sector." );
			}	
			frm.other_sector.focus ();
			id_valida = false;
		}
            }
            else if ( isWhitespace(frm.txt_sitioweb.value) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, ingresa tu sitio web." );
		}
		else{
			alert ( "Input web site." );
		}
		frm.txt_sitioweb.focus ();
		id_valida = false;
            }
	//else if ( isWhitespace(frm.txt_officeNumber.value) )
	//{
	//	if(frm.idioma.value=='E'){
	//		alert ( "Por favor, ingresa tu Numero de oficina." );
	//	}
	//	else{
	//		alert ( "Input Office number." );
	//	}
	//	frm.txt_officeNumber.focus ();
	//	id_valida = false;
	//}
            else if ( isWhitespace(frm.txt_telCompany.value) )
            {
		if(frm.idioma.value=='E'){
			alert ( "Por favor, ingresa Teléfono compañia." );
		}
		else{
			alert ( "Input Company telephone." );
		}
		frm.txt_telCompany.focus ();
		id_valida = false;
            }
            if (id_valida){
                var pattern3 = /;/g;
		frm.save.value = 'S2';
                protoSend(); // ----> funcion en functions.js: envia formulario mediante prototype 
                //if (eval(frm.ten)){frm.ten.value = 'Y';}                                    

		//frm.action = "member_preferences.jsp"
		//frm.submit()
	}
}


function checkform_language(){
    var frm = document.formulario;
    var id_valida;
    id_valida = true;

    if (frm.rad_idioma[0].checked)
	frm.txt_idioma.value = 'I';
    if (frm.rad_idioma[1].checked)
	frm.txt_idioma.value = 'E';

    if (id_valida){
	frm.save.value = 'S3'
        protoSend(); // ----> funcion en functions.js: envia formulario mediante prototype 
	//frm.action = "member_preferences.jsp"
	//frm.submit()
    }
}



    function checkform_email_format(){
    var frm = document.formulario;
    id_valida = true;

	if (frm.rad_seleccion[0].checked)
		frm.txt_seleccion.value = 1;
	if (frm.rad_seleccion[1].checked)
		frm.txt_seleccion.value = 2;
	if (frm.rad_seleccion[2].checked)
		frm.txt_seleccion.value = 3;
	if (frm.rad_seleccion[3].checked)
		frm.txt_seleccion.value = 4;

	if (id_valida){
		frm.save.value = 'S4'
                protoSend(); // ----> funcion en functions.js: envia formulario mediante prototype 
		//frm.action = "member_preferences.jsp"
		//frm.submit()
	}
}


function build_chkb_selection2(sel, Nombre, NumCheckboxes){ 

	StrResult = ""; 
	contIn = 1;
	if (Nombre=="chk_country"){
            contIn=21;
        }
	for (id_chkbox = contIn ; id_chkbox <= NumCheckboxes ; id_chkbox++) 
	{
        //alert(Nombre+id_chkbox +": "+document.getElementById(Nombre+id_chkbox).checked);
          if(document.getElementById(Nombre+id_chkbox)){
	    //isChecked = eval(sel+"."+Nombre+id_chkbox+".checked");
            isChecked = document.getElementById(Nombre+id_chkbox).checked;
		
            if (isChecked==true){
		
		if (StrResult == "")
                    //StrResult = eval(sel+"."+Nombre+id_chkbox+".value"); 
                    StrResult = document.getElementById(Nombre+id_chkbox).value;
		else
                    //StrResult = StrResult + "," + eval(sel+"."+Nombre+id_chkbox+".value"); 
                    StrResult = StrResult + "," + document.getElementById(Nombre+id_chkbox).value;
	    }
          }
	}
	return StrResult;
}

function checkform_email_preferences(){
var frm = document.formulario;
id_valida = true;

	frm.L_sector_daily.value = build_chkb_selection2(frm.name, "chk_daily", 12);
	frm.L_sector_weekly.value = build_chkb_selection2(frm.name, "chk_weekly", 12);
	frm.L_sector_regional.value = build_chkb_selection2(frm.name, "chk_country", 24);
        
        //alert(frm.L_sector_daily.value + " - "+ frm.L_sector_weekly.value + " - " + frm.L_sector_regional.value);
        
	if (id_valida){
		frm.save.value = 'S5'
                protoSend(); // ----> funcion en functions.js: envia formulario mediante prototype 
                //frm.action = "member_preferences.jsp"
		//frm.submit()
	}
}




