//07-12-09 mparsons - added ShowHideSection
//08-02-13 mparsons - moved mcms only scripts to McmsScripts.js

//	******* popHelp *************************************************
//Popup functions 
//Normal width=420
function popHelp(link){
	newwindow = window.open(link,"helpItemWindow","height=555,width=480,left=100,top=10,status=yes,menubar=no,scrollbars=1,location=no,resizable=1");
	if (!newwindow.opener) newwindow.opener = self;
	if (window.focus) {newwindow.focus()}
}
//	******* popMCMSLwias *************************************************
function popMCMSLwias(link){
	newwindow = window.open(link,"mcmsLWIAS","height=600,width=600,left=100,top=10,status=yes,menubar=no,scrollbars=yes,resizable=yes");
	if (!newwindow.opener) newwindow.opener = self;
	if (window.focus) {newwindow.focus()}

}
//	******* popTour *************************************************
function popTour(link){
	newwindow = window.open(link,"tour","height=320,width=450,left=100,top=10,status=yes,menubar=no,scrollbars=1,location=no");
	if (!newwindow.opener) newwindow.opener = self;
	if (window.focus) {newwindow.focus()}
}
//	******* popSpanishTour *************************************************
function popSpanishTour(link){
	newwindow = window.open(link,"Conozca_el_sitio","height=525,width=500,left=100,top=10,status=yes,menubar=no,scrollbars=1,location=no");
	if (!newwindow.opener) newwindow.opener = self;
	if (window.focus) {newwindow.focus()}
}
//	******* fnOpenVideoWindow256K *************************************************
function fnOpenVideoWindow256K(FileName)
			{
			    setting="toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=no,resizable=yes,width=390,height=400,top=5,left=5";
			    PopupWindow256K = window.open(FileName,"CIS256K",setting);
			    PopupWindow256K.focus();
			    return false;
			}
//	******* popRegistration *************************************************
function popRegistration(link){
	location.href=link;
}
//	******* fnOpenWindowX *************************************************
//A function with this name is expected by the text returned from CIS searches
function fnOpenWindowX(link){
	//location.href=link;
	//var newwindow = window.open(link,"","height=600,width=850,left=100,top=10,status=yes,scrollbars=1,location=yes,resizable=yes,menubar=yes");		
	var newwindow = window.open(link);		
}

//	******* popLanding *************************************************
function popLanding(link,pred){
	link=link+"?pred="+encodeURIComponent(pred);	
	newwindow = window.open(link,"LandingPage","height=600,width=500,left=100,top=10,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes");
	if (!newwindow.opener) newwindow.opener = self;
	if (window.focus) {newwindow.focus()}
}
//	******* popLanding *************************************************
function popLanding(link){
	newwindow = window.open(link,"Print","height=600,width=500,left=100,top=10,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes");
	if (!newwindow.opener) newwindow.opener = self;
	if (window.focus) {newwindow.focus()}
}
//	******* popLanding *************************************************
function popLanding(eventTarget, eventArgument){
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms["Form1"];
	}
	else {
		theform = document.Form1;
	}
	theform.__EVENTTARGET.value = eventTarget;
	theform.__EVENTARGUMENT.value = eventArgument;		
	theform.submit();
}
//	******* AutoTab *************************************************
// This version does nothing - it is for the standard interface. If user requests advanced interface the advanced.js file will be added to override this method
function AutoTab(oElem, intElemLength, oNextElem, e){return true;}

