function checkValue(el){

if(el != 'address_select' && el != 'email_change'){
var fv = document.getElementById(el).value;
}

if(document.getElementById(el) && document.getElementById(el).type == 'checkbox'){
fv = document.getElementById(el).checked;
}

var emailValidationRule = new RegExp(/^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/);
var postcodeValidationRule = new RegExp(/^([A-PR-UWYZa-pr-uwyz]([0-9]{1,2}|([A-HK-Ya-hk-y][0-9]|[A-HK-Ya-hk-y][0-9]([0-9]|[ABEHMNPRV-Yabehmnprv-y]))|[0-9][A-HJKS-UWa-hjks-uw])\ {0,1}[0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}|([Gg][Ii][Rr]\ 0[Aa][Aa])|([Ss][Aa][Nn]\ {0,1}[Tt][Aa]1)|([Bb][Ff][Pp][Oo]\ {0,1}([Cc]\/[Oo]\ )?[0-9]{1,4})|(([Aa][Ss][Cc][Nn]|[Bb][Bb][Nn][Dd]|[BFSbfs][Ii][Qq][Qq]|[Pp][Cc][Rr][Nn]|[Ss][Tt][Hh][Ll]|[Tt][Dd][Cc][Uu]|[Tt][Kk][Cc][Aa])\ {0,1}1[Zz][Zz]))$/);
var fail = 0;

switch(el){

case "email_change":
var pass = document.getElementById('password1').value;
if(document.getElementById('original_email').value != document.getElementById('email1').value && pass.length == 0){
fail = 1;
}
break;

case "company_name":
if(fv.length < 2){
fail = 1;
}
results = 'enter your company name';
break;

case "firstname":
if(fv.length < 2){
fail = 1;
}
results = 'enter your first name';
break;

case "surname":
if(fv.length < 2){
fail = 1;
}
results = 'enter your surname';
break;

case "fullname":
if(fv.length < 2){
fail = 1;
}
results = 'enter your name';
break;

case "users_name":
if(fv.length < 2){
fail = 1;
}
results = 'enter your name';
break;

case "friends_name":
if(fv.length < 2){
fail = 1;
}
results = 'enter your friends name';
break;

case "username":
if(fv.length < 2){
fail = 1;
}
results = 'enter a username';
break;

case "company_type":
if(fv.length == 0){
fail = 1;
}
results = 'select your trade';
break;

case "description_txt":
if(fv.length == 0){
fail = 1;
}
results = 'enter a description of your business';
break;

case "trades":
if(fv.length == 0){
fail = 1;
}
results = 'select your trade';
break;

case "areas":
if(fv.length == 0){
fail = 1;
}
results = 'select your area';
break;

case "telephone":
if(fv.substring(0,1) != '0' || fv.length < 9 || isNaN(fv.replace(/ /g, "")) == true){
fail = 1;
}
results = 'enter numbers only';
break;

case "mobile":
if(fv.length > 0 && (fv.substring(0,1) != '0' || fv.length < 9 || isNaN(fv.replace(/ /g, "")) == true)){
fail = 1;
}
results = 'enter numbers only';
break;

case "email1":
if(fv.length == 0 || !emailValidationRule.test(fv)){
fail = 1;
}
results = 'enter your email address';
break;

case "email2":
if(fv.length == 0 || !emailValidationRule.test(fv) || fv != document.getElementById('email1').value){
fail = 1;
}
results = 'confirm your email address';
break;

case "email_address":
if(fv.length == 0 || !emailValidationRule.test(fv)){
fail = 1;
}
results = 'enter your email address';
break;

case "users_email":
if(fv.length == 0 || !emailValidationRule.test(fv)){
fail = 1;
}
results = 'enter your email address';
break;

case "friends_email":
if(fv.length == 0 || !emailValidationRule.test(fv)){
fail = 1;
}
results = 'enter your friends email address';
break;

case "password1":
if(fv.length < 6 || fv.length > 16){
fail = 1;
}
results = 'choose 6-16 alphanumeric characters';
break;

case "password2":
if(fv.length < 6 || fv.length > 16 || fv != document.getElementById('password1').value){
fail = 1;
}
results = 'confirm your password';
break;

case "line_1":
if(fv.length == 0){
fail = 1;
}
results = 'enter your address';
break;

case "city":
if(fv.length == 0){
fail = 1;
}
results = 'select your town / city';
break;

case "postcode":
if(fv.length == 0 || !postcodeValidationRule.test(fv)){
fail = 1;
}
results = 'enter your postcode';
break;

case "terms":
if(fv == false){
fail = 1;
}
results = 'agree to the terms of use';
break;

case "web_link":
if(fv.length == 0){
fail = 1;
}
results = 'enter your website link';
break;

case "job_title":
if(fv.length < 5){
fail = 1;
}
results = 'enter a job title';
break;

case "job_description":
if(fv.length < 10){
fail = 1;
}
results = 'enter a job description';
break;

case "message":
if(fv.length < 10){
fail = 1;
}
results = 'enter a description';
break;

case "address_select":
if(document.getElementById('address_select_0').checked == true && (document.getElementById('line_1').value == '' || document.getElementById('city').value == '' || document.getElementById('postcode').value == '')){
fail = 1;
}
results = 'select or enter an address';
break;

}

var result_div = el+'_result';
var el = el+'_wrap';

if(fail > 0){

if(el == 'email_change_wrap'){

document.getElementById('email_change').style.display = 'block';

return false;

}

else{

// cross

document.getElementById(result_div).innerHTML = '<img src="/images/cross.png" alt="" /><span>Please '+results+'</span>';

return false;

}

}

else{

// tick

if(el != 'email_change_wrap'){

document.getElementById(result_div).innerHTML = '<img src="/images/tick.png" alt="" />';

}

return true;

}

}

function formval(form_name){

switch(form_name){

case "register":
var form_elements = new Array("firstname","surname","telephone","mobile","email1","email2","password1","password2","line_1","line_2","line_3","city","postcode","newsletter","terms");
break;

case "register-my-business":
var form_elements = new Array("company_name","firstname","surname","username","trades","areas","telephone","mobile","email1","email2","password1","password2","line_1","line_2","line_3","city","postcode","newsletter","terms","trading_name","company_type","company_reg_number","description_txt","website","reference_1_name","reference_1_telephone","reference_2_name","reference_2_telephone","reference_3_name","reference_3_telephone");
break;

case "postjob":
var form_elements = new Array("job_title","trades","address_select","job_description");
break;

case "personal-details":
var form_elements = new Array("firstname","surname","telephone","mobile","email1","email2","line_1","line_2","line_3","city","postcode","email_change");
break;

case "edit-company-profile":
var form_elements = new Array("firstname","surname","username","telephone","mobile","email1","email2","line_1","line_2","line_3","city","postcode","description","website","email_change");
break;

case "password-reset":
var form_elements = new Array("password1","password2");
break;

case "contact-us":
var form_elements = new Array("fullname", "telephone", "email_address", "message");
break;

case "refer":
var form_elements = new Array("users_name", "friends_name", "users_email", "friends_email");
break;

case "links":
var form_elements = new Array("users_name", "users_email", "web_link", "info");
break;

}

for (x in form_elements)
{
	if(checkValue(form_elements[x]) == false){
	var phail = true;
	}
}

if(phail != true){

if(form_name == "postjob"){

var imageVal = document.getElementById('image_1').value;

if(imageVal.length > 0){

// loading images
document.getElementById('image_result').innerHTML = '<span>Uploading images, please wait...</span>';

}

}

document.forms[form_name].submit();

}

else{
window.scroll(0,0);

if(document.getElementById('error_div')){
document.getElementById('error_div').innerHTML = '<p style="color: #cc0000;"><strong>Please correct the highlighted fields.</strong></p>';
document.getElementById('error_div').style.display = 'block';
}

}

}

function removeHighlight(el){

var wrap = el+'_wrap';
var wrap = document.getElementById(wrap);
wrap.style.backgroundColor = '#FFFFFF';

}

function highlight(el){

if(document.getElementById('areas_wrap')){
document.getElementById('areas_wrap').style.backgroundColor = '#FFFFFF';
}

if(document.getElementById('trades_wrap')){
document.getElementById('trades_wrap').style.backgroundColor = '#FFFFFF';
}

var wrap = el+'_wrap';
var wrap = document.getElementById(wrap);
wrap.style.backgroundColor = '#FFF7C0';

}

function addNewTrade(newid){

document.getElementById('areas_wrap').style.backgroundColor = '#FFFFFF';
document.getElementById('trades_wrap').style.backgroundColor = '#FFF7C0';

var x=document.getElementById("trades");

var newDropdown = '<select id="trade_'+newid+'" name="trade_'+newid+'" class="textbox" onfocus="return highlight(\'trades\');" onblur="return removeHighlight(\'trades\');">'+"\n";

for (i=0;i<x.length;i++)
  {
  newDropdown=newDropdown + '<option value="'+x.options[i].value+'">'+x.options[i].text+'</option>'+"\n";
  }

newDropdown=newDropdown + '</select>'+"\n";

  var newdiv = document.createElement('div');
  var divIdName = 'trade_container_'+newid;
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = newDropdown;
  document.getElementById('multiple_trades').style.fontSize = '1em';
  document.getElementById('multiple_trades').appendChild(newdiv);

newid++;

if(newid < 18){
var new_link = '<a onclick="return addNewTrade('+newid+');">Add another</a>';
document.getElementById('addNewTrade').innerHTML = new_link;
}

else{
document.getElementById('addNewTrade').innerHTML = '';
}

document.getElementById('total_trades').value = newid;

}

function addNewArea(newid){

document.getElementById('trades_wrap').style.backgroundColor = '#FFFFFF';
document.getElementById('areas_wrap').style.backgroundColor = '#FFF7C0';

var x=document.getElementById("areas");

var newDropdown = '<select id="area_'+newid+'" name="area_'+newid+'" class="textbox" onfocus="return highlight(\'areas\');" onblur="return removeHighlight(\'areas\');">'+"\n";

for (i=0;i<x.length;i++)
  {
  newDropdown=newDropdown + '<option value="'+x.options[i].value+'">'+x.options[i].text+'</option>'+"\n";
  }

newDropdown=newDropdown + '</select>'+"\n";

  var newdiv = document.createElement('div');
  var divIdName = 'area_container_'+newid;
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = newDropdown;
  document.getElementById('multiple_areas').appendChild(newdiv);

newid++;

if(newid < 10){
var new_link = '<a onclick="return addNewArea('+newid+');">Add another</a>';
document.getElementById('addNewArea').innerHTML = new_link;
}

else{
document.getElementById('addNewArea').innerHTML = '';
}

document.getElementById('total_areas').value = newid;

}

function updateMainArea()
{

document.getElementById('areas').value = document.getElementById('city').value;
autoSelectAreas();

}

function autoSelectAreas(){

if(document.getElementById('areas').value != '' && isNaN(document.getElementById('areas').value) == false){

var string = "/functions/ajax_localAreas.php?area=" + document.getElementById('areas').value + "&radius=11";

var xmlHttp;
cursor_wait();
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	cursor_clear();
	var ajaxResponse = xmlHttp.responseText;
	var arArray = new Array();
	arArray = ajaxResponse.split("^_^_SPLIT_^_^",2);

	var totalAreas = arArray[0];
	var localAreasHtml = arArray[1];

if(totalAreas < 10){
var new_link = '<a onclick="return addNewArea('+totalAreas+');">Add another</a>';
document.getElementById('addNewArea').innerHTML = new_link;
}

else{
document.getElementById('addNewArea').innerHTML = '';
}

document.getElementById('total_areas').value = totalAreas;

document.getElementById('multiple_areas').innerHTML = localAreasHtml;

      }
    }
  xmlHttp.open("GET",string,true);
  xmlHttp.send(null);

}

else
{

}

}

function cursor_wait() {
document.body.style.cursor = 'wait';
}

// Returns the cursor to the default pointer
function cursor_clear() {
document.body.style.cursor = 'default';
}

function addressEnabler(enable_ref)
{

if(enable_ref == '1'){

// enable address area

document.getElementById('line_1').disabled=false;
document.getElementById('line_2').disabled=false;
document.getElementById('line_3').disabled=false;
document.getElementById('city').disabled=false;
document.getElementById('postcode').disabled=false;

}

else{

// disable address area

document.getElementById('line_1').disabled=true;
document.getElementById('line_2').disabled=true;
document.getElementById('line_3').disabled=true;
document.getElementById('city').disabled=true;
document.getElementById('postcode').disabled=true;

document.getElementById('line_1').value='';
document.getElementById('line_2').value='';
document.getElementById('line_3').value='';
document.getElementById('city').value='';
document.getElementById('postcode').value='';

}

}

function addImageInput(newid){

newid = newid + 1;

  var newdiv = document.createElement('div');
  var divClass = 'image_upload_container';
  var divID = divClass+'_'+newid;
  newdiv.setAttribute('id',divID);
  newdiv.setAttribute('class',divClass);
  newdiv.innerHTML = '<input type="file" name="image_'+newid+'" id="image_'+newid+'" class="textbox" onfocus="return highlight(\'image\');" onblur="return removeHighlight(\'image\');" />';
  document.getElementById('image_uploads').appendChild(newdiv);
  document.getElementById('total_images').value=newid;

if(newid < 3){
document.getElementById('addImageLink').innerHTML = '<a onclick="return addImageInput('+newid+');">Add another</a>';
}

else{
document.getElementById('addImageLink').innerHTML = '';
document.getElementById('addImageLink').style.display = 'none';
}

}

function addImageInput2(newid, limit){

newid = newid + 1;

  var newdiv = document.createElement('div');
  var divClass = 'image_upload_container';
  var divID = divClass+'_'+newid;
  newdiv.setAttribute('id',divID);
  newdiv.setAttribute('class',divClass);
  newdiv.innerHTML = '<input type="file" name="image_'+newid+'" id="image_'+newid+'" class="textbox" onfocus="return highlight(\'image\');" onblur="return removeHighlight(\'image\');" />';
  document.getElementById('image_uploads').appendChild(newdiv);
  document.getElementById('total_images').value=newid;

if(newid < limit){
document.getElementById('addImageLink').innerHTML = '<a onclick="return addImageInput2('+newid+','+limit+');">Add another</a>';
}

else{
document.getElementById('addImageLink').innerHTML = '';
document.getElementById('addImageLink').style.display = 'none';
}

}

function jobs_search(){

var tradeVal = (document.getElementById('trade')) ? document.getElementById('trade').value : '' ;
var areaVal = (document.getElementById('area')) ? document.getElementById('area').value : '' ;
var radiusVal = (document.getElementById('radius')) ? document.getElementById('radius').value : '' ;
var postcodeVal = (document.getElementById('postcode')) ? document.getElementById('postcode').value : '' ;

var newURL = '';

if(tradeVal.length > 0 && areaVal.length > 0){
newURL = '/'+tradeVal+'/jobs/'+areaVal;
}

else if(tradeVal.length == 0 && areaVal.length > 0){
newURL = '/'+areaVal+'/jobs/all-trades';
}

else if(tradeVal.length > 0 && areaVal.length == 0){
newURL = '/'+tradeVal+'/jobs/all-areas';
}

else{
newURL = '/view-jobs';
}

newURL+=(postcodeVal.length > 0) ? '?postcode='+postcodeVal+'&radius='+radiusVal : '';

location.href=newURL;

}

function tradesmen_search(){

var tradeVal = (document.getElementById('trade')) ? document.getElementById('trade').value : '' ;
var areaVal = (document.getElementById('area')) ? document.getElementById('area').value : '' ;
var radiusVal = (document.getElementById('radius')) ? document.getElementById('radius').value : '' ;
var postcodeVal = (document.getElementById('postcode')) ? document.getElementById('postcode').value : '' ;

var newURL = '';

if(tradeVal.length > 0 && areaVal.length > 0){
newURL = '/tradesmen/'+tradeVal+'/'+areaVal;
}

else if(tradeVal.length == 0 && areaVal.length > 0){
newURL = '/tradesmen/'+areaVal+'/all-trades';
}

else if(tradeVal.length > 0 && areaVal.length == 0){
newURL = '/tradesmen/'+tradeVal+'/all-areas';
}

else{
newURL = '/tradesmen';
}

newURL+=(postcodeVal.length > 0) ? '?postcode='+postcodeVal+'&radius='+radiusVal : '';

location.href=newURL;

}

function feedbackBox(id){

var divID = 'popupDiv';
var box;

var content = '<h1>Leave feedback</h1><div class="popup_close"><a onclick="return popupDisplayNone(\''+divID+'\');"><img src="/images/cross.png" alt="Close" title="Close" /></a></div>\
<form method="post" action="/post_feedback.php" id="feedback_form">\
<input type="hidden" name="jid" value="'+id+'" />\
<div class="formRowWrapper">\
<div class="formRowLeft" style="width: 70px;">Your rating</div>\
<div class="formRowRight">\
<div class="ratingsPanel">\
<div id="reviewRating" style="background-image: url(\'/images/10-star.gif\'); background-repeat: no-repeat; background-position: top right;">\
<a onclick="return changeRating(\'0\',\'reviewRating\');"><img src="/images/ratings_block.gif" alt="0" title="0" /></a>\
<a onclick="return changeRating(\'1\',\'reviewRating\');"><img src="/images/ratings_block.gif" alt="0.5" title="0.5" style="width:9px;" /></a>\
<a onclick="return changeRating(\'2\',\'reviewRating\');" style="width:9px;"><img src="/images/ratings_block.gif" alt="1" title="1" style="width:9px;" /></a>\
<a onclick="return changeRating(\'3\',\'reviewRating\');"><img src="/images/ratings_block.gif" alt="1.5" title="1.5" /></a>\
<a onclick="return changeRating(\'4\',\'reviewRating\');" style="width:9px;"><img src="/images/ratings_block.gif" alt="2" title="2" style="width:9px;" /></a>\
<a onclick="return changeRating(\'5\',\'reviewRating\');"><img src="/images/ratings_block.gif" alt="2.5" title="2.5" /></a>\
<a onclick="return changeRating(\'6\',\'reviewRating\');" style="width:9px;"><img src="/images/ratings_block.gif" alt="3" title="3" style="width:9px;" /></a>\
<a onclick="return changeRating(\'7\',\'reviewRating\');"><img src="/images/ratings_block.gif" alt="3.5" title="3.5" /></a>\
<a onclick="return changeRating(\'8\',\'reviewRating\');" style="width:9px;"><img src="/images/ratings_block.gif" alt="4" title="4" style="width:9px;" /></a>\
<a onclick="return changeRating(\'9\',\'reviewRating\');"><img src="/images/ratings_block.gif" alt="4.5" title="4.5" /></a>\
<a onclick="return changeRating(\'10\',\'reviewRating\');" style="width:9px;"><img src="/images/ratings_block.gif" alt="5" title="5" style="width:9px;" /></a>\
<input type="hidden" id="rating" name="rating" value="10" />\
</div></div>\
</div></div>\
<div class="formRowWrapper">\
<div class="formRowLeft"><label for="review">Your review</label></div>\
<div class="formRowRight"><textarea id="review" name="review" rows="5" cols="32"></textarea></div>\
</div>\
<div class="formRowWrapper" style="text-align: right;">\
<a onclick="valFeedback();" style="margin-right: 25px; cursor: pointer;"><img src="/images/submit_review.gif" alt="Submit review" /></a>\
</div>\
</form>\
<div style="display: none;">\
<img src="/images/0-star.gif" alt="" />\
<img src="/images/1-star.gif" alt="" />\
<img src="/images/2-star.gif" alt="" />\
<img src="/images/3-star.gif" alt="" />\
<img src="/images/4-star.gif" alt="" />\
<img src="/images/5-star.gif" alt="" />\
<img src="/images/6-star.gif" alt="" />\
<img src="/images/7-star.gif" alt="" />\
<img src="/images/8-star.gif" alt="" />\
<img src="/images/9-star.gif" alt="" />\
<img src="/images/10-star.gif" alt="" />\
</div>';

var divWidth = 400;
var divHeight = 200;

if(document.getElementById(divID)){
box = document.getElementById(divID);
}

else{
box = document.createElement("div");
box.setAttribute("id",divID);
box.setAttribute("class","popup");
box.className = 'popup';
document.body.appendChild(box);
}

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);
	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.width = divWidth+'px';
	box.innerHTML = content;
	box.style.display = 'block';
	box.style.position = 'absolute';
	box.style.top = scrollingTop+'px';
	box.style.left = scrollingLeft+'px';
	box.style.zIndex = '3';

	return hideShowSelects('hidden');

}

function valFeedback(){

var form_name = 'feedback_form';

var review_val = document.getElementById('review').value;

if(review_val.length == 0 || review_val == 'Please leave a detailed review of the tradesman'){

document.getElementById('review').value = 'Please leave a detailed review of the tradesman';

}

else{

document.forms[form_name].submit();

}

}

function popupDisplayNone(div){
document.getElementById(div).style.display = 'none';
document.getElementById(div).style.width = '';
hideShowSelects('visible');
}

function hideShowSelects(toggle){

if(navigator.appName == 'Microsoft Internet Explorer'){

var e=document.getElementsByTagName("select");

	for(var i=0;i<e.length;i++)
	{
	e[i].style.visibility = toggle;
	}

return false;
}

else{
return false;
}

}

function changeRating(rating,div){
document.getElementById(div).style.backgroundImage = 'url(/images/'+rating+'-star.gif)';
if(div == 'reviewRating'){
document.getElementById('rating').value = rating;
}
}

function acceptQuote(id, amount, company){

var divID = 'popupDiv';
var box;

var content = '<h1>Accept quote</h1><div class="popup_close"><a onclick="return popupDisplayNone(\''+divID+'\');"><img src="/images/cross.png" alt="Close" title="Close" /></a></div>\
<p style="font-size: 0.6875em; padding: 0px 15px 10px 15px;">Please confirm that you would like to accept the quote for: '+amount+' from: '+company+'</p>\
<p style="font-size: 0.6875em; padding: 0px 15px 10px 15px;">Note: This will notify the tradesman of your acceptance and provide them with your contact details to contact you. Always remember to ask your tradesman for identification, references and copies of liabilty insurance.</p>\
<a href="/accept_quote.php?qid='+id+'" style="float: left; margin: 10px 0px 15px 215px; display: inline;"><img src="/images/accept_quote.gif" alt="Accept quote" /></a> <a onclick="return popupDisplayNone(\''+divID+'\');" style="float: left; cursor: pointer; margin: 10px 0px 15px 10px; display: inline;"><img src="/images/cancel_button.gif" alt="Cancel" /></a>';

var divWidth = 400;
var divHeight = 200;

if(document.getElementById(divID)){
box = document.getElementById(divID);
}

else{
box = document.createElement("div");
box.setAttribute("id",divID);
box.setAttribute("class","popup");
box.className = 'popup';
document.body.appendChild(box);
}

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);
	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.width = divWidth+'px';
	box.innerHTML = content;
	box.style.display = 'block';
	box.style.position = 'absolute';
	box.style.top = scrollingTop+'px';
	box.style.left = scrollingLeft+'px';
	box.style.zIndex = '3';

	return hideShowSelects('hidden');
}

function verifyMobile(){

var divID = 'popupDiv';
var box;
var string = '/functions/ajax_verify_mobile.php';
var divWidth = 400;
var divHeight = 200;

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {

if(document.getElementById(divID)){
box = document.getElementById(divID);
}

else{
box = document.createElement("div");
box.setAttribute("id",divID);
box.setAttribute("class","popup");
box.className = 'popup';
document.body.appendChild(box);
}

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);
	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.width = divWidth+'px';
	box.innerHTML = xmlHttp.responseText;
	box.style.display = 'block';
	box.style.position = 'absolute';
	box.style.top = scrollingTop+'px';
	box.style.left = scrollingLeft+'px';
	box.style.zIndex = '3';

      }
    }
  xmlHttp.open("GET",string,true);
  xmlHttp.send(null);

}

function verifyMobile2(){

var code = document.getElementById('txt_code').value;
var divID = 'popupDiv';
var string = '/functions/ajax_verify_mobile_2.php?code='+code;

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {

	if(xmlHttp.responseText == '1'){

	location.href = '/notification-settings?mobile=verified';

	}

	else{

	document.getElementById('verify_error').innerHTML = 'That code is incorrect.';
	document.getElementById('verify_error').style.display = 'block';

	}

      }
    }
  xmlHttp.open("GET",string,true);
  xmlHttp.send(null);

}

function send_message(tradesman_id, job_id){

var divID = 'popupDiv';
var box;

var content = '<h1>Send message</h1><div class="popup_close"><a onclick="return popupDisplayNone(\''+divID+'\');"><img src="/images/cross.png" alt="Close" title="Close" /></a></div>\
<form method="post" action="/post_message.php" id="message_form">\
<input type="hidden" name="tid" value="'+tradesman_id+'" />\
<input type="hidden" name="jid" value="'+job_id+'" />\
<div class="formRowWrapper">\
<div class="formRowLeft"><label for="message">Your message</label></div>\
<div class="formRowRight"><textarea id="message" name="message" rows="5" cols="32"></textarea></div>\
</div>\
<div class="formRowWrapper" style="text-align: right;">\
<a onclick="valMessage();" style="margin-right: 25px; cursor: pointer;"><img src="/images/submit_button.gif" alt="Submit message" /></a>\
</div>\
</form>';

var divWidth = 400;
var divHeight = 200;

if(document.getElementById(divID)){
box = document.getElementById(divID);
}

else{
box = document.createElement("div");
box.setAttribute("id",divID);
box.setAttribute("class","popup");
box.className = 'popup';
document.body.appendChild(box);
}

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);
	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.width = divWidth+'px';
	box.innerHTML = content;
	box.style.display = 'block';
	box.style.position = 'absolute';
	box.style.top = scrollingTop+'px';
	box.style.left = scrollingLeft+'px';
	box.style.zIndex = '3';

	return hideShowSelects('hidden');

}

function valMessage(){

var form_name = 'message_form';

var message_val = document.getElementById('message').value;

if(message_val.length == 0 || message_val == 'Please enter your message'){

document.getElementById('message').value = 'Please enter your message';

}

else{

document.forms[form_name].submit();

}

}