var count = 0;
var FDCount = 0;
var ProcID;
var MoveFDID;
var NewsID;
var LastType='';
var LastObject = '';
var LastArea = '';
var LastWilayah = '';
var FDContent1Left = 0;
var FDContent2Left = 0;
var FDContentTemp = '';

function ShowDetail(PropCode) { //use in home.aspx
    window.location = 'propertydetail.aspx?id=' + PropCode;
}

function ShowHotNews() { //use in home.aspx
    window.location = 'HotNews.aspx';
}

function CallData(wilayah) { //use in home.aspx
    load_hotnews('HotNews',wilayah, count);
    load_launching('Launching',wilayah, count);
    load_promo('Promo',wilayah, count);
    count++;
    LastWilayah = wilayah;
    NewsID = setTimeout(function() { CallData(wilayah); }, 3000);
}

function stop_CallData() {
  if (NewsID) {
    clearTimeout(NewsID);
    NewsID = '';
  }
}

function load_CallData() {
  if (NewsID == '')
    CallData(LastWilayah);
}

function load_simpan(query) { //use in home.aspx
    var AJAXQuery = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (AJAXQuery.readyState == 0 || AJAXQuery.readyState == 4) {
        AJAXQuery.onreadystatechange = function() { if (AJAXQuery.status == 200 && AJAXQuery.readyState == 4) { } };
        AJAXQuery.open('GET', 'Query.aspx?query=' + query, true);
        AJAXQuery.send(null);
    }
}

function load_hotnews(variabel,wilayah,count) { //use in home.aspx
  XmlHttpHotNews = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if (XmlHttpHotNews.readyState == 0 || XmlHttpHotNews.readyState == 4) {
    XmlHttpHotNews.onreadystatechange = function() {
      if (XmlHttpHotNews.status == 200 && XmlHttpHotNews.readyState == 4) {
        document.getElementById("HotNews").innerHTML = XmlHttpHotNews.responseText;
      }
    };
    XmlHttpHotNews.open('GET', 'News.aspx?nama=' + variabel + '&area=' + wilayah + '&count=' + count, true);
    XmlHttpHotNews.send(null);
  }
}

function load_launching(variabel,wilayah,count) { //use in home.aspx
  XmlHttpLaunching = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if (XmlHttpLaunching.readyState == 0 || XmlHttpLaunching.readyState == 4) {
    XmlHttpLaunching.onreadystatechange = function() {
      if (XmlHttpLaunching.status == 200 && XmlHttpLaunching.readyState == 4)
        document.getElementById("Launching").innerHTML = XmlHttpLaunching.responseText;
    };
    //alert('News.aspx?nama=' + variabel + '&area=' + wilayah + '&count=' + count);
    XmlHttpLaunching.open('GET', 'News.aspx?nama=' + variabel + '&area=' + wilayah + '&count=' + count, true);
    XmlHttpLaunching.send(null);
  }
}

function load_promo(variabel,wilayah,count) { //use in home.aspx
  XmlHttpPromo = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if (XmlHttpPromo.readyState == 0 || XmlHttpPromo.readyState == 4) {
    XmlHttpPromo.onreadystatechange = function() {
      if (XmlHttpPromo.status == 200 && XmlHttpPromo.readyState == 4)
        document.getElementById("Promo").innerHTML = XmlHttpPromo.responseText;
    };
    XmlHttpPromo.open('GET', 'News.aspx?nama=' + variabel + '&area=' + wilayah + '&count=' + count, true);
    XmlHttpPromo.send(null);
  }
}

function load_hotlist(type,wilayah,count,object) { //use in home.aspx
  XmlHttpHotList = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if (InitType != type) {
    document.getElementById('hotlistcontainer').innerHTML = '<img src="images/ajax-loader.gif" style="width:128px;height:15px;" />';
    if (!window.ActiveXObject)
      document.getElementById('hotlistcontainer').setAttribute('style', 'text-align:center;position:relative;top:90px;left:40px;');
    clearTimeout(ProcID);
    InitType = type;
  }
  if (XmlHttpHotList.readyState == 0 || XmlHttpHotList.readyState == 4) {
    XmlHttpHotList.onreadystatechange = function() {
      if (XmlHttpHotList.status == 200 && XmlHttpHotList.readyState == 4) {
        document.getElementById('hotlistcontainer').setAttribute('style', '');
        document.getElementById('hotlistcontainer').innerHTML = XmlHttpHotList.responseText;
      }
    };//alert('News.aspx?nama=hotlist&type=' + type + '&area=' + wilayah + '&count=' + count);
    XmlHttpHotList.open('GET', 'News.aspx?nama=hotlist&type=' + type + '&area=' + wilayah + '&count=' + count, true);
    XmlHttpHotList.send(null);
    LastObject = object;
    LastArea = wilayah;
    ProcID = setTimeout(function() { load_hotlist(type,wilayah,count + 1,object); }, 2000);
  }
  ChangeColor(object);
}

