// <!-- begin script
//
//	2009-07-24: virusmelding avira opgelost (in stock / prijs )
//	2004-04-14: sjamaan /	local location = _pages
//	2004-01-26: dedicated server => 1 script file
//
//	2003-06-30:  OPERA FIX
//	function sjm_product_code_get()
//
//
//	2006: sjmadd2006.exe / sjmvw2006.exe / sjmordr2006.exe
//

	//	=========  GLOBAL VARIABLES (2004) =============

	//	var	BasicUrl = "http://enigma/cgi/"
	//	var	PictUrl	 = "http://enigma/cgi-ron/sjm_pict.exe?"


		var	BasicUrl = "https://secure.desjamaan.nl/sjamaan/sjm-cgi2/"
		var	PictUrl	 = "http://desjamaan.nl/cgi-ron/sjm_pict.exe?"

	//	var	BasicUrl = "http://salvador/sjamaan/shoptotaal0409/"
	

	//	========== search_google ============


// =================================================
//
//	begin_2009 Price/Stock in IFRAME (virus/browsers)
//
// =================================================


//	function fnPriceStockShow('IfEN1321')
	
	function fnPriceStockShow(STUBBIE)
	{
	   var Url = '"http://desjamaan.nl/sjm-cgi2/sjmprd.exe?' + STUBBIE +'"' ;
	   var Line1 = '<iframe src =' + Url + 'scrolling="auto" width="100%" height="50" frameborder="0">\n' 
	   var Line2 = '  			<p>Your browser does not support iframes.</p>\n'
	   var Line3 = '</iframe>\n'  			
	   //	    
	   document.writeln(Line1);
	   document.writeln(Line2);
	   document.writeln(Line3);
	   document.close()
	}
	
// =================================================
//
//	end__2009 Price/Stock in IFRAME (virus/browsers)
//
// =================================================

	function search_google(Searchwhat)
	{
		var stub = "http://www.google.com/search?as_sitesearch=www.de-sjamaan.nl&num=100&as_occt=body&as_qdr=m3&as_q=" ;
		var loc = stub + escape(Searchwhat) ;
		alert (loc) ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (loc, x, y ) ;
	}
	
	//	========== jump_to special offers / new products / quickorder  ============
	
	function gospecial()
	{
		var location = "http://www.sjamaan.com/special.htm" ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (location, x, y )
	}

	function gonewproducts()
	{
		var location = "http://www.sjamaan.com/en/9600.htm" ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (location, x, y )
	}

	function goquickorder()
	{
		var location = "http://www.desjamaan.nl/cgi-ron/sjmprd.exe?FormID=QuickOrder&Config=SJMPRODCONFIG_EN_SELECTIONS" ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (location, x, y )
	}

	function gouptodate()
	{
		var location = "http://www.sjamaan.com/en/index.html" ;
		alert ("Your are going to the up to date site (English)") ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (location, x, y )
	}

	//	========== jump_to_link_and_postings 01-07-25 ============

	function golinks()
	{	// http://www.sjamaan.com/links/links.asp
		var location = "http://www.sjamaan.com/links/links.asp" ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (location, x, y )
	}

	function gopostings()
	{
		var location = "http://www.sjamaan.com/forum/" ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (location, x, y )
	}

	function goshops()
	{
		var location = "http://www.de-sjamaan.nl/shops/" ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (location, x, y )
	}
	function goprofile()
	{
		var location = "http://www.sjamaanwholesale.nl/wsprofile.htm" ;
		var x=620 ;
		var y=460 ;
		sjm_open_full_window (location, x, y )
	}

	//	autopict 01-07-15
	//	writes pict PRODID.GIF or PRODID.JPG
	// 	in html-source: <script language="javascript">autopict()</script>

	function autopict ()
	 {
		var urlbase = PictUrl ;
	 	var url = urlbase + sjm_product_code_get() // first 4 chars of title
	 	var alt = document.title
	 	var t = "<img border='0' src='" + url +"' alt='"+ alt + "' >" ;
	 	//%debug2
		//alert(t)
	 	self.document.write(t)
	 }	

	 

