﻿// JScript File
function CleanCookiesAndGetBack()
{
    document.getElementById ("classicHome").value = 'go';
    var theform = document.getElementById ("frm_default");    
    var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ 
            window.location = 'http://www.hakia.com';
      }
    }
  );
}

function CloseMe (data)
{
    document.getElementById(data).style.display = 'none';
}

function showEditForm (fromName, qq, isTopStories)
{
   var editForm = document.getElementById ("edit_form_" + fromName);
   var resultForm = document.getElementById ("result_" + fromName);
   var q = document.getElementById ("query_" + fromName);
   var queryBox = document.getElementById("query_box_" + fromName);
   editForm.style.display = 'block';
   resultForm.style.display = 'none';   
   if (qq == null)
   {
       if (isTopStories == null) 
            queryBox.value = q.value;
       else 
       {
            for (var index = 0, roof = queryBox.options.length; index < roof; index++) {
               if (q.value == queryBox.options[index].value) {
                  queryBox.options[index].selected = true;
                  break;
               }
            }
       }
   } 
   else  
   {
        if (isTopStories == null)  
            queryBox.value = qq;
        q.value = qq;
   }
   if (isTopStories == null) 
   {
       queryBox.select();   
       queryBox.focus();
   }
}

function CancelUpdateContent (fromName)
{
   var editForm = document.getElementById ("edit_form_" + fromName);
   var resultForm = document.getElementById ("result_" + fromName);
    //647211d8-dfd2-427c-b096-e
   editForm.style.display = 'none';
   resultForm.style.display = 'block';
   
}

function DeleteForm (formName, fromName)
{
    if (confirm("Do you really want to delete this? There is NO undo for this operation."))
    {
        document.getElementById (formName).style.display = 'none';
        document.getElementById ("hiddenDel_" + fromName).value = 'YES';
        var theform = document.getElementById ("frm_" + fromName);
        var status = AjaxRequest.submit(theform);
        AutoSave('frm_default', 1);
        return status;  
    }
}
function UpdateContent (fromName, isTopStories)
{
   var editForm = document.getElementById ("edit_form_" + fromName);
   var loading = document.getElementById ("loading_" + fromName);
   var query = document.getElementById ("query_" + fromName);
   var queryBox = document.getElementById("query_box_" + fromName);
   var resultForm = document.getElementById ("result_" + fromName);
   var query_display = document.getElementById("query_display_" + fromName);
   var theform = document.getElementById ("frm_" + fromName);

   editForm.style.display = 'none';
   if (query_display != null) query_display.style.display = 'none';
   loading.style.display = 'block';

   var status = AjaxRequest.submit(
   theform
    , {
        'onSuccess': function(req) {

            loading.style.display = 'none';
            resultForm.style.display = 'block';
			if (query_display != null)  {
				query_display.style.display = 'block';
				query_display.innerHTML = '(' + queryBox.value + ')';
			}
            if (req.responseText != '') {
                resultForm.innerHTML = req.responseText;
                if (isTopStories != null && isTopStories == "true") {
                    query.value = queryBox.options[queryBox.selectedIndex].value;
                }
                else {
                    query.value = queryBox.value;                    
                }
                AutoSave('frm_default', 1);
            }
        }
    }
  );
  return status;  
}

function SaveContent (formData, save_type)
{
  var loading = document.getElementById ("loading_default");
  var warning_default = document.getElementById ("warning_default");
  var theform = document.getElementById (formData);
  
  loading.style.display = 'block';
  warning_default.style.display = 'none';
  $('Save_Type').value = save_type;
   var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){
        if (save_type == 2) 
            window.location = "http://club.hakia.com/my/save.aspx";
        if (req.responseText != '')
        { 
            loading.style.display = 'none';        
            warning_default.style.display = 'block';
            warning_default.innerHTML=req.responseText;            
        }
      }
    }
  );
  return status;  
}

function AutoSave (formData, save_type)
{
  var loading = document.getElementById ("AutoSaveMark");
  var theform = document.getElementById (formData);
  
  loading.style.display = 'block';
  $('Save_Type').value = save_type;
   var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){
        if (req.responseText != '')
        { 
            loading.style.display = 'none';
        }
      }
    }
  );
  return status;  
}

/*
WEATHER
*/

