gadmin = ggetCookie("admin_level");
gadmin_links = ggetCookie("display_admin_menu");
gusername = ggetCookie("username");
gcurrency = ggetCookie("currency");
year = new Date().getYear();
tb = "http://www.getstockphotos.ca";
var baseURL = "http://www.getstockphotos.ca";
var baseurl = "http://www.getstockphotos.ca";
currentPageName = location.href;
pages = currentPageName.split("/");
currentPageName = pages[pages.length-1];


var swithinchecked = 0;

function toggleboxes(ttype,tval){
	d = document.getElementsByName(ttype); 
	for (i = 0; i < d.length; i++){ 
			d[i].checked = tval; 
	} 
}

isindex = false;
if((currentPageName == tb) || (currentPageName == tb+'/index.shtml') || (currentPageName == tb+'/') || (currentPageName == tb+'index.html') 
	|| (currentPageName == "/") || (currentPageName == "index.shtml") || (currentPageName == "index_pre.shtml") ||(currentPageName == "") || currentPageName.indexOf('index')>0)
	isindex=true;

isindex = ((typeof(loginpage) != 'undefined') && loginpage) ? false : isindex;


if ((screen.width<=800) && (screen.height<=600) && !isindex){
	document.write('<link rel="stylesheet" href="/css/main2_800.css"></link>');

}else if ((screen.width<=1024) && (screen.height<=768) && !isindex){
	document.write('<link rel="stylesheet" href="/css/main2_1024.css"></link>');
}

/////// admin bar inline ///////
if(gadmin && gadmin_links && gusername && gsession)
{
		document.write('<div id=navbar><div id=navbar_enclosure><font class=adminlabel>&nbsp;ADMIN:</font> <a href="/" target="left" class="adminlink">Homepage</a> | ');
		//write in the navbar here;
		if (gadmin_links && gadmin_links.toString().length > 1) //also have additional links to parse
		{
				var tnavObjs = eval(''+gadmin_links+'');
				for (i=0;i< tnavObjs.length;i++){
						document.write('<A href="' + tnavObjs[i]['lnk'] + '" class=adminlink>' + tnavObjs[i]['txt'] + '</a> | ');
				}
		}
		document.write('</div></div><BR>');
//setTimeout("document.getElementById('searchmore').style.top='76px';",6000);
}
/////////////////////////////

	
        if(self.innerWidth ){
                var zwinW = self.innerWidth;
                var zwinH = self.innerHeight;
        } else {
                var zwinH = document.body.offsetHeight;
                var zwinW = document.body.offsetWidth;
        }
//	if(self.location.href.indexOf('tools')>0){
//        	alert(zwinH+" "+zwinW);
//	}	
	        var trz=Math.floor(zwinH/110);
                var dtime_rez_limit=Math.floor(         trz * Math.floor(zwinW/95));





function ghome() {
	if(goinghome==1){
	} else {
		gsetCookie("gwhichstartpage","", "", "/", gGetCookieDom());
		var gurl = document.qform2.Keywords.value + '';
		var orient = '';
		var theurl= '/Search/SWSearch?Keywords=' + gurl + orient ;
		theurl.replace(" ","+");
//		alert(theurl);
		self.location='' + theurl;

		goinghome=1;
	}
}

document.write('<div id="navadvsearch"></div>');


function clearsubnav(){
	MM_setTextOfLayer('navlayer','','');
}


/* Simple search option variable*/

var advsearch_options = '<div style="float:left"><form id="asearchpanel" action="#" name="asearchpanel"><table cellspacing=0 cellpadding=0 style="width:170px">' 
		+ (typeof(q_id) != 'undefined' ? '<tr><td valign=top><input type="checkbox" name="searchmethod" value="within" onclick="javascript:fsearchprefs(\'\',\'\');"></input></td><td>Search within Results</tr><tr><td colspan=2> </td></tr><tr><td colspan=2><hr/></td></tr>':'<tr><td colspan=2><br></td></tr>') 
		+ '<tr><td><input type="checkbox" checked name="rmrftype" onclick="javascript:fsearchprefs(\'\',\'\');"></input></td><td>Rights Managed (RM)</td></tr><tr><td><input type="checkbox" checked name="rmrftype" onclick="javascript:fsearchprefs(\'\',\'\');"></input></td><td>Royalty Free (RF)</td></tr><tr><td><input type="checkbox" name="dreamstime" onclick="javascript:fsearchprefs(\'\',\'\');" checked></input></td><td><font color="red">BUDGET</font> images ($1 and up) from Dreamstime</td></tr><tr><td colspan=2><hr/></td></tr><tr><td><input type="checkbox" name="rmrftype" onclick="javascript:fsearchprefs(\'\',\'\');"></input></td><td>Only Model Released</td></tr></table></form></div><div id="navadvsearch_close"><a href="javascript:hide_advsearchbox(\'navadvsearch_box\')"></a></div>';

var more_options = '<form id="asearchpanel" action="#" name="asearchpanel"><div class="navadvsearch_text">'
	+'<table cellspacing=0 cellpadding=0>'
			+ (typeof(q_id) != 'undefined' ? '<tr><td valign=top><input type="checkbox" name="searchmethod" value="within"></input></td><td>Search within Results</tr>':'<tr><td colspan=2> </td></tr>')
	+'<tr><td colspan=2><b>TYPE:</b></td></tr>'
	+'<tr><td><input type="checkbox" name="rmrftype" checked onclick="javascript:fsearchprefs(\'\',\'\');"></input></td><td>Rights Managed (RM)</td></tr>'
	+'<tr><td><input type="checkbox" name="rmrftype" checked onclick="javascript:fsearchprefs(\'\',\'\');"></input></td><td>Royalty Free (RF)</td></tr>'
	+'<tr><td colspan=2><b>RELEASES:</b></td></tr>'
	+'<tr><td><input type="checkbox" name="rmrftype" onclick="javascript:fsearchprefs(\'\',\'\');"></input></td><td>Only Model Released</td></tr>'
	+'<tr><td colspan=2><b>EDITORIAL(Budget):</b></td></tr>'
	+'<tr><td><input type="checkbox" name="editorial" value="only" onclick="javascript:fsearchprefs(\'\',\'\');"></input></td><td>Editorial only</td></tr>'
+'</table></div>'
	+'<div class="navadvsearch_text" border=1><table cellspacing=0 cellpadding=0><tr><td colspan=2><b>ORIENTATION:</b></td></tr>'
		+'<tr><td valign=top><input type="checkbox" name="orient" value="horizontal" onclick="javascript:fsearchprefs(\'f\',\'add\');" checked></input></td><td>Horizontal</td></tr>'
		+'<tr><td valign=top><input type="checkbox" name="orient" value="vertical" onclick="javascript:fsearchprefs(\'g\',\'add\');" checked></input></td><td>Vertical</td></tr>'
		+'<tr><td valign=top><input type="checkbox" name="orient" value="panoramic" onclick="javascript:fsearchprefs(\'h\',\'add\');" checked></input></td><td>Panoramic</td></tr>'
		+'<tr><td valign=top><input type="checkbox" name="orient" value="square" onclick="javascript:fsearchprefs(\'i\',\'add\');" checked></input></td><td>Square</td></tr>'
		//+'<tr><td colspan=2><b>PEOPLE(Budget):</b></td></tr>'
		//+'<tr><td valign=top><input type="radio" name="people" value="" onclick="javascript:fsearchprefs(\'m\',\'add\');" checked></input></td><td>Any</td></tr>'
		//+'<tr><td valign=top><input type="radio" name="people" value="withpeople" onclick="javascript:fsearchprefs(\'n\',\'add\');"></input></td><td>With people</td></tr>'
		//+'<tr><td valign=top><input type="radio" name="people" value="nobody" onclick="javascript:fsearchprefs(\'o\',\'add\');"></input></td><td>Without people</td></tr>'
+'</table></div>'
	+'<div class="navadvsearch_text"><table cellspacing=0 cellpadding=0><tr><td colspan=2><b>COLOUR:</b></td></tr><tr><td valign=top><input type="checkbox" name="color" value="color" onclick="javascript:fsearchprefs(\'color\',\'add\');" checked></input></td><td valign=top>Colour</td></tr><tr><td valign=top><input type="checkbox" name="color" value="gray" onclick="javascript:fsearchprefs(\'color\',\'add\');" checked></input></td><td valign=top>B/W</td></tr><tr><td colspan=2><b>MEDIA:</b></td></tr><tr><td valign=top><input type="checkbox" name="type" value="illustration" onClick="javascript:fsearchprefs(\'0\',\'add\');" checked></input></td><td valign=top>Illustration</td></tr><tr><td><input type="checkbox" name="type" value="photography" onClick="javascript:fsearchprefs(\'1\',\'add\');" checked></input></td><td>Photography</td></tr><tr><td><input type="checkbox" name="type" value="vector" onClick="javascript:document.asearchpanel.rmrftype[0].checked=false;document.asearchpanel.rmrftype[1].checked=false;fsearchprefs(\'1\',\'add\');"></input></td><td>Vector<br/>(Budget<br> items)</td></tr></table></div>'
			+'<div class="navadvsearch_text" ><table cellspacing=0 cellpadding=0><tr><td colspan=4><b>COLLECTIONS:</b></td></tr><tr><td><input type="checkbox" name="rm_collection" checked onclick="javascr' 
			+ 'pt:if(this.checked){ts=true;} else {ts=false;};toggleboxes(\'rm_collection_name\',ts);"></input></td><td>All Rights Managed</td><td><input type="checkbox" name="rf_collection" checked onclick="javasc'
			+ 'ript:if(this.checked){ts=true;} else {ts=false;};toggleboxes(\'rf_collection_name\',ts);toggleboxes(\'Dreamstime\',ts);"></input></td>'
			+ '<td>All Royalty Free&nbsp;&nbsp;</td></tr><tr><td colspan=2 width=100><div style="width:125px;overflow:auto;height:80px;border:solid 1px #888"><table cellspacing=0 cellpadding=0>'
			+ '<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="Toronto Star" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;"></input></td><td valign=top>Toronto Star</td></tr>'
			+ (gcurrency=='CAD' ? '<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="Alamy" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;"></input></td><td valign=top>Alamy</td></tr>':'<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="Alamy" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;" style="visibility:hidden;"></input></td><td valign=top></td></tr>')
			+'<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="Aperture" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;"></input></td><td valign=top>Aperture</td></tr>'
			+'<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="Aurora" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;"></input></td><td valign=top>Aurora</td></tr>'
			+'<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="DesignPics" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;"></input></td><td valign=top>Design Pics</td></tr>'
			+'<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="EyeCandy" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;"></input></td><td valign=top>Eyecandy Images</td></tr>'
			+'<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="Jim Powell" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;"></input></td><td valign=top>Jim Powell</td></tr>'
			+'<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="Michale Yamashita" checked onclick="javascr' + 'ipt:document.asearchpanel.rm_collection.checked=false;"></input></td><td valign=top>Michael Yamashita</td></tr>'
						//+'<tr><td valign=top><input type="checkbox" name="rm_collection_name" value="TopFoto" checked onclick="javascr' + 'ipt:document.isn1.rm_collection.checked=false;"></input></td><td valign=top>TopFoto</td></tr>'
			+'</table></div><td colspan=2><div style="overflow:auto;height:80px;border:solid 1px #888"><table cellspacing=0 cellpadding=0>'
			+(gcurrency=='CAD' ? '<tr><td valign=top><input type="checkbox" name="rf_collection_name" value="Alamy" checked onclick="javascr' + 'ipt:document.asearchpanel.rf_collection.checked=false;"></input></td><td valign=top>Alamy</td></tr>':'<tr><td valign=top><input type="checkbox" name="rf_collection_name" value="Alamy" checked  onclick="javascr' + 'ipt:document.asearchpanel.rf_collection.checked=false;" style="visibility:hidden;"></input></td><td valign=top></td></tr>')
			+'<tr><td valign=top><input type="checkbox" name="rf_collection_name" value="Aurora" checked  onclick="javascr' + 'ipt:document.asearchpanel.rf_collection.checked=false;"></input></td><td valign=top>Aurora</td></tr>'
			+'<tr><td valign=top><input type="checkbox" name="rf_collection_name" value="DesignPics" checked onclick="javascr' + 'ipt:document.asearchpanel.rf_collection.checked=false;"></input></td><td valign=top>Design Pics</td></tr>'
			+'<tr><td valign=top><input type="checkbox" name="Dreamstime" value="Dreamstime" checked  onclick="javascr' + 'ipt:document.asearchpanel.rf_collection.checked=false;"></input></td><td valign=top>Dreamstime <br>Budget images</td></tr>'
				//	+'<tr><td valign=top><input type="checkbox" name="rf_collection_name" value="Toronto Star" checked  onclick="javascr' + 'ipt:document.isn1.rf_collection.checked=false;"></input></td><td valign=top>Toronto Star</td></tr>'
				//+'<tr><td valign=top><input type="checkbox" name="rf_collection_name" value="TopFoto" checked onclick="javascr' + 'ipt:document.isn1.rf_collection.checked=false;"></input></td><td valign=top>TopFoto</td></tr>'
			+'<tr><td valign=top><input type="checkbox" name="rf_collection_name" value="Blend" checked onclick="javascr' + 'ipt:document.asearchpanel.rf_collection.checked=false;"></input></td><td valign=top>Blendimages</td></tr>'
			//+'<tr><td valign=top><input type="checkbox" name="rf_collection_name" value="Stockshop" checked onclick="javascr' + 'ipt:document.asearchpanel.rf_collection.checked=false;"></input></td><td valign=top>Stockshop</td></tr>'
			+'</table></div></td></tr><tr><td colspan=4><b>SORT BY:<b/></td></tr><tr><td colspan=4><select name="tsort" onchange="javascript:fsearchprefs(\'tsort\',\'add\');"><option selected="selected" value="">Optimize order of images for</option><option value="adweight">Advertising</option><option value="newsweight">News</option><option value="scienceweight">Science</option><option value="sportsweight">Sports</option><option value="travelweight">Travel</option><option value="sort_date">Newest First</option></select></table></form></div>'
			+'<div id="navadvsearch_close"><a href="javascript:hide_advsearchbox(\'navadvsearch_box\')"></a></div></div>'; 

function display_advsearchbox(aid,atext){
	gcurrency = ggetCookie("currency");

	var navadvsearch = document.getElementById(aid);
/*
	navadvsearch.innerHTML = '<table cellspacing=0 cellpadding=0><tr><td id="navadvsearch_topl"></td><td class="navadvsearch_top"></td><td id="navadvsearch_topr"></td></tr><tr><td class="navadvsearch_left"></td><td>'+atext+'</td><td class="navadvsearch_right"></td></tr><tr><td id="navadvsearch_botl"></td><td class="navadvsearch_bottom"></td><td id="navadvsearch_botr"></td></tr></table>';
*/

/*
if(typeof(q_id) != 'undefined'){
	if($('Keywordfield').value == "")
		$('Keywordfield').value = q_id;		
}
*/


if(navadvsearch.innerHTML.indexOf('ORIENTATION') >1){
} else {
	navadvsearch.innerHTML = '<div id="navadvsearch_box">'
		+ '<div id="navadvsearch_topl"></div><div id="navadvsearch_topr"></div><div id="navadvsearch_botl"></div><div id="navadvsearch_botr"></div>'
		+ '<div id="navadvsearch_content">'+atext+'</div></div>';
	var navadvsearch_box = document.getElementById('navadvsearch_box');
	var navadvsearch_content = document.getElementById('navadvsearch_content');
	var tkeybox = Position.cumulativeOffset($('navsearchbox'));
	var mpanelx = tkeybox[0];
	var mpanely = tkeybox[1];
	if(atext == more_options){
                navadvsearch_box.style.width = "670px";
                navadvsearch_content.style.width = "670px";
                navadvsearch_box.style.height = "185px";
                navadvsearch_content.style.height = "185px";
                navadvsearch.style.left = parseInt(mpanelx - 670 + $('navsearchbox').getWidth() - 8) + 'px';
                navadvsearch.style.top = parseInt(mpanely + $('navsearchbox').getHeight() + 5) + 'px';

                if(browser == "Explorer" ){
                	//navadvsearch.style.left = parseInt(mpanelx - navadvsearch.getWidth() + $('navsearchbox').getWidth() - 8) + 'px';
	                //navadvsearch.style.top = parseInt(mpanely + $('navsearchbox').getHeight() + 5) + 'px';
                }
        }
        else{
                navadvsearch.style.left = mpanelx + 'px';
                navadvsearch.style.top = parseInt(mpanely + $('navsearchbox').getHeight() + 5) + 'px';

                navadvsearch_box.style.width = "187px";
                navadvsearch_content.style.width = "187px";
                navadvsearch_box.style.height = "140px";
                navadvsearch_content.style.height = "140px";
                if(browser == "Explorer"){
                navadvsearch_box.style.height = "170px";
                navadvsearch_content.style.height = "170px";
                       //navadvsearch.style.top = "10px";
                        //navadvsearch.style.right = "46px";
                }
        }
        navadvsearch.style.display="block";
        loadsearchprefs();
        }
}



function hide_advsearchbox(aid){
	 var navadvsearch = document.getElementById(aid);
        navadvsearch.innerHTML = '';
	navadvsearch.style.display="none";

}

/* Search box */
function cKey(e){
	var key;

         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.keyCode;     //firefox

        if (key == 13){
	       g_search(document.isn1);
	}
}

function writesearchbox(){

 if (typeof(global) != 'undefined' && global.userBrowser == 'NS')
  {
   document.write('        <form method="get" action="javascript:g_search(document.isn1)" enctype="application/x-www-form-urlencoded" name="isn1">');
  }
 else
  {
   document.write('        <form onsubmit="return false;" name="isn1">');
  }
document.write('                <div id="navsearchbar">');

document.write(' 		<div id="navsearchbox">');
document.write('<div id="navsearchlc"></div>');
document.write('<input type="hidden" name="pixperpage"></input>');
document.write('<div id="navsearchb"><input onkeydown="javasc' + 'ript:cKey(event);" type="text" name="Keywords" id="Keywordfield" onfocus="if(this.value==\'search image by keyword or ID number\')this.value=\'\';display_advsearchbox(\'navadvsearch\',advsearch_options);" onblur="if(this.value==\'\')this.value=\'search image by keyword or ID number\';" onclick="javascript:display_advsearchbox(\'navadvsearch\',advsearch_options);" value="search image by keyword or ID number"  /></div>');
document.write('<div id="navsearchrc"></div>');
document.write('</div>');

document.write('                <div id="goButton"><a href="javascript:g_search(document.isn1);"></a></div>');
//document.write('<div id="navadvsearch">');
//document.write('</div>');	
document.write('</div>');

document.write('        </form>');

//document.write(' </div>');

}




function sec_nav(){
	document.write('<div id="secnav">');
	document.write('<div id="secnav_left">');
	document.write('                        <div id="navabout"><a href="'+tb+'/aboutus_mission.shtml"></a></div>');
	document.write('<div class="navdivider"></div>');
	document.write('                        <div id="navgalleries"><a href="'+tb+'/galleries_front.shtml"></a></div>');
	document.write('<div class="navdivider"></div>');
	document.write('                        <div id="navhelp"><a href="'+tb+'/help_starthere.shtml"></a></div>');
	document.write('<div class="navdivider"></div>');
	document.write('                        <div id="navcontact"><a href="'+tb+'/contact.shtml"></a></div>');
	document.write('</div>');
	document.write('<div id="secnav_right">');
	document.write('                        <div id="navregister"><a href="'+tb+'/bin/Register"></a></div>');
	document.write('<div class="navdivider"></div>');
	document.write('                        <div id="navaccount"><a href="'+tb+'/bin/Profile"></a></div>');
	document.write('<div class="navdivider"></div>');
	document.write('                        <div id="navlightbox"><a href="javascript:toplightboxrefresh();"></a></div>');
	document.write('<div class="navdivider"></div>');
	document.write('                        <div id="navcart"><a href="javascript:topcartrefresh();"></a></div>');
	document.write('<div class="navdivider"></div>');
	if(gsession && gusername) 
		document.write('                        <div id="navdownld"><a href="'+tb+'/tools/DDload?supst=getstock"></a></div>');
	else
		document.write('                        <div id="navdownld"><a href="'+tb+'/user/login.shtml"></a></div>');
	document.write('</div>');
	document.write('</div>');

}

if(typeof(gsession) == 'undefined')
        gsession = '';
if(typeof(gusername) == 'undefined')
        gusername = '';

/////////////////////// first row of nav //////
//if(typeof(dsplkys) == 'undefined' && typeof(navwidepage) == 'undefined' ){
if(isindex){
	document.write('<div id="doc2" class="yui-t7">');
	if(typeof(hidenavhd) == 'undefined'){
		document.write('        <div id="hd">');
	if ((screen.width<=1024) && (screen.height<=768) && !isindex)
		document.write('                <div id="logo_primary"><a href="'+tb+'/" target=_top><img src="/graphics/getstock_logo_small_800.gif" border=0></a></div>');
	else
		document.write('                <div id="logo_primary"><a href="'+tb+'/" target=_top><img src="'+tb+'/graphics/getstock_logo_small.gif"></a></div>');


		writesearchbox();
		document.write('                <div id="navbuttons">');
		//document.write('                        <div id="float:left;display:block;"><a href="/aboutus_mission.shtml">more options</a></div>');
		document.write('                        <div id="navmore"><a href="javascript:display_advsearchbox(\'navadvsearch\',more_options);"></a></div>');
	if(gsession && gusername) {
		document.write('<div id="twelcomeback">&nbsp;Welcome back '+gusername+'</div>');
		document.write('<div id="buttonsignout"><a href="jav' + 'ascript: gsetCookie2\(\'username\',\'\'\);gsetCookie2\(\'gmpsess\',\'\'\);gsetCookie2\(\'gmpauth\',\'\'\);top.location=\'/index.shtml\';\"></a></div>');

	}
	else
		document.write('                        <div id="buttonlogin"><a href="'+tb+'/user/login.shtml"></a></div>');
/*		document.write('                        <a href="/aboutus_mission.shtml"></a>');
		document.write('                        <a href="/help_starthere.shtml"></a>');
		document.write('                        <a href="/contact.shtml"></a>');
		document.write('                        <a href="/user/search.shtml"></a>');
		document.write('                        <a href="/SwishSearch?n=1&amp;lb_view=1"></a>');
		document.write('                        <a href="javascript:topcartrefresh();"></a>');
*/

	document.write('<iframe id="RSIFrame" name="RSIFrame" style="width:0px; height:0px; border: 0px"> </iframe>');
		document.write('                </div>');
		document.write('        </div>');
	}
	if(!isindex)
	{
	document.write('        <div id="bd"><div id="bodycontent">');
		sec_nav();
	}else
		document.write('        <div id="bd"><div id="bd_index">');
} else {
	//search results page
	document.write('<div id="doc3">');

	document.write('        <div id="hdsmall">');
	if ((screen.width<=1024) && (screen.height<=768) && !isindex)
		document.write('                <div id="logo_primary"><a href="'+tb+'/" target=_top><img src="/graphics/getstock_logo_small_800.gif" border=0></a></div>');
	else
		document.write('                <div id="logo_primary"><a href="'+tb+'/" target=_top><img src="/graphics/getstock_logo_small.gif" border=0></a></div>');

	document.write('		<div id="hdsmall_curve"></div>');
	writesearchbox();
	document.write('                <div id="navbuttons">');
	document.write('                        <div id="navhome"><a href="'+tb+'"></a></div>');
	document.write('<div class="navdivider"></div>');
	document.write('                        <div id="navabout"><a href="'+tb+'/aboutus_mission.shtml"></a></div>');
	document.write('			 <div class="navdivider"></div>');
	document.write('                        <div id="navgalleries"><a href="'+tb+'/galleries_front.shtml"></a></div>');
	document.write('			<div class="navdivider"></div>');
	document.write('                        <div id="navhelp"><a href="'+tb+'/help_starthere.shtml"></a></div>');
	document.write('			<div class="navdivider"></div>');
	document.write('                        <div id="navcontact"><a href="'+tb+'/contact.shtml"></a></div>');
	 document.write('                        <div id="navmore"><a href="javascript:display_advsearchbox(\'navadvsearch\',more_options);"></a></div>');

	if(gsession && gusername) {
		document.write('<div id="twelcomeback"><nobr>&nbsp;&nbsp;&nbsp;Welcome back '+gusername+'&nbsp;&nbsp;&nbsp;');
		document.write(' <a href="jav' + 'ascript: gsetCookie2\(\'username\',\'\'\);gsetCookie2\(\'gmpsess\',\'\'\);gsetCookie2\(\'gmpauth\',\'\'\);top.location=\'/index.shtml\';\"> Signout </a> </nobr></div>');

	}
	else
		document.write('                        <div id="buttonlogin"><a href="'+tb+'/user/login.shtml"></a></div>');
	
	document.write('                </div>');
	document.write('        </div>');
	// secondary navigation
	document.write('<div id="hdsmall_nav">');

	document.write('<div id="hdsmall_nav_right">');
	//if(!(gsession && gusername))
	//	document.write('<div id="contest_notice" ><a href="'+tb+'/user/login.shtml">SIGN IN TO ENTER OUR CONTEST</a></div>');
	document.write('                        <div id="snavaccount"><a href="'+tb+'/bin/Profile"></a></div>');
	document.write('<div class="snavdivider">&nbsp;|&nbsp;</div>');
	document.write('                        <div id="snavlightbox"><a href="javascript:toplightboxrefresh();"></a></div>');
	document.write('<div class="snavdivider">&nbsp;|&nbsp;</div>');
	document.write('                        <div id="snavcart"><a href="javascript:topcartrefresh();"></a></div>');
	document.write('<div class="snavdivider">&nbsp;|&nbsp;</div>');
	if(gsession && gusername)
		document.write('                        <div id="snavdownld"><a href="'+tb+'/tools/DDload?supst=getstock"></a></div>');
	else
		document.write('                        <div id="snavdownld"><a href="'+tb+'/user/login.shtml"></a></div>');
	document.write('<iframe id="RSIFrame" name="RSIFrame" style="width:0px; height:0px; border: 0px"> </iframe>');
	document.write('</div>');
	document.write('</div>');
	

	document.write('        <div id="bdresults"><div class="yui-g">');
	//document.write('        <div id="bdresults">');
	
}


function g_search(gform){
	if(typeof(goinghome) != 'undefined'){
	} else {
		var theurl= '/Search/SWSearch?glo=1&max_res=200&Keywords='; 
		if( (gform.Keywords.length<1) || (gform.Keywords.value == "search image by keyword or ID number") && !( (typeof(q_id) != 'undefined') && (typeof($('asearchpanel').searchmethod) != 'undefined') && ($('asearchpanel').searchmethod.checked)) ){
			alert("Please enter a search term");
		}else{
            //collections
			var preurl='';

			var rmlimit=0;var rflimit=0;
			d = document.getElementsByName('rm_collection_name'); 
			for (i = 0; i < d.length; i++){ 
				if(! d[i].checked){
					 rmlimit=1;
				}
			} 
			d = document.getElementsByName('rf_collection_name'); 
			for (i = 0; i < d.length; i++){ 
				if(! d[i].checked){
					 rflimit=1;
				}
			} 

			var xtrasql = '&xtrasql=';
			var rmxtrasql = '';
			var rfxtrasql = '';

                        if(($('asearchpanel') !=null ) && (typeof($('asearchpanel').rm_collection_name) != 'undefined')){
	        	    	if(rmlimit==1){  // lets be selective
					var rmlistlimit=new Array();
				        if ($('asearchpanel').rm_collection_name[0].checked){
				               rmlistlimit.push('sphotoggetstock');
				    	}
				        if ($('asearchpanel').rm_collection_name[2].checked){
				               rmlistlimit.push('sphotogaperture');
				        } 
				        if ($('asearchpanel').rm_collection_name[3].checked){
				               rmlistlimit.push('sphotogaphotos');
				        } 
				        if ($('asearchpanel').rm_collection_name[4].checked){
				               rmlistlimit.push('sphotogdesignpics');
   				    	}
				        if ($('asearchpanel').rm_collection_name[5].checked){
				               rmlistlimit.push('sphotogeyecandyimages');
				    	}
				        if ($('asearchpanel').rm_collection_name[6].checked){
				               rmlistlimit.push('sphotogjimpowell');
				    	}
				        if ($('asearchpanel').rm_collection_name[7].checked){
				               rmlistlimit.push('sphotogyamashita');
				    	}
					if(rmlistlimit[0]){
						rmxtrasql += '(rmrftyperm (';
						for (i = 0; i < rmlistlimit.length; i++){
							if(i>0){rmxtrasql += ' or ';}
							rmxtrasql += rmlistlimit[i];
						}					
						rmxtrasql += '))';
					}
					
					if( (rmlistlimit.length==0) && ($('asearchpanel').rm_collection_name[1].checked) )
						preurl += '&alamy=1'; 

						//  if (! $('asearchpanel').rm_collection_name[3].checked){
						// xtrasql  += '+NOT+TopFoto'; // don't include topfoto
						//}
						//special Alamy syntax
				        if (! $('asearchpanel').rm_collection_name[1].checked && ! $('asearchpanel').rf_collection_name[0].checked){
				                preurl += '&Alamy=0'; // don't include Alamy
				        }
				}
			}
		
			if(($('asearchpanel') !=null ) && (typeof($('asearchpanel').rf_collection_name) != 'undefined')){
                        	if(rflimit==1){ // lets be selective
                        	        var rflistlimit=new Array();   
				        if ($('asearchpanel').rf_collection_name[1].checked){
				               rflistlimit.push('sphotogaphotos');
				    	}
				        if ($('asearchpanel').rf_collection_name[2].checked){
				               rflistlimit.push('sphotogdesignpics');
				    	}
				        if ($('asearchpanel').rf_collection_name[3].checked){
				               rflistlimit.push('sphotogblendimages');
				    	}
				        /*if ($('asearchpanel').rf_collection_name[4].checked){
				               rflistlimit.push('sphotogstockshop');
				    	}*/
					if(rflistlimit[0]){
	                        	        if(xtrasql.length > 10){xtrasql += ' or ';} // in case rm had some limiting
						rfxtrasql += '(rmrftyperf (';
						for (i = 0; i < rflistlimit.length; i++){
							if(i>0){rfxtrasql += ' or ';}
							rfxtrasql += rflistlimit[i];
						}					
						rfxtrasql += '))';
					}
					if( (rflistlimit.length==0) && ($('asearchpanel').rf_collection_name[1].checked) )
						preurl += '&alamy=1'; 

				}
			}

			if(rmxtrasql.length > 0 && rfxtrasql.length > 0){
				xtrasql += '(' + rmxtrasql + ') or (' + rfxtrasql + ')';
			} else if(rmxtrasql.length>0){
				xtrasql += '((' + rmxtrasql + ') or rmftyperf)';
			} else if(rfxtrasql.length>0){
				xtrasql += '((' + rfxtrasql + ') or rmftyperm)';
			}


			if(typeof($('asearchpanel').Dreamstime) != 'undefined'){
				if(!$('asearchpanel').Dreamstime.checked){
					preurl += '&Dreamstime=0';
				} else { // dreamstime is clicked. lets see if anything else is clicked too
					if(rflimit ==1){ // at least 1 rf is turned off
												//if( (( typeof($('asearchpanel').rf_collection_name) != 'undefined') &&  ! $('asearchpanel').rm_collection_name.checked ) || ( ($('asearchpanel').rf_collection_name.length==2) && ! $('asearchpanel').rf_collection_name[0].checked && ! $('asearchpanel').rf_collection_name[1].checked)){
						if(!rflistlimit[0]){ // no rf are on except dreamstime
							if(! rmlimit==1 && !$('asearchpanel').rmrftype[0].checked){ // no rm is unchecked and RM is unchedked so appears to be just dreamstime
								preurl += '&dreamstime=1'; // dreamstime only
							} else if (rmlimit==1 && !rmlistlimit[0]){ // rm is limited but list is empty -- just dreamstime
								preurl += '&dreamstime=1'; // dreamstime only
							} else { //dreamstime and possibly something else
								preurl += '&Dreamstime=1';
								xtrasql += 'not rmrftyperf'; // all rf were turned off
							}
						} else { // some rf are turned off
			               	                preurl += '&Dreamstime=1';
						}
					}
				}
			}	
	
			
	
			if(typeof($('asearchpanel').dreamstime) != 'undefined'){
	                /*        if($('asearchpanel').dreamstime.checked){
	                                preurl += '&dreamstime=1&Alamy=0';
					 preurl += "&res_limit="+dtime_rez_limit
				}
			*/
			
	                        if(!$('asearchpanel').dreamstime.checked)
	                                preurl += '&Dreamstime=0';
				//if( (!$('asearchpanel').rmrftype[0].checked &&  !$('asearchpanel').rmrftype[1].checked &&  !$('asearchpanel').rmrftype[2].checked)){	
				if( (!$('asearchpanel').rmrftype[0].checked &&  !$('asearchpanel').rmrftype[1].checked)){	
	                                preurl += '&dreamstime=1&Alamy=0';
					preurl += "&res_limit="+dtime_rez_limit;
				}
			

	                }
	
			if( (typeof(q_id) != 'undefined') && (typeof($('asearchpanel').searchmethod) != 'undefined') && ($('asearchpanel').searchmethod.checked)){
					if(gform.Keywords.value == "search image by keyword or ID number")
						gform.Keywords.value = "";
		
					theurl+=q_id+preurl+"&ex_keys="+gform.Keywords.value;
			}
			else
				theurl += gform.Keywords.value +preurl ;
			if(typeof($('asearchpanel').rmrftype) != 'undefined'){
				if(! $('asearchpanel').rmrftype[0].checked || ! $('asearchpanel').rmrftype[1].checked){
					if($('asearchpanel').rmrftype[0].checked)
						theurl += "&searchinclude=RM";
					if($('asearchpanel').rmrftype[1].checked)
						theurl += "&searchinclude=RF";
				}
				if(($('asearchpanel').rmrftype[2].checked) ){
					theurl += "&editorial=not";
					xtrasql	+= "+(releasedmodel+or+releasedproperty+or+releasednotapplicable+or+releasedmodelandproperty)";
				}
			}
	
			
	
					theurl += xtrasql;
			if(typeof($('asearchpanel').orient) != 'undefined'){
				if($('asearchpanel').orient[0].checked == true && $('asearchpanel').orient[1].checked == true && $('asearchpanel').orient[2].checked == true && $('asearchpanel').orient[3].checked == true){
				} else {
					if ($('asearchpanel').orient[0].checked == true){
						theurl += '&orient=horizontal';
					}
					if ($('asearchpanel').orient[1].checked == true){
						theurl += '&orient=vertical';
					}
					if ($('asearchpanel').orient[2].checked == true){
						theurl += '&orient=panoramic';
					}
					if ($('asearchpanel').orient[3].checked == true){
						theurl += '&orient=square';
					}
				}
			}
	
			if(typeof($('asearchpanel').color) != 'undefined'){
				if ($('asearchpanel').color[0].checked && ! $('asearchpanel').color[1].checked){
					theurl += '&color=color';
				}
				if ($('asearchpanel').color[1].checked && ! $('asearchpanel').color[0].checked){
					theurl += '&color=gray';
				}
			}
	
			if(typeof($('asearchpanel').type) != 'undefined'){
				if ($('asearchpanel').type[0].checked && ! $('asearchpanel').type[1].checked){
		                        theurl += '&searchinclude=illustration';
		                }
		                if ($('asearchpanel').type[1].checked && ! $('asearchpanel').type[0].checked){
		                        theurl += '&searchinclude=photography';
		                }
				if ($('asearchpanel').type[2].checked ){
	                                theurl += '&format=vector&dreamstime=1';
	                        }
	
			}
	
			if(typeof($('asearchpanel').tsort) != 'undefined'){
				if($('asearchpanel').tsort.value != ""){
					theurl += '&sort=' + $('asearchpanel').tsort.options[$('asearchpanel').tsort.selectedIndex].value;		
				}
			}
	
			if(typeof($('asearchpanel').editorial) != 'undefined'){
				if($('asearchpanel').editorial.checked){
					theurl += '&editorial=only';
				}
			}

/*	
			if(typeof($('asearchpanel').people) != 'undefined'){
	                        if($('asearchpanel').people[1].checked != ""){
	                                theurl += '&people=withpeople';
	                        }
				if($('asearchpanel').people[2].checked != ""){
	                                theurl += '&people=nobody';
	                        }
	
	                }
	
*/
	
			gsetCookie("gwhichstartpage","", "", "/", gGetCookieDom());
			if($('Layer1')){$('Layer1').innerHTML = '<center><img src=/graphics/spacer.gif height=150 width=1 border=0></img><h1>searching ...';}
			var newurl='';	
			for (i = 0; i < theurl.length; i++){
				var c = theurl.charAt(i);
				if( c ==' '){
					newurl +='+';
				} else {
					newurl +=c;
				}
				
			}
			if(gform.Keywords.value.match(/g8|g20/i)){
				if(confirm("Click ok to view a special live feed of G8 and G20 images from Getstock")){
				      self.location = '/SwishSearch?n=1&fn=16232';
		                      goinghome=1;
				} else{
				      self.location = newurl;
		                      goinghome=1;
				}
			}
			else if(self.location.href.indexOf('tools')>0){
//				alert(newurl);
				self.location = newurl;
				goinghome=1;
			} else {
				self.location = newurl;
				goinghome=1;
			}
		
		}	
	}
}

function greleasedselect(tsetval) {

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




function fsearchprefs(val,mode) {
	var gsearchprefs = ggetCookie('gsearchprefs');
	if(gsearchprefs){
	} else {
		gsearchprefs= new String(" ");
	}
	var buildpref = new String(" ");
	if($('asearchpanel') != null){

		
		
		if(!$('asearchpanel').rmrftype[0].checked)
			buildpref+='a';
		if(!$('asearchpanel').rmrftype[1].checked)
			buildpref+='b';
		if($('asearchpanel').rmrftype[2].checked)
			buildpref+='c';

		if(($('asearchpanel').orient != undefined) && ($('asearchpanel').orient.length == 4)){ 	
	
			if ($('asearchpanel').orient[0].checked==false)
				buildpref+='d';
		
			if ($('asearchpanel').orient[1].checked==false)
				buildpref+='e';
		
			if ($('asearchpanel').orient[2].checked==false)
				buildpref+='f';
		
			if ($('asearchpanel').orient[3].checked==false)
				buildpref+='g';

		}

/*
		if ($('asearchpanel').searchmethod != undefined) {
			if($('asearchpanel').searchmethod.checked)	
				buildpref+='p';
		}
*/

		if ($('asearchpanel').searchmethod != undefined) {
                        if($('asearchpanel').searchmethod.checked)
				swithinchecked = 1;
                }


		if($('asearchpanel').dreamstime != undefined){
                        if(!$('asearchpanel').dreamstime.checked)
				buildpref+='q';
                }

	

		if( ($('asearchpanel').color != undefined) && ($('asearchpanel').color.length ==2)){

			if ($('asearchpanel').color[0].checked==false)
				buildpref+='h';
		
			if ($('asearchpanel').color[1].checked==false)
				buildpref+='i';
	
		}
		
		if(($('asearchpanel').type != undefined) && ($('asearchpanel').type.length ==3)){		
			
			if($('asearchpanel').type[0].checked==false) 
				buildpref+='j';
			
			if($('asearchpanel').type[1].checked==false) 
				buildpref+='k';
			if($('asearchpanel').type[2].checked) 
				buildpref+='l';
		}

/*
		 if(($('asearchpanel').people != undefined)){
			if($('asearchpanel').people[0].checked==false)
                                buildpref+='m';
			 if($('asearchpanel').people[1].checked==true)
                                buildpref+='n';
			 if($('asearchpanel').people[2].checked==true)
                                buildpref+='o';
		 }
	
*/
	
		if(($('asearchpanel').editorial != undefined)){
        	        if($('asearchpanel').editorial.checked == true)
				buildpref+='p';
	        }


		if($('asearchpanel').tsort != undefined){
	
			if ($('asearchpanel').tsort.selectedIndex == 0)
				buildpref+='s';
			
			if ($('asearchpanel').tsort.selectedIndex == 1)
				buildpref+='t';
		
			if ($('asearchpanel').tsort.selectedIndex == 2)
				buildpref+='u';
		
			if ($('asearchpanel').tsort.selectedIndex == 3)
				buildpref+='v';
		
			if ($('asearchpanel').tsort.selectedIndex == 4)
				buildpref+='w';
			if ($('asearchpanel').tsort.selectedIndex == 5)
				buildpref+='x';
			if ($('asearchpanel').tsort.selectedIndex == 6)
				buildpref+='y';
		
			if ($('asearchpanel').tsort.selectedIndex == 7)
				buildpref+='z';

		}
}
		gsetCookie("gsearchprefs",buildpref, '', '/', gGetCookieDom());
}


function loadsearchprefs (){

	var gsearchprefs = ggetCookie('gsearchprefs');
	if (gsearchprefs){
	} else { gsearchprefs=new String(" ");}

	if( $('asearchpanel') != null ){

	if(gsearchprefs.indexOf("a")>=0)
		$('asearchpanel').rmrftype[0].checked = false;
	else
		$('asearchpanel').rmrftype[0].checked = true;


	if(gsearchprefs.indexOf("b")>=0)
		$('asearchpanel').rmrftype[1].checked = false;
	else
		$('asearchpanel').rmrftype[1].checked = true;

	
	if(gsearchprefs.indexOf("c")>=0)
		$('asearchpanel').rmrftype[2].checked = true;
	else
		$('asearchpanel').rmrftype[2].checked = false;

	if(($('asearchpanel').orient != undefined) && ($('asearchpanel').orient.length ==4 )){
		 if(gsearchprefs.indexOf("d")>=0)
			$('asearchpanel').orient[0].checked = false;
		 else
			$('asearchpanel').orient[0].checked = true; 

		 if(gsearchprefs.indexOf("e")>=0)
			$('asearchpanel').orient[1].checked = false;
		 else
			$('asearchpanel').orient[1].checked = true;

		 if(gsearchprefs.indexOf("f")>=0)
			$('asearchpanel').orient[2].checked = false;
		 else
			$('asearchpanel').orient[2].checked = true;
		 
		if(gsearchprefs.indexOf("g")>=0)
			$('asearchpanel').orient[3].checked = false;
		else
			$('asearchpanel').orient[3].checked = true;

	}

/*
	if ($('asearchpanel').searchmethod != undefined) {
		if(gsearchprefs.indexOf("p")>=0)
                        $('asearchpanel').searchmethod.checked=true;
        }
*/

	if ($('asearchpanel').searchmethod != undefined) {
                if(swithinchecked)
			$('asearchpanel').searchmethod.checked=true; 
        }



	 if($('asearchpanel').dreamstime != undefined){
		if(gsearchprefs.indexOf("q")>=0)
                        $('asearchpanel').dreamstime.checked=false;
        }



	if(($('asearchpanel').color != undefined) && ($('asearchpanel').color.length ==2)){
		 if(gsearchprefs.indexOf("h")>=0)
			$('asearchpanel').color[0].checked = false;
		 else
			$('asearchpanel').color[0].checked = true;
		
		 if(gsearchprefs.indexOf("i")>=0)
			$('asearchpanel').color[1].checked = false;
		else	
			$('asearchpanel').color[1].checked = true;

	}
	
	if(($('asearchpanel').type != undefined) && ($('asearchpanel').type.length ==2)){
                 if(gsearchprefs.indexOf("j")>=0)
                        $('asearchpanel').type[0].checked = false;
		 else
                        $('asearchpanel').type[0].checked = true;

                 if(gsearchprefs.indexOf("k")>=0)
                        $('asearchpanel').type[1].checked = false;
		else
                        $('asearchpanel').type[1].checked = true;

		  if(gsearchprefs.indexOf("l")>=0)
                        $('asearchpanel').type[2].checked = true;
                else
                        $('asearchpanel').type[2].checked = false;

        }

/*
	if(($('asearchpanel').people != undefined) && ($('asearchpanel').people.length ==3)){
                 if(gsearchprefs.indexOf("m")>=0)
                        $('asearchpanel').people[0].checked = false;
                 else
                        $('asearchpanel').people[0].checked = true;

                 if(gsearchprefs.indexOf("n")>=0)
                        $('asearchpanel').people[1].checked = true;
                else
                        $('asearchpanel').people[1].checked = false

                  if(gsearchprefs.indexOf("o")>=0)
                        $('asearchpanel').people[2].checked = true;
                else
                        $('asearchpanel').people[2].checked = false;

        }
*/

	if(($('asearchpanel').editorial != undefined)){
		if(gsearchprefs.indexOf("p")>=0)
			$('asearchpanel').editorial.checked = true;
	}


	  if($('asearchpanel').tsort != undefined){
		if(gsearchprefs.indexOf("s")>=0)
			$('asearchpanel').tsort.selectedIndex == 0;
		if(gsearchprefs.indexOf("t")>=0)
			$('asearchpanel').tsort.selectedIndex == 1;
		if(gsearchprefs.indexOf("u")>=0)
			$('asearchpanel').tsort.selectedIndex == 2;
		if(gsearchprefs.indexOf("v")>=0)
			$('asearchpanel').tsort.selectedIndex == 3;
		if(gsearchprefs.indexOf("w")>=0)
			$('asearchpanel').tsort.selectedIndex == 4;
		if(gsearchprefs.indexOf("x")>=0)
			$('asearchpanel').tsort.selectedIndex == 5;
		if(gsearchprefs.indexOf("y")>=0)
			$('asearchpanel').tsort.selectedIndex == 6;
		if(gsearchprefs.indexOf("z")>=0)
			$('asearchpanel').tsort.selectedIndex == 7;

         }

	}

}


