/*
COPYRIGHT: 2007-2008.
AUTHOR: John Connolly.
PURPOSE: Functions for the Contact Us page
*/



/*
FUNCTION: validateEmail()
PURPOSE: Validate the email id entered in the contact us form
INPUT: str = email id string
*/
function validateEmail(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 ;
   } 

   /* Email ID is valid */
   return true ;                              
} 



/*
FUNCTION: validateForm()
PURPOSE: Validate the contact us form
INPUT: form = name of the form.
*/
function validateForm(form){ 

   var contactName=form.fromname;
   var contactEmail=form.fromemail;
   /* var contactPhone=form.fromphone; */
   var contactMsg=form.message;
   
   /* Contact Name is Required */
   if ((contactName.value==null)||(contactName.value=="")){ 
      alert("Please enter your contact name (required)"); 
      contactName.focus() ;
      return false ;
   } 
   
   /* Email ID is optional, so only validate if a value is entered */
   if ((contactEmail.value!=null)&&(contactEmail.value!="") && (validateEmail(contactEmail.value)==false)) { 
      alert("Please enter a valid E-mail ID");
      contactEmail.value=""; 
      contactEmail.focus() ;
      return false ;
   }
   
   /* Message is Required */
   if ((contactMsg.value==null)||(contactMsg.value=="")){ 
      alert("Please enter a message (required)"); 
      contactMsg.focus() ;
      return false ;
   } 
/*   else {
       Prefix the message with the contact phone number if one entered 
      if ((contactPhone.value!=null)&&(contactPhone.value!="")){      
         contactMsg.value = "[PHONE: " + contactPhone.value + "][MSG: " + contactMsg.value + "]";
      }
   }

   alert("Message = " + contactMsg.value);
*/

   form.submit();
 
} 



/*
FUNCTION: getContactUsForm()
PURPOSE: HTML for contact us form
INPUT: bgColour = Background colour
*/
function getContactUsForm(bgColour) { 
document.write('<div class="ofTable ofTableRounded">');
document.write(' <div class="ofEntryForm ofLastChild">');
document.write('  <form name="" action="http://www.mrsite.co.uk/emailformpost.asp" method="post">');
document.write('   <table cellspacing="0">');
document.write('    <colgroup>');
document.write('     <col style="width: 50%" />');
document.write('     <col style="width: 50%" />');
document.write('    </colgroup>');
document.write('    <tbody>');
document.write('     <tr>');
document.write('      <th class="ofTextBlock">');
document.write('       <label for="fromname">Contact Name</label><span class="ofRequired">*</span>');
document.write('      </th>');
document.write('      <td>');
document.write('       <input type="text" name="fromname" size="20" value="">');
document.write('      </td>');
document.write('     </tr>');
document.write('     <tr>');
document.write('      <th class="ofTextBlock">');
document.write('       <label for="fromemail">Contact Email</label>');
document.write('      </th>');
document.write('      <td>');
document.write('       <input type="text" name="fromemail" size="20" value=""> ');
document.write('       <span class="ofNote">(optional)</span>');
document.write('      </td>');
document.write('     </tr>');
document.write('     <tr>');
document.write('      <th class="ofTextBlock">');
document.write('       <label for="message">Your Message</label><span class="ofRequired">*</span>');
document.write('      </th>');
document.write('      <td>');
document.write('       <textarea rows="5" cols="27" name="message"></textarea>');
document.write('      </td>');
document.write('     </tr>');
document.write('     <tr>');
document.write('      <td>');
document.write('       <input style="width: 0px" type="hidden" name="toname" value="">');
document.write('       <input style="width: 0px" type="hidden" name="foldername" value="cleanirishwater.com">');
document.write('       <br />');
document.write('       &nbsp;');
document.write('      </td>');
document.write('     </tr>');
document.write('     <tr>');
document.write('      <th>');
document.write('       &nbsp;');
document.write('      </th>');
document.write('      <td>');  
document.write('       <INPUT TYPE="button" NAME="button" Value="Send" onClick="validateForm(this.form)">');
document.write('       <input type="button" name="cancel" value="Cancel" style="width: 75px;" />');
document.write('      </td>');
document.write('     </tr>');
document.write('    </tbody>');
document.write('   </table>');
document.write('  </form>');
document.write(' </div>');
document.write('</div>');
}

