﻿
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2031670-19']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

var settings_similarsites = true ;
var searchid = 0;
var subid = getParam('subid');
var type = getParam('type');

//Check setings in cookie
(function()
{

    if(document.cookie == '')
    {
        setCookie("settings-similarsites","true",360);
        settings_similarsites = true;
    }  
    else
    {
        var enableSimilarSites = getCookie("settings-similarsites");
        
        if(enableSimilarSites != null)
        {
            settings_similarsites = ParseBoolean(enableSimilarSites);    
        }
    } 
})();

function changeSettings(checkbox)
{
    switch(checkbox.id)
    {
        case "cbxsimilarsites":
            if(checkbox.checked == 1)
            {
                setCookie("settings-similarsites","true",360);
                var items = $('.sslink');
                if(items.length == 0)
                {
                    addWidget();
                }
                else
                {
                    $('.sslink').show();
                }
            }
            else
            {
                setCookie("settings-similarsites","false",360);
                $('.sslink').hide();
            }
        break;
    }
}

function toggleMenu()
{
    
      $('#lmenuh').animate({
        opacity: 'toggle',
        height: 'toggle'
      }, 500, function() {
       /*
       var a = document.getElementById('#tglText');
       if(a.innetHTML == "More")
       {
       
            a.innerHTML = "Fewer";
            document.getElementById('tglImg').className = "m_icon fewer";
       }
       else
       {
           a.innerHTML = "More";
           document.getElementById('tglImg').className = "m_icon more";
       }*/
      });
}

function setSearch(i)
{
    searchid = i;
}

function search()
{   
    var text="";
    if(searchid && searchid == 1)
    {
        text = document.getElementById("searchTerm2").value;
    }
    else
    {
       text = document.getElementById("searchTerm").value;
    }
    
    if(text == "")
         return;
    
    try{
         if(type == "" || subid =="")
         {
            window.location = "search.htm?sterm="+ encodeURIComponent(text);
         }
         else
         {
            window.location = "search.htm?sterm="+ encodeURIComponent(text) +"&subid="+subid+"&type="+type;
         }
    }catch(e)
            {
             window.location = "search.htm?sterm="+ encodeURIComponent(text);
            }
       
}

function searchTopSite()
{
     text = document.getElementById("searchTerm").value;
     window.location = "http://www.topsite.com/search?searchType=0&stype=1&sterm="+encodeURIComponent(text)+"&sbtn=submit";

}

function searchKeyPress(event)
{
    if (event.keyCode == 13)
    {
        search();
    }
}

function sw(element)
{
    id = element.id;
    var text="";
    if(searchid && searchid == 1)
    {
        text = document.getElementById("searchTerm2").value;
    }
    else
    {
       text = document.getElementById("searchTerm").value;
    }
    switch(id)
    {
      case "web":
       window.location = "search.htm?sterm="+encodeURIComponent(text);
       break;
       case "images":
       window.location = "http://images.google.com/images?q="+encodeURIComponent(text);
       break;
       case "videos":
       window.location = "http://images.google.com/search?q="+encodeURIComponent(text)+"&tbs=vid:1";
       break;
    }
    
}



function clearText()
{
    if(document.getElementById("helperText").style.display == "block")
    {
      document.getElementById("helperText").style.display = "none";
      document.getElementById("searchTerm").value ="";
      document.getElementById("searchTerm").focus();
      }
}


function getParam(paramName){
    try {
        // get the current URL
        var url = window.location.toString();
        //get the parameters
        url.match(/\?(.+)$/);
        var params = RegExp.$1;
        // split up the query string and store in an
        // associative array
        var params = params.split("&");
        var queryStringList = {};
        
        for (var i = 0; i < params.length; i++) {
            var tmp = params[i].split("=");
            queryStringList[tmp[0]] = tmp[1];
        }
        
        // print all querystring in key value pairs
        for (var i in queryStringList) {
            if (i == paramName) {
                return queryStringList[i];
            }
        }
    } 
    catch (e) {
    }
    
    return "";
}


function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function ParseBoolean(str) {
  switch (str.toLowerCase ()) {
    case "true":
      return true;
    case "false":
      return false;
    default:
        return true;
  }
};
