function update_sorted_table(cmd, script, div_id, order_by, direction)
{
	var cmd = 'cmd=' + cmd + '&';
	cmd += 'div_id=' + div_id + '&';
	cmd += 'order_by=' + order_by + '&';
	cmd += 'direction=' + direction;
	
	var update_request = new AjaxRequest(div_id, script, cmd);
	handle_request(update_request);
}

function setIDTextSelected(id, fntWeight, decoration)
{
	document.getElementById(id).style.fontWeight = fntWeight;
	
	document.getElementById(id).style.textDecoration = decoration;
}

function callFlashFunc(funcTitle,flashID,params)
{	
	var flashMov = document.getElementById(flashID);
	flashMov.extJS_call(encodeURIComponent(funcTitle)+','+encodeURIComponent(params));
}

var media_center_description_interval;
var media_center_description_counter = 0;
var media_center_description_speed = 1;

function start_show_media_center_description(do_hide)
{
	var desc_div = document.getElementById('description_div');
	
	if(desc_div.innerHTML != '')
	{
		clearInterval(media_center_description_interval);
		media_center_description_interval = setInterval('show_media_center_description(' + do_hide + ')', 1);
	}
}

function start_hide_media_center_description()
{
	var desc_div = document.getElementById('description_div');
	
	if(desc_div.style.visibility != 'hidden')
	{
		clearInterval(media_center_description_interval);
		media_center_description_interval = setInterval('hide_media_center_description()', 1);
	}
}

//we show the box by setting the visibility of the element and incrementing the height smoothly
function show_media_center_description(do_hide)
{
	var obj = document.getElementById('description_div');
	
	//Depending on the amount of text, set the maximum height here in pixels
	if(media_center_description_counter >= 100)
	{		
		obj.style.opacity = '';
		obj.style.filter = '';
		
		clearInterval(media_center_description_interval);
		
		if(do_hide) start_hide_media_center_description();
		
		return;
	}
	
	obj.style.visibility = 'visible';
	
	media_center_description_counter += media_center_description_speed;
	
	obj.style.opacity = (media_center_description_counter / 10);						//FireFox, Safari etc
	obj.style.filter = 'alpha(opacity='+(media_center_description_counter * 10)+');';	//Internet Explorer
}

//same way as above but reversed
function hide_media_center_description()
{
	var obj = document.getElementById('description_div');
	
	if(media_center_description_counter <= 2)
	{
		obj.style.visibility = 'hidden';
		
		clearInterval(media_center_description_interval);
		
		return;
	}
	
	media_center_description_counter -= media_center_description_speed;
	
	obj.style.opacity = (media_center_description_counter / 10);						//FireFox, Safari etc
	obj.style.filter = 'alpha(opacity='+(media_center_description_counter * 10)+');';	//Internet Explorer
}

var media_center_interval;
var media_center_counter = 0;
var media_center_menu_height = 135;
var media_center_speed = 5;

//we show the box by setting the visibility of the element and incrementing the height smoothly
function show_media_center_menu(id)
{
	var obj = document.getElementById('media_center_menu_' + id);
	var autech_logo_img = document.getElementById('autech_logo');
	
	var alpha_value = ((media_center_counter / media_center_menu_height) * 10);
	
	//Depending on the amount of text, set the maximum height here in pixels
	if(media_center_counter >= media_center_menu_height)
	{
		obj.style.height = media_center_menu_height + 'px';
		
		obj.style.opacity = '';
		obj.style.filter = '';
		
		clearInterval(media_center_interval);
		return;
	}
	
	obj.style.visibility = 'visible';
	
	media_center_counter += media_center_speed;
	
	obj.style.height = media_center_counter + 'px';
	
	obj.style.opacity = (alpha_value / 10);							//FireFox, Safari etc
	obj.style.filter = 'alpha(opacity='+(alpha_value * 10)+');';	//Internet Explorer
}

//same way as above but reversed
function hide_media_center_menu(id)
{
	var obj = document.getElementById('media_center_menu_' + id);
	var autech_logo_img = document.getElementById('autech_logo');
	
	if(media_center_counter <= 2)
	{
		obj.style.visibility = 'hidden';
		
		obj.style.height = 0 + 'px';
		
		clearInterval(media_center_interval);
		return;
	}
	
	media_center_counter -= media_center_speed;
	
	obj.style.height = media_center_counter + 'px';
	
	var alpha_value = ((media_center_counter / media_center_menu_height) * 10);
	
	obj.style.opacity = (alpha_value / 10);							//FireFox, Safari etc
	obj.style.filter = 'alpha(opacity='+(alpha_value * 10)+');';	//Internet Explorer
}

