<!-- The following forces redirection to main page framework-->
<!-- if 'sub-file' loading is attempted.  -->

<!-- Following lines of code must be placed in each file requiring possible redirection: -->
<!-- <SCRIPT LANGUAGE="JavaScript" SRC="../../testdirect.js"   -->
<!-- < /script>   remove space before /    -->

<!-- Also, in body declaration place this code: onLoad="redirect()"    -->

function redirect() {
//alert('inside redirect');
//alert(self.location);
//alert(top.location);
if (self.location == top.location)
// && location.search.substring(1) != 'nf')
  top.location.href = 'http://www.ronhayward.net?' + self.location;
}


////////// Following returns a date string for output elsewhere in form MM/DD/YYYY ///////////////
//////// Must be passed a date string mytime, and myformat defining predefined output
///// 0 (zero): no leading zeros, 2-digit year
////  1       : no leading zeros, 4-digit year
////  2       : leading day zero, 2-digit year
////  3       : leading day zero, 4-digit year
////   month never has a leading zero
function dateString(mytime,myformat) {
  ds='';
  delimiter1 = mytime.indexOf("/",0);                    // find first slash /
  if (delimiter1!=-1) {
      delimiter2 = mytime.indexOf("/",(delimiter1+1));   // find second /
	  delimiter3 = mytime.indexOf(" ",(delimiter2+1));   // find space
	  mo = mytime.substring(0,delimiter1);               // extract month
	  da = mytime.substring(delimiter1+1,delimiter2);      // extract day of month
	  yr = mytime.substring(delimiter2+1,delimiter3);      // extract year
      longmo = mo;
	  shortmo = mo;
	  longda = da;
	  shortda = da;
	  longyr = yr;
	  shortyr = yr;
      if ((yr.length==2) && (yr.charAt(0)=="9")) {                // year is in 1990s
		shortyr = yr;
		longyr = "19"+yr;
	  }
	  if ((yr.length==2) && (yr.charAt(0)=="0")) {  // year >=2000
	    shortyr = yr;
		longyr = "20"+yr;
	  }
	  if (yr.length==1) { // year >=2000
	    shortyr = "0"+yr;
		longyr = "200"+yr;
	  }
	  if ((yr.length==3) && (yr.charAt(0)=="1")) { // year >=2000, but returned value in 100 range
	    shortyr = yr.substring(1,3);
		longyr = "20"+shortyr;
	  }
 	  if (da.length==1) {  //day of month is 1..9, no leading zero
	    shortda = da;
		longda = "0"+da;
	  }
	  if (yr.length==4) {  //full year was passed
		shortyr = yr.substring(2,4);
	  }
  
  if (myformat==0) ds=mo+"/"+shortda+"/"+shortyr;
  if (myformat==1) ds=mo+"/"+shortda+"/"+longyr;
  if (myformat==2) ds=mo+"/"+longda+"/"+shortyr;
  if (myformat==3) ds=mo+"/"+longda+"/"+longyr;
 
  }  //if delimiter...

  return ds;
}
//-------------------------------------------------------------------------------------------------
// following opens window to display photo tags using tags.php (in root); path and photo filename must be passed to tags.php
// example file mtntreks/grandpass/DSC_0001.jpg called by ... tags.php?f=mtntreks/grandpass/DSC_0001.jpg   no quotes required

function open_win(myfile) // file whose tags are to be displayed
{
	var mytop=150;
	var myheight=360;
	var mywidth=275;
	var myleft = screen.width-mywidth-40;
	myproperties = '';
	myproperties += 'top='+mytop;
	myproperties += ',screenY='+mytop;
	myproperties += ',left='+myleft;
	myproperties += ',screenX='+myleft;
	myproperties += ',width='+mywidth;
	myproperties += ',height='+myheight;
	myproperties += ',titlebar=no';
	myproperties += ',toolbar=no';

//		alert('myfile is '+myfile);//-----------------------------------------------------------------------------
//	if (myfile.search('http://ronhayward.net')==-1) {  //domain does not exist in myfile... add it
//		if (myfile.charAt(0)!='/') {myfile = '/'+myfile;}
//		myfile = 'http://ronhayward.net' + myfile;
//	}
	myfile = '../' + myfile;		//relative reference is required here to get to image file from scripts folder

	
	myurl = 'scripts/tags.php?f='+myfile;
//	alert("myfile is "+myfile);
//	alert("myurl is "+myurl);
	window.open(myurl,'_blank',myproperties);     // myproperties must be a continuous string, no spaces
}


// following opens window to display google map using map.php (in root); path and photo filename must be passed to map.php
// example file http://ronhayward.net/mtntreks/grandpass/DSC_0001.jpg called by ... tags.php?f=mtntreks/grandpass/DSC_0001.jpg   no quotes required

function open_map(myfile) // file whose tags are to be displayed
{
	var mytop=100;
	var myheight=512;    //see also map.php for google map size parameters
	var mywidth=512;     //see also map.php for google map size parameters
	var myleft = screen.width-mywidth-40;
	myproperties = '';
	myproperties += 'top='+mytop;
	myproperties += ',screenY='+mytop;
	myproperties += ',left='+myleft;
	myproperties += ',screenX='+myleft;
	myproperties += ',width='+mywidth;
	myproperties += ',height='+myheight;
	myproperties += ',titlebar=no';
	myproperties += ',toolbar=no';
	
//	alert('myfile is '+myfile);
//	if (myfile.search('http://ronhayward.net')==-1) {  //domain does not exist in myfile... add it
//		if (myfile.charAt(0)!='/') {myfile = '/'+myfile;}
//		myfile = 'http://ronhayward.net' + myfile;
//	}
	myfile = '../' + myfile;		//relative reference is required here to get to image file from scripts folder
	
	myurl = 'scripts/map.php?f='+myfile;
//	alert("myfile is "+myfile);
//	alert("myurl is "+myurl);
	window.open(myurl,'',myproperties);     // myproperties must be a continuous string, no spaces
}




function parse_qs()    // retrieves query string from url, returns array of terms; array[0] contains number of terms
{
    alert("In parse query");
	qs = parent.location.href.split("?");   //split url from parameters 
	alert(qs[0]);
	if (qs[1]!=null) {                              //if parameter list exists...
	    alert("qs is "+qs[1]);   
		params = qs[1].split(",");              // split parameters by commas                     
		alert("params[0] is "+params[0]);
		alert(params[1]);
		alert(params[2]);
		alert(params[3]);
		alert(params[4]);
		alert(params[5]);
		      
    }
}
