// Copyright (c) 2001 Todd Roseman, LUKY.COM, ALL RIGHTS RESERVED.

// DO NOT COPY WITHOUT PERMISSION - ALL RIGHTS RESERVED.

function CookieVal(key)	{
	var cookies = document.cookie;
	var i,j,k;
	var value="";

	k = (new String(key)).length;
	i = cookies.indexOf(key);
	if (i>=0)	{
		j = cookies.indexOf(";",i);
		if (j==-1) { j = cookies.length; }
		value = unescape(cookies.substring(i+k,j));
	}
	return value;
}

function SetFormFrom(f)	{
	if (f && f.op1_2)	{
		// get cookie value
		var value = CookieVal("fromsrch=");
		var value2 = CookieVal("refer=");
		var v;
		
		v = value;
		if (!v) { v = "unknown "; }
		if (value2)	{
			v = (v + " | refer: " + value2);
		}
		f.op1_2.value = v;
	}
	return true;
}

function CookieExp()	{
	var exp = new Date();
	var expFromNow = exp.getTime() + (90 * 24 * 60 * 60 * 1000); // 90 days

	exp.setTime(expFromNow);
	return exp.toGMTString();
}

function SetDocFrom()	{
	// if there is a 'from' field, set a cookie for it
	var loc = document.URL;
	var i;
	var rgNotUrl = new Array();
	var bMatch=false;
	var s;

	rgNotUrl[0] = "http://www.haikudesigns.com";
	rgNotUrl[1] = "http://haikudesigns.com";
	rgNotUrl[2] = "https://ns1.haikudesigns.com";
	rgNotUrl[3] = "http://ns1.haikudesigns.com";
	rgNotUrl[4] = "http://216.71.205.231";
	i = loc.lastIndexOf("from=");
	if (i>=0)	{
		var val = loc.substring(i+5);
		if (val.length>0) {
			document.cookie = "fromsrch=" + val + "; expires=" + CookieExp();
		}
	}
	loc = document.referrer;
	loc = loc.toLowerCase();
	if (loc)	{
		for (i=0; (i<rgNotUrl.length) && !bMatch; i++)	{
			s = rgNotUrl[i];
			if (loc.indexOf(s) == 0)	{
				bMatch = true;
			}
		}
		if (!bMatch)	{	
			// set referrer if not already set and if there is one
			// set always when not referring internally
			document.cookie = "refer=" + loc + "; expires=" + CookieExp();
		}
	}
}

function showPic(nColor)	{
	var s = (nColor==1) ? imgNatural : imgBlack;
	setPic(s,nColor);
}

function setPic(source,nSel)	{
	if (source)	{
		document['pic'].src=source;
	}
	if (document.form1)	{
		if (document.form1.op1)	{
			if (document.form1.op1.length>1)
				document.form1.op1.selectedIndex = nSel;
		}
	}
	if (document.form2)	{
		if (document.form2.op1)	{
			if (document.form2.op1.length>1)
				document.form2.op1.selectedIndex = nSel;
		}
	}
	picColor=nSel;
}

function showPic2(nSel,formname,picname,images)	{
	var s = images[nSel];
	if (s)	{
		document[picname].src=s;
	}
	if (document.forms[formname])	{
		if (document.forms[formname].op1)	{
			if (document.forms[formname].op1.length>1)
				document.forms[formname].op1.selectedIndex = nSel;
		}
	}
	picColor=nSel;
}

function showLargeImage(source)	{
	var s;
	s = "largeimg.htm?src="+escape(source);
	showWindow(s);	
	return false;
}

function showLargeImage2(source0,source1)	{
	var s;
	var source = (picColor==0) ? source0 : source1;
	s = "largeimg.htm?src="+escape(source);
	showWindow(s);	
	return false;
}

function showInfo(thePage)	{
	var newWin = window.open(thePage,"newWin","resizable=yes,menubar=no,titlebar=yes,dependent=yes,width=480,height=550");
	newWin.focus();
	return false;
}

function showWindowXY( thePage, width, height)	{
	var newWin = window.open(thePage,"newWin","resizable=yes,scrollbars=yes,menubar=no,titlebar=yes,dependent=yes,width="+width+",height="+height);
	newWin.focus();
	return false;
}

function showWindow(thePage)	{
	var newWin = window.open(thePage,"newWin","resizable=yes,menubar=no,titlebar=yes,dependent=yes,width=350,height=450");
	newWin.focus();
	return false;
}

function WriteEmail( t )	{
	document.writeln('<a href="mailto:'+'information'+'@'+'haikudesigns.com">'+t+'</a>');
}

SetDocFrom();
var picColor = 0;

/* functions for menus */

sfHover = function() {
	if (document.getElementById("nav"))	{
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

/* END for menus */



function relativeFilePart( s )	{
	var i;
	
	var rsl = /\\/g;
	s = s.replace(rsl,'/');
	var re = /\/dw\/(.*)/;
	var rg = re.exec(s);
	if (rg)	{
		if (rg.length<=1)	{
			rr = /\/.com\/(.*)/;
			rg = rr.exec(s);
			if (rg.length<=1) { return s; }
		}
		return rg[1];
	}
	else { return s; }
}


function setCurrentPage( tagid ) {
	var navEl = document.getElementById(tagid);
	if (navEl)	{
		var aEls = navEl.getElementsByTagName("A");
		var i, as, thisFile, liEl, liEj, liElast;
		var currentFile;
		
		currentFile = relativeFilePart(document.URL);
	
		// find this page and set it's <li> to different class, also set parents li (if exists)
		for (var i=0; aEls && (i<aEls.length); i++) {
			// className
			as = new String(aEls[i].href);
			thisFile = relativeFilePart(as);
	//		alert(thisFile + " " + as);
			// thisFile = as.substring(as.lastIndexOf('/')+1,100);
			// alert( thisFile + currentFile + (thisFile==currentFile));
			if (thisFile == currentFile)	{
				// break; // do all occurances of this file in menu
				
				// set this element
				// set top-level parent (this menu, immediate parent, (not ul though)
				liEl = aEls[i];
				liEl.className = liEl.className + " here";
				// also set parent (li)
				// (for table cells when child anchor is link)
				liEj = liEl.parentNode;
				liEj.className = liEj.className + " here";
				
			}
		}
	}
}


function setHover( idholder, hover_el ) {
	// sets sfhover class on elements when hovered
	if (document.getElementById(idholder))	{
		var sfEls = document.getElementById(idholder).getElementsByTagName(hover_el);
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

function SwitchOver( obj )	{
	// alert(obj.id + " " + obj.className);
	// content div is 'content_'+id
	
	// switch tab class (don't need hover class)
	// also display/hide all other content blocks
	if (document.getElementById) {
		//var el = document.getElementById(obj);	// this tab
		var el = obj;
		var elP = el.parentNode;		// parent 
		var ar = elP.getElementsByTagName("a"); 
		for (var i=0; i<ar.length; i++){
			ela = ar[i];
			// set content to match
			content_el = document.getElementById("content_"+ela.id);
			if (ela.id == el.id)	{
				// on
				ela.className = 'tabOn';
				if (content_el)	
					content_el.style.display = "block";
			} else {
				// off
				ela.className = 'tab';
				if (content_el)	
					content_el.style.display = "none";
			}
		}
	}
	return false;	// for use in onClick anchor
}


