﻿// JScript File
// IE6 Validation and if it is true must show the upgrade message.
$(document).ready(function() {
    var useragent = navigator.userAgent.toLowerCase();
    var isMsIe6 = /msie 6./.test(useragent) && !/opera/.test(useragent);
    if (isMsIe6) { window.onload = function() { e("/common/images/") } }
});




//Variables de cambio de color de tab para el form Servicio al cliente
var colorTabActive = "#DBDBDB";
var colorTextoActive = "#000000";
var colorTabNoActive = "#F0F0F0";
var colorTextoNoActive = "#999999";
//------------------------------


function GetValueFromRadioButton(element)
{
   var returnValue;
   var rbl = document.getElementById(element);
   var options = rbl.getElementsByTagName('input');
    
    for (var i=0; i < options.length; i++)
    {
        if (options[i].checked)
        {
         
            returnValue = options[i].value;
            break;
        }
    }

    return returnValue;
}

function fixMoney(fld,sep)
{ // monetary field check
  if(!fld.value.length||fld.disabled) return true; // blank fields are the domain of requireValue 
  var val= fld.value;
  if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
  if(val.indexOf('$') == 0)
    val= parseFloat(val.substring(1,40));
  else
    val= parseFloat(val);
  if(isNaN(val))
  { // parse error 
   alert("El campo '" + fieldname(fld) +  "' debe ser un valor monetario.");
    return false;
  }
  var sign= ( val < 0 ? '-': '' );
  val= Number(Math.round(Math.abs(val)*100)).toString();
  while(val.length < 2) val= '0'+val;
  var len= val.length;
  val= sign + ( len == 2 ? '0' : val.substring(0,len-2) ) + '.' + val.substring(len-2,len+1);
  fld.value= val;
  return true;
}

function fixInt(fld,sep)
{ // integer check/complainer 
  if(!fld.value.length||fld.disabled) return true; // blank fields are the domain of requireValue 
  var val= fld.value;
  if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
  val= parseInt(val);
  if(isNaN(val))
  { // parse error 
     alert("El campo '" + fieldname(fld) +  "' debe ser un valor numérico.");
    return false;
  }
  fld.value= val;
  return true;
}

function fieldname(fld)
{ // get the field label text or name
  if(fld.id && document.getElementsByTagName)
  {
    for(var i= 0, lbl= document.getElementsByTagName('LABEL'); i < lbl.length; i++)
      if(lbl[i].htmlFor==fld.id) return lbl[i].nodeValue||lbl[i].textContent||lbl[i].innerText;
    for(var i= 0, lbl= document.getElementsByTagName('label'); i < lbl.length; i++)
      if(lbl[i].htmlFor==fld.id) return lbl[i].nodeValue||lbl[i].textContent||lbl[i].innerText;
  }
  return fld.name;
}

function OpenIMC()
{
  window.open('/Common/Themes/Tonisa/html/calculadoraImc.html','CalculadoraIMC','width=605,height=555,scrollbars=no,status=yes,resizable=no,titlebar=yes,toolbar=no');
}

