var constPath = "http://www.yogyes.com/";
var divHeight = 0;
var acceleration = 1;
var centerLatLng;
var zoomLevel = 14;

var xmlhttp;
var isSupportAjax = true;
if (window.XMLHttpRequest) {
  xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} else {
  isSupportAjax = false;
}

function initialize() {
  var myLatlng = new Array();
  var marker = new Array();
  var infowindow = new Array();

  if (centerLatLng==null) { centerLatLng = new google.maps.LatLng(places[0][1],places[0][2]); }
  var myStyle = [
    {
       featureType: "poi",
       elementType: "labels",
       stylers: [
         { visibility: "off" }
       ]
    }
  ];
  var myOptions = {
    center: centerLatLng,
    zoom: zoomLevel,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  for (i=0;i<places.length;i++)
  {
    myLatlng[i] = new google.maps.LatLng(places[i][1],places[i][2]);
    contentString = 
      '<div class="wndInfo">'+
      '  <img src="' + constPath + 'en/places/' + places[i][0].toString() + '/60x60.jpg" width="60" height="60" style="float: left; margin-right: 5px;" /><span class="title">' + places[i][4] + '</span><br/>' +
      '  <p class="address">' + places[i][5] + '</p>' + 
      '  <p class="meta-description">' + places[i][6] + '</p>' +
      '  » <a href="' + places[i][7] + '" target="_blank">read more</a>'+
      '</div>';
   infowindow[i] = new google.maps.InfoWindow({
     content: contentString.replace(/&lt;/g,'<').replace(/&gt;/g,'>')
   });
   if (i==0) {
     marker[i] = new google.maps.Marker({
       position: myLatlng[i],
       map: map,
       title: places[i][4]
     });
   }else{
     marker[i] = new google.maps.Marker({
       icon: constPath + 'theme2012/map/' + places[i][3],
       shadow: constPath + 'theme2012/map/shadow.png',
       position: myLatlng[i],
       map: map,
       title: places[i][4]
     });
   }
   if (i!=0) {eval("google.maps.event.addListener(marker["+i+"], 'click', function() {  for (i=0;i<places.length;i++) { infowindow[i].close() }; infowindow["+i+"].open(map,marker["+i+"]) })")};
 }
 marker[0].setZIndex(100000);
}

function random() { 
  random.seed = (random.seed*random.a + random.c) % random.m; 
  return random.seed / random.m; 
}
random.m=714025; random.a=4096; random.c=150889;
random.seed = (new Date()).getTime()%random.m;
function validate(objForm) {
  if (objForm.elements["requiredField"]==null || objForm.elements["requiredField"].value=="") {
    var arrRequired=new Array()
  }else{
    var arrRequired=objForm.elements["requiredField"].value.split(",")
  }
  if (objForm.elements["numericField"]==null || objForm.elements["numericField"].value=="") {
    var arrNumeric=new Array()
  }else{
    var arrNumeric=objForm.elements["numericField"].value.split(",")
  }
  if (objForm.elements["dateField"]==null || objForm.elements["dateField"].value=="") {
    var arrDate=new Array()
  }else{
    var arrDate=objForm.elements["dateField"].value.split(",")
  }
  if (objForm.elements["eMailField"]==null || objForm.elements["eMailField"].value=="") {
    var arrEmail=new Array()
  }else{
    var arrEmail=objForm.elements["eMailField"].value.split(",")
  }
  valid=true;
  if (valid) {
    for (i=0;i<arrRequired.length;i++) {
      if (objForm.elements[arrRequired[i]].value=="") {
        valid=false;
        objForm.elements[arrRequired[i]].focus();
        alert(arrMessage[0] + objForm.elements[arrRequired[i]].name + "\".");
        break;
      }
    }
  }
  if (valid) {
    for (i=0;i<arrEmail.length;i++) {
      if (objForm.elements[arrEmail[i]].value.indexOf("@")==-1 || objForm.elements[arrEmail[i]].value.indexOf(".")==-1) { 
        valid=false;
        objForm.elements[arrEmail[i]].select();
        alert(objForm.elements[arrEmail[i]].name + arrMessage[1]);
        break;
      }
    }
  }
  if (valid) {
    for (i=0;i<arrDate.length;i++) {      
      strReservationDate=objForm.elements[arrDate[i]].value
      arrReservationDate=strReservationDate.split("/");
      reservationDate=new Date(arrReservationDate[2], arrReservationDate[0]-1, arrReservationDate[1]);
      if (isNaN(reservationDate)) {
        valid=false;
      }else{
        if (reservationDate.getMonth()!=arrReservationDate[0]-1) {
          valid=false;
        }
      }
      if (objForm.elements[arrDate[i]].value=="") valid=true;
        if (!valid){
          objForm.elements[arrDate[i]].select();
          alert(objForm.elements[arrDate[i]].name + arrMessage[3]);
          break;
      }
    }
  }
  if (valid) {
    for (i=0;i<arrNumeric.length;i++) {
      if (isNaN(objForm.elements[arrNumeric[i]].value)) {
        valid=false;
        objForm.elements[arrNumeric[i]].select();
        alert(objForm.elements[arrNumeric[i]].name + arrMessage[2]);
        break;
      }
    }
  }
  return valid;
}


function send() {
  document.forms["frmContact"].elements["randomKey"].value = Math.round(random()*10000);
  if (validate(document.forms["frmContact"])) {
    if (isSupportAjax) {
      var params = "";
      for (i=0;i<document.forms["frmContact"].elements.length;i++) {
        params = params + document.forms["frmContact"].elements[i].name + "=" + document.forms["frmContact"].elements[i].value.replace(/ /gi,"+").replace(/\n/gi,"<br+/>") + "&";
      }
      document.getElementById("btnSend").innerHTML="";
      xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState==4) {
          document.getElementById("kawista-contact").innerHTML=xmlhttp.responseText;
        }
      }
      xmlhttp.open("POST",constPath + "kawista-send.asp",true);
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlhttp.setRequestHeader("Content-length", params.length);
      xmlhttp.setRequestHeader("Connection", "close");
      xmlhttp.send(params);
    }else{
      document.forms["frmContact"].action = constPath + "kawista-send.asp?isSupportAjax=false";
      document.forms["frmContact"].submit();
    }
  }
}




