function getDeptNumber(dept,dealer_id) {
  if (dealer_id > 0) {
    $('#mainSwitch').hide();

    $.ajax({
      type: 'POST',
      url: '/site-custom/assets/ajax/get_number.php',
      data: 'department='+dept+'&dealer_id='+dealer_id,
      async: false,
      success: function(data) {
	if (data) {
	  $('.numberBlock').html(data);
        }
	else {
          $('.numberBlock').html('01213824000');
	}	
      }
    });
  }
  else {
    $('#mainSwitch').show();
    $('.numberBlock').html('');
  }
}
function updateRedir(module,instance,variable,value,clear,page) {
  session_controller(module,instance,variable,value,clear);
  setTimeout(function() {window.location = page;},500);
}
function inc(filename) {
  var head = document.getElementsByTagName('head').item(0);
  script = document.createElement('script');
  script.setAttribute('type','text/javascript');
  script.setAttribute('src', '/site-custom/assets/js/' + filename);
  script.setAttribute('language', 'javascript');
  head.appendChild(script);
}

inc("colliers.js");
inc("clear-box.js");
inc("colliers-validate.js");

/* DA scripts added by Hubert on 06.07.2009 */
function upperCase(x)
{
var y=document.getElementById(x).value;
document.getElementById(x).value=y.toUpperCase();
}
function getSessionValue(module,instance,variable) {
  
  $.ajax({
      type: "POST",
      url: "/cars/ajax/getsessionvalue.php",
      dataType: "html",
      data: "module="+module+"&instance="+instance+"&var="+variable,
      success: function(data) {
        document.getElementById('postcodeinput').value = data;
      }
    });


}
function getTempSessionValue(variable) {
  
  $.ajax({
      type: "POST",
      url: "/cars/ajax/gettempsessionvalue.php",
      data: "var="+variable,
      success: function(data) {
        document.getElementById('postcodeinput').value = data;
      }
    });


}
function saveTempVar(variable, value) {
    $.ajax({
      type: "POST",
      url: "/cars/ajax/savetempvar.php",
      data: "var="+variable+"&value="+value
    });
}
    function showMap()
    {
      obj=document.getElementById('map');
    obj.style.display=(obj.style.display=="none")? "block" : "none"; 
    }
function clearPostcodeBox() {
  document.getElementById('postcodeinput').value = 'Postcode (optional)';
}
function validateEmailUpdates(form) {
  var make = form.elements[1].options[form.elements[1].selectedIndex].innerHTML;
  var modelclass = form.elements[3].options[form.elements[3].selectedIndex].innerHTML;
  var email = form.elements[2].value;

  var valid = true;
  if (make == 'Make' || modelclass == 'Model' || email == 'Email Address' || email == '') {
    var msg = "Please fill out all fields.";
    valid = false;
  }
  if(!valid) alert(msg);
  else {
     form.make.value = make;
     form.modelclass.value = modelclass;
  }
  return valid;
}
function openThankYou() {
        window.open('about:blank','thanks','toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=0,width=500,height=100,left=312,top=134');
}

function switchbookmark(instance,id,mode) {
 
 if (mode == 'remove') { 
   document.getElementById("book_"+id).innerHTML = '<a href="#" OnClick="javascript:removefromforecourt(&#39;'+instance+'&#39;,&#39;'+id+'&#39;,&#39;'+'used'+'&#39;);javascript:switchbookmark(&#39;'+instance+'&#39;,&#39;'+id+'&#39;,&#39;add&#39;);" class="current" title="Remove from Bookmarks">Remove</a>';
   } else {
   document.getElementById("book_"+id).innerHTML = '<a href="#" OnClick="javascript:addtoforecourt(&#39;'+instance+'&#39;,&#39;'+id+'&#39;,&#39;'+'used'+'&#39;);javascript:switchbookmark(&#39;'+instance+'&#39;,&#39;'+id+'&#39;,&#39;remove&#39;);" title="Bookmark">Bookmark</a>';
   }

}


/*****************************  validation data functions */

function validate_sellyourcar(form) {

	var name = form.name.value;
  var address1 = form.address1.value;
  var address2 = form.address2.value;
  var towncity = form.towncity.value;
  var postcode = form.postcode.value;
	var phone = form.phone.value;
	var email_F = form.email_F.value;

  var registration = form.registration.value;
  var mileage = form.mileage.value;

  var valid = true;
  var msg = "";

  if (name == '' || name == 'Name') {
          msg = msg + "Please type your name in.\n";
          valid = false;
  }
  if (address1 == '' || address1 == 'Address1') {
          msg = msg + "Please fill in Address1 field.\n";
          valid = false;
  }
  if (address1 == '' || address2 == 'Address2') {
          msg = msg + "Please fill in Address2 field.\n";
          valid = false;
  }
  if (towncity == '' || towncity == 'Town/City') {
          msg = msg + "Please fill in Town/City field.\n";
          valid = false;
  }
  if (postcode == '' || postcode == 'Post code') {
          msg = msg + "Please fill in Post code field.\n";
          valid = false;
  }
  if (phone == '' || phone == 'Telephone') {
          msg = msg + "Please fill in Telephone field.\n";
          valid = false;
  }
  if (email_F == '' || email_F == 'Email Address') {
          msg = msg + "Please fill in Email Address field.\n";
          valid = false;
  }
  if (registration == '' || registration == 'Reg. Number') {
          msg = msg + "Please fill in Reg. Number field.\n";
          valid = false;
  }
  if (mileage == '' || mileage == 'Mileage') {
          msg = msg + "Please fill in Mileage field.\n";
          valid = false;
  }

  if(!valid) alert(msg);
  return valid;
}




