//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);		
}
//	******* fnOpenVideoWindow *************************************************
// Opens a youtube video in a new page
function fnOpenVideoWindow(vCode){
	var vidPage = "/vos_portal/support/workNetVideo.aspx?v=" + vCode;
	
  mywindow = window.open(vidPage,"wnVideo","menubar=0, toolbar=0, location=0, directories, status, scrollbars, resizable, dependent, width=600, height=550, left=50, top=50");

  mywindow.focus();
}
//	******* 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;
}

//	******* Image Title Attribute *************************************************
//The function imageTitle creates(if not already existing) or sets(if already existing) the 'title' attribute(img Tag).
function imageTitle()
{
   y = document.getElementsByTagName("img");
   l = document.getElementsByTagName("img").length;
	for (var x = 0; x < l; x++)
	   {      
	    if(y[x].getAttribute("alt"))
          y[x].setAttribute("title",y[x].getAttribute("alt"));
        else
          y[x].setAttribute("title","");
       }
}  

// ******* Javascript for simple YouTube playlist *****************************************

      function loadVideo(oName,videoId) {
        var video = document.getElementById(oName);
        var innerHTML="";
        // Check for IE
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
          var ieversion=new Number(RegExp.$1); //allows version check of IE if it's IE, otherwise do it the correct way.  Kept in case IE9 does it the same as FF we can check for IE8 or older
            video.innerHTML = "";
            var newDiv = document.createElement("div");
            innerHTML = innerHTML + "<embed src='http://www.youtube-nocookie.com/v/"+videoId+"&hl=en_US&fs=1&rel=0' ";
            innerHTML = innerHTML + "type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' ";
            innerHTML = innerHTML + "width='425' height='344'></embed>";
            newDiv.innerHTML = "test";
            newDiv.innerHTML = innerHTML;
            video.appendChild(newDiv);
        } else {
          innerHTML = innerHTML + "<object width='425' height='344'>";
          innerHTML = innerHTML + "<param name='movie' value='http://www.youtube-nocookie.com/v/"+videoId+"&hl=en_US&fs=1&rel=0'></param>";
          innerHTML = innerHTML + "<param name='allowfullscreen' value='true'></param>";
          innerHTML = innerHTML + "<param name='allowscriptaccess' value='always'></param>";
          innerHTML = innerHTML + "<embed src='http://www.youtube-nocookie.com/v/"+videoId+"&hl=en_US&fs=1&rel=0' ";
          innerHTML = innerHTML + "type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' ";
          innerHTML = innerHTML + "width='425' height='344'></embed>";
          innerHTML = innerHTML + "</object>";
          video.innerHTML = innerHTML; 
        }
      }    

// ******* Javascript for single Viddler video *****************************************

    function getFlashMovieObject(id) {
      if(window.document[id]) {
        return window.document[id];
      }
      if(navigator.appName.indexOf("Microsoft Internet")==-1) {
        if(document.embeds && document.embeds[id])
          return document.embeds[id];
      } else { // if(navigator.appName.indexOf("Microsoft Internet")!=-1)
        return document.getElementById(id);
      }
    }
  
    function playMovie(id, me) {
//      alert("Entered playMovie");
      var obj = me.childNodes[0];
      getFlashMovieObject(id).playMovie();
      /*if(jwplayer(id).getState() != "PAUSED" && jwplayer(id).getState() != "IDLE") {
        me.childNodes[0].src="/vos_portal/images/player/control_pause_blue.png";
      } else {
        me.childNodes[0].src="/vos_portal/images/player/control_play_blue.png";
      }*/
    }
    function stopMovie(id, me) {
      getFlashMovieObject(id).stopMovie();
    }
    function toggleFullScreen(id, me) {
      var a = browserSize();
      x = document.getElementById(id+"Width").innerHTML;
      y = document.getElementById(id+"Height").innerHTML;
      fs = document.getElementById(id+"IsFS").innerHTML;
      if(fs == "true") {
        document.getElementById(id+"IsFS").innerHTML="false";
        getFlashMovieObject(id).width=x;
        getFlashMovieObject(id).height=y;
        me.childNodes[0].src="/vos_portal/images/player/arrow_out.png";
      } else {
        document.getElementById(id+"IsFS").innerHTML="true";
        getFlashMovieObject(id).width=a.x - 50;
        getFlashMovieObject(id).height=a.y - 50;
        me.childNodes[0].src="/vos_portal/images/player/arrow_in.png";
      }
    }
    function rewindMovie(id) {
      var pos = getFlashMovieObject(id).getCurrentTime();
      if(pos < 10) {
        pos = 0;
      } else {
        pos = pos - 10;
      }
      getFlashMovieObject(id).viddlerSeek(pos);
    }
    function fastForwardMovie(id) {
      var pos = getFlashMovieObject(id).getCurrentTime();
      pos = pos + 10;
      getFlashMovieObject(id).viddlerSeek(pos);
    }
      
    function  browserSize() {
      var x = 0, y = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        x = window.innerWidth;
        y = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        x = document.body.clientWidth;
        y = document.body.clientHeight;
      }
      return {x : x, y : y};
    }
    
    function secondsToTime(seconds) {
      var mins = parseInt(seconds / 60);
      var secs = parseInt(seconds % 60);
      var time = "";
      if (mins < 10) {
        time = "0"+mins.toString();
      } else {
        time = mins.toString();
      }
      if (secs < 10) {
        time = time + ":0" + secs.toString();
      } else {
        time = time + ":"+secs.toString();
      }
      return time;
    }