function check_top()
{  if (window.self == window.top)
	{	
		window.location.href="index.htm" ;  
	}	
}


// ******************************
// COOKIES
// ******************************
//  Cookie Functions - Second Helping  (21-Jan-96)
//  Written by:  Bill Dortch, hIdaho Design <bdortch@netw.com>
//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
	   if (document.cookie.substring(i, j) == arg)
     return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
//
//  Function to create or update a cookie.
//    name - String object object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to current date/time)
//    name - String object containing the cookie name
//
function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);  // This cookie is history
  var cval = GetCookie (name);
  if (cval != null)
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//
//  Example
//
function example() {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
SetCookie ("ccpath", "http://www.hidaho.com/colorcenter/", expdate);
SetCookie ("ccname", "hIdaho Design ColorCenter", expdate);
SetCookie ("tempvar", "This is a temporary cookie.");
SetCookie ("ubiquitous", "This cookie will work anywhere in this domain",null,"/");
SetCookie ("paranoid", "This cookie requires secure communications",expdate,"/",null,true);
SetCookie ("goner", "This cookie must die!");
document.write (document.cookie + "<br>");
DeleteCookie ("goner");
document.write ("ccpath = " + GetCookie("ccpath") + "<br>");
document.write ("ccname = " + GetCookie("ccname") + "<br>");
document.write ("tempvar = " + GetCookie("tempvar") + "<br>");
}
// ******************************
//  Tools
// ******************************
function str_add_zeros(Instr, Length)
{ // prefixes string with "0"
	var Wstr = Instr;
	while (Wstr.length < Length) {Wstr ="0"+Wstr}
	return(Wstr)
}

//******************** GENERATE UNIQUE ID **********************

function sjm_generate_id(Prefix)
{  
  var newdate = new Date ();
  var millies   = newdate.getTime();
  var mil_str   =  ""+millies; 
  mil_str 	=  mil_str.substring(7,12)		// mili seconds
  var y		=  newdate.getYear();          		y_str=""+y ;    while (y_str.length < 2) {y_str ="0"+y_str}
  var m		=  newdate.getMonth(); m+=1;        	m_str=""+m ; while (m_str.length < 2) {m_str ="0"+m_str}
  var d		=  newdate.getDate();           	d_str=""+d ;   while (d_str.length < 2) {d_str ="0"+d_str}
  var h		=  newdate.getHours();         		h_str=""+h ;   while (h_str.length < 2) {h_str ="0"+h_str}
  var min	=  newdate.getMinutes();    		min_str=""+min ;   while (min_str.length < 2) {min_str ="0"+min_str}
  var s		=  newdate.getSeconds();     		s_str=""+s ;   while (s_str.length < 2) {s_str ="0"+s_str}
  var idstr 	=  Prefix+ "_" + y_str + m_str + d_str + "_" + h_str + min_str + s_str + "_"+mil_str
  // random string 
  var x = 10000; x = Math.round(Math.random() * x) ; x_str=""+x; while (x_str.length < 5) {x_str ="0"+x_str}
  idstr = idstr + "_" + x_str
  return(idstr)
}



function sjm_cookie_order()
{
  var  expdate = new Date;
  var sesname   = "xsjmsesid";
  var sescookie  = GetCookie(sesname);
  if 	(sescookie == null)
  	{  	expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
		ID = sjm_generate_id("__O");
		SetCookie (sesname, ID, expdate);
	}
  sescookie = GetCookie(sesname);
//  DeleteCookie(sesname);
  return sescookie	
	
}

