/*
 *  msApplyPNGFilter(o)
 *
 *  Applies the PNG Filter Hack for IE browsers when showing 24bit PNG's
 *
 *  var o = object (this png element in the page)
 */
function msApplyPNGFilter(o)
{
    var t="./images/transparent.gif";
    if( o.src != t )
    {
        var s=o.src;
        o.src = t;
        o.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+s+"',sizingMethod='scale')";
    }
}

window.onload = function() {}
window.onresize = function() {}

/* process user login */
function processUserLogin()
{
    //clearHighlightLogin();
    var u = document.userlogin.usernamelogin.value;
    var p = document.userlogin.password.value;
    if( u.length <=3 )
    {
        var d = document.getElementById('qloginerror');
        d.innerHTML = 'Your username must have at least 3 characters!';
        return false;
    }
    else if( p == '' )
    {
        var d = document.getElementById('qloginerror');
        d.innerHTML = 'You must specify a password!';
        return false;    
    }
    else
    {
        document.userlogin.submit();
        return true;
    }
}


/* open a new window */
function openWin(szPage, nWidth, nHeight)
{
  var wh = window.open(szPage,'genwin','width='+nWidth+',height='+nHeight+',directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes');
  wh.focus();
}

/* HELPER FUNCTIONS */

function emailCheck (emailStr) {
    // user@domain format.
  var emailPat=/^(.+)@(.+)$/
    // Special characters including ( ) < > @ , ; : \ " . [ ]
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    // Range of characters allowed in a word.  Really which chars aren't allowed.
  var validChars="\[^\\s" + specialChars + "\]"
    // quoted user string E.g. "jiminy cricket"@disney.com
  var quotedUser="(\"[^\"]*\")"
    // Domains that are IP addresses E.g. joe@[123.124.233.4] Square brackets are required.
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    // An atom (series of non-special characters.)
  var atom=validChars + '+'
    // Single words in the username. A word is an atom or quoted string.
  var word="(" + atom + "|" + quotedUser + ")"
    // Describes the structure of the user
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    // Describes the structure of a normal symbolic domain, not ipDomainPat as shown above.
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

    // Break up user@domain into different pieces that are easy to analyze.
  var matchArray=emailStr.match(emailPat)
  if (matchArray==null) {
    alert("Email address seems incorrect (check @ and .'s)")
    return false
  }
  var user=matchArray[1]
  var domain=matchArray[2]

    // See if "user" is valid
  if (user.match(userPat)==null) {
      alert("The username doesn't seem to be valid.")
      return false
  }

    // if the e-mail address is at an IP address make sure the IP address is valid.
  var IPArray=domain.match(ipDomainPat)
  if (IPArray!=null) {
      for (var i=1;i<=4;i++) {
        if (IPArray[i]>255) {
            alert("Destination IP address is invalid!")
      return false
        }
      }
      return true
  }

    // Domain is symbolic name
  var domainArray=domain.match(domainPat)
  if (domainArray==null) {
    alert("The domain name doesn't seem to be valid.")
      return false
  }

    // Domain name seems valid, ensure it ends in a 3-letter (com, org) or 2-letter word, (uk, ca), and that a hostname is preceding.
    // Break up the domain to count of how many atoms it consists of.
  var atomPat=new RegExp(atom,"g")
  var domArr=domain.match(atomPat)
  var len=domArr.length
  if (domArr[domArr.length-1].length<2 ||
      domArr[domArr.length-1].length>3) {
     alert("The address must end in a three-letter domain, or two letter country.")
     return false
  }

  if (len<2) {
     var errStr="This address is missing a hostname!"
     alert(errStr)
     return false
  }
  return true;
}

/* Process the Appointment */
function processAppt()
{
    var f = document.appt;
    var bGo = true;
    
    if( f.fname.value == '' )
    {
        alert('Please provide a first name.');
        bGo = false;
    }
    else if( f.lname.value == '' )
    {
        alert('Please provide a last name.');
        bGo = false;
    }
    else if( !emailCheck(f.email.value) )
    {
        bGo = false;
    }    
    else if( f.phone.value == '' )
    {
        alert('Please provide a phone number.');
        bGo = false;
    }    
    else if( f.address.value == '' )
    {
        alert('Please provide an address.');
        bGo = false;
    }    
    else if( f.city.value == '' )
    {
        alert('Please provide a city.');
        bGo = false;
    }    
    else if( f.postalcode.value == '' )
    {
        alert('Please provide a postalcode.');
        bGo = false;
    }    
    else if( f.make.value == '' )
    {
        alert('Please provide the make of car.');
        bGo = false;
    }    
    else if( f.model.value == '' )
    {
        alert('Please provide the model of car.');
        bGo = false;
    }    
    else if( f.year.value == '' )
    {
        alert('Please provide the year your car was made.');
        bGo = false;
    }    
    else if( f.mileage.value == '' )
    {
        alert('Please provide a mileage estimate.');
        bGo = false;
    }
    else if( f.service.value == '' )
    {
        alert('Please provide at least a brief description of service.');
        bGo = false;
    }    
    
    
    if( bGo )
        f.submit();
    
}