function createCookie(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 readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);}


function buy (id) {
  clickto("pictopia " + id);
  win = window.open("http://www.davidsanger.com/buyid.php?id=" + id,"purchase");
  win.focus();
}

function windowpop (url) {
  win = window.open(url,"","scrollbars=yes, resizable=yes, toolbar=no, status=yes, width=720,height=600, menubar=no");
  win.focus();
}

function go(dir){
qq=document.search.q.value.toLowerCase();
qq=qq.replace(/\+/g,'-'); 
qq=qq.replace(/\s+/g,'-');
qq=qq.replace(/[-]+/g,'-'); 
window.location.href='http://www.davidsanger.com/' + dir + '/' + qq;
return true;}

function stock(){
qq=document.search.q.value.toLowerCase();
qq=qq.replace(/\+/g,'-'); 
qq=qq.replace(/\s+/g,'-');
qq=qq.replace(/[-]+/g,'-'); 
window.location.href='http://www.davidsanger.com/stock/' + qq;
return true;}




function dosearch(){
qq=document.entry.q.value.toLowerCase();
qq=qq.replace(/\+/g,'-'); 
qq=qq.replace(/\s+/g,'-');
qq=qq.replace(/[-]+/g,'-'); 
dir=document.entry.t.value;
dest='http://www.davidsanger.com/' + dir + '/' + qq;
document.forms.search.action=dest;
document.forms.search.submit();	
return true;}

function setsearch(){
qq=document.entry.q.value.toLowerCase();
qq=qq.replace(/\+/g,'-'); 
qq=qq.replace(/\s+/g,'-');
qq=qq.replace(/[-]+/g,'-'); 
dest = document.getElementById("search").href
document.getElementById("search").href = dest + qq;
}


function clickto(dest){ 
 a=new Image(1,1); 
 a.src='http://www.davidsanger.com/stats.php?to=' + dest + '&from=' + escape(location.href)+ '&ref=' + escape(document.referrer);
}



function addEngine(name,ext,cat)
{
var url = "http://www.davidsanger.com/";
if ((typeof window.sidebar == "object") && (typeof
window.sidebar.addSearchEngine == "function"))
  {
    window.sidebar.addSearchEngine(url+name+".src", url+name+"."+ext,
name, cat );
  }
  else
  {
    alert("ERROR");
  }
}
