var constPath = "http://solo.yogyes.com/";
var divHeight = 0;
var acceleration = 1;

var xmlhttp;
var isSupportAjax = true;
if (window.XMLHttpRequest) {
  xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} else {
  isSupportAjax = false;
}

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();
}

