function disable_stylesheet_rules(stylesheet_href_search, rules)
{
	if(document.styleSheets)
	{
		var c = document.styleSheets.length;
		var i = 0;
		for(; i < c; i++)
		{
			if(document.styleSheets[i].href != undefined)
			{
				if(document.styleSheets[i].href.search(stylesheet_href_search) != -1)
				{
					var r = 0;
					var num = rules.length;
					for(; r < num; r++)
					{
						for(rule in document.styleSheets[i]['cssRules'])
						{
							if(document.styleSheets[i]['cssRules'][rule] != undefined)
							{
								if(document.styleSheets[i]['cssRules'][rule]['selectorText'] == rules[r]) document.styleSheets[i].deleteRule(rule);
							}
						}
					}
				}
			}
		}
	}
}

function refresh_captcha(img_id)
{
	var now = new Date();
	document.getElementById(img_id).src = '../admin/kitchensink.php?cmd=captcha&rand=' + now.getTime();
}

var Layout = new function() {
	this.rootWindow = function()
	{
		var currWin = window;
        for(a=0;a<10;a++)
		{
            currWin=currWin.parent;
        }
        return currWin;
	}
    this.windowDimensions = function()
    {
		var rWin = this.rootWindow();
    	if(rWin.innerWidth)return {width:rWin.innerWidth,height:rWin.innerHeight};
    	else return {width:rWin.document.body.clientWidth,height:rWin.document.body.clientHeight};
    };
    this.absolutePositionY = function(object)
    {
    	var top = 0;
 	    if(object.offsetParent){
 	        while(1){
 	          top += object.offsetTop;
 	          if(!object.offsetParent)break;
 	         object = object.offsetParent;
 	        }
 	    }else if(object.y){
 	        top += object.y;
 	    }
 	    return top;
    }
    this.absolutePositionX = function(object)
    {
	    var left = 0;
	    if(object.offsetParent){
	        while(1) {
	          left += object.offsetLeft;
	          if(!object.offsetParent)break;
	          object = object.offsetParent;
	        }
	    }else if(object.x){
	        left += object.x;
	    }
	    return left;
    }
	//This method assumes we have an object on screen that is positioned fixed at 0,0 in document
	this.centerObjectToWindow = function(object)
	{
		var winDims = Layout.windowDimensions();
		var newX = Math.round((winDims.width*.5)-(object.offsetWidth*.5));
		var newY = Math.round((winDims.height*.5)-(object.offsetHeight*.5));
		if(newX<0) newX=0;
		if(newY<0) newY=0;
		object.style.top = newY+'px';
		object.style.left = newX+'px';
		
	}
    this.absolutePosition = function(object)
    {
    	return {x:this.absolutePositionX(object),y:this.absolutePositionY(object)}
    } 
}

//http://sixrevisions.com/tutorials/javascript_tutorial/create_lightweight_javascript_tooltip/
var Tooltip=function(){
	var id = 'tooltip';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){Tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){Tooltip.fade(-1)},timer);
		}
	};
}();

function ShadowBox(id){
	this.recenter = function()
	{
		if(promptLayer!==false)	Layout.centerObjectToWindow(promptLayer);
		if (contentFrameLayer !== false) {
			
			Layout.centerObjectToWindow(contentFrameLayer);
		}
	}
	
	this.remove = function()
	{
		if(this.removeFunction!==false) this.removeFunction();
		
		if(rootWin.removeEventListener)
			rootWin.removeEventListener("resize", this.recenter,false);
		else if(rootWin.detachEvent)
			rootWin.detachEvent("onresize", this.recenter);
		
		rootWin.document.body.removeChild(this.shadLayer);
		
	}
	
	this.promptCancel = function()
	{
		if(this.cancelFunction!==false) this.cancelFunction();
		this.remove();
	}
	
	this.promptOK = function()
	{
		if(this.okFunction!==false) this.okFunction();
		this.remove();
	}
	
	this.startCenterEvent = function()
	{
		this.recenter();
		if(rootWin.addEventListener)
			rootWin.addEventListener("resize", this.recenter,false);
		else if( rootWin.attachEvent )
			rootWin.attachEvent("onresize", this.recenter);
	}
	
  this.prompt = function(shadBoxVarName,promptTitle,promptText,okLabel,cancelLabel,useTextField,textFieldValue)
	{
	  rootWin.thisShadowBox = this;
	  
  	if(okLabel == undefined) okLabel = 'OK';
  	if(cancelLabel == undefined) cancelLabel = 'Cancel';
		
		promptLayer = document.createElement('div');
		promptLayer.className='shadPromptBox';
		
		var str = this.htmlWinSeg1+promptTitle.htmlspecialchars()+this.htmlWinSeg2+'Layout.rootWindow().thisShadowBox'+this.htmlWinSeg3+'<div class="shadPromptText">'+promptText+'</div>';
		
		if ((useTextField != undefined) && (useTextField == true))
		{
		  var txt_val = '';
		  if(textFieldValue != undefined) txt_val = textFieldValue;
		  
		  str += '<div style="width: 100%; text-align: center;"><br /><input type="text" id="shadBoxPromptText" name="shadBoxPromptText" style="width: 90%;" value="' + txt_val + '" /><br /><br /></div>';
		}
		
		str += '<table align="center"><tr>';
		
		//dont display Ok button if a label for it was not specified
		if(okLabel != '') str += '<td><input id="shadBoxPromptOK" onclick="Layout.rootWindow().thisShadowBox.promptOK();" class="shadPromptButt" type="button" value="'+okLabel+'" /></div></td>';
		
		//dont display Cancel button if a label for it was not specified
		if(cancelLabel != '') str += '<td><input class="shadPromptButt" type="button" onclick="Layout.rootWindow().thisShadowBox.promptCancel();" value="'+cancelLabel+'" /></td>';
		
		str += '</tr></table>'+this.htmlWinSeg4;

		promptLayer.innerHTML = str;
		
		this.shadLayer.appendChild(promptLayer);
		
		this.startCenterEvent();
		
		if ((useTextField != undefined) && (useTextField == true)) {
			var t = document.getElementById('shadBoxPromptText');
			if (t) {
				t.onkeydown = function(e){
					var e = (window.event ? event : e);
					if (e.keyCode == 13) { //ENTER key!
						var k = document.getElementById('shadBoxPromptOK');
						if (k) k.click();
					}
				};
			}
		}
  };
  
	this.attachContentFrame = function(shadBoxVarName,title,href,windowWidth,windowHeight,scrollable,iframeID)
	{
		var iframeStr='';
		if(iframeID!==undefined)
		{
			iframeStr = ' id="'+iframeID+'" name="'+iframeID+'"';
		}
		
		var scrollableStr='auto';
		if(scrollable===true) scrollableStr='auto';
		else if(scrollable===false) scrollableStr='no';
		
		contentFrameLayer = document.createElement('div');
		contentFrameLayer.className='shadBox_contentFrame';
		
		contentFrameLayer.innerHTML = this.htmlWinSeg1+title.htmlspecialchars()+this.htmlWinSeg2+shadBoxVarName+this.htmlWinSeg3+
		'<iframe'+iframeStr+' width="'+windowWidth+'" height="'+windowHeight+'" frameborder="0" scrolling="'+scrollableStr+'" allowtransparency="true" src="'+href+'"></iframe>'+this.htmlWinSeg4;
		
		this.shadLayer.appendChild(contentFrameLayer);
		
		if (iframeID !== undefined) {
			//create reference to this shadow box in the iframe... this way we can easily obtain it from within itself.
			Layout.rootWindow().document.getElementById(iframeID).contentWindow.thisShadowBox = this;
		}
		
		this.startCenterEvent();
	}
	
	this.show = function()
	{
		this.shadLayer.style.visibility = "visible";
		
		//set overflow to auto so that we can scroll to the close button if the screen res is tiny
		this.shadLayer.style.overflow = "auto";
		this.recenter();
	}
	
	this.hide = function()
	{
		this.shadLayer.style.visibility = "hidden";
		this.shadLayer.style.overflow = "hidden";
	}
	
	var rootWin = Layout.rootWindow();
	
	this.htmlWinSeg1='<table cellspacing="0" class="shadBoxWindowTable"><tr><td class="tl"></td><td class="tm"><div class="tmTitle">';
	this.htmlWinSeg2='</div><div onclick="';
	this.htmlWinSeg3='.remove();" class="close"></div></td><td class="tr"></td></tr><tr><td class="ml"></td><td class="mm">';
	this.htmlWinSeg4='</td><td class="mr"></td></tr><tr><td class="bl"></td><td class="bm"></td><td class="br"></td></tr></table>';
	this.shadLayer = rootWin.document.createElement('div');
	this.shadLayer.id = id;
	this.shadLayer.className = 'shadBox';
	this.hide(); //hide by default. use display
  
	rootWin.document.body.appendChild(this.shadLayer);
	
	this.okFunction = false; //used to call a function when a prompt uses OK button
	this.cancelFunction = false; //used to call a function when a prompt uses Cancel button
	
	this.removeFunction = false;
	
	var promptLayer = false;
	var contentFrameLayer = false;
}

