<!--Copyright Info-->
<!--The contents of this file are copyrighted by Zyz International Technology -->
<!--All Rights Reserved.  You are not permitted to copy or use this script in any circumstances -->

function onSignInLoad(form, bFocus)
{
  var email = form.email.value;
  if (email.length==0)
     email = getCookie(form.domain_email.value);
    
//alert("username =" + username+","+form.domainname.value);
  if (email)
  {
    form.email.value = email;
    form.remember.checked = true;
    setFocus(form.password);
  }
  else
  {
    form.email.value = '';
  }

  if (bFocus)
  {
     if (email==null || email.length==0)
        setFocus(form.email);
     else
        setFocus(form.password);
  }
}

function validateSignIn(form)
{
    //. check the email
    if (checkFieldEmpty(form.email))
    {
       alert("You have to enter E-Mail.");
       setFocus(form.email);
       return false;
    }
    if (!validateEmail(form.email))
       return false;

    //. check the password is empty or not
    if (checkFieldEmpty(form.password))
    {
        alert("You have to enter Password.");
        setFocus(form.password);
        return false;
    }

    setCookie(form.domain_email.value, form.remember.checked ? form.email.value : "");

//    showProcessBar();

    return true;
}

function forgotPassword(form, sAction)
{
    setCookie(form.domain_email.value, form.remember.checked ? form.email.value : "");

    form.action1.value = sAction;//"Forgot Password_SignIn";
    form.submit();
}

function onMemberFormLoad(form)
{
    setFocus(form.firstname);
//alert("Your Name here");
}

function validateAccount(form)
{
  //. check the your name
  if (checkFieldEmpty(form.firstname))
  {
     alert("You have to enter First Name.");
     setFocus(form.firstname);
     return false;
  }

  //. check the your name
  if (checkFieldEmpty(form.lastname))
  {
     alert("You have to enter Last Name.");
     setFocus(form.lastname);
     return false;
  }

  return true;
}

var g_sSectionId = null;
var g_sSectionRow = null;
function showAddTrackForm(sSectionId, bLogin)
{
try {
/*
  if (!bLogin)
  {
     alert("Please login first.");
     return false;
  }
*/

  hideTrackForm();

  g_sSectionRow = "sitetrackrow_0";
  showHide("close", g_sSectionRow);

//   alert("It is called by click=" + sSectionId);
  var formContent = document.getElementById("trackform_section").innerHTML;   
  formContent = formContent.replace("Track_Title", "Add New Site Track");
  formContent = formContent.replace("_formid", "_add");
  document.getElementById(sSectionId).innerHTML = formContent;//.replace("submit_button", "Add Now");

  var form = document.trackform_add;
  form.itemname.value = "";
  form.searchterm.value = "";
  form.maxcount.value = 5;
  form.editid.value = "0";
  form.tracktotal.value = getValueByElementId("track_total");

  form.removeitems.disabled = true;
  form.searchterm.focus();

  g_sSectionId = sSectionId;
}
catch (ex)
{
   showException(ex, "showAddTrackForm(sSectionId)");
}
}

function showEditTrackForm(sSectionId)
{
try {
  hideTrackForm();

  var nIndex = sSectionId.indexOf("_");
  var sEditId = sSectionId.substring(nIndex+1);

  g_sSectionRow = "sitetrackrow_" + sEditId;
  showHide("close", g_sSectionRow);
//alert("g_sSectionRow=" + g_sSectionRow);

  var formContent = document.getElementById("trackform_section").innerHTML;
  formContent = formContent.replace("Track_Title", "Edit Site Track");
  formContent = formContent.replace("_formid", "_edit");
  document.getElementById(sSectionId).innerHTML = formContent;//.replace("submit_button", "Update Now");

  var form = eval(document.trackform_edit);
  form.itemname.value = getValueByElementId("itemname_" + sEditId);
  form.searchterm.value = getValueByElementId("searchterm_" + sEditId);
  form.maxcount.value = 5;//getValueByElementId("maxcount_" + sEditId);
  form.description.value = getValueByElementId("description_" + sEditId);
  form.createdate.value = getValueByElementId("createdate_" + sEditId);
  form.editid.value = sEditId;

  form.searchterm.focus();
  form.searchterm.select();

  g_sSectionId = sSectionId;
}
catch (ex)
{
   showException(ex, "showEditTrackForm(sSectionId, sParams)");
}

}

