var_default_theme="grey1";

// Google site search + Prevent multiple form submission

var googlesitesearchSubmitted = false;

function validategooglesiteForm(form)
{//alert("Validating")
if(!googlesitesearchSubmitted)
  {googlesitesearchSubmitted = true;
  var v=form.q.value.indexOf('www.octobergallery.co.uk');
  //alert("v is "+v);
  if (v!=-1){}
  else
   { form.q.value+=" +site\:www.octobergallery.co.uk";}

  timeoutUnlockform=setTimeout("googlesitesearchSubmitted=false",3000);

  }
 else
  {return false;}

 return true;
}



 function changepic() {
 if (document.images)
 		{
 		randomimageno=0+randomimageno+1;
  		if (randomimageno==6)
 			{randomimageno=1};
  		document.images['randompic'].src = '/images/homepage_random/'+randomimageno+'.jpg';
 		top.randomimagetimer=setTimeout('startTimer()',3000);
 		}
 }



 function startTimer() { //starts Changepic()
 	top.randomimagetimer=setTimeout('changepic()',2000);
 	}


// -----------------------------------------------------/
// --           get page distance from root           --/
// --                                                 --/
// -----------------------------------------------------/

var thishref=location.href;

// alert('thishref='+thishref);

whichroot=thishref.indexOf('public_html');
if(whichroot!=-1)
	{
	var thispath=thishref.substring(whichroot,thishref.length);
	var thisabroot=thishref.substring(0,whichroot);

	};
whichroot=thishref.indexOf('127.0.0.10');
if(whichroot!=-1)
	{
	var thispath=thishref.substring(whichroot,thishref.length);
	var thisabroot='http://127.0.0.10';
	};
whichroot=thishref.indexOf('octobergallery.co.uk');
if(whichroot!=-1)
	{
	var thispath=thishref.substring(whichroot,thishref.length);
	var thisabroot='http://www.octobergallery.co.uk';

	};

//alert("thisabroot="+thisabroot);

var slashcount="-1";

// alert("thispath = >>"+thispath+"<<");


while(thispath.indexOf('/')!=-1)
{
si=thispath.indexOf('/');
nextpath=thispath;
slashcount++;
thispath=nextpath.substring(si+1,nextpath.length);
}


// alert("slashcount = >>"+slashcount+"<<");

var rootrel="";
if(slashcount>=1)
for (i=1;i<=slashcount;i++)
{
rootrel+="../";
}

// -----------------------------------------------------/
// --           navbar rollover images                --/
// --                                                 --/
// -----------------------------------------------------/

var flag = false;

if (document.images) {
nav_artistson = new Image(71,16); nav_artistson.src = rootrel + "theme/"+var_default_theme+"/navbar/artists_on.gif";
nav_countrieson = new Image(95,16); nav_countrieson.src = rootrel + "theme/"+var_default_theme+"/navbar/countries_on.gif";
nav_exhibitionson = new Image(107,16); nav_exhibitionson.src = rootrel + "theme/"+var_default_theme+"/navbar/exhibitions_on.gif";
nav_eventson = new Image(72,16); nav_eventson.src = rootrel + "theme/"+var_default_theme+"/navbar/events_on.gif";
nav_educationon = new Image(98,16); nav_educationon.src = rootrel + "theme/"+var_default_theme+"/navbar/education_on.gif";
nav_shopon = new Image(57,16); nav_shopon.src = rootrel + "theme/"+var_default_theme+"/navbar/shop_on.gif"; 
flag=true; 
}

if (document.images) {   
nav_artistsoff = new Image(71,16); nav_artistsoff.src = rootrel + "theme/"+var_default_theme+"/navbar/artists_off.gif";
nav_countriesoff = new Image(95,16); nav_countriesoff.src = rootrel + "theme/"+var_default_theme+"/navbar/countries_off.gif";
nav_exhibitionsoff = new Image(107,16); nav_exhibitionsoff.src = rootrel + "theme/"+var_default_theme+"/navbar/exhibitions_off.gif";
nav_eventsoff = new Image(72,16); nav_eventsoff.src = rootrel + "theme/"+var_default_theme+"/navbar/events_off.gif";
nav_educationoff = new Image(98,16); nav_educationoff.src = rootrel + "theme/"+var_default_theme+"/navbar/education_off.gif";
nav_shopoff = new Image(57,16); nav_shopoff.src = rootrel + "theme/"+var_default_theme+"/navbar/shop_off.gif";   
}   

function ietest(x) {if (window.focus) {window.focus()}}

// -----------------------------------------------------/
// --           rollover functions                    --/
// --                                                 --/
// -----------------------------------------------------/


function rollIn(imgName) {
     if (document.images && (flag == true)) {
         document[imgName].src = eval(imgName + "on.src");
     } 
}  

function rollOut(imgName) {  
     if (document.images){
         document[imgName].src = eval(imgName + "off.src");
     } 
} 



// -----------------------------------------------------/
// --           DW rollover functions                    --/
// --                                                 --/
// -----------------------------------------------------/


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_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_findObj(n, d) { //v3.0
  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); return x;
}

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


// -----------------------------------------------------/
// --           Open Restyle Window                   --/
// --                                                 --/
// -----------------------------------------------------/

function restyle()
 {

   //GET SCREEN DIMENSIONS

      var sh=window.screen.height; var sw=window.screen.width;

   //SET SIZE & CENTRING POS ARGS FOR NEW WINDOW

    ww=350; wh=600;
    var posx=parseInt((window.screen.width-ww)/2); if(posx<=0){posx=0};
    var posy=parseInt((window.screen.height-wh)/2)-25; if(posy<=0){posy=0};
 
    posx=0;
    posy=0;

    args = "height=" + wh
         + ",width=" + ww
         + ",top=" + posy
         + ",left=" + posx
         + ",status=1"
         + ",toolbar=0"
         + ",location=0"
         + ",directories=0"
         + ",menubar=0"
         + ",scrollbars=1"
         + ",resizable=1";


    restyleWindow = window.open(rootrel + "maintain/restyle.shtml", "restyleWindow", args);
    
    

 }
 
// -----------------------------------------------------/
// --           Restyle Functions                     --/
// --                                                 --/
// -----------------------------------------------------/

 
 function changemastheadbg2(newbg)
  {  
     restyleWindow.close();

     newbgimage=thisabroot + '/images/mastheads0724/mastheads_0'+newbg+'.gif';

//  get url without location search string

     var lh= location.href;
        var ls= location.search;
        if(lh.indexOf("?")!=-1)
        	{
        	var thisurl=lh.substring(0,lh.indexOf("?"))
        	}
        else
        	{
        	var thisurl=lh
        	}

// add or change location search

        var newls=ls+'mast0'+newbg;
        
        if(ls.indexOf("mast")!=-1)
        	{
        	var mi=ls.indexOf("mast");
        	newls=ls.substring(1,mi) + 'mast0'+newbg;

         	if(ls.length>mi+7)
			{
			newls=ls.substring(1,mi) + 'mast0'+newbg + ls.substring(ls.indexOf("mast")+7,ls.length);
         		}
         
        	}
        	
 // reload page & reopen restyle window
        
        location.href=thisurl+"?"+newls;
        restyle();
     	window.focus();        


  }

function changetheme2(newtheme)
  {
  
     restyleWindow.close();
  
//  get url without location search string

        var lh= location.href;
        var ls= location.search;
        if(lh.indexOf("?")!=-1)
        	{
        	var thisurl=lh.substring(0,lh.indexOf("?"))
        	}
        else
        	{
        	var thisurl=lh
        	}
  
// add or change location search

        var newls=ls+'theme'+newtheme;
        
        if(ls.indexOf("theme")!=-1)
        	{
        	var mi=ls.indexOf("theme");
        	newls=ls.substring(1,mi) + 'theme'+newtheme;

         	if(ls.length>mi+7)
			{
			newls=ls.substring(1,mi) + 'theme'+newtheme + ls.substring(ls.indexOf("theme")+7,ls.length);
         		}
         
        	}
 

 // reload page & reopen restyle window
        
        location.href=thisurl+"?"+newls;
        restyle();
     	window.focus();        
        	
    }







 
 function resize2(x,y)
 {
   window.resizeTo(x,y);
 }
 
 
 
function popupnotes()
 {

   //GET SCREEN DIMENSIONS

      var sh=window.screen.height; var sw=window.screen.width;

   //SET SIZE & CENTRING POS ARGS FOR NEW WINDOW

    ww=350; wh=650;
    var posx=0;
    var posy=0;

    args = "height=" + wh
         + ",width=" + ww
         + ",top=" + posy
         + ",left=" + posx
         + ",status=1"
         + ",toolbar=0"
         + ",location=0"
         + ",directories=0"
         + ",menubar=0"
         + ",scrollbars=1"
         + ",resizable=1";


        var lh= location.href;
        if(lh.indexOf("?")!=-1)
        {
       restyle();         
        }
        else
        {
        }
        
        

 }
 
 // -----------------------------------------------------/
 // --     Function to ammend all hard-coded links     --/
 // --     (except for js:actions and outside URLs)    --/
 // --        so that they include the ss setting      --/
 // -----------------------------------------------------/
 
 function ammendLinks()
   {
//   alert('amendlinks');
   if(location.search)
     {
     linksLen=document.links.length;
     for(i=0; i < linksLen; i++)
        {
        var changelink="yes"; dl=document.links[i];
        if((dl.protocol.toLowerCase()=='javascript\:') || (dl.protocol.toLowerCase()=='mailto\:')) {changelink="no"; }
        if(changelink=="yes") {document.links[i].href=dl.href + location.search; }
        }
      }     
    }
 
 function onLoader()
 {
  ammendLinks(); 
  popupnotes();
 }
 