//******************** CUSTOMER ID **********************
function sjm_cookie_customer()
{
  var  expdate = new Date;
  var sesname   = "xsjmcusid";
  var sescookie  = GetCookie(sesname);
  if 	(sescookie == null)
  	{  	expdate.setTime (expdate.getTime() + (365*24 * 60 * 60 * 1000)); // 365 days from now
		ID = sjm_generate_id("__C");
		SetCookie (sesname, ID, expdate);
	}
  sescookie = GetCookie(sesname);
  return sescookie		
}

//******************** DELETE ID'S  **********************
function sjm_cookies_delete()
{
  DeleteCookie ("xsjmsesid");
  DeleteCookie ("xsjmcusid");
  return ("deleted ok")
}

// ********************** PRODUCT-CODE-FROM HTML-PAGE *****************************
	function sjm_product_code_get()
	{   //2003-06-30 OPERA FIX
	    var T 	= 	window.document.title ;
	    var C 	= 	new String       ;
	    var TEST 	= 	T.substring(0,5) ;
	    var OPERA	=	T.substring(1,5) ;
	    var NSIE	=	T.substring(0,4) ;
	    var L	=	TEST.lastIndexOf(" ")
	    if  ( L>0 )
			{ RR = NSIE }
	    else	{ RR = OPERA }
	    // alert (RR)
	    return (RR)
	    
	}

// ********************** OPEN POPUP WINDOW *****************************
function sjm_open_popup_window (location, x, y ) {
		if (navigator.appName=="Microsoft Internet Explorer" &&  parseInt (navigator.appVersion) <= 3) {
				y = y - 30;
		}
		if (navigator.appName=="Netscape") {
				if (parseInt (navigator.appVersion) <= 3) {
					y = y + 30;
					x = x + 27;
				} else {
					y = y + 17;
					x = x + 17;
				}
		}
		
		// var win = window.open (location, '_blank', "resizable=no,scrollbars=no,status=0,menubar=no,width="+x+",height="+y);
		
		// scrollbars YES -- resizable=no, // scrollbars=no
		var win = window.open (location, '_blank', "status=0,menubar=no,width="+x+",height="+y);
	}

// ********************** OPEN SCROLL / FULL WINDOW *****************************
function sjm_open_full_window (location, x, y ) {
		if (navigator.appName=="Microsoft Internet Explorer" &&  parseInt (navigator.appVersion) <= 3) {
				y = y - 30;
		}
		if (navigator.appName=="Netscape") {
				if (parseInt (navigator.appVersion) <= 3) {
					y = y + 30;
					x = x + 27;
				} else {
					y = y + 17;
					x = x + 17;
				}
		}
//		var win = window.open (location, '_blank', "location=yes,resizable=yes,scrollbars=yes,status=yes,menubar=no,width="+x+",height="+y);
//		var win = window.open (location, '_blank', "location=no,resizable=yes,scrollbars=yes,status=no,menubar=yes,width="+x+",height="+y);
//		var win = window.open (location, '_blank', "location=no,resizable=yes,scrollbars=yes,status=yes,menubar=yes,width="+x+",height="+y);

		var win = window.open (location, '_blank', "location=no,resizable=yes,scrollbars=yes,status=yes,menubar=yes");

		// win.close()
		// return win
	}

// ********************** OPEN FULL SCREEN WINDOW *************************************

function sjm_open_full_screen (location)
 {
	// 'top=100,left=100,width=575,height=400'
 	
 	var windefstr = "location=no,resizable=yes,scrollbars=yes,status=yes,menubar=yes,top=0,left=0"
 		 	
		if (navigator.appName=="Microsoft Internet Explorer" &&  parseInt (navigator.appVersion) <= 3) 
			{	var x = 630;
				var y = 470;
				var win = window.open (location, '_blank', "location=no,resizable=yes,scrollbars=yes,status=yes,menubar=yes,width="+x+",height="+y);
			}
		else	{	
				if ( (navigator.appName=="Netscape") && (parseInt (navigator.appVersion) <= 3) )
				{
					var toolkit = java.awt.Toolkit.getDefaultToolkit();
					var screen = toolkit.getScreenSize();
					var scrwidth = screen.availWidth - 10 ;
					var scrheight = screen.availHeight - 100 ;		
				}
				else
				{
					var scrwidth = window.screen.availWidth - 10;
					var scrheight = window.screen.availHeight - 100;		
				}
				windefstr += ",width="+scrwidth+",height="+scrheight+"";
				var win = window.open (location, '_blank', windefstr);
			}	
			
}