function validateSubmitTrack(form)
{
try {
    if (checkFieldEmpty(form.searchterm))
    {
        alert("You have to enter Seach Term.");
        setFocus(form.searchterm);
        return false;
    }

    if (checkFieldEmpty(form.maxcount))
    {
        alert("You have to enter Search Limits.");
        setFocus(form.maxcount);
        return false;
    }
/*
    if (form.maxcount.value<0 || form.maxcount.value>10)
    {
        alert("The number you entered must be larger than 0 and less than 11.");
        setFocus(form.maxcount);
        return false;
    }
*/
    form.submit.disabled = true;
    doProcess('MaskProcessing', 'MainPageTable');

    var sEditId = form.editid.value;
//    if (sEditId!="0")
    {
        var sRequest = getFormQuery(form) + "&time="+new Date().getTime();
        var sAjaxUrl = "/ajax/trackaction.jsp";
        var sResponse = postUrlContent(sAjaxUrl, sRequest);
//alert("sResponse=" + sResponse);
        if (sEditId!="0")
           document.getElementById("idsitetrack_"+sEditId).innerHTML = sResponse;
        else
        {// alert("sResponse=" + sResponse);
            var newTrack = document.createElement("div") //create dhtml window div
            newTrack.id = "tracknew_" + form.tracktotal.value;
            newTrack.innerHTML = sResponse;

//            document.getElementById("sitetrack_new").appendChild(domdiv);
            var insertHere = document.getElementById('sitetrackmarker');
            insertHere.parentNode.insertBefore(newTrack,insertHere);

            document.getElementById("track_total").innerHTML = '' + (parseInt(form.tracktotal.value)+1);
        }

        hideTrackForm();
   }

    closeProcess('MaskProcessing');

return false;
/*
    if (sEditId!="0")
       return false;
    else
       return true;
*/
}
catch (ex)
{
   showException(ex, "validateSubmitTrack(form)");
}
    return false;
}

function refrechTrack(sSectionId)
{
try {

    doProcess('MaskProcessing', 'MainPageTable');

    var nIndex = sSectionId.indexOf("_");
    var sEditId = sSectionId.substring(nIndex+1);

    var sUrl = "/ajax/trackaction.jsp?action=RefreshSiteTrack&itemname=" + getValueByElementId("itemname_" + sEditId) + "&editid=" + sEditId + "&"+new Date().getTime();
    var sResponse = getUrlContent(sUrl);
    document.getElementById(sSectionId).innerHTML = sResponse;

//    showHide("close", "waitprocess_" + sEditId);
    closeProcess('MaskProcessing');
}
catch (ex)
{
   showException(ex, "refrechSearchItem(sSectionId, sTrackId)");
}
}

function deleteTrack(sSectionId)
{
try {
    if (!confirm('Are you sure you want to delete it?'))
       return;

    doProcess('MaskProcessing', 'MainPageTable');

    var nIndex = sSectionId.indexOf("_");
    var sEditId = sSectionId.substring(nIndex+1);

    var sUrl = "/ajax/trackaction.jsp?action=DeleteSiteTrack&itemname=" + getValueByElementId("itemname_" + sEditId) + "&editid=" + sEditId + "&"+new Date().getTime();
    var sResponse = getUrlContent(sUrl);
    document.getElementById(sSectionId).innerHTML = "";//sResponse;

    closeProcess('MaskProcessing');
}
catch (ex)
{
   showException(ex, "deleteTrack(sSectionId)");
}
}

function saveTrack(sSectionId, sSiteId, bLogin)
{
  if (!bLogin)
  {
     alert("Please login first.");
      
     return false;
  }

  return false;
}

function hideTrackForm()
{
  if (g_sSectionId!=null)
     document.getElementById(g_sSectionId).innerHTML = "";  

  if (g_sSectionRow!=null)
  {
     showHide("open", g_sSectionRow);
     g_sSectionRow = null;    
  }
}

var g_sSectionCommentId = null;
var g_sSectionCommentRow = null;
function showAddCommentForm(sSectionId, bLogin)
{
try {
    
/*
  if (!bLogin)
  {
     alert("Please login first.");
     return false;
  }
*/

  hideCommentForm();

  g_sSectionCommentRow = "sitecommentrow_0";
  showHide("close", g_sSectionCommentRow);

//   alert("It is called by click=" + sSectionId);
  var formContent = document.getElementById("commentform_section").innerHTML;
  formContent = formContent.replace("Comment_Title", "Add New Comment");
  formContent = formContent.replace("_formid", "_add");
  document.getElementById(sSectionId).innerHTML = formContent.replace("submit_button", "Add Now");

  var form = document.commentform_add;
  form.itemname.value = "";
  form.comment.focus();

  g_sSectionCommentId = sSectionId;
}
catch (ex)
{
   showException(ex, "showAddCommentForm(sSectionId)");
}
}