function toggle_media_gallery_menu(id)
{
	var menu_div = document.getElementById('media_center_menu_' + id);
	var menu_button_img = document.getElementById('media_center_menu_button_img_' + id);
	
	if(menu_div.style.visibility == 'hidden')
	{
		clearInterval(media_center_interval);
		media_center_interval = setInterval('show_media_center_menu(\'' + id + '\')', 1);
		menu_button_img.src = '../admin/images/media_player_hide_menu.png';
	}
	else
	{
		clearInterval(media_center_interval);
		media_center_interval = setInterval('hide_media_center_menu(\'' + id + '\')', 1);
		menu_button_img.src = '../admin/images/media_player_show_menu.png';
	}
}

function send_media_gallery_to_friend(url)
{
	var status_div = document.getElementById('send_to_friend_status');
	status_div.innerHTML = '<span style="color: #FF0000;">Sending...</span>';
	
	var name_field = document.getElementById('name');
	var email_field = document.getElementById('email');
	var message_field = document.getElementById('message');
	
	var send_to_friend_request = new AjaxRequest('send_to_friend_status', '../admin/kitchensink.php', 'cmd=send_media_center_friend&name=' + name_field.value + '&email=' + email_field.value + '&message=' + message_field.value + '&url=' + url);
	handle_request(send_to_friend_request);
}

//LOG JAVASCRIPT ERROR HANDLER
window.onerror = function(msg, url, line)
{
	var browserInfo = 'BROWSER INFO:User Agent: '+navigator.userAgent+'\r\nLocation: '+document.location+'\r\nCookies Enabled: '+navigator.cookieEnabled+'\r\nScreen Resolution: '+screen.width+'x'+screen.height+' ('+screen.colorDepth+'bit)';
	var jsErrorInfo = "\r\nJAVASCRIPT ERROR INFO:\r\nJS Error: " + msg + '\r\nJS File: ' + url + "\r\nJS Line: " + line;
	if(document.location.toString().indexOf('autech.local')!=-1)
	{
		if(typeof(msg)!='object') //wysiwyg pro was sending bogus errors with msg as an object.. Couldnt figure out why.
		{
			alert(msg+'Please report this javascript error to webmaster@autech.com.au\r\n\r\n----------------------------------------------------\r\n'+browserInfo+'\r\n'+jsErrorInfo+'\r\n----------------------------------------------------');
		}
	}
}

// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function flashDivWarning(el,siteRootPath,vNum)
{
	var vNumSplit = vNum.split(',');
	var vd = DetectFlashVer(vNumSplit[0],vNumSplit[1],vNumSplit[2]);
	if(vd[0]!==true)
	{
		var imgPath = siteRootPath+'images/getFlash.gif';
		var htmlCont = '<table cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td valign="middle"><div align="center"><a href="http://www.adobe.com/go/getflashplayer" style="font-size:x-small;font-family:Verdana,Arial,Helvetica,sans-serif;color:#333333;font-weight:normal;"><img src="'+imgPath+'" border="0" alt="Adobe Flash version &quot;'+vNum+'&quot; required" title="Adobe Flash version &quot;'+vNum+'&quot; required" /></a></div></td></tr></table>';
		el.innerHTML=htmlCont;
		el.style.backgroundColor='#DDDDDD';
	}
	//WARNING.... When updateing version number you must also update the
	//admin/images/getFlash.gif file
}
function frameDetect()
{
	if(top!=self)
	{
		document.body.innerHTML = '<table align="center" cellpadding="20"><tr><td><div align="center"><b>Page Error</b><br />This page does not support running inside a frame.</center></td></tr></table>';
	}
}
function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");		
			// default to the first public version
			version = "WIN 6,0,21,0";
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {}
	}
	
	if (!version)
	{
        try
		{
			//seen a few strange installs fail one of the above whilst being successfull here
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
            version = axo.GetVariable("$version");
        }
		catch(e){}
	}
	
	if (!version)
	{
		version = -1;
	}
	return version;
}
// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	var versionArray,tempArray ,tempString;
	var versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return [false,versionStr];
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        // is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return [true,versionMajor+','+versionMinor+','+versionRevision];
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return [true,versionMajor+','+versionMinor+','+versionRevision];
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return [true,versionMajor+','+versionMinor+','+versionRevision];
			}
		}
		return [false,versionMajor+','+versionMinor+','+versionRevision];
	}
	else
	{
		return [false,versionStr];
	}
}

//adds prompt text to end of url ... max 256 chars(Just so we dont break any url max lengths)
function promptBeforeLink(msgStr,linkStr)
{
	var reply = prompt(decodeURIComponent(msgStr), "");
	if(reply.length>256)
	{
		alert('String must be less than 256 characters');
	}
	if(reply!==false && reply.length>0)
	{
		parent.location.href = decodeURIComponent(linkStr+encodeURIComponent(reply));
	}
}

//very handy with things like.. are you sure you want to delete links before directing to the delete command.
function OKCancelWindowBeforeLink(msgStr,linkStr)
{
	var fRet;
	fRet = confirm(decodeURIComponent(msgStr));
	if(fRet===true)
	{
		parent.location.href = decodeURIComponent(linkStr);
	}
}
//same as above ... but witha  form submission
function OKCancelWindowBeforeSubmit(msgStr)
{
	//confim returns true of false
	return confirm(decodeURIComponent(msgStr));
}