function ShowWeatherEdit ()
{
    var weather_place = document.getElementById ("weather_place");
    var weather_form = document.getElementById ("weather_form");
    var wbox = document.getElementById ("weather_box");
    var wContent = document.getElementById ("weather_content");
    var wLinks = document.getElementById ("weather_links");
    
    wbox.value = document.getElementById ("weather_initial").value;
   
    weather_form.style.display = 'block';
    wContent.style.display = 'none';
    wLinks.style.display = 'none';
    weather_place.style.display = 'none';
    wbox.focus();
    wbox.select();
}
function UpdateWeather ()
{
  var loading = document.getElementById ("weather_loading");
  var weather_content = document.getElementById ("weather_content");
  var theform = document.getElementById ('frm_weather');
  var wbox = document.getElementById ("weather_box");
  var wContent = document.getElementById ("weather_content");
  var wLinks = document.getElementById ("weather_links");
  
  document.getElementById ("weather_form").style.display  = 'none';
  loading.style.display = 'block';
  weather_content.style.display = 'none';
   
   var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ 
      
            loading.style.display = 'none'; 
            AutoSave('frm_default', 1);             
            weather_content.style.display = 'block';
            if (req.responseText != '')
            {
                weather_content.innerHTML = req.responseText.split('#')[0];
                document.getElementById ("weather_In").innerHTML = "<b>" + req.responseText.split('#')[1] + "</b>";
                document.getElementById ("weather_initial").value = req.responseText.split('#')[1];
                wbox.value = req.responseText.split('#')[1];
            }
            document.getElementById ("weather_place").style.display = 'block';
            wContent.style.display = 'block';
            wLinks.style.display = 'block';
            document.getElementById ("weather_form").style.display = 'none';
            
      }
    }
  );
  return status;  
}
function CancelWeatherUpdate ()
{
    var weather_place = document.getElementById ("weather_place");
    var weather_form = document.getElementById ("weather_form");
    var wContent = document.getElementById ("weather_content");
    var wLinks = document.getElementById ("weather_links");
    
    weather_form.style.display = 'none';
    weather_place.style.display = 'block';
    wContent.style.display = 'block';
    wLinks.style.display = 'block';    
}

/*
VERTICALS
*/
function FillOtherDropDown()
{
   var VerticalDatabase = document.getElementById ("VerticalDatabase");
   var VerticalsCategory = document.getElementById ("VerticalsCategory");
   var theform = document.getElementById ('frm_verticals');
   
   document.getElementById ("SelectedVertical").value = VerticalsCategory.options[VerticalsCategory.selectedIndex].value;
   VerticalsCategory.disabled = 'disabled';
   
   var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){            
            //if (req.responseText != '')
            {
                VerticalDatabase.style.display = 'block';
                VerticalDatabase.innerHTML = req.responseText; 
                VerticalsCategory.disabled = '';
            }
      }
    }
  );
  return status;  
}
function GetVerticals()
{
    var verticals_result = document.getElementById ("verticals_result");
    var theform = document.getElementById ('frm_verticals');
    var status = AjaxRequest.submit(
        theform
        ,{
          'onSuccess':function(req){                            
              verticals_result.innerHTML = req.responseText;
          }
        }
      );
      return status;  
}

function DeleteWeather ()
{
    if (confirm("Do you really want to delete this? There is NO undo for this operation."))
    {
        document.getElementById ("weather_holder").style.display = 'none';
        document.getElementById ("hiddenDel_weather").value = 'YES';
        var theform = document.getElementById ("frm_weather");    
        var status = AjaxRequest.submit(theform);
        return status;  
    }    
}

function LoadQuotes(fromName)
{   
   var ddlQ = document.getElementById ("ddlQuote_" + fromName);  
   document.getElementById("query_box_" + fromName).value = ddlQ.options[ddlQ.selectedIndex].text;
} 
function TestQ()
{
    if ($('Query').value == '')
    {
        alert ('please enter a query.');
        $('Query').focus();
        return false;
    }    
    return true;
}
function CheckAlexa()
{
    if ($('Site1').value == '' && $('Site2').value == '' && $('Site3').value == '')
    {
        alert ('please enter at least one site address.');
        $('Site1').focus();
        return false;
    }  
    return true;
}
function CheckVerticals()
{
    if ($('VerticalQuery').value == '')
    {
        alert ('please enter a query.');
        $('VerticalQuery').focus();
        return false;
    }  
    return true;
}
function IsThisReturn(event, numero)
{
    if (event.keyCode == 13){
        if (numero != null)
            UpdateContent(numero);
        else UpdateWeather();
    } 
}
function RefreshAllPage ()
{
    window.location = "default.aspx";
}
function HideShow (doWhat, withID, doWho, isBold)
{
    document.getElementById ('n'+withID+"_"+doWho).style.display = doWhat;
    if (doWhat == 'block') 
    { 
        if (isBold != null)
            document.getElementById ('pluslink'+withID+"_"+doWho).innerHTML = "<a href=\"javascript:;\" style=\"text-decoration: none;color: blue;\" onclick=\"HideShow(\'none\', '" + withID + "' ,'" + doWho + "');\" >[-]</a>&nbsp;";
        else  document.getElementById ('pluslink'+withID+"_"+doWho).innerHTML = "<b><a href=\"javascript:;\" style=\"text-decoration: none;color: blue;\" onclick=\"HideShow(\'none\', '" + withID + "' ,'" + doWho + "');\" >[-]</a></b>&nbsp;";
        document.getElementById ('title'+withID+"_"+doWho).style.fontWeight  = 'bold';
    }
    else 
    {
        document.getElementById ('pluslink'+withID+"_"+doWho).innerHTML = "<a href=\"javascript:;\" style=\"text-decoration: none;color: blue;\" onclick=\"HideShow(\'block\', '" + withID + "' ,'" + doWho + "');\" >[+]</a>&nbsp;";
        document.getElementById ('title'+withID+"_"+doWho).style.fontWeight  = 'normal';
    }
    
}