

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=[
	"http://shpa.rentsoft.biz/scripts/cgiip.exe/WService=SHPA/app/ws2/objects/sset-all.r?Mode=InLine&amp;Action=GotoHome",
	//"http://jppr.shpa.rentsoft.biz/scripts/cgiip.exe/WService=SHPAJP/app/ws2/objects/sset-all.r?Mode=InLine&Action=GotoHome",
	"http://cpd.shpa.rentsoft.biz/scripts/cgiip.exe/WService=SHPACP/app/ws2/objects/sset-all.r?Mode=InLine&Action=GotoHome",
	"http://jobs.shpa.rentsoft.biz/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;
		var name=$("#loginForm form :text")[0].value;
		var password=$("#loginForm form :password")[0].value;
		if (name && password)
		{
			for (i=0; i<urllist.length; i++)
			{
				buildSiteForm(urllist[i],i);
			}
			for (i=0; i<urllist.length; i++)
			{
				eval("iframe"+i+".document.getElementById('login').value=name");
				eval("iframe"+i+".document.getElementById('password').value=password");
				eval("iframe"+i+".document.getElementById('LoginForm').submit()");
			}
			
			
		}
	}

	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) {
			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();
			}
		}
	};
	
	var configure=function()
	{
		$("#loginForm form").submit(function(){submitHandler(); return false;});
	};
	
	var submitHandler=function()
	{
		$("#loginForm :submit").attr("disable","true");
		registerAllSites();
		testBeforeSubmit();
	};
	
	configure();

}

function submitThisForm()
{
$('#loginForm form')[0].submit()
}

$(window).ready(function()
{
	var universalLogin=new universalSHPAlogin();
});

var testBeforeSubmit=function()
	{
		if ( testAllSites() )
		{
			window.setTimeout("submitThisForm()",350);
		}
		else
		{
			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;
		}
	};




