var win=null;
	
	
	function openSendWindow(idUsuario,title){
		var ajax = new Ajax();
		ajax.handleResp=function(resp){
			Dialog.info(resp, {width:304, height:295, showProgress: false});
		}	
			ajax.doAsyncRequest("_ajax.php","GET","text","opc=enviarMailForm&idUsuario="+idUsuario+"&title="+title);
	}
	
	function openReportWindow(idReview,title){
		var ajax = new Ajax();
		ajax.handleResp=function(resp){
			Dialog.info(resp, {width:304, height:295, showProgress: false});
		}	
			ajax.doAsyncRequest("_ajax.php","GET","text","opc=enviarReportForm&idReview="+idReview+"&title="+title);
	}
	
	function openChangePasswordWindow(title){
		var ajax = new Ajax();
		ajax.handleResp=function(resp){
			Dialog.info(resp, {width:304, height:255, showProgress: false});
		}	
		ajax.doAsyncRequest("_ajax.php","GET","text","opc=showChangePassword");
	}
	
	function sendEmail(fromName,fromEmail,toName,toEmail,message,title){
		var ajax = new Ajax();
			ajax.handleResp=function(resp){
				Dialog.setInfoMessage(resp);
			}	
		ajax.doAsyncRequest("_ajax.php","GET","text","opc=sendEmail&fromName="+fromName+"&fromEmail="+fromEmail+"&toName="+toName+"&toEmail="+toEmail+"&message="+message+"&title="+title);
	}
	
	function sendReport(fromName,fromEmail,message,idReview,title){
		var ajax = new Ajax();
			ajax.handleResp=function(resp){
				Dialog.setInfoMessage(resp);
			}	
		ajax.doAsyncRequest("_ajax.php","GET","text","opc=sendReport&fromName="+fromName+"&fromEmail="+fromEmail+"&message="+message+"&idReview="+idReview+"&title="+title);
	}

	function openForgotPasswordWindow(){
		var ajax = new Ajax();
		ajax.handleResp=function(resp){
			Dialog.info(resp, {width:304, height:195, showProgress: false});
		}	
		ajax.doAsyncRequest("_ajax.php","GET","text","opc=enviarForgotPasswordForm");
	}
	
	function sendForgotPassword(email){
		var ajax = new Ajax();
		ajax.handleResp=function(resp){
			try{
				Dialog.setInfoMessage(resp);
			}
			catch(ex){
			}
		}	

		ajax.doAsyncRequest("_ajax.php","GET","text","opc=sendForgotPassword&email="+email);
	}
	
	function sendEcceedEmail(idUser){
		var ajax = new Ajax();
		ajax.handleResp=function(resp){
		}	
		ajax.doAsyncRequest("_ajax.php","GET","text","opc=sendEcceedEmail&idUser="+idUser);
	}
	
	function changePassword(email,oldPassword,newPassword){
		var ajax = new Ajax();
		ajax.handleResp=function(resp){
			try{
				Dialog.setInfoMessage(resp);
			}
			catch(ex){
			}
		
		}	
		ajax.doAsyncRequest("_ajax.php","GET","text","opc=changePassword&email="+email+"&oldPassword="+oldPassword+"&newPassword="+newPassword);
	}
	
	function openReview(idLawyer,idReview){
		window.open( "reviews.php?idLawyer="+idLawyer+(idReview!=""?"&idReview="+idReview:''), 'window_lawyerReview', "height=440,width=670,scrollbars=yes,resizable=yes" );
	}


function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} 
	else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} 
	else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} 
	else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function ShowPicture(){
	
	this.lockLayer = document.createElement('DIV');
	this.img = document.createElement('IMG');
	this.showInterval = null;
	this.actualOpacity =  0;
	ShowPicture.prototype.increment = 10;
	ShowPicture.prototype.interval =  100;
	
	this.lockScreen=function(){
		var self=this; //Referencia a ShowPicture;
		var pageSize = getPageSize();
		var fecha=new Date();
		this.lockLayer.id='lockLayer'+fecha.getHours()+"_"+fecha.getMinutes()+"_"+fecha.getSeconds()+"_"+fecha.getMilliseconds();
		this.lockLayer.style.width  = pageSize[0]+'px';
		this.lockLayer.style.height = pageSize[1]+'px';
		this.lockLayer.style.position='absolute';
		this.lockLayer.style.top = '0px';
		this.lockLayer.style.left = '0px';
		this.lockLayer.style.zIndex = '998';
		this.lockLayer.style.backgroundColor = '#fdb000';
		this.lockLayer.style.backgroundImage='url(img/ajax-loader.gif)';
		this.lockLayer.style.backgroundRepeat='no-repeat';
		this.lockLayer.style.backgroundPosition='50% '+((screen.availHeight/2)-100)+'px';
		if(document.all){
			this.lockLayer.style.filter = 'alpha(opacity=' +60+ ')';
		}
		else{
			this.lockLayer.style.opacity = 60/100;				
		}
		document.body.appendChild (this.lockLayer);
	}
	
	
 	
	this.unlockScreen=function(){
		try{
			document.body.removeChild(document.getElementById(this.lockLayer.id));
		}
		catch(e){
			alert(e);
			return false;	
		}	
		
		return true;
	}
	
}	
function showToolTip(e,id,text){
	var coords=getMousePos(e);
	var divToolTip =  document.getElementById(id);
	if(divToolTip.style.display=='block')return;
	divToolTip.innerHTML="<p>"+text+"  "+coords.x+"|"+coords.y+"</p>";
	divToolTip.style.top=coords.y+"px";
	divToolTip.style.left=(coords.x-30)+"px";
	divToolTip.style.zIndex='999';
	divToolTip.style.display='block';
	
}


function hideToolTip(id){
	document.getElementById(id).style.display='none';
}

function getMousePos(e) {
	//NS
	var x1,y1;
	if (document.layers||document.getElementById&&!document.all) {
		x1 = e.pageX
		y1 = e.pageY
	}
	//IE
	else if (document.all) {
		x1 = event.clientX
		y1 = event.clientY
	}
	return {x:x1,y:y1};
} 

function accessDenyMsg(idioma){
	if(idioma=='en'){
		alert('Sorry. You must be logged in to access this content');
	}
	if(idioma=='es'){
		alert('Debe estar registrado para acceder a este contenido.');
	}
}


function _popImage(imageURL,imageTitle){
	if(document.getElementById('popupImage')){
		document.body.removeChild(document.getElementById('popupImage'));	
	}
	
	var scrollHeight=document.documentElement.scrollTop + 20;
	var div=document.createElement("DIV");
	var img = new Image();
	img.src = imageURL;
	img.style.border='5px solid #000';
	
	img.onload=function(){
		div.id='popupImage';
		div.appendChild(img);
		div.style.position='absolute';
		div.style.width=(img.width)+"px";
		div.style.height=(img.height)+"px";
		//div.style.overflow='scroll';
		div.style.backgroundColor='#000';
		div.style.top  = scrollHeight +'px';
		div.style.left= ((screen.width - parseInt(div.style.width))/2)+'px';
		div.style.cursor='pointer';
		div.onclick=function(){
			document.body.removeChild(this);
		}
		document.body.appendChild(div);	
	}
	
	
	
}

function popImage(imageURL,imageTitle){
	PositionX = 100;
	PositionY = 100;
	defaultWidth = 500;
	defaultHeight = 500;
	var AutoClose = true;
	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=yes,width=150,height=100,left='+PositionX+',top='+PositionY;
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
	writeln('<html><head><title>Cargando ...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
	writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
	writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
	writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
	writeln('width=100-(document.body.clientWidth-document.images[0].width);');
	writeln('height=100-(document.body.clientHeight-document.images[0].height);');
	writeln('window.resizeTo(width,height);}');writeln('if (isNN){');
	writeln('window.innerWidth=document.images["imagenes"].width;');writeln('window.innerHeight=document.images["imagenes"].height;}}');
	writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
	if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body bgcolor=ffffff scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
	writeln('<img name="imagenes" src='+imageURL+' style="display:block"></body></html>');
	close();
	}
}
/***********************************************************************/
	
	<!-- Begin
	function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
		 even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		//alert("The username doesn't seem to be valid.")
		return false
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!")
			return false
			}
		}
		return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
		return false
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	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) {
	   // the address must end in a two letter or three letter word.
	   //alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   //alert(errStr)
	   return false
	}
	
	// If we've gotten this far, everything's valid!
	return true;
	}
	//  End -->
	
	
	function toggleRadio(rObj) {
		if (!rObj) return false;
		rObj.__chk = rObj.__chk ? rObj.checked = !rObj.__chk : rObj.checked;
	}
	
	function showWait(){
		var inner='<div style="float:left; margin-top:10px"><img src="../img/cargando.gif"></div><div style="float:left;margin-left:10px; margin-right:10px; margin-top:20px; font-size:16px"><i>Procesando información...</i></div>';
		var y1 = 100;   // change the # on the left to adjuct the Y co-ordinate
		var divWait=document.createElement("DIV");
		divWait.id='wait';
		divWait.name='wait';
		divWait.style.backgroundColor='#FFFFFF';
		divWait.style.border="1px solid black";
		divWait.style.position="absolute";
		divWait.style.left=((screen.width-172)/2)+'px';
		divWait.width='172px';
		divWait.height='62px';
		divWait.style.display='block';
		divWait.innerHTML=inner;
		document.body.appendChild(divWait);
		(document.getElementById) ? dom = true : dom = false;
		if (dom && !document.all) {document.getElementById("wait").style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1))}
		if (document.layers) {document.layers["wait"].top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1))}
		if (document.all) {document.all["wait"].style.top = document.body.scrollTop + (document.body.clientHeight - (document.body.clientHeight-y1));}
	}
	
	function hideWait(){
		var Node = document.getElementById('wait');
		Node.parentNode.removeChild(Node);	
	}
	
	function mouseCoords(ev){
		if(ev.pageX || ev.pageY){
			//document.getElementById('coords').value=(ev.pageX)+", "+(ev.pageY);
			return {x:ev.pageX, y:ev.pageY};
		}
		else{
			if (document.documentElement && !document.documentElement.scrollTop){
				scrollY=document.documentElement.scrollTop;
				scrollX=document.documentElement.scrollLeft;
			}
			// IE6 +4.01 but no scrolling going on
			else if (document.documentElement && document.documentElement.scrollTop){
				scrollY=document.documentElement.scrollTop;
				scrollX=document.documentElement.scrollLeft;
			}
			// IE6 +4.01 and user has scrolled
			else if (document.body && document.body.scrollTop){
				scrollY=document.body.scrollTop;
				scrollX=document.body.scrollLeft;
			// IE5 or DTD 3.2
			}
			//document.getElementById('coords').value=(ev.clientX + scrollX)+", "+(ev.clientY + scrollY);
			return {
				x:ev.clientX + scrollX,
				y:ev.clientY + scrollY
			};
		}	
	}
		
	function updateLista(lista,tabla,position_field,id_field,inicio){
		//Para explorer poner id y name en los elementos, ya que el
		//getElementsByName funciona solo con algunos tags. Pero si no puede
		//encontrar por name encuentra por id!
		var filas,listInputs,listNumbers,listIds,ids;
		filas=document.getElementsByName("listFila");
		listNumbers=document.getElementsByName("listNumber");
		listIds=document.getElementsByName("listId");
		ids=new Array();
		for(i=0;i<filas.length;i++){
			listNumbers[i].innerHTML=(i+1)+'.-'+'&nbsp;&nbsp;';
			ids.push(listIds[i].value);
			if(i==0 || i%2==0){
				filas[i].className="row";
				filas[i].onmouseout=function(){this.className='row';};
			}
			else{
				filas[i].className="row2";
				filas[i].onmouseout=function(){this.className='row2';};
			}
		}
		//alert(ids.join(','));
		ajax_do("_ajax.php?opc=orderList&ids="+ids.join(',')+"&table="+tabla+"&id_field="+id_field+"&position_field="+position_field+"&inicio="+inicio);
	}
	
	function checkDate(y,m,d){
	   y=document.getElementById(y);
	   m=document.getElementById(m);
	   d=document.getElementById(d);
	   if(m.value==2){
			if(y.value % 4==0){
				if(d.value>29){
					d.value=29;
				}
			}
			else{
				if(d.value>28){
				d.value=28;
				}
			}
	   }
	   else{
			if(m.value==4||m.vlaue==6||m.value==9||m.value==11){
				if(d.value>30){
					d.value=30;
				}
			}
	   }	 
	   
				
	}	
	
	function open_window( name, page, params ) {
		window.open( page, 'window_' + name, params );
	}
	
	function cambiar_anio( anio ) {
		document.reserva.anio.value	= anio;
		document.reserva.submit();
	}

	function rowOverEffect(object) {
		if (object.className == 'row') {
			object.className	= 'row_on';
		}
	}

	function rowOutEffect(object) {
		if (object.className == 'row_on') {
			object.className	= 'row';
		}
	}	
	function textCounter(field,maxlimit,evento) {
		if(in_array(evento.keyCode)){
			return;	
		}
		if (field.value.length > maxlimit){ // if too long...trim it!
				cancelEvent(evento);
				field.value = field.value.substring(0, maxlimit);
				ex=new Array('8','46','37','38','39','40');
		}
	}		
	
	function open_window( name, page, params ) {
		window.open( page, 'window' + name, params );
	}

	function rollOver( object, className ) {
		object.className = className;
	}

	function uploadFile(tipo,svar,idRegistro) {
		open_window( 'image', 'upload_file.php?svar='+svar+'&tipo='+tipo+'&idRegistro='+idRegistro, 'top=200, width=320, height=150, resizable=yes, scrollbars=yes, status=yes' );
	}
	
	function uploadGaleria(tipo,svar,idRegistro) {
		
		open_window( 'image', 'upload_galeria.php?ext=jpg,gif,png&svar='+svar+'&tipo='+tipo+'&idRegistro='+idRegistro, 'top=200, width=320, height=160, resizable=yes, scrollbars=yes, status=yes' );
	}
	
	function validateUser( ) {
		if ( document.login.username.value.length && document.login.password.value.length ) {
			document.login.submit();
		}
	}
  	function showIframe(iframe,label){
	  	if(document.getElementById(iframe).style.display=='block'){
			document.getElementById(iframe).style.display='none';
			label.innerHTML="+ "+label.innerHTML.replace('- ','');
		}
		else{
			document.getElementById(iframe).style.display='block';
			label.innerHTML="- "+label.innerHTML.replace('+ ','');
		}
 	 }

	function setOrder( id, current, direction ) {
		document.form.method			= 'GET';
		document.form.pos.value			= current;
		document.form.move.value		= direction;
		document.form.id.value			= id;
		document.form.exec.value		= 'set_order';
		document.form.submit();
	}
	
	function editRecord( id ) {
		document.form.method			= 'POST';
		document.form.exec.value		= 'edit';
		document.form.id.value			= id;
		document.form.submit();
	}
	
	function newRecord( ) {
		editRecord( 0 );
	}

	function changeStatus( id,table ) {
		
		ajax_do('_ajax.php?opc=changeStatus&id='+id+'&table='+table);
	}
	function changeStatusMain( id ) {
		document.form.exec.value		= 'status_main';
		document.form.id.value			= id;
		document.form.submit();
	}

	function changePrivate( id ) {
		document.form.exec.value		= 'private';
		document.form.id.value			= id;
		document.form.submit();
	}

	function changeNextStatus( id ) {
		document.form.exec.value		= 'next_status';
		document.form.id.value			= id;
		document.form.submit();
	}

	function changeOrderStatus( id, status ) {
		document.form.exec.value		= 'order_status';
		document.form.pos.value			= status;
		document.form.id.value			= id;
		document.form.submit();
	}

	function changeHighlight( id,table ) {
		ajax_do('_ajax.php?opc=highlightItem&id='+id+'&table='+table);
	}
	
	function changeHighlightNews( id,table ) {
		ajax_do('_ajax.php?opc=highlightNews&id='+id+'&table='+table);
	}
	
	function setHome( id,table ) {
		ajax_do('_ajax.php?opc=setHome&id='+id+'&table='+table);
	}

	function setDefaultUserLevel( id,table ) {
		ajax_do('_ajax.php?opc=setDefaultUserLevel&id='+id+'&table='+table);
	}

	function confirmDrop( id, table, sortable,order_field ) {
		if ( confirm( 'Confirm item drop?' ) ) {
			ajax_do('_ajax.php?opc=dropItem&table='+table+'&id='+id+'&sortable='+sortable+'&order_field='+order_field);
		}
	}
	
	function confirmImageDrop( image ) {
		if ( confirm( 'Está seguro que desea eliminar la imagen seleccionada?' ) ) {
			document.form.exec.value	= 'drop_image';
			document.form.image.value	= image;
			document.form.submit();
		}
	}

	function acceptContent( ) {
		document.form.exec.value		= 'save';
		document.form.submit();
	}

	function setViewStatus( ) {
		document.form.submit();
	}

	function updateCurrencies( ) {
		document.form.exec.value		= 'update_currencies';
		document.form.submit();
	}

	function cancelContent( ) {
		window.location=window.location;
	}

	function checkTextLength(l){
		aux=new String();
		aux=event.srcElement.value;
		if(aux.length>=l){
			event.returnValue=false;
		}
	}
	
	function checkFormForAtListOneField(frm){ //(formulario, array de excepciones)
		for(var i=0;i<document.getElementById(frm).elements.length;i++){
			if(document.getElementById(frm).elements[i].type == "password" || document.getElementById(frm).elements[i].type == "text" || document.getElementById(frm).elements[i].type == "select"  || document.getElementById(frm).elements[i].type == "textarea" || document.getElementById(frm).elements[i].type == "select-one" || document.getElementById(frm).elements[i].type == "select multiple"){
				if(document.getElementById(frm).elements[i].value!=""){
					return true;
				}
			}	
	   }
	   alert("You must enter search criteria in at least one field.");
	   return false;
	}	
	
	function checkForm(frm,arr){ //(formulario, array de excepciones)
		var aux="";
			for(var i=0;i<document.getElementById(frm).elements.length;i++){
       			if(document.getElementById(frm).elements[i].type == "password" || document.getElementById(frm).elements[i].type == "text" || document.getElementById(frm).elements[i].type == "select"  || document.getElementById(frm).elements[i].type == "textarea" || document.getElementById(frm).elements[i].type == "select-one" || document.getElementById(frm).elements[i].type == "select multiple"){
		       		if(!in_array(arr,document.getElementById(frm).elements[i].id)){ 
						//document.frmOp.elements[i].checked = true;
						if(document.getElementById(frm).elements[i].value==""){
							aux=aux+"\n"+document.getElementById(frm).elements[i].title;
						}
						else{
							if(document.getElementById(frm).elements[i].id.indexOf('email')!=-1){
								if(!emailCheck(document.getElementById(frm).elements[i].value)){
									aux=aux+"\n"+document.getElementById(frm).elements[i].title;
								}
							}	
						}
						
					}
				}	
		   }
		   if(aux!=""){
				aux="You must complete these fields:" + aux;
			   	alert(aux);
				return false;
		   }
		   else{
				return true;
		   }	
	}	
	
	function checkFormFields(frm,arr,idioma){ //(formulario, array de campos a validar)
			var aux="";
			for(var i=0;i<document.getElementById(frm).elements.length;i++){
       			if(document.getElementById(frm).elements[i].type == "password" || document.getElementById(frm).elements[i].type == "text" || document.getElementById(frm).elements[i].type == "select"  || document.getElementById(frm).elements[i].type == "textarea" || document.getElementById(frm).elements[i].type == "select-one" || document.getElementById(frm).elements[i].type == "select multiple" || document.getElementById(frm).elements[i].type == "select-multiple"){
					if(in_array(arr,document.getElementById(frm).elements[i].id)){ 
						if(document.getElementById(frm).elements[i].value==""){
							aux=aux+"\n"+document.getElementById(frm).elements[i].title;
						}
						else{
							if(document.getElementById(frm).elements[i].id.toLowerCase().indexOf('email')!=-1){
								if(!emailCheck(document.getElementById(frm).elements[i].value)){
									aux=aux+"\n"+document.getElementById(frm).elements[i].title;
								}
							}	
						}
					}
					
				}	
		   }
		  
		   if(aux!=""){
				if(idioma=='es'){
					aux="Debe completar los siguientes campos:" + aux;
				}
				if(idioma=='en'){
					aux="You must complete these fields:" + aux;
				}
			   	alert(aux);
				return false;
		   }
		   else{
				return true;
		   }	
	}	

	function in_array(mat,field){
			var i;
			for(i=0;i<mat.length;i++){
				if(mat[i].toLowerCase()==field.toLowerCase()){
					return true;
				}	
			}
			return false;	
	}


	function eventTrigger (e) {
	    	if (! e) e = event;
		    return e.target || e.srcElement;
	}
		
	function cancelEvent(e){
			if(navigator.userAgent.indexOf("MSIE")!=-1){
				e.returnValue=0;	
			}
			if(navigator.userAgent.indexOf("Gecko")!=-1){
				e.preventDefault();	
			}
	}
	function validateExtensions(file,ext,evt){
		var auxext=new String(file);
		var extPosibles;
		for (var i=0;i<ext.length;i++){
			if(i==0){
				extPosibles=ext[i];
			}
			else{
				extPosibles += ","+ext[i];
			}
		}
		auxext=auxext.substring(auxext.lastIndexOf('.')+1);
		if(!in_array(ext,auxext)){
			alert ("Sólo se admiten las siguientes extensiones: \n"+extPosibles);
			cancelEvent(evt);	
		}
		else{
			return true;	
		}
	
	}