// ***************************************************************************************************

function sjm_open_link(location)
{
   var win = window.open (location, '_blank', "toolbar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,menubar=yes,width=500,height=400");
}

function sjm_open_full_window_timeout (location, x, y, timeout ) {
		if (navigator.appName=="Microsoft Internet Explorer" &&  parseInt (navigator.appVersion) <= 3) {
				y = y - 30;
		}
		if (navigator.appName=="Netscape") {
				if (parseInt (navigator.appVersion) <= 3) {
					y = y + 30;
					x = x + 27;
				} else {
					y = y + 17;
					x = x + 17;
				}
		}
		var nwin = window.open (location, '_blank', "resizable=yes,scrollbars=yes,status=yes,menubar=no,width="+x+",height="+y);
		if	((timeout != null) && (timeout != 0))
		{	
		//	timerID = setTimeout("nwin.close()",timeout)
			mytime = new Date()
			mytime2 = new Date()
			now = mytime.getTime()
			dan = mytime2.getTime() 
			while ((dan - now) < (timeout * 1000)) { mytime2 = new Date(); dan = mytime2.getTime()  }
			if (nwin != null) {nwin.close()}
		}
		// return win
	}

		
// ********************** ADD PRODUCT  NEW!!!  *****************************
//
// 	2002:	 sjm_add()  => sjmadd(c_Lan)
//
// *************************************************************************

function sjmadd(c_Lan)
{
	
//	BasicUrl in global Var
	var cgi_prog 		=	BasicUrl+"sjmadd2006.exe"
//	alert("start")
	var prodid		= ""
	prodid			=	sjm_product_code_get()
	var prod_post     	= 	prodid.substring(2,4)
//	alert (prodid)
	if	(prod_post == "00")			// Product-category selected => show message box
		{
			alert("Oops.... You are currently in an OVERVIEW page; Please select a PRODUCT first.");
		}
	else  {	var cgi_str	=	new String;	// Product selected => send to server
		  o_cookie	=	sjm_cookie_order();
		  c_cookie	=	sjm_cookie_customer()
//		  %$#@ 
		  cgi_str	=	"FormID=__sjm_add&";
		  cgi_str 	+=	"OrderID="+o_cookie+"&CustID="+c_cookie+"&ProdID="+prodid+"&";
		  cgi_str 	+=	"c_Lan="+c_Lan+"";
		  cgi_str	=	cgi_prog+"?"+cgi_str;
		  cgi_str	+=	"&Unique="+sjm_generate_id("unique")+""  
		  // make unique url
		  // alert(cgi_str);
		  sjm_open_popup_window(cgi_str,300, 300);
		}	
}


function sjmaddprod(Prod_ID, c_Lan)
{
	
//	BasicUrl in global Var
	var cgi_prog 		=	BasicUrl+"sjmadd2006.exe"
//	alert("start")
	var prodid		= ""
	prodid			=	Prod_ID ;
//	sjm_product_code_get()
	var prod_post     	= 	prodid.substring(2,4)
//	alert (prod_post)
	if	(prod_post == "00")			// Product-category selected => show message box
		{
			alert("Oops.... You are currently in an OVERVIEW page; Please select a PRODUCT first.");
		}
	else  {	var cgi_str	=	new String;	// Product selected => send to server
		  o_cookie	=	sjm_cookie_order();
		  c_cookie	=	sjm_cookie_customer()
//		  %$#@ 
		  cgi_str	=	"FormID=__sjm_add&";
		  cgi_str 	+=	"OrderID="+o_cookie+"&CustID="+c_cookie+"&ProdID="+prodid+"&";
		  cgi_str 	+=	"c_Lan="+c_Lan+"";
		  cgi_str	=	cgi_prog+"?"+cgi_str;
		  cgi_str	+=	"&Unique="+sjm_generate_id("unique")+""  
		  // make unique url
		  // alert(cgi_str);
		  sjm_open_popup_window(cgi_str,400, 400);
		}	
}

