// PLEASE NOTE, THIS CODE SHOULD BE RE_WRITTEN!!!!!!


// JavaScript Document
function $( sElementId ) {
	return document.getElementById(sElementId) ;
}

var the_picture_width = 0;
var the_picture_height = 0;
var fit_mode    = 0;

function reloadCaptcha()
{
//document.getElementById('captcha').src ="includes/securimage_show.php?" + Math.random();

document.getElementById('captcha').src 
='/includes/captcha/securimage_show.php?' + Math.random();
document.getElementById('code').focus();
}


var ScaleFuncs = {
	// ------------------------------------------------------------------
	// Get window (image) size in pixels; return [0, 0] if unidentifiable
	// ------------------------------------------------------------------
	GetWindowDims : function () {
	    var d  = document;
	    var de = d.documentElement;
	    if (de && typeof de.clientWidth != 'undefined'
	        && de.clientWidth != 0) {
	        return [de.clientWidth, de.clientHeight];
	    }
	    else if (d.body && typeof d.body.clientWidth != 'undefined') {
	        return [d.body.clientWidth, d.body.clientHeight];
	    }
	    else if (typeof window.innerWidth != 'undefined') {
	        return [window.innerWidth, window.innerHeight];
	    }
	    else {
	        // alert ("Can't identify window width.");
		return [0, 0];
	    }
	},

	GetImageDims : function (image) {
	    var image_width  = 900;
            //image.width;
	    var image_height = image.height;

	    // Fix IE problems
	    if (image_width == 0 || image_height == 0) {
	        var img = image.outerHTML;
		if (typeof(img) == 'string') {
		  var w_match  = img.match(/width\s*=\s*['"]?(\d+)['"]?/);
		  var h_match  = img.match(/height\s*=\s*['"]?(\d+)['"]?/);
		  image_width  = w_match[1];
		  image_height = h_match[1];
		}
	    }
            //alert ("GetImageDims image width " + image );
	    return [image_width, image_height];
        },

	Scale : function (button, force) {
	    var image      = $('the_picture');
	    var win_dims   = ScaleFuncs.GetWindowDims();
	    var fit_width  = win_dims[0] - 26;
	    var fit_height = win_dims[1] - 72;
	    var fit_ratio  = 1;


//            alert ("selected is " + fit_width + "  " + the_picture_width + " " + the_picture_height );

	    if (   the_picture_width <= 0 || the_picture_height <= 0
	        ||  fit_width <= 0 ||  fit_height <= 0) {
	        return;
	    }


	    if (force != 1) {
	        fit_mode = (fit_mode + 1) % 3;
            }

	    if (fit_mode == 1) {
	        // Smaller of height and width
		fit_ratio        = Math.min(fit_width  / the_picture_width,
		                            fit_height / the_picture_height);
	        fit_ratio        = Math.min(fit_ratio, 1);
		window.onresize  = function () { ScaleFuncs.Scale(button, 1) };
		button.innerHTML = 'Fit Width';
	    }
	    else if (fit_mode == 2) {
		// Width only
	        fit_ratio        = Math.min(fit_width / the_picture_width, 1);
		window.onresize  = function () { ScaleFuncs.Scale(button, 1) };
		button.innerHTML = 'Full Size';
	    }
	    else {
		// No fit
		fit_mode         = 0;
	        window.onresize  = null;
		button.innerHTML = 'Fit Image';
	    }

	    image.width     = fit_ratio * the_picture_width;
	    image.height    = fit_ratio * the_picture_height;
	    document.cookie = 'the_picture=' + fit_mode + ';path=/;max-age=631152000';

	},

	TestFit : function () {
	    var cookies = document.cookie.split(/;\s*/);
	    var do_fit  = 1;
	    for (var i in cookies) {
		if (   cookies[i].length > 7
		    && cookies[i].substr(0,7) == "the_picture=") {
		    var mode = cookies[i].substr(7);
		    do_fit   = mode;
		    fit_mode = mode - 1;
		}
	    }
	    if (do_fit != 0) {
            //alert ("selected is " + do_fit + " " + the_picture_width );
	        ScaleFuncs.Scale($('the_picture'), 0);
	    }
	}
};


var Feedback =
  {
  RadioBut : function ( ) 
    {
     //a variable that will hold the index number of the selected radio button
    for (i=0;i<document.thoughts.myradio.length;i++)
      {
      if (document.thoughts.myradio[i].checked==true)
        {
        theone=i
        alert ("selected is " + theone + " " + document.thoughts.myradio[i].id );
        } 
      }  
    }
  
};

function f_clientWidth() 
{
return f_filterResults 
  (
  window.innerWidth ? window.innerWidth : 0,
  document.documentElement ? document.documentElement.clientWidth : 0,
  document.body ? document.body.clientWidth : 0
  );
}
function f_clientHeight() 
  {
  return f_filterResults 
    (
	window.innerHeight ? window.innerHeight : 0,
	document.documentElement ? document.documentElement.clientHeight : 0,
	document.body ? document.body.clientHeight : 0
    );
}
function f_scrollLeft() 
{
return f_filterResults 
  (
  window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
  );
}
function f_scrollTop() 
  {
  return f_filterResults  
     (
      	window.pageYOffset ? window.pageYOffset : 0,
	document.documentElement ? document.documentElement.scrollTop : 0,
	document.body ? document.body.scrollTop : 0
     );
  }
function f_filterResults(n_win, n_docel, n_body)  
  {
  var n_result = n_win ? n_win : 0;
  if (n_docel && (!n_result || (n_result > n_docel)))
	n_result = n_docel;
  return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
  }

function selectListGoto(selectlist)
  {
  //alert("The submit_vender function was called.");
  var myindex = selectlist.selectedIndex;
  if (selectlist.options[myindex].title != "")
    {
    var tl = selectlist.options[myindex].title;
    //alert ( tl );

    location = tl;
    }
  }

var time = 3000;
var numofitems = 7;


//menu constructor
function menu(allitems,thisitem,startstate)
  { 
  callname= "gl"+thisitem;
  divname="subglobal"+thisitem;  
  this.numberofmenuitems = 7;
  this.caller = document.getElementById(callname);
  this.thediv = document.getElementById(divname);
  this.thediv.style.visibility = startstate;
  }

//menu methods
function ehandler(event,theobj){
  for (var i=1; i<= theobj.numberofmenuitems; i++){
    var shutdiv =eval( "menuitem"+i+".thediv");
    shutdiv.style.visibility="hidden";
  }
  theobj.thediv.style.visibility="visible";
}
				
function closesubnav(event){
  if ((event.clientY <48)||(event.clientY > 107)){
    for (var i=1; i<= numofitems; i++){
       var shutdiv =eval("menuitem"+i+".thediv");
      shutdiv.style.visibility="hidden";
    }
  }
}


