function setbackpagetrap(sba,sbb,sbc,siid){
	if(siid){
		lowerframelocation = sba + '|' + sbb + '|' + sbc + '|' + siid + '|';
	} else {
		lowerframelocation = sba + '|' + sbb + '|' + sbc + '|';
	}
	//alert(lowerframelocation);
	gsetCookie("gcurrentview", lowerframelocation, '', '/', gGetCookieDom());
	parent.hidden.location = '/hidden.shtml?' + lowerframelocation;
}

var bad;
function testAll(){
	noSearch();
}

function noSearch(){
	bad=0;
	mt=document.isn.Keywords.value;
	if (mt.length<1){
		alert("You must first enter search criteria in the field next to the go button.");
		bad++;
		return false;
	} else {
		submitCheck();
	}
	return true;
}

function submitCheck(){
	if (bad==0){
		document.isn.submit();
	}
}

function writeqt(qid){
var temph= + qid.substring(0,2) + '/' + qid.substring(0,5) + '/' + qid;
thehtml += '<EMBED SRC="http://tools.cgibackgrounds.com/qtvideo/' + temph + '.MOV" WIDTH=420 HEIGHT=280></EMBED>';
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


var agt=navigator.userAgent
var yourOS="PC"
if (agt.indexOf("Mac")!=-1)
   {yourOS='Mac'}
var yourBrowse="IE"
if (navigator.appName == 'Netscape')
   {yourBrowse="NS"}
if (navigator.appVersion.substr(22,1) >= "5")
{ver5="Yes"}

if((yourOS=="Mac" && yourBrowse=="NS")||(yourOS=="Mac" && yourBrowse=="IE" && ver5 != "Yes")){
        document.write('<LINK rel="stylesheet" href="/css/main.css" type="text/css">')
}
else{
        document.write('<LINK rel="stylesheet" href="/css/main.css" type="text/css">')
}

function toplightboxrefresh() {
	if (parent == top){
		parent.frames[1].location = "/bin/Cklb?ref=/bin/Search?n~1^fmt~table";
	} else {
		 parent.location = "/bin/Cklb?ref=/bin/Search?n~1^fmt~table";
	}
}

function topcartrefresh() {
	if (parent == top){
		parent.frames[1].location = "/bin/Cklb?ref=/bin/Cart?op~view";
	} else {
		 parent.location = "/bin/Cklb?ref=/bin/Cart?op~view";
	}
}

function topsearchrefresh() {
	if (parent == top){
		parent.frames[1].location = "/bin/Cklb?ref=/user/search.shtml";
	} else { 
		parent.location = "/bin/Cklb?ref=/user/search.shtml";
	}
}

function topsearchrefreshpower() {
	if (parent == top){
		parent.frames[1].location = "/bin/Cklb?ref=/user/search_advanced.shtml";
	} else { 
		parent.location = "/bin/Cklb?ref=/user/search_advanced.shtml";
	}
}

function topsearchconcept() {
	if (parent == top){
		parent.frames[1].location = "/bin/Cklb?ref=/search_concept.shtml";
	} else { 
		parent.location = "/bin/Cklb?ref=/search_concept.shtml";
	}
}

function tload(dref)
{
	if(parent.thetop.href != dref){
		parent.thetop.location=dref;
	}
}

function siderefresh()
{
parent.left.location.replace('/bin/Search?n=1');

}

function csiderefresh(id)
{
	xcurrentdate = new Date();
  xcore = xcurrentdate.getSeconds();
  if (id){
  parent.left.location.replace('/bin/Cart?op=view&lc='+ id + '&random=' + xcore);
  }
  else {
  parent.left.location.replace('/bin/Cart?op=view' + '&random=' + xcore);
  }
}

function lccsiderefresh(id){parent.left.location.replace('/bin/Cart?op=view&lc=1');}

function cceditWindow(){  ccedit_window = window.open("https://argus.auroraquanta.com/bin/Profile?cc=1","ccedit","width=500,height=320,status=1");}

function addlb(id) {
		if (parent.lb) {
			var theurl= '/bin/Add_to_lightbox?id=' + id + '&add=1&ii=1';
			parent.lb.location=theurl;
		} else {
			var theurl= '/bin/Cklb?atlb=' + id;
			self.location=theurl;
		}
}
function exaddlb(id) {
		if (parent.lb) {
			var theurl= '/bin/ExLbAdd?id=' + id;
			parent.lb.location=theurl;
		} else {
			var theurl= '/bin/Cklb?atlb=' + id;
			self.location=theurl;
		}
}
function addcart2(id) {
			var theurl= '/contact_price.shtml?' + id;
			self.location=theurl;
}
function addcart2_old(id) {
		if (parent.lb) {	
			parent.lb.location.replace('/bin/Cart?op=add&id=' + id + '&fmt=index');
			parent.com.location.replace('/user/cart_menu.shtml');

		} else {
			var theurl= '/bin/Cklb?atct=' + id;
			self.location=theurl;
		}
}

function license(id) {
                if (top.frames[1]) {
                        top.frames[1].location.replace('/bin/Cklb?atct=' + id + '&fmt=index&pi=1');

                }
}

//////////////////////////cookie functions/////////////////////

function gsetCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function ggetCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds

function gdeleteCookie(name, path, domain) {
  if (ggetCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function gfixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function gGetQV(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("="); 
    if (pair[0] == variable) {    
      return pair[1];         
    }                
  }  
  return false;
}
 
function checkRef() {
 var portal = getQV('portal');
 if (portal){
 var portalcookie = getCookie('portal');
  if (portalcookie != portal){
    setCookie('portal',portal,'','/');
  }
 } 
}

function gGetCookieDom(){
var thisdomain = document.domain;
var domainparts = thisdomain.split(".");
var end = domainparts.length - 1;
var start = domainparts.length - 2;
var domainend = domainparts[end];
var domainstart = domainparts[start];
var setdom = "." + domainstart + "." + domainend;
return setdom;
}

function gSetBackpage(pa) {
	var thispage = location.href;
	// ideally add the snum variable here to the url(if it exists as LB won't exist)
	if(pa){
		gsetCookie('backpage', pa, '', '/', gGetCookieDom());
	} else {
		gsetCookie('backpage', thispage, '', '/', gGetCookieDom());
	}
}



/////////admin functions //////////////////////////


function editReject(edit,id) {
var edname = "Advertising";
if (edit == 'ne'){ edname = "All Sites"; conf = 'Remove ' + id + ' from ' + edname + '? This change is permanent.'; }
if (edit == 'ed'){ edname = "Editorial"; }
var conf = 'Remove ' + id + ' from ' + edname + '?';


if (edit == 'ne'){ conf = 'Remove ' + id + ' from ' + edname + '? This change is permanent.'; }
	if (confirm(conf)){
	var loadurl = '/bin/ShareControl?rem=' + id + '&edit=' + edit;
	window.open(loadurl,'Win','resizable=no,scrollbars=no,menubar=no,status=no,width=200,height=100');
	}
}


function displayWindow(url, width, height) {
if (navigator.appName == 'Netscape'){
height = parseInt(height) + 16;
}
var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=no' );
Win.focus();
}

function displayWindow2(url, width, height) {        
var Win2 = window.open(url,"displayWindow2",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no,status=no' );
Win2.focus();
}



///////////////js functions for search //////////////////////////
function addlb_bkjs(id) {
                if (parent.lb) {
                        var theurl= '/bin/ExLbAdd?id=' + id;
                        parent.lb.location=theurl;
                } else {
                        //remember which sub-page you're on for the redirect.
                        gSetBackpage();
                        if(firstpictureonpage){
                                gsetCookie("gwhichstartpage",firstpictureonpage, '', '/', gGetCookieDom());
                        }
                        var theurl= '/bin/Cklb?supst=bkjs&atlb=' + id;
                        self.location=theurl;
                }
}

function optimize() {
        var searchthreshhold = 60;
        ophtml='';
        if (optimizemenu == 1){
			if (searchthreshhold < total){
							ophtml+='<TABLE cellspacing=0 cellpadding=1 border=0>';
							ophtml+='<FORM name="optimizer" action="#">';
							ophtml+='<TR><TD>';
							ophtml+='<SELECT NAME="narrow" ONCHANGE="javascript:narrowit(this.form.narrow.options[this.form.narrow.selectedIndex].value);" class="smallmenu">';
							ophtml+='<OPTION VALUE="#">Narrow your search results';
							ophtml+='<OPTION VALUE="colorgray">Remove black and white images';
							ophtml+='<OPTION VALUE="colorrgb">Remove color images';
							ophtml+='<OPTION VALUE="imagehasrestrictions">Remove restricted images';
							ophtml+='<OPTION VALUE="orientationvertical">Remove verticals';
							ophtml+='<OPTION VALUE="(orientationhorizontal+OR+orientationpanoramic)">Remove horizontals';
	
							if(spec_idx != 'ed'){
									ophtml+='<OPTION VALUE="lowres">Remove small scans (< 30 Mb)';
							}
							ophtml+='<OPTION VALUE="agefiveyears">Only show recent images (<5 yrs)';
							ophtml+='<OPTION VALUE="agetenyears">Remove very old images (>10 yrs)';
							ophtml+='</SELECT></td></tr></form></table>';
							ophtml+='';
	
			} else {
	
							ophtml+='';
							ophtml+='<FORM name="optimizer" action="#"><SELECT NAME="narrow" ONCHANGE="javascript:expandit(this.form.narrow.options[this.form.narrow.selectedIndex].value);" class="smallmenu">';
							ophtml+='<OPTION VALUE="#">Expand your search results';
							ophtml+='<OPTION VALUE="deep">Have IPN members perform a deep search';
							if(spec_idx != 'ne'){
									ophtml+='<OPTION VALUE="expand">Show me the broadest set of images';
							}
							ophtml+='</SELECT></form>';
							ophtml+='';
	
			}
        }
        return(ophtml);
}


function narrowit(url) {
        if(url == "#"){
                alert('please select an item from the list');
        } else {
                var url1 = 'http://www.ipnstock.com/SwishSearch?spec_idx=<!spec_idx>&Keywords=<!ukeys>+NOT+' + url;
                self.location=url1;
        }
}

function expandit(url) {
        if(url == "#"){
                alert('please select an item from the list');
        } else if (url == "deep" ) {
                var url1 = 'http://www.ipnstock.com/deepsearch.shtml';
                self.location=url1;
        } else {
                var url1 = 'http://www.ipnstock.com/SwishSearch?synsearch=true&spec_idx=ne&Keywords=<!ukeys>';
                self.location=url1;
        }
}

