﻿// JScript File
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function quick_submit()
{
    var txtName = document.getElementById("ctl00_Navigation_Vertical_Quick_Contact1_txtFullName");
    var txtEmail = document.getElementById("ctl00_Navigation_Vertical_Quick_Contact1_txtEmail");
    var txtPhone = document.getElementById("ctl00_Navigation_Vertical_Quick_Contact1_txtPhone");
    var txtComments = document.getElementById("ctl00_Navigation_Vertical_Quick_Contact1_txtComments");
    var validation_summary = "Please complete and answer the required fields:\n";
    if(trim(txtName.value)=="name" || trim(txtName.value)=="")
    {
        txtName.value = "name";
        validation_summary = validation_summary + "Full Name\n";
    }
    
    if(trim(txtEmail.value)=="email" || trim(txtEmail.value)=="")
    {
        txtEmail.value="email";
        validation_summary = validation_summary + "E-mail\n";
    }
    else
    {
        retxtname = new RegExp(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
       	if (!(retxtname.test(trim(txtEmail.value))))
        {
            validation_summary = validation_summary + "E-mail address is not valid\n";
       	}
    }
    /*if(trim(txtComments.value)=="Comments" || trim(txtComments.value)=="")
    {
        validation_summary = validation_summary + "Comments / Inquiry\n";
    }*/
    if (validation_summary == "Please complete and answer the required fields:\n")
    {
        return true;
    }
    else
    {
        alert(validation_summary);
        return false;
    }
}

function contactus_submit()
{
    var txtFName = document.getElementById("ctl00_body_Contact_Form_txtFirstName");
    var txtLName = document.getElementById("ctl00_body_Contact_Form_txtLastName");
    var txtEmail = document.getElementById("ctl00_body_Contact_Form_txtEmail");
    var txtWork1 = document.getElementById("ctl00_body_Contact_Form_txtWork1");
    var txtWork2 = document.getElementById("ctl00_body_Contact_Form_txtWork2");
    var txtWork3 = document.getElementById("ctl00_body_Contact_Form_txtWork3");
    var txtTotalBal = document.getElementById("ctl00_body_Contact_Form_txtTotalBal");
    var cmbProperty = document.getElementById("ctl00_body_Contact_Form_cmbProperty");
    var cmbTime = document.getElementById("ctl00_body_Contact_Form_cmbTime");
    
    
    var lblFName = document.getElementById("lblFName");
    var lblLName = document.getElementById("lblLName");
    var lblEmail = document.getElementById("lblEmail");
    var lblWPhone = document.getElementById("lblWPhone");
//    var lblTotalBal = document.getElementById("lblTotalBal");
//    var lblTypeProp = document.getElementById("lblTypeProp");
//    var lblTime = document.getElementById("lblTime");
    
    lblFName.style.color = "#000000";
    lblLName.style.color = "#000000";
    lblEmail.style.color = "#000000";
    lblWPhone.style.color = "#000000";
    
    var validation_summary = "Please complete and answer the required fields:\n";
    if(trim(txtFName.value)=="")
    {
        validation_summary = validation_summary + "First Name\n";
        lblFName.style.color = "#ff0000";
    }
    else
    {
        lblFName.style.color = "#000000";
    }
    
    if(trim(txtLName.value)=="")
    {
        validation_summary = validation_summary + "Last Name\n";
        lblLName.style.color = "#ff0000";
    }
    else
    {
        lblLName.style.color = "#000000";
    }
    
    if(trim(txtEmail.value)=="")
    {
        validation_summary = validation_summary + "E-mail\n";
        lblEmail.style.color = "#ff0000";
    }
    else
    {
        retxtname = new RegExp(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
       	if (!(retxtname.test(trim(txtEmail.value))))
        {
            validation_summary = validation_summary + "E-mail address is not valid\n";
            lblEmail.style.color = "#ff0000";
       	}
       	else
       	{
       	    lblEmail.style.color = "#000000";
       	}
    }
    if(trim(txtWork1.value)=="" || trim(txtWork2.value)=="" || trim(txtWork3.value)=="")
    {
        validation_summary = validation_summary + "Primary Phone\n";
        lblWPhone.style.color = "#ff0000";
    }
    else
    {
         retxtwork1 = new RegExp(/^[0-9a-zA-Z]{3}$/);
         retxtwork2 = new RegExp(/^[0-9a-zA-Z]{4}$/);
         
         if(!(retxtwork1.test(trim(txtWork1.value))) || !(retxtwork1.test(trim(txtWork2.value))) || !(retxtwork2.test(trim(txtWork3.value))))
         {
            validation_summary = validation_summary + "Invalid Primary Phone. Please enter the # in XXX-XXX-XXXX format.\n";
            lblWPhone.style.color = "#ff0000";
         }
         else
         {
            lblWPhone.style.color = "#000000";
         }
    }
//    if(cmbProperty.selectedIndex == 0)
//    {
//        validation_summary = validation_summary + "Type of Property\n";
//        lblTypeProp.innerHTML = "*";
//    }
//    else
//    {
//        lblTypeProp.innerHTML = "";
//    }
//    
//    if(trim(txtTotalBal.value)=="")
//    {
//        validation_summary = validation_summary + "Total Mortgage Balance\n";
//        lblTotalBal.innerHTML = "*";
//    }
//    else
//    {
//        lblTotalBal.innerHTML = "";
//    }
//    
//    if(cmbTime.selectedIndex == 0)
//    {
//        validation_summary = validation_summary + "Best Time to Call\n";
//        lblTime.innerHTML = "*";
//    }
//    else
//    {
//        lblTime.innerHTML = "";
//    }
    
    if (validation_summary == "Please complete and answer the required fields:\n")
    {
        return true;
    }
    else
    {
        alert(validation_summary);
        return false;
    }
}