function validar( frm ){
	
	missinginfo = "";
	
	for ( i = 0; i < frm.elements.length; i++ ){
		if ( !validar_campo( frm.elements[i] ) )
		missinginfo += "\n     -  "+strMayuscula(frm.elements[i].name);
	}
	
	if ( document.getElementById('IDidPais') ){
		if ( document.getElementById('IDidPais').value == '' ) missinginfo += '\n     -  País';
	}
	
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"Te ha faltado introducir los siguientes datos:\n" +
		missinginfo + "\n_____________________________" +
		"\n¡Por favor pulsa enter, rellena los datos y prueba de nuevo!";
		alert(missinginfo);
		return false;
	}
}
function validar_campo( campo ){

	if ( campo ){
		if ( isnull( campo.name ) ){
			return true;
		}else{

			switch ( campo.type ){

				case "hidden": return true; break;

				case "checkbox": if ( !campo.checked == false ) return true; break;

				case "radio": return true; break;

				default :

				switch ( campo.name ){

					case "email": case "msn": return isValidEmailAddress( campo.value ); break;

					case "password2": pass = document.getElementById('password').value; if ( campo.value == pass ) return true; break;

					case "http": case "nullhttp":
					case "web": case "nullweb":

					if ( campo.value != "" ) {

						return isValidWeb( campo );

					}else return true;

					break;

					default : if ( campo.value != "" ) return true; break; break;

				}

				break;

			}
		}
	}
}
function isnull( name ){
	if ( name == "nullhttp" || name == "nullweb" ) return false;
	if ( name.substring(0,4) == "null" ) return true;
	else return false;
}
function strMayuscula( name ) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = name.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0) {
		for (index = 0; index < strLen; index++) {
			if (index == 0) {
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
			}
			else {
				tmpChar = tmpStr.substring(index, index+1);
				if (tmpChar == " " && index < (strLen-1)) {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
	return tmpStr;
}
function isValidEmailAddress(s) {

	var atPosition = s.indexOf("@");

	if(atPosition == -1)
	return false;

	if(atPosition < s.lastIndexOf("@"))
	return false; // more than one

	var dotPosition = s.lastIndexOf(".");

	if(dotPosition < atPosition || dotPosition == (atPosition + 1))
	return false;

	return true;

}
function isValidWeb(campo) {

	var s = campo.value;

	var atPosition = s.indexOf("http://");

	if(atPosition == -1){
		campo.name = "web";
		return false;
	}

	if(atPosition < s.lastIndexOf("http://")){
		campo.name = "web";
		return false;
	}

	return true;

}