if (!appleBox)	var appleBox = {};

appleBox.init = function (){
	if ( navigator.userAgent.toLowerCase().indexOf('safari') < 0  && document.getElementById ){
		this.clearBtn = false;
	};
}

// called when on user input - toggles clear fld btn
appleBox.onChange = function (fldID, btnID, imgPath){
	// check whether to show delete button
	var fld = this.goo( fldID );
	var btn = this.goo( btnID );
	if (fld.value.length > 0)	{
		btn.style.background = "white url("+imgPath+"srch_r_f2.gif) no-repeat top left";
		btn.fldID = fldID; // btn remembers it's field
		btn.imgPath = imgPath; // btn remembers image path
		btn.onclick = this.clearBtnClick;
		this.clearBtn = true;
	} else if (fld.value.length == 0) {
		btn.style.background = "white url("+imgPath+"srch_r.gif) no-repeat top left";
		btn.onclick = null;
		this.clearBtn = false;
	};
}

appleBox.clearFld = function (fldID,btnID,imgPath){
	this.goo( fldID ).value = "";
	this.goo( fldID + '_ok').style.display='none';
	this.goo( fldID + '_no').style.display='none';
	this.goo( fldID ).focus();
	this.onChange(fldID,btnID,imgPath);
}

// called by btn.onclick event handler - calls clearFld for this button
appleBox.clearBtnClick = function (){appleBox.clearFld(this.fldID, this.id, this.imgPath);}

appleBox.valid = function(fld, valid){
	valid=(typeof(valid)=="undefined")?true:valid;
	if (valid!="none"){
		if (!valid){
			fadetext('e_'+fld.id ,199,0,0);
			this.goo( fld.id + '_ok').style.display='none';
			this.goo( fld.id + '_no').style.display='inline';
		}else{
			fadetext('e_'+fld.id ,0,199,0);
			this.goo( fld.id + '_ok').style.display='inline';
			this.goo( fld.id + '_no').style.display='none';
		};
	};
}

appleBox.goo = function(id){
	return document.getElementById(id);
}
/* END appleBox object */

var R=G=B=x=0;
function fadetext(id,r,g,b){ fade(id,r,g,b,R,G,B,x); }
function fade(id,r,g,b,R,G,B,x){
	if (x<255){
		x+=8; R=(R<r)?(R+x):r; G=(G<g)?(G+x):g; B=(B<b)?(B+x):b; R=(R>255)?255:R; G=(G>255)?255:G; B=(B>255)?255:B;
    	document.getElementById(id).style.color= "rgb("+R+","+G+","+B+")";
		setTimeout("fade('"+id+"',"+r+","+g+","+b+","+R+","+G+","+B+","+x+")",30);
	}else var R=G=B=x=0;
}

function pm(name){document.write('<a href=mailto:' + name + '@' + enlace + '>' + name + '@gurusistemas.com</a>');};

function valCorreo(emailStr) { 
	var emailPat=/^(.+)@(.+)$/; 
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; 
	var validChars="\[^\\s" + specialChars + "\]"; 
	var quotedUser="(\"[^\"]*\")"; 
	var ipDomainPat=/^[(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})]$/; 
	var atom=validChars + '+'; 
	var word="(" + atom + "|" + quotedUser + ")"; 
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); 
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); 
	var matchArray=emailStr.match(emailPat); 
	if (matchArray==null) return false;
	var user=matchArray[1] ;
	var domain=matchArray[2] ;
	if (user.match(userPat)==null) return false ;
	var IPArray=domain.match(ipDomainPat) 
	if (IPArray!=null) { 
	    for (var i=1;i<=4;i++) if (IPArray[i]>255) return false ;
	    return true ;
	};
	var domainArray=domain.match(domainPat) ;
	if (domainArray==null) return false; 
	var atomPat=new RegExp(atom,"g") ;
	var domArr=domain.match(atomPat) ;
	var len=domArr.length ;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) return false ;
	if (len<2) return false; 
	return true; 
} ;
