//------------- Core Navigation ---------------------------
function roll_over(img_name, img_src)
   {
   document[img_name].src = img_src;
   }
   
//--------------FORM Validation -------------------------
function clickclear(thisfield, defaulttext) 
{
if (thisfield.value == defaulttext) 
{
thisfield.value = "";
}
}
function clickrecall(thisfield, defaulttext) 
{
if (thisfield.value == "") 
{
thisfield.value = defaulttext;
}
}
function validateFormOnSubmit(theForm) 
{
	 
	var reason = "";
	reason += validateEmpty(theForm.name);
	reason += validateEmail(theForm.email);
	reason += validatePhone(theForm.phone);
	reason += validatevl(theForm.sq);
	
	//reason += validatePhone(theForm.phone);	
	if(reason != "") 
	{
		alert("Fill in the valid information in highlighted fields:\n" + reason);
		return false;
	}
	return true;
}
function validatevl(fld) 
{
    var error = "";
 
    if ((fld.value.length == 0)||(fld.value != '4')) 
	{
        fld.style.background = '#ccffff'; 
        error = "> Kindly provide a valid answer.\n"
    } 
	else 
	{
        fld.style.background = 'White';
    }
    return error;  
}
function validateEmpty(fld) 
{
    var error = "";
 
    if ((fld.value.length == 0)||(fld.value == 'Name')) 
	{
        fld.style.background = '#ccffff'; 
        error = "> Kindly provide a valid name.\n"
    } 
	else 
	{
        fld.style.background = 'White';
    }
    return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#ccffff';
        error = "> Provide an Email Address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#ccffff';
        error = "> Please enter a valid Email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#ccffff';
        error = "> The Email address contains invalid characters.\n";
    } else {
        fld.style.background = '#ffffff';
    }
    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "> You didn't enter a phone number.\n";
        fld.style.background = '#ccffff';
    } else if (isNaN(parseInt(stripped))) {
        error = "> The Phone number contains invalid characters.\n";
        fld.style.background = '#ccffff';
    } else if (!(stripped.length == 10)) {
        //error = "The Phone number is the wrong length. Make sure you included an area code.\n";
        //fld.style.background = 'Yellow';
    }
    return error;
}

