parent.KeyWord = ''
parent.eventx=-1
parent.tempX=185
parent.tempY=190

function capturequery(mquery)
{
host = document.location.href
host.match(/(.*)\/cgi-bin/)
host = RegExp.$1.toLowerCase()
//alert(host)
ns('',host+'/cgi-bin/build-spider-link.pl?mquery='+escape(mquery),'makelink')
}


function capturequeryold(mquery)
{
//code from viewqueries on queries page
//now in it's own pl program
var close=''
var url=''
var fields = mquery.split('&')
for(var j=0;j < fields.length-1;j++)
{
	attributes = fields[j].split(' ')
	if (attributes[0] == 'includes' || attributes[0] == 'removes')
	{
		url += '&'+attributes[0]+'='
		temp=''
		for(var k=2;k < attributes.length-1;k++)
		{
			temp += ' '+attributes[k]
		}	
		url += temp.substring(1)
	}
	else
	{
		if (attributes[1] == '=' && close == '') 
			url += '&required='+attributes[0]
		if (attributes[0] == 'keyword')
		{
			url += '&'+attributes[0]+'='
			for(var k=2;k < attributes.length-1;k++)
			{
				url += attributes[k] +' '
			}	
		}
		else
		{
			for(var k=2;k < attributes.length-1;k++)
			{
				url += '&'+attributes[0]+'='+attributes[k]
			}	
		}	
	}
}

host = document.location.href
host.match(/(?:t|test)\.(.*)\/cgi-bin/)
host = RegExp.$1.toLowerCase()

if (!confirm('Press OK to use the current domain:\n'+ host + '\n\nIf you want to use the default domain of www.socks-science.com press Cancel.'))
	host = 'socks-science.com'

if (confirm('If this a Google ad and you want to track their ad ID, click OK.\n\nThen when the url is placed into the Goggle ad system, simply add their ID number after the "goadid=ss" part of this url.'))
	url += '&goadid=ss'
if (confirm('If you want to use a promotional code, click OK.\n\nThen when the url is placed into the Goggle or Yahoo ad system, simply add the promotional code after the "promo=" part of this url.'))
	url += '&promo='


url = 'http://www.'+host+'/cgi-bin/socks-selector.pl?type=search'+url+'&'
if (window.clipboardData)
{
	wcb=window.clipboardData
	wcb.setData('text',url)
	clipboard='This URL has been copied to your clipboard.'
}
else
{
	clipboard='To capture this URL open in the new window and copy from the url address bar.'
}

if (confirm(url+'\n\n'+clipboard+'\n\nDo you want to test this saved search in a new window?'))
{
	ns('',url,'_blank')
}
}

function selectorOL()
{
if (!document.forms['selectorform'])
{
	setTimeout("selectorOL()",100)
	return
}
//selectorlinks()
//alert('page is loaded')
for(var j=1;j < document.forms['selectorform'].length;j++)
{
	mobject=document.forms['selectorform'].elements[j]
	//if (mobject.type == 'checkbox' && mobject.checked && 'debug data'.indexOf(mobject.name) == -1)
	//this is new 2/29
	if ((mobject.type == 'checkbox' || mobject.type == 'radio') && 'debug data'.indexOf(mobject.name) == -1)
	{
		update_selector(mobject,mobject.name,mobject.type)
	}
	else if (mobject.type == 'hidden' && mobject.title)
	{
		img = document.images[mobject.title]
		if (!img) continue
		if (mobject.value == mobject.title)
		{
			img.src = '../../assets/images/lock1.gif'
		}
		else
		{
			img.src = '../../assets/images/lock0.gif'
		}
	}
}

}

//function nofunction() {}

function getMouseXY(e)
{
	//setTimeout("setOpacity('notice', .50)",1000)
	//setTimeout("document.getElementById('notice').style.visibility='hidden'",3000)
	
	//if (document.all) x = window.event.x
	//else x = e.pageX
	
	if (document.all)
	{
		x = window.event.x
	}	
	else
	{
		x = e.pageX
	}
	
	if (parent.abR==1 && parent.eventx>0 && parent.eventx != x)
	{
		//alert(x+'___'+parent.eventx)
		//setTimeout("fadeOut()",1000)
		clearTimeout(parent.abT)
		parent.abT=setTimeout("alertnotehide();hidealertbox()",4000)
		parent.eventx=-1
		//setTimeout("document.getElementById('alertboxdiv').style.visibility='hidden'",2000)
		//document.onmousemove = null;
	}
	else
	{
		if (parent.loaded==1) parent.eventx=x
	}
}

