//NOTE:This is setup to use a security certificate - but PSS doesn't have one - so only use "non-secure" mode (0 or 2)
function submitNav(host,action){
    action = 'http://'+host+'/'+action; 
    document.forms['nav'].action = action;
//alert('action '+action);
    document.forms['nav'].submit();
}

function checkemail(email){
    if (!emailisvalid(email)){
        alert('Email doesn\'t appear to be a valid address'); 
        return false;
    }
    else
        return true;
}



function checkentry(frm){
    var msg;
    var empty_fields = "";
    var empcnt = 0;
    var errors = "";
    var ischecked = false;
    //frm.phone.numeric    = "true";

    for (var i=0; i<frm.length; i++){
        var e = frm.elements[i];

    if (e.className == 'req' && (e.type == "text" || e.type == "textarea" || e.type == "radio" || e.type == "hidden")){

	       //See if quote type is checked
             if (e.name == "type" && e.checked  ){
                 ischecked = true;
             }
             //if ((e.value == null) || (e.value == "") || isblank(e.value)){
 
             if ((e.value == null) || (e.value == "")){
                empty_fields += "\n        "+ e.title;
                empcnt++;
                continue;
             }


             if (e.name == "email"){
                if (!emailisvalid(e.value))
                   errors += "- Email doesn't appear to be valid\n";
             }
             if (e.name == "phone"){
                if (!phoneisvalid(e.value))
                   errors += "- Phone number doesn't appear to be valid\n";
             }

/*
            //check for numeric only fields
            if (e.numeric || (e.min != null) || (e.max != null)){
                var v = parseFloat(e.value);
                if (isNaN(v) || ((e.min != null) && (v < e.min)) ||
                                ((e.max != null) && (v > e.max)))
                {
                    errors += "- The entry " + e.title + " must be a number";
                    if (e.min != null)
                         errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null)
                         errors += " and less than " + e.max;
                    else if (e.max != null)
                         errors += " that is less than " + e.max;
                    errors += ".\n";
                 }
             }
*/

        }
    }//end for


         
    if (!empty_fields && !errors)
        return true;


    msg =  "______________________________________________\n\n";
    msg += "We'll still need more information to finish your order.\n";
    msg += "Please recheck the following to send your Quote Request:\n";
    msg += "______________________________________________\n\n";

    if (empty_fields)
    {
        if (empcnt > 1)
            msg += "- The following required entries are blank:" + empty_fields + "\n";
        else
            msg += "- The following required entry is blank:" + empty_fields + "\n";

        if (errors) 
            msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

function emailisvalid(str){
    var foundat  = false;
    var founddot = false;
    for (var i = 0; i< str.length; i++){
        if (str.charAt(i) == '@')
            foundat = true;
        if (str.charAt(i) == '.')
            founddot = true;
    }
    if (foundat && founddot)
        return true;
    else
        return false;
}

function phoneisvalid(str){
    if (!IsNumeric(str))
           return false;
    else
        return true;    
}

//valid phone number characters
function IsNumeric(sText){
   var ValidChars = "0123456789-()";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


function sndml(emailhost){
  var email     = "contact";
  window.location='mailto:'+email+'@'+emailhost;
}