// ********************** VIEW SHOPPING LIST  *****************************
//
// 	2002:	 sjm_view()  => sjmview(c_Lan)
//
// *************************************************************************

function sjmview(c_Lan)
{
//	%$#@!
	cgi_prog 	=	BasicUrl+"sjmvw2006.exe"
//	alert("start")
	var cgi_str	=	new String;	
	o_cookie	=	sjm_cookie_order();
	c_cookie	=	sjm_cookie_customer()
//	%$#@ 
//	timestamp
	var newdate = new Date ();
  	var millies   = newdate.getTime();
  	var mil_str   =  ""+millies; 
  
  	cgi_str		=	"FormID=__Sjm_view&";
	cgi_str 	+=	"OrderID="+o_cookie+"&CustID="+c_cookie+"";
	cgi_str 	+=	"&c_Lan="+c_Lan+"";
	cgi_str		+=	"&TimeStamp="+mil_str+"";
	cgi_str		=	cgi_prog+"?"+cgi_str;
	// alert(cgi_str);
	sjm_open_full_screen (cgi_str)
	
	// sjm_open_full_window(cgi_str,630, 450);
}


//
// ********************* PSYCHOACTIVE SEARCHING **************************************
//
//******************* Open browser ************************

function sjm_open_browser (location, x, y ) 
{
		var win = window.open (location, '_blank', "toolbar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,menubar=yes,width="+x+",height="+y);
}

//******************* Real name  Eroticava (200) => Erotikava ************************
function get_real_productname(fullname)
{
	haakloc = fullname.indexOf("(");
	
//	alert(haakloc)
	
	if 	(haakloc == -1)			
		{
		   newname = fullname;
		}
	else  {
		   haakloc -= 1;
		   newname = fullname.substring(0,haakloc);
		}	
//	alert(newname)	
	return newname
}
function split_productname(fullname)
{
	words =   ""; 
	rest    =   fullname;
	spaceloc = rest.indexOf(" ");
	if              (spaceloc != -1) 
			{words = rest.substring(0,spaceloc); newloc = spaceloc + 1; rest=rest.substring(newloc,rest.length)}
	else	      {return fullname}
		
	spaceloc = rest.indexOf(" ");
	while (spaceloc != -1)
	{   
		words += ("+" + rest.substring(0,spaceloc));
		newloc = spaceloc + 1;
		rest  = rest.substring(newloc,rest.length);
		spaceloc = rest.indexOf(" ");
	}
	if 	(rest !="")	{ words += ("+" + rest)}
	alert (words)
	return words
}
//******************* Search Lycaeum- EntheoCrawler  ************************

function  search_lycaeum(fullname)
{
	realname = get_real_productname(fullname);
	words = split_productname(realname)
	locationStr = "http://www.lycaeum.org/search.cgi?ul=&ps=20&np=0&q="+words
	x=600; y=400;
	return sjm_open_browser (locationStr, x, y );
}

// http://www.erowid.org/cgi-bin/search/htsearch.cgi?config=&restrict=&exclude=&method=and&format=builtin-short&words=kava+kava

//******************* Search Erowid  ************************

function  search_erowid(fullname)
{
	realname = get_real_productname(fullname);
	words = split_productname(realname)
	locationStr = "http://www.erowid.org/cgi-bin/search/htsearch.cgi?config=&restrict=&exclude=&method=and&format=builtin-short&words="+words;
	x=600; y=400;
	return sjm_open_browser (locationStr, x, y );
}

// end script -->