//------------------------ORDENAMIENTO DE IMAGENES Y ARCHIVOS-------------------------------------------
	function ordenarElementos(lista,elemento,dir){
		
		lista=document.getElementById(lista);
		var elements = lista.getElementsByTagName('li');
		var pos=0;
		if(elemento!='' && elemento!=null){
			elemento=document.getElementById(elemento);
			for(var i=0;i<elements.length;i++){
				if(elements[i].id==elemento.id){
					pos=i;
					break;
				}
			}
			if(dir=='last'){
				lista.removeChild(elemento);
				//lista.appendChild(elemento);
				lista.insertBefore(elemento, null);
			}
			if(dir=='first'){
				if(elements.length>0){
					if(pos>0){
						lista.removeChild(elemento);
						lista.insertBefore(elemento, elements[0]);
					}
				}
			}
			if(dir=='up'){
				if(elements.length>0){
					var anterior;
					if(pos>0){
						for(var i=0;i<elements.length;i++){
							if(i==pos-1){
								anterior=elements[i];
								break;
							}	
						}
						lista.removeChild(elemento);
						lista.insertBefore(elemento,anterior);
					}
				}
			}	
			if(dir=='down'){
				if(elements.length>0){
					var siguiente;
					
					if(pos<elements.length-1){
						for(var i=0;i<elements.length;i++){
							if(i==pos+1){
								siguiente=elements[i];
								break;
							}
						}
						lista.removeChild(elemento);
						lista.insertBefore(elemento,siguiente.nextSibling);
					}
				}
			}
		}
		elements = lista.getElementsByTagName('li');
		
		for(var i=0;i<elements.length;i++){
			if(i==0){
				var botonera=document.getElementById('botonera_'+elements[i].id);
				botones=botonera.getElementsByTagName("img");
				botones[0].style.visibility='hidden';
				botones[1].style.visibility='hidden';
				botones[3].style.visibility='visible';
				botones[4].style.visibility='visible';
			}
			else if(i==elements.length-1){
				
				var botonera=document.getElementById('botonera_'+elements[i].id);
				botones=botonera.getElementsByTagName("img");
				botones[0].style.visibility='visible';
				botones[1].style.visibility='visible';
				botones[3].style.visibility='hidden';
				botones[4].style.visibility='hidden';
			}
			else{
				var botonera=document.getElementById('botonera_'+elements[i].id);
				botones=botonera.getElementsByTagName("img");
				botones[0].style.visibility='visible';
				botones[1].style.visibility='visible';
				botones[3].style.visibility='visible';
				botones[4].style.visibility='visible';
			}
		}	
		if( elements.length==1){
			var botonera=document.getElementById('botonera_'+elements[0].id);
			botones=botonera.getElementsByTagName("img");
			botones[0].style.visibility='hidden';
			botones[1].style.visibility='hidden';
			botones[3].style.visibility='hidden';
			botones[4].style.visibility='hidden';
		}
			
	}

	//SELECTS MULTIPLES
	function swapItems(idOrigen,idDestino,accion){
		var origen=document.getElementById(idOrigen);
		var destino=document.getElementById(idDestino);
		var selected=Array();
		var alreadySelectedValues=Array();

		for(var i=0;i<destino.options.length;i++){
			alreadySelectedValues.push(destino.options[i].value);	
		}
		
		while(origen.selectedIndex!=-1){
			if(!in_array(alreadySelectedValues,origen.options[origen.selectedIndex].value)){
				selected.push(origen.selectedIndex);
			}
			origen.options[origen.selectedIndex].selected=false;
		}

		for(var i=0;i<selected.length;i++){
		//while(origen.selectedIndex!=-1){
			var opt=document.createElement("OPTION");
			opt.text=trim(origen.options[selected[i]].text);
			opt.value=origen.options[selected[i]].value;
			if(opt.value=='')return;
			try {
				destino.add(opt, null); // standards compliant; doesn't work in IE	
			}
			catch(ex) {
				destino.add(opt); // IE only
			}
			origen.options[selected[i]].style.color='#CCC';
			//origen.remove(origen.selectedIndex);
		}
		if(accion == 'actualizar'){
			for(var i=0;i<origen.length;i++){
				var opt=document.createElement("OPTION");
				opt.text=trim(origen.options[i].text);
				opt.value=origen.options[i].value;
				if(in_array(alreadySelectedValues,opt.value)){
					origen.options[i].style.color='#CCC';
				}
			}
		}
	
		
		//Ordenar items
		for(var i=0;i<(destino.length-1);i++){
			for(var j=i+1;j<destino.length;j++){
				if(destino.options[i].text>destino.options[j].text){
					var texto=destino.options[i].text;
					var valor=destino.options[i].value;
					destino.options[i].text=trim(destino.options[j].text);
					destino.options[i].value=destino.options[j].value;
					destino.options[j].text=trim(texto);
					destino.options[j].value=valor;
				}
			}
		}
		
	}
	
	function restoreItems(idOrigen,idDestino){
		
		var origen=document.getElementById(idOrigen);
		var destino=document.getElementById(idDestino);
		
		if(origen.selectedIndex==-1)return;
		
		var selectedValues=Array();
		var unselectedValues=Array();
		var unselectedText=Array();

		
		for (var i=0 ; i < origen.options.length ; i++) {
			
			if (origen.options[i].selected==true) {
				selectedValues.push(origen.options[i].value);
			}
			else{
				unselectedValues.push(origen.options[i].value);
				unselectedText.push(origen.options[i].text);
			}
		}
		origen.length=0;
		for(var i =0; i< unselectedValues.length ; i++){
			addItem(unselectedText[i],idOrigen,unselectedValues[i]);
		}
		
		for(var i=0;i<destino.options.length;i++){
			if(in_array(selectedValues,destino.options[i].value)){
				destino.options[i].style.color='#000';
			}
		}
		for(var i=0;i<(origen.length-1);i++){
			for(var j=i+1;j<origen.length;j++){
				if(origen.options[i].text>origen.options[j].text){
					var texto=origen.options[i].text;
					var valor=origen.options[i].value;
					origen.options[i].text=origen.options[j].text;
					origen.options[i].value=origen.options[j].value;
					origen.options[j].text=texto;
					origen.options[j].value=valor;
				}
			}
		}
	}
	

	function addItem(text,lista,value){
		if(text!=''){	
			lista=document.getElementById(lista);
			for(var i=0;i<lista.length;i++){
				if(lista.options[i].text==text){
					return;
				}
			}
			var opt = document.createElement("OPTION");
			opt.text=text;
			opt.value=value;
			try {
					lista.add(opt, null); // standards compliant; doesn't work in IE	
				}
				catch(ex) {
					lista.add(opt); // IE only
			}
		}
	}
	
	function removeItem(lista){
		lista=document.getElementById(lista);
		while(lista.selectedIndex!=-1){
			lista.remove(lista.selectedIndex);
		}
	}
	
	function selectAllItems(combo){
		var lista=document.getElementById(combo);
		for(var i=0;i<lista.length;i++){
			var opt=lista.options[i];
			opt.selected=true;
		}
	}
	function trim(cadena){
		for(i=0; i<cadena.length; ){
			if(cadena.charAt(i)==" ")
				cadena=cadena.substring(i+1, cadena.length);
			else
				break;
		}
	
		for(i=cadena.length-1; i>=0; i=cadena.length-1){
			if(cadena.charAt(i)==" ")
				cadena=cadena.substring(0,i);
			else
				break;
		}
		
		return cadena;
	}
		