function validateSubmitComment(form)
{
try {

    if (checkFieldEmpty(form.comment))
    {
        alert("You have to enter YOUR Comment.");
        setFocus(form.comment);
        return false;
    }

    form.submit.disabled = true;
    showHide("open", "id_waitprocess_0");
        
    var sRequest = getFormQuery(form) + "&time="+new Date().getTime();
    var sAjaxUrl = "/ajax/commentaction.jsp";
    var sResponse = postUrlContent(sAjaxUrl, sRequest);
    document.getElementById('id_commentlist').innerHTML = sResponse;

    hideCommentForm();

    showHide("close", "id_waitprocess_0");

    return false;
}
catch (ex)
{
   showException(ex, "validateSubmitComment(form)");
   return false;
}

}

function deleteComment(sUrl)
{
try {
    if (!confirm('Are you sure you want to delete it?'))
       return;

//    doProcess('MaskProcessing', 'MainPageTable');

    var sRequest = sUrl + "&time="+new Date().getTime();
    var sAjaxUrl = "/ajax/commentaction.jsp?" + sRequest;
    var sResponse = getUrlContent(sAjaxUrl);

    document.getElementById('id_commentlist').innerHTML = sResponse;
//    hideCommentForm();

//    closeProcess('MaskProcessing');

    return false;
}
catch (ex)
{
   showException(ex, "deleteComment(sUrl)");
   return false;
}

}

function saveComment(sSectionId, sSiteId, bLogin)
{
  if (!bLogin)
  {
     alert("Please login first.");

     return false;
  }

  return false;
}

function hideCommentForm()
{
  if (g_sSectionCommentId!=null)
     document.getElementById(g_sSectionCommentId).innerHTML = "";

  if (g_sSectionCommentRow!=null)
  {
     showHide("open", g_sSectionCommentRow);
     g_sSectionCommentRow = null;
  }
}

function tryDownload(form, sAjaxUrl)
{
   try {

    var sRequest = getFormQuery(form);//  + "&time="+new Date().getTime();
//  alert("sRequest=" + sRequest);
    var sResponse = postUrlContent(sAjaxUrl, sRequest);
    var arReturn = sResponse.split("<!--!>");
 //alert("sResponse=" + sResponse+"!");
    document.getElementById('id_message').innerHTML = arReturn[1];

    if ("1"==arReturn[0])
    {
//       form.submit.disabled = "true";
       document.getElementById("download_submit").disabled = true;
       window.location.href = arReturn[2];
//       showDownloadFile('DownloadWin', 'Download is processing and Close it when the process ends', arReturn[2]);
    }

    return false;
  }
  catch (ex)
  {
     showException(ex, "tryDownload()");
     return false;
  }
}

var gl_map = null;
var gl_geocoder = null;
function initializeGMap(sCanvasId, sLatLog, sAddress, bControls, bCityLevel)
{
    gl_map = new GMap2(document.getElementById(sCanvasId));
//    gl_map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    if (bControls)
    {
        gl_map.addControl(new GLargeMapControl());
        gl_map.addControl(new GMapTypeControl());
    }
//gl_map.disableDragging();
        
    gl_map.doubleClickZoomEnabled();
    gl_map.enableScrollWheelZoom();

    var arLatLog = sLatLog.split(",");
//alert(sLatLog+"," + arLatLog[0] + ", " + parseFloat(arLatLog[1]));
    if (arLatLog[0]!='0')
    {
        var point = new GLatLng(parseFloat(arLatLog[0]), parseFloat(arLatLog[1]));
        if (bCityLevel)
           gl_map.setCenter(point, 6);
        else
           gl_map.setCenter(point, 13);
        var marker = new GMarker(point);
        gl_map.addOverlay(marker);
//        gl_map.checkResize();
    }
    else
      showAddressOnGMap(sAddress);
}

function showAddressOnGMap(address)
{
  gl_geocoder = new GClientGeocoder();

  if (gl_geocoder) {
    gl_geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
//		  alert(address + " not found");
        } else {
          gl_map.setCenter(point, 14);
          var marker = new GMarker(point);
          gl_map.addOverlay(marker);
//          marker.openInfoWindowHtml(address);
        }
      }
    );
  }
}
