// JavaScript Document
function setBackground(id,bgpath,bgcolor)
{
	var td;
	td=document.getElementById(id);
	if(bgpath != '') { td.style.backgroundImage="url(" + bgpath + ")"; }
	if(bgcolor != '') { td.style.backgroundColor=bgcolor; }
}

function moveProductsMenu()
{
	//--> determine how much the page was scrolled
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	if(y>110)
	{
		pos=y-110;
		document.getElementById('float-menu').style.top=pos+"px";
	}
	else
	{
		document.getElementById('float-menu').style.top=0+"px";
	}
}

function fixLeftBox()
{		
	var rboxheight,mnuheight;
	default_height=500;

	if(document.getElementById)
	{
		if(document.getElementById('home-left-menu'))
		{
			rboxheight=document.getElementById('right-box').offsetHeight;
			if(rboxheight>default_height)
			{
				document.getElementById('home-left-menu').style.height=rboxheight+"px";
			}
		}
		else
			if(document.getElementById('prod-left-menu'))
			{
				rboxheight=document.getElementById('right-box').offsetHeight;
				if(rboxheight>default_height)
				{
					document.getElementById('prod-left-menu').style.height=rboxheight+"px";
				}
			}
	}
}

function validateSelFields() {
	args=validateSelFields.arguments;
	var errors='';
	for(i=0;i<args.length;i++) {
		val=MM_findObj(args[i]);
		nm=val.name;
		if(val.options[val.selectedIndex].value=="-1")
			errors+='- '+val.options[val.selectedIndex].text+' no es una opcion valida en '+nm+'.\n';
	}
	if (errors) alert('Los siguientes errores ocurrieron:\n'+errors);
		document.vsf_returnValue=(errors == '');
}

/* FUNCIONES DE MACROMEDIA */
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_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 MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
		test=args[i+2];
		val=MM_findObj(args[i]);
		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 una dirección de correo electrónico.\n';
				} else 
					if (test.indexOf('isDate')!=-1) {
						if(!isDate(val))
							errors+='- '+nm+' debe contener una fecha válida en formato dd/mm/yyyy .\n';
					} 
					else
						if (test!='R') { 
							num = parseFloat(val);
							if (isNaN(val)) 
								errors+='- '+nm+' debe contener un nú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úmero entre '+min+' y '+max+'.\n';
							}
						} 
			}
			else
				if (test.charAt(0) == 'R')
					errors += '- '+nm+' es requerido.\n';
		}
	}
	if (errors) alert('Los siguientes errores ocurrieron:\n'+errors);
		document.MM_returnValue = (errors == '');
}

function isDate(Str){
    
	  var Patern = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
	  var matchArray = Str.match(Patern); 


	  if (matchArray == null) {
    	return false;
	  }

	  day = matchArray[1];
	  month = matchArray[2];
	  year = matchArray[3];


	  if (month < 1 || month > 12) { 
    	return false;
	  }

	  if (day < 1 || day > 31) {
    	return false;
	  }

	  if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    	return false;
	  }

	  if (month == 2) { 
		  var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		  if (day > 29 || (day==29 && !isleap)) {
    		  return false;
	    	}
	  }
	  if(year < 2000){
	    return false;
	  }
	  

	  return true;  
        
} // isDate

/* funcion para hacer self submit del form de busqueda */
function formSearchSelfSubmit(lang)
{
	var form;
	form=document.frmSearch;
	
	form.action="index.php?lang=" + lang + "&self=true";
	form.submit();
}

/* SCRIPT PARA CREAR BARRA DE CARGA PORCENTUAL */
	var duracionScript;	
	var progressPercentage;
	var timeRatio;
	var widthProp;
	var tout;

	function setDuracionScript(mm) {
		duracionScript=mm*60*1000;
		progressPercentage=0;
		timeRatio=Math.ceil(duracionScript/100);
		widthProp=3;
		tout;
	}
		
	// Ejemplo el script debe durar 60 sg o 60,000 ms
	// el 100% es 60,000
	// el 1% equivale a 60*0.01=0.6 o 600ms
	
	function progressBarLoader() {
		divProgBar=document.getElementById('div-progress-bar');	
		divProgBar.style.width=(progressPercentage*widthProp)+'px';
		divProgCounter=document.getElementById('div-progress-counter');
		divProgCounter.innerHTML=progressPercentage+'%';
		if(progressPercentage<100)
			tout=setTimeout('progressBarLoader()',timeRatio);
		//else
			//alert('Progress Percentage: '+progressPercentage+'DuracionScript: '+duracionScript+'Time Ratio:'+timeRatio);
		progressPercentage++;
	}
	
	function setTimeRatio(ms) {
		timeRatio=ms;
	}
	
	function setInfoFields(fieldId,value) {
		div=document.getElementById(fieldId);
		div.innerHTML=value;
	}
/* TERMINA SCRIPT DE BARRA DE CARGA */

