$(document).ready(function(imgLoc,loc){
   // Define div that contains links and add class to each one.
   loc = document.getElementById("link");
   imgLoc = loc.getElementsByTagName("a");
   for(w=0; w<=imgLoc.length; w++){
      $(imgLoc[w]).addClass("locate");
      
   }
   springP(imgLoc,loc);
});

$(document).ready(function(){
   if(document.location.href.indexOf("contact.html")!== -1 || document.location.href.indexOf("contactfinish.php")!== -1){
      if($("#tow").attr("checked")!== "checked"){
         $("#web").hide();
      }
   }
});


function rollover(thisE)
{
    if(!document.getAttribute && document.setAttribute) return
    var regularState = thisE.getAttribute("src")
    var locateDot = regularState.indexOf(".");
    var changeState = regularState.slice(0,locateDot);
    var getExt = regularState.slice(locateDot);
    thisE.setAttribute("src",changeState + "over" + getExt);
    thisE.onmouseout = function(){thisE.setAttribute("src",regularState)
    }
} 

function chv()
{
   document.write("2.3");
}
function springP(imgLoc,loc){

   // On hover, grab attributes changeimg and changetext for image and text swap
   $(".locate").hover(function(){
      var img=$(this).attr("changeimg");
      var word=$(this).attr("changetext");
      // swap image in, making it hidden for the fade in effect.
      
      if($("#swapable").is(":hidden")){
         $("#swapable").attr("src",img);
         $("#text").text(word);
         $("#swapable").fadeIn(400);
         $("#text").fadeIn(400);
      }
   },function(){
   if($("#swapable").is(":visible")){
         $("#swapable").hide();
         $("#text").hide();
      }
      
   });
}
function checkField(thisE)
{
   var fieldType= thisE.getAttribute("name");
   var toSpan;
   if(thisE.nextSibling.nodeType===3){
      toSpan = thisE.nextSibling.nextSibling;
   }
   else{
      toSpan = thisE.nextSibling;
   }

   var getError;
   switch(fieldType){
      // checks to make sure the name input has something in it.
      case "nme":
         if(thisE.value === ""){
            thisE.style.border="2px solid #FF2222";
            thisE.setAttribute("status","<img src='graphic/error.png' alt='status' /> Blank Field");
            getError = thisE.getAttribute("status");
            toSpan.style.color="#FF2222";
            toSpan.style.fontSize="10pt";
            toSpan.innerHTML = getError;
            return false;
         } 
         else{
            thisE.style.border="2px solid #00FF00"; 
            thisE.setAttribute("status","<img src='graphic/correct.png' alt='status' />");
            getError = thisE.getAttribute("status");
            toSpan.innerHTML = getError;
            return true;
         }
         break;
         // checks the mail input for basic validness.
      case "mil":
         if(thisE.value === ""){
            thisE.style.border="2px solid #FF0000";
            thisE.setAttribute("status","<img src='graphic/error.png' alt='status' /> Blank Field");
            getError = thisE.getAttribute("status");
            toSpan.style.color="#FF2222";
            toSpan.style.fontSize="10pt";
            toSpan.innerHTML = getError;
         }
         else if(thisE.value.indexOf("@") !== -1  && thisE.value.indexOf("@") !== 0){
         
            var charC = thisE.value.length;
            console.log(charC);
            var indexC = thisE.value.lastIndexOf(".");
            console.log(indexC);
            var differ = charC - indexC;
            console.log(differ);
            switch(differ){
               case 3:
               case 4:
               case 5:
                
               thisE.style.border="2px solid #00FF00"; 
               thisE.setAttribute("status","<img src='graphic/correct.png' alt='status' />");
               getError = thisE.getAttribute("status");
               toSpan.innerHTML = getError;
               break;
               
               default:
               thisE.style.border="2px solid #FF0000";
               thisE.setAttribute("status","<img src='graphic/error.png' alt='status' /> Invalid Email Address");
               getError = thisE.getAttribute("status");
               toSpan.style.color="#FF2222";
               toSpan.style.fontSize="10pt";
               toSpan.innerHTML = getError;
               break;
            
            }// end of switch
            
         }
            
         else{
            thisE.style.border="2px solid #FF0000";
            thisE.setAttribute("status","<img src='graphic/error.png' alt='status' /> Invalid Email Address");
            getError = thisE.getAttribute("status");
            toSpan.style.color="#FF2222";
            toSpan.style.fontSize="10pt";
            toSpan.innerHTML = getError;

         }
           
         break;
         
      // to whom, checks whether email is sent to business or a copy is sent to me for a possible problem.   
      case "tow":
         // adds a text input for a website address to look up if theres a problem.
         if(thisE.value === "web"){
            if($("#web").is(":hidden")){
               $("#web").slideDown("fast");
            }
         }
            
         // if biz is reselected, removes text input for the url.   
        else if(thisE.value === "biz"){
            if($("#web").is(":visible")){
               $("#web").slideUp("fast");
            }        }
        break;
        
     // checks location text input to check for basic requirements.   
     case "url":
        if(thisE.value.indexOf(".html")!== -1 && thisE.value.indexOf("area57cafe.com")!== -1){
            thisE.style.border="2px solid #00FF00";
            thisE.setAttribute("status"," <img src='graphic/correct.png' alt='status' />");
            getError = thisE.getAttribute("status");
            toSpan.style.color="#00FF00";
            toSpan.innerHTML = getError;
        }
            
        else if(thisE.value.indexOf("area57cafe.com")===-1){
            thisE.style.border="2px solid #FF9922";
            thisE.setAttribute("status"," <img src='graphic/warn.png' alt='status' /> Domain is incorrect, document will proceed.");
            getError = thisE.getAttribute("status");
            toSpan.style.color="#FF9922";
            toSpan.style.fontSize="10pt";
            toSpan.innerHTML = getError;
        }
        break;
     // comment block, just checks for any text.
     case "cmt":
         if(thisE.value === ""){
            thisE.style.border="2px solid #FF2222";
            thisE.setAttribute("status","<img src='graphic/error.png' alt='status' /> You forgot your comment!");
            getError = thisE.getAttribute("status");
            toSpan.style.color="#FF2222";
            toSpan.style.fontSize="10pt";
            toSpan.innerHTML = getError;
         } 
         else{
            thisE.style.border="2px solid #00FF00"; 
            thisE.setAttribute("status","<img src='graphic/correct.png' alt='status' />");
            getError = thisE.getAttribute("status");
            toSpan.innerHTML = getError;
         }
   }// end of main switch
} // end of checkField()

function autoCheck(){
   var checkAll = new Array();
   checkAll[0] = "nme";
   checkAll[1] = "mil";
   checkAll[2] = "url";
   checkAll[3] = "cmt";
   var loc;
   for(x=0; x<=3; x++){
      loc=document.getElementById(checkAll[x]);
      loc.focus();
      loc.blur();
   }
}