function DataGrid(dataGridVarName,objDivRef,dataArray,columnInfo,defaultSortColumnIndex)
{
	this.dataArray = dataArray;
	this.columnInfo = columnInfo;
	this.divRef = objDivRef;
	this.defaultSortColumnIndex = defaultSortColumnIndex;
	this.dataGridVarName = dataGridVarName;
	this.currentSort = this.defaultSortColumnIndex;
	this.display = function()
	{
		this.sort(this.defaultSortColumnIndex,false);
	}
	this.update = function()
	{
		this.sort(this.currentSort,false);
	}
	this.sort = function(sortColumn,reverseSort)
	{	
		this.currentSort = sortColumn;
		var currSort = this.columnInfo[this.currentSort].currentSort;
		if(currSort===undefined){
			currSort = 'desc'; //will reverse to ascending by default
		}
		if (reverseSort === true) {
			if (currSort == 'asc') {
				currSort = 'desc';
			}
			else {
				currSort = 'asc';
			}
		}
		
		//unset any current sort variables
		for(a=0;a<this.columnInfo.length;a++)
		{
			if(this.columnInfo[a].currentSort!==undefined)
			{
				delete(this.columnInfo[a].currentSort);
			}
		}
		//set new column sort
		this.columnInfo[sortColumn].currentSort = currSort;
		
		//see if sort overrides exist for this object
		var sortColumnPrefix='c';
		if(this.dataArray[0] && this.dataArray[0]['cSort'+sortColumn]!==undefined) sortColumnPrefix='cSort';
		this.dataArray.sortArrayOfObjects(sortColumnPrefix+sortColumn,this.columnInfo[sortColumn].sortType,currSort);
		this.buildHTML();
	}
	this.buildInnerObjectHTML=function(obj,parentObj,columnNum)
	{
		var r='';
		if(obj.controlType!==undefined){
			switch(obj.controlType){
				case 'toggle':
					r+="<div onclick=\"DataGrid.boolToggle("+dataGridVarName+","+parentObj.origIndex+","+columnNum+",'"+obj.url+"',"+(obj.checked?'false':'true')+");\" class=";
					if(obj.waiting!==undefined && obj.waiting===true) r+='"toggleWait"';
					else if(obj.checked===true) r+='"toggleTick"';
					else r+='"toggleCross"';
					r+='></div>';
					break;
				default: throw 'Control type "'+obj.controlType+'" not valid.';
			}
		}
		return r;
	}
	this.buildHTML = function(){
		var a;
		var b;
		var r = '<table><thead><tr>';
		for (a = 0; a < columnInfo.length; a++) {
			r += '<th';
			if (columnInfo[a].sortable === true) {
				r += ' onclick="'+this.dataGridVarName+'.sort('+a+',true);"';
				if (columnInfo[a].currentSort !== undefined) {
					r += ' class="sortableDataGridTH_' + columnInfo[a].currentSort + '"';
				}
				else {
					r += ' class="sortableDataGridTH_default"';
				}
			}
			r += '>' + columnInfo[a].title + '</th>';
		}
		
		r += '</tr></thead><tbody>';
		for (a = 0; a < dataArray.length; a++) {
			r += '<tr>';
			for (b = 0; b < 1000; b++) {
				if (dataArray[a]['c' + b] === undefined) {
					break;
				}
				else {
					r+='<td align="'+columnInfo[b].textAlignment+'">';
					if(typeof(dataArray[a]['c' + b])=='object') r+=this.buildInnerObjectHTML(dataArray[a]['c' + b],dataArray[a],b);
					else r+=dataArray[a]['c' + b];
					r+='</td>';
				}
			}
			r += '</tr>';
		}
		r += '</tbody></table>';
		this.divRef.innerHTML = r;
	}
}
DataGrid.boolToggle = function(dataGridRef,rowIndex,columnIndex,url,toggleBool)
{
	var fullURL =  url+'&toggleBool='+(toggleBool?'1':'0');
	var ajaxCall = new AjaxHandler(url+'&toggleBool='+(toggleBool?'1':'0'),'callback');
	ajaxCall.callback = function(result){
		if (result == '1') {
			var a;
			var found=false;
			for(a=0;a<dataGridRef.dataArray.length;a++)
			{
				if(dataGridRef.dataArray[a].origIndex==rowIndex)
				{
					found=true;
					dataGridRef.dataArray[a]['c'+columnIndex].waiting=false;
					dataGridRef.dataArray[a]['c'+columnIndex].checked = toggleBool;
					dataGridRef.dataArray[a]['cSort'+columnIndex] = (toggleBool?'1':'0');
					break;
				}
			}
			if(found===true)dataGridRef.update();
			else throw new Error('Did not find row "'+rowIndex+'" when updating with DataGrid.boolToggle');
		}
		else 
			throw new Error('DataGrid.boolToggle result failed. URL="' + fullURL + '" Response="' + result + '"');
	}
	
	//set icon to please wait
	var i;
	var foundColumnRef=false;
	for(i=0;i<dataGridRef.dataArray.length;i++)
	{
		if(dataGridRef.dataArray[i].origIndex==rowIndex)
		{
			foundColumnRef = dataGridRef.dataArray[i]['c'+columnIndex];
			break;
		}
	}
	if(foundColumnRef!==false && foundColumnRef.waiting!==true){
		foundColumnRef.waiting=true;
		dataGridRef.update();
		ajaxCall.request();
	}

}

