function createXHR() 
{
	var request;
	if (window.XMLHttpRequest)// Mozilla, Safari, ...
	{ 
		request = new XMLHttpRequest();
		if (request.overrideMimeType)
		{
			request.overrideMimeType('text/xml');
			// See note below about this line
		}
	}
	else if (window.ActiveXObject)// IE
	{ 
		try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){}
		}
	}

	if (!request)
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	return request;
}
function getQueryString(q)
{
	/*/////////////////////////////////////////
	Developer : Original Unknown and Chayne Walsh
	Version Date : 2007-03-28-02
	Querystring extractor
	//////////////////////////////////////////*/
	var qs = location.search.substring(1);
	var nv = qs.split('&');
	var url = new Object();
	for(i = 0; i < nv.length; i++)
	{
		eq = nv[i].indexOf('=');
		url[nv[i].substring(0,eq)] = unescape(nv[i].substring(eq + 1));
	}
	return (url[q]) ? url[q] : '' ;
}
function getEnv(op)
{
	/* //////////////////////////////////////////////////////////
	Developer: Chayne Walsh
	Copyright: None, use at your own risk
	Date Modified: 14 March 2007
	
	This function is intended to emulate the PHP getEnv function
	and provide a way to seamlessly use the scripts in a development 
	localhost and remove server environments.
	It has other added options like HTTP_ROOT and RELATIVE_ROOT.
	RELATIVE ROOT is an alternative to DOCUMENT ROOT as we do not 
	want to show anyone the DOCUMENT ROOT in our scripts.
	
	If you make any amazing addition and improvements to this function
	please send me a copy to development@chayne.net.
	////////////////////////////////////////////////////////////// */
	var r='';
	var strPathName = new String(window.location.pathname);
	splitPathName = strPathName.split("/");
	
 	if(op == 'SCRIPT_NAME')
	{
		splitPathName.pop();
		r = splitPathName.join("/");
	}
	if(op == 'DOCUMENT_ROOT')
	{
		r = (window.location.hostname=='localhost') 
		? "c:/www/domains/lockforce.com.au/" // document root of your development server 
		: ''; // document root of your deployment server
	}
	if(op == 'HTTP_ROOT')
	{
		r = (window.location.hostname=='localhost') 
		? "http://"+window.location.hostname+'/'+splitPathName[1] + "/" //iis virtual
		: "http://"+window.location.hostname + "/" ;
	}
	
	if(op == 'RELATIVE_ROOT')
	{
		var directoryDepth = (window.location.hostname=='localhost')
		? splitPathName.length - 3 
		: splitPathName.length -3;
		if(directoryDepth > 0)
		{
			for(i = 0; i < directoryDepth; i++)
			{
				r += '../';
			}
		}
	}
	return r;
}
function buttonState(bid,opac,grayscale)
{
	try
	{
		bid = ( typeof bid == 'object' ) ? bid : document.getElementById(bid) ;
		if ( opac < 0 || opac > 100 ) opac = false;
		if ( grayscale < 0 || grayscale > 1 ) grayscale = false;
		changeOpac(opac, bid)
		if (bid.filters)
		{
			if ( grayscale != false ) bid.style.filter='progid:DXImageTransform.Microsoft.BasicImage(grayscale=' + grayscale +')';
		}
	}
	catch (e) {/*do nothing*/};
}

function opacity(id, opacStart, opacEnd, millisec)
{
	try
	{
		var speed = Math.round(millisec / 100); 
		var timer = 0; 
		
		if(opacStart > opacEnd)
		{ 
			for(i = opacStart; i >= opacEnd; i--)
			{ 
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
				timer++; 
			} 
		}
		else if(opacStart < opacEnd)
		{ 
			for(i = opacStart; i <= opacEnd; i++) 
			{ 
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
				timer++; 
			} 
		} 
	}
	catch (e) {/*do nothing*/}
} 

function changeOpac(opacity, id)
{
	try
	{
		var object = ( typeof id == 'object' ) ? id.style : document.getElementById(id).style ;
		object.opacity = (opacity / 100); 
		object.MozOpacity = (opacity / 100); 
		object.KhtmlOpacity = (opacity / 100); 
		object.filter = "alpha(opacity=" + opacity + ")"; 
	}
	catch (e) { /*do nothing*/}
} 

var abortTimeOutRequest = true;
function timeOutRequest(id)
{
	if (abortTimeOutRequest) document.getElementById(id).innerHTML = "The page failed to load. Please try again.";
}

function getPageContent(p,q)
{
	document.getElementById('pageContents').innerHTML = '<img src="' + getEnv('RELATIVE_ROOT') + 'assets/images/loading/loading.gif" />';
	setTimeout( "timeOutRequest('pageContents')", 15000);
	var httpRequest = createXHR();
	httpRequest.onreadystatechange = function()
	{  
		if (httpRequest.readyState == 4)
		{
			if (httpRequest.status == 200)
			{
				try
				{
					document.getElementById('pageContents').innerHTML = httpRequest.responseText;
					abortTimeOutRequest = false;
				}
				catch (e){document.getElementById('pageContents').innerHTML = "Failed to load content!"}
			}
			else
			{
				/* */
			}
		}
	}
	httpRequest.open('GET', p + q, true);
	httpRequest.send(null);
}

var globalAjaxId = '';
function getAjax(id,p)
{
	globalAjaxId = id;
	document.getElementById(id).innerHTML = '<img src="' + getEnv('RELATIVE_ROOT') + 'assets/images/loading/loading.gif" />';
	setTimeout( "timeOutRequest('"+id+"')", 15000);
	var httpRequest = createXHR();
	httpRequest.onreadystatechange = function()
	{  
		if (httpRequest.readyState == 4)
		{
			if (httpRequest.status == 200)
			{
				try
				{
					document.getElementById(globalAjaxId).innerHTML = httpRequest.responseText;
					abortTimeOutRequest = false;
				}
				catch (e){document.getElementById(globalAjaxId).innerHTML = "Failed to load content!"}
			}
			else
			{
				/* */
			}
		}
	}
	httpRequest.open('GET', p, true);
	httpRequest.send(null);
}

function CPW_openPagelessWindow(dir,img)
{
	uploadwindow=window.open(getEnv('RELATIVE_ROOT') + 'assets/scripts/popup_resize.asp?dir='+dir+'&img='+img, 'upload', 'width=200,height=200,menubar=no,location=no,toolbar=no,status=no,resizable=no,top=10,left=10');
}

function MM_findObj(n, d) { //v4.01
  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() { //v3.0
  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_swapImgRestore() { //v3.0
  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() { //v3.0
  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];}}
}
/* ///////////////////////////////////////////////////////////////////// */