
function loadPage(leftPage,rightPage)
{
	parent.rightFrame.document.location.href = rightPage;
	parent.leftFrame.document.location.href= leftPage;
	
}

function loadPage1(url,frameName)
{
	if(frameName=="leftFrame")
		parent.leftFrame.document.location.href = url;
	else if(frameName=="rightFrame")
		parent.rightFrame.document.location.href = url;
	else if(frameName=="topFrame")
		top.document.location.href = url;
	else
	{
		aWin = window.open(url,'aWin','toolbar=yes,scrollbars=yes,location=yes,status=yes,menubar=yes,resizable,width=780,height=550');
		aWin.focus();
	}


}

function PopURL(url,w,h)
{
	str = "'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable,width=" + w + ",height=" + h + "'";
	picWind = window.open(url,'picWind',str);
	picWind.focus();
}

function PopURL1(url,w,h)
{
	str = "'toolbar=no,scrollbars=yes,location=no,status=no,menubar=no,resizable,width=" + w + ",height=" + h + "'";
	picWind = window.open(url,'picWind',str);
	picWind.focus();
}


function goHome(url)
{
	top.document.location.href = url;
}

function openWin(aPage)
{
	
	aWin = window.open(aPage,'aWin','toolbar=yes,scrollbars=yes,location=yes,status=yes,menubar=yes,resizable,width=780,height=550');
	aWin.focus();
}

/*************************************************************************/
/* We need pass in:
aMax //the maximum number of pictures in the list
thisPic //the current picture number
pageName // the name of the image such as "S_O99_"
picName //the picture name inside the document such as picName = document.myPicture
selectName //the name of the selection box such as selectName=document.form[0].pageNum
*/

/* This one for new letter pages */
function processPrevious(picName,selectName)
{
	if(document.images && thisPic > 1)
	{
		thisPic--;
		picName.src = "../../gif/"+ pageName + thisPic + ".gif";
		selectName.selectedIndex = (thisPic - 1);
	}
	else
		alert("This page is the first page");
}

function processNext(picName,selectName)
{
	if(document.images && thisPic < aMax)
	{
		thisPic++;
		picName.src = "../../gif/"+ pageName + thisPic + ".gif";
		selectName.selectedIndex = (thisPic - 1);
	}
	else
		alert("This page is the last page");
}

function processFirst(picName,selectName)
{
	if(document.images && thisPic != 1)
	{
		thisPic = 1
		picName.src = "../../gif/"+ pageName + thisPic + ".gif";
		selectName.selectedIndex = (thisPic - 1);
	}
	else
		alert("This page is the first page.");
}

function processLast(picName,selectName)
{
	if(document.images && thisPic != aMax)
	{
		thisPic = aMax;
		picName.src = "../../gif/"+ pageName + thisPic + ".gif";
		selectName.selectedIndex = (thisPic - 1);
	}
	else
		alert("This page is the last page.");
}

function goPage(picName,selectName)
{
	var index = selectName.selectedIndex;
	thisPic = selectName.options[index].value;
	if(document.images)
		picName.src="../../gif/"+ pageName + thisPic + ".gif";
}

/*********************************************************************/


/*********************************************************************/
/* These functions will be used for all benefit Information pages such as
SSI, IHSS, Medi-Cal ...
We need:
+ Max // the total number of pages for rehab
+ currentPage //the current page display
+ pageName //the name of the page such as ssi, mediCal, rehab...
+ selectName is the selection box name will be passed in each time we call the
	functions.
+ ext: is extension of the file
*/

/* This function will go to the first page */
function moveFirst(selectName)
{
	if(currentPage != 1)
	{
		currentPage = 1;
		top.rightFrame.location.href = pageName + currentPage + ext;
		selectName.selectedIndex = currentPage -1;
	}
	else
		alert("This page is the first page.");
}

function moveLast(selectName)
{
	if(currentPage != Max)
	{
		currentPage = Max;
		top.rightFrame.location.href = pageName + currentPage + ext;
		selectName.selectedIndex = currentPage -1;
	}
	else
		alert("This page is the last page.");
}

function movePrevious(selectName)
{
	if(currentPage > 1)
	{
		currentPage--;
		top.rightFrame.location.href = pageName + currentPage + ext;
		selectName.selectedIndex = currentPage -1;
	}
	else
		alert("This page is the first page");
}


function moveNext(selectName)
{
	if(currentPage < Max)
	{
		currentPage++;
		top.rightFrame.location.href = pageName + currentPage + ext;
		selectName.selectedIndex = currentPage -1;
	}
	else
		alert("This page is the last page");
}

function benGoPage(selectName)	
{
	currentPage = selectName.selectedIndex + 1;
	top.rightFrame.location.href = pageName + currentPage + ext;
}

/**************************************************************************/
function formSubmit(ele,val)
{
	document.forms[0].elements[ele].value = val;
	document.forms[0].submit();

}


function filterUrl(url, filterString, dest) {
		url = url + filterString;
		if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	        req.onreadystatechange = function() {
	            	if (req.readyState == 4) {
				        // only if "OK"
				        if (req.status == 200) {
				       		document.getElementById(dest).innerHTML=req.responseText;
				        } else {
				            alert("There was a problem retrieving the data:\n" + req.statusText);
				        }
			    	}
	            };
	        req.open("GET", url, true);
	        req.send(null);
	    // branch for IE/Windows ActiveX version
	    } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	        if (req) {
	            req.onreadystatechange = function() {
	            	if (req.readyState == 4) {
				        // only if "OK"
				        if (req.status == 200) {
				       		document.getElementById(dest).innerHTML=req.responseText;
				        } else {
				            alert("There was a problem retrieving the data:\n" + req.statusText);
				        }
			    	}
	            };
	            req.open("GET", url, true);
	            req.send();
	        }
	    }
	}

function buildFrame(url,width,height,border)
{
	document.write(
	  '<ifr' + 'ame' +
	  ' src=' + url +
	  ' width=' + width +
	  ' height=' + height +
	  ' frameborder=' + border +
	  ' hspace=0' +
	  ' vspace=0' +
	  ' scrolling=no' +
	  ' marginwidth=0' +
	  ' marginheight=0' +
	  ' allowtransparency=true' +
	  ' name=iframe0></ifr' + 'ame>'
	);


}


function showAds(url,pm,eId,minLoadTime,maxLoadTime,currentLoadNum,maxLoadNum)
{
	var reloadTime = Math.round(Math.random()*(maxLoadTime-minLoadTime)) + minLoadTime;
	
	
	//create xmlHttp object
	var xmlHttp;
	if (window.XMLHttpRequest)
	{
		xmlHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	
	//if the browser does not support the xmHttp object, display an error
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	
	var fullUrl = url;
	if(pm != "")
		fullUrl += "?"+ pm;
		
	
		
	xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				document.getElementById(eId).innerHTML=xmlHttp.responseText;
				
			} 
		}
	
	if(currentLoadNum <= maxLoadNum)
	{
		xmlHttp.open("GET",fullUrl,true);
		xmlHttp.send(null);
	}
	
	
	var num = Math.round(Math.random() * 3 + 1);
	var parameters = "num=" + num;
	var func = "showAds('" + url + "','" + parameters + "','" + 
		eId + "'," + minLoadTime + "," + maxLoadTime + "," +
		++currentLoadNum + "," + maxLoadNum + ")";
	//alert(func + "; reloadTime=" + reloadTime);
	
	setTimeout(func, reloadTime);
	
	
	
}