//these are for the old notice box
var fadeStep = 1;
var fadeSteps = 30;

function fadeOut()
{
	if (fadeStep > fadeSteps)
	{
		document.getElementById('notice').style.visibility='hidden'
		setOpacity('notice', 1)
		return
	}	
	setOpacity('notice', 1-(fadeStep/fadeSteps))
	fadeStep++;
	setTimeout("fadeOut()",5)
}

function fadeIn()
{
	if (fadeStep > fadeSteps)
	{
		setOpacity('notice', 1)
		fadeStep = 1;
		fadeSteps = 30;
		//if (parent.eventx>0) setTimeout("fadeOut()",5000)
		//setTimeout("document.getElementById('notice').style.visibility='hidden'",5000)
		return
	}	
	setOpacity('notice', (fadeStep/fadeSteps))
	fadeStep++;
	setTimeout("fadeIn()",5)
}

function setOpacity(el, opacity)
{
	el = document.getElementById(el)    
	if(el.style.opacity != undefined)
	{
        el.style.opacity = opacity;
    }
	else if( el.style.MozOpacity != undefined)
	{
        el.style.MozOpacity = opacity;
    }
	else if ( el.style.filter != undefined)
	{
        el.style.filter="alpha(opacity="+Math.round(opacity * 100)+")";
    }
}
//end old notice box

function adjustSelector()
{
	obj=document.getElementById('selector')
	obj.style.top='183px'
}

parent.dtext='$dtext'
parent.dtext = parent.dtext.replace(/~`/g,"\r")
parent.values='$values'

mdiv= new Array();
mdivtimer= new Array();
//parent.mdiv = null
//parent.mdivtimer = null

function hidediv(mname)
{
	return
	mdivtimer[mname]=setTimeout("document.getElementById('"+mname+"').style.visibility='hidden'",3000)
}
function showdiv(mname)
{
	return
	if (mdivtimer[mname])
	clearTimeout(mdivtimer[mname])
}

function hide_div(mname)
{
els=document.getElementById(mname+'-search')
els.style.visibility='hidden'
//el=document.getElementById('size_lb')
//if (el)
	//el.style.visibility='visible'
for (j=0; j < parent.sorted.length; j++)
{
	obj=document.getElementById('size_lb'+parent.sorted[j])
	if (obj) obj.style.visibility='visible'
}

}

function toggleevery_fun()
{
	obj=document.getElementById('everysize').src
	if (!obj) return
	if (obj.indexOf('on.gif') == -1)
	{
		on = 'on'
		title='Click to only use the GO button to search'
		document.selectorform.action='../../cgi-bin/socks-selector.pl?is=on'
	}
	else
	{
		on = 'off'
		title='Click to immediately search after each selection'
		document.selectorform.action='../../cgi-bin/socks-selector.pl'
	}
	document.selectorform.every.value=on
	setCookie('myevery',on,7)
	
	obj=document.getElementsByName('toggleevery')
	for (j=0;j<obj.length;j++)
	{
		obj[j].src='../../assets/images/gearsmall'+on+'.gif'
		obj[j].title= title
	}
}

function togglelock(mname)
{
	img = document.images[mname]
	mvalue=mname
	if (img.src.indexOf('1.gif') == -1)
	{
		img.src='../../assets/images/lock1.gif'
	}
	else
	{
		img.src='../../assets/images/lock0.gif'
		mvalue=''
	}
	for(var i=1;i < document.forms['selectorform'].length;i++)
	{
		mobject=document.forms['selectorform'].elements[i]
		if (mobject.name=='required' && mobject.title == mname)
		{
			mobject.value=mvalue
		}
	}
}

function reset_selector(mthis,mname,mtype)
{
	for(var i=1;i < mthis.form.length;i++)
	{
		mobject=mthis.form.elements[i]
		if (mobject.name==mname)
		{
			if (mobject.title=='')
			{
				continue
			}	
			if (mtype=='checkbox') mobject.checked=false
		}	
	}
}

function sizeselected()
{
	//parent.tempX=185
	//parent.tempY=190

	parent.tempY=gettop(document.selectorform.size)-document.documentElement.scrollTop
	parent.tempX=getleft(document.selectorform.size)+50-document.documentElement.scrollLeft

	if (document.getElementById('alertboxdiv'))
		hidealertbox()
	if (document.selectorform.osize.value==0)
		document.selectorform.submit()
}

function changeclose(obj)
{
	if (!sizealert()) return

	o=document.selectorform.size
	if (obj.src.indexOf('0') == -1)
	{
		document.location.href='../../cgi-bin/socks-selector.pl?close=1&size='+o[o.selectedIndex].value
		setCookie('close','1',7)
	}
	else
	{
		document.location.href='../../cgi-bin/socks-selector.pl?close=no&size='+o[o.selectedIndex].value
		setCookie('close','no',7)
	}
	//here nov
}

function socksize(obj,id)
{
	document.selectorform.size.selectedIndex=obj.selectedIndex
	if (obj[obj.selectedIndex].id=='no')
	{
		if (!confirm('This sock model is not available in this shoe size.\n\nClick "OK" to see other socks that match your search criteria, or\nClick "Cancel" to select another size.'))
		return
	}
	if (document.selectorform.action.indexOf('?')==-1)
		t='?'
	else
		t='&'
	document.selectorform.action=document.selectorform.action + t + 'partID='+id
	if (obj[obj.selectedIndex].title)
	{
		//alert(obj[obj.selectedIndex].title)
		document.selectorform.association.value=obj[obj.selectedIndex].title
		//document.selectorform.action = document.selectorform.action + '&association='+obj[obj.selectedIndex].title
		//obj.form.partID.value=obj[obj.selectedIndex].title
		//obj.form.submit()
		//setCookie('size',obj[obj.selectedIndex].value,7)
		//return
	}
	document.selectorform.submit()
}

function paramchange(mchecked)
{
	//if (mchecked && document.selectorform.every.value=='on')
	if (document.selectorform.every.value=='on')
		search()
		//document.selectorform.submit();
}

function update_selector(mthis,mname,mtype)
{
//update_checkboxs(mthis,mname,mtype)
el=document.getElementById(mname+'-selector')
if (!el) return
pname=mname.replace(/^./,function($1) { return $1.toUpperCase(); });
var mtext='Choose <a href="javascript:select(\''+mname+'\')" class=selectorlink>'+pname+'</a><br><span class=selectormatch>'
count=0
for(var i=1;i < mthis.form.length;i++)
{
	mobject=mthis.form.elements[i]
	
	if (mobject.name==mname)
	{
		if (mobject.title=='' || mobject.title=='Matches any of the following')
		{
			mall=mobject
			if (mtype=='checkbox' && mthis)
				mall.checked=true
		}	
		if (mobject.checked)
		{
			if (mobject.title=='' || mobject.title=='Matches any of the following')
			{
				continue
			}	
			
			//if (mtype=='radio' && mthis.value != mobject.value)
			//{
				//mobject.checked=false
				//continue
			//}
			
			if (count ==3)
			{
				count=0
				//mtext+='<br>'
			}
			//mtext+= mobject.title+', <img src=../shim.gif width=8 height=1 border=0>'
			mtext+= mobject.title+',&nbsp; '
			mall.checked=false
			//count++
		}
	}	
}
j=mtext.lastIndexOf(',')
if (j>-1)
	el.innerHTML = mtext.substring(0,j)+'</span>'
else
	el.innerHTML = mtext+'</span>'
//alert(el.innerHTML)
//if (wrapperheight) alert('yes')
//alert(wrapperheight)
if (window.wrapperheight) wrapperheight()
}

function elementfocus()
{
	//if (document.selectorform.every.value=='on')
	//{
		if (!sizealert())
		document.selectorform.size.focus()
	//}
}

allrows = new Array('keyword', 'manufacturer', 'brand', 'application', 'width', 'height', 'color', 'construction', 'fiber', 'size', 'help')
parent.sorted = new Array();

function select(mname)
{
if (document.selectorform.every.value=='on')
{
	if (!sizealert()) return
}

for(var i=0;i < allrows.length;i++)
{
	els=document.getElementById(allrows[i]+'-search')
	if (els)
	els.style.visibility='hidden'
}

el=document.getElementById(mname+'-selector')
els=document.getElementById(mname+'-search')
//els.style.top=gettop(el)-5+'px'
//els.style.left=getleft(el)+el.offsetWidth+6+'px'
els.style.top=gettop(el)-183-10+'px'
// width:177px;

//els.style.left=177+6+6+10+'px'
//els.style.left=getleft(el)+el.offsetWidth+24+'px'
els.style.left=177+2+'px'
els.style.visibility='visible'

//el=document.getElementById('size_lb')
//if (el)
	//el.style.visibility='hidden'
for (j=0; j < parent.sorted.length; j++)
{
	obj=document.getElementById('size_lb'+parent.sorted[j])
	if (obj) obj.style.visibility='hidden'
}
//alert(els.innerHTML)
}

function showhelp()
{
for(var i=0;i < allrows.length;i++)
{
	els=document.getElementById(allrows[i]+'-search')
	if (els)
	els.style.visibility='hidden'
}

el=document.getElementById('brand-selector')
els=document.getElementById('help-search')
//els.style.left=getleft(el)+el.offsetWidth+27+'px'
els.style.left=177+5+'px'
els.style.top=gettop(el)-183-10+'px'

els.style.top=gettop(el)-183-103+'px'
writehelp()

els.style.visibility='visible'

for (j=0; j < parent.sorted.length; j++)
{
	obj=document.getElementById('size_lb'+parent.sorted[j])
	if (obj) obj.style.visibility='hidden'
}
}

function writehelp()
{
	els=document.getElementById('help-search')
	//els.style.height='443px'
	els.style.height='413px'
	//els.style.width='621px'
	els.style.width='591px'
	els.style.backgroundColor="#eeeeee"
	t=''
t+='	<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="591"'
t+='	HEIGHT="413"'
t+='	CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">'
	
t+='	<PARAM NAME=movie VALUE="../../assets/selector-help.swf">'
t+='	<PARAM NAME=play VALUE=true>'
t+='	<PARAM NAME=loop VALUE=false>'
t+='	<PARAM NAME=quality VALUE=low>'
t+='	<EMBED SRC="../../assets/selector-help.swf" WIDTH=591 HEIGHT=413 quality=low'
t+='	loop=false TYPE="application/x-shockwave-flash"'
t+='	PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
	
t+='	</EMBED>'
	
	els.innerHTML = t;
}

function helpclose()
{
els=document.getElementById('help-search')
if (els)
	els.style.visibility='hidden'
}

function sizealert()
{

if (document.selectorform.size.selectedIndex==0)
{
	if (document.getElementById('alertboxdiv'))
		showalertbox('First, select<br>your shoe size')
	else
		alert('First, select your shoe size')
	//document.selectorform.size.focus()
	return false
}
else
return true

}

function tsearch()
{
	return search(0)
}

function search(size)
{
	//alert(document.selector.size.selectedIndex)
	document.selectorform.fewer.value='1 4'
	//if (!size && document.selectorform.size.selectedIndex==0)
	if (!size && !sizealert())
	{
		//if (document.getElementById('alertboxdiv'))
			//showalertbox('First, select<br>your shoe size')
		//else
			//alert('First, select your shoe size')
		return false
	}
	//setcookie('size',document.selector.size[document.selector.size.selectedIndex].value)
	
	if (document.getElementById('alertboxdiv'))
	{
		showalertbox('Searching<br>Please Wait...')
	}	
		//setTimeout("showalertbox('Searching<br>Please Wait...','up')",1)

	obj=document.getElementById('notice')
	if (0&&obj)
	{
		obj.innerHTML = 'Searching<br>Please Wait...'
		obj.style.visibility='visible'
		setOpacity('notice', .4)
		fadeStep = 5;
		fadeSteps = 10;
		setTimeout("fadeIn()",1)
		//setTimeout("document.getElementById('notice').visibility='hidden'",300)
	}
	setTimeout("document.selectorform.submit()",20)
	return true
}

function getTagsByName(root,tagName)
{
	/* lowercase for xhtml proper */
	var elems = root.getElementsByTagName(tagName.toLowerCase());
	if(elems.length==0)
	{
		/* Uppercase when html4 */
		elems = root.getElementsByTagName(tagName.toUpperCase());
    }
	return elems;
}

function thisMovie(movieName) { //not using this function does not always find foxpro
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	obj = (isIE) ? window[movieName] : document[movieName];
	if (obj.length)
		return obj[1]
	else
		return obj
}

function getFlashMovieObject(movieName)
{
  if (document.getElementsByName)
  {
	  return document.getElementsByName(movieName)[document.getElementsByName(movieName).length-1]
  }
  if (document.getElementById)
  {
	  return document.getElementById(movieName);
  }
  // this is the old way
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function makeCall(str,way) {
	if (flashAlertBox==0)
	flashAlertBox = getFlashMovieObject('alertbox')
	//alert(thisMovie('alertbox').length)
	//obj=thisMovie('alertbox')
	//alert(thisMovie('alertbox').id)
	//obj=document.getElementById('alertbox')
	//alert(obj.width)
	//flashAlertBox.asFunc(str,way)
	flashAlertBox.asFunc(str,parent.abD)
	//alert(thisMovie("alertbox").width)
	//thisMovie("alertbox").asFunc(str);
}

// This function "jsFunc" will be called from ActionScript
function jsFunc(str) {
	document.forms["inForm"].inField.value = "ActionScript: " + str;
}

function clickpos(event)
{
	parent.tempY=event.clientY
	parent.tempX=event.clientX
	//showalertbox('Click','up')
	return
	alert('Y= '+event.clientY+'  tempY= '+parent.tempY + ' scrollTop= ' + document.body.scrollTop)
	mtext=''
	//alert(document.body.offsetHeight)
	for (j in document.body)
	{
		//if (j.match(/top|parent/i))
			//alert(j+'= '+document.body[j])
		mtext+=j+' '
		//alert(j)
	}
	alert(mtext)
	//document.body
}

function showalertbox(mtext)
{
	//clearTimeout(parent.abT)
	parent.eventx=-1
	parent.abR=1
	//alert(parent.abT)
	clearTimeout(parent.abT)
	//alert(parent.abT)
	//window.status='cleared by showalertbox'
	//parent.abT=null
	//alert(parent.abT)
	
	//have this on all the time
	//if (!document.all) document.captureEvents(Event.MOUSEMOVE)
	//document.onmousemove = getMouseXY;
	obj=document.getElementById('alertboxdiv')
	if (obj && parent.loaded==1)
	{
		if (parent.tempY < 110)
		{
			parent.abD='down'
			obj.style.top=(parent.tempY+document.documentElement.scrollTop)+'px'
			obj.style.left=(parent.tempX+document.documentElement.scrollLeft+5)+'px'
		}
		else
		{
			//parent.abD='up'
			//parent.abY=event.clientY+document.body.scrollTop-125+12
			//parent.abX=event.clientX+document.body.scrollLeft-5
			parent.abD='up'
			obj.style.top=(parent.tempY+document.documentElement.scrollTop-125+12)+'px'
			obj.style.left=(parent.tempX+document.documentElement.scrollLeft-5)+'px'
		}
		//obj.style.left=parent.abX+'px'
		//obj.style.top=parent.abY+'px'
	}
	else
	{
		setTimeout("showalertbox('"+mtext+"')",100)
		//window.status='wait...'
		return
	}	
	//obj.style.zIndex='6'
	obj.style.visibility='visible'
//		alert('showalertbox')
	//setTimeout("makeCall(mtext)",0)
	//makeCall('')
	makeCall(mtext,parent.abD)
	//if (flashAlertBox==0)
		//getFlashMovieObject('alertbox').Play()
	//else
		//flashAlertBox.Play()
	//thisMovie('alertbox').Play()
	//alert('end of showalertbox')
}

function hidealertbox()
{
	//makeCall('hello there')
	e = document.getElementById('alertboxdiv')
	if (e)
	{
		clearTimeout(parent.abT)
		parent.abR=0
		makeCall('','up')
		e.style.visibility='hidden'
	}
	//setTimeout("showalertbox('me again')",2000)
}

function alertnotehide()
{
	e=document.getElementById('alertnote')
	if (e) e.style.visibility='hidden'	
}

function checkquantity(id,type)
{
	text=''
	//alert(document.socklist.elements[0].value)
	//alert(document.socklist.elements[0].name)
	//alert(document.socklist.length)
	//id=document.socklist.purID.value
	qt=0
	//alert(document.forms[1].name)
	for (j=0;j<document.forms[1].length;j++)
	{
		if (document.forms[1][j].name.match('sk'+id+'-'))
			qt += document.forms[1][j].value 
		//text+= document.socklist[j].name+'='+document.socklist[j].value+' '
	}
	//alert(id+type+qt)
	if (type=='btn')
	{
		if (qt==0)
			document.getElementById('ctext'+id).src='../../assets/images/cartadd-craig3-0.gif'
		else
			document.getElementById('ctext'+id).src='../../assets/images/cartadd-craig3-1.gif'
	}
	else if (type=='form')
	{
		if (qt==0)
		{
			setTimeout("showalertbox('Select your color<br>then the quantity.')",20)
			//alert('Oops, enter a quantity for your prefered color choice.')
			return false
		}
	}
	//for (j in document.socklist.elements)
	//{
	//	text += j+' '
	//}
	//alert(text)
//btn
}
