var $$=function(objId)
{
	return document.getElementById(objId);
}

function raw_validate(param)
{
	// me quedo con los objetos de tipo input
	tagList = document.getElementsByTagName(param);
	var supererror = false;
	for (var i = 0; i < tagList.length; i++)
	{
		var att = tagList[i].getAttribute("validate"),
		    val = tagList[i].value,
			error = false;			
		
		if (att != null)  
		{
			switch(att)
			{
				case "str": // string
					if (!(val.length>0)) error = true;
					else
					{
						var min = tagList[i].getAttribute("min");
						if (min != null && val.length < min-1) error = true;
						else
						// chequeo que no sean sólo espacios
						{
							var t = val.replace(new RegExp(' ' , "g"),'');
							if (!(t.length>0)) error = true;
						}
					}
					break;
					
				case "int": // entero
					if (isNaN(val) || val.length==0) error = true;
					break;
					
				case "intpos": // entero y positivo
					if (isNaN(val) || val.length==0 || val<0) error = true;
					break;
					
				case "select": // item seleccionado con value != -1
					if (val == -1) error = true;
					break;
				case "emailempty": // email o empty
					if (val.length==0) break;
				case "email": // email@server.ccc
					error = !validate_email(val);
					break;
			}
			
			if (error)
			{
				tagList[i].style.backgroundColor = "#D58380";
				supererror = true;
			}
			else
				tagList[i].style.backgroundColor = "#FFFFFF";
		}
	}
return supererror;
}

function validate()
{
	var error = false;
	error = raw_validate('input') || error;
	error = raw_validate('select') || error;
	error = raw_validate('textarea') || error;
	
	return !error;
}

function validate_email(field)
{
	var apos=field.indexOf("@"),
	dotpos=field.lastIndexOf("."),
	len = field.length;
	if (apos<1||dotpos-apos<2||dotpos+2>len) 
	  return false;
	else return true;
}

function isIntPos(value)
{
	return (!(isNaN(value) || value.length==0 || value<0));
}

function LoadAjaxDiv(divId, path, text, callbackFunc)
{
	$('#'+divId).html('<p> '+text+' <img src="images/loader.gif" width="16" height="11" /></p>');
	$('#'+divId).load(path, callbackFunc);
}
