function frameloaded()
{
alert('done');
}
function universalSHPAlogin()
{
	//edit the url list for each subsite - comment out the one relevant login address - watch your commas at the end of the line


	var urllist=new Array();
	urllist[0]="http://jppr.shpa.org.au/scripts/cgiip.exe/WService=SHPAJP/app/ws2/objects/sset-all.r?Mode=InLine&Action=GotoHome";
	urllist[1]="http://cpd.shpa.org.au/scripts/cgiip.exe/WService=SHPACP/app/ws2/objects/sset-all.r?Mode=InLine&Action=GotoHome";
	urllist[2]="http://jobs.shpa.org.au/scripts/cgiip.exe/WService=SHPAJO/app/ws2/objects/sset-all.r?Mode=InLine&Action=GotoHome";

	var createIframe =function(iframeName, width, height) {
		var iframe;
		if (document.createElement && (iframe =
		document.createElement('iframe'))) {
			iframe.name = iframe.id = iframeName;
			iframe.width = width;
			iframe.height = height;
			iframe.src = 'about:blank';
			iframe.style.display="none";
			document.body.appendChild(iframe);
		}
		return iframe;
	};
	
	var registerAllSites=function()
	{
		var i,name,password;
		//var name=$("#loginForm form :text")[0].value;
		//var password=$("#loginForm form :password")[0].value;
		var login_form=document.getElementById("loginForm");
if(login_form == null)login_form=document.getElementById("homeLogin");
		if (!login_form) return;
		var form_elements=login_form.getElementsByTagName("INPUT");
		for (i=0; i<form_elements.length; i++)
		{
			if (form_elements[i].type=="text" && !name)
			{
				name=form_elements[i];
			}
			if (form_elements[i].type=="password")
			{
				password=form_elements[i];
			}
		}
		
		if (name && password)
		{
			for (i=0; i<urllist.length; i++)
			{
				buildSiteForm(urllist[i],i);
			}
			for (i=0; i<urllist.length; i++)
			{
try{
				eval("iframe"+i+".document.getElementById('login').value=name.value");
				eval("iframe"+i+".document.getElementById('password').value=password.value");
				eval("iframe"+i+".document.getElementById('LoginForm').submit()");
}
catch(err){}

			}
			
			
		}
	}

	var buildSiteForm=function(siteURL,i) {
	var iframe = createIframe ('iframe'+i, 300, 300);
	if (iframe) {
		var iframeDoc;
		if (iframe.contentDocument) {
			iframeDoc = iframe.contentDocument;
			}
			else if (iframe.contentWindow) {
			iframeDoc = iframe.contentWindow.document;
			}
			else if (window.frames[iframe.name]) {
			iframeDoc = window.frames[iframe.name].document;
			}
			if (iframeDoc) {
try{
			iframeDoc.open();

			iframeDoc.write(
				'<html><body><form action="'+siteURL+'" method="post" name="LoginForm" id="LoginForm"><input type="text" value="Username" title="Username" name="login" id="login" class="loginUser"/><input type="password" value="Password" title="Password" class="loginPass" name="password" id="password"/><input type="submit" value="LOGIN" id="Submit" name="Submit"/><input type="hidden" value="GotoHome" name="action"/></form></body><\/html>');
				iframeDoc.close();
}catch(err){};
			}
		}
	};
	
	var configure=function()
	{
		//$("#loginForm form").submit(function(){submitHandler(); return false;});

		var thisForm=document.getElementById("loginForm");

if(thisForm==null){thisForm=document.getElementById("homeLogin");}
		if (thisForm)
		{
			thisForm=thisForm.getElementsByTagName("FORM");

			var o=document.getElementById("Submit");if(o)o.onclick=function(){submitHandler(); return false;};
			//thisForm[0].onsubmit=function(){submitHandler(); return false;};
		}
	};
	
	var submitHandler=function()
	{
		//$("#loginForm :submit").attr("disable","true");
		var submit,i;
		var thisForm=document.getElementById("loginForm");
if(thisForm==null){thisForm=document.getElementById("homeLogin");}
		if (thisForm)
		{
			document.getElementById("Submit").disabled="true";
		}
		registerAllSites();
		testBeforeSubmit();
	};
	
	configure();

}

function submitThisForm()
{
	//$('#loginForm form')[0].submit()
	var thisForm=document.getElementById("loginForm");
if(thisForm==null){thisForm=document.getElementById("homeLogin");}
	if (thisForm)
	{
		thisForm=thisForm.getElementsByTagName("FORM");
		if(thisForm[0])thisForm[0].submit();
thisForm=document.getElementsByName("LoginForm");
try{
		if(thisForm[0])thisForm[0].submit();
}catch(err){};

	}
}


var count=1;

var testBeforeSubmit=function(){
		if ( testAllSites() )
		{
			window.setTimeout("submitThisForm()",450);
		}
		else
		{

count++;
if(count>15){submitThisForm();return;}
window.setTimeout("testBeforeSubmit()",200);

		}
	};

var testAllSites=function()
	{
		try
		{
			var text=iframe0.location.href;
			text=iframe1.location.href;
			text=iframe2.location.href;
			return false;
		}
		catch(err)
		{
			return true;
		}
	};


/*
$(window).ready(function()
{
	var universalLogin=new universalSHPAlogin();
});
*/

function init() {
       // quit if this function has already been called
       if (arguments.callee.done) return;
       // flag this function so we don't do the same thing twice
       arguments.callee.done = true;

       var universalLogin=new universalSHPAlogin();
   };

   /* for Mozilla */
   if (document.addEventListener) {
       document.addEventListener("DOMContentLoaded", init, false);
   }

   /* for Internet Explorer */
   /*@cc_on @*/
   /*@if (@_win32)
     //  document.write("<script defer src=ie_onload.js><"+"/script>");
   /*@end @*/

   /* for other browsers */
   window.onload = init;


