//init globals...
MACIE5 = false;
var firstpictureonpage = ( firstpictureonpage ? firstpictureonpage : 0 );
if (typeof(pshown) == 'undefined')
	pshown = 0;
var snum = ( snum ? snum : 0 );
var tset = ( tset ? tset : 'on' );
var showstartnumber_trap = 0;
var currentlbname; 
var currentlblist;
var feat_requestview;
var typeoflbaction;
var sphotog;
var pre_q_args;
var winW;
var baseurl;
var carnit = 1; //flag to do once on load for cartview
//
gloCrop = '';
var emaillbaddhtml='';
var emaillburladd='';
//
var currentLbdivMode; 	//when flipping between lb and cart, set this	
			//to say, "lightbox" or "cart" so that global refreshes in
			//subs like checkpageresize will know whether to draw
			//lb or cart or whatever else... 
document.currentLayer1Mode = currentLayer1Mode = (document.currentLayer1Mode ? currentLayer1Mode : 'searchresults');
//enlarge shouldn't travel
if(currentLayer1Mode == 'enlarge')
	document.currentLayer1Mode = currentLayer1Mode = 'searchresults';
									//same thing but for the status of what is in Layer1 values are 
									//"searchresults", "cartview", or "enlarge" defaults to 
									//searchresults, as that is default page action 
var cartview = (cartview ? cartview : ''); //trip this flag to display cart in main window and draw cart in lightbox
var enlargeview = (enlargeview ? enlargeview : '');
currMousedOverObj = null;
lbtosave = 0;
suspendpreviews=0;
scr='';

var d = new Date();
var currentYear = d.getFullYear();

//-------------------------------
//begin page check for UA type...

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";}

var now = new Date();
gfixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var bad;

lbexpansionspace=0;
var pmousedelta=[20,-30]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
        browser = "Konqueror";
        OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari";
else if (checkIt('omniweb')) browser = "OmniWeb";
else if (checkIt('firefox')) browser = "Firefox";
else if (checkIt('opera')) browser = "Opera";
else if (checkIt('msie')) browser = "Internet Explorer";
else if (!checkIt('compatible'))
{
        browser = "Netscape Navigator";
        version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

var getpost = 'POST'; //had reports of IE caching ajax calls with a GET and firefox not able to complete fake POSTS, so..
if (browser == 'Firefox') // && parseInt(version) < 2)
	getpost = 'GET';
var pngsupport = 1;
if (browser == 'Internet Explorer' && parseInt(version) < 7)
	pngsupport = 0;

if (!OS)
{
        if (checkIt('linux')) OS = "Linux";
        else if (checkIt('x11')) OS = "Unix";
        else if (checkIt('mac')) OS = "Mac";
        else if (checkIt('win')) OS = "Windows";
        else OS = "an unknown operating system";
};

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

if (yourBrowse == "IE" || browser == "Internet Explorer")
{
	document.write('<LINK rel="stylesheet" href="/css/fixed4ie.css" type="text/css">');
};


//checking for login status
gsession = ggetCookie("gmpsess");
gcartimages = ggetCookie("gcartimages");
gusername = ggetCookie("username");
if(!gusername || gusername == '')
	gusername = ggetCookie("gwhichuser");

//
//	NON SEARCH PAGES 
//

if (typeof(scriptname) !="undefined"){
	//establish some init properties

	viewmode = ggetCookie('gviewmode');
	pixperpage=12;

	//initialize some page variables
	grange="legal";
	winW = 700;
	winH = 460;
	area = 12;
	resized=0;
	c=-1;
	fmstartnumber = 0;

	overflowtype = 'hidden';
	if ((agt.indexOf("Mac")!=-1) && (navigator.appName.indexOf("Microsoft")!=-1)){ 
		overflowtype = 'hidden';
	MACIE5=true;
	} else {
		MACIE5=false;
	}

	//optional configurations for this page varies from site to site
	optimizemenu = 0;
	showphotographer = 1;
	showrelease = 1;
	showfilesize = 1;
	showcaptionview = 1;

	nextlink=String(scriptname + "?&color=" + color + "&orient=" + orient + "&spec_idx=" + spec_idx + "&sort=" + sort + "&date=" + date + "&searchinclude=" + searchinclude) ;

	if(typeof(q_args) != 'undefined' && q_args.match(/lb_view=1/)) //if viewing lightbox, nextlink is different
	{
		nextlink += '&n=1&lb_view=1';
	}
	else if(typeof(q_args) != 'undefined' && q_args.match(/rid=/)) //if viewing requests, nextlink is also different
	{
		var rid = q_args.match(/rid=([^\&]+)/);
		if(rid[1])
			nextlink += '&n=1&rid='+rid[1];
	}
	else if(typeof(q_args) != 'undefined' && q_args.match(/fn=/))
	{
		var fid = q_args.match(/fn=([^\&]+)/);
		if(fid[1])
                        nextlink += '&n=1&fn='+fid[1];
	}

	narrowurl = nextlink + "&snum=0";

	if(typeof(pre_q_args) != 'undefined') //append VMO= info for nextlinks on lightboxes
	{
		var vmo_arg = pre_q_args.match(/vmo=([^&]+)/);
		if (vmo_arg && vmo_arg[1])
			nextlink += '&vmo='+escape(vmo_arg[1]);
	}

	nextlink +=  "&method=" + method  + "&q_id=" + q_id + "&" + ucats;

	if (enlargeview)
		setTimeout("enlarge2('"+enlargeview+"', 0)", 500);
};
if(typeof(gsession) != 'undefined' && gsession && typeof(tosave) != undefined){
	spring_lightbox_trap(); // check if there's a cookie hanging around to save
	if (cartview)
	{
		document.currentLbdivMode = 'cart';	
		document.currentLayer1Mode = 'cartview';
		currMousedOverObj = 'shop_cart';
		setTimeout("cart_build('changing')", 500);
	}
	
	if ( (typeof(pagetype) != 'undefined' && pagetype=='lb') || (typeof(pre_q_args) != 'undefined' && ( pre_q_args.match(/lb_view=1/) || pre_q_args.match(/fn=/) )) || (typeof(q_args) != 'undefined' && q_args.match(/vmo=/)) )
	{
		pagetype='lb';
		gsetCookie('gwhichstartpage', '', '', '/', gGetCookieDom());
	}
	
	setInterval("polllb()",3000);
}
else if (cartview)
{
	top.location="/user/login.shtml?/SwishSearch?cartview=1";
};

tempW =  winW;

if (feat_requestview)
{
	//alert('feat_requestview');
	document.thisIsFeatureView = true;
};

if (typeof(pagetype) != "undefined"){
	setTimeout("currentpage()", 1000); // kinda doesn't get called onload without being logged in, so do it once on-after load.
	setTimeout("checkpageresize()", 10000);
	//setInterval("checkpageresize()",10000);
	//set event handler also for more instant results
	window.onresize = checkpageresize;
};

//setTimeout("toplightboxrefresh()", 1000);
//******************************* SUBFUNCTIONS ****************************//

function set_lightbox_trap (usethislb) {
	var traplb = (typeof(currentlbstash) != 'undefined' ? currentlbstash.join('|') : 
			( usethislb ? usethislb.join('|') : 1 ) );

	if (traplb == 1 || typeof(currentlbname) == 'undefined') //not enough info to trap
		return;

	var date = new Date; // Generic JS date object
	var unixtime_ms = date.getTime(); // Returns milliseconds since the epoch
	var unixtime = parseInt(unixtime_ms / 1000);

	traplb = unixtime+','+currentlbname+','+traplb;

        date.setTime(date.getTime()+(60*60*1000));
	gsetCookie('lightbox_trap',traplb,date,'/',gGetCookieDom());
};

function spring_lightbox_trap (usethisstring) {
	var lbstring = ( usethisstring ? usethisstring : ggetCookie('lightbox_trap') );

	if (! lbstring)
		return;

	var mainparts = lbstring.split(','); //should contain 0 timestamp 1 lbname 2 lbidstring sep by |

	if (typeof(mainparts) != 'object')//can't parse
		return; 	

	//do date checking
	var date = new Date; // Generic JS date object
	var unixtime_ms = date.getTime(); // Returns milliseconds since the epoch
	var timenow = parseInt(unixtime_ms / 1000);

// 	alert(parseInt(mainparts[0])+' vs '+timenow);	

	if (	(timenow - parseInt(mainparts[0])) < 2	) //did this happen less than a minute ago?
	{
		//okay
		currentlbname = mainparts[1];
		currentlbstash = mainparts[2].split('|');
		polllb(1); //force save now.
// 		alert('force save: '+(timenow - parseInt(mainparts[0])));
	}
	else //too old
	{
		gsetCookie('lightbox_trap',"", "", "/", gGetCookieDom());
// 		alert('too old, clearit');
	}
	return;
};

function maxscreen(){
        window.moveTo(0,0);
        window.resizeTo(screen.availWidth,screen.availHeight);
	if (self.location)
		self.location.href=self.location.href;
};

function price_image(pid,ttype){

	//alert('PID: '+pid+' TYPE: '+type);

	if (! pid || ! pid.match(/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/))  //did this longhand (instead of w/ curly brackets) b/c
		return false;								   //it screws up the compressors otherwise

	//simplemessage('Loading rate calculator <blink>.</blink>','','LB');
	//get image info to retrieve pricing tier
	var url = '/AjaxHandlers/ImageInfo/'+ pid + '.json';
	ajax_JSON( url, 'POST', null ); 

	price_image_act(pid, 0, 0);
	return false;
};

function price_image_act(pid, tryCtr, force){
	if ( document.ajaxLoaded || force )
	{
		var supst = ( document.JSONobj.getImgDat('tier') || '' );
		//clear status
		/*if(typeof(currentlbstash) != 'undefined')
			lightbox_build(currentlbstash);
		else
			simplemessage('', '', 'LB');*/

		launchwin('/bin/Rates?ln='+pid+'&calc_only=1&supst='+supst);	
	}
	else if ( tryCtr < 5 ) 
	{
		tryCtr++;
		setTimeout("price_image_act('"+pid+"','"+tryCtr+"', 0 )", 500);
	}
	else // nothing loaded, pop the page w/ missing data..
	{
		tryCtr++;
		price_image_act(pid,tryCtr,1);
	}
	return;
};

function center_panel(x,y,thehtml,tp){ // sub to center a panel and write the passed html with optional flag for search expansion
        	if ((winW - x) < 0){
        	        panelx = 0;
        	} else {
        	        panelx = parseInt((winW - x)/2); // center it
        	}
        	if ((winH - y) < 0){
        	        panely = 41;
        	} else {
        	        panely = parseInt((winH - y)/2); //center it
        	}
		if(tp){
			var tx = Position.cumulativeOffset($('scontainer'));
			var ty = Position.cumulativeOffset($('row2'));
			panelx = tx[0];
			panely = ty[1];
		}
		$('displaypanellayer').style.top = panely + 'px';
		$('displaypanellayer').style.left = panelx + 'px';
		$('displaypanellayer').style.width =x + 'px';
		$('displaypanellayer').style.height =y + 'px';
		coverlayerobj().visibility="visible";
		new Effect.Opacity('coverlayer',{ duration: .3, transition: Effect.Transitions.slowstop, from: 0, to: 0.7 });
	        $('displaypanellayer').innerHTML = thehtml;
	        setTimeout("displaypanelshow();",320);
};

function lightbox_new(){ // show the panel to create a new lightbox
		var thehtml= '<div id="lightboxPopUp">';
		thehtml += '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="290" height="200"><TR>';
		thehtml +='<td class="dark1" valign=bottom width="100%"><DIV class="barheader">&nbsp;<FONT class="bartitle">Make a new lightbox</font></DIV></td></tr>';
		thehtml +='<tr><TD ALIGN="left" VALIGN="top" width="290" class="dark1"><DIV class="light1" style="padding: 15px;"><form action="javascript:nada();" method="get" name="send"><p>Enter a name for your new lightbox in the box below ';
		thehtml +='</p><p><INPUT type="text" name="lightbox_new_name" id="lightbox_new_name" size="15" class="emailbox" value="My new LB name" onfocus="javascript: if (this.value == \'My new LB name\'){ this.value=\'\';}">';
		thehtml +='<A href="javascript:lightbox_new_send();" class=lblink style="font-size: 10pt; font-weight:bold;">Create the Lightbox</A><BR><BR>';
		thehtml +='Note:  You must enter a unique name for your new lighbox.  It will only be viewable by you unless you use the "E-mail this lightbox" function to share it with someone.<BR><BR>';
		thehtml +='If you do not need a lightbox anymore click the link below.<br><br><A HREF="javascript:lightbox_email(\'close\');">[X] close window</A>';
		thehtml += '</div>';
		center_panel(290,200,thehtml);
};

function test_valid_name(v){ // validator for new lightbox names
	var wrong=0;
	for (i = 0; i < v.length; i++){
    		var c = v.charAt(i);
		if( (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == " ") || (c == "-") || (c == "_") || ((c >= "0") && (c <= "9")) )){
		} else {
			wrong=1;
		}
	}
	if(wrong==1){
		alert("Lightbox names may only contain letters, numbers, spaces, hyphens, and underscores.");
	        return false;
	} else {
		return true;
	}
};

function lightbox_new_send(){ // URL call to make the LB in the database 
//	alert ('lb new send!');
	if( $F('lightbox_new_name').length ==0 || $F('lightbox_new_name').length > 100){
		 alert('Lightbox names must be between 1 and 100 characters long.');
		$F('lightbox_new_name')='';
	} else {
		if(test_valid_name($F('lightbox_new_name'))){
			var theurl = '/bin/ExLbCreate?np=1&name=' + $F('lightbox_new_name');
			$('LBFrame').src=theurl;
			simplemessage('creating your lightbox ' + $F('lightbox_new_name') + ' <blink>.</blink>',0);
		} 
	}
};

function lightbox_email_send(){ // URL call to send lightbox by email
        var theurl='/bin/Mail';

        var prams = 'ot=2&dsm=1&to_email=' + $('to_email').value + '&mail_text=' + escape($('mail_text').value);
        if($('allow_hrdl') && $('allow_hrdl').checked == true){ prams += (typeof(emaillburladd) != 'undefined' ? emaillburladd : ''); };
        if($('notify').checked == true){ prams +='&notify=1'};
        if($('readonly').checked == true){ prams +='&readonly=1'};
	$('LBFrame').src = theurl+'?'+prams;

        simplemessage('Sending your lightbox ' + ' <blink>.</blink>',0);
};


function simplemessage(m,mode,trg){ // Shows transition messages to the LB frame or centered based on param input
	if(trg){
		var thehtml='<DIV class=light1 style="width:400px; text-align:left; padding:10px;"><FONT class="header">' + m +'</DIV>';
		$('LBdiv').innerHTML = thehtml;
	} else {

		if($('displaypanellayer').style.left=='0px'){
			$('displaypanellayer').style.left=parseInt(winW - 200)/2 + 'px';
		}
		if($('displaypanellayer').style.top=='0px'){
			$('displaypanellayer').style.top=parseInt(winH - 100)/2 + 'px';
		}
		if($('displaypanellayer').style.visibility=='hidden'){
			$('displaypanellayer').style.visibility='visible';
		}
		var thehtml='<DIV class=light1 style="width:290px; height:60px; text-align:center; padding:20px;"><FONT class="header">' + m +'</DIV>';
		$('displaypanellayer').innerHTML = thehtml;
	}
	if (!mode){setTimeout("hidedisplaypanel(1);",700);}
};

function lightbox_email(mode){ // control for lightbox email state messages and menu
	if(mode=='sent'){
		simplemessage('Lightbox Sent!' + '<blink>.</blink>');
	} else if(mode=='close'){
		hidedisplaypanel(1);
	} else {
		var thehtml='<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="390" height="280"><TR>';
		thehtml +='<td class="dark1" valign=bottom width="100%"><DIV class="barheader"><FONT class="bartitle">Email your lightbox to a friend</font></DIV></td></tr>';
		thehtml +='<tr><TD ALIGN="left" VALIGN="top" width="390" class="dark1"><DIV class="light1" style="padding: 15px;"><form action="javascript:nada();" method="get" name="send"><p><B>E-mail your lightbox ';
		thehtml += '"' + currentlbname + '"</B> to a friend or colleague.</p><p><B>1.</B> Send To:<CODE>*</CODE></b></font><br><input type="text" name="to_email" id="to_email" size="35" class="emailbox" value="friend@domain.com" onfocus="javascript: if (this.value == \'friend@domain.com\') {this.value=\'\';}"><BR>';
		thehtml +='<BR><B>2.</B> Message:<BR><TEXTAREA NAME="mail_text" ID="mail_text" ROWS="7" COLS="45"></TEXTAREA><BR><BR><B>3.</B> <input type="checkbox" id="readonly" name="readonly" value=1> Read only<BR><FONT CLASS="xsmall">check this box to prevent recipient from changing your lightbox.</FONT></p>';
		thehtml +='<B>4.</B> <input type="checkbox" name="notify" id="notify" value="1"><font class="small">Notify me when this lightbox is viewed</font><br>';
		thehtml +=emaillbaddhtml + '<br><p><A href="javascript:lightbox_email_send();" class=lblink style="font-size: 10pt;font-weight:bold;">Send the Lightbox</A>';
		thehtml +='<input type="hidden" name="ot" value="2"><input type="hidden" name="dsm" value="1"></center></form><br><br><p>If you have changed your mind, click the link below.<BR><BR> <A HREF="javascript:lightbox_email(\'close\');">[X] close window</A>.<BR>';
		thehtml +='</DIV></TD></TR></TABLE>';
		center_panel(390,280,thehtml);
	}
};

function cart_mod_act (tryCtr){ // just wrap calls to redraw cart once the response is there... useful for any asynch cart actions

	tryCtr++;
	if ( ! document.TEXTresp && tryCtr < 10)
	{
		setTimeout("cart_mod_act('"+tryCtr+"')", 500);
	} 
	else
	{
		hidedisplaypanel(1);
		cart_build();
		if (document.currentLayer1Mode == 'cartview') 	// if we're viewing expanded cart, and you modify the cart from the lower panel
			cart_display();			// then main layer should immed get redrawn to avoid confusion
	}
};

function cart_addto(id){
	if (gsession)//logged in user
	{
		document.TEXTresp = null;
		simplemessage('Adding image to Shopping Cart <blink>.</blink>','','LB');
		ajax_TEXT('/AjaxHandlers/CartAdd/' + id + '.txt', 'POST', null);
		cart_mod_act(-1);
	}
	else //not
	{
		window.location='/bin/Cklb?ref=/SwishSearch%3FKeywords%3D'+escape(ukeys)+'%26cartview%3D1&atct='+id;
	}
};

function cart_delete_image(id) {
	document.TEXTresp = null;
	simplemessage('Deleting image from Shopping Cart <blink>.</blink>','','LB');
	ajax_TEXT('/AjaxHandlers/CartDel/' + id + '.txt', 'POST', null);
	cart_mod_act(-1);
};

function lightbox_add2cart(){ 
	document.TEXTresp = null;
	simplemessage('Adding lightbox images to Shopping Cart <blink>.</blink>','','LB');
	ajax_TEXT('/AjaxHandlers/CartLbAdd/0000000000.txt', 'POST', null);
	cart_mod_act(-1);
};

function lightbox_delete(){ 
	simplemessage('Deleting your current lightbox ' + currentlbname,'','LB');
	var theurl='/bin/ExLbDelLb';
	$('LBFrame').src=theurl;

	if (currentlblist && ( currentlblist.indexOf(currentlbname) > -1 ))
	{
		currentlblist.splice(currentlblist.indexOf(currentlbname), 1);
		currentlbname = '';
		currentlbstash = currentlblist;
		gsetCookie(gusername+'lastlb',"", "", "/", gGetCookieDom());
		gsetCookie(gusername+'lb',"", "", "/", gGetCookieDom());
//username lastlb
//username lb
	}
};

function lightbox_rename(){

		var thehtml='<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="290"><TR>';
		thehtml +='<td class="dark1" valign=bottom width="100%"><DIV class="barheader">&nbsp;<FONT class="bartitle">Rename  lightbox</font></DIV></td></tr>';
		thehtml +='<tr><TD ALIGN="left" VALIGN="top" width="290" class="dark1"><DIV class="light1" style="padding: 15px;"><form action="javascript:nada();" method="get" name="send"><p>';
		thehtml +='</p><p><INPUT type="text" name="lightbox_new_name" id="lightbox_new_name" size="15" class="lightbox_new_name" value="'+currentlbname+'" onfocus="javascript: if (this.value == \''+currentlbname+'\'){ this.value=\'\';}">';
		thehtml +='<A href="javascript:lightbox_rename_send();" class=lblink style="font-size: 10pt; font-weight:bold;">Rename</A><br/>';
		thehtml +='<A HREF="javascript:lightbox_email(\'close\');">[X] close window</A>';
		thehtml +='</form></DIV></TD></TR></TABLE>';
/*
	var thehtml='<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="290" height="200"><TR>';
	thehtml +='<td class="dark1" valign=bottom width="100%"><DIV class="barheader">&nbsp;<FONT class="bartitle">Rename lightbox</font></DIV></td></tr>';
	thehtml +='<tr><TD ALIGN="left" VALIGN="top" width="290" class="dark1"><DIV class="light1" style="padding: 15px;"><form action="javascript:nada();" method="get" name="send">';
	var thehtml = '<input type="text" name="lightbox_new_name" id="lightbox_new_name" value="'+currentlbname+'" onfocus="javascript: if (this.value == \''+currentlbname+'\'){ this.value=\'\';}"/>';
	thehtml +=  '<A href="javascript:lightbox_rename_send();" class=lblink style="font-size: 10pt; font-weight:bold;">Rename this Lightbox</A><BR><BR>';
	thehtml +='<A HREF="javascript:lightbox_email(\'close\');">[X] close window</A>';
*/	
	center_panel(290,200,thehtml);
};

function lightbox_rename_send(){
	if( $F('lightbox_new_name').length ==0 || $F('lightbox_new_name').length > 100){
		 alert('Lightbox names must be between 1 and 100 characters long.');
		$F('lightbox_new_name')='';
	} else {
		if(test_valid_name($F('lightbox_new_name'))){
			var theurl = '/bin/ExLbRn?rename=' + $F('lightbox_new_name');
			$('LBFrame').src=theurl;
			simplemessage('renaming your lightbox ' + $F('lightbox_new_name') + ' <blink>.</blink>',0);
		} 
	}
};

function lightbox_change(newlb){
	polllb();//make sure and save changes
	currentlbname=newlb;
	simplemessage('Changing to Lightbox: ' + newlb + '<blink>.</blink>','','LB');
	$('LBFrame').src='/bin/ExLbView?n=' + newlb;
	//lightbox_build(currentlbstash);
};

function lightbox_addto(id) { // adding an image to the current lightbox

	if (gsession)
	{
		var temp=currentlbstash.join(" ");
		if(temp.indexOf(id)>0){
			alert('That image is already in your Lightbox');
		} else {
			if (! currentlbname)
			{
				currentlbname = 'newlb';
			}
			//alert(currentlbname);

			if (!currentlbstash.push)
			{
				currentlbstash = new Array();
			}
			currentlbstash.push(id);
			lbtosave=1;
			set_lightbox_trap();
			lightbox_build(currentlbstash);
		}
	}
	else //not
	{
		window.location='/bin/Cklb?ref=/SwishSearch%3F'+escape(pre_q_args)+'&atlb='+id;
		//Keywords%3D'+escape(ukeys)
	}

};

//deleting lightbox from exlarge view (as opposed to local lb).
function lightbox_delete_image_enl(locid,callback) {
	var targetlb;
	var loc_mobj = '';
	var owner = gusername;
	if(typeof(mobject_id) != 'undefined' && mobject_id != '') //always sent in as a page var by template on VMO links
	{
		var pargs = new Array;
		pargs = mobject_id.match(/^([^.]+)\.([^.]+)\.([^.]+)$/);
		targetlb = pargs[3];
		owner = pargs[2];
		loc_mobj = mobject_id;
	}
	else if (typeof(pagetype) != 'undefined' && pagetype == 'lb' ) //viewing local lightbox
	{
		targetlb = dsplkys;//so needs to also update lower lb
	}
	else
	{
		return; //do nothing if we can't find the full id of the lightbox viewed
	}

	//ajax call to delete lb image directly, since it may or not be the user's lb.
	ajax_TEXT('/bin/CreateLightbox?delid='+locid+'&vmo='+loc_mobj+'&uname='+owner+'&lbname='+targetlb, 'POST', null);
	
	//for removing images from lightbox viewed in enlarge mode, which may, or may not be also viewed in the lower panel.
	for(var tt=0; tt < id.length; tt++) // if we're in lbview need to also splice the image out
	{					//the display arrays
		if(id[tt] == locid)
		{
			cs.splice(tt,1);
			fs.splice(tt,1);
			o.splice(tt,1);
			rm.splice(tt,1);
			id.splice(tt,1);
			st.splice(tt,1);
			hrdl.splice(tt,1);
			rel.splice(tt,1);
			sw.splice(tt,1);
			pho.splice(tt,1);
			scp.splice(tt,1);
			buildimages(0,0);
		}
	}

	//need nameof this viewed lightbox to compare against currentlbname
	//to see if we need to update the lightbox tray too
//	alert(targetlb+' == '+currentlbname+' -- '+callback);
	if(targetlb == currentlbname && (typeof(callback == 'undefined') || callback != 1 ))
		lightbox_delete_image(locid);

};

function lightbox_delete_image(locid) {// removing an image locally and updating status to save ad periodical update
	var nlb = new Array();
	var targetlb = '';
	for(var temp=0;temp<currentlbstash.length;temp++){
		if(currentlbstash[temp] == locid){
			var tolightbox_delete_image=temp;
			if(typeof(mobject_id) != 'undefined' && mobject_id != '') //always sent in as a page var by template on VMO links
			{
				var pargs = new Array;
				pargs = mobject_id.match(/^([^.]+)\.([^.]+)\.([^.]+)$/);
				targetlb = pargs[3];
			}
			else if (typeof(pagetype) != 'undefined' && pagetype == 'lb' ) //viewing local lightbox
			{
				targetlb = dsplkys;//so needs to also update lower lb
			}

		}
		else
		{
			nlb.push(currentlbstash[temp]);
		}
	}

	currentlbstash = nlb;
	
	if(targetlb && targetlb != '' && targetlb == currentlbname) //need to refresh expanded view too if we're viewing expanded local lb
		lightbox_delete_image_enl(locid,1);

	if (typeof(currentlbstash) != 'undefined' && currentlbstash.length == 0)
	{
		lightbox_delete();
	}
	else
	{
		lightbox_build(currentlbstash);
		set_lightbox_trap();
		lbtosave=1;
	}
};

function lightbox_build(tlba,lname,secr,lbl){ // major code to build the lightbox area
	if(cartview && carnit)
	{
		carnit = 0;
		currentlbstash=tlba;
		cart_build();//preempt initial lightbox build if we've been asked to go direct to cart.
		cart_display();
		return;
	}

	hidedisplaypanel(1)	// clears the message that was saying loading lightbox or any other transition messages

	if(!tlba && typeof(currentlbstash) == 'undefined') //I got called but there is no lightbox data anywhere
	{
		return;
	}
	else if(!tlba)
	{
		tlba=currentlbstash;
	}

	currentLbdivMode = 'lightbox';
	if(lname){  // called from the LBframe results routine otherwise, usually we don't need to change lb just rebuild it
		//alert(lname);
		currentlbname=lname;
		lbtosave=0;
	}
	
	if(lbl){
		currentlblist=lbl.split('|');
	}
	if(secr){scr=secr;} // secret auth tag passed from server to prevent from an open lightbox security vulnerability

	var lbdPos = Position.cumulativeOffset($('LBdiv'));
	var lbbgH = winH - lbdPos[1] - 18; //18 being height of lbbuttons	

	currentlbstash=tlba;
        var thehtml='<DIV id=lbbuttons style="padding: 0px; margin: 0px; width: 127px; height:18px;"><A href="javascript:cart_build(\'changing\');" TITLE="SWITCH TO YOUR CART"><IMG SRC="/graphics/lightbox_enabled_02.gif" border="0" width="127" height="18" hspace="0" vspace="0"></A></DIV><DIV class="lbname" style="padding-left: 3px; margin: 0px; height: 100%; overflow: hidden;">';



	if ( currentlblist && currentlblist.length > 0) //|| (currentlbstash && (! currentlbstash['1']) ) ) && ( tlba.length > 0 || currentlbname)) 
	{
		var displen = ( currentlbstash[0] == 1 ? ( currentlbstash.length - 1 ) : currentlbstash.length );
		thehtml += '<B>' + currentlbname + ' Lightbox</B>&nbsp;&nbsp;(' + displen + ') &nbsp;';
		thehtml +='<B>Change to</B> ' + '<SELECT name="n" onchange="javascript:lightbox_change(this.options[this.selectedIndex].value);" id="lightbox_menu" class="smallmenu">';
		if (currentlblist)
			for(var i=0;i<currentlblist.length;i++){
			if (currentlblist[i] != '')
			{
				if(currentlblist[i]==currentlbname){
					thehtml+='<OPTION value="' + currentlblist[i] + '" SELECTED>' + currentlblist[i] + '</OPTION>';
				} else {
					thehtml+='<OPTION value="' + currentlblist[i] + '">' + currentlblist[i] + '</OPTION>';
				}
			}
			}
		thehtml +='</SELECT>';
	}

	thehtml +='<A href="javascript:lightbox_new();" class=lblink>';
	var tlb1 = '';
	var tlb2 = '';
	var tlb3 = '';
	var tlb4 = '';
	var tlb5 = '';
	var tlb6 = '';
	if(winW>832){
		tlb1 ='Make new lightbox';
		tlb2 ='View expanded lightbox';
		tlb3 ='Email lightbox';
		tlb4 ='Add Lightbox to Cart';
		tlb5 ='Delete Lightbox';
		tlb6 ='Rename Lightbox';
		tlb7 ='Make LB a Feature';
		tlb8 ='Copy LB to User';
	} else {
		tlb1 ='new LB';
		tlb2 = 'View LB';
		tlb3 = 'Email LB';
		tlb4 = 'Add LB to Cart';
		tlb5 ='Delete LB';
		tlb6 ='Rename LB';
		tlb7 ='Make Feature';
		tlb8 ='Copy LB';
	}
	//alert(currentpagenum);
	thehtml +=tlb1 + '</A> | <A href="javascript:toplightboxrefresh();" onclick="var d = new Date(); d.setMinutes(d.getMinutes()+5); gsetCookie(\'gprewhichstartpage\', showstartnumber_trap, d, \'/\', gGetCookieDom());" class=lblink>' + tlb2 + '</A> | <A href=javascript:lightbox_email(); class=lblink>' + tlb3 + '</A> | <A href=javascript:lightbox_add2cart(); class=lblink>' + tlb4 + '</A> | <A href=javascript:lightbox_delete(); class=lblink>' + tlb5 + '</A> | <A href=javascript:lightbox_rename(); class=lblink>' + tlb6 + '</A>';

	if(typeof(makelightboxfeature) != 'undefined')
	{

		thehtml += ' | <A href="#" onclick="javascript:launchwin(\''+makelightboxfeature + currentlbname+'\', \'make feature\', 500, 400, 100, 100); return false;" class="lblink">'+tlb7+'</A>';

		//"javascript:window.open(\'' + makelightboxfeature + currentlbname + '\', \'make feature\', \'width=500,height=400,scrollbars=yes\'); return false;"
	}

	if(typeof(copylightboxtouser) != 'undefined')
	{
		thehtml += ' | <A href="#" onclick="javascript:launchwin(\'' + copylightboxtouser + '\', \'copy lightbox to user\', 300, 300, 300, 400); return false;" class="lblink">'+tlb8+'</A>';
		
		//"javascript:window.open(\'' + copylightboxtouser + '\', \'copy lightbox to user\', \'width=500,height=400,scrollbars=yes\'); return false;"
	}
	

	thehtml +='</DIV>';
        if(tlba.length>0){

		thehtml +='<DIV id=LBimgdiv style="padding: 6px 0 0 3px; height: 100% ">';
		var tofit=parseInt((winW*.65)/tlba.length);
	    if(truevertHeight < 340){vlim=25;} else if(truevertHeight < 450){vlim=35;} else {vlim=58;}

		//alert(tofit+', '+vlim+', '+truevertHeight+' x '+winW);

		if(tofit> vlim){
                	tofit=vlim;
                } else if (tofit<18){
                        tofit=18;
                }
                for (lbi=0;lbi<tlba.length;lbi++){
                        lbid=tlba[lbi];
			if ((lbid == 1 && tlba.length < 2) || lbid != 1){ // hide image 1 from view unless new box...
		            thehtml+='<DIV align=center id="dlb_' + lbi + '" name="dlb_' + lbi + '" valign=bottom style="float:left; height:' + (tofit + 18) + 'px; overflow:hidden;"><A ';
				thehtml+=' onclick="javascript:if(suspendpreviews==0){enlarge2(\'' + lbid + "', '" + lbi + '\');}" id="dlb' + lbi + 's_lbi" onmouseover="prloadimg(\''+lbid+'\'); sp(this, \'' + lbid + "', '" + lbi +  "','" + tset + "');\" onmouseout=\"hp();\"><IMG SRC=\"http://globaldyn.ipnstock.com/dyn_images/135/50/" + lbid + ".JPG\" height=" + tofit + " class=\"lbimg\" hspace=2></A><BR>";
				//thehtml+=' id="dlb' + lbi + 's_lbi" onmouseover="sp(this, \'' + lbid + "', '" + lbi +  "','" + tset + "');\" onmouseout=\"hp();\"><IMG SRC=\"http://globaldyn.ipnstock.com/dyn_images/135/50/" + lbid + ".JPG\" height=" + tofit + " class=\"lbimg\" hspace=2></A><BR>";

				if ( lbid != 1 ) //as corollary, don't let the user delete the placeholder, either 
				{
					thehtml+='<DIV style="padding-left: 2px; padding-right: 2px; padding-bottom:6px;">';
					thehtml+='<A href="javascript:lightbox_delete_image(\'' + lbid + '\');" class="lblink" TITLE="Remove this image from the lightbox">X</A>';
					thehtml+='<A href="javascript:enlarge2(\'' + lbid + "', '" + lbi + '\');" class="lblink" style="font-size: 8pt;" TITLE="Enlarge this image">+</A></DIV>';
				}
				thehtml+='</DIV>';
			}
			//sp('','" + lbid + "','','','" + lbid + "','" + lbid + "','off')
		}

                thehtml+='<BR clear=all>';
		//write the lb to the div

        }
	else if (currentlbname)
	{
		thehtml +='<DIV id=LBimgdiv style="padding: 6px 0 0 3px; height: 100% ">';
		thehtml+='<DIV align=center id="dlb_0" name="dlb_0" valign=bottom style="float:left; height:' + (tofit + 18) + 'px; overflow:hidden;"><A ';
		thehtml+=' onclick="javascript:if(suspendpreviews==0){enlarge2(\'1\', \'0\');}" id="dlb0s_lbi" onmouseover="prloadimg(\'1\'); sp(this, \'1\', \'0\',\'' + tset + "');\" onmouseout=\"hp();\"><IMG SRC=\"http://globaldyn.ipnstock.com/dyn_images/135/50/1.JPG\" height=" + tofit + " class=\"lbimg\" hspace=2></A><BR></DIV><BR clear=all>";
	}

        if($('LBdiv'))
	{
	        //MM_setTextOfLayer('LBdiv','',thehtml);
		$('LBdiv').innerHTML = thehtml;
		//var temp='dlb' + (tlba.length - 1) + 's';
		var temp='dlb_' + (tlba.length - 1) + '';
		lbexpansionspace=0;
		var temp3=$$$(temp);

		if (temp3)		
		{
			var topoflastimage = Position.cumulativeOffset($$$(temp));
			var heightoflastimage = parseInt(Element.getHeight(temp3));
			var heightoflbdiv = Element.getHeight('LBdiv');
			var topoflbdiv = Position.cumulativeOffset($('LBdiv'));
			var bottomoflastimage = topoflastimage[1] + heightoflastimage;
	
			//alert('topoflastimage=' + topoflastimage + ' heightoflastimage=' + heightoflastimage + ' heightoflbdiv=' + heightoflbdiv + ' topoflbdiv=' + topoflbdiv + ' winH=' + winH + ' trueh=' + trueh + ' bottomoflastimage=' + bottomoflastimage );
	
			if((topoflastimage[1] + heightoflastimage) > trueh){
				lbexpansionspace = (bottomoflastimage - topoflbdiv[1] + 5);
				
				//choke it off to 30% of the screen max
				if(lbexpansionspace > parseInt(trueh * .3))
					lbexpansionspace=parseInt(trueh * .3);
					
				currentpage();
			} else {
				currentpage();
			}
	        Sortable.create("LBimgdiv", {
               tag:'DIV',
               overlap:'horizontal',
               constraint: false,
               onChange:function(){
                  hp();
                  suspendpreviews=1;
               },
               onUpdate:function(){
                  resort(Sortable.serialize("LBimgdiv"));
               }  
         });
		}
        }
	return;
};

function resort(neworder){ // called after a drag and drop to rebuild the lb according to the drag-drop resorted list
	rExp = /LBimgdiv/gi;
	results = neworder.replace(rExp, '');
	results = results.replace(/\&/g, '|');
	results = results.replace(/\[\]\=/g, '');
	var newlborder=new Array();
	var newarray=results.split('|');
	for (var i=0;i< newarray.length;i++){
		newlborder[i]=currentlbstash[newarray[i]]; 
	}
	lightbox_build(newlborder);
	set_lightbox_trap();
	lbtosave=1;
	setTimeout('suspendpreviews=0;',1000);
};

function changesortable(){
	hp();suspendpreviews=1;
};

function updatesortable(){
	suspendpreviews=0;
	resort(Sortable.serialize("LBimgdiv"));
};

function polllb(force){ // routinely called to see if the lightbox needs to be send to the server for updating also manually called when we need to check if LBs have changed before we do something that would loose changes

	if( (lbtosave == 1 || force) && document.getElementById('LBFrame')){
			var newlb = (typeof(currentlbstash) != 'undefined' ? currentlbstash.join('|') : 1) ;
			tosave='/bin/CreateLightbox?' + 
				'sphotog='+sphotog+
				'&secret=' + scr + 
				'&override=yes' + 
				'&username=' + gusername + 
				'&lightbox=' + currentlbname + 
				'&lbimages=' +  newlb;
			$('LBFrame').src = tosave;
			lbtosave=0;
	}
};

function bail(twiddle){ //onunload handler
	lbtosave = twiddle;
	set_lightbox_trap();
	polllb(twiddle); //force it JIC
	return;
};

function cart_away() { //leave site for universal checkout
        top.location = "/bin/Cart?op=ckout";
};

function cart_check (){ //verifys all items in current cart are priced
	simplemessage('<a style="cursor:pointer; text-decoration:underline;" title="click here if you find you are waiting too long to load." onclick="cart_check();">Tabulating Shopping Cart <blink>.</blink> </a>','','LB');
	ajax_JSON( '/AjaxHandlers/CartInfo/open.json', 'POST', null );
	cart_check_act(0);
};

function cart_check_act(cartTryCtr){
	//alert('LOADED? '+document.ajaxLoaded+' COB? '+currMousedOverObj+' TRY? '+cartTryCtr);
	if((document.ajaxLoaded || cartTryCtr >= 10) && currMousedOverObj == 'shop_cart')
	{
		var cart_good = 1;

		if (! document.JSONobj)
		{	//fake it
			document.JSONobj = new Object();
			document.JSONobj.oJSON = new Object();
			document.JSONobj.oJSON.total = 0;
		}

		if(document.JSONobj.getCartDat('total') > 0){
			for (cti=0; cti < document.JSONobj.getCartDat('total'); cti++)
			{
				if(document.JSONobj.getCartDat('price',cti))
				{
					if(!( document.JSONobj.getCartDat('price',cti) != 'null' && document.JSONobj.getCartDat('price',cti) > 0)) 
						cart_good = 0;
				}
				else
				{
					cart_good = 0;
				}
			}
		}
		else
		{
			cart_good = 0;
		}

// 		alert('CG: '+cart_good);

		if (cart_good == 1)
		{
			cart_away();	
		}
		else
		{
			alert("Your cart is empty, or there are items in your cart with no prices.  To license image(s) first click the 'specify usage and calculate fee' link for each image in your cart and use the Rate calculator. Rates vary based on usage.");
			topcartrefresh();
		}		
	}
	else if (cartTryCtr < 10)
	{
		cartTryCtr++;
		setTimeout("cart_check_act('"+cartTryCtr+"')",  (500 + (50 * (cartTryCtr - 1))) ); //((50 * cartTryCtr - 1) / 2)
	}
	else if (!document.ajaxLoaded )
	{
		topcartrefresh();
	}
};

function cart_display (flip) { // call to load shopcart display into Layer1
	currentLayer1Mode = document.currentLayer1Mode = 'cartview';
	if(!flip)
		flip='view';

	if (typeof(cartdispcheck) != 'undefined' && cartdispcheck == 1) //already trying to refresh...
	{
		return;
	}
	else
	{
		//alert(flip);
		ajax_HTML('Layer1', '/bin/Cart?op='+flip+'&drk='+Math.random(10), 'GET');
		$('Layer1').style.overflow = 'auto';
		$('Layer1').style.height = truevertHeight + 'px';
	}
};

function cart_build(mode) { //wrapper for asynch calls to cart data
	currentLbdivMode = 'cart';
	if(mode == 'changing'){
		simplemessage('<a style="cursor:pointer; text-decoration:underline;" title="click here if you find you are waiting too long to load." onclick="cart_build(\'changing_again\');"> Loading Shopping Cart <blink>.</blink></a>','','LB');
	}
 	ajax_JSON( '/AjaxHandlers/CartInfo/open.json', 'POST'); //( typeof(baseurl) != 'undefined' ? 'http://www.'+baseurl : '' ) +

	//alert(( typeof(baseurl) != 'undefined' ? 'http://www.'+baseurl : '' ) + '/AjaxHandlers/CartInfo/open.json');
	currMousedOverObj = 'shop_cart';
	cart_build_act(0);
};

function cart_build_act(cartTryCtr){
// 	alert(document.ajaxLoaded+' && '+currMousedOverObj);
	if(document.ajaxLoaded && currMousedOverObj == 'shop_cart')
	{
		if (! document.JSONobj)
		{
			document.JSONobj = new Object();
			document.JSONobj.oJSON = new Object();
			document.JSONobj.oJSON.total = 0;
		}
		hidedisplaypanel(1)	// clears the message that was saying loading lightbox or any other transition messages
		var thehtml='<DIV id=lbbuttons style="padding: 0px; margin: 0px; width: 127px;height:18px;"><A href="javascript:currentLbdivMode=\'lightbox\'; cartview=\'\'; lightbox_build();" TITLE="SWITCH TO YOUR LIGHTBOX"><IMG SRC=/graphics/cart_enabled_02.gif border=0 width=127 height=18 hspace=0 vspace=0></A></DIV>';
		thehtml +=  '<DIV class=lbname style="padding-left: 3px;margin: 0px;"><B>Shopping Cart&nbsp;&nbsp;' + document.JSONobj.getCartDat('total') + ' images &nbsp;';
		thehtml +='<A onclick="cart_display();" class="lblink" style="text-decoration:none; cursor:pointer;">View Cart and Calculate Usage Fees</A> | <A href="javascript:cart_check();" class=lblink>Checkout</A></font>';

		if(document.thisIsFeatureView)
		{
			thehtml +=' | <a class="lblink" onclick="$(\'LBdiv\').style.visibility = \'hidden\';" style="cursor:pointer">[x] Hide Cart</a>';
		}
		
		thehtml +='</DIV>';
		if(document.JSONobj.getCartDat('total')>0){
			thehtml +='<DIV id=LBimgdiv style="padding: 6px 0 0 3px; height: 100%">'; 
			var tofit=parseInt((winW*.65)/document.JSONobj.getCartDat('total'));
			if(winH < 340){vlim=25;} else if(winH < 450){vlim=35;} else {vlim=58;}
			if(tofit> vlim){
				tofit=vlim;
			} else if (tofit<18){
				tofit=18;
			}

			for (cti=0;cti<document.JSONobj.getCartDat('total');cti++)
			{
				ctimid = document.JSONobj.getImgDat('id', cti);
				ctid = document.JSONobj.getCartDat('id',cti);				
				thehtml+='<div align=center id="dct' + cti + 's" name="dct' + cti + 's" valign="bottom" style="float:left; height:' + (tofit + 18) + 'px; overflow:hidden;"><A ';
				thehtml+=' onclick="hp();" id="dct' + cti + 's_cti" onmouseover="prloadimg(\''+ctimid+'\'); sp(this, \'' + ctimid + "', '" + cti + "','"+tset+'\');" onmouseout="hp();">';
				thehtml+='<IMG SRC=http://globaldyn.ipnstock.com/dyn_images/135/50/' + ctimid + ".JPG height=" + tofit + " class=lbimg hspace=2></A><BR>";
				thehtml+='<DIV style="padding: 2px;"><A href=javascript:cart_delete_image(\'' + ctid + '\'); class=ctlink TITLE="Remove this image from the cart">X</A></DIV></DIV>';
			}

			//set future cookie for remaining images in cart
			var date = new Date();
        		date.setTime(date.getTime()+(60*24*60*60*1000));
			gsetCookie('gcartimages',cti,date,'/',gGetCookieDom());
			thehtml+='<BR clear=all>';
		}
		
		if($('LBdiv')){
			MM_setTextOfLayer('LBdiv','',thehtml);
			var temp='dct' + (document.JSONobj.getCartDat('total') - 1) + 's';
			lbexpansionspace=0;
			var temp3=$$$(temp);

			if (temp3)	
			{
				var topoflastimage = Position.cumulativeOffset($$$(temp));
				var heightoflastimage = parseInt(Element.getHeight(temp3));
				var heightoflbdiv = Element.getHeight('LBdiv');
				var topoflbdiv = Position.cumulativeOffset($('LBdiv'));
				var bottomoflastimage = topoflastimage[1] + heightoflastimage;
		
				if((topoflastimage[1] + heightoflastimage) > trueh)
				{
					lbexpansionspace = (bottomoflastimage - topoflbdiv[1] + 5);
		
					//choke it off to 30% of the screen max
					if(lbexpansionspace > parseInt(trueh * .3))
						lbexpansionspace=parseInt(trueh * .3);
					currentpage();
				} 
				else 
				{
					currentpage();
				}
			}
		}
	}
	else if (cartTryCtr < 10)
	{
		cartTryCtr++;
		setTimeout("cart_build_act('"+cartTryCtr+"')",  (500 + (100 * (cartTryCtr - 1))) ); //((50 * cartTryCtr - 1) / 2)
	}
	else
	{
		cart_build('changing');
	}
};	

function gfixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);   
};

function g() {
	var url2 = $F('Keywords');
	var uname = $F('Username');  // for id of query in logs... to assoc with users
	pagetype = 'search';
	//alert(url2+'| |'+uname);
	
//SB>> search fix to preserve previous terms:
       	var prev_keys = '';
       	if(typeof('q_args') != 'undefined' && q_args)
       	{
               	prev_keys = q_args.match(/Keywords=(.*?)(\&|$)/);
		if(typeof(prev_keys) != 'undefined' && prev_keys && prev_keys.length > 1)
			prev_keys = prev_keys[1];
		else
			prev_keys = '';

               prev_keys = unescape(prev_keys);
       	}

       	if (url2.length<1 && ! prev_keys){ //	if (url2.length<1){
		alert("You must first enter search criteria in the field next to the search button.");
	} else {
		polllb(1); //force lbsave before searching...
                if (url2.length<1) //got here because we're going to rely on the previous search term
                        $('Keywords').value = url2 = prev_keys;

		var theurl = '';
		if ($('method') && typeof($('method').value) != 'undefined' && $('method').value=='within'){
			theurl= '/SwishSearch?Keywords=' + q_id + '&ex_keys=' + url2;
		} else {
			theurl= '/SwishSearch?Keywords=' + url2 ;
		}

		if($('displaypanel'))
		{

			if ( $('collection').selectedIndex == 0 )
				theurl += '+lifestylecollection';

			if ( $('collection').selectedIndex == 1 )
				theurl += '+travelcollection';

			if(typeof(suspendWithPeople) == 'undefined')
			{	
				if ($('displaypanel').people[1].checked == true){
					theurl += '+haspeople';
				}
				if ($('displaypanel').people[2].checked == true){
					theurl += '+nobody';
				}
				if ($('displaypanel').people[3].checked == true){
					theurl += '+hascrowd';
				}
			}

			if(typeof(suspendYesNoRestrictons) == 'undefined')
			{
				if ($('displaypanel').restrictions[1].checked == true){
					theurl += '+NOT+imagehasrestrictions';
				}
			}


			if ($('displaypanel').xtrasql[1].checked == true){
				theurl += '&xtrasql=(releasedmodel+or+releasedproperty+or+releasednotapplicable+or+releasedmodelandproperty)';
			}
	
			if($('spec_idx'))
			{
				if ($('spec_idx').selectedIndex==1){
					theurl += '&spec_idx=ed';
				}
				if ($('spec_idx').selectedIndex==2){
					theurl += '&spec_idx=ne';
				}
			}
	
			if(!(	$('displaypanel').orient[0].checked && 
				$('displaypanel').orient[1].checked && 
				$('displaypanel').orient[2].checked && 
				$('displaypanel').orient[3].checked	))
			{
				if ($('displaypanel').orient[0].checked == true){
					theurl += '&orient=horizontal';
				}
				if ($('displaypanel').orient[1].checked == true){
					theurl += '&orient=vertical';
				}
				if ($('displaypanel').orient[2].checked == true){
					theurl += '&orient=panoramic';
				}
				if ($('displaypanel').orient[3].checked == true){
					theurl += '&orient=square';
				}
			}
	
			if($('displaypanel').rmrftype)
			{
				if ($('displaypanel').rmrftype[0].checked == true && $('displaypanel').rmrftype[1].checked == false){
					theurl += '&searchinclude=RM';
				}
				if ($('displaypanel').rmrftype[1].checked == true && $('displaypanel').rmrftype[0].checked == false){
					theurl += '&searchinclude=RF';
				}
			}
	
			if ($('displaypanel').color[1].checked == true){
				theurl += '&color=color';
			}
			if ($('displaypanel').color[2].checked == true){
				theurl += '&color=gray';
			}

// conditional for Illustation agencies
                        if (typeof(showIllusPhotog) != 'undefined'){
                                if ($('displaypanel').searchinclude[0].checked == true && $('displaypanel').searchinclude[1].checked == false){
                                        theurl += '&searchinclude=illustration';
                                }
                                if ($('displaypanel').searchinclude[1].checked == true && $('displaypanel').searchinclude[0].checked == false){
                                        theurl += '&searchinclude=photography';
                                }
                        }

		}
		//if ($('displaypanel').tsort.selectedIndex >0){
		//	theurl += '&sort=' + $('displaypanel').tsort.options[$('displaypanel').tsort.selectedIndex].value;
		//}
		if (uname && uname != '')
			theurl += '&Username='+escape(uname);


		gsetCookie("gwhichstartpage","", "", "/", gGetCookieDom());
		//alert(theurl);
		if (url2 != 'enter keywords') {
			coveroff();
			hidedisplaypanel(1);
			MM_setTextOfLayer('Layer1','','<TABLE width=100% height=100%><TR width=100% height=100%><TD valign=middle align=center width=100% height=100%><B><FONT class=header>Searching for ' + $F('Keywords') + ' <blink>.</blink></font></B></TD></TR></TABLE>');
			self.location=theurl;

		} else {
			alert('You must first type in keywords to search for.');
			document.isn.Keywords.focus();
		}
	}
};

function coverlayerobjnostyle(){
	if (document.getElementById)
		return document.getElementById("coverlayer");
	else if (document.all)
		return document.all.coverlayer;
};

function coverlayerobj(){
	if (document.getElementById)
		return document.getElementById("coverlayer").style;
	else if (document.all)
		return document.all.coverlayer.style;
};

function gwhichindex(tset) {	
	gsetCookie("gwhichindex",tset, '', '/', gGetCookieDom());
};

function fsearchprefs(val,mode) {
	var gsearchprefs = ggetCookie('gsearchprefs');
	if(gsearchprefs){
	} else {
		gsearchprefs= new String(" ");
	}
	var buildpref = new String("");
		if(val == 'released' && mode == 'remove'){

		} else {
			if((gsearchprefs.indexOf('a')>=0) || (val == 'released' && mode == 'add')){
				buildpref+='a';
			}			
		}
		if(val == 'norestrictions' && mode == 'remove'){	
		} else {
			if((gsearchprefs.indexOf('b')>=0) || (val == 'norestrictions' && mode == 'add')){
				buildpref+='b';
			}
		}
		if(val == 'people' && mode == 'remove'){
		} else {

			if(((gsearchprefs.indexOf('c')>=0) && (val != 'withpeople') && (val != 'withcrowd'))  || (val == 'nobody' && mode == 'add')){
				buildpref+='c';
			} else if (((gsearchprefs.indexOf('d')>=0) && (val != 'withcrowd') ) || (val == 'withpeople' && mode == 'add')){
				buildpref+='d';
			} else if ((gsearchprefs.indexOf('e')>=0) || (val == 'withcrowd' && mode == 'add')){
				buildpref+='e';
			}
		}

		if (document.displaypanel.orient[0].checked == true){
			buildpref+='f';
		}
		if (document.displaypanel.orient[1].checked == true){
			buildpref+='g';
		}
		if (document.displaypanel.orient[2].checked == true){
			buildpref+='h';
		}
		if (document.displaypanel.orient[3].checked == true){
			buildpref+='i';
		}

		if(typeof(rmonly) == 'undefined')
		{
			if (document.displaypanel.rmrftype[0].checked == true){
				buildpref+='j';
			}
			if (document.displaypanel.rmrftype[1].checked == true){
				buildpref+='k';
			}
		}

		if (document.displaypanel.color[0].checked == true){
			buildpref+='m';
		}
		if (document.displaypanel.color[1].checked == true){
			buildpref+='n';
		}
		if (document.displaypanel.color[2].checked == true){
			buildpref+='o';
		}

                if (typeof(showIllusPhotog) != 'undefined'){ //if adding Illustration / Photography selector checkboxes
                        if(document.displaypanel.searchinclude[0].checked == true){
                                buildpref+='0';
                        }
                        if(document.displaypanel.searchinclude[1].checked == true){
                                buildpref+='1';
                        }
                }


		//if (document.displaypanel.tsort.selectedIndex == 0){
		//	buildpref+='s';
		//}
		//if (document.displaypanel.tsort.selectedIndex == 1){
		//	buildpref+='t';
		//}
		//if (document.displaypanel.tsort.selectedIndex == 2){
		//	buildpref+='u';
		//}
		//if (document.displaypanel.tsort.selectedIndex == 3){
		//	buildpref+='v';
		//}
		//if (document.displaypanel.tsort.selectedIndex == 4){
		//	buildpref+='w';
		//}
		//if (document.displaypanel.tsort.selectedIndex == 5){
		//	buildpref+='x';
		//}
		//if (document.displaypanel.tsort.selectedIndex == 6){
	//		buildpref+='y';
	//	}
	//	if (document.displaypanel.tsort.selectedIndex == 7){
	//		buildpref+='z';
	//	}
		gsetCookie("gsearchprefs",buildpref, '', '/', gGetCookieDom());
};

function greleasedselect(tsetval) {
	gsetCookie("greleasestatus",tsetval, '', '/', gGetCookieDom());
};


////////////search functions only////////////

// catch all errors...
function stopError() {return true;};
//window.onerror=stopError;

function htmlit(showid){

	// build html for each image depending on viewing mode
	
	var html='';
	switchpage = false;
	if (id[showid]){
		
		var myrmrftype = rm[showid];
		myid = id[showid];
		//myshortcaption=scp[showid]; //eval("document.fm.sc" + myid);
		mysimilarto=st[showid];
		if (viewmode == 'list' ){myshortcaption=unescape(scp[showid]);} else {myshortcaption = "n/a";}
		var temp = true;
		var tempshortcaption='';
		myreleased = rel[showid];
		if(showrelease){
			if(myreleased == "MODEL RELEASED" || myreleased == "MODEL AND PROPERTY RELEASED" || myreleased == "PROPERTY RELEASED"){
				myreleased = "<BR>" + myreleased;
			} else {
				myreleased = "<BR>RELEASED:" + myreleased;
			}
		} else { myreleased="";}
		//shorten long captions
		if(myshortcaption.length > 90){
			for(z=0; z < 130; z++){
				var c = myshortcaption.charAt(z);
				if(temp == true){
					if((z > 90) && (c == ".")){
						temp = false;
						tempshortcaption+=c + " ...";
					} else if((z > 110) && (c == " ")){
						temp = false;
						tempshortcaption+=" ...";
					} else {
						tempshortcaption+= c;
					}
				}
        		}
        		myshortcaption = tempshortcaption;
    		}
    		var thishassimilars = "yes";
		myphotographer=pho[showid];
		myrglobaldynf = rm[showid];
		myfilesize=fs[showid];
		var myhrdlink = hrdl[showid];

		if(myhrdlink){
			myhrdlink = myhrdlink.replace(/(<br>|%3cbr%3e)/ig, '');
			adminheight=11;
		} else {
			adminheight=0;
		}
		if(myfilesize < 5){myfilesize='Scan on Demand';} //else {myfilesize+=" Mb";}
		if(myid.length > 9){
		
			if(viewmode == "list"){
				var theight = 172 + adminheight;
				if ( mysimilarto.length < 12){	
					
					html += '<span valign=bottom style="float:left;">';
					html += '<div align=center valign=bottom style="width:305px; height:' + theight + 'px;">';
					html += '<TABLE width=298 cellspacing=2 cellpadding=0 border0><TR><TD valign=top><a href="javasc' + 'ript:enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\');"><img src="http://globaldyn.ipnstock.com/dyn_images/135/50/' + myid + '.JPG" border=0 class=pimg vspace=2 hspace=3';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";html += '" onmouseout="hp();" id=' + myid + '>';
					//sp('','" + myid + "','" + myrglobaldynf + "','" + myphotographer + "','" + myid + "','" + showid + "');
					html += '</a><BR>';
					if(myhrdlink)
						html += '<center>'+myhrdlink+'</center>';
					html += '</TD><TD valign="top"><font class=xsmall>ID:' + myid;
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					html += '<DIV class=icons>';

//					if (typeof(pagetype) != 'undefined' && pagetype=='lb' && 
//						typeof(currentLayer1Mode) != 'undefined' && currentLayer1Mode == 'lightbox')

					if ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) )	
					{
						html+='<A href="javascript:lightbox_delete_image_enl(\'' + myid + '\');" class="lblink" TITLE="Remove this image from the lightbox">X</A>';
					}

//cart_addto(\'' + myid + '\'); return false;
					html += '<a href="" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}

					html += '<a href="" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$</a>';
					html += '<a href="" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class=iconlink title="Enlarge image and more info"><font class=eye>i</font></a>';
					html += '</DIV>';
					
					if(showphotographer == 1){html +='<BR>&copy; '+currentYear+' ' + myphotographer;}
					html += '  <nobr>';
					if(showfilesize){html += myfilesize;}
					html += '</nobr>' + myreleased + '<BR>CAPTION: ' + myshortcaption + '</font>';
					html += '</TD></TR></TABLE></DIV></SPAN>';
				} else {	
			
	
					html += '<span valign=bottom style="float:left;">';
					html += '<div id="d' + myid + '" align=center valign=bottom style="width:305px; height:' + theight + 'px;">';
					html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','list', myhrdlink);
					html += '</DIV></SPAN>';
				}
				
			
			} else if (viewmode == "tiny"){
				//adminheight += 8;
				var theight = 100 + adminheight;
				if ( mysimilarto.length < 12){	
					
					html += '<span valign=bottom style="float:left;">';
					html += '<div align=center valign=bottom style="width:95px; height:' + theight + 'px; overflow: hidden;"><a href="javasc' + 'ript:enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\');"';
					if(document.page.previews.selectedIndex == 1){html +=' TITLE="ID:' + myid;
						if(showphotographer == 1){html += '\r&copy; ' + myphotographer;}
						if(showfilesize){html += '\rSIZE: '+ myfilesize ;}
						html +=  ' \r' + 'CAPTION: ' + myshortcaption + '"';
					}
					html += '><img src=http://globaldyn.ipnstock.com/dyn_images/135/50/' + myid + '.JPG border=0 class=pimg vspace=1 hspace=1 height=55';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "', '" + showid + "','"+tset+"');";
					html += '" onmouseout="hp();" id=' + myid + '>';
					
					//sp('','" + myid + "','" + myrglobaldynf + "','" + myphotographer + "','" + myid + "','" + showid + "')
					html += '</a><BR>';
					html += '<DIV class=icons>';

					//if (typeof(pagetype) != 'undefined' && pagetype=='lb'&& 
					//	typeof(currentLayer1Mode) != 'undefined' && currentLayer1Mode == 'lightbox')	
					if ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) )	
					{
						html+='<A href="javascript:lightbox_delete_image_enl(\'' + myid + '\');" class="iconlinktiny" TITLE="Remove this image from the lightbox">X</A>';
					}

					html += '<a href="" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlinktiny" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlinktiny" title="Add this image to your shopping cart">CART+</a>';}

					html += '<a href="" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlinktiny" Title="Price Image">$</a>';
					html += '<a href="" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlinktiny" title="Enlarge image and more info"><font class=eye>i</font></a>';
					html += '</DIV>';
					html += '<DIV class=imidxxsmall>' + myid;
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					html +='</DIV>';
					if(myhrdlink)
						html += myhrdlink;
					html += '</DIV></SPAN>';

				} else {				
	
					html += '<span valign=bottom style="float:left;">';
					html += '<div id="d' + myid + '" align=center valign=bottom style="width:95px; height:' + theight + 'px; overflow:hidden;">';
					html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','tiny');		
					if(myhrdlink)
						html += myhrdlink;
					html += '</DIV></SPAN>';
				}
			
			
			} else if (viewmode == "med"){
				//adminheight += 4; // tweaking adminheight...
				var theight = 120 + adminheight;
				if ( mysimilarto.length < 12){	
				
					html += '<span valign=bottom style="float:left;">';
					html += '<div align=center valign=bottom style="width:140px; height:' + theight + 'px; overflow: hidden;">';
					html += '<a href="" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;"';
					if(document.page.previews.selectedIndex == 1){html += ' TITLE="ID:' + myid;
						if(showphotographer == 1){html += '  \r&copy; ' + myphotographer;}
						if(showfilesize){html += '\rSIZE: ' + myfilesize ;}
						html += ' \r' + 'CAPTION: ' + myshortcaption + '"';
					}
					html += '><img src=http://globaldyn.ipnstock.com/dyn_images/135/50/' + myid + '.JPG border=0 vspace=1 class=pimg hspace=1 height=80';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "', '" + showid + "','"+tset+"');";
					html += '" onmouseout="hp();" id=' + myid + '>';
						//sp('','" + myid + "','" + myrglobaldynf + "','" + myphotographer + "','" + myid + "','" + showid + "')
					html += '</a><BR>';
					html += '<DIV class=icons>';

					//if (typeof(pagetype) != 'undefined' && pagetype=='lb' && 
					//	typeof(currentLayer1Mode) != 'undefined' && currentLayer1Mode == 'lightbox')
					if ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) )	
					{
						html+='<A href="javascript:lightbox_delete_image_enl(\'' + myid + '\');" class="lblink" TITLE="Remove this image from the lightbox">X</A>';
					}

					html += '<a href="" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}

					html += '<a href="" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$</a>';
					html += '<a href="" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlink" title="Enlarge image and more info"><font class=eye>i</font></a>';
					html += '</DIV>';
					html += '<DIV class=imidxxsmall>' + myid;
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					html +='</DIV>';
					if(myhrdlink)
						html += myhrdlink;
					html += '</DIV></SPAN>';

				} else {				
	
					html += '<span valign=bottom style="float:left;">';
					html += '<div id="d' + myid + '" align=center valign=bottom style="width:140px; height:' + theight + 'px;">';
					html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','med');		
					if(myhrdlink)
						html += myhrdlink;
					html += '</DIV></SPAN>';
				}
			} else if (viewmode == "ss"){			
				html = '  ';
			} else if (viewmode == "huge"){		
				var theight = 220;
				if ( mysimilarto.length < 12){	
					html += '<span valign=bottom style="float:left;">';
					html += '<div align=center valign=bottom style="width:330px; height:' + theight + 'px; overflow: hidden;">';
					html += '<a href="" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" TITLE="ID:' + myid;
					if(showphotographer == 1){html += '\r&copy; ' + myphotographer;}
					if(showfilesize){html +=   '\rSIZE: ' + myfilesize ;}
					html += ' \r' + 'CAPTION: ' + myshortcaption + '"><img src="http://globaldyn.ipnstock.com/dyn_images/420/60/' + myid + '.JPG" border="0" vspace="1" hspace="3" alt="loading..." height="192"></a><BR>';
					html += '<DIV class=icons>';

//					if (typeof(pagetype) != 'undefined' && pagetype=='lb' && 
//						typeof(currentLayer1Mode) != 'undefined' && currentLayer1Mode == 'lightbox')
					if ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) )	
					{
						html+='<A href="javascript:lightbox_delete_image_enl(\'' + myid + '\');" class="lblink" TITLE="Remove this image from the lightbox">X</A>';
					}

					html += '<a href="" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LIGHTBOX+</a>';
					if(gsession){html += '<a href="" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}

					html += '<a href="" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$</a>';
					html += '<a href="" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlink" title="Enlarge image and more info"><font class=eye>i</font> ENLARGE</a>';
					html += myid;
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					if(myhrdlink)
						html += ' &nbsp; '+myhrdlink;
					html += '</DIV></DIV></SPAN>';
					
				} else {
					html += '<span valign=bottom style="float:left;">';
					html += '<div id="d' + myid + '" align=center valign=bottom style="width:330px; height:' + theight + 'px; overflow: hidden;">';
					html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','huge', myhrdlink);
					html += '</DIV></SPAN>';
				}				
			} else {
				var theight = 166 + adminheight;
				if ( mysimilarto.length < 12){		
					html += '<span valign=bottom style="float:left;">';
					html += '<div align=center valign=bottom style="width:152px; height:' + theight + 'px; overflow:hidden;">';
					html += '<a href="javasc' + 'ript:enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\');"';
					if(document.page.previews.selectedIndex == 1){html += ' TITLE="ID:' + myid;
						if(showphotographer == 1){html +=  '\r&copy; ' + myphotographer;}
						if(showfilesize){html += '\rSIZE: ' + myfilesize ;}
						html += ' \r' + 'CAPTION: ' + myshortcaption + '"';
					}
					html += '><img src="http://globaldyn.ipnstock.com/dyn_images/135/50/' + myid + '.JPG" class=pimg border="0" vspace="0" hspace="3"';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";
					html += '" onmouseout="hp();" id=' + myid + '>';
					
					//sp('','" + myid + "','" + myrglobaldynf + "','" + myphotographer + "','" + myid + "','" + showid + "');
					html += '</a><BR>';
					html += '<DIV class=icons>';

					
//					if (typeof(pagetype) != 'undefined' && pagetype=='lb' && 
//						typeof(currentLayer1Mode) != 'undefined' && currentLayer1Mode == 'lightbox')	
					if ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) )						{
						html+='<A href="javascript:lightbox_delete_image_enl(\'' + myid + '\');" class="iconlink" TITLE="Remove this image from the lightbox">X</A>';
					}

					html += '<a href="" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}
					html += '<a href="" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$</a>';
					html += '<a href="" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlink" title="Enlarge image and more info"><font class=eye>i</font></a>&nbsp;';
					html += '</div><div><font class=imid>' + myid + '</font>';
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					html +='</DIV>';
					//html += '<DIV class=imid>' + myid + '</DIV>';
					if(myhrdlink)
						html += myhrdlink;
					html += '</DIV></SPAN>';
		
			
				} else {			
					html += '<span valign=bottom style="float:left;">';
					html += '<div id="d' + myid + '" align=center valign=bottom style="width:152px; height:' + theight + 'px; overflow: hidden;">';
					html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','normal');
					if(myhrdlink)
						html += myhrdlink;
					html += '</DIV></SPAN>';
				}
			}
		}
	} 
	return html;
};

function enlarge2 (enid,encount,featuredimage) { //ajax calls to data for detail/enlarged view of image
	var previousMode = currentLayer1Mode = document.currentLayer1Mode;
	currentLayer1Mode = document.currentLayer1Mode = 'enlarge';
	var url = '/AjaxHandlers/ImageInfo/'+ 
		( featuredimage ? featuredimage : enid )+
		'.json';
	ajax_JSON( url, getpost, null ); 
	setuppagesize();
	$('Layer1').style.height = truevertHeight + 'px';
	enlarge2_act(enid,encount,featuredimage,0,0,previousMode);
};

function enlarge2_act(enid,encount,featuredimage,tryCtr,force, preMem){
	featuredimage = ( featuredimage == 'undefined' ? '' : featuredimage );
	hp();//ensure closure the preview window
	if ( document.ajaxLoaded || force ) //made it
	{
		//wipe viewmode cookie:
		if(typeof(viewmode) != 'undefined' && viewmode == 'ss')
			gsetCookie("gcurrentview",'', '', '/', gGetCookieDom());

		if( featuredimage || preMem == 'cartview' || id[encount] )
		{
			if(overflowtype == "hidden"){suspendtrap=1;}
			gSetBackpage();
			if(firstpictureonpage){
				gsetCookie("gwhichstartpage",firstpictureonpage, '', '/', gGetCookieDom());
			}
			//set metatdata variables
			var myshortcaption	= (	document.JSONobj.getImgDat('short_caption') ?
						document.JSONobj.getImgDat('short_caption')
							:
						"n/a");
			var myrmrftype = document.JSONobj.getImgDat('rmrftype');
			var myratetiers = document.JSONobj.getImgDat('rfcdimgpricing'); //this is currently preformatted list from templates, could
								//be extended in ajaxhandlers to return a data obj if we need 
								//more granular data

			var myphotographer	= document.JSONobj.getImgDat('photographer') +
					((document.JSONobj.getImgDat('agent_name') && document.JSONobj.getImgDat('agent_name') != '') ? '&nbsp;/&nbsp;'+document.JSONobj.getImgDat('agent_name') : '' );
			var myfilesize = (	document.JSONobj.getImgDat('file_size') < 5 ?
					'Scan on Demand'
						:
					document.JSONobj.getImgDat('file_size') + ' Mb');	
			var myreleased = document.JSONobj.getImgDat('released');
			var myrestrictions = document.JSONobj.getImgDat('image_restrictions');
			var mycompallow = document.JSONobj.getImgDat('comp_allow');
	
			//slideshow functions
			//if (! document.thisIsFeatureView)
			//{
				var nextimage = parseInt(encount) + 1;
				var nextimageid = id[nextimage];
				var previmage = parseInt(encount) - 1;
				var previmageid = id[previmage];
			//}
			//build html for enlarge page
			thehtml =  '<table cellspacing="0" cellpadding="0" border="0" width="99%" style="height:99%;overflow:auto">';
			thehtml += '   <TR height="99%">';
			thehtml += '           <TD align="left" valign="top" width="99%" height="99%" style="overflow:auto">';
	
			if(! document.thisIsFeatureView && st[encount] && st[encount].length > 12){
				suspendtrap=1;
				thehtml += '                    <table cellspacing="4" cellpadding="0" border="0" width="920" height="470" >';
			} else {
				thehtml += '                    <table cellspacing="4" cellpadding="0" border="0" width="920" height="470" >';
			}

			thehtml += '                            <TR><TD valign="top" align="left" width="430" height="440" style="min-width: 440px">';

	
			if((! document.thisIsFeatureView) && v[encount] && (v[encount] == 'H')){
				writeqt(enid);
			} else {
				var tarid = '0000000000';
				if(featuredimage){tarid = featuredimage;} else {tarid= enid;}
				thehtml += '                                    <div style="position:relative"><A HREF="javascript:currentpage();">';

				//want to wmark but maybe cant on this browser
				thehtml += '<img src="http://globaldyn.ipnstock.com/dyn_images/'+
					( (typeof(localwatermark) != 'undefined' && ! pngsupport) ? 'wm' : '420' )
					+'/60/'+tarid+'.JPG" border=1 style="display:inline; clear:none;" id="'+tarid+'">';

				if (typeof(localwatermark) != 'undefined' && pngsupport)
					thehtml += '<img style="z-index: 300; position:absolute; left:0px; bottom:0px;" src="'+localwatermark+'" border="0" onload="fitMeTo(\''+tarid+'\', this)"/>';
				
				thehtml += '</A></div>';
			}
			thehtml += '                                   <BR></td>';

			if(! document.thisIsFeatureView && st[encount] && st[encount].length > 12){
				thehtml += '<TD valign="top" align="left" width="120" height="440">';//overflow: auto; safari hack
				thehtml += '<div style="position:relative; overflow: auto; overflow-y: auto; overflow-x: hidden; height:75%">'; //wraper for scroll on large # of sim images
				thehtml += "<B>Similar Images:</B><BR>";
				var simlist =st[encount];
				var simarray=simlist.split(" ");
				var temparray = simarray[1].split(",");
				if(temparray.length > 1){temparray=simarray[0] + ' ' + temparray.join(' ');simarray=temparray.split(' ');}
				var simcount =simarray.length;
				if(simcount>40){simheight=(70 - simcount/2)} else {simheight=70 - simcount;}
				for(var i=0;i< simcount;i++){
					thehtml += '<span valign=bottom style="float:left;">';
					thehtml += '<a href="javasc' + 'ript:enlarge2(\'' + enid + '\'' + ',' + '\'' + encount + '\',\'' + simarray[i] + '\');" TITLE="ID:' + simarray[i];
					if(showphotographer == 1){thehtml += '  \r&copy; ' + myphotographer;}
					thehtml += ' click image to view similar"><img src=http://globaldyn.ipnstock.com/dyn_images/135/50/' + simarray[i] + '.JPG border=0 vspace=2 hspace=2 height=' + simheight + ' align=left></a></span>';
				}
				thehtml += '</div></TD>';
			}

			thehtml += '<TD align="left" valign="top" width="320"><BR>';

			if (preMem == 'cartview')
			{
				thehtml += '<A HREF="javascript:currentLayer1Mode=document.currentLayer1Mode=\'cartview\'; viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom());currentpage();"><FONT style="font-size:9pt; font-family:Arial;">&#8593;</font> BACK TO CART</A><BR><BR>';
			}
			else if (document.thisIsFeatureView)
			{
				thehtml += '<A HREF="javascript:currentLayer1Mode=document.currentLayer1Mode=\'searchresults\'; viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom()); window.location = window.location"><FONT style="font-size:9pt; font-family:Arial;">&#8593;</font> BACK TO REQUEST RESULTS</A><BR><BR>';
			}
			else
			{
				thehtml += '<A HREF="javascript:currentLayer1Mode=document.currentLayer1Mode=\'searchresults\'; viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom());currentpage();"><FONT style="font-size:9pt; font-family:Arial;">&#8593;</font> BACK TO SEARCH RESULTS</A><BR><BR>';
			}

			if(preMem != 'cartview')
			{
				if((snum + encount) > 0){thehtml += '                                  <A HREF="javascript:enlarge2(\'' + previmageid + '\',\'' + previmage + '\');" TITLE="GO TO THE PREVIOUS IMAGE"><FONT style="font-size:9pt; font-family: Arial;">&#8592;</FONT> PREV IMAGE </A>&nbsp;&nbsp;';}
				if((Number(snum) + Number(encount) + 1) < Number(total)){thehtml += '                                  <A HREF="javascript:enlarge2(\'' + nextimageid + '\',\'' + nextimage + '\');" TITLE="GO TO THE NEXT IMAGE">NEXT IMAGE <FONT style="font-size:9pt; font-family: Arial;">&#8594;</FONT></A><BR>';}
			}

			thehtml += '<BR><a href="javascri' + 'pt: lightbox_addto(\'';
			if(featuredimage){thehtml += featuredimage;} else {thehtml += enid;}
			thehtml += '\');"><img src="/graphics/icon_lightbox.gif" width=21 height=15 border=0 alt=""> ADD TO CURRENT LIGHTBOX</a><BR>';
			thehtml += '<a href="javascri' + 'pt: license(\'';
			if(featuredimage){thehtml += featuredimage;} else {thehtml += enid;}
			
			thehtml += '\');"><img src="/graphics/icon_price.gif" width=21 height=15 border=0 alt=""> CHECK USAGE RATES</a><BR>';
			///bin/Cklb?atct=
			thehtml += '<a href="javascript: cart_addto(\'';
			if(featuredimage){thehtml += featuredimage;} else {thehtml += enid;}
			thehtml += '\');"><img src="/graphics/icon_cart.gif" width=21 height=15 border=0 alt=""> ADD TO SHOPPING CART</a><BR>';

			if(preMem != 'cartview')
			{
				if(gsession && gusername && mycompallow == 'Y') { //&& ! document.thisIsFeatureView && ! document.thisIsFeatureView
					thehtml += '<a href="Javascr' + 'ipt:displayWindow(\'/comp_view.shtml?' + gusername + '/' + cs[encount] + '/';
					if(featuredimage){thehtml += enid + ',' + featuredimage;} else {thehtml += enid;}
					thehtml += '.JPG\',\'600\',\'640\');"><img src="/graphics/icon_comp.gif" width=21 height=15 alt="" border="0"> DOWNLOAD COMP</a><BR><BR>';
				} else {
				if(gsession) {
					thehtml += '<a href="Javascr' + 'ipt:displayWindow(\'/comp_view.shtml?guest/' + cs[encount] + '/';
					if(featuredimage){thehtml += enid + ',' + featuredimage;} else {thehtml += enid;}
					thehtml += '.JPG\',\'600\',\'640\');"><img src="/graphics/icon_comp.gif" width=21 height=15 alt="" border="0"> DOWNLOAD COMP</a><BR><BR>';
					}
				}
			}
	
	// META DATA FOR ENLARGED TARGET IMG:
	
			if (myratetiers != '')
				thehtml += '<BR/><span style="color:#C01920;">' + myratetiers + '</span>';
			thehtml += '<BR><b>Image Number:</b> ';
			if(featuredimage){thehtml += featuredimage;} else {thehtml += enid;}
			thehtml += '&nbsp['+myrmrftype+']';
	
			thehtml += '<br><b>Caption:</b> ' + myshortcaption + '<br>';
	
			if(showrelease){thehtml += '<b>Release:</b> ' + myreleased + '<br>';}
			var linked_photog = myphotographer;
			if(myphotographer.indexOf('/') > 0)
			{
				linked_photog = linked_photog.substring(0, linked_photog.indexOf('/'));
			}
			if(showphotographer){thehtml += '<b>Photographer:</b> <A href="/SwishSearch?Keywords=' + linked_photog + '&spec_idx=ne">' + myphotographer + '</a><br>';}
	
			if(featuredimage){
			} else {
				if(showfilesize){thehtml += '<b>File Size:</b> ' + myfilesize;}
			}
			
			if(myrestrictions)
				thehtml += '<BR/><span style="color:#990000">'+myrestrictions+'</span>';

			//get position of lbbutons in order to size keywords properly
			
			thehtml += '<BR><A class="olink" onclick="javascript:popkeys2(\'enlarge_keywords\', this);">Show keywords</A><BR>';
			thehtml += '<div id="enlarge_keywords" style="display:none; overflow-y:auto;">';
			
			document.JSONobj.getKeywords().each(function (kwd){
				var relink = q_args;
				//e.g. Keywords=shot%20put+haspeople+NOT+imagehasrestrictions
				if(relink.match(/Keywords=[^\+\&]+\+/))
				{
					relink = relink.replace(/Keywords=[^\+]+\+/, 'Keywords='+kwd+'+');
				}
				else if (relink.match(/Keywords=[^\+\&]+\&/))
				{
					relink = relink.replace(/Keywords=[^\+\&]+\&/, 'Keywords='+kwd+'&');
				}
				else if (relink.match(/Keywords=[^\+\&]+$/))
				{
					relink = relink.replace(/Keywords=[^\+\&]+$/, 'Keywords='+kwd);
				}
				else //might be lightbox or request, but so no actual keywords, so append it directly
				{
					relink = relink.replace(/((rid|\&rid)|(vmo|\&vmo)|(lb_view|\&lb_view)|(cartview|\&cartview))=[^\&]+/, '');
					relink = 'Keywords='+kwd+'&'+relink;
					relink = relink.replace(/\&+/, '&');
				}
				relink = relink.replace('&spec_idx=ne', '');
				thehtml += '<a href="/SwishSearch?' + relink +'&spec_idx=ne">' + kwd + '</a>, ';
			});
			thehtml += '</div>';
			
			//calculate similars
			thehtml += '</td></TR></table>';
	// END META DATA FOR ENLARGED TARGET IMG:
	
			thehtml += '<BR></td></TR></table>';
			//write html for enlarge page
			MM_setTextOfLayer('Layer1','',thehtml);
			MM_preloadImages('http://globaldyn.ipnstock.com/dyn_images/420/60/' + nextimageid + '.JPG');
			//suspendtrap=0;
			setbackpagetrap('ss',firstpictureonpage,'ss');
		} 
		else {
			//alert("This is the last image of the search results.");
			gsetCookie('gviewmode','ss', '', '/', gGetCookieDom());

			self.location= nextlink + 'snum=' + (Number(firstpictureonpage) + Number(snum)); //figure out which should be first picture on next page	
		}//end if id[enid]	
	}
	else if ( tryCtr < 10 ) 
	{
		tryCtr++;
		setTimeout("enlarge2_act('"+enid+"','"+encount+"','"+featuredimage+"', '"+tryCtr+"', 0, '"+preMem+"')", (500 + (10 * (tryCtr - 1))));
	}
	else // nothing loaded, pop the page w/ missing data..
	{
		enlarge2_act(enid,encount,featuredimage,tryCtr,1,preMem);
	}
	
};

function fitMeTo(targetid, thar) {
	if (! targetid || ! thar || ! $(targetid))
	return;

	var dems = Element.getDimensions(targetid);

	if (thar.style)
	{
		thar.style.width = (dems['width']+8) + 'px';	
 		thar.style.height = (dems['height']+8) + 'px';
	}
	return 1;
};

function writesearch(){
	var thehtml = '<form action="javasc' + 'ript:g(); return false;" method=get name=displaypanel id=displaypanel>';
	panelheight=300;
	if (typeof(showIllusPhotog) != 'undefined'){ //if adding Illustration / Photography selector checkboxes
		panelheight += parseInt(showIllusPhotog);
	}
	
	gsearchprefs=ggetCookie('gsearchprefs');
	var temph=' checked';
	var tempv=temph;
	var temps=tempv;
	var tempp=tempv;
	var temprno='';
	var temprany=tempv;
	var temppeopany=tempv;
	var temppeopwith='';
	var temppeopwithout='';
	var temppeopcrowd='';
	var temprelany=tempv;
	var temprelonly='';
	var tempcolany=tempv;
	var tempcolcol='';
	var tempcolbw='';
	var rmc="checked";var rfc=rmc;

        var tempillustration=' checked';
        var tempphotography= tempillustration;

	var tempsearchnew = ' selected';
	var tempsearchwithin = '';


	if(gsearchprefs){
		if(gsearchprefs.indexOf("f")>=0 || gsearchprefs.indexOf("g")>=0 || gsearchprefs.indexOf("h")>=0 || gsearchprefs.indexOf("i")>=0){
			if(gsearchprefs.indexOf("f")>=0){ } else {
				temph=' ';
			}
			if(gsearchprefs.indexOf("g")>=0){ } else {
				tempv=' ';
			}
			if(gsearchprefs.indexOf("h")>=0){ } else {
				tempp=' ';
			}
			if(gsearchprefs.indexOf("i")>=0){ } else {
				temps=' ';
			}
		}

                if (typeof(showIllusPhotog) != 'undefined'){ //if adding Illustration / Photography selector checkboxes
			if(gsearchprefs.indexOf("1")<=0 && gsearchprefs.indexOf("0")<=0){ }
			else
			{
				if(gsearchprefs.indexOf("1")<=0){ tempphotography=' '; } 
				if(gsearchprefs.indexOf("0")<=0){ tempillustration=' '; } 
			}
                }

		if (typeof(showSearchWithin) != 'undefined'){
			if ( $('method') && $F('method') == 'within')
			{
				tempsearchnew = '';
				tempsearchwithin = 'selected';
			}
			else
			{
				tempsearchnew = 'selected';
				tempsearchwithin = '';
			}
// 			thehtml += '<nobr>&nbsp;<select id="method" name="method" class="smallmenu" style="height:16px;"><option selected value="new">as a new search</option><option value="within">within current results</option></select></nobr><br/>';
		}

		if(gsearchprefs.indexOf("j")<0 || gsearchprefs.indexOf("k")<0){
			if(gsearchprefs.indexOf("k")<=0 && gsearchprefs.indexOf("j")<=0 ){ }
			else
			{
				if(gsearchprefs.indexOf("k")<=0){// && ! gsearchprefs.indexOf("k")>=0){
					rfc = "";
				}
				if(gsearchprefs.indexOf("j")<=0){// && ! gsearchprefs.indexOf("j")>=0){
					rmc = "";
				}
			}
		}
		if(gsearchprefs.indexOf("b")>=0){ //restrictions
			temprany='';
			temprno='checked';
		}
		if(gsearchprefs.indexOf("c")>=0 || gsearchprefs.indexOf("d")>=0 || gsearchprefs.indexOf("e")>=0)
		{
			if(gsearchprefs.indexOf("c")>=0) //without people
			{
				temppeopany = '';
				temppeopwith = '';
				temppeopwithout = 'checked';
				temppeopcrowd = '';
			}
			if(gsearchprefs.indexOf("d")>=0) //with people
			{
				temppeopany = '';
				temppeopwith = 'checked';
				temppeopwithout = '';
				temppeopcrowd = '';
			}
			if(gsearchprefs.indexOf("e")>=0) //with crowd
			{
				temppeopany = '';
				temppeopwith = '';
				temppeopwithout = '';
				temppeopcrowd = 'checked';
			}
		}
		if(gsearchprefs.indexOf("a")>=0){
			temprelonly = 'checked';
			temprelany = '';
		}
		if(gsearchprefs.indexOf("m")>=0 || gsearchprefs.indexOf("n")>=0 || gsearchprefs.indexOf("o")>=0)
		{
			if(gsearchprefs.indexOf("m")>=0) //any
			{
				tempcolany='checked';
				tempcolcol='';
				tempcolbw='';
			}
			if(gsearchprefs.indexOf("n")>=0) //
			{
				tempcolany='';
				tempcolcol='checked';
				tempcolbw='';
			}
			if(gsearchprefs.indexOf("o")>=0) //
			{
				tempcolany='';
				tempcolcol='';
				tempcolbw='checked';
			}
		}
	}
	thehtml += '<table cellspacing=0 cellpadding=10 border=0 width=100% height=' + panelheight + '>';
	thehtml += '<tr><td valign=top align=left class="light1">';
	thehtml += '<b>ORIENTATION:</b><br>';
	thehtml += '<table cellspacing=3 cellpadding=0 border=0><tr>';
	thehtml += '<td><nobr><input type=checkbox name=orient value=horizontal onclick=javasc' + 'ript:fsearchprefs("f","add"); ' + temph + '> Horizontal</nobr></td></tr>';
	thehtml += '<tr><td><input type=checkbox name=orient value=vertical onclick=javasc' + 'ript:fsearchprefs("g","add"); ' + tempv + '> Vertical</td></tr>';
	thehtml += '<tr><td><input type=checkbox name=orient value=panoramic onclick=javascr' + 'ipt:fsearchprefs("h","add"); ' + tempp + '> Panororamic</td></tr>';
	thehtml += '<tr><td><input type=checkbox name=orient value=square onclick=javasc' + 'ript:fsearchprefs("i","add"); ' + temps + '> Square</td></tr>';
	thehtml += '</table><br>';
	thehtml += '<b>COLOR:</b><br>';
	thehtml += '<table cellspacing=3 cellpadding=0 border=0>';
	thehtml += '<tr><td><nobr><input '+tempcolany+' type=radio name=color value="" onclick=javascr' + 'ipt:fsearchprefs("color","add");> ANY</td></tr>';
	thehtml += '<tr><td><nobr><input '+tempcolcol+' type=radio name=color value=color onclick=javascr' + 'ipt:fsearchprefs("color","add");> COLOR</td></tr>';
	thehtml += '<tr><td><input '+tempcolbw+' type=radio name=color value=gray onclick=javascr' + 'ipt:fsearchprefs("color","add");> B/W</td></tr>';
	thehtml += '</table>';

/*	<BR><b>TYPE:</b><br>';
	thehtml += '<table cellspacing="0" cellpadding="3" border="0"><tr><td><font class="black2"><nobr><input type="checkbox" name="rmrftype" value="RM" ' + rmc + ' onclick=javascr' + 'ipt:fsearchprefs("RM","add");> Rights Managed</nobr></font></td>';
	thehtml += '</tr><tr><td><font class="black2"><input type="checkbox" name="rmrftype" value="RF" ' + rfc + ' onclick=javascr' + 'ipt:fsearchprefs("RF","add");> Royalty Free</font></td></tr></table></td>';  */

        if (typeof(rmonly) == 'undefined'){
                thehtml += '<BR><b>TYPE:</b><br>';
                thehtml += '<table cellspacing="0" cellpadding="3" border="0"><tr><td><font class="black2"><nobr><input type="checkbox" name="rmrftype" value="RM" ' + rmc + ' onclick=javascr' + 'ipt:fsearchprefs("RM","add");> Rights Managed</nobr></font></td>';
                thehtml += '</tr><tr><td><font class="black2"><input type="checkbox" name="rmrftype" value="RF" ' + rfc + ' onclick=javascr' + 'ipt:fsearchprefs("RF","add");> Royalty Free</font></td></tr></table>';
        }


	thehtml += '</td><td valign=top align=left class="light1">';

	if (typeof(showIllusPhotog) != 'undefined'){ 
		thehtml += '<b>MEDIA:</b><br>';
//		thehtml += '<input type="checkbox" name="searchinclude" value="illustration"/>Illustration<br/>';
//		thehtml += '<input type="checkbox" name="searchinclude" value="photography"/>Photography<br/>';
//		thehtml += '<br/>';
               thehtml += '<input type="checkbox" name="searchinclude" value="illustration"' + tempillustration + ' onclick=javascr' + 'ipt:fsearchprefs("0","add"); />Illustration<br/>';
                thehtml += '<input type="checkbox" name="searchinclude" value="photography"' + tempphotography + ' onclick=javascr' + 'ipt:fsearchprefs("0","add"); />Photography<br/>';
                thehtml += '<br/>';
	}

	if (typeof(suspendYesNoRestrictons) == 'undefined'){
		thehtml += '<b>RESTRICTIONS:</b><br>';
		thehtml += '<input '+temprany+' type=radio name=restrictions value="" onclick=javascr' + 'ipt:fsearchprefs("norestrictions","remove");> ANY<br>';
		thehtml += '<input '+temprno+' type=radio name=restrictions value=not+imagehasrestrictions  onclick=javascr' + 'ipt:fsearchprefs("norestrictions","add");> NO RESTRICTIONS<br>';
		thehtml += '<br>';
	}

	if (typeof(suspendWithPeople) == 'undefined'){
		thehtml += '<b>PEOPLE:</b><br>';
		thehtml += '<input '+temppeopany+' type=radio name=people value="" onclick=javasc' + 'ript:fsearchprefs("people","remove");> ANY<br>';
		thehtml += '<input '+temppeopwith+' type=radio name=people value=withpeople onclick=javasc' + 'ript:fsearchprefs("withpeople","add");> WITH PEOPLE<br>';
		thehtml += '<input '+temppeopwithout+' type=radio name=people value=nobody onclick=javascr' + 'ipt:fsearchprefs("nobody","add");> WITHOUT PEOPLE<br>';
		thehtml += '<input '+temppeopcrowd+' type=radio name=people value=withcrowd onclick=javascr' + 'ipt:fsearchprefs("withcrowd","add");> CROWD<br>';
	}

	thehtml += '<br><b>RELEASES:</b><br>';
	thehtml += '<font class=small>';
	thehtml += '<input '+temprelany+' type=radio name=xtrasql value="" onclick=javascr' + 'ipt:fsearchprefs("released","remove");> Any release status<br>';
	thehtml += '<input '+temprelonly+' type=radio name=xtrasql value=released onclick=javascr' + 'ipt:fsearchprefs("released","add");> Only show released images<br>';

// conditional to insert 'search within' box in dropdown:
	if (typeof(showSearchWithin) != 'undefined'){
		thehtml += '<br/><b>METHOD:</b><br/>';
		thehtml += '<nobr>&nbsp;<select id="method" name="method" class="smallmenu" style="height:16px;"><option value="new" '+tempsearchnew+'>as a new search</option><option value="within" '+tempsearchwithin+'>within current results</option></select></nobr><br/>';
	}

	thehtml += '<BR><a href="javascript:g();"><img src="/graphics/button_go.gif" alt="search" border="0"></a><BR><BR><A href="javascript:hidedisplaypanel(1);">[x] close search options panel</A>';
	thehtml += '</td></tr></table>';
	var temp=Position.cumulativeOffset($('tablerow2'));
	center_panel(340,panelheight,thehtml,temp[1]);
	if(browser != 'Internet Explorer'){
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = getMouseXY;
};

function getMouseXY(e) {
  if(browser != 'Internet Explorer'){
    msX = e.pageX
    msY = e.pageY
  } else {
    msX = event.clientX + document.body.scrollLeft
    msY = event.clientY + document.body.scrollTop
  }  
	if( msX < panelx || msY > (panely+panelheight)){
		document.isn.Keywords.blur();
                hidedisplaypanel(1);
        }

};

function displaypanelshow(){
	new Effect.Opacity('displaypanellayer',{duration: .01, from: 0.01, to: 0 });
	$('displaypanellayer').style.visibility="visible";
	$('displaypanellayer').style.zIndex = '1001';
	new Effect.Appear('displaypanellayer', {duration: .5})

	setTimeout("divshim(1);", 200);
};

function divshim (twid) { //simply to have it set-timeoutable..
	if($('DivShim'))//site that has the popup fix for IE6 and below (it can't render form elements behind dom objects)
	{
		if (twid) //on
		{
			$('DivShim').style.width = $('displaypanellayer').style.width;
			$('DivShim').style.height = $('displaypanellayer').style.height;
			$('DivShim').style.top = $('displaypanellayer').style.top;
			$('DivShim').style.left = $('displaypanellayer').style.left;
			$('DivShim').style.zIndex = $('displaypanellayer').style.zIndex - 1;
			$('DivShim').style.display = "block";
		}
		else
		{
			$('DivShim').style.display = "none";
		}
	}
};

function hidedisplaypanel(mode){

	divshim(0);
	if($('displaypanellayer').style && $('displaypanellayer').style.visibility == 'visible'){
		if(mode==1){
			new Effect.Fade('displaypanellayer', {duration: .01})			
		} else {
			new Effect.Fade('displaypanellayer', {duration: .3})
		}
	}
	if($('coverlayer').style && $('coverlayer').style.visibility == 'visible'){
		new Effect.Opacity('coverlayer',{ delay: .22, duration: .3, transition: Effect.Transitions.exponential, from: 0.7, to: 0 });	
		setTimeout("coveroff();",.31);
	}
	setTimeout("$('displaypanellayer').style.visibility='hidden';", .31);
	document.onmousemove = "";
};

function coveroff(){
	coverlayerobj().visibility="hidden";
};

function buildpages(startnumber,endnumber,snum){
        suspendtrap=1;

        //builds pulldown menu for page numbers depending on pixperpage and total pagenumbers
        var thehtml= '<table width="100%"><tr><td valign="top">';

	thehtml+= '<NOBR><FONT class=page>';

	//pagenumbers
	var showstartnumber = parseInt(startnumber) + parseInt(snum) + 1;
	var showendnumber = parseInt(endnumber) + parseInt(snum);

        //conditional previous page
        if(Number(currentpagenum) > 0){
                thehtml+='<A href="javascript:javascript:currentLayer1Mode=document.currentLayer1Mode=\'searchresults\';prevpage();"><FONT style=\"font-size:9pt;font-family: Arial;\">&#8592;</FONT> PREV PAGE</A>&nbsp;';
        } else if (showstartnumber <= total){
                thehtml+='<FONT style=\"font-family: Arial;color:#AAAAAA;\"><FONT style="9pt;">&#8592;</FONT> PREV PAGE</FONT>&nbsp;';
	}

	//alert('e '+showendnumber+' b '+showstartnumber+' t '+total);
	if ( showstartnumber <= total )
	{
		thehtml+='Go&nbsp;to&nbsp;Page:&nbsp;<SELECT name="pageurl" align="absmiddle"  onChange="javascript:currentLayer1Mode=document.currentLayer1Mode=\'searchresults\'; javas' + 'cript:self.location=this.options[this.selectedIndex].value;" class="smallmenu">';
	
		totalpages=(  Math.ceil((snum)/( parseInt( $F('pixperpage') ))) +  Math.ceil( (total - snum) / ( parseInt( $F('pixperpage') )  ))) ;
		if(Number(currentpagenum) > 12){psn = (Number(currentpagenum) - 10);} else { psn = 1;}
	
		if((Number(totalpages) - Number(currentpagenum)) > 10){ pen = (Number(currentpagenum) + 10);} else {pen = totalpages;}
		if(psn >1 && currentpagenum != 0){
			thehtml+='<OPTION VALUE="' + nextlink + 'snum=' + ((psn - 2) * (parseInt(gpixperpagev))) + '">&lt; ' + (Number(psn) - 1) + '</option>';
		}
	
		for(i=psn;i <= pen;i++){
			if(i == (Number(currentpagenum) + 1)){
				thehtml+='<OPTION VALUE="' + nextlink + 'snum=' + ((i-1) * (parseInt(gpixperpagev))) + '" SELECTED>' + i + '</option>';
			} else {
				thehtml+='<OPTION VALUE="' + nextlink + 'snum=' + ((i-1) * (parseInt(gpixperpagev))) + '">' + i + '</option>';
			}
		}
	
		if(pen != totalpages){
			thehtml+='<OPTION VALUE="' + nextlink + 'snum=' + ((Number(pen)) * (parseInt(gpixperpagev))) + '">&gt; ' + (Number(pen) + 1) + '</option>';
		}

		//alert(thehtml);
	
		thehtml+='</select>';
		if(grange != "outofrange"){
			thehtml+='&nbsp;<A HREF="javascript:currentLayer1Mode=document.currentLayer1Mode=\'searchresults\';nextpage();">NEXT&nbsp;PAGE&nbsp;<FONT style="font-size:9pt;font-family: Arial;">&#8594;</FONT></A></font>';
		}

		
		thehtml += '&nbsp;&nbsp;[' + showstartnumber + '-';
		if (showendnumber > parseInt(total)){
			thehtml +=  total + ']&nbsp;of&nbsp;' + total;
		} else {
			thehtml += showendnumber + ']&nbsp;of&nbsp;' + total;
		}
		thehtml += '</NOBR>';

		thehtml += '</td><td align="right">';

		//linkback to feature:
		if (document.thisIsFeatureView)
		{
			thehtml += '<a href="/R?'+feat_requestview+'" style="color:#c00; font-size:10px"><nobr>View images from</nobr> <br/><nobr><b>All IPN Members</b></nobr></a>';
		}

	}

	thehtml += '</td></tr></table>';

	$('Layerpages').style.overflow = 'visible';
        MM_setTextOfLayer('Layerpages','',thehtml);
        //suspendtrap=0;
	//alert (showstartnumber+', '+snum+', '+viewmode);
        setbackpagetrap(showstartnumber,snum,viewmode);

};

function buildimages(startnumber,mode,resized){
	if(typeof(cartview) != 'undefined' && cartview)
		return;

	currentLayer1Mode=document.currentLayer1Mode='searchresults';
	if(!MACIE5){var tshown = Element.getOpacity('coverlayer');}
	
	if(tshown > 0.2){
		//alert('HIDE!');
		hidedisplaypanel();
	}
// 	alert(startnumber);
        suspendcheck=1;
        //calculate how many images can be held on the page depending on mode being used
        if(startnumber > 1 || resized==1){setuppagesize();}

        //  build the page
	showstartnumber_trap = parseInt(startnumber);  //save for later
        var thehtml=optimize() + '<FORM name=activedisplay action=#>';
        grange="legal";
        MM_setTextOfLayer('Layer1','','<CENTER> <BR><BR><BR><BR><BR><BR><BR><BR>loading ...</CENTER>');
        var cnt=startnumber;
        //figureout current range of images to show
        firstpictureonpage=startnumber;
        endnumber = parseInt(gpixperpagev) + parseInt(startnumber);

        if (viewmode != "ss"){
                //loop through images in the array and build html
				if(pagetype=='lb' && (typeof(pre_q_args) != 'undefined' && ! ( pre_q_args.match(/lb_view=1/) || pre_q_args.match(/fn=/) || pre_q_args.match(/vmo=/) ) ) )
					thehtml += '&nbsp;&nbsp;<A href="" onclick="viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom()); window.location=\'/SwishSearch'+pre_q_args+'\'; return false;"><FONT style="font-size:9pt; font-family:Arial;">&#8593;</font> BACK TO SEARCH RESULTS</A><BR/><BR/>';

                while(cnt < (endnumber)){
                        if( id[cnt] ){
                                thehtml += htmlit(cnt);
                        } else {
                                if((snum + cnt)>=total){
                                        if (grange != "outofrange"){
                                                thehtml+='<span valign=bottom style="float:left;"><div align=center valign=bottom style="width:130; height:50px; overflow: hidden;">';

                                                if(pagetype=='lb'){
							thehtml+='<BR><nobr>&nbsp;[ end of lightbox images ]&nbsp;</nobr></DIV></SPAN> ';
                                                } else {
							thehtml+='<BR><nobr>&nbsp;[ end of search results ]&nbsp;</nobr></DIV></SPAN> ';
						}
                                        }

                                        grange="outofrange";

                                } else {
                                        grange="illegalpage";   //check to see if page numbers are out of the legal range of images
                                }
                        }
                        cnt++;

                }
               //conditions below are for going ahead or behind available imagenumber ranges
                if (grange == "illegalpage"){
                        if (mode == "next"){
				//alert('buildim illegal '+firstpictureonpage+'+'+snum);
                                self.location= nextlink + 'snum=' + (Number(firstpictureonpage) + Number(snum)); //figure out which should be first picture on next page
                                 MM_setTextOfLayer('Layer1','','<CENTER> <BR><BR><BR><BR><BR><BR><BR><BR>loading next set of images...</CENTER>');
                        } else {

                                // two ways to go with this code
                                // method a is one screen at a time
                                //prevtogoto = snum + startnumber;

                                // method b is two screens at a time
                                prevtogoto=Number(snum) + Number(startnumber) - parseInt($F('pixperpage')); // go back two pages from start page
                                //gsetCookie("gwhichstartpage",parseInt($F('pixperpage')), '', '/', gGetCookieDom());
                                // ensure no negative numbers
                                if(prevtogoto < 0 ){ prevtogoto=0;}
				//alert('buildim illegal not next');
                                self.location=nextlink + 'snum=' + prevtogoto;

                        }

                } else {

                        //normal page ranges - add lower right next page link

                        thehtml+= "<BR clear=all><table width=99% height=17 cellpadding=0 cellspacing=0 border=0><TR><TD align=left width=10%>";
                        if ((typeof(snum) != 'undefined' && Number(snum) > 1) || ( typeof(startnumber) != 'undefined' && Number(startnumber) > 1)){
                                thehtml+= "<nobr>&nbsp;&nbsp;<A HREF=javasc" + "ript:prevpage();><FONT style=\"font-size:9pt;font-family: Arial;\">&#8592;</FONT> PREV PAGE</A></nobr>";
                        } else {
                                thehtml+= "&nbsp;";
                        }

                        thehtml+= "</TD><TD align=center width=80%>" + footer() + "</TD><TD align=right>";

                        if (grange != "outofrange"){
                                thehtml+= "<nobr><A HREF=javasc" + "ript:nextpage(); name=bottomnext>NEXT PAGE <FONT style=\"font-size:9pt;font-family: Arial;\">&#8594;</FONT></A>&nbsp;&nbsp;</nobr></DIV>";
                                //reset the page numbersw

                        } else {
                        }
                        thehtml+= "</TD></TR></FORM></table>";
                        MM_setTextOfLayer('Layer1','',thehtml);


                        // preload next page worth of images
                        lastimage=cnt;
                      	if($('pixperpage')){
				prestart=endnumber;
				preend=(lastimage + parseInt($F('pixperpage')));
                       		if(startnumber==0){
					var delay=6000 + parseInt($F('pixperpage') * 30);
                       		         self.setTimeout("preloadnextpage()",delay);
                       		} else {
					var delay=1000;//delay just a bit to make several next page load requests have time to catch up
                       		         self.setTimeout("preloadnextpage()",delay);
                        	}
			}
                }
        } else {
                //ss mode
                enlarge2(id[0],0); // new page and slideshow mode
        }

	

        currentpagenum = Math.ceil(         (      Number(snum) + Number(startnumber)         ) /      parseInt($F('pixperpage'))            );
	//alert(startnumber+', '+endnumber+', '+snum);
        buildpages(startnumber,endnumber,snum);
};

function writesimilar(myid,showid,myphotographer,myshortcaption,action,mode,myhrdlink) {
        var simlist =st[showid];
        var simarray=simlist.split(" ");
	var temparray = simarray[1].split(",");
	if(temparray.length > 1){temparray=simarray[0] + ' ' + temparray.join(' ');simarray=temparray.split(' ');}
	var simcount =simarray.length;
	if(mode =='normal' || mode=='huge'){
        	if(parseInt(simcount) < 5 ){simindicator=simcount;} else {simindicator=4;}
	} else {
        	if(parseInt(simcount) < 4 ){simindicator=simcount;} else {simindicator=3;}
	}
        var thehtml='';
        var wmyid = myid;
    var setid = myid;
    var iconheight=15;var iconwidth=15;

        if (action == 'next'){

                var n=sw[showid];
                n++;
                sw[showid] = n;
                if(sw[showid] >= simcount) { sw[showid]=0;n=0;}
                wmyid = simarray[n];

        } else if (action == 'prev'){
                var n=sw[showid];
                n--;
                sw[showid] = n;
                if(sw[showid] < 0) { sw[showid]=simcount - 1;n=simcount - 1;}
                wmyid = simarray[n];
        }
	//empty array fix for a single image returned which is a similar
	//alert(sw[showid] + 1);
	if ( isNaN((sw[showid] + 1)) )
		sw[showid] = 0;
		var theight = 172 + adminheight;
        if (mode == 'list'){
                                thehtml += '<TABLE width=298 cellspacing=2 cellpadding=0 border0 height=' + theight + '><TR><TD valign=top width=149 align=center>';

        }
        // similar graphics zzz
        thehtml += '<table cellpadding=0 cellspacing=0 border=0><TR><TD colspan=2 align=right valign=bottom bgcolor=#c9c9c9 width=18 height=18>';
        thehtml += '<a href="javasc' + 'ript:enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\', \''+wmyid+'\');" TITLE="ID:' + wmyid;
        if(showphotographer == 1){'  \r&copy; ' + myphotographer;}
        if(showfilesize){thehtml += '  \rSIZE: '+ myfilesize;}
        thehtml += '  \r' + 'CAPTION: ' + myshortcaption;
        if (mode == 'huge'){
                thehtml += '"><img src="http://globaldyn.ipnstock.com/dyn_images/420/60/' + wmyid + '.JPG" border="0" alt="loading..." height="190"></a></TD>';
        } else if( mode == 'med'){
                iconheight=10;iconwidth=14;
                thehtml += '"><img src="http://globaldyn.ipnstock.com/dyn_images/135/50/' + wmyid + '.JPG" border="0" vspace="0" hspace="0" alt="loading..." height=72></a></TD>';
        } else if( mode == 'tiny'){
                iconheight=8;iconwidth=12;
                thehtml += '"><img src="http://globaldyn.ipnstock.com/dyn_images/135/50/' + wmyid + '.JPG" border="0" vspace="0" hspace="0" alt="loading..." height=45></a></TD>';

        } else {
				iconheight=12;iconwidth=16;
                thehtml += '"><img src="http://globaldyn.ipnstock.com/dyn_images/135/50/' + wmyid + '.JPG" border="0" vspace="0" hspace="0" alt="loading..."></a></TD>';
        }
        //simindicator="";

        thehtml += '<TD background=/graphics/similars_rc' + simindicator + '.gif valign=top width=9><IMG SRC=/graphics/similars_ru' + simindicator + '.gif width=12 height=9></TD></TR><TR height=8>';
        if(mode == 'normal' || mode=='huge'){
		thehtml += '<TD background=/graphics/similars_ll' + simindicator + '.gif height=8 width=12></TD><TD background=/graphics/similars_lc' + simindicator + '.gif height=8><div style="width: 18px;height:8px;padding:0;margin:0;"></DIV></TD>';
	} else {
		thehtml+='<TD colspan=2 background=/graphics/similars_lc' + simindicator + '.gif height=8></TD>';
	}
	thehtml += '<TD width=12 height=8 background=/graphics/similars_lr' + simindicator + '.gif></TD></TR></TABLE>';

        if(mode == 'normal' || mode =='med' || mode == 'tiny'){
                thehtml += '<Table cellpadding=0 cellspacing=0 border=0><TR><TD valign=top align=center>';
        }


          thehtml += '<DIV class=icons><a href=javascr' + 'ipt:lightbox_addto(\'' + wmyid + '\'); class=iconlink title="Add to your current lightbox">LB+</a>';
          thehtml += '<a href="" onclick="return price_image(\'' + wmyid + '\',\''+rm[wmyid]+'\');" class=iconlink Title="Price Image">$</a>';
          thehtml += '<a href="javasc' + 'ript:enlarge2(\'' + wmyid + '\'' + ',' + '\'' + showid + '\');" class=iconlink title="Enlarge image and more info"><font class=eye>i</font></a>';
        if(mode == 'huge'){
                thehtml += '<font class=xsmall>' + wmyid + '</font>&nbsp;&nbsp;' + (typeof(myhrdlink) != 'undefined' ? myhrdlink : '')+'&nbsp;&nbsp;';
	} else if (mode == 'list') {
		thehtml += '&nbsp;&nbsp;'+ (typeof(myhrdlink) != 'undefined' ? myhrdlink : '')+'</DIV>';
        } else {
        	thehtml += '</DIV>';
	}
        if(mode == 'normal' || mode =='med' || mode == 'tiny'){
        //   thehtml += '<BR>';
        }

        if(mode =='med' || mode == 'tiny'){
                thehtml += '<font class=xsmall>' + wmyid + '</font>';
                thehtml += '</TD><TD valign=top align=center width=40><nobr>';
        }
        if (mode == 'list' || mode == 'normal'){
                thehtml += '</TD><TD valign="top">';
        }

        thehtml += '<A HREF="javascript:writesimilar(\'' + setid + '\',\'' + showid + '\',\'';
        thehtml += myphotographer + '\',\'';
        thehtml += myshortcaption + '\',\'prev\',\'' + mode + '\');" TITLE="show similars">';
        thehtml += '<IMG SRC="/graphics/similars_prev.gif" border="0" hspace="1" height="' + iconheight + '" width="' + iconwidth + '" align="absmiddle"></A>';

        if (mode == 'list' || mode == 'huge' || mode == 'normal'){
                thehtml += '<font class=xsmall>' + (sw[showid] + 1) + ' of ' + simcount + '</font>';
        }

        thehtml += '<A HREF="javascript:writesimilar(\'' + setid + '\',\'' + showid + '\',\'';
        thehtml += myphotographer + '\',\'';
        thehtml += myshortcaption + '\',\'next\',\'' + mode + '\');" TITLE="show similars">';
        thehtml += '<IMG src="/graphics/similars_next.gif" border="0" hspace="1" height="' + iconheight + '" width="' + iconwidth + '" align="absmiddle"></A></nobr><BR>';
        if (mode =='med' || mode == 'tiny'){
                thehtml += '<font class=xsmall>' + (sw[showid] + 1) + ' of ' + simcount + '</font>';
        }

        if (mode == 'list'){
                thehtml += '<font class=xsmall>ID:' + wmyid;
                if(showphotographer == 1){thehtml +='  <BR>&copy; '+currentYear+' ' + myphotographer;}
                if(showfilesize){thehtml += '<nobr>' + myfilesize + '</nobr>';}
                thehtml += myreleased + '<BR>CAPTION: ' + myshortcaption + '</font><BR>';
        }
	if (mode== 'huge'){
		thehtml += '</DIV>';
	}
        thehtml += '</td></TR></TABLE>';

        if (action == 'start'){
                return thehtml;
        }
        if (action == 'prev'){
                MM_setTextOfLayer( 'd' + setid,'',thehtml);
        }
        if (action == 'next'){
                MM_setTextOfLayer( 'd' + setid,'',thehtml);
        }
};

function currentpage(){
	setuppagesize(); 	
	
	if (document.currentLayer1Mode == 'searchresults')
	{
        	buildimages( ( firstpictureonpage ? firstpictureonpage : 0 ),0);
	}
	else if (document.currentLayer1Mode == 'cartview')
	{
		cart_display();
	}
	$('coverlayer').style.width = winW + 'px';
	if($('Layer1')){
		$('Layer1').style.height = ( document.currentLayer1Mode == 'cartview' || document.currentLayer1Mode == 'enlarge' ? truevertHeight : winH ) + 'px';

		if($('lbbuttons'))
		{
			$('coverlayer').style.height = 
			( Position.cumulativeOffset($('lbbuttons'))[1] - Position.cumulativeOffset($('row2'))[1]  + Element.getHeight("lbbuttons") ) + 'px';// + 'px';//$('Layer1').style.height;
		}
		else
		{
			$('coverlayer').style.height = (winH + 30) + 'px';
		}

		$('coverlayer').style.width = $('Layer1').style.width;
		$('coverlayer').style.top = Position.cumulativeOffset($('row2'))[1] + 'px'//$('Layer1').style.top;
		$('coverlayer').style.left = Position.cumulativeOffset($('row2'))[0]  + 'px'//$('Layer1').style.left;
		var temptop = (trueh - Element.getHeight("LBdiv") -1);	
	}
};

function setuppagesize(){
	if( typeof(hrdl) != 'undefined' && hrdl[0] && hrdl!=''){
		adminheight=11;
	} else {
		adminheight=0;
	}
		
	if(self.innerWidth && self.innerHeight){
		winW = self.innerWidth;
		trueh = self.innerHeight;
	} else {
		winW = document.body.offsetWidth - 0;
		trueh = document.body.offsetHeight - 0;
	}
	if (document.documentElement.clientHeight && document.documentElement.clientHeight > trueh && (typeof(viewmode) != 'undefined' && (viewmode != 'med' || yourBrowse == 'IE' ) ))
	{
		trueh = document.documentElement.clientHeight - 0;
	}

	//alert(trueh+ ' r2H: '+Element.getHeight("row2")+ ' r2O: '+Position.cumulativeOffset($('row2'))[1]);
	safetyspace = 8;
	menuheight = 20;
//	if(browser == 'Safari'){menuheight = menuheight + 6;}
	truew = winW;
	winH = parseInt(trueh) - parseInt(Element.getHeight("row2")) - Position.cumulativeOffset($('row2'))[1];
	if(typeof(currentLayer1Mode) != 'undefined' && currentLayer1Mode == 'enlarge')
	{
		winH = winH - safetyspace;
	}
	else
	{
	 	winH = winH - safetyspace - menuheight;
	}
	//alert('winH is trueh ' + parseInt(trueh) + '  - height of the row2 ' + parseInt(Element.getHeight("row2")) + ' - top of row 2 ' +  Position.cumulativeOffset($('row2'))[1] + ' minus menuheight ' + menuheight + ' which is ' + winH  )

	if(gsession){//logged in
		if(document.getElementById('LBdiv')){//lightbox is present measure height
			var lbh = parseInt(Element.getHeight("LBdiv"));
			if(lbh < 55){//be safe and leave room
				winH=winH - 100;
			} else {
				winH=winH - lbh;
			}
		} else {
			winH=winH - 100;
		}
	//	alert('due to LBwinH2 altered to ' + winH);
	}
	imagerows=Math.floor(winH/(166 + adminheight));
	imagespaceheight=imagerows * (166 + adminheight);
	area=imagerows * Math.floor(winW/152);

	if(! viewmode && imagerows == 1)
	{
		viewmode='med';
		gsetCookie('gviewmode','med', '', '/', gGetCookieDom());
	}

	if(viewmode){
		if(viewmode == 'table'){
			imagerows=Math.floor(winH/(166 + adminheight));
			if(imagerows == 0)
				imagerows=1;
			imagespaceheight=imagerows * (166 + adminheight);
			area=imagerows * Math.floor(winW/152);
		} else 	if(viewmode == 'list'){
			imagerows=Math.floor(winH/(172.00 + adminheight));
			if(imagerows == 0)
				imagerows=1;
			imagespaceheight=imagerows * (172 + adminheight);
			area=imagerows * Math.floor(winW/300.00);
		} else 	if (viewmode == 'tiny'){
			imagerows=Math.floor(winH/(100.00 + adminheight));
			if(imagerows == 0)
				imagerows=1;
			imagespaceheight=imagerows * (106 + adminheight);
			area=imagerows * Math.floor(winW/96.00);
		} else if (viewmode == 'med'){
			imagerows=Math.floor(winH/(120.00 + adminheight));
			if(imagerows == 0)
				imagerows=1;
			imagespaceheight=imagerows * (120 + adminheight);
			area=imagerows * Math.floor(winW/140.00);
		} else if (viewmode == 'huge'){
			imagerows=Math.floor(winH/(220.00 + adminheight));
			if(imagerows == 0)
				imagerows=1;
			imagespaceheight=imagerows * (220 + adminheight);
			area=imagerows * Math.floor(winW/330.00);
		}
			
	}
	if(currentLayer1Mode == 'enlarge'){
			imagespaceheight=winH - menuheight;
		}
	truevertHeight = winH;

	winH=imagespaceheight + menuheight; // restore it to accomodate narrowbar and footer
	//alert(winH);
	if(winH<450){
		smallscreen=1;
	}
	if(area > 0){
		totalimagesthatcanfit=area;
		gpixperpagev=totalimagesthatcanfit;
	} else {
		// load images per page into field
		gpixperpagev = ggetCookie('gpixperpage');
		if(! gpixperpagev)
			gpixperpagev=12;
	}


};

function preloadnextpage(){
        preloadcurrent=prestart;
        preloadnextimg();
};

function preloadnextimg(){
        preloadcurrent++;
        // preload till the next page's images are loaded and stop preloading if next page is clicked
        if(preloadcurrent < preend && endnumber < preend){
                objImage = new Image();
                objImage.onLoad=setTimeout("preloadnextimg();",10);//recursive to itself
                objImage.src='http://globaldyn.ipnstock.com/dyn_images/135/50/' + id[preloadcurrent] + '.JPG';
        }
	//return preloadcurrent+' < '+preend+' && '+endnumber+' < '+preend;
};

function nextpage(){
        buildimages(lastimage,"next");
};

function prevpage(){
        backpagestart=lastimage - ( 2 * parseInt($F('pixperpage')));
        if((backpagestart) < 0){ // past this set of images
                if((backpagestart + snum) < 0){
                        prevtogoto=0;
                } else {
                        prevtogoto=Number(snum) + Number(backpagestart); // go back two pages from start page
                        gsetCookie('gwhichstartpage','0', '', '/', gGetCookieDom());
                        if(prevtogoto < 0 ){ prevtogoto=0;}
                }

                self.location=nextlink + 'snum=' + prevtogoto;

        } else { //within this set of images
                buildimages(backpagestart,"prev");
        }
};

function footer(){

	var footerhtml = '';

	if (typeof(customfooter) != 'undefined')
			footerhtml = customfooter;
	else
		footerhtml = '<DIV id="copyright"><span class="disclaimer"><A href="/aboutus_mission.shtml" onmouseover="javascript:hovercopyright();" class="disclaimer">&copy; '+currentYear+'</A></span></DIV>';
        //footerhtml='<nobr><font class=disclaimer> &copy;2006 IPNstock.com  All rights reserved <a href=/help_login.shtml#Terms_and_Conditions class=disclaimer>Terms</a> <a href=/help_faq.shtml#Privacy_Policy class=disclaimer>Privacy policy</A> &nbsp;<A HREF=/contact.shtml class=disclaimer>contact</a></FONT></nobr>';
        return(footerhtml);
};

function tellme(){
        setuppagesize();
        alert($F('pixperpage') + " browser is " + browser + " and os is " + OS + 
				" width=" + document.body.offsetWidth + "," + self.innerWidth + "," + winW +
				" winH="+winH+", truevertHeight="+truevertHeight
				);
};

//////preview functions////zpp///

function previewset(){
	tset = document.page.previews.options[document.page.previews.selectedIndex].value;
        var date = new Date();
        date.setTime(date.getTime()+(60*24*60*60*1000));
        gsetCookie('gpreviews',tset,date, '/', gGetCookieDom());
};

function pfindbody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
};

function prloadimg(prid,crop){
	var nh = '<div id="previewpaneshadow2">';
	nh += '<div id="previewpaneshadow1">';	
	nh += '<div id="previewpane">'; // + '<div id="dbgdiv"></div>';	
	nh += '<div align="center" style="padding: 2px 2px 2px 2px;"><img id=previewimg_' + prid + ' src="http://globaldyn.ipnstock.com/dyn_images/420/60/' + prid + '.JPG" border="0" alt="loading.." LOWSRC="/graphics/spacer.gif"';
	if(winH < 450){
		smallscreen=1;
		if(typeof crop != undefined){//smallscreen using orientation to decide limiter
			if(crop=='panoramic'){
				nh += ' width="420"';
			} else if(crop=='vertical'){
				nh += ' height="' + (winH - 100) + '"';
			} else {
				nh += ' height="' + (winH - 142) + '"';
			}
		} else {
			nh += ' height="135"';
		}
	} else {
		smallscreen=0;
	}
	
	nh +='></div><div id="previewpane_metdat_'+prid+'"></div></div></div></div>';
                      //prgetobj().visibility="hidden";
	$('pimid').style.visibility="hidden";
	if ($("pimid"))
		$("pimid").innerHTML = nh;
};

function sp(oObj, imageid, imagenum, mode) { //wrapper func to make asynch call before rendering popup
	ajax_JSON( '/AjaxHandlers/ImageInfo/'+imageid+'.json', getpost, null ); //even if it's off make the call anyway to cache
	if (oObj.id)
		currMousedOverObj = oObj.id;
	sp_act(oObj.id, imageid, imagenum, mode, 0);
};

function sp_act(oObjId, imageid, sid, mode, tryCtr){  //imagename, imagenum, license, photographer, 
	pshown=1;
	var prshortcaption ='';
	var prphotographer='';
	if( (! document.page.previews.selectedIndex || document.page.previews.selectedIndex != 1) && suspendpreviews==0)
	if(sid && ( mode == 'on'))
	{
 		document.onmousemove=pfindmouse;
		if(document.ajaxLoaded && (oObjId == document.JSONobj.getImgDat('id')) && (oObjId == currMousedOverObj))
		{
			if(pshown < 1)
				return;
			var crop = gloCrop = document.JSONobj.getImgDat('crop');
			//SMALL SCREEN HACK
			if(smallscreen=='1' && (crop=='panoramic' || crop=='vertical')){
				prloadimg(imageid,crop);
			}

// 			alert(oObjId+ ' ?? '+currMousedOverObj);
			var oMd_div = document.getElementById('previewpane_metdat_'+imageid);

			var temp = true;
			var tempshortcaption = document.JSONobj.getImgDat('short_caption');	//=spcap;
			var rmrftype = document.JSONobj.getImgDat('rmrftype');

			var file_size = document.JSONobj.getImgDat('file_size');
			if (file_size < 5){file_size='';} else {file_size += 'Mb';} //something wrong do not show

			if(tempshortcaption && tempshortcaption.length > 130)
			{
				var tsc='';
				for(z=0; z < 170; z++)
				{
					var c = tempshortcaption.charAt(z);
					if(temp == true)
					{
						if((z > 130) && (c == ".")){
							temp = false;
							tsc+=c + " ...";
						} else if((z > 150) && (c == " ")){
							temp = false;
							tsc+=" ...";
						} else {
							tsc+= c;
						}
					}
				}
				tempshortcaption = tsc;
			}

			prshortcaption = tempshortcaption;
			prphotographer = document.JSONobj.getImgDat('photographer');

			//RENDER!
			oMd_div.innerHTML = '<span class="blah"># ' + imageid + ' ' + rmrftype + ' ' + file_size + '  :: ' + prshortcaption + ' &copy; ' + prphotographer + 
			(document.JSONobj.getImgDat('image_restrictions') ? ' :: <span style="color:#990000">This image has restrictions. Click to View</span> ' : '' ) 
			+ '</span><BR><span class=warning>To turn live previews off, use Previews menu at top of page</span>';

			$('pimid').style.visibility="visible";
			pshown=2;
			new Effect.Appear('pimid', {duration:.1});
		}
		else if (tryCtr < 10) // effectively, try 10 times to get ajax data... waiting a max of 10 * 250 ms
		{
			if(pshown < 1)
				return;
			tryCtr++;
			setTimeout("sp_act('"+oObjId+"', '"+imageid+"', '"+sid+"', '"+mode+"', '"+tryCtr+"')", 250);
		}
	}
};

function hpoff(){
	if(pshown==0){
		if(typeof(mouseX)!='undefined' && mouseX > parseInt(portSize()[0]/2))
			$('pimid').style.left = '-500px';
		else
			$('pimid').style.top = '-750px';
// 		$('pimid').style.left="-500px";
	}
};

function hp(){
	currMousedOverObj = null;
	if (pshown> 0){
		pshown=0;
		document.onmousemove="";
		new Effect.Fade('pimid', {duration:.2});
		setTimeout("hpoff()",200);
	}
};

/*function pfindmouse(e){
	if(pshown!=0) {
		var xcoord=pmousedelta[0]
		var ycoord=pmousedelta[1]
		var truCoordX;// = Event.pointerX(e);
		var truCoordY;// = Event.pointerY(e);

		if(browser != 'Internet Explorer'){
			truCoordX = e.pageX
			truCoordY = e.pageY
		} else {
			truCoordX = event.clientX + document.body.scrollLeft
			truCoordY = event.clientY + document.body.scrollTop
		}  

		if (truew - truCoordX < 450){
			xcoord = truCoordX - xcoord - 430; // Move to the left side of the cursor
		} else {
			xcoord += truCoordX;
		}

		if (trueh - truCoordY < 450){
			ycoord += truCoordY - Math.max(10,(490 + truCoordY - trueh - pfindbody().scrollTop));
		} else {
			ycoord += truCoordY;
		}
		if(ycoord < 0 ){ycoord = 0;}
	
		$('pimid').style.left=xcoord+"px";
		$('pimid').style.top=ycoord+"px";
	}
}*/
function portSize() {
	var retY = parseInt(document.body.offsetHeight - 20);
	var retX = parseInt(document.body.offsetWidth - 20);

	var iX = window.innerWidth;
	var iY = window.innerHeight;

	retX = ( iX < retX ? iX : retX);
	retY = ( iY < retY ? iY : retY); //we want smaller of 2 anyway, also pseud-crossbrowser as a result...


	return [retX, retY]; //X x Y
};

function pfindmouse(e, sX, sY){
	if($('pimid')) { //pshown!=0 && 
 		var xcoord=pmousedelta[0];
 		var ycoord=pmousedelta[1];

		mouseX = (sX || 0); 
		mouseY = (sY || 0);
		var theTar;
		if (typeof(event) == 'undefined')
		{
			mouseX = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
			mouseY = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
			theTar = e.target;
		}
		else //IE
		{
			mouseX = event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
			mouseY = event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
			theTar = event.target;
		}


		//keep it in the viewport...

// 		if ((mouseX + Element.getDimensions($('pimid'))['width'] + pmousedelta[0]) > portSize()[0])
// 		{	xcoord = (mouseX - Element.getDimensions($('pimid'))['width'] - pmousedelta[0] - 45);	}
// 		else
// 		{	xcoord += mouseX;	}
// 
// 		if(xcoord < 0 ){xcoord = pmousedelta[0];}
 		var primHt = 60;
 		if(theTar && theTar.nodeName == 'IMG')
 		{
 			primHt = Element.getDimensions(theTar)['height'];
 		}
// 		var gHt = Element.getDimensions($('previewpane'))['height'];
// 		if ((mouseY - gHt + pmousedelta[1]) < document.body.scrollTop)
// 		{	ycoord = document.body.scrollTop - pmousedelta[1];			}
// 		else if ((mouseY + gHt - pmousedelta[1] + 55) > portSize()[1])
// 		{	ycoord = (mouseY - gHt + pmousedelta[1]);	}
// 		else
// 		{	ycoord += (mouseY - primHt);	}


		if ((mouseX + Element.getDimensions($('pimid'))['width']) > winW)
		{	xcoord = (mouseX - Element.getDimensions($('pimid'))['width'] - pmousedelta[0] - 45);	}
		else
		{	xcoord += mouseX;	}
		if(xcoord < 0 ){xcoord = pmousedelta[0];}

//Element.getDimensions($('pimid'))['height']
		if ((mouseY - Math.min(primHt, 420) + pmousedelta[1] - 20) < document.body.scrollTop)
		{	ycoord = document.body.scrollTop - pmousedelta[1];			
			
			if ((ycoord + 40) > winH)
			{	ycoord = (ycoord - Math.min(primHt, 420)+ pmousedelta[1]);
				if ( ((ycoord + Math.max(primHt, 420) - document.body.scrollTop) - winH) > 0)
				{
					ycoord = ycoord - (typeof(event) == 'undefined' ? Math.min((primHt+160), 420) : (gloCrop == 'panoramic' || (gloCrop != '' && gloCrop !='vertical') ? 190 : 380));	 //ie can't find heights properly.. so rely on crop..
				}
			}
			
		}
		else if ((mouseY + Math.max(primHt, 420)) > winH)
		{	ycoord = (mouseY - Math.min(primHt, 420)+ pmousedelta[1]);

			if ( ((ycoord + Math.max(primHt, 420) - document.body.scrollTop) - winH) > 0)
			{
				ycoord = ycoord - (typeof(event) == 'undefined' ? Math.min((primHt+160), 420) : (gloCrop == 'panoramic' || (gloCrop != '' && gloCrop !='vertical') ? 190 : 380));	 //ie can't find heights properly.. so rely on crop..
			}

			if (ycoord < document.body.scrollTop)
			{	ycoord = document.body.scrollTop - pmousedelta[1];	}
		 }
		else
		{	ycoord += mouseY;	
			if ((ycoord + 40) > winH)
			{	ycoord = (ycoord - Math.min(primHt, 420)+ pmousedelta[1]);
				//DC:
	//  			$('ddd').innerHTML = ((ycoord + Math.max(primHt, 420) - document.body.scrollTop) - portSize()[1]);
				if ( ((ycoord + Math.max(primHt, 420) - document.body.scrollTop) - winH) > 0)
				{
					ycoord = ycoord - (typeof(event) == 'undefined' ? Math.min((primHt+160), 420) : (gloCrop == 'panoramic' || (gloCrop != '' && gloCrop !='vertical') ? 190 : 380));	 //ie can't find heights properly.. so rely on crop..
				}
			}
		}


  		$('pimid').style.left = parseInt(xcoord) + "px";
  		$('pimid').style.top  = parseInt(ycoord) + "px";

	/*	if ($('dbgdiv'))
 			$('dbgdiv').innerHTML = 
					'MX: '+mouseX+' MY: '+mouseY + '<br/>' +
					'X: '+Position.page($('pimid'))[0] + ' Y: '+ Position.page($('pimid'))[1] +
 					'<br/>PSX: ' + (portSize()[0]) + ' PW '+Element.getDimensions($('pimid'))['width']+
 					'<br/>PSY: ' + (portSize()[1]) + ' PH '+Element.getDimensions($('pimid'))['height']; */
	}
};

/////////////////////
function setbackpagetrap(sba,sbb,sbc){
	lowerframelocation = sba + '|' + sbb + '|' + sbc + '|';
	//alert(lowerframelocation);
	gsetCookie("gcurrentview", lowerframelocation, '', '/', gGetCookieDom());
	$('RSIFrame').src = '/hidden.shtml?' + lowerframelocation;
};

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; }
};

function toplightboxrefresh() {
	//currentLayer1Mode='searchresults';
	polllb(1);
	if(gsession){
		top.location="/SwishSearch?n=1&lb_view=1";
	} else {
		//top.location="/user/login.shtml?/SwishSearch?n=1";
		top.location = '/user/login.shtml?/SwishSearch?lb_view=1';
	}
};

function topcartrefresh() {
	polllb(1);
	if(gsession){
		//top.location="/bin/Cart?op=view";
		top.location="/SwishSearch?n=1&cartview=1";
	} else {
		//top.location="/user/login.shtml?/bin/Cart?op=view";
		top.location="/user/login.shtml?/SwishSearch?cartview=1";
	}
};


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

function narrowit(url) {
        if(url == "#"){
                alert('please select an item from the list');
        } else {
                var url1 = '/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 = '/deepsearch.shtml';
                self.location=url1;
        } else {
                var url1 = '/SwishSearch?synsearch=true&spec_idx=ne&Keywords=' + ukeys;
                self.location=url1;
        }
};

function checkIt(string){
        place = detect.indexOf(string) + 1;
        thestring = string;
        return place;
};

function VersionNavigateur(Netscape, Explorer) {
  if ((navigator.appVersion.substring(0,3) >= Netscape && navigator.appName == 'Netscape') ||      
      (navigator.appVersion.substring(0,3) >= Explorer && navigator.appName.substring(0,9) == 'Microsoft'))
    return true;
else return false;
};
function netie(net, ie) {
  if ((navigator.appVersion.substring(0,3) >= net && navigator.appName == 'Netscape' && net != -1) || (navigator.appVersion.substring(0,3) >= ie && navigator.appName.substring(0,9) == 'Microsoft' && ie != -1))
    return true;
else return false;
};

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

// all new functions


function popkeys2(oId, oLbj) {
	var topop = $(oId);
	if (topop)
		if (topop.style.display == 'none')
		{
			topop.style.display = 'block';
			//top of lbbuttons - top of keyword div
			var kwdht = Position.cumulativeOffset($('lbbuttons'))[1] - Position.cumulativeOffset(topop)[1] + 'px'; 
			topop.style.maxHeight = kwdht;
			topop.style.overflowY = 'auto';
		}
		else
			topop.style.display = 'none';
	if (oLbj)
		if (oLbj.innerHTML == 'Show keywords')
			oLbj.innerHTML = 'Hide keywords';
		else if (oLbj.innerHTML == 'Hide keywords')
			oLbj.innerHTML = 'Show keywords';
};

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;
};

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));
};

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 gGetQV(variable) {
  var query = '';
 if (window.location)
	if (window.location.search)
		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 gsetCookie2(name2,value2) {
	gsetCookie(name2, value2, '', '/', gGetCookieDom());
};

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() {
	var thispage = '';
	if (location.href)
		thispage = location.href;
	gsetCookie('backpage', thispage, '', '/', gGetCookieDom());
};

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 checkpageresize(e){
	if(self.innerWidth){
                newW = self.innerWidth - 0;
	} else if (document.body){
		newW = document.body.offsetWidth - 0;
	}

	if (newW != tempW){
		if(self.innerWidth){
			tempW = self.innerWidth - 0;
		} else {
			tempW= document.body.offsetWidth - 0;
		}

		try {
			if (currentLbdivMode == 'lightbox')
				lightbox_build(currentlbstash);
			else if (currentLbdivMode == 'cart')
				cart_build();
		} catch (e) {}
		currentpage();
	}
};

function nada(){
};

function ajaxLoaded(){
	if (document.ajaxLoaded)
		return true;
	else
		return false;
};

function launchwin(url, tle, ht, wd, px, py){ // for popups etc (primarily used on cart page)...
	if (!tle)
		tle = "newwindow";
	if (!ht)
		ht = 590;
	if (!wd)
		wd = 550;
	if (!px)
		px = 40;
	if (!py)
		py = 40;

	newwin = window.open( url, tle, "height="+ht+",width="+wd+",alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,loc	ation=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,z-lock=0,screenX=0,screeny=0,left="+px+",top="+py);
	if (!newwin.opener) newwin.opener=parent;
	if (newwin.focus) newwin.focus();
};

function hovercopyright(){
        if($('copyright')){
                var thtml;
		if (typeof(customhovermessage) != 'undefined' && customhovermessage != '')
			thtml = customhovermessage;
		else
		 	thtml = '&copy;'+currentYear+' '+(baseurl ? baseurl : '')+'  All rights reserved <a href=/help_login.shtml#Terms_and_Conditions class=disclaimer>Terms</a> <a href=/help_faq.shtml#Privacy_Policy class=disclaimer>Privacy policy</A> &nbsp;<A HREF=/contact.shtml class=disclaimer>contact</a></FONT></nobr>';

                $('copyright').innerHTML = thtml;
        }
};

//for CHECK USAGE RATES
function license(id) {
	launchwin('/bin/Rates?calc_only=1&usage=1&ln='+id);
};

function twidle_price_img(selId, type, price) {
	setTimeout("twidle_price_img_delay("+selId+", '"+type+"', '"+price+"')", 10);
	return false;
};

function twidle_price_img_delay(selId, type, price) {
        var docold = 'lic'+selId;

	if (document[docold].loaded == 'true')
		return;
        if(type == 'RF'){
		var thyimg = new Image();
		thyimg.src = '/graphics/specify_filesize.gif';
                document[docold].src=thyimg.src;
        }

        if(price == '$ 0.00'){
        } else {
		var thyimg = new Image();
		thyimg.src = '/graphics/ready_to_license.gif';
                document[docold].src=thyimg.src;
        }
	document[docold].loaded = 'true';
	return true;
};

function emaillb(){
	return;
};

function gsetuser(){
	return;
};
