
// Handles form validations

function formHandler(ourform) {

 //alert(ourform);

 switch (ourform){



 case "frmArtCmt":
 // Comments
 ourform = document.frmArtCmt;
 var errText=""; var arrI=0; var EmtF=new Array();
 // Create an array to hold the names of the fields that need to be validated.
 var formelem=['txtNamebedit', 'txtCommentbedit', 'ImVar']; // Shortcut Array Definition!
 
 if (ourform.txtNamebedit.value.length < 2) {
  errText     += "- Your Name was not entered.\n"; // Add the error to display to our string var
  EmtF[++arrI] = formelem[0]; // First increment the arrI variable then add the field name if the field was not entered in correctly
 }

 if (ourform.txtCommentbedit.value.length < 5) {
  errText     += "- Your Comment was not supplied.\n";
  EmtF[++arrI] = formelem[1];
 }

 if (ourform.txtCommentbedit.value.length > 2000) {
  errText     += "- Your Message is greater than 2000 characters.\n";
  EmtF[++arrI] = formelem[1];
 }

 if (ourform.ImVar.value.length < 4 || isNaN(ourform.ImVar.value)) {
  errText     += "- Anti-spam verfication code was not entered.\n";
  EmtF[++arrI] = formelem[2];
 }
 var errL = EmtF.length;
 if (errL > 0) {
  // Show message that required information was not supplied
  alert('The following ' + ((errL-1)>1 ? '' + (errL-1) + ' fields' : 'field') + ' must be corrected to post a comment:\n\n'+errText);

  // Focus first field supplied with incorrect information
  ourform.elements[EmtF[1]].focus();

  // Start by making sure that all text fields have a white background colour
  for (i in formelem) 
   eval('document.getElementById(\''+formelem[i]+'\').style.backgroundColor = \'#fff\';');

  // Visually highlight incorrectly filled fields by changing their background colour
  for (i in EmtF) 
   eval('document.getElementById(\''+EmtF[i]+'\').style.backgroundColor = \'pink\';');
  
  // Prevent form submission since errors were detected.
  return false;

 } else {
  // Allow form submission if no errors were detected.
  return true;
 }

 break;



 // Mail form on home page
 case "frmFormMail":

 ourform = document.frmFormMail;
 errText=""; arrI=0; EmtF=new Array();
 formelem=['txt_name', 'txt_message', 'ImVar'];

 if (ourform.txt_name.value.length < 2) {
  errText     += "- Your Name was not supplied.\n";
  EmtF[++arrI] = formelem[0];
 }

  if (ourform.txt_message.value.length < 5) {
  errText     += "- Your message was not supplied.\n";
  EmtF[++arrI] = formelem[1];
 }

 if (ourform.txt_message.value.length > 2000) {
  errText     += "- Your Message is greater than 2000 characters.\n";
  EmtF[++arrI] = formelem[1];
 }

 if (ourform.ImVar.value.length < 4 || isNaN(ourform.ImVar.value)) {
  errText     += "- Please enter the 4-digit code as it is displayed, in the left-hand box.\n";
  EmtF[++arrI] = formelem[2];
 }

 errL = EmtF.length;
 if (errL > 0) {
  alert('The following ' + ((errL-1)>1 ? '' + (errL-1) + ' fields' : 'field') + ' must be corrected to contact me:\n\n'+errText);

  ourform.elements[EmtF[1]].focus();

  for (i in formelem)
   eval('document.getElementById(\''+formelem[i]+'\').style.backgroundColor = \'#fff\';');

  // Visually highlight incorrectly filled fields by changing their background colour
  for (i in EmtF)
   eval('document.getElementById(\''+EmtF[i]+'\').style.backgroundColor = \'pink\';');

  return false;

 } else {
  return true;
 }




 //return false;

 break;







 case "ArtCmt":

 // 
 ourform = document.frmArtCmt;
 var errText=""; var arrI=0; var EmtF=new Array();

 if (ourform.txtNme.value.length < 1) {
  arrI++;
  errText   += "Your Name\n";
  EmtF[arrI] = "txtNme";

 }

 if (ourform.txtCmt.value.length < 1) {
  arrI++;
  errText   += "Your Comment\n";
  EmtF[arrI] = "txtCmt";
 }

 if (ourform.txtCmt.value.length > 6000) {
  arrI++;
  errText   += "Your Comment is greater than 6000 characters\n";
  EmtF[arrI] = "txtCmt";
 }

 if (ourform.ImVar.value.length < 4) {
  arrI++;
  errText   += "Anti-spam verfication\n";
  EmtF[arrI] = "ImVar";
 }

 if (arrI) {
  alert('The following fields must be supplied:\n\n'+errText);
  //alert(typeof(ourform.ImVar.value));
  ourform.elements[EmtF[1]].focus();
  return false;

 } else {
  return true;
 }

 break;

 } // end switch

} // end function




// SEARCH BOX
function sftm() {

 if (document.frm_q.q.value.length < 2) {
  alert('Please enter at least two characters.');
  document.frm_q.q.focus();
  return false;
 } // end if
 
}





/***********************************************
* Email Validation script- � Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}
// mailing list box
function sftm2(t) {

 if ( !checkmail(document.frmML.txtUser) || document.frmML.txtUser.value == 'enter email' ) {
  //alert(\'Please enter an email address.\');
  document.frmML.txtUser.value='';
  document.frmML.txtUser.focus();
  return false;
 } // end if
 
}


function checkmsglength(val, lenmax) {
 var msglength = val.length;
 if (msglength > lenmax) {
  document.getElementById("Msg").style.color = 'c00';
 } else {
  document.getElementById("Msg").style.color = '#000';
 }
 document.getElementById("Msg").innerHTML = 'Current Message Length: ' + msglength + '/' + lenmax + ' char(s)';
}



function init2() {
 
}


function processajax(serverPage, obj, getOrPost, id) {

 // Only set cookie if new subcategory was selected (not on page reload, for example)
 //alert(id);
 if (typeof(id)!="undefined") setCookie('smapitemselected', id, getExpDate(14,0,0));

 xmlhttp = getxmlhttp ();



 if (getOrPost == "get") {

  xmlhttp.open("GET", serverPage);

  /* send If-Modified-Since header - Prevents IE and others from caching (http://www.codingforums.com/showthread.php?t=142180) - 31-05-2009 */
  xmlhttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");


  //obj.innerHTML = "Getting Data, Please wait a moment ...";
  obj.innerHTML = "<span style=\"font-size: 18pt\">Loading... </span>" + FlPath(75, 35, "/images/flash/wait.swf");


  xmlhttp.onreadystatechange = function() {
   if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    obj.innerHTML = xmlhttp.responseText;
   }
  }
  xmlhttp.send(null);

 } else { // Using POST

 }

}


//alert('');
// Main AJAX function
function makerequest(serverPage, objID, id) {

 //alert('test');

 var obj = document.getElementById(objID);

 processajax(serverPage, obj, 'get', id);


}

// When page loads - get details for today
function init() {
 var cookieval = getCookie('smapitemselected');
 makerequest('ifr_smap.php?scatid=' + cookieval, 'div_skillsmap');
}



