﻿// JScript File
function toNumberWZero(control) {
  var textBox = document.getElementById(control);
    var msg=textBox.value; 
    var w;
    var ind;
  
    for ( w=0; w<msg.length; w++ )  {

      ind=msg.substring(w,w+1);
      if ( ind<"0" || ind>"9" )  {  
           msg=msg.substring(0,w);
           textBox.value=msg; 
           break;           
      }
    }
}
function validate_Required_Field(ctrl)
{
    var valor = document.getElementById(ctrl).value;
    
    return valor.length > 0;
}
function validade_Invalid_Email(ctrl)
{
    var email = document.getElementById(ctrl).value;
    var isValid = true;
                  
    var filter = /^(?:[a-zA-Z0-9_'^&amp;/+-])+(?:\.(?:[a-zA-Z0-9_'^&amp;/+-])+)*@(?:(?:\[?(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\.){3}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\]?)|(?:[a-zA-Z0-9-]+\.)+(?:[a-zA-Z]){2,}\.?)$/;
    if(email.match(filter) == null)
        isValid = false;
    
    return isValid;
}
function validateFields(First_Name, Email, Area_Code, Phone)
{
    var msg="";
    var isValid = true;    
    
    //{0} is an invalid e-mail.[alias@something.domain]
    //{0} is a required field.
    if(!validate_Required_Field(First_Name))
    {
        msg = msg + "Contact Person is a required field. \r"
        isValid = false;
    }
    
    if(validate_Required_Field(Email) == false)
    {
        msg = msg + "E-mail is a required field. \r"
        isValid = false;
    }
    else if(validade_Invalid_Email(Email) == false)
    {
        msg = msg + "E-mail is an invalid e-mail.[alias@something.domain]. \r"
        isValid = false;
    }
    
    if(validate_Required_Field(Area_Code) == false)
    {
        msg = msg + "Day Phone, area code is a required field. \r"
        isValid = false;
    }
    if(validate_Required_Field(Phone) == false)
    {
        msg = msg + "Day Phone is a required field. \r"
        isValid = false;
    }
    
    
    if(isValid == false)
    alert(msg);
    
    
    return isValid;
}
function add_DayFlight_ROW(tblId, imgCtrl)
{
  var tblBody = document.getElementById(tblId).tBodies[0];
  var maxFlight = 21;
  if(tblBody.rows.length == maxFlight -1 )
  {
     imgCtrl.style.display = "none";
  }
  
  if(tblBody.rows.length < maxFlight)
  {
      var newRow = tblBody.insertRow(-1);
      var newCell0 = newRow.insertCell(0);
      newCell0.style.backgroundColor="#FFFFFF";
      newCell0.style.textAlign="right";
      newCell0.innerHTML = 'Day ' + tblBody.rows.length + '.';
      
      var newCell1 = newRow.insertCell(1);
      newCell1.style.backgroundColor="#FFFFFF";
      newCell1.style.textAlign="left";
      newCell1.innerHTML = '<input type="input" value="" size="50" maxlength="100" name="Day' + tblBody.rows.length + '"/>';
  }
}

// Bloqueio do uso right-click na página
var currentDate = new Date();
var message="(c)"+ currentDate.getYear() + " Abreu."
function click(e) {
    if (document.all) {
        if (event.button == 2) {
            alert(message);
            return false;
        }
    }
    if (document.layers) {
        if (e.which == 3) {
            alert(message);
            return false;
        }
    }
}
if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
//---------------------------------------------------------------------------


function fillDropDownProducts(control, xml)
{
    var selDest = control[control.selectedIndex].text;    
    var xDoc = loadXMLDoc(xml);
    
    //remove todos os items    
    clearDropDown(control);  
}
function clearDropDown(control)
{
}
function loadXMLDoc(dname)
{
    try //Internet Explorer
      {
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      }
    catch(e)
      {
      try //Firefox, Mozilla, Opera, outros.
        {
            xmlDoc=document.implementation.createDocument("","",null);
        }
      catch(e) {alert(e.message)}
      }
    try
      {
          xmlDoc.async=false;
          xmlDoc.loadXML(dname) //ler o conteudo
//          xmlDoc.load(dname); //ler do ficheiro
          return(xmlDoc);
      }
    catch(e) {alert(e.message)}
    return(null);
} 