function PopUp(perfil, tamx, tamy, yn)
{  window.open(perfil,"","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=" + yn + ",width=" + tamx + ",height=" + tamy)
}

function $(str){return document.getElementById(str);}

function isEmail(obj){
	if(obj.value.length!=0)
		if(obj.value.indexOf('@')!=-1)
			if(obj.value.indexOf('@')==obj.value.lastIndexOf('@'))
				if(obj.value.indexOf('.',obj.value.indexOf('@'))!=-1)
					return true;
	return false;
}


function isBlank(obj,initialValue){
	if(obj.value=='' || (obj.value == initialValue)){
		return true;
	}else
		return false;
}

function validation(f,objError){
	var validate = true;
	var attrName = (!document.all)?'class':'classname';
	var classDefault = 'textbox';
	var classError = 'textbox_erro';
		
	for(i=0;i<f.elements.length;i++){
		obj = f.elements[i];
		initialValue = (obj.getAttribute('initialValue')!=undefined)?obj.getAttribute('initialValue'):'';

		switch(obj.getAttribute('typeValidation')){
			case 'blank':
				if(isBlank(obj,initialValue)){
					obj.setAttribute(attrName,classError,0);
					obj.setAttribute('title',obj.getAttribute('errorMenssage'),0);
					validate = false;
				}else{
					obj.setAttribute(attrName,classDefault,0);
				}
			break;
			case 'email':
				if(!isEmail(obj)){
					obj.setAttribute(attrName,classError,0);
					obj.setAttribute('title',obj.getAttribute('errorMenssage'),0);
					validate = false;	
				}else{
					obj.setAttribute(attrName,classDefault,0);
				}
			break;
			default:
				// faz nada
			break;
		}
	}
	
	if(!validate){
		objError.innerHTML = 'Os campos em vermelho precisam ser preenchidos.';
		return false;
	}
	return true;
}

function setAparence(obj, texto){
	obj.onblur=function(){
		if(this.value==''){
			this.value = texto;
		}
	}
	
	if(obj.value == texto){
		obj.value = '';	
	}
}