/* TEMP LINES */
/*
document.write('         <tr>');
document.write('          <th class="ofTextBlock">');
document.write('           <label for="fromphone">Contact Phone</label>');
document.write('          </th>');
document.write('          <td>');
document.write('           <input type="text" name="fromphone" size="20" value="">');
document.write('           <span class="ofNote">(optional)</span>');
document.write('          </td>');
document.write('         </tr>');

document.write('         <tr>');
document.write('          <th>');
document.write('           <label for="select1">How did you hear about us?</label>');
document.write('          </th>');
document.write('          <td>');
document.write('           <select name="select1">');
document.write('            <option selected="selected">');
document.write('             - Select -');
document.write('            </option>');
document.write('            <option value="">');
document.write('             Option');
document.write('            </option>');
document.write('            <option value="">');
document.write('             Option');
document.write('            </option>');
document.write('            <option value="">');
document.write('             Option');
document.write('            </option>');
document.write('            <option value="">');
document.write('             Option');
document.write('            </option>');
document.write('            <option value="">');
document.write('             Option');
document.write('            </option>');
document.write('           </select>');
document.write('           <span class="ofNote">(optional)</span>');
document.write('          </td>');
document.write('         </tr>');

document.write('         <tr>');
document.write('          <th>');
document.write('           <label for="select2">Receive an email Newsletter?</label>');
document.write('          </th>');
document.write('          <td class="ofRadio">');
document.write('           <input name="radio1" name="radio1" type="radio" value=""> ');
document.write('           <label for="radio1">Yes</label>&nbsp;&nbsp; ');
document.write('           <input name="radio1" id="radio2" type="radio" value="">'); 
document.write('           <label for="radio2">No</label>');
document.write('          </td>');
document.write('         </tr>');

*/



/*
FUNCTION: getCustomerPhone()
PURPOSE: HTML company phone number
INPUT: bgColour = Background colour
*/
function getCustomerPhone(bgColour) { 
document.write('<!-- Start: Container, ' + bgColour + ' -->');
document.write('<div class="ofContainer ofAlt4Border ofAltBorderColorD7 ' + bgColour + ' ofPad1">');
document.write(' <div class="ofTextBlock ofCallout ofAltBullet1 ofTextAncillary ofLastChild">');
document.write('  <h4 class="ofFirstChild">');
document.write('   <font color="#CE9E00">Contact Us by Phone</font>');
document.write('  </h4>');
document.write('  <ul class="ofLastChild">');
document.write('   (087)914 8078');
document.write('  </ul>');
document.write(' </div>');
document.write('</div>');
document.write('<!-- End: Container, ' + bgColour + ' -->');
}



/*
FUNCTION: getCustomerEmail()
PURPOSE: HTML company email ID
INPUT: bgColour = Background colour
*/
function getCustomerEmail(bgColour) { 

document.write('<!-- Start: Container, ' + bgColour + ' -->');
document.write('<div class="ofContainer ofAlt4Border ofAltBorderColorD7 ' + bgColour + ' ofPad1">');
document.write(' <div class="ofTextBlock ofCallout ofAltBullet1 ofTextAncillary ofLastChild">');
document.write('  <h4 class="ofFirstChild">');
document.write('   <font color="#CE9E00">Contact Us by E-Mail</font>');
document.write('  </h4>');
document.write('  <ul class="ofLastChild">');
document.write('   info@cleanirishwater.com');
document.write('  </ul>');
document.write(' </div>');
document.write('</div>');
document.write('<!-- End: Container, ' + bgColour + ' -->');

}



/* TEMP FUNCTION */
/*
FUNCTION: getCustomerPost()
PURPOSE: HTML company postal address
INPUT: bgColour = Background colour
*/
function getCustomerPost(bgColour) { 
document.write('<!-- Start: Container, ' + bgColour + ' -->');
document.write('<div class="ofContainer ofAlt4Border ofAltBorderColorD7 ' + bgColour + ' ofPad1">');
document.write(' <div class="ofTextBlock ofCallout ofAltBullet1 ofTextAncillary ofLastChild">');
document.write('  <h4 class="ofFirstChild">');
document.write('   <font color="#CE9E00">Contact Us by Mail</font>');
document.write('  </h4>');
document.write('  <ul class="ofLastChild">');
document.write('   <li>');
document.write('    Clean Irish Water');
document.write('   </li>');
document.write('   <li>');
document.write('    Street x');
document.write('   </li>');
document.write('   <li>');
document.write('    Town x');
document.write('   </li>');
document.write('   <li>');
document.write('    Co. x');
document.write('   </li>');
document.write('   <li>');
document.write('    Ireland');
document.write('   </li>');
document.write('  </ul>');
document.write(' </div>');
document.write('</div>');
document.write('<!-- End: Container, ' + bgColour + ' -->');
}