/* -------------------------------------------------------------------------------------------- */
/* Global Variables																																							*/
/* -------------------------------------------------------------------------------------------- */

/* Finds the currently called Object Name */
function FindObject(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=FindObject(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/* Changes the Property the selected DIV from one value to another */
function ChangeProperty(objName,x,theProp,theValue) 
{
	var obj = FindObject(objName);
	
	if (obj && (theProp.indexOf("style.")==-1 || obj.style))
	{
		if (theValue == true || theValue == false)
		{ eval("obj."+theProp+"="+theValue); }
		else 
		{ eval("obj."+theProp+"='"+theValue+"'"); }
	}
}

/* ---------------------------------------------------- */
/* JQuery												*/
/* ---------------------------------------------------- */
$jQuery(document).ready(function() 
{
	$jQuery("a.null").click(function(){
		return false;
	});
});

/* -------------------------------------------- */
/* General Functions							*/
/* -------------------------------------------- */

/* shows a given layer */
function ShowLayer( theLayer )
{
	if ( document.getElementById )
	{
		if (!theLayer.nodeName) { theLayer = document.getElementById(theLayer); }
		if (theLayer)
		{
			theLayer.style.display = '';
			return;
		}
	}
}

/* hides a given layer */
function HideLayer( theLayer )
{ 
	if ( document.getElementById )
	{
		if (!theLayer.nodeName) { theLayer = document.getElementById(theLayer); }
		theLayer.style.display = 'none';
		return;
	}
}


function trim(s){
	toTrim = new Array(' ','\n','\r');
	for(x=0; x<toTrim.length; x++){
		while(s.substring(0,1) == toTrim[x]){
			s = s.substring(1,s.length);
		}
		while(s.substring(s.length-1,s.length) == toTrim[x]){
			s = s.substring(0,s.length-1);
		}
	}
	return s;
}

/* Rollover Fuctions */
function GetObject(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=GetObject(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function SwapImage() { //v3.0
  var i,j=0,x,a=SwapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=GetObject(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function SwapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// Ask as confirmation, before an item is deleted */
function ConfirmDelete( type, msg ) 
{
	// Ask a confirmation alter box.
	input_box=confirm("Are you sure you wish to delete the selected '" + type + "?'\n\n" + msg + "");
	
	// If they have clicked 'Ok', set the checkbox to true.
	if (input_box==true) 
	{ 
		 return true;
	}
	else
	{
		// Stop processing the request, as they clicked 'Cancel'
		return false;
	}		
}

/* Checks to make sure both password fields are the same */
function PasswordCheck(field1, field2, result_id, match_html, nomatch_html) 
{
	this.field1 = field1;
	this.field2 = field2;
	this.result_id = result_id;
	this.match_html = match_html;
	this.nomatch_html = nomatch_html;
	
	this.Check = function() 
	{
		// Make sure we don't cause an error
		// for browsers that do not support getElementById
		if (!this.result_id) { return false; }
		if (!document.getElementById){ return false; }
		r = document.getElementById(this.result_id);
		if (!r){ return false; }
		
		if (this.field1.value != "" && this.field1.value == this.field2.value) 
		{ r.innerHTML = this.match_html; } 
		else 
		{ r.innerHTML = this.nomatch_html; }
	}
}

/* -------------------------------------------- */
/* Image Upload									*/
/* -------------------------------------------- */

/* Array of Allowed Image extensions */
function AllowedImageExtensions()
{
	return 	extArray = new Array(".gif", ".jpg", ".jpeg", ".png");
}

/* Check the image file extension */
function CheckImageFileType( warning, form ) 
{
	// Define the form value to check
	var file = form.value;
	
	// Get a list of allowed extensions
	extArray = AllowedImageExtensions();

	/* Allows Mac users to upload images */
	while (file.indexOf("/") != -1)
	{
		file = file.slice(file.indexOf("/") + 1);
		ext = file.slice(file.indexOf(".")).toLowerCase();
		for (var i = 0; i < extArray.length; i++) {
			
			// return true, if we have found a match
			if (extArray[i] == ext) { return true; }
		}
	}

	/* Allows Windows users to upload images */
	while (file.indexOf("\\") != -1)
	{
		file = file.slice(file.indexOf("\\") + 1);
		ext = file.slice(file.indexOf(".")).toLowerCase();
		for (var i = 0; i < extArray.length; i++) {
			
			// return true, if we have found a match
			if (extArray[i] == ext) { return true; }
		}
	}
	
	return false;
}

