/*******************************
 *
 * Search block
 *
 *******************************/

	function SetGFilter (name) {
        var ads = '?filter='+encodeURI(escape(name));
        var loc = '/search/g/';

        
        if(document.getElementById('edit-keys')) {
         loc += encodeURI(escape(document.getElementById('edit-keys').value));
        } else if(document.getElementById('myGgSearchTop')) {
         loc += encodeURI(escape(document.getElementById('myGgSearchTop').value));
        }
        
        document.location = loc + ads + '&amp;'+Math.random();
      }
      
      function AnalyseSearch () {
       var def = 'all';
       var re = new RegExp("^http\:\/\/www\.hypnosisdownloads\.com/scripts");
       if(re.exec(document.location.href)) def = 'script';
       re = new RegExp("^http\:\/\/www\.hypnosisdownloads\.com/all\-scripts");
       if(re.exec(document.location.href)) def = 'script';
       SetGFilter(def);
      }




/*******************************
 *
 * Cookie block
 *
 *******************************/

function _setCookie(name,value,days) {
   if (days) {
       var date = new Date();
       date.setTime(date.getTime()+(days*24*60*60*1000));
       var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/";
  }
  
  function _getCookie(c_name){
  var i,x,y,ARRcookies=document.cookie.split(";");
  for (i=0;i<ARRcookies.length;i++)
  {
    x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
    y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
    x=x.replace(/^\s+|\s+$/g,"");
    if (x==c_name)
      {
      return unescape(y);
      }
    }
  }
  
  
/*******************************
 *
 * A/B test block
 *
 *******************************/

   function ABTestAddProduct(pcode, flag) {
    var was = _getCookie('hdabtest');
    var to_store = new Array();
    if(was) {
     var a = was.split('|');
     for(var i in a) {
      var b = a[i].split(':');
      if(b[0] != pcode) to_store.push(b[0]+':'+b[1]);
     }
    }
    to_store.push(pcode+':'+flag);
    _setCookie('hdabtest', to_store.join('|'), 1);
   }