function user_browser()
{
	var agt = navigator.userAgent.toLowerCase();
	
	if(agt.indexOf("opera") != -1) return 'Opera';
	if(agt.indexOf("staroffice") != -1) return 'Star Office';
	if(agt.indexOf("webtv") != -1) return 'WebTV';
	if(agt.indexOf("beonex") != -1) return 'Beonex';
	if(agt.indexOf("chimera") != -1) return 'Chimera';
	if(agt.indexOf("netpositive") != -1) return 'NetPositive';
	if(agt.indexOf("phoenix") != -1) return 'Phoenix';
	if(agt.indexOf("firefox") != -1) return 'Firefox';
	if(agt.indexOf("safari") != -1) return 'Safari';
	if(agt.indexOf("skipstone") != -1) return 'SkipStone';
	if(agt.indexOf("msie") != -1) return 'Internet Explorer';
	if(agt.indexOf("netscape") != -1) return 'Netscape';
	if(agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if(agt.indexOf('\/') != -1)
	{
		if(agt.substr(0,agt.indexOf('\/')) != 'mozilla')
		{
			return navigator.userAgent.substr(0,agt.indexOf('\/'));
		}
		else return 'Netscape';
	}
	else if (agt.indexOf(' ') != -1) return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}

function survey_increment_node_offset(offset)
{
	var node_offset = parseInt(document.forms.form.node_offset.value);
	
	node_offset += parseInt(offset);
	
	document.forms.form.node_offset.value = node_offset;
}

function survey_survey_complete(value)
{
	document.forms.form.survey_complete.value = value;
}

function rand(min, max)
{
	if(max)
	{
		return Math.floor(Math.random() * (max - min + 1)) + min;
	}
	else
	{
		return Math.floor(Math.random() * (min + 1));
	}
}

function new_public_user_password_field()
{
	var randomPassword = '';

	//generate 6 character password
	for(var counter = 0; counter < 6; counter++)
	{
		var randNum = rand(0, 9);
		var randLetter = String.fromCharCode(rand(97, 122));
		
		var letterOrNum = rand(0, 1);
		
		if(letterOrNum == 0)
		{
			randChar = randLetter;
		}
		else if(letterOrNum == 1)
		{
			randChar = randNum;
		}
		
		randomPassword += randChar;
	}
	
	document.forms.save_new_user_form.password.value = randomPassword;
}

//To Stop Activate Clicking
function embedExtJSFlash(codeBase,swfLink,movWidth,movHeight,flashVars,wmode){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+codeBase+'" width="'+movWidth+'" height="'+movHeight+'">');
	document.write('<param name="movie" value="'+swfLink+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wMode" value="'+wmode+'">');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="FlashVars" value="'+flashVars+'">');
	document.write('<embed wmode="'+wmode+'" FlashVars="'+flashVars+'" src="'+swfLink+'" width="'+movWidth+'" height="'+movHeight+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>');
	document.write('</object>');
}

function readCookie(cookieName)
{
	var theCookie=""+document.cookie;	
	
	var ind=theCookie.indexOf(cookieName);
	if(ind==-1 || cookieName=="")
	{
		return "";
	}
	var ind1=theCookie.indexOf(';',ind);
	if(ind1==-1)
	{
		ind1=theCookie.length;
	}
	var retStr = unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	return retStr;
}

function setCookie(cookieValueAndParams)
{
	var cookieSplit = cookieValueAndParams.split(',');
	if(cookieSplit.length==2)
	{
		var cookieName = cookieSplit[0];
		var cookieValue = unescape(cookieSplit[1]);
		var today = new Date();
		var expire = new Date();
		expire.setTime(today.getTime() + 3600000*24*10);
		//path=/ used to keep all cookies together (was an issue as flash was executing JS from different location to the main.html
		document.cookie = cookieName+"="+escape(cookieValue) + ";path=/ ;expires="+expire.toGMTString();
		
		return cookieValue;
	}
}


function autech_preloadImages(imgLinks)
{
	for(var i=0; i<imgLinks.length; i++)
	{
		var img=new Image;
		img.src=imgLinks[i];
	}
}

function autech_swapImg(idStr,overImgLink)
{
	var imgObj = document.getElementById(idStr);
	imgObj.oSrc = imgObj.src;
	imgObj.src = overImgLink;
}
function autech_restoreImg(idStr)
{
	var imgObj = document.getElementById(idStr);
	imgObj.src = imgObj.oSrc;
}

//Standard MM/Adobe Functions
function MM_swapImgRestore() {
  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() {
  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) {
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() {
  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];}
}
function MM_jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  	newwin=window.open(theURL,winName,features);
	newwin.focus();
}