// ---------------------------------------------
// common javascript library for cruisingfree.com
// ---------------------------------------------
function footer_mouseover(obj) {
  obj.className = "footer_link_item_a_mouseover";
}

function footer_mouseout(obj) {
  obj.className = "footer_link_item_a";
}

function index_caption_mouseover(obj) {
  obj.className = "page_index_section_2_item_title_link_highlight";
}

function index_caption_mouseout(obj) {
  obj.className = "page_index_section_2_item_title_link";
}


function index_caption_steven_mouseover(obj) {
  obj.className = "page_index_section_2_item_title_link_highlight_steven";
}

function index_caption_steven_mouseout(obj) {
  obj.className = "page_index_section_2_item_title_link_steven";
}




function checkcruiseclasssignupform()
{

  var rslt = false;
  var frm = document.forms[0];

  if (fchk("fld_cust_first",3,"First Name")) {

    if (fchk("fld_cust_last",3,"Last Name")) {

      if (fchk("fld_cust_phone1", 3, "Phone")) {

        if (fchk("fld_cust_email",3,"Email Address")) {

          var emailaddress = gv(frm, "fld_cust_email");
          if (validateEmailAddress(emailaddress)) {

            if (frm.fld_over_eighteen.checked) {
              rslt = true;
            }
            else {
              alert("Error. 18 Years Old Confirmation Not Checked");
            }
          }
          else {
            alert("Error In Email Address");
          }
        }
      }
    }
  }

  return rslt;
}





function checksignupform() 
{

  var rslt = false;
  var frm = document.forms[0];

  if (fchk("fld_cust_first",3,"First Name")) {

    if (fchk("fld_cust_last",3,"Last Name")) {

      if (fchk("fld_cust_phone1", 3, "Phone")) {

        if (fchk("fld_cust_email",3,"Email Address")) {

          var emailaddress = gv(frm, "fld_cust_email");
          if (validateEmailAddress(emailaddress)) {

            if (frm.fld_over_eighteen.checked) {
              rslt = true;
            }
            else {
              alert("Error. 18 Years Old Confirmation Not Checked");
            }
          }
          else {
            alert("Error In Email Address");
          }
        }
      }
    }
  }


  return rslt;
}


function fchk(fldname, fldlength, emsg)
{
  var rslt = true;
  var gsform = document.forms[0];
  var s = gv(gsform, fldname);
  if (s.length < fldlength) {
    alert("Error In Field " + emsg);
    rslt = false;
  }
  return rslt;
}


// ----------------------------------------------
// gets a field value
// ----------------------------------------------
function gv(formReference, fieldname)
{

  var objString = "formReference." + fieldname;
  var obj = eval(objString);
  var s = obj.value;
  return s;
}


// ----------------------------------------------
// simple email validator
// ----------------------------------------------
function validateEmailAddress(str) 
{

  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)

  if (str.indexOf(at)==-1){
    return false
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    return false
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    return false
  }

  if (str.indexOf(at,(lat+1))!=-1){
    return false
  }

  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    return false
  }

  if (str.indexOf(dot,(lat+2))==-1){
    return false
  }
		
  if (str.indexOf(" ")!=-1){
    return false
  }

  return true					
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


// ---------------------------------------
// handles quick connect submit
// ---------------------------------------

function qcsubmit() 
{

  var rslt = false;
  var frm = document.forms[0];

  if (fchk("fld_page_index_quick_connect_first",3,"First Name")) {

    if (fchk("fld_page_index_quick_connect_last",3,"Last Name")) {
    
 
      /*

      var bEmailCheck = false;
      var sEmail = gv(frm, "fld_page_index_quick_connect_email");
      sEmail = trim(sEmail);
      nEmailLength = sEmail.length;
      if (nEmailLength > 0) {
        bEmailCheck = true;
      }
         
         
      var bPhoneCheck = false;
      var sPhone = gv(frm, "fld_page_index_quick_connect_phone");
      sPhone = trim(sPhone);
      nPhoneLength = sPhone.length;      
      if (nPhoneLength > 0) { 
         bPhoneCheck = true;
      }
 	
      */
 
      if (fchk("fld_page_index_quick_connect_email",3,"Email Address")) {

        var emailaddress = gv(frm, "fld_page_index_quick_connect_email");
        if (validateEmailAddress(emailaddress)) {
          rslt = true;
        }
        else {
          alert("Error In Email Address");
        }  
      }
    }
  }

  if (rslt) {
    frm.submit();
  }
  
  return rslt;
}
