﻿// JScript File
function generalTexto1(CampoTexto, CampoOpcion, CampoDias, CampoFecha, CampoMonto, CantLetras, MaxLimit, diaDesde, diaHasta, valor1, valor2, valor3, valor4, valor5, valor6, valor7, valor8, recargo)
{
//if(document.getElementById && !(document.all)) //MOZILLA
//	{
	/*alert("aaa");
	alert(document.getElementById(CampoTexto).value)
	//alert(document.getElementById(CampoOpcion).value);
	alert(document.getElementById(CampoDias).value);
	alert(document.getElementById(CampoFecha).value);
	alert(document.getElementById(CampoMonto).value);
	alert(document.getElementById(CantLetras).value);*/
//	}
calculateDia1(document.getElementById(CampoFecha).value, diaDesde, diaHasta, CampoDias);
//alert("ok");
if (document.getElementById(diaDesde).value=='Lunes' && document.getElementById(diaHasta).value=='Jueves')
     {
     //alert("entre lunes y jueves");
     MaxLimit=76;
     }
//alert("NO es lunes/jueves");
textCounter1(CampoTexto,CantLetras,MaxLimit);
//alert("Sali de textCounter1");
calculoImporte1(CampoTexto,CampoOpcion,CampoDias,CampoMonto,diaDesde,diaHasta, valor1, valor2, valor3, valor4, valor5, valor6, valor7, valor8, recargo);
//alert("Sali de calculoImporte1");
}

function textCounter1(field,cntfield,MaxLimit) 
{
//alert("entre a textCounter1");
if (document.getElementById(field).value.length > MaxLimit) // if too long...trim it!
    document.getElementById(field).value = document.getElementById(field).value.substring(0, MaxLimit);
//alert("largo del campo " + document.getElementById(field).value.length);
document.getElementById(cntfield).value = document.getElementById(field).value.length;
}

function calculoImporte1(CampoTexto,CampoOpcion,CampoDias,CampoMonto,diaDesde,diaHasta, valor1, valor2, valor3, valor4, valor5, valor6, valor7, valor8, recargo)
{
//alert("entre a calculoImporte1");
var cc0 = document.getElementById("ctl00_ContenidoMasterFormato_rblPublicar_0");
var cc1 = document.getElementById("ctl00_ContenidoMasterFormato_rblPublicar_1");
//alert("cc0 " + cc0 + "     cc1 " + cc1);
if (cc0.checked)
    {DyW=1}
if (cc1.checked)
    {DyW=0}
//alert("DyW " + DyW);
var importeActual = 0;

if (document.getElementById(diaDesde).value=='Lunes' && document.getElementById(diaHasta).value=='Jueves')
    {
    if (DyW==1)
        importeActual = valor8;//22.75;
    else
        importeActual = valor7;//17.50;
    }
else
    {
    if (document.getElementById(CampoDias).value == 1)
        {
        if (DyW==1)
            importeActual = valor2;//22.10;
        else
            importeActual = valor1;//17;
        }
    else
        {
        if (document.getElementById(CampoDias).value <= 3)
            {
            if (DyW==1)
                importeActual = valor4;//45.50;
            else
                importeActual = valor3;//35;
            }
        else
            {
            if (document.getElementById(CampoDias).value <= 7)
                {
                if (DyW==1)
                    importeActual = valor6;//65;
                else
                    importeActual = valor5;//50;
                }
            }
        }
    }
//alert("importeActual " + importeActual);
//hasta 76
if (document.getElementById(CampoTexto).value.length <= 76) 
    {
    document.getElementById(CampoMonto).value = importeActual.toFixed(2);
    }
else
    if (document.getElementById(CampoTexto).value.length <= 95) 
        {
        document.getElementById(CampoMonto).value = (importeActual * (1 + recargo / 100)).toFixed(2);//1.30).toFixed(2);
        }
    else
        {
        if (document.getElementById(CampoTexto).value.length <= 114) 
            {
            document.getElementById(CampoMonto).value = (importeActual * (1 + 2 * recargo / 100)).toFixed(2);//1.60).toFixed(2);
            }
        }
}
//alert("fin del CalculoImporte1");

function uno(src)
{
	with(document)
	{
		var cel = getElementById(src);
		with(cel)
		{
		 	style.backgroundColor="yellow";
		 	style.color="#000000";
			//style.cursor='hand';
		}
	}
}
function dos(src)
{
	with(document)
	{
		var cel = getElementById(src);
		with(cel)
		{
			style.backgroundColor="white";
			style.color="#787878";
			//style.cursor='default';
		}
	}
}
function tres(src)
{
	with(document)
	{   
		var cel = getElementById(src);
		with(cel)
		{
			style.backgroundColor="#E6E6CA";
			style.color="#136C7F";
			//style.cursor='default';
		}
	}
}
function ini()
{
	with(document)
	{
		getElementById('1').style.backgroundColor = "yellow";
	}
}



function calculateDia1(fecha, diaDesde, diaHasta, CampoDias) {

/*
"string".slice(2,4) => "ri"
"string".substr(1,3) => "tri"
"string".substr(-1) => "g"
"string".slice(-5, -2) => "tri" 
*/
//fecha = 05/03/2009


/********************************************/
/*alert("estoy en calculatedia1");
alert("fecha " + fecha);
alert("diadesde " + document.getElementById(diaDesde).value);
alert("diaHasta " + document.getElementById(diaHasta).value);*/
var dia=fecha.substr(0,2);
var mes=fecha.substr(3,2);
var ano=fecha.substr(6,4);
var temp=mes + '/' + dia + '/' + ano;
fechita=new Date(temp);
var diasemana = fechita.getDay()
var weekday = new Array(6);
weekday[0]="Domingo";
weekday[1]="Lunes";
weekday[2]="Martes";
weekday[3]="Miércoles";
weekday[4]="Jueves";
weekday[5]="Viernes";
weekday[6]="Sábado";

/*alert("dia " + dia);
alert("mes " + mes);
alert("ano " + ano);
alert("temp " + temp);*/

/********************************************/
document.getElementById(diaDesde).value = weekday[diasemana];
//alert("diadesde " + document.getElementById(diaDesde).value);

Date.prototype.dateAdd = dateAddExtention; 
//pay attention to the new.  If you don't use it 
//you won't create a Date object, and that code up there won't work          
var fechitaHasta = new Date(temp);    
//blamo!
var dias = document.getElementById(CampoDias).value-1;
fechitaHasta.dateAdd("d", dias);
diasemana = fechitaHasta.getDay()
document.getElementById(diaHasta).value = weekday[diasemana];
//alert("diaHasta " + document.getElementById(diaHasta).value);
//   }
}

function dateAddExtention(p_Interval, p_Number){ 


   var thing = new String(); 
    
    
   //in the spirt of VB we'll make this function non-case sensitive 
   //and convert the charcters for the coder. 
   p_Interval = p_Interval.toLowerCase(); 
    
   if(isNaN(p_Number)){ 
    
      //Only accpets numbers  
      //throws an error so that the coder can see why he effed up    
      throw "The second parameter must be a number. \n You passed: " + p_Number; 
      return false; 
   } 

   p_Number = new Number(p_Number); 
   switch(p_Interval.toLowerCase()){ 
      case "yyyy": {// year 
         this.setFullYear(this.getFullYear() + p_Number); 
         break; 
      } 
      case "q": {      // quarter 
         this.setMonth(this.getMonth() + (p_Number*3)); 
         break; 
      } 
      case "m": {      // month 
         this.setMonth(this.getMonth() + p_Number); 
         break; 
      } 
      case "y":      // day of year 
      case "d":      // day 
      case "w": {      // weekday 
         this.setDate(this.getDate() + p_Number); 
         break; 
      } 
      case "ww": {   // week of year 
         this.setDate(this.getDate() + (p_Number*7)); 
         break; 
      } 
      case "h": {      // hour 
         this.setHours(this.getHours() + p_Number); 
         break; 
      } 
      case "n": {      // minute 
         this.setMinutes(this.getMinutes() + p_Number); 
         break; 
      } 
      case "s": {      // second 
         this.setSeconds(this.getSeconds() + p_Number); 
         break; 
      } 
      case "ms": {      // second 
         this.setMilliseconds(this.getMilliseconds() + p_Number); 
         break; 
      } 
      default: { 
       
         //throws an error so that the coder can see why he effed up and 
         //a list of elegible letters. 
         throw   "The first parameter must be a string from this list: \n" + 
               "yyyy, q, m, y, d, w, ww, h, n, s, or ms.  You passed: " + p_Interval; 
         return false; 
      } 
   } 
   return this; 
} 
