function JS_sniffit() {
	var t = document.getElementById("tableFooter");
	var diff = screen.availHeight - (215 + t.clientHeight);
	if ( t.offsetTop < diff ) {
		t.style.position = 'absolute';
		t.style.top = diff;
	}
}


//---------------------------------------------------------------------
function JS_confirmAction(msg) {
	var txt = "Are you sure?";

	if ( msg )
		txt = txt + ":\n" + msg;

	if ( confirm (txt) )
		return true;
	else
		return false;
}


//---------------------------------------------------------------------
function JS_showStatus(sMsg) {
    window.status = sMsg ;
}


//---------------------------------------------------------------------
// w = width of new window;		h = height of new window
// specs = attributes of new window
function JS_popupWindow(url,name,w,h,specs) {

	// x=left;	y=top
	var x = (document.body.clientWidth - w)/2;
	var y = (document.body.clientHeight - h)/2;

	var sp = 'width='+w+',height='+h+',left='+x+',screenX='+x+',top='+y+',screenY='+y+','+specs;

	pop = window.open(url,name,sp);
	pop.focus();
}


//---------------------------------------------------------------------
/*
		'oID' is object id, the id of tag to show or hide

		if you have set an array 'tglThis' in your script,
		with ids of your multiple screens, script will:
			set all screens to display=none
			before setting target screen to display=block

		EXAMPLE
		The following 2 statements are optionally used by toggleThis():

			// array - alternate between 2 or more screens
			var tglThis = new Array('frmCats','frmTypes');

			// boolean - don't close all screens
			var dontClose = true;
*/
function JS_toggleThis(oID) {
	if ( !oID ) {
		alert("No object sent in 'common.js::toggleThis(obj);'");
		return false;
	}
	var o = document.getElementById(oID);

	try {
		if ( o.style.display == 'block' && !dontClose)
			o.style.display = 'none';
		else {
			try {
				if ( tglThis ) {
					for ( var i=0; i<tglThis.length; i++ ) {
						document.getElementById(tglThis[i]).style.display='none';
					}
				}
			}
			catch(e) {
				// do nothing
			}
			o.style.display = 'block';
		}
	}
	catch(e) {
		if ( o.style.display == 'block' )
			o.style.display = 'none';
		else {
			try {
				if ( tglThis ) {
					for ( var i=0; i<tglThis.length; i++ ) {
						document.getElementById(tglThis[i]).style.display='none';
					}
				}
			}
			catch(e) {
				// do nothing
			}
			o.style.display = 'block';
		}
	}
}


//---------------------------------------------------------------------
// gets the cookie, if it exists
function JS_Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


//---------------------------------------------------------------------
/*
Set_Cookie() only the first 2 parameters are required: name, value.

The Set_Cookie values for 'domain' and 'secure' are not utilized. Use
'domain' on the Javascript cookie if you are using it on a subdomain,
like widgets.yoursite.com, where the cookie is set on the widgets
subdomain, but you need it to be accessible over the whole
yoursite.com domain.

It's good practice to not assume the path to the site root will be set
the way you want it by default, so do this manually as a rule, '/'. If
no value is set for expires, it will only last as long as the current
session of the visitor, and will be automatically deleted when they
close their browser.
*/
function JS_Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}


//---------------------------------------------------------------------
// The same 'name' & 'path' & 'domain' used in Set_Cookie()
function JS_Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//---------------------------------------------------------------------


function GetXmlHttpObject(){
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}

//---------------------------------------------------------------------
var xmlHttpRating;

function updateRating(rating, uid, med_id){

	xmlHttpRating=GetXmlHttpObject();
	if (xmlHttpRating==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	var url="ajaxRating.php";
	url=url+"?rating="+rating;
	url=url+"&uid="+uid;
	url=url+"&mid="+med_id;
	url=url+"&sid="+Math.random();
	xmlHttpRating.onreadystatechange=updateRatePics;
	xmlHttpRating.open("GET",url,true);
	xmlHttpRating.send(null);

}

//-----------------------------------------------------------------------------------

function updateRatePics(){

	if ( xmlHttpRating.readyState==4 ){
		var mid_rate = xmlHttpRating.responseText;
		var theUnderscore = mid_rate.indexOf("_");
		var med_id = mid_rate.substr(0,theUnderscore);
		var rating = mid_rate.substr(theUnderscore+1);

		//Update Light Pics
		for ( var i=1; i<=rating; i++ ){
//					document.getElementById(med_id+"_"+i).src = "images/voteDickLight"+i+".jpg";
			document.getElementById(med_id+"_"+i).src = "images/light"+i+".ico";
		}

		//Update Dark Pics
		rating++;
		for ( var i=rating; i<=5; i++ ){
//					document.getElementById(med_id+"_"+i).src = "images/voteDickDark"+i+".jpg";
			document.getElementById(med_id+"_"+i).src = "images/dark"+i+".ico";
		}
	}

}

//----------------------------------------------------------------------------------

function checkAllBoxes(formName, boxName){
	//Set true or false
	var tf = document.formName.checked == true ? false : true;
	//Get element
	var boxRay = document.getElementById(boxName);
	//check or uncheck
	alert(boxRay.length);

	for (var i=0; i<=boxRay.length; i++ ){
		document.getElementById(boxRay[i]).checked = tf
	}
}

//--------------------------------------------------------------------------------
	function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
