
function submitInfo(action){

    action = 'http://'+document.forms['nav'].httphost.value+'/'+action; 
//alert('action '+action);
    document.forms['nav'].action = action;
    document.forms['nav'].submit();

}


function checkemail(email){
    if (!emailisvalid(email)){
        myalert('Email doesn\'t appear to be a valid address','Error Information','');
        //alert('Email doesn\'t appear to be a valid address'); 
        return false;
    }
    else
        return true;
}


function myalert(msg,title,locurl){
    titlwd = title.length*7;
    jQuery("#dialog").html(msg).dialog({
        position: 'center',autoOpen: true, width: 'auto',height: 'auto',title: '<div style="margin:0 0 0 35%;width:'+titlwd+'px;">'+title+'</div>',
        buttons: {
            "Exit": function() { 
                if (locurl.length > 0)
                    location.replace(locurl);
                $(this).dialog("close"); 
                //return false;
            }
        }
    });
}


function checkentry(){
    frm = document.forms[0];
    var msg;
    var errcnt = 0;
    var errors = "";
    
    //frm.phone.numeric    = "true";	//set which items need to be numeric here
    var i = 0;

    while( i<frm.length){
        var el = frm.elements[i];
 
    if (el.className == 'req' || el.className == 'tstscr'){
             if (el.tagName == "SELECT" && el.value == 0){
                  errors += '<span style="font-weight:bold">'+el.title+'</span> - has not been entered<br />';
                  errcnt++;
             }

             if ((el.type == "text" || el.type == "password") && el.value.length == 0){
                  errors += '<span style="font-weight:bold">'+el.title+'</span> - has not been entered<br />';
                  errcnt++;
             }
             if (el.name == "password"){
                 var password = document.getElementById('password').value;  
                 if (password.length < 6)
                     errors += '<span style="font-weight:bold">Password Error:</span> Must be at least 6 characters long<br />';  

                 if (frm.cpassword != null){
                     var cpassword = document.getElementById('cpassword').value;   
                     if (cpassword != password)
                         errors += '<span style="font-weight:bold">Password Error:</span> Re-enter Password and Confirm Password<br />';  
                 } 
             }

             if (el.type == "radio"){
                 foundcheck = false;
                 curradid = el.id;

                 while (el.id == curradid){
//alert('while loop curid at i:'+i+' id '+el.id+' checked '+el.checked);
                     if (el.checked)
                         foundcheck = true;
                     i++;
//alert('just set i to '+i);
                     var el = frm.elements[i];
                 }
                 i--;		//revert i so end loop incrementor won't skip next element
//alert('after while el id '+el.id + ' foundcheck '+foundcheck);
                 if (!foundcheck){	//past current radio button - verify if checked
                      errors += '<span style="font-weight:bold">'+frm.elements[i].title+'</span> - has not been entered<br />';
                      errcnt++;
                 }
             }
             if (el.name == "email"){
                if (!emailisvalid(el.value)){
                   errors += '<span style="font-weight:bold">Email</span> - doesn\'t appear to be valid<br />';
                   errcnt++;
                }
             }
             if (el.name == "phone"){
                if (!phoneisvalid(el.value)){
                   errors += '<span style="font-weight:bold">Phone number</span> - doesn\'t appear to be valid<br />';
                   errcnt++;
                }
             }
/*
            //check for numeric only fields
            if (el.numeric || (el.min != null) || (el.max != null)){
                var v = parseFloat(el.value);
                if (isNaN(v) || ((el.min != null) && (v < el.min)) ||
                                ((el.max != null) && (v > el.max)))
                {
                    errors += '<span style="font-weight:bold">' + el.title + '</span> - must be a number';
                    errcnt++;
                    if (el.min != null){
                         errors += ' that is greater than ' + el.min + '<br />';
                         errcnt++;
                    }
                    if (el.max != null && el.min != null){
                         errors += ' and less than ' + el.max +'<br />';
                         errcnt++;
                    }else if (el.max != null){
                         errors += ' that is less than ' + el.max + '<br />';
                         errcnt++;
                    }
                    errors += '<br />';
                 }
             }
*/
        }

        i++;
        if (errcnt > 15)
            break;			//only display up to 15 errors - or OK/cancel buttons are too far down
    }//end while

    
     if (document.getElementById('personnum') != null && document.getElementById('personnum').value == 1 && frm.firstname2.value.length > 0){
        pers2exists = frm.pers2exists.value;
        if (pers2exists == 0)
             errors += '<span style="font-weight:bold">Person 2 Personality Profile</span> - has not been entered<br />';
     }
    
   
    jQuery("#dialog").dialog({ position: 'center', autoOpen: false });		//INIT dialog
    //SET DEFAULT BUTTONS
    
    jQuery("#dialog").dialog( "option", "buttons", {
        "Exit": function() { 
        $(this).dialog("close"); 
        return false;
	}
    });
    


    //Build Msg
    if (!errors){		//NO ERRORS - ALL fields are complete - so no msg and set complete status  
            return true;			//generic signal entry is OK -    don't show any dialog
    }else{				//HAVE ERRORS
        msg = '<span style="font-weight:bold">You still to enter more information to complete this entry</span><br /><br />';
        msg += "Please recheck the following items:<br /><br />";
        msg += errors;



        if (frm.checkstrong != null){		//hidden field to signal strong error checking
            msg += '<br />You must fix these before continuing<br />';
        }
        jQuery("#dialog").dialog({ title: '<div style="margin:0 0 0 50%;width:120px;">Error Information</div>' });
    }			//end have errors


    
    jQuery("#dialog").html(msg);
    jQuery("#dialog").dialog({ width: 'auto' }); 
    jQuery("#dialog").dialog({ height: 'auto' });            
    jQuery('#dialog').dialog('open');


}



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;
}