function stop_hotlist() {
  if (ProcID) {
    clearTimeout(ProcID);
    ProcID = '';
    LastType = InitType;
  }
}

function load_hotlistagain() {
  if (ProcID == '')
    load_hotlist(LastType, LastArea, count + 1, LastObject);
}

function LoadFeaturedDev(action,wilayah) {
  if (action == 'left') FDCount--; else if (action == 'right') FDCount++;
  CheckMoreFD = 0;
  XmlHttpFD = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if (XmlHttpFD.readyState == 0 || XmlHttpFD.readyState == 4) {
    XmlHttpFD.onreadystatechange = function() {
      if (XmlHttpFD.status == 200 && XmlHttpFD.readyState == 4) {
        FDContentTemp = XmlHttpFD.responseText;
        if (FDContentTemp != '') {
          if (action == 'still') {
            document.getElementById('fdcontent1').innerHTML = FDContentTemp;
            document.getElementById('fdcontent1').style.display = 'block';
            //LoadMoreFeaturedDev(action, FDCount);
          }
          else if (action != 'still') {
            document.getElementById('fdcontent2').innerHTML = FDContentTemp;
            document.getElementById('fdcontent2').style.display = 'block';
            FDContent1Left = 26;
            if (action == 'left') FDContent2Left = -300; else if (action == 'right') FDContent2Left = 350;
            //LoadMoreFeaturedDev(action, FDCount);
            MoveFDContent(action);
          }
        }
      }
    };
    XmlHttpFD.open('GET', 'featureddev.aspx?id=' + FDCount + '&area=' + wilayah, true);
    XmlHttpFD.send(null);
  }
}

function LoadMoreFeaturedDev(action, FDCount) {
  if (action == 'left' || action == 'still') FDCount--; else if (action == 'right') FDCount++;
  XmlHttpMoreFD = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if (XmlHttpMoreFD.readyState == 0 || XmlHttpMoreFD.readyState == 4) {
    XmlHttpMoreFD.onreadystatechange = function() {
      if (XmlHttpMoreFD.status == 200 && XmlHttpMoreFD.readyState == 4) {
        if (XmlHttpMoreFD.responseText == '') {
          if (action == 'left' || action == 'still') {
            document.getElementById('imgleftarrow').style.visibility = 'hidden';
            document.getElementById('imgrightarrow').style.visibility = 'visible';
          }
          else if (action == 'right') {
            document.getElementById('imgleftarrow').style.visibility = 'visible';
            document.getElementById('imgrightarrow').style.visibility = 'hidden';
          }
        }
        else if (XmlHttpMoreFD.responseText != '') {
          document.getElementById('imgleftarrow').style.visibility = 'visible';
          document.getElementById('imgrightarrow').style.visibility = 'visible';
        }
      }
    };
    XmlHttpMoreFD.open('GET', 'featureddev.aspx?id=' + FDCount, true);
    XmlHttpMoreFD.send(null);
  }
}

function MoveFDContent(action) {
  if (action == 'left') {
    if (FDContent2Left >= -300 && FDContent2Left < 26) {
      FDContent1Left += 5;
      FDContent2Left += 5;
      document.getElementById('fdcontent1').style.left = FDContent1Left + 'px';
      document.getElementById('fdcontent2').style.left = FDContent2Left + 'px';
      MoveFDID = setTimeout(function() { MoveFDContent(action); }, 10);
    }
    else if (FDContent2Left >= 26) {
      clearTimeout(MoveFDID);
      document.getElementById('fdcontent1').innerHTML = FDContentTemp;
      document.getElementById('fdcontent2').style.display = 'none';
      document.getElementById('fdcontent1').style.left = '26px';
      document.getElementById('fdcontent2').innerHTML = '';
    }
  }
  else if (action == 'right') {
    if (FDContent1Left >= -300 && FDContent2Left > 26) {
      FDContent1Left -= 5;
      FDContent2Left -= 5;
      document.getElementById('fdcontent1').style.left = FDContent1Left + 'px';
      document.getElementById('fdcontent2').style.left = FDContent2Left + 'px';
      MoveFDID = setTimeout(function() { MoveFDContent(action); }, 10);
    }
    else if (FDContent2Left <= 26) {
      clearTimeout(MoveFDID);
      document.getElementById('fdcontent1').innerHTML = FDContentTemp;
      document.getElementById('fdcontent2').style.display = 'none';
      document.getElementById('fdcontent1').style.left = '26px';
      document.getElementById('fdcontent2').innerHTML = '';
    }
  }
}