//	******* handleGeneralInputEnterKeyPress *************************************************
function handleGeneralInputEnterKeyPress(lDocumentObject, lEventObject,buttonName){
	var lKeyCode;
	if (window.event) 
		{
		lKeyCode = window.event.keyCode;
		}
	else if (lEventObject) 
		{
		lKeyCode = lEventObject.which;
	}
	else 
	{
		return true;
	}

	
	if (lKeyCode == 13)
	{
		//getTheTargetObject
		var targ;
		if (!lEventObject) var lEventObject = window.event;
		if (lEventObject.target) targ = lEventObject.target;
			else if (lEventObject.srcElement) targ = lEventObject.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;
		
		//ONLY IF TARGET IS AN INPUT
		if (targ.tagName=="INPUT"){
			//Use the ID to get the name of the object, replace the "_" with "$"		
			var objectID=targ.id.charAt(0)+(targ.id.substr(1).replace(new RegExp('([\\_])+','g'),":"));
			buttonIDprefix=objectID.substring(0,objectID.lastIndexOf(":"));
			
			if (buttonIDprefix==""){
				//execute the button				
				__doPostBack(buttonName,'');
			}else{
			//replace the last part of the ID with the ID of the button
			buttonID=objectID.substring(0,objectID.lastIndexOf(":"))+":"+buttonName;
			//submitThis(buttonID,'');
			//execute the function			
			if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) 
				{	submitThis(buttonID,'');}
			else{
					//no difference between the code for IE and NS?? :-S
				submitThis(buttonID,'');
			}
		}
			return false;
		}else{
			return true
		}
	}
	else
	{
		return true;
	}
}
//	******* googleSearch *************************************************
function googleSearch() 
{
//Call external google search
	var item = document.getElementById('ctl00_tagline_searchItem');
	var site = document.getElementById('ctl00_tagline_currentSite');	
	//alert("item _ " + item.value);
	//alert("site: " + site.value);
	if (item.value == "")  {
		alert("You must enter a search term, try again");
		return false;
		} 
	var link1 = "http://www.google.com/search?hl=en&q=site:www.illinoisworknet.com/vos_portal/residents/en " + item.value;		
	var link = "http://www.google.com/search?hl=en&q=site:" + site.value + " " + item.value;
	//location.href = link;
	
	
	var newwindow3 = window.open(link,"","");		
	return false;
}
//	******* ShowHideSection *************************************************
//Show / hide a section
function ShowHideSection(section)
{
	var obj = document.getElementById(section);
	if(obj.style.display=="none") {
		obj.style.display="block";
		//eval('x' + ref).innerHTML = '<span style="text-decoration: underline;">Hide</span>';
	} else {
		obj.style.display="none";
	}
}//

//	******* Image preload and swapping Section *************************************************
//MM_preloadImages
function MM_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=MM_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 MM_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 MM_findObj(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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//change border color of image or hyperlink to make it stand out
function ChangeColor(x,y)
{
if (y =='On')
{
document.getElementById(x).style.borderColor  = '#ffcc33';
document.getElementById(x).style.borderWidth = '5px';
}
else
{ 
document.getElementById(x).style.borderColor = '';
document.getElementById(x).style.borderWidth = '0px'; 
}
}//
//	******* TipShow *************************************************
//TipShow() and TipHide(), when used in conjunction with CSS class "hints"
//and <A> and <SPAN> tags, allow a tip box to appear whenever the link is 
//hovered or tabbed to.
function TipShow(objElement) 
{
	objElement.className="focused";
}
function TipHide(objElement) {
	objElement.className="normal";
}
//	******* highlightDiv *************************************************
function highlightDiv(objId) {
		fnDeSelect();
		
		if (document.selection) {
			var range = document.body.createTextRange();
 	    range.moveToElementText(document.getElementById(objId));
			range.select();
			
		} else if (window.getSelection) {
			var range = document.createRange();
			range.selectNode(document.getElementById(objId));
			window.getSelection().addRange(range);
		}
	}
//	******* fnDeSelect *************************************************
function fnDeSelect() {
	if (document.selection) 
		document.selection.empty(); 
	else if (window.getSelection)
    window.getSelection().removeAllRanges();
}

//	******* URLEncode *************************************************
//The function URLEncode has been taken from the website http://cass-hacks.com/articles/code/js_url_encode_decode/
function URLEncode(clearString) 
{
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