function AjaxHandler(url, responseMethod)
{
	this.element = false;
	this.callback = false;
	var element = this.element;
	var callback = this.callback;
	this.url = url;
	if (responseMethod=='innerhtml' || responseMethod=='javascript' || responseMethod=='callback') this.responseMethod = responseMethod;
	else throw "Invalid response method '"+responseMethod+"' must be 'innerhtml','javascript' or 'callback'";
	
	this.request = function(){
		
		//set for response as it may have been set after construction
		element = this.element; 
		callback = this.callback;
		
		if(window.XMLHttpRequest || window.ActiveXObject){
			var xmlHTTP = AjaxHandler.createXMLHTTPRequestObject();
			if(xmlHTTP != null){				
				xmlHTTP.open('GET', this.url, true);
				xmlHTTP.onreadystatechange = function bob(){
					if(xmlHTTP.readyState == 4){
						if(xmlHTTP.status == 200){
							if(responseMethod==='javascript'){
								try {
									eval(xmlHTTP.responseText);
								}catch(e){alert('Failed to run \n'+xmlHTTP.responseText);}
							}else if (responseMethod === 'callback') {
								if (callback === false) 
									throw "Callback must not be false. Set callback to appropriate function after construction.";
								else {
									callback(xmlHTTP.responseText);
								}
							}else {
								if (element === false) 
									throw "Element must not be false. Set element to appropriate HtmlElement after construction.";
								else element.innerHTML = xmlHTTP.responseText;
							}
							xmlHTTP = null;
						}//else throw new Error('There was an problem retrieving the data:\n' + 'Status: ' + xmlHTTP.status + '\n' + xmlHTTP.statusText);
					}
				};
				xmlHTTP.send(null);
			}else throw new Error("XMLHttpRequest object was not created.");
		}
	}
}

