/*
 *	BrowserCheck Object
 */
function BrowserCheck() 
{
	nav = navigator.appVersion;
	nan = navigator.appName;
	nua = navigator.userAgent;
	if (nan=="Netscape") this.b = "ns"
	else if (nan=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = nan
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ieMac = (this.version.indexOf('Macintosh')>0 && this.version.indexOf('Internet Explorer')>0)
	if (!this.ieMac)
	{
		this.ie = (this.b=="ie" && this.v>=4)
		this.ie4 = (this.version.indexOf('MSIE 4')>0)
		this.ie5 = (this.version.indexOf('MSIE 5')>0)
		this.ie6 = (this.version.indexOf('MSIE 6')>0)
		this.ie7 = (this.version.indexOf('MSIE 7')>0)
	}
	this.opera = 			(nan.indexOf('Opera')>=0);
	this.operaMac = 	(nan.indexOf('Opera')>=0 && this.version.indexOf('Macintosh')>0)
	this.firefox = 		(nua.indexOf('Firefox')>=0);
	this.ff2 = 				(nua.indexOf('Firefox/2')>=0);
	this.ff3 = 				(nua.indexOf('Firefox/3')>=0);
	this.safari = 		(nua.indexOf('Safari')!=-1);
	this.konqueror = 	(!this.safari && (nua.indexOf('Konqueror')!=-1) ) ? true : false;

	this.mac = (nav.indexOf('Mac')!=-1);
	this.windows = ( ( (nav.indexOf('Win')!=-1) || (nav.indexOf('NT')!=-1) ) && !this.mac)?true:false;
	this.linux = (nua.indexOf('Linux')!=-1);

	this.chrome = nua.toLowerCase().indexOf('chrome') > -1;	
	
}
var es = new BrowserCheck();


/*encrypt(value){
	
}*/
function str2float(str)
{
	if (str == "") return 0;
	
	str = str.replace(",", ".");
	f= new Number(str);
	
	f = f.toFixed(2);
	
	return f;
}


/*
*	convertir un float en string
*	float 	: 25.3597
*	regresa : 25,36
*/
function float2str(tfloat)
{
	if (tfloat == ""||tfloat==0) return "0,00";
	
	//float = 0.0 + float;
	
	f= new Number(tfloat);
	f = f.toFixed(2);   
	str= f.toString();
	str = str.replace(".",",");
	pos = str.indexOf(",");
	if(pos == -1)
		str+=",00";
	if((str.length-pos)==2)
	str+="0";
	return str;
}


function idate(month){	
	mes = (month.charAt(0)!= '0') ? month : month.substr(1);
	//alert(mes);
	return mes;
}


/*
*	funciones para tratado de FECHAS
*/


function isValidDate(anyo,mes,dia){
	if(dia==0 || mes==0 || anyo==0) return false;
	if(mes==2&& dia>29)return false
	if((mes==2||mes==4||mes==6||mes==8||mes==11)&& dia >30)return false;
	return true;
}


/*day,month	: enteros  {1,9,15,...}
	year			: entero de 4 digito
*/
function isValidIntervalDate(year1,month1,day1,year2,month2,day2){
	//validar el ENDDATE
	if(month2==0|| day2==0){alert("Insert an end date");return false;}				
	if(month2==2 && day2 >29){alert("to: Invalid day Feb");return false;}
	if((month2==2||month2==4||month2==6||month2==8||month2==11)&& day2 >30){alert("to: invalid day 31");return false;}
	
	//validar STARTDATE
	if(month1==0|| day1==0){alert("Insert a start date");return false;}				
	if(month1==2&& day1 >29){alert("from: Invalid day Feb");return false;}
	if((month1==2||month1==4||month1==6||month1==8||month1==11)&& day1 >30){alert("from: invalid day 31");return false;}
	//alert(year2+month2+day2+' - '+year1+month1+day1);				
	if((parseInt(year2+month2+day2)-parseInt(year1+month1+day1)) <= 0){alert("the End date is not a valid date");return false;}
	
	return true;
}


//se toma en cuenta que FEBRERO  tiene 28 dias (debido a que no tenemos ano)
function isValidIntervalMonthDay(month1,day1,month2,day2){
		//validar el ENDDATE
	if(month2.value==0) {alert("Seleccionar Mes"); month2.focus(); return false;}
	if(day2.value==0)		{alert("Seleccionar Dia"); day2.focus(); return false;}				
	if(month2.value==2 && day2.value >28){alert("Febrero solo tiene 28 dias"); month2.focus(); return false;}
	if((month2.value==2||month2.value==4||month2.value==6||month2.value==8||month2.value==11)&& day2.value >30){alert("Este mes solo tiene 30 dias"); month2.focus(); return false;}
	
	//validar STARTDATE
	if(month1.value==0) {alert("Seleccionar Mes"); month1.focus(); return false;}     
	if(day1.value==0)		{alert("Seleccionar Dia"); day1.focus(); return false;}				
	if(month1.value==2&& day1.value >28){alert("Febrero solo tiene 28 dias"); month1.focus(); return false;}
	if((month1.value==2||month1.value==4||month1.value==6||month1.value==8||month1.value==11)&& day1.value >30){alert("Este mes solo tiene 30 dias"); month1.focus(); return false;}
	//alert(year2+month2+day2+' - '+year1+month1+day1);
	
	
	m2=(month2.value < 10) ? "0" + month2.value : month2.value ;
	d2=(day2.value   < 10) ? "0" + day2.value   : day2.value   ;
	m1=(month1.value < 10) ? "0" + month1.value : month1.value ;
	d1=(day1.value   < 10) ? "0" + day1.value   : day1.value   ;
	//alert('2009'+m2+d2+'-'+'2009'+m1+d1);			
	if((parseInt('2009'+m2+d2)-parseInt('2009'+m1+d1)) <= 0){alert("La fecha final es icorrecta"); day2.focus(); return false;}
	
	return true;
	
}


function htmlentities(str) 
{
    var i,output,len,tchar='';
    len = str.length;
    for(i=0;i<len;i++){
        tchar = str[i].charCodeAt(0);
        if( (tchar>47 && tchar<58)||(tchar>62 && tchar<127) ){
            output += str[i];
        }else{
            output += "&#" + str[i].charCodeAt(0) + ";";
        }
    }
    return output;
}




// Fa un canvi de posicio en la data
// Si idioma == "ES" passa de "Lun 2008-06-15" a "Lun 15-06-2008"
function transformaData(sIn)
{
	if (idioma == "ES")
	{
		
		var date = sIn.split(" ");
		if (date.length < 2) return "";
		var DateArr = date[1].split("-");
		if (DateArr.length < 3) return "";
		var DateDia = DateArr[2];
		var DateMes = DateArr[1];
		var DateAny = DateArr[0];
		return date[0]+" "+DateDia+"-"+DateMes+"-"+DateAny;
	}
	else return sIn;
}


/*@params	: sdata = data te el format "yyyy-mm-dd hh:mm:ss"  FORMATO INGLES
*						format= 'es'  
* @return 	: un string en formato dado
*/
function formatDate(sdata,format){		
	// i volem el format format [es]=  dd-mm-yyyy hh:mm
	//													[en]=  yyyy-mm-dd hh:mm	
	var reshora='';
	var posEspai= sdata.indexOf(" ");
	if(posEspai!=-1)
		reshora = sdata.substring(posEspai+1,posEspai+6);	
	var resdata = sdata.substring(8,10) + sdata.substring(4,8) + sdata.substring(0,4);
	return resdata+' '+reshora;// + " &nbsp; (" + resdata + ")";
}

/*
*	@params
				days: "1,2....7"  los dias de la semana en formato numerico
	@return
				las iniciales de los dias
*/
function days2str(days)
{
	if (typeof(inicialsDies) == "undefined"){
		inicialsDies = Array("L", "Ma", "Mi", "J", "V", "S", "D")
	}
	var strdays ='';
	//days =  days.split("");
	for(var z=1; z<8; z++){
		if(days.indexOf(z)!=-1)
			switch(z){
				case 1: 	strdays+=inicialsDies[0]+" "; break;
				case 2: 	strdays+=inicialsDies[1]+" "; break;
				case 3: 	strdays+=inicialsDies[2]+" "; break;
				case 4: 	strdays+=inicialsDies[3]+" "; break;
				case 5: 	strdays+=inicialsDies[4]+" "; break;
				case 6: 	strdays+=inicialsDies[5]+" "; break;
				case 7: 	strdays+=inicialsDies[6]+" "; break;					
			}
			
	}	
	return strdays;
}


/*
@param s aguja
@return la posicion de un ELEMENTO en el array, -1 si no se encuentra el ELEMENTO
funcion para buscar un elemento en un array (esta funcion es para IE6 ya que los demas ya lo tienen);
*/
	Array.prototype.indexOf = function(aguja) {
		for (var i=0; i < this.length; i++) 
			if(this[i] == aguja) return i;
		return -1;
	}
