// Validate Consumer request form
function consformval() {
// validate the fields
var msg="";
var errs=0;
var namerr=0;
var joberr=0;
var emerr=0;
var pherr=0;
var interr=0;
var leadserr=0;
ff = document.forms.ConsumerForm;

if (!validatePresent(ff.Name,  'lab_Name')) {
  errs += 1;
  namerr += 1;
}


 if (!validateEmail(ff.Email, 'lab_Email', true)) {
  errs += 1;
  emerr+= 1;
}

//if (!validateSelected(ff.State,  'lab_State'))        errs += 1; 

if (!validateTelnr  (ff.Phone, 'lab_Phone', true)) {
  pherr+= 1;
  errs += 1;
}


if (errs>0) {
	msg = "Please complete all required fields marked in red.";
	if (namerr>0) {
		msg = msg + "  \nPlease enter your name.";
	}
	if (emerr>0) {
		msg = msg + "  \nPlease give a valid email address.";
	}
	if (pherr>0) {
		msg = msg + "  \nPlease give a valid telephone number.";
	}
	alert(msg);
}
return (errs==0);
}

// Delayed focus setting to get around IE bug
function setFocusDelayed()
{
  global_valfield.focus();
}

function setfocus(valfield)
{
  // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}

var nbsp = 160;		// non-breaking space char
var node_text = 3;	// DOM text node-type
var emptyString = /^\s*$/ ;
var global_valfield;	// retain valfield for timer thread

// Trim leading/trailing whitespace off string
function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}


// Display warn/error message in HTML element.
// commonCheck routine must have previously been called
function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  var elem = document.getElementById(fld);
  elem.className = msgtype;   // set the CSS class to adjust appearance of message
}

// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed), 
//         false (validation failed) or 
//         proceed (don't know yet)
var proceed = 2;  
function commonCheck    (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  if (!document.getElementById) {
    return true;  // not available on this browser - leave validation to the server
  }
  var elem = document.getElementById(infofield);
  if (!elem.firstChild) {
	return true;  // not available on this browser 
	}
  /*
  if (elem.firstChild.nodeType != node_text) {
	alert("error c");
	return true;  // infofield is wrong type of node  
	}
*/
	if (emptyString.test(valfield.value)) {
    if (required) {
      msg (infofield, "laberr", "ERROR: required");  
      setfocus(valfield);
      return false;
    }
    else {
      msg (infofield, "labwarn", "");   // OK
      return true;  
    }
  }
  return proceed;
}

// Validate if something has been entered
function validatePresent(valfield,   // element to be validated
                         infofield ) // id of element to receive info/error msg
{
  var stat = false;
  stat = commonCheck (valfield, infofield, true);
  if (stat != proceed) return stat;

  msg (infofield, "lab", "");  
  return true;
}

// Validate if something has been selected
function validateSelected(valfield,   // element to be validated
                         infofield ) // id of element to receive info/error msg
{
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem = document.getElementById(infofield);
  if (!elem.firstChild) return true;  // not available on this browser 
  if (elem.firstChild.nodeType != node_text) return true;  // infofield is wrong type of node  
	if (valfield.selectedIndex <= 0) {
		msg(infofield, "laberr", "ERROR: required");
    setfocus(valfield);
    return false;
	}		

  msg (infofield, "lab", "");  
  return true;
}

// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
function validateEmail  (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
  if (!email.test(tfld)) {
    msg (infofield, "laberr", "ERROR: not a valid e-mail address");
    setfocus(valfield);
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
  if (!email2.test(tfld)) 
    msg (infofield, "labwarn", "Unusual e-mail address - check if correct");
  else
    msg (infofield, "lab", "");
  return true;
}

function validateURL (valfield, infofield)
{
	var stat = commonCheck (valfield, infofield, true);
	
	var webval = valfield.value;
	
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/ ;
	
	return regexp.test(webval) ;
}

// --------------------------------------------
//            validateTelnr
// Validate telephone number
// Returns true if so (and also if could not be executed because of old browser)
// Permits spaces, hyphens, brackets and leading +
// --------------------------------------------

function validateTelnr  (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var telnr = /^\+?[0-9 ()-xX]+[0-9]$/  ;
  if (!telnr.test(tfld)) {
    msg (infofield, "laberr", "ERROR: not a valid telephone number. Characters permitted are digits, space ()- and leading +");
    setfocus(valfield);
    return false;
  }

  var numdigits = 0;
  for (var j=0; j<tfld.length; j++)
    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;

  if (numdigits<6) {
    msg (infofield, "laberr", "ERROR: " + numdigits + " digits - too short");
    setfocus(valfield);
    return false;
  }

  if (numdigits>15) {
    msg (infofield, "labwarn", numdigits + " digits - check if correct");
    setfocus(valfield);
    return false;
  }
  else { 
    if (numdigits<10){
      msg (infofield, "labwarn", "Only " + numdigits + " digits - check if correct");
	    setfocus(valfield);
		  return false;
    }
    else {
      msg (infofield, "lab", "");
    }
  }
  return true;
}


function changegenerate() {
	document. getElementById('Genpic'). style. backgroundPosition = "-81px 0";
	document. getElementById('Gentoppic'). style. backgroundPosition = "-131px 0";
	document. getElementById('Genbottomtext'). style.color = '#B34C49';
	document. getElementById('SEOtxt'). style.color = '#B34C49';
	document. getElementById('SEMtxt'). style.color = '#B34C49';
	document. getElementById('Affiliate'). style.color = '#B34C49';
	document. getElementById('Gen'). style.border = "1px solid #B34C49";
	document.getElementById('Gen').style.cursor='pointer';
	document.getElementById('Gen').style.cursor='hand';
	
	
} 

function changegenerateback() {
	document.getElementById('Genpic').style.backgroundPosition = "0 0";
	document.getElementById('Gentoppic').style.backgroundPosition = "0 0";
	document.getElementById('Genbottomtext').style.color = '#5D5D5D';
	document. getElementById('SEOtxt'). style.color = '#5D5D5D';
	document. getElementById('SEMtxt'). style.color = '#5D5D5D';
	document. getElementById('Affiliate'). style.color = '#5D5D5D';
	document. getElementById('Gen'). style.border = 'none';
	
} 

function changerespond() {
	document. getElementById('Respondpic'). style. backgroundPosition = "-81px 0";
	document. getElementById('Respondtoppic'). style. backgroundPosition = "-120px 0";
	document. getElementById('Respondbottomtext'). style.color = '#B34C49';
	document. getElementById('Resp'). style.border = "1px solid #B34C49";
	document.getElementById('Resp').style.cursor='pointer';
	document.getElementById('Resp').style.cursor='hand';
} 

function changerespondback() {
	document.getElementById('Respondpic').style.backgroundPosition = "0 0";
	document.getElementById('Respondtoppic').style.backgroundPosition = "0 0";
	document.getElementById('Respondbottomtext').style.color = '#5D5D5D';
	document. getElementById('Resp'). style.border = 'none';
} 

function changequalify() {
	document. getElementById('Qualifypic'). style. backgroundPosition = "-81px 0";
	document. getElementById('Qualifytoppic'). style. backgroundPosition = "-108px 0";
	document. getElementById('Qualifybottomtext'). style.color = '#B34C49';
	document. getElementById('Qual'). style.border = "1px solid #B34C49";
	document.getElementById('Qual').style.cursor='pointer';
	document.getElementById('Qual').style.cursor='hand';
} 

function changequalifyback() {
	document.getElementById('Qualifypic').style.backgroundPosition = "0 0";
	document.getElementById('Qualifytoppic').style.backgroundPosition = "0 0";
	document.getElementById('Qualifybottomtext').style.color = '#5D5D5D';
	document. getElementById('Qual'). style.border = 'none';
} 

function changelivetransfer() {
	document. getElementById('LiveTransferpic'). style. backgroundPosition = "-81px 0";
	document. getElementById('LiveTransfertoppic'). style. backgroundPosition = "-195px 0";
	document. getElementById('LiveTransferbottomtext'). style.color = '#B34C49';
	document. getElementById('LiveTrans'). style.border = "1px solid #B34C49";
	document.getElementById('LiveTrans').style.cursor='pointer';
	document.getElementById('LiveTrans').style.cursor='hand';
} 

function changelivetransferback() {
	document.getElementById('LiveTransferpic').style.backgroundPosition = "0 0";
	document.getElementById('LiveTransfertoppic').style.backgroundPosition = "0 0";
	document.getElementById('LiveTransferbottomtext').style.color = '#5D5D5D';
	document. getElementById('LiveTrans'). style.border = 'none';
} 

function changereport() {
	document. getElementById('Reportpic'). style. backgroundPosition = "-81px 0";
	document. getElementById('Reporttoppic'). style. backgroundPosition = "-216px 0";
	document. getElementById('Reportbottomtext'). style.color = '#B34C49';
	document. getElementById('Rep'). style.border = "1px solid #B34C49";
	document.getElementById('Rep').style.cursor='pointer';
	document.getElementById('Rep').style.cursor='hand';
} 

function changereportback() {
	document.getElementById('Reportpic').style.backgroundPosition = "0 0";
	document.getElementById('Reporttoppic').style.backgroundPosition = "0 0";
	document.getElementById('Reportbottomtext').style.color = '#5D5D5D';
	document. getElementById('Rep'). style.border = 'none';
} 

function changeSEM() {
	document.getElementById('SEM').style.backgroundPosition = "0 0";
	document.getElementById('SEM').style.cursor='pointer';
	document.getElementById('SEM').style.cursor='hand';
} 

function changeSEMback() {
	document.getElementById('SEM').style.backgroundPosition = "188px 0";
} 

function changeSEO() {
	document.getElementById('SEO').style.backgroundPosition = "0 0";
	document.getElementById('SEO').style.cursor='pointer';
	document.getElementById('SEO').style.cursor='hand';
} 

function changeSEOback() {
	document.getElementById('SEO').style.backgroundPosition = "188px 0";
} 

function changeLeadQual() {
	document.getElementById('Lead_Qual').style.backgroundPosition = "0 0";
	document.getElementById('Lead_Qual').style.cursor='pointer';
	document.getElementById('Lead_Qual').style.cursor='hand';
} 

function changeLeadQualback() {
	document.getElementById('Lead_Qual').style.backgroundPosition = "188px 0";
} 

function changesentient() {
	document.getElementById('sentientpic').style.backgroundPosition = "-138px 0";
} 

function changesentientback() {
	document.getElementById('sentientpic').style.backgroundPosition = "0 0";
} 

function changeembassy() {
	document.getElementById('embassypic').style.backgroundPosition = "-111px 0";
} 

function changeembassyback() {
	document.getElementById('embassypic').style.backgroundPosition = "0 0";
} 

function showservicesmenu() {
	document. getElementById('servicesmenu'). style. display = 'inline';
	document. getElementById('aboutusmenu'). style. display = 'none';
	document. getElementById('contactusmenu'). style. display = 'none';
}

function hideservicesmenu() {
	document. getElementById('servicesmenu'). style. display = 'none';
	document. getElementById('aboutusmenu'). style. display = 'none';
	document. getElementById('contactusmenu'). style. display = 'none';
}

function showaboutusmenu() {
	document. getElementById('aboutusmenu'). style. display = 'inline';
	document. getElementById('servicesmenu'). style. display = 'none';
	document. getElementById('contactusmenu'). style. display = 'none';
}

function hideaboutusmenu() {
	document. getElementById('aboutusmenu'). style. display = 'none';
	document. getElementById('servicesmenu'). style. display = 'none';
	document. getElementById('contactusmenu'). style. display = 'none';
}

function showcontactusmenu() {
	document. getElementById('contactusmenu'). style. display = 'inline';
	document. getElementById('servicesmenu'). style. display = 'none';
	document. getElementById('aboutusmenu'). style. display = 'none';
}

function hidecontactusmenu() {
	document. getElementById('contactusmenu'). style. display = 'none';
	document. getElementById('servicesmenu'). style. display = 'none';
	document. getElementById('aboutusmenu'). style. display = 'none';
}

function changeclientlogin() {
	document. getElementById('clientloginimg'). style. backgroundPosition = "0 0";
	document.getElementById('clientloginimg').style.cursor='pointer';
	document.getElementById('clientloginimg').style.cursor='hand';
}

function changeclientloginback() {
	document. getElementById('clientloginimg'). style. backgroundPosition = "-89px 0";
}

function changeWhitepaper() {
	document. getElementById('WhitePaper'). style. backgroundPosition = "-188px 0";
	document.getElementById('WhitePaper').style.cursor='pointer';
	document.getElementById('WhitePaper').style.cursor='hand';
}

function changeWhitepaperback() {
	document. getElementById('WhitePaper'). style. backgroundPosition = "0 0";
}








