//THIS IS THE SCRIPT TO IDENTIFY AN ELEMENT
function myid(myelement)
{
	return document.getElementById(myelement);
}
//TO HERE





//THIS IS THE SCRIPT TO SWAP LAYERS Z-INDEX
function swap(thelayer, otherlayer)
{
	myid(thelayer).style.zIndex = 2;
	myid(otherlayer).style.zIndex = 1;
}
//TO HERE





//THIS IS THE LOAD IMAGES AND ROLLOVER SCRIPT
function 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=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 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 findobj(n, d) { //v4.0
  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=findobj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

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





//THIS IS THE SCRIPT FOR ANY POPUPS IE IN THE GALLERY ETC
function popup(page, name, xsize, ysize, menubars, scrollbars, location, directories, resizable, status, toolbar) {

	var yes = 1;
	var no = 0;

	var myleftpos = (window.screen.width/2) - ((xsize/2) + 30);
	var mytoppos = (window.screen.height/2) - ((ysize/2) + 40);

	windowprops = "width=" + xsize + ",height=" + ysize + ",top=" + mytoppos + ",left=" + myleftpos + "";
	windowprops += "menubars=" + menubars + ",scrollbars=" + scrollbars + ",location=" + location + ",directories=" + directories + ",resizable=" + resizable + ",status=" + status + ",toolbar=" + toolbar;

	window.open(page, name, windowprops);
}
//to here





//THIS IS THE FIX WINDOW SCRIPT
function fixWin() {

  if (window.screen) {
    var mywidth = 786;
    var myheight = 591;
		var myleftpos = (window.screen.width/2) - (415);
		var mytoppos = (window.screen.height/2) - (320);
    window.top.moveTo(myleftpos, mytoppos);
    window.top.resizeTo(mywidth, myheight);
  }

}
//to here





//THIS IS THE TABLE ROLLOVER EFFECT
function setcellbgcolor(id,color)
{
	var c = document.getElementById ? document.getElementById(id) :
	document.all ? document.all[id] :
	document.layers ? document[id+'Outer'].document[id+'Inner'] : null;
	if (document.layers)
	{
		c.background.src = '';
		c.bgColor = color;
	}
	else
	{
		c.style.background = '';
		c.style.backgroundColor = color;
	}
}

function setcellbgimage(id,sImgSrc)
{
	var c = document.getElementById ? document.getElementById(id) :
	document.all ? document.all[id] :
	document.layers ? document[id+'Outer'].document[id+'Inner'] : null;
	if (document.layers)
	{
		c.background.src = sImgSrc;
	}
	else
	{
		c.style.backgroundImage = 'url('+sImgSrc+')';
	}
}
//to here





//----------------These are forms functions to be applied to buttons-------------------

//get a url for forms textarea or input
function geturl(formname, fieldname)
{
	var link = prompt("Enter the link title","");
	var url = prompt("Enter the link url","");

	if (link != "")
	{
		if ((url.indexOf("http://") == 0) || (url.indexOf("ftp.") == 0))
		{
			var mouse_out = '(window.status=""); return true';
			var mouse_over = '(window.status="open link in popup"); return true';
			var the_name = "<a href='" + url + "' target='_blank' onmouseout='" + mouse_out + "' onmouseover='" + mouse_over + "'>" + link + "</a>";
			window.document[formname][fieldname].value+=the_name;
			window.document[formname][fieldname].focus();
		}
		else
		{
			alert ("Url's should be entered in the format format \n'http://' ou 'ftp.'");
		}
	}
	else
	{
		alert ("You must enter a link title for the url link.");
	}

}
//to here





//get an email for forms textarea or input
function getemail(formname, fieldname)
{
	var link = prompt("Enter the email title","");
	var email = prompt("Enter the email address","");

	if (link != "")
	{
		if ((email.indexOf("@") != -1) && (email.indexOf(".") != -1))
		{
			var mouse_out = '(window.status=""); return true';
			var mouse_over = '(window.status="email me"); return true';
			var the_name = "<a href='mailto:" + email + "?subject=asquare.org' onmouseout='" + mouse_out + "' onmouseover='" + mouse_over + "'>" + link + "</a>";
			window.document[formname][fieldname].value+=the_name;
			window.document[formname][fieldname].focus();
		}
		else
		{
			alert ("Email addresses should be entered in the format \n'nom@domain.ext'");
		}
	}
	else
	{
		alert ("You must enter a link title for the email link.");
	}

}
//to here







//get an image url for forms textarea or input
function getimage(formname, fieldname)
{
	var link = prompt("Enter the image title","");
	var url = prompt("Enter the image url","");

	if ((url.indexOf("http://") == 0) || (url.indexOf("ftp.") == 0))
	{
		var the_name = '<img src="' + url + '" alt="' + link + '" id="' + link + '" name="' + link + '" />';
		window.document[formname][fieldname].value+=the_name;
		window.document[formname][fieldname].focus();
	}
	else
	{
		alert ("Image url's should be entered in the format format \n'http://' ou 'ftp.'");
	}

}
//to here





//get an image url for forms textarea or input
function boldtext(formname, fieldname)
{
	var text = prompt("Enter the text to put in the bold tags","");

	if (text != "")
	{
		var the_name = '<b>' + text + '</b>';
		window.document[formname][fieldname].value+=the_name;
		window.document[formname][fieldname].focus();
	}
	else
	{
		alert ("You must enter some text to make bold.");
	}

}
//to here





//get an image url for forms textarea or input
function italictext(formname, fieldname)
{
	var text = prompt("Enter the text to put in the italic tags","");

	if (text != "")
	{
		var the_name = '<i>' + text + '</i>';
		window.document[formname][fieldname].value+=the_name;
		window.document[formname][fieldname].focus();
	}
	else
	{
		alert ("You must enter some text to make italic.");
	}

}
//to here





//get an image url for forms textarea or input
function underlinetext(formname, fieldname)
{
	var text = prompt("Enter the text to put in the underline tags","");

	if (text != "")
	{
		var the_name = '<u>' + text + '</u>';
		window.document[formname][fieldname].value+=the_name;
		window.document[formname][fieldname].focus();
	}
	else
	{
		alert ("You must enter some text to underline.");
	}

}
//to here





//voids textareas, fields, tick boxes, radio buttons and selects
function voidall(formname)
{

	for (i = 0; i < document[formname].length; i++)
	{
		window.document[formname].elements[i].value = "";
		window.document[formname].elements[i].checked = false;
		window.document[formname].elements[i].selectedIndex=0;
	}

}
//to here





//selects all tick boxes
function selectall(formname)
{

	for (i = 0; i < document[formname].length; i++)
	{
		window.document[formname].elements[i].checked = true;
	}

}
//to here

//----------------These are forms functions to be applied to buttons-------------------
