
//
//  Copyright 2001 (c) Ismael Canales Luis.
//
//  This software is under G.P.L license 2.0.
// 


function confirm_jump(msg,link)
{
	ok=confirm(msg);
	if(ok)	document.location.href=link;
	return void(0);
}

function noerror(){
	return true;
}
//window.onerror = noerror;



function printit(){ 
	if ((navigator.appName == "Netscape")) { 
		window.print() ; 
	} else { 
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
		WebBrowser1.ExecWB(6, -1); 
		WebBrowser1.outerHTML = ""; 
	} 
}



  // anadido por pedro pla para que desactive los botones de form cuando se pulsan
  function desactiveForm(f) {
	//alert(f);
	if (document.all || document.getElementById) {
		for (i = 0; i < f.length; i++) {
			var t = f.elements[i];
			if ((t.type.toLowerCase() == "submit" || t.type.toLowerCase() == "reset") && t.name == "")
			t.disabled = true;
		}
	}
	return true;
  }

  function activeForm(f) {
	//alert(f);
	if (document.all || document.getElementById) {
		for (i = 0; i < f.length; i++) {
			var t = f.elements[i];
			if ((t.type.toLowerCase() == "submit" || t.type.toLowerCase() == "reset") && t.name == "")
			t.disabled = false;
		}
	}
	return true;
  }


  function date_check_not_actual(inicio,finales){

		var splitstart;
		var splitend;
							 
						 
		fechainicio=inicio;
		fechafinal=finales;
													   
											   
	   	splitstart=fechainicio.split("/");
	   	splitend=fechafinal.split("/");
           	if (splitstart[1].length<2) splitstart[1] = '0'+splitstart[1];
           	if (splitstart[0].length<2) splitstart[0] = '0'+splitstart[0];
	  
		if (splitend[1].length<2) splitend[1] = '0'+splitend[1];
		if (splitend[0].length<2) splitend[0] = '0'+splitend[0];
	   
		if (splitstart[2] > splitend[2]) return false;
		if ((splitstart[2] == splitend[2])  && (splitstart[1] >  splitend[1])) return false;
		if ((splitstart[2] == splitend[2]) && (splitstart[1] == splitend[1]) && (splitstart[0]  > splitend[0])) return false;
		return  true;
  }
  
  
  
  function date_check(inicio, finales) {
           var splitstart;
	   var splitend;
	   var actualdate=new Date();
								 
						 
	   fechainicio=inicio;
	   fechafinal=finales;
													   
											   
	   splitstart=fechainicio.split("/");
	   splitend=fechafinal.split("/");
           if (splitstart[1].length<2) splitstart[1] = '0'+splitstart[1];
           if (splitstart[0].length<2) splitstart[0] = '0'+splitstart[0];
	  
           if (splitend[1].length<2) splitend[1] = '0'+splitend[1];
           if (splitend[0].length<2) splitend[0] = '0'+splitend[0];
	  
	   
	   if (actualdate.getUTCFullYear() > splitstart[2]) return false;
	   if ((actualdate.getUTCFullYear() == splitstart[2]) && ((actualdate.getUTCMonth()+1) >  splitstart[1])) return false;
	   
	   if ((actualdate.getUTCFullYear() == splitstart[2]) && ((actualdate.getUTCMonth()+1) == splitstart[1]) && (actualdate.getUTCDate() > splitstart[0])){ return false;}
	   
	  if (splitstart[2] > splitend[2]) return false;
	  if ((splitstart[2] == splitend[2])  && (splitstart[1] >  splitend[1])) return false;
	  if ((splitstart[2] == splitend[2]) && (splitstart[1] == splitend[1]) && (splitstart[0]  > splitend[0])) return false;
	  return  true;
  }

  function check_date_format(date_field,format)
  {
	format=format.toLowerCase();
  	if (format=="dd/mm/yyyy"){ format ="^([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})$"; d=1; m=2; y=3; }
	if (format=="mm/dd/yyyy"){ format ="^([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})$"; d=2; m=1; y=3; }
	
	v = new RegExp(format,"gi")
	date=date_field.value;
	if (date!='')
	{
		if (date.search(v)!=0)
		{
			date_field.focus();
			date_field.select();
			alert("Incorrect date format");
			return false;
		}else{
			arr = date.match(format);
			if (arr[d]<1 || arr[d]>31 || arr[m]<1 || arr[m]>12 || arr[y]<1)
			{
				date_field.focus();
				date_field.select();
				alert("Incorrect date format");
				return false;
			}else{
				return true;
			}
		}
	}else{
		return true;
	}
  	
  
  }
																																									      
  function check_time_format(time_field)
  {
  	var format ="^([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})$";
	
	v = new RegExp(format,"g")
	time=time_field.value;
	if (time!='')
	{
		if (time.search(v)!=0)
		{
			time_field.focus();
			time_field.select();
			alert("Incorrect time format");
			return false;
		}else{
			arr = time.match(format);
			if (arr[1]<0 || arr[1]>23 || arr[2]<0 || arr[2]>59 || arr[3]<0 || arr[3]>59)
			{
				time_field.focus();
				time_field.select();
				alert("Incorrect time format");
				return false;
			}else{
				return true;
			}
		}
	}else{
		return true;
	}
  	
  
  }



//Funcion discriminadora devuleve True en caso de Microsoft Internet Explorer
//False en cualquier otro caso
//Si se le pasa una version de explorer la comprueba
//por ejemplo

	function is_explorer(){
	
          var explorador="";
	  var cadena_explorer="Microsoft Internet Explorer";
		    
	  explorador=navigator.appName;
	  if (explorador.search(cadena_explorer)!=-1){
	     return true;
	  }else{
	     return false;
	  }
								 
	 }
						     
//genera un frame, necesa pasarle la url, un nombre, el ancho y el alto, el scroll esta desactivado

									     
//	function generar_iframe(url,nombre,ancho,alto){
//	    document.write('<iframe name="'+nombre+'" src="'+url+'width="'+ancho+'" height="'+alto+'" scrolli
//	    document.write ("<form  target='"+nombre+'" action="'+url+'">');
//	    document.write ('<INPUT type="submit"    onClick="carga(\''+url+'\',\''+nombre+'\')" id='+nombre+
//	    document.write ("</form>");
//	    document.write ('</iframe>');
	    //oculta_layer(nombre);
//	}
																								     

//muestra iframe , solo iexplorer
    function muestra_iframe(nombre){
	if (is_explorer()){
	    document.all[nombre].style.visibility='visible';
	}else{
	    iframeElement=document.getElementById(nombre);
    	    iframeElement.visibility="show";
        
	}
    }
			     

//oculta iframe, solo iexplore
    
    function oculta_iframe(nombre){
	if (is_explorer()){
	    document.all[nombre].style.visibility='hidden';
	}else{
	    iframeElement=document.getElementById(nombre);
    	    iframeElement.visibility="hide";
	    
	}
    }


function visibility(id,visible){
	try{
		obj=document.getElementById(id);
		if(visible){
		    obj.style.visibility='visible';
		}else{
		    obj.style.visibility='hidden';
		}
	}catch(e){
		alert(e)
	}
}

function display(id,visible){
	try{
		obj=document.getElementById(id);
		if(visible){
		    obj.style.display='inline';
		}else{
		    obj.style.display='none';
		}
	}catch(e){
		alert(e)
	}
}

			
//cargr el iframe
    															   
    function carga_iframe(url,nombre)
    {
	
	if (is_explorer()){
	    document.all[nombre].src=url;
	}else{
	    window.frames[nombre].location.href=url;
	}
    }
																										    
//funcion para rescalar iframe, nombre iframe, ancho, y alto final
function resize_iframe (nombre,ancho,alto)
{
    
	if (is_explorer()){
          if ((ancho>=0) && (alto>=0)) {
              document.all[nombre].style.width=ancho;
	      document.all[nombre].style.height=alto;
	        
	  }							
	  
	}else{
    	      iframeElement=document.getElementById(nombre);
              iframeElement.width=ancho;
              iframeElement.height=alto;
        }
    
																				  
}
																				     
// funcion que muestra un iframe aumentando el tamaño, se le pasa, el nombre del iframe, el ancho final,el alto final
// ancho inicial, alto inicial, y paso osea el incremento en pixeles para el ejex																				     
function resize_iframe_stepped(nombre,finalx,finaly,ancho,alto,step)
{
    var paso=0.0;
    //var mate=new maths
    paso=(finaly/finalx);
    
    if (step>0) {
        if (ancho<finalx) {
	    ancho=ancho+step;
	    alto=alto+(paso*step);
    	    cadena="resize_iframe_stepped('"+nombre+"',"+finalx+","+finaly+","+ancho+","+alto+","+step+");";
	    //alert ("ancho:"+ancho+"  "+"alto: "+alto+" finalx:"+finalx+" finaly:"+finaly+" step:"+step);
	    resize_iframe (nombre,ancho,alto);
    	    setTimeout (cadena,1);
	}
    }else{
	if (finalx>ancho) {
	    finalx=finalx+step;
	     finaly=finaly+(paso*step);
	    //alert ("ancho:"+ancho+"  "+"alto: "+alto+" finalx:"+finalx+" finaly:"+finaly+" step:"+step);
	    cadena="resize_iframe_stepped('"+nombre+"',"+finalx+","+finaly+","+ancho+","+alto+","+step+");";
	    if (finalx>=0)
		    resize_iframe (nombre,finalx,finaly);
    	    setTimeout (cadena,1);
	}
    }
    
}    
										


 //funcion para reescalar un iframe en vertical y horizontal, 
 // definicion de parametros
 // nombre: nombre del iframe
 // finalx,finaly: ancho y alto final
 // ancho, alto: ancho y alto inicial
 // step: paso , positivo, aumenta negativo disminiye, ojo no se hace comprobacion de valores iniciales
 //       los valores deben ser coherentes
 // tipo: 0 reescala en horizontal, 1 reescala en vertical, horizontal en beta
function resize_iframe_steppedhv(nombre,finalx,finaly,ancho,alto,step,tipo)
{
    
    if (tipo==0){ 
          ancho=ancho+step;
	  alto=finaly;
    }else{	
          
          alto=alto+step;
	  //alert(alto);
	  ancho=finalx;
    }
      
    if (step>0) {
        if (((tipo==1) && (alto<finaly)) || ((tipo==0) && (ancho<finalx))){
            cadena="resize_iframe_steppedhv('"+nombre+"',"+finalx+","+finaly+","+ancho+","+alto+","+step+","+tipo+");";
	    //alert (cadena);
	    resize_iframe (nombre,ancho,alto);
    	    setTimeout (cadena,1);
	  
	}  
    }else{
	if (((tipo==1) && (alto>finaly)) || ((tipo==0) && (ancho>finalx))){    
	    
	    
	    cadena="resize_iframe_steppedhv('"+nombre+"',"+finalx+","+finaly+","+ancho+","+alto+","+step+","+tipo+");";
	    //alert(cadena);
	    resize_iframe (nombre,ancho,alto);
    	    setTimeout (cadena,1);
	}    
	
    }	
    
    
}    


	function endLayer()
	{
		var a;
		
	//	if (!is_explorer()){
	//		a='</layer>';
	//	}else{
			a='</div>';	
	//	}
		return a;

	}
	function beginLayer(layer,layerTgt,visible,style,x,y)
	{
		if(visible=='hide'){
			style='visibility:hidden; '+style
		}
		document.write('<DIV id='+layer+'  onMouseOver=\"hide(1,\''+layerTgt+'\'); return true\" onMouseOut=\"hide(0,\''+layerTgt+'\'); return true\" style=\"position:absolute; left:'+x+'; top:'+y+'; '+style+'\" >');
	}

	// Se hace visible cuando 
	function beginLayer2(layer,layerTgt,visible,style,x,y,other_layers)
	{
		if(visible=='hide'){
			style='visibility:hidden; '+style
		}
		document.write('<DIV id='+layer+' style=\"position:absolute; left:'+x+'; top:'+y+'; '+style+'\" >');
	}
	
	function addMenuIframe(menu_name)
	{
		// Crea un iframe justo antes de la capa del menu con las mismas dimensiones que esta para evitar
		// que los pulldowns aparezcan por encima de la capa (bug IE)
			
		if (document.all)
		{
			menu = document.getElementById(menu_name);

			//creo el iframe
			var iframeEl = document.createElement("IFRAME");
			iframeEl.frameBorder = 1;
			iframeEl.src = "javascript:false;";
			iframeEl.style.display = "none";
			iframeEl.style.position = "absolute";
			iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
			
			if (menu.iframeEl==null)
			{
				// si no tiene el iframe ya creado se lo añado
				menu.iframeEl = menu.parentNode.insertBefore(iframeEl, menu);
			}
			
			// redimensiono el iframe para ajustarlo a la capa
			if (menu.iframeEl != null)
			{
				menu.iframeEl.style.left = menu.style.left;
				menu.iframeEl.style.top  = menu.style.top;
				menu.iframeEl.style.width  = menu.offsetWidth + "px";
				menu.iframeEl.style.height = menu.offsetHeight + "px";
				menu.iframeEl.style.display = "";
			}
		}
	}

	function removeMenuIframe(menu_name)
	{
		if (document.all)
		{
			// Elimina el iframe anti-pulldowns
			menu = document.getElementById(menu_name);
			
			menu.iframeEl.style.display = 'none';
		}
	}

	function hide(on,layer){
		if( window.cargada==1 ){
			obj=document.getElementById(layer);
			if( on >0 ){
					obj.style.visibility='visible'
			}else{
					obj.style.visibility='hidden'
			}
		}
	}

	// Activa la capa actual y desactiva las demas, si las hay
	function activeLayer (layer,other_layers)
	{
		var a=other_layers.split(',')
		var active_tab=-1
		
		for (i=0;i<a.length;i++) {
//			alert('Oculta '+a[i])
			if (a[i]!=layer) {
				hide(0,a[i])
			} else {
				active_tab=i
			}
		}
		hide(1,layer)
		
		if (active_tab!=-1) {
			document.cookie='menu_tab_active='+active_tab
		}
//		alert('hasta aqui '+other_layers);
	}


	function set_form_jump(form,jump,url)
	{
		form.jump.value=jump; form.action=url;
	}

	var lastwin;

	function popup(url){
		window.open(url,'_blank',"location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes");
	}

	function openWindow(url,name,width,height){
		win=window.open(url,name,"height="+height+",width="+width+",location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes");
		center_window(win,width,height);
		win.focus();
		lastwin = win;
	}

	function openBrowser(url,name,width,height)
	{
		win=window.open(url,name,"height="+height+",width="+width+",location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
		center_window(win,width,height);
		win.focus();
		lastwin = win;
	
	}

	function openDialog(url,name,width,height){
	         
		 win=window.open(url,name,"height="+height+",width="+width+",location=no,menubar=no,resizable=yes,scrollbars=auto,status=no");
		 
		 center_window(win,width,height);
		 win.focus();
		lastwin = win;
	}
	function openDialogXY(url,name,width,height,x,y){
	         
		 win=window.open(url,name,"height="+height+",width="+width+",location=no,menubar=no,resizable=yes,scrollbars=auto,status=no");
		 
		 win.moveTo(x,y);
		 win.focus();
		lastwin = win;
	}
	
	function openDialogScrolledXY(url,name,width,height,x,y){
	         
		 win=window.open(url,name,"height="+height+",width="+width+",location=no,menubar=no,resizable=yes,scrollbars=yes,status=no");
		 
		 win.moveTo(x,y);
		 win.focus();
		lastwin = win;
	}

	function openDialog2(url,name,width,height){
	         
		 if (window.win) window.win.close();
		 win=window.open(url,name,"height="+height+",width="+width+",location=no,menubar=no,resizable=yes,scrollbars=auto,status=no");
		 center_window(win,width,height);
		 win.focus();
		lastwin = win;
	}
	function openDialogScrolled(url,name,width,height){
	         
		 win=window.open(url,name,"height="+height+",width="+width+",location=no,menubar=no,resizable=yes,scrollbars=yes,status=no");
		 
		 center_window(win,width,height);
		 win.focus();
		lastwin = win;
	}

	function swap_background(object,image){
		object.background=image	
	}
	
	function swap_bgcolor(object,color){
		object.bgcolor=color
	}	

	var sw_style_bg=new Array();

	function swap_tr_bgcolor(tr,color1){
		tds=tr.getElementsByTagName("td")
		for(i=0;i<tds.length;i++){
			td=tds.item(i)
			sw_style_bg[i]=td.getAttribute('bgcolor')
			td.style.backgroundColor=color1
		}
	}

	function restore_bg(tr)
	{
		tds=tr.getElementsByTagName("td")
		for(i=0;i<tds.length;i++){
			td=tds.item(i)
			td.style.backgroundColor=sw_style_bg[i]
		}
	}

	var sw_style_bg_vert=new Array();

	function mark_td(td,color,restore){
		if( window.cargada && window.cargada==1){
			trx=td.parentNode
			tbody=trx.parentNode
			tds=trx.getElementsByTagName("td")
			soy=-1
			len=tds.length
			for(i=0;i<tds.length;i++){
				mtd=tds.item(i)
				if( td == mtd ){
					soy=i
				}
			}

			tds2=trx.getElementsByTagName("td")
			for(i=0;i<tds.length;i++){
					td=tds2.item(i)
					if(!restore){
						sw_style_bg[i]=td.getAttribute('bgcolor')
						if( i != soy){
							td.setAttribute('bgcolor',color)
						}
					}else{
						td.setAttribute('bgcolor',sw_style_bg[i])
					}
			}

			if( soy != -1){
				trs=tbody.getElementsByTagName("tr")
				for(i=0;i<trs.length;i++){
						tr=trs.item(i)
						tds=tr.getElementsByTagName("td")
						if (tds.length == len) {
							td=tds[soy]
							if(td){
								if(!restore){
									sw_style_bg_vert[i]=td.getAttribute('bgcolor')
									td.setAttribute('bgcolor',color)
								}else{
									td.setAttribute('bgcolor',sw_style_bg_vert[i])
									
								}
							}
						}
				}
			}
		}
		
	}


	function findFormField(name,form)
	{
		var i;
		for ( i=0 ; i < form.length ; i++) {
			if( form[i].name == name){
				return form[i];
			}
		}
		alert('form '+form.name+' or field '+name+'not found');
		return false;
	}



	function set_form_time_value(formNumber,nameField,hour,time){
		form= document.forms[formNumber];

		oy=findFormField(nameField+'[hour]',form);	
		if(oy!=false)find_and_select_value(oy,hour);
		
		om=findFormField(nameField+'[min]',form);	
		if(om!=false)find_and_select_value(om,time);

	}

	function set_form_date_value(formNumber,nameField,year,month,day){

		form= opener.document.forms[formNumber];
		
		oy=findFormField(nameField+'[year]',form.elements);	
		find_and_select_value(oy,year);
		
		om=findFormField(nameField+'[month]',form.elements);	
		find_and_select_value(om,month);

		od=findFormField(nameField+'[day]',form.elements);	
		find_and_select_value(od,day);

	}

	function get_form_date(form,nameField){

		oy=findFormField(nameField+'[year]',form.elements);	
		oy=oy.options[oy.selectedIndex].value;
		
		om=findFormField(nameField+'[month]',form.elements);	
		om=om.options[om.selectedIndex].value;

		od=findFormField(nameField+'[day]',form.elements);	
		od=od.options[od.selectedIndex].value;

		return oy+'-'+om+'-'+oy ;
	}


	function get_select(form,nameField)
	{
		om=findFormField(nameField,form.elements);	
		id=om.options[om.selectedIndex].value;
		val=om.options[om.selectedIndex].text;
		return [id,val];
	}

	function get_select_value(form,nameField)
	{
		r=get_select(form,nameField);
		return r[1];
	}

	function find_and_select_value(field,value){
		var a=0;
		var finded=0;
		for(i=0;i<field.options.length;i++){
			if(field.options[i].value==value){
				if( i != 0){	
					field.selectedIndex=i;
					return i;			
				}else{
					a=1;
				}
			}
		}

		/*
		if(a){
			field.selectedIndex=0;
		}else{
			opt=new Option();
			opt.value=value;
			opt.text=value;
			opt.selected=true;
			field.options[field.options.length]=opt;
			field.selectedIndex=field.options.length-1;
		}
		*/
		return -1;
	}

	function get_form_by_object(objt){
		var i;
		for(i=0;i<document.forms.length;i++){
			if(document.forms[i] == objt){
				return i;
			}
		}
		return -1;
	}

	//function center_window(win)
	//{
		//win.self.screenX=(self.screen.height-win.height)/2
		//win.self.screenY=(self.screen.width-win.width)/2
		
	//}
	function center_window (win,width,heigth)
	  {
	        win.moveTo((screen.width-width)/2,(screen.height-heigth)/2);
		  
	  } 



function cookie_set(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
}


function cookie_get(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function  cookie_del(name)
{
	cookie_set(name,"",-1);
}

function carro_add(id_producto,num_objetos)
{
	ok = confirm("The article will be added to your cart, are you sure?");
	if (ok == true){
		prenum=cookie_get('carro['+id_producto+']');
		if( prenum != null) num_objetos = parseInt(num_objetos) + parseInt(prenum);

		if( num_objetos <=0)	carro_del(id_producto);
		else	cookie_set('carro['+id_producto+']',num_objetos,30);
	}
}


function carro_del(id_producto)
{
	ok = confirm("The article will be deleted from your cart, are you sure?");
	if (ok==true) 
	{
		num = cookie_get('carro['+id_producto+']');
		if (num > 1){
			cookie_set('carro['+id_producto+']', num-1, 30);
		}else{
			cookie_del('carro['+id_producto+']');
			
		}
		window.location.reload();
		alert("The article was deleted");


	}
}


function check(form_field,tipo,msg){

	try{
	ok=true;
	if (form_field.value !='')
	{
		if( tipo == 'int'){
			val=form_field.value;
			if (val!='')
			{
				for(i=0;i<val.length && ok;i++){
					ok= ( val.charAt(i) >= '0' && val.charAt(i) <= '9' ) || val.charAt(i)=='-';
				}
			}
		}


		if( tipo == 'year'){
			val=form_field.value;
			if (val!='')
			{
				for(i=0;i<val.length && ok;i++){
					ok= ( val.charAt(i) >= '0' && val.charAt(i) <= '9' ) || val.charAt(i)=='-';
				}
				if( ok){
					year=parseInt(val)
					if( year <=0 ) ok =false
				}
			}
		}
		
		if( tipo == 'real'){
			val=form_field.value;
			if (val!='')
			{
//				val=val+'';
				dot=false;
				for(i=0;i<val.length && ok;i++){
					ok= ( val.charAt(i) >= '0' && val.charAt(i) <= '9' ) || val.charAt(i)=='-' || (!dot && val.charAt(i)=='.') ||  val.charAt(i)==',';
					//Fuerzo un solo punto
					if(val.charAt(i)=='.') dot=true;
				}
			}
			//Compruebo que haya algo tras el punto
			if ((val.indexOf('.')+1)==val.length)
			{
				ok=false;
			}
		}
		
		if( tipo == 'email'){
			val=form_field.value;
			if (val!='')
			{
				k=val.indexOf('@')
				// no es -1 y la @ no es el primer caracter
				ok=k>0
				k++
				// ya tenemos @ amos a ver si hay algo despues del @
				if( ok){
					ok=val.length>k
				}
			}
		}
		
		if( tipo == 'url'){
			val=form_field.value;
			if (val!='')
			{
				k=val.indexOf('http://');
				ks=val.indexOf('https://');
				if (k!=0 && ks!=0)
				{
					ok=false;
				}
			}
		}
		
		if( !ok ) { 
			//form_field.focus();
			//form_field.select();
			alert(msg);
		};
	}
	}catch(e){
		ok=false;
		alert(msg);
	}
	return ok;
}


// From the google

function insertAtCursor(myField, myValue) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

/******************************************
* Find In Page Script -- Submitted/revised by Alan Koontz (alankoontz@REMOVETHISyahoo.com)
* Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code
* This notice must stay intact for use
******************************************/

//  revised by Alan Koontz -- May 2003

var TRange = null;
var dupeRange = null;
var TestRange = null;
var win = null;


//  SELECTED BROWSER SNIFFER COMPONENTS DOCUMENTED AT
//  http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var nom = navigator.appName.toLowerCase();
var agt = navigator.userAgent.toLowerCase();
var is_major   = parseInt(navigator.appVersion);
var is_minor   = parseFloat(navigator.appVersion);
var is_ie      = (agt.indexOf("msie") != -1);
var is_ie4up   = (is_ie && (is_major >= 4));
var is_not_moz = (agt.indexOf('netscape')!=-1)
var is_nav     = (nom.indexOf('netscape')!=-1);
var is_nav4    = (is_nav && (is_major == 4));
var is_mac     = (agt.indexOf("mac")!=-1);
var is_gecko   = (agt.indexOf('gecko') != -1);
var is_opera   = (agt.indexOf("opera") != -1);


//  GECKO REVISION

var is_rev=0
if (is_gecko) {
var temp = agt.split("rv:")
var is_rev = parseFloat(temp[1])
}


//  USE THE FOLLOWING VARIABLE TO CONFIGURE FRAMES TO SEARCH
//  (SELF OR CHILD FRAME)

//  If you want to search another frame, change from "self" to
//  the name of the target frame:
//  e.g., var frametosearch = 'main'

//var frametosearch = 'main';
var frametosearch = self;

function findString(text) {

	var whichframe=this

//  TEST FOR IE5 FOR MAC (NO DOCUMENTATION)

if (is_ie4up && is_mac) return;

//  TEST FOR NAV 6 (NO DOCUMENTATION)

if (is_gecko && (is_rev <1)) return;

//  TEST FOR Opera (NO DOCUMENTATION)

if (is_opera) return;

//  INITIALIZATIONS FOR FIND-IN-PAGE SEARCHES

if(text!=null && text!='') {

       str = text;
       win = whichframe;
       var frameval=false;
       if(win!=self)
{
       frameval=true;  // this will enable Nav7 to search child frame
       win = parent.frames[whichframe];

}

    
}

else return;  //  i.e., no search string was entered

var strFound;

//  NAVIGATOR 4 SPECIFIC CODE

if(is_nav4 && (is_minor < 5)) {
   
  strFound=win.find(str); // case insensitive, forward search by default

//  There are 3 arguments available:
//  searchString: type string and it's the item to be searched
//  caseSensitive: boolean -- is search case sensitive?
//  backwards: boolean --should we also search backwards?
//  strFound=win.find(str, false, false) is the explicit
//  version of the above
//  The Mac version of Nav4 has wrapAround, but
//  cannot be specified in JS

 
        }

//  NAVIGATOR 7 and Mozilla rev 1+ SPECIFIC CODE (WILL NOT WORK WITH NAVIGATOR 6)

if (is_gecko && (is_rev >= 1)) {
   
    if(frameval!=false) win.focus(); // force search in specified child frame
    strFound=win.find(str, false, false, false, false, frameval, false);

//  The following statement enables reversion of focus 
//  back to the search box after each search event 
//  allowing the user to press the ENTER key instead
//  of clicking the search button to continue search.
//  Note: tends to be buggy in Mozilla as of 1.3.1
//  (see www.mozilla.org) so is excluded from users 
//  of that browser.

//  if (is_not_moz)  findthis.focus();

//  There are 7 arguments available:
//  searchString: type string and it's the item to be searched
//  caseSensitive: boolean -- is search case sensitive?
//  backwards: boolean --should we also search backwards?
//  wrapAround: boolean -- should we wrap the search?
//  wholeWord: boolean: should we search only for whole words
//  searchInFrames: boolean -- should we search in frames?
//  showDialog: boolean -- should we show the Find Dialog?


}

 if (is_ie4up) {

  // EXPLORER-SPECIFIC CODE revised 5/21/03

  if (TRange!=null) {
	  
   TestRange=win.document.body.createTextRange();
 
	  

   if (dupeRange.inRange(TestRange)) {

   TRange.collapse(false);
   strFound=TRange.findText(str);
    if (strFound) {
        //the following line added by Mike and Susan Keenan, 7 June 2003
        win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop;
        TRange.select();
        }


   }
   
   else {

     TRange=win.document.body.createTextRange();
     TRange.collapse(false);
     strFound=TRange.findText(str);
     if (strFound) {
        //the following line added by Mike and Susan Keenan, 7 June 2003
        win.document.body.scrollTop = TRange.offsetTop;
        TRange.select();
        }



   }
  }
  
   if (TRange==null || strFound==0) {
   TRange=win.document.body.createTextRange();
   dupeRange = TRange.duplicate();
   strFound=TRange.findText(str);
    if (strFound) {
        //the following line added by Mike and Susan Keenan, 7 June 2003
        win.document.body.scrollTop = TRange.offsetTop;
        TRange.select();
        }

   
   }

 }

  if (!strFound) alert ("String '"+str+"' not found!") // string not found

}

function stat(id_proyect,tipo,debug)
{
	parm="";
	parm+="id_project="+id_proyect;
	parm+="&tipo="+tipo;
	parm+="&screen_with="+screen.width;
	parm+="&screen_height="+screen.height;
	parm+="&screen_title="+escape(document.title);
	parm+="&url="+escape(document.location.href);
	url="stat_watcher/stat.php?"+parm;
	if(! debug){
		document.write('<img width=1 height=1 src="'+url+'" alt="Stats">');
 	}else{
	//	alert(url);
		document.write('<img width=1 height=1 src="'+url+'" alt="Stats">');
	}
}

function getOffsetLeft(layer) {
	var value = 0;
	if (DOM) {      
		object = document.getElementById(layer);
		value = object.offsetLeft;
		while (object.tagName != "BODY" && object.offsetParent) {
			object = object.offsetParent;
			value += object.offsetLeft;
		}
	} else if (NS4) {
		value = document.layers[layer].pageX;
	} else {    
		if (document.all["IE4" + layer]) {
		layer = "IE4" + layer;
	}
		object = document.all[layer];
		value = object.offsetLeft;
		while (object.tagName != "BODY") {
			object = object.offsetParent;
			value += object.offsetLeft;
		}
	}
	return (value);
}

function getOffsetTop(layer)
{
	// IE 5.5 and 6.0 behaviour with this function is really strange:
	// in some cases, they return a really too large value...
	// ... after all, IE is buggy, nothing new
	var value = 0;
	if (DOM) {
		object = document.getElementById(layer);
		value = object.offsetTop;
		while (object.tagName != 'BODY' && object.offsetParent) {
			object = object.offsetParent;
			value += object.offsetTop;
		}
	} else if (NS4) {
		value = document.layers[layer].pageY;
	} else {        // IE4 IS SIMPLY A BASTARD !!!
		if (document.all['IE4' + layer]) {
			layer = 'IE4' + layer;
		}
		object = document.all[layer];
		value = object.offsetTop;
		while (object.tagName != 'BODY') {
			object = object.offsetParent;
			value += object.offsetTop;
		}
	}
	return (value);
}

function findObj(n, d) { //v4.01

var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
 
}

function validateForm_es_ES() { //v4.0
  	var index,i,p,q,nm,test,num,min,max,errors='',args=validateForm_es_ES.arguments;
	for (i=1; i<(args.length-3); i+=4){ 
		test=args[i+0]; val=args[0][args[i+2]];
	if( val == null ){
		val=args[0][args[i+2]+'[value]'];
	}
		if (val){
			nm=val.name; 
			if ((val=val.value)!=""){
				if (test.indexOf('isEmail')!=-1){ 
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener un email valido\n';
				} else if (test!='R'){ 
					num = parseFloat(val);
					if (isNaN(val)) errors+='- '+args[i+3]+' debe contener un n&uacute;mero.\n';
					if (test.indexOf('inRange') != -1){ 
						p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nm+' debe contener un n&uacute;mero entre '+min+' y '+max+'.\n';
					} 
				}
			} else if (test.charAt(0) == 'R') {
				errors += '- El campo "'+args[i+3]+'" es obligatorio.\n';
			}
		}
	} 
	if (errors) alert(errors);
	document.returnValue = (errors == '');
	return document.returnValue;
}


function validateForm_en_GB() { //v4.0
  var index,i,p,q,nm,test,num,min,max,errors='',args=validateForm_en_GB.arguments;



  for (i=1; i<(args.length-3); i+=4) 
  { 
    test=args[i+0]; 
    //val=findObj(args[i+2]);
    test=args[i+0]; val=args[0][args[i+2]];
	if( val == null ){
		val=args[0][args[i+2]+'[value]'];
	}
    if (val) 
    {
	nm=val.name; 
	if ((val=val.value)!="") 
	{
	      if (test.indexOf('isEmail')!=-1) 
	      { 
	      	p=val.indexOf('@');
	        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain a valid email\n';
	      } else if (test!='R'){ 
	      	num = parseFloat(val);
	        if (isNaN(val)) errors+='- '+args[i+3]+' must contain a number.\n';
	        if (test.indexOf('inRange') != -1) 
		{ 
			p=test.indexOf(':');
		        min=test.substring(8,p); max=test.substring(p+1);
		        if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
		} 
	}
   } else if (test.charAt(0) == 'R') {
   		errors += '- The field "'+args[i+3]+'" is obligatory.\n';
	}
   }
  } 
  if (errors) alert(errors);
  document.returnValue = (errors == '');
  return document.returnValue;
}


function decrypt(cad)
{
	a="";
	for( i=0 ; i<cad.length ; i++){
	  a+=String.fromCharCode(33^cad.charCodeAt(i))
	}
	return a;
}

function resize_fit_content(){
	var altura_ventana=document.alto.height+30;
	var anchura_ventana=document.ancho.width+10;
	var max_altura=700;
	var max_anchura=1000;

	if(anchura_ventana>max_anchura) anchura_ventana=max_anchura;
	if(altura_ventana>max_altura) altura_ventana=max_altura;

	if (is_explorer()){
		window.resizeTo(anchura_ventana,altura_ventana);
	}else{
		window.innerWidth=anchura_ventana;
		window.innerHeight=altura_ventana;
   	}
	
	center_window(window,anchura_ventana,altura_ventana);
}


function selectListItem_change_selected(form,selectedIndex)
{
	lista = form.elements;	
	for (i=0;i<=lista.length;i++)
	{
		if (lista[i])
		{
			check=document.getElementById(lista[i].id);
			if(check!=null && check.type=='select-one')	
			{
				check.selectedIndex=selectedIndex
			}
		}
		
	}
	
}


function checkListItem_select_all(form,field_id)
{
	lista = form.elements;	
	base_name=field_id.replace(/\[(\d+)?\]/,'')
	for (i=0;i<=lista.length;i++) {
		if (lista[i]) {
			try
			{
				check=document.getElementById(lista[i].id)
				if (check && check.type && lista[i].id.indexOf(base_name)==0) {
					if (check.type=='checkbox') {
						if(check.checked==false) check.click()
					}
				}
			}catch(e){
			
			}
		}
	}
}

function checkListItem_deselect_all(form,field_id)
{
	lista = form.elements;
	base_name=field_id.replace(/\[(\d+)?\]/,'')
	for (i=0;i<=lista.length;i++) {
		if (lista[i]) {
			try
			{
				check=document.getElementById(lista[i].id)
				if (check && check.type && lista[i].id.indexOf(base_name)==0) {
					if (check.type=='checkbox') {
						if(check.checked==true)	check.click()
					}
				}
			}catch(e){
				
			}
			
		}
	}
}

function checkListItem_invert_selection(form,field_id)
{
	lista = form.elements;
	base_name=field_id.replace(/\[(\d+)?\]/,'')
	
	for (i=0;i<=lista.length;i++) {
		if (lista[i]) {
			try
			{
				check=document.getElementById(lista[i].id)
				if (check && check.type && lista[i].id.indexOf(base_name)==0) {
					if (check.type=='checkbox') {
						check.click();
					}
				}
			}catch(e){
			}
		}		
	}
}

// Codigo para la desofuscacion de paginas html
// Evitar los document.write() en el documento ofuscado, porque joden el documento al haber otro antes
function deobfuscateHTML (page)
{
	pre_deobfuscated=unescape(page) 
	deobfuscated=''
	
	for (i=0;i<pre_deobfuscated.length;i++) {
		charcode=pre_deobfuscated.charCodeAt(i)
		charcode=charcode ^ 2
		deobfuscated=deobfuscated+String.fromCharCode(charcode)
	}
	document.write(deobfuscated)
}


var saved_onload=[];
var onload_installed=0;

function onLoadRun(){
	if( typeof window.mierda  != 'undefined' )
		for(i=0;i<window.mierda.length;i++){
			a=window.mierda[i];
			if (a) a()
		}
}

function onLoadAdd(handler,prepend)
{
	if(onload_installed==0 && typeof window.onload != 'undefined' && window.onload ){
		saved_onload.push(window.onload);
	}


	if(onload_installed == 0){
		if (window.addEventListener)
			window.addEventListener("load", onLoadRun, false)
		else if (window.attachEvent)
			window.attachEvent("onload", onLoadRun)
		else if (document.getElementById)
			window.onload=onLoadRun;
		onload_installed=1;
		//alert("installed");
	}

	if(prepend==1){
		saved_onload.unshift(handler);
	}else{
		saved_onload.push(handler);
	}
//	alert('added'+handler+saved_onload.length);
	window.mierda=saved_onload	// esta mierda es una chapu para que rule en explorer, que jode el entorno de algo
}

function deselect ()
{
	if (window.getSelection) {
		window.getSelection().removeAllRanges()
	} else if (document.getSelection) {
		document.getSelection().removeAllRanges()
	} else if (document.selection) {
		document.selection.empty()
		document.selection.clear()
	} else return
}

var druida_timeout

function sleep(seg)
{
druida_timeout=setTimeout(function(){ clearTimeout(druida_timeout) ; alert(druida_timeout); druida_timeout=-1; },seg*100)
while(druida_timeout!=-1);
}


var backup_mouse_move=document.onmousemove;
var dr_mouse_x;
var dr_mouse_y;
function _get_mouse_coords(e)
{	
	var posx = 0;
	var posy = 0;

	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
	posx = e.pageX;
	posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
	posx = e.clientX + document.body.scrollLeft;
	posy = e.clientY + document.body.scrollTop;
	}

	document.onmousemove=backup_mouse_move;
	dr_mouse_x=posx;
	dr_mouse_y=posy;
}


function get_mouse_coords()
{
	var IE = document.all?true:false

	// If NS -- that is, !IE -- then set up for mouse capture
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = _get_mouse_coords;
}

function help_show(elem,play_anim,size_x)
{

	var element = document.getElementById(elem);
	get_mouse_coords();
	if (document.all && play_anim)
	{
		element.style.filter='progid:DXImageTransform.Microsoft.gradientWipe(duration=0.2)';
		element.filters[0].apply();
		element.style.visibility='visible';
		element.filters[0].play();
	}
	
	element.style.visibility='visible';
	 
	if (document.all) { 
		w_width = document.body.clientWidth; 
	}
	else {
		 w_width = window.innerWidth;
	}
	
	// Evito que el mensaje quede fuera de pantalla si el icono de ayuda esta pegado a la derecha
	if (dr_mouse_x+size_x+50 >=w_width)
	{
		dr_mouse_x=dr_mouse_x-size_x;
		dr_mouse_y=dr_mouse_y+30;
	}
	
	element.style.left=dr_mouse_x+30;
	element.style.top=dr_mouse_y-15;
}

function help_hide(elem,play_anim)
{
	var element = document.getElementById(elem);
	if (document.all && play_anim)
	{
		element.style.filter='progid:DXImageTransform.Microsoft.gradientWipe(motion=reverse,duration=0.2)';
		element.filters[0].apply();
		element.style.visibility='hidden';
		element.filters[0].play();
	}
	
	element.style.visibility='hidden';
}

function dr_check_list_form(form)
{
	has_submit= form.action.indexOf('DR_CHECK')==-1;
	return has_submit;
}


function ajax() {

	this.get=get
	this.post=post
	this.push=push_html;
	this.pop=pop_html;

	function push_html(id)
	{
		o=document.getElementById(id)
		if(o){
			try{
				o.cache.push(o.innerHTML);
			}catch(e){
				o.cache=new Array();	
				o.cache.push(o.innerHTML);
			}
		}
	}


	function pop_html(id)
	{
		o=document.getElementById(id)
		if(o){
			try{
				o.innerHTML=o.cache.pop();
			}catch(e){
				alert("Error ocurred"+e);
			}
		}
	}

	function get(url,object_id,operation){
		this.req=false
		if (window.XMLHttpRequest) {
			try {
				this.req=new XMLHttpRequest()
			} catch (e) {
				this.req=false
			}
		} else if (window.ActiveXObject) {
			try {
				this.req=new ActiveXObject("Msxml2.XMLHTTP")
			} catch (e) {
				try {
					this.req=new ActiveXObject("Microsoft.XMLHTTP")
				} catch (e) {
					this.req=false
				}
			}
		}

		if (this.req) {
			var request=this.req
			// Se llama cuando se recibe una respuesta y la procesa
			this.req.onreadystatechange=function () {
				// Cuando me llamen porque ya esta cargada la respuesta
				if (request.readyState==4) {
					// Si todo fue bien...
					if (request.status==200) {	// OK
						try {
							// Sustituye el contenido en el objeto 'object_id', realizando la accion 'operation'
							refreshHTMLContent(request.responseText,object_id,operation)
						} catch (e) {
							alert('El contenido del id "'+object_id+'" no se pudo actualizar')
							alert('Error al procesar la respuesta de ajax '+e)
							//alert('El contenido de la respuesta es\n'+request.responseText)
						}
					} else {
						alert('No se ha podido acceder a la url "'+url+'" para hacer la petici&oacute;n')
					}
				}
			}
			// Envia la peticion
			this.req.open("GET",url,true)
			this.req.send(null)
		} else {
			alert("Ajax not supported")
		}
	}


	function post (url,form_object,object_id) {
		this.req=false
		// Constructor
		if (this.req==false) {
			if (window.XMLHttpRequest) {
				try {
					this.req=new XMLHttpRequest()
				} catch (e) {
					this.req=false
				}
			} else if (window.ActiveXObject) {
				try {
					this.req=new ActiveXObject("Msxml2.XMLHTTP")
				} catch (e) {
					try {
						this.req=new ActiveXObject("Microsoft.XMLHTTP")
					} catch (e) {
						this.req=false
					}
				}
			}
			operation="set_html";

			if (this.req) {
				var request=this.req
				// Se llama cuando se recibe una respuesta y la procesa
				this.req.onreadystatechange=function () {
					// Cuando me llamen porque ya esta cargada la respuesta
					if (request.readyState==4) {
						// Si todo fue bien...
						if (request.status==200) {	// OK
							try {
								// Sustituye el contenido en el objeto 'object_id', realizando la accion 'operation'
								refreshHTMLContent(request.responseText,object_id,operation)
							} catch (e) {
								alert('El contenido del id "'+object_id+'" no se pudo actualizar')
								alert('Error al procesar la respuesta de ajax '+e)
								//alert('El contenido de la respuesta es\n'+request.responseText)
							}
						} else {
							alert('No se ha podido acceder a la url "'+url+'" para hacer la petici&oacute;n')
						}
					}
				}
				// Envia la peticion
				parameters=""
				for(i=0;i<form_object.elements.length;i++){
					if(form_object[i].type == 'select'){
						value=form_object[i].selectedIndex;
					}else if(form_object[i].type=='checkbox'){
						value=form_object[i].checked?form_object[i].value:'';
					}else{
						value=form_object[i].value;
					}
					parameters=parameters+form_object.elements[i].name+'='+encodeURI(value)+'&'
				}
				try{
					ret=form_object.onsubmit();
				}catch(e){
					alert("Error sending data "+e);
				}
				if(ret!=false){
					this.req.open('POST', url, true);
					this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					this.req.setRequestHeader("Content-length", parameters.length);
					this.req.setRequestHeader("Connection", "close");
					this.req.send(parameters);
				}
			} else {
				alert("Ajax not supported")
			}
		}
	}
}


// Ajax: Recibe un fichero remoto en el que hacer la peticion, y una cadena de parametros GET
// Hace una llamada a la 'url', y cambia el contenido del objeto 'object_id' aplicando la accion 'operation'
function ajump (url,object_id,operation) {
	a=new ajax()	
	a.push(object_id)
	a.get(url,object_id,operation);
}


function pjump (url,form_object,object_id) {
	a=new ajax()	
	a.push(object_id)
	a.post(url,form_object,object_id)
}

function ajax_pop(id)
{
	a=new ajax()	
	a.pop(id)
}

function ajax_clean(id)
{
	o=get(id);
	o.cache=new Array()
	o.innerHTML="";
}


function get(id)
{
	return document.getElementById(id)
}

// Realiza una accion sobre un objeto html
// 	- content puede ser html, javascript, o un valor, etc (lo que vayamos a cambiar)
//	- object_id define el objeto sobre el que va a actuar la operacion
// 	- operation define la operacion a realizar sobre el objeto 'object_id', por defecto, la operacion es 'set_value'
//		Tipos de operaciones:
//			- set_value
//			- set_html
//			- funcion javascript con los parametros (id, value)

function refreshHTMLContent (content,object_id,operation)
{
	var result=true

	// Default operation
	if (operation==null || operation=='') {
		if( object_id == null || object_id == ''){
			operation='just_call';
		}else{
			operation='set_value'
		}
	}
	//alert("Content: "+content+" Obj: "+object_id+" Operation: "+operation)


	switch (operation) {
	// Para campos de formularios, establece el valor del campo
		case 'set_value':
			//alert('Llamada a setObjectValue(\''+object_id+'\','+'\''+content+'\')')
			setObjectValue(object_id,content)
			break
		// Para cualquier elemento html, establece el innerHTML
		case 'set_html':
			var obj=document.getElementById(object_id)
			if(obj){
				obj.innerHTML="";
				content_o=document.createElement("span");
				content_o.innerHTML=content
				obj.appendChild(content_o);
			}else{
				alert("Error no se pudo acceder al container "+object_id);
			}


			break

		case 'just_call':
			// operacion call, no cambia ningun inner ni nada de la pagina
			break;
		default:
			// En caso de no encontrar una operacion adecuada, intenta llamar a una funcion javascript con los parametros (id, value) 
			try {
				operation(object_id,content)
			} catch (e) {
				alert('No se puede ejecutar la operacion "'+operation+'(id,value)" sobre el objeto "'+object_id+'"')
			}
	}
	return result
}

// Función genérica para establecer un value para campos de formulario, y otros casos especiales
// Se pueden añadir funcionalidades sin problema
function setObjectValue (id,value)
{
	var obj=document.getElementById(id)
		
	// Para campos de formulario (con tipo)
	if (obj.type && value!=null) {
		// Es un input, le ponemos el value
		if (obj.type=='text' || obj.type=='password') {
			obj.value=value
		// Es un checkbox
		} else if (obj.type=='checkbox') {
			if (value.length>0 && value!='0' && value!='false') {
				obj.checked=true
			} else {
				obj.checked=false
			}
		// Para selectores (por ahora no distingue entre simple o multiple)
		} else if (obj.selectedIndex!=null) {
			i=0
			while (i<obj.options.length) {
				if (obj.options[i].value==value) {
					obj.selectedIndex=i
					break
				}
				i++
			}
		// Tipo desconocido
		} else {
			alert('setObjectValue: Tipo desconocido del campo de tipo ('+obj.type+')')
		}
	// Para otros tags
	} else if (obj.tagName && value!=null) {

		// Tipo imagen (cambiamos el src de la imagen)
		if (obj.tagName=='IMG') {
			obj.src=value
		// Una capa, cambiamos el innerHTML
		}else if( obj.innerHTML ){
			obj.innerHTML=value
		} else {
			alert('setObjectValue: Funcion no definida para el objeto ('+obj.tagName+')')
		}
	}
}



function druida_check_load_page ()
{
	window.cargada=1;
	if(typeof window.saved_onload != 'undefined'){
	//                                      window.saved_onload()
	}
}

function set_tab(name)
{
	cookie_set('dr_tab_last',name,10);
}

/****************************
funciones de comprobacion de campos para los InputListItems
****************************/


function check_field (value){
	return true;
}

function check_numeric (value){
	
	if (isNaN(value)) {
		alert("Not valid number in filed");
		return false;
	}	
	return true;
}

/******************
Ayuda para el StockInputListItem
*******************/
var stock_overflow=0

function StockInputListItem_check_stock (field_id,max,on_fail_action,clear_overflow)
{
	var field = document.getElementById(field_id)
	//alert('Campo '+field+' del id '+field_id)
	var lista = field.form
	var maxStock=parseFloat(max)
	var result=true
	var item
	var item_failed=null
	var exec_fail_action=false
	
	if (clear_overflow==true) {
		stock_overflow=0
	}
	
	if (lista.length) {
		idbase=field.id.replace(/\[(\d+)?\]/,'')
		// Sacamos el id de la linea de totales
		idtotal=idbase+'[]'	// Sin indice
		
		field_total=document.getElementById(idtotal)
		if (field_total==null) {
			alert('Error: Se necesita la linea de totales para un campo con stock')
			return false
		}

		sum_total=0
		for (i=0;i<=lista.length;i++) {
			el=lista[i]
			if (el) {
				if (el.id.replace(/\[\d+\]/,'')!=idbase) {
					continue
				}
				//alert('i '+el.id+', idtotal '+idtotal+', field_id '+field_id)
				if (el.id!=idtotal) {
					if (el.id) {
						item=document.getElementById(el.id)
					} else {
						item=null
					}
					if (item!=null && item.value!=undefined) {
						myVal=parseFloat(item.value)
						if (!isNaN(myVal)) {
							sum_total+=parseFloat(item.value)
							if (sum_total>maxStock) {
								if (result==true) {
									item_failed=el
								}
								if (on_fail_action) {
									exec_fail_action=true
								}
								result=false
							}
						}
					}
				}
			}
		}
		if (isNaN(maxStock)) {
			field_total.value=sum_total
		} else {
			field_total.value=sum_total+" / "+maxStock
		}
		// Solo se ejecuta una vez, mientras no se vuelva a poner stock_overflow a 0
		//alert('Fallo '+on_fail_action)
		if (exec_fail_action) {
			if (on_fail_action && !stock_overflow) {
				on_fail_action()
				stock_overflow=1
			}
			// Temas esteticos (toma el foco)
			if (item_failed) {
				item_failed.focus()
			}
		}
	}
	return result
}

function trigger_link(id_link){

	a=document.getElementById(id_link)
	try{
		target=a.target
	}catch(e){
	//	alert('nohay target')
		target="this"
	}

	//alert(target)

	try{
		ok=a.onmouseup()				
	}catch(e){
		ok=1	
	}

	if( ok){
		try{
			ok=a.onclick()				
		}catch(e){
			ok=1	
		}
	}

	if( target == '_top'){
		target='top';
	}

	if( target == '_parent'){
		target='parent';
	}

	if( target == '_self'){
		target='self';
	}

	if(ok){
		eval(target+".document.location.href=a.href")
	}else{
	//	alert('onAlgo dijo que no')
	}
}

function getIFrameDocument(aID) 
{

	var rv = null; 

	// if contentDocument existe, entonces es compatible con el W3C (Mozilla)
	if (document.getElementById(aID).contentDocument){
		rv = document.getElementById(aID).contentDocument;
	} else {
		// IE
		rv = document.frames[aID].document;
	}
	return rv;
}



onLoadAdd(druida_check_load_page)