function showComplete(){
  if (kawistaComplete.offsetHeight==0) {
    acceleration = 1;
    slideDown();
  }else{
    acceleration = 1;
    slideUp();
  }
}
function slideDown(){
  if (divHeight+(5*acceleration) <= kawistaCompleteHeight) {
    acceleration++;
    divHeight = divHeight + (5 * acceleration);
    kawistaComplete.style.height = divHeight +'px';
    setTimeout("slideDown()",50);
  }else{
    divHeight = kawistaCompleteHeight;
    kawistaComplete.style.height = kawistaCompleteHeight+ 'px';
    document.getElementById('btnComplete').innerHTML = arrMessage[7];
  }
}
function slideUp(){
  if (divHeight-(5*acceleration) >= 0) {
    divHeight = divHeight - (5 * acceleration);
    kawistaComplete.style.height = divHeight +'px';
    acceleration++;
    setTimeout("slideUp()",50);
  }else{
    divHeight = 0;
    kawistaComplete.style.height = '0px';
    document.getElementById('btnComplete').innerHTML = arrMessage[6];
  }
}
function calendar(id,defaultDate) {
  wndCalendar=window.open("","wndCalendar","toolbar=no,width=370,height=220,resizable=no,scrollbars=no");
  wndCalendar.document.write("<html><head><title>YogYES.COM: Calendar</title></head><body bgColor=#C0C0C0><p align=center style=font-size:10pt;font-family:verdana;><b>Loading calendar, please wait</body><html>");
  wndCalendar.moveTo((screen.width/2)-(220/2),(screen.height/2)-(220/2));
  wndCalendar=window.open(constPath+"calendar.asp?id="+id+"&defaultDate="+defaultDate,"wndCalendar","toolbar=no,width=370,height=260,resizable=no,scrollbars=no");
  wndCalendar.focus();
}
function go(shortcut) {
  if (shortcut.value!="") window.location = shortcut.value;
}