AjaxHandler.buildPostData=function(dataobj)
{
	var chunks=new Array();
	for (var key in dataobj) {
		chunks.push(encodeURIComponent(key)+'='+encodeURIComponent(dataobj[key]))
	}
	return chunks.join('&');
}
AjaxHandler.createXMLHTTPRequestObject=function()
{
	var xmlHTTP;
	try{
		xmlHTTP = new XMLHttpRequest();
	}
	catch(e){
		//if browser is IE6 or older
		var xmlHTTPVersions = new Array('MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHttp');
		for(var i=0; (i<xmlHTTPVersions.length) && !xmlHTTP; i++){
			try{
				xmlHTTP=new ActiveXObject(xmlHTTPVersions[i]);
			}catch(e){
				//Removed this cos on IE6 it is way annoying
				//alert('Could not create xmlHTTP ActiveXObject.');
			}
		}
	}
	if(!xmlHTTP)alert('Error creating XMLHTTPRequest object.');
	else{
		return xmlHTTP;
	}
	return null;
}


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, alt_html)
{
	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>';
		
		if((alt_html != undefined) && (alt_html != '')) el.innerHTML = alt_html;
		else 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();
}

function ContLibBrowser(shadBoxVarName, override_window)
{
  this.remove = function()
  {
    if(this.removeFunction !== false) this.removeFunction();
    
    if(rootWin.removeEventListener) rootWin.removeEventListener('resize', this.recenter,false);
    else if(rootWin.detachEvent) rootWin.detachEvent('onresize', this.recenter);
    
    rootWin.document.body.removeChild(this.shadLayer);
  }
  
  this.hide = function()
  {
    this.shadLayer.style.visibility = 'hidden';
  }
  
  this.promptCancel = function()
  {
    if(this.cancelFunction !== false) this.cancelFunction();
    this.remove();
  }
  
  this.recenter = function()
  {
    if(promptLayer !== false) Layout.centerObjectToWindow(promptLayer);
  }
  
  this.startCenterEvent = function()
  {
    this.recenter();
    if(rootWin.addEventListener) rootWin.addEventListener('resize', this.recenter, false);
    else if(rootWin.attachEvent) rootWin.attachEvent('onresize', this.recenter);
  }
  
  this.show = function()
  {
    promptLayer = document.createElement('div');
    promptLayer.className = 'shadPromptBox';

    promptLayer.innerHTML =   '<table cellspacing="0" class="shadBoxWindowTable">'+
                                '<tr>'+
                                  '<td class="tl"></td>'+
                                  '<td class="tm">'+
                                    '<div class="tmTitle">Web Content Library</div>'+
                                    '<div onclick="Layout.rootWindow().thisContLibBrowser.remove();" class="close"></div>'+
                                  '</td>'+
                                  '<td class="tr"></td>'+
                                '</tr>'+
                                '<tr>'+
                                  '<td class="ml"></td>'+
                                  '<td class="mm">'+
                                    '<iframe id="'+this.iframe_id+'" style="width: 460px; height: 460px; overflow-x: hidden;" frameborder="0" scrolling="yes" allowtransparency="true" src="admin_cont_lib_browse.php"></iframe>'+
                                  '</td>'+
                                  '<td class="mr"></td>'+
                                '</tr>'+
                                '<tr>'+
                                  '<td class="bl"></td>'+
                                  '<td class="bm"></td>'+
                                  '<td class="br"></td>'+
                                '</tr>'+
                              '</table>';
    
    this.shadLayer.appendChild(promptLayer);
    
    //create reference to this ContLibBrowser in the iframe... this way we can easily obtain it from within itself.
    rootWin.thisContLibBrowser = this;
    
    this.startCenterEvent();
    
    this.shadLayer.style.visibility = 'visible';
    this.recenter();
  }
  
  var rootWin = Layout.rootWindow();
  
  this.shadLayer = rootWin.document.createElement('div');
  this.shadLayer.className = 'shadBox';
  this.hide();
  
  this.iframe_id = shadBoxVarName+'_iframe';
  
  rootWin.document.body.appendChild(this.shadLayer);
  
  var promptLayer = this.cancelFunction = this.okFunction = this.removeFunction = this.file_filters = false;
  
  this.file_url = false;
  
  this.element = false;       //the field whose value will be populated wit hthe selected files URL
  this.file_select = false;	//set to true if you wish files to be selectable
  this.folder_select = false;//set to true if you wish folders to be selectable
  
  this.move_files = false; 	//set to true if using the prompt to move files
  
  this.include_upfiles_dir_in_url = true;
}