function SendToFriend(pageId)
{
     window.open('/utility/sendtofriend.aspx?p='+ pageId,'CerveceriaNacional','width=580,height=600,scrollbars=yes,status=yes,resizable=no,titlebar=yes,toolbar=no');
 }


 function PrintEntry(pageId) {
     window.open('/utility/Printer.aspx?p=' + pageId, 'CerveceriaNacional', 'width=580,height=500,scrollbars=yes,status=yes,resizable=no,titlebar=yes,toolbar=no');
 }


 function OpenNewsList() {
     history.back(-1);
 }

 function PopulateDaysCombo(sourceYear, month, target) {
     var elem = document.getElementById(sourceYear);
     var year = elem.options[elem.selectedIndex].value;
     var days = 0;
     if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
        days = 31;
     }
     else {
         if (month != 2)
            days = 30;
         else {
            if (isLeapYear(year)) 
                days = 29; 
            else days = 28;
         }
     }
     elem = document.getElementById(target);
     elem.options.length = 0;
     for (i = 0; i < days; i++) {
         elem.options[i] = new Option(i + 1, i + 1);
     }
     
 }

 function isLeapYear(Year) {
     if (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0)) {
         return (true);
     } else { return (false); }
 }


 function eventClickCheckboxEventSponsorship(objCheck) {
     if (objCheck.checked) {
         mostrarDivEventSponsorship('block');
     } else {
         mostrarDivEventSponsorship('none');
     }
 }

 function eventClickCheckboxEquipMaintenance(objCheck) {
     if (objCheck.checked) {
         mostrarDivEquipMaintenance('block');
     } else {
         mostrarDivEquipMaintenance('none');
     }
 }

 function eventClickCheckboxEquipAssign(objCheck) {
     if (objCheck.checked) {
         mostrarDivEquipAssign('block');
     } else {
         mostrarDivEquipAssign('none');
     }
 }
 function mostrarDivEventSponsorship(divMain) {
     var objDivMain = document.getElementById("divEventSponsorship");
     objDivMain.style.display = divMain;

 }

 function mostrarDivEquipMaintenance(divMain) {
     var objDivMain = document.getElementById("divEquipMaintenance");
     objDivMain.style.display = divMain;
 }


 function mostrarDivEquipAssign(divMain) {
     var objDivMain = document.getElementById("divEquipAssign");
     objDivMain.style.display = divMain;
 }
 
 function mostrarDiv(divSeccion1, divSeccion2) {

//     var objTxtTab = document.getElementById("<%=TipoTextBox.ClientID%>");    

//     if (divSeccion1 == "block") {
//         objTxtTab.value = "buyer_distributor";         
//     } else {
//         objTxtTab.value = "buyer_retailer";
//     }

     cambiarColorTabActivo(divSeccion1, divSeccion2);

     var objDivSeccion1 = document.getElementById("divConsumer");
     objDivSeccion1.style.display = divSeccion1;

     var objDivSeccion2 = document.getElementById("divRetailer");
     objDivSeccion2.style.display = divSeccion2;

     var objDivSeccion2 = document.getElementById("divAdd");
     objDivSeccion2.style.display = divSeccion2;

     var objDivSeccion2 = document.getElementById("divhelpRetailer");
     objDivSeccion2.style.display = divSeccion2;

     var objDivSeccion2 = document.getElementById("divhelpConsumer");
     objDivSeccion2.style.display = divSeccion1;

     var objDivSeccion2 = document.getElementById("divCodeEvent");
     objDivSeccion2.style.display = divSeccion2;
    
     
 }

 function cambiarColorTabActivo(divSeccion1, divSeccion2) {
     //Tabs Arriba
     var objTabSeccion1 = document.getElementById("tabConsumer");
     var objTabSeccion2 = document.getElementById("tabRetailer");
     /**
     QUITAR EL ICONO DE LISTA
     **/

     objTabSeccion1.style.listStyleType = "none";
     objTabSeccion2.style.listStyleType = "none";

     //objTabSeccion1.style.listStyle="square";
     //objTabSeccion2.style.listStyle="square";

     /**
     CAMBIA EL COLOR DEL FONDO
     **/
     objTabSeccion1.style.background = colorTabNoActive;
     objTabSeccion2.style.background = colorTabNoActive;
     /**
     CAMBIA EL COLOR DEL TEXTO
     **/
     objTabSeccion1.style.color = colorTextoNoActive;
     objTabSeccion2.style.color = colorTextoNoActive;
     /**
     CAMBIA EL COLOR Y FONDO DEL LINK ACTIVO
     **/
     if (divSeccion1 == 'block') {
         objTabSeccion1.style.background = colorTabActive;
         objTabSeccion1.style.color = colorTextoActive;
     }
     if (divSeccion2 == 'block') {
         objTabSeccion2.style.background = colorTabActive;
         objTabSeccion2.style.color = colorTextoActive;
     }
 }

 function characters(event) {
     if (event.keyCode > 45 && event.keyCode < 58) event.returnValue = false;
 }

 function number(event) {
     if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
 }

 function numbersonly(e) {
     //debugger;
     var unicode = e.charCode ? e.charCode : e.keyCode;
     if (unicode != 8 && unicode != 9) { //if the key isn't the backspace key (which we should allow)
         if (unicode < 48 || unicode > 57) //if not a number
             return false;  //disable key press
     }
     return true;
 }

 function lettersonly(e) {
     
     var unicode = e.charCode ? e.charCode : e.keyCode;
     if (unicode != 8) { //if the key isn't the backspace key (which we should allow)
         if (unicode > 45 && unicode < 58) //if not a letter
             return false;  //disable key press
     }
     return true;
 }


 function fnTrapKD(btn, event) {

     if (document.all) {
         if (event.keyCode == 13) {
             event.returnValue = false;
             event.cancel = true;
             btn.click();
         }
     }
     else
         if (document.getElementById) {
         if (event.which == 13) {
             event.returnValue = false;
             event.cancel = true;
             btn.click();
         }
     }
     else
         if (document.layers) {
         if (event.which == 13) {
             event.returnValue = false;
             event.cancel = true;
             btn.click();
         }
     }
 } 
