/****************************************
* Copyright 2006 Ex-designz.net & Myasp-net.com
* JavaScript written by: Dexter Zafra
****************************************/

//--------------------------------------------------------//
// Handle PopUp Window
function openWinReqPassword(url) 
 {
 popupWin = window.open(url,'new_page','width=430,height=230,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no')
}
//--------------------------------------------------------//


//--------------------------------------------------------//
// Multiple Functions to handle element OnFocus event on Contact form
function UnameContactFocus() 
 {
   document.getElementById('name').style.backgroundColor = '#FFF9EC'; 
   document.getElementById('lblconuname').style.color = '#000000';
   document.getElementById('lblconuname').innerHTML = 'Name:'; 
}
function UemailContactFocus() 
 {
   document.getElementById('email').style.backgroundColor = '#FFF9EC'; 
   document.getElementById('lblconemail').style.color = '#000000';
   document.getElementById('lblconemail').innerHTML = 'Email:';
}
function UcommentContactFocus() 
 {
   document.getElementById('comments').style.backgroundColor = '#FFF9EC'; 
   document.getElementById('lblcomment').style.color = '#000000';
   document.getElementById('lblcomment').innerHTML = 'Comments:';
}
// Handle Contact Form Validation
function ContactVal(ConForm) 
 {
 var FirstName = ConForm.elements['name'].value;
 var UserEMail = ConForm.elements['email'].value;
 var ConComments = ConForm.elements['comments'].value;
if (FirstName == "" && UserEMail == "" && ConComments =="") 
  {
     // Change the background color of the textbox,border as well as label text
     document.getElementById('name').style.backgroundColor='#FFF4F4'; 
     document.getElementById('name').style.border = '1px solid #CC0000';
     document.getElementById('lblconuname').style.color = '#CC0000';
     document.getElementById('lblconuname').innerHTML = 'Empty:';
     document.getElementById('email').style.backgroundColor='#FFF4F4'; 
     document.getElementById('email').style.border = '1px solid #CC0000';
     document.getElementById('lblconemail').style.color = '#CC0000';
     document.getElementById('lblconemail').innerHTML = 'Empty:';
     document.getElementById('comments').style.backgroundColor='#FFF4F4'; 
     document.getElementById('comments').style.border = '1px solid #CC0000';
     document.getElementById('lblcomment').style.color = '#CC0000';
     document.getElementById('lblcomment').innerHTML = 'Empty:';
     alert("Please fill in the empty fields.\n- Your name\n- Email\n- Comments");
     return false;
}
// Contact First name
 if (FirstName == "")
  {
     alert("You must enter your name");
     document.getElementById('name').style.backgroundColor='#FFF4F4'; 
     document.getElementById('name').style.border = '1px solid #CC0000';
     document.getElementById('lblconuname').style.color = '#CC0000';
     document.getElementById('lblconuname').innerHTML = 'Empty:';
     return false;
  }
// Allow only letters 
else if (FirstName.search(/^[A-Z ]+$/i) == -1) 
  {
     alert ("Your name contained numbers. Only alphabetic characters are allowed..\n Please try again.");
     document.getElementById('name').style.backgroundColor='#FFF4F4'; 
     document.getElementById('name').style.border = '1px solid #CC0000';
     document.getElementById('lblconuname').style.color = '#CC0000';
     document.getElementById('lblconuname').innerHTML = 'Illegal Char:';
     return false;
} 
 // Contact Email
 if (UserEMail == "")
  {
     alert("You must enter an email address");
     document.getElementById('email').style.backgroundColor='#FFF4F4'; 
     document.getElementById('email').style.border = '1px solid #CC0000';
     document.getElementById('lblconemail').style.color = '#CC0000';
     document.getElementById('lblconemail').innerHTML = 'Empty:';
     return false;
  }
else if (!(UserEMail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1))
 {
    alert("E-mail address is not valid.\n Please enter a valid email address.");
    document.getElementById('email').style.backgroundColor='#FFF4F4'; 
    document.getElementById('email').style.border = '1px solid #CC0000';
    document.getElementById('lblconemail').style.color = '#CC0000';
    document.getElementById('lblconemail').innerHTML = 'Invalid Email:';
    return false ;
}
 // Contact Comments Field
 if (ConComments == "")
  {
     alert("You must a comments or questions");
     document.getElementById('comments').style.backgroundColor='#FFF4F4'; 
     document.getElementById('comments').style.border = '1px solid #CC0000';
     document.getElementById('lblcomment').style.color = '#CC0000';
     document.getElementById('lblcomment').innerHTML = 'Empty:';
     return false;
  }
return true;
}


// Handle the registration form hide and unhide optional fields
 window.onload = function()
 {
  if(document.getElementById)
   {
     var linkContainer = document.getElementById('optreqlink');
     var linebreak = linkContainer.appendChild(document.createElement('br'));
     var toggle = linkContainer.appendChild(document.createElement('a'));
     toggle.href = '#';
     toggle.appendChild(document.createTextNode(' Hide optional fields?'));

   toggle.onclick = function()
    {
      var linkText = this.firstChild.nodeValue;
      this.firstChild.nodeValue = (linkText == ' Hide optional fields?') ? ' Display optional fields?' : ' Hide optional fields?';

      var tmp = document.getElementsByTagName('div');
      for (var i=0;i<tmp.length;i++)
      {
      if(tmp[i].className == 'optfield')
       {
         tmp[i].style.display = (tmp[i].style.display == 'none') ? 'block' : 'none';
       }
     }
     return false;
    }
  }
}