var InitType = '';
var news1left = 0;
var news2left = 670;
function geser() {

  news1left -= 2;
  news2left -= 2;
  if (news1left <= -670) {
    news1left = 670;
  }
  if (news2left <= -670) {
    news2left = 670;
  }
  document.getElementById('news1').style.left = news1left + 'px';
  document.getElementById('news2').style.left = news2left + 'px';
  setTimeout(function() { geser(); }, 100);
}

function CekFocus(object) { //use in each pages
  if ((object.id == "searchtype") && (object.value == '<Masukkan Pencarian Anda>'))
    object.value = '';
  else if ((object.id == "quicksearch") && (object.value == '<Kode Property/Kota/Alamat>'))
    object.value = '';
  else if ((object.id == "txtMin") && (object.value == '<Min Price>'))
    object.value = '';
  else if ((object.id == "txtMax") && (object.value == '<Max Price>'))
    object.value = '';
  object.style.color = "#000000";
}

function CekBlur(object) { //use in each pages
  if ((object.id == "searchtype") && (object.value.length == 0)) {
    object.value = '<Masukkan Pencarian Anda>';
    object.style.display = 'none';
    document.getElementById('type').value = 'semua';
    document.getElementById('type').style.display = 'inline';
  }
  else if ((object.id == "quicksearch") && (object.value.length == 0))
    object.value = '<Kode Property/Kota/Alamat>';
  else if ((object.id == "txtMin") && (object.value.length == 0))
    object.value = '<Min Price>';
  else if ((object.id == "txtMax") && (object.value.length == 0))
    object.value = '<Max Price>';
  object.style.color = "#666666";
}

function BursaKedip() { //use in each pages
  if (document.getElementById('bursacounter').style.visibility == 'visible' || document.getElementById('bursacounter').style.visibility == '')
    document.getElementById('bursacounter').style.visibility = 'hidden';
  else
    document.getElementById('bursacounter').style.visibility = 'visible';
  setTimeout(function() { BursaKedip(); }, 500);
}

function ShowBig(image) { //use in propertydetail.aspx, search.aspx
  var gbr;
  gbr = '<div style="float:right;clear:none;margin:0;"><img src="images/popupclose.jpg" style="cursor:pointer;" onclick="TINYPOPUP.box.hide()" /></div>';
  gbr += '<img src="' + image + '" style="max-width:600px;max-height:500px;margin:32px 5px 32px 32px;" /> ';
  TINYPOPUP.box.show(gbr, 0, 0, 0, 1);
}

function load_hotlistimage(type, wilayah, object, root) { //use in each pages except home.aspx  
  XmlHttpHotList = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if (InitType != type) {
    document.getElementById('hotlistimagecontainer').innerHTML = '<img src="images/ajax-loader.gif" style="width:128px;height:15px;" />';
    if (!window.ActiveXObject)
      document.getElementById('hotlistimagecontainer').setAttribute('style', 'text-align:center;position:relative;top:75px;');
    InitType = type;
  }
  if (XmlHttpHotList.readyState == 0 || XmlHttpHotList.readyState == 4) {
    XmlHttpHotList.onreadystatechange = function() {
      if (XmlHttpHotList.status == 200) {
        document.getElementById('hotlistimagecontainer').setAttribute('style', '');
        document.getElementById('hotlistimagecontainer').innerHTML = XmlHttpHotList.responseText;
      }
    };
    XmlHttpHotList.open('GET', root + 'News.aspx?nama=hotlistimage&area='+wilayah+'&type=' + type + '&root=' + root, true);
    XmlHttpHotList.send(null);
  }
  ChangeColor(object);
}

function ChangeColor(type) { //use in each pages
  var i = 0;
  var name = '';
  var object;
  var style;

  for (i = 1; i <= 7; i++) {
    name = 'hotlist' + i;
    if (name == type) {
      object = document.getElementById(type);
      style = object.getAttribute('class');
      if (style.substring(0, 7) == 'HotList') {
        object.setAttribute('class', 'HotListOnFocus');
      }
      else if (style.substring(0, 14) == 'HomePerkebunan') {
        object.setAttribute('class', 'HomePerkebunanOnFocus');
      }
      else if (style.substring(0, 10) == 'Perkebunan') {
        object.setAttribute('class', 'PerkebunanOnFocus');
      }
    }
    else if (name != type) {
      object = document.getElementById(name);
      style = object.getAttribute('class');
      if (style.substring(0, 7) == 'HotList') {
        object.setAttribute('class', 'HotListOnBlur');
      }
      else if (style.substring(0, 14) == 'HomePerkebunan') {
        object.setAttribute('class', 'HomePerkebunanOnBlur');
      }
      else if (style.substring(0, 10) == 'Perkebunan') {
        object.setAttribute('class', 'PerkebunanOnBlur');
      }
    }
  }
}

function ChangePropType() {
  var object = document.getElementById('type');
  if (object.value == 'Others') {
    object.style.display = 'none';
    document.getElementById('searchtype').style.display = 'inline';
  }
}

function ValidSearch(form) {
  if (document.getElementById('area').value != 'semua')
    form.submit();
  else if (document.getElementById('area').value == 'semua')
    alert('Anda belum memilih Daerah/Wilayah');
}

function login(name, pass, alamat, ingat) { //use in home.aspx
  var AJAXQuery = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if (navigator.appName != 'Microsoft Internet Explorer')
    document.getElementById('login').innerHTML = '<img src="/images/ajax-loader.gif" style="width:128px;height:15px;" />';
  if (document.getElementById(name).value != "" && document.getElementById(pass).value != "") {
    if (AJAXQuery.readyState == 0 || AJAXQuery.readyState == 4) {
      AJAXQuery.onreadystatechange = function() {
        if (AJAXQuery.status == 200 && AJAXQuery.readyState == 4) {
          if (AJAXQuery.responseText == '0') {
            if (navigator.appName != 'Microsoft Internet Explorer')
              document.getElementById('login').innerHTML = 'User Name atau Password Salah';
          }
          else if (AJAXQuery.responseText == '1') {
            if (navigator.appName != 'Microsoft Internet Explorer')
              document.getElementById('login').innerHTML = '';
            document.location = alamat;
          }
          else if (AJAXQuery.responseText == '2') {
            TINY.box.show('LoginAlert.aspx', 1, 0, 0, 1);
          }
        }
      };
      AJAXQuery.open('GET', 'Query.aspx?login=yes&custname=' + document.getElementById(name).value + '&pass=' + document.getElementById(pass).value + '&ingat=' + document.getElementById(ingat).checked, true);
      AJAXQuery.send(null);
    }
  }
  else
    alert("Data yang diisi belum lengkap.");
}
