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_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_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];}
}
function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function pageHeight() {
	return window.innerHeight != null ? 
	window.innerHeight: document.documentElement && document.documentElement.clientHeight ? 
	document.documentElement.clientHeight:document.body != null ? 
	document.body.clientHeight:null;
}

function pageWidth() {
	return window.innerWidth != null ? 
	window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       
	document.documentElement.clientWidth : document.body != null ? 
	document.body.clientWidth : null;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function winReject(url) {
	window.open( url, 'reject', 'resizable=yes,height=300,width=525,left=25,top=25,scrollbars=no,menubar=no,location=no');
	}

function winEditor(url,w,h,n) {
	if (w==""||w==undefined) {w=800;}
	if (h==""||h==undefined) {h=700;}
	if (n==""||n==undefined) {n='maintenance';}
	window.open( url, n, 'resizable=yes,height='+h+',width='+w+',left=25,top=25,scrollbars=yes,menubar=no,location=no');
	}

function PDFDisplay(url,w,h,n) {
	if (w==""||w==undefined) {w=900;}
	if (h==""||h==undefined) {h=750;}
	if (n==""||n==undefined) {n='pdf';}
	window.open( url, n, 'resizable=yes,height='+h+',width='+w+',left=15,top=15,scrollbars=yes,menubar=yes,location=no,titlebar=no');
	}

function popSite(url) {
	window.open( url, 'othersite', 'resizable=yes,height=600,width=850,left=50,top=50,scrollbars=yes,menubar=yes,location=yes');
	}

function chkSearch() {
	if (document.search.searchstr.value=="") { 
		return false; 
	} else {
		return true;
	}
}


function DoMath( value1, operator, value2 ) {

	operators	= '+-*/';
	v1			= ( isNaN( parseFloat( value1 ) ) ) ? 0 : parseFloat( value1 );
	v2			= ( isNaN( parseFloat( value2 ) ) ) ? 0 : parseFloat( value2 );

	if ( ( v1==0 && value1!='0'  && value1!='' ) || ( v2==0 && value2!='0'  && value2!='' ) || operators.indexOf( operator )<0 ) {
		return 'Error';
	} else {
		return eval(v1+operator+v2);
	}
}

function calcInputList( frm, list ) {
	result = 0;
	aList = list.split( " " );
	for (i in aList) {
		e = aList[i];
		o = e.substr(0,1);
		v1 = 'document.'+frm+'.'+e.substring(1)+'.value';
		v = eval(v1);
		result = DoMath( result, o, v );
	}
	if ( result != 'Error' && Math.round(result) != result ){
		result = Math.round( result * 100 ) / 100;
	}
	if ( result == 'Error' || result==undefined || isNaN(result) ){
		result = '';
	}
	return result;
}

function unCheckRadio(oRadio) {
	  var or = document.getElementsByName(oRadio);
      for (var i = 0; i < or.length; i++) {
         or[i].checked = false;
     }
}

//function imgDisplay(url,h,w) {
//	twin = window.open( url, 'imageDisplay', 'resizable=yes,height='+(h+45)+',width='+(w+35)+',left=25,top=25,scrollbars=yes,menubar=no,location=no');
//	twin.focus();
//}

function submitMaintApproval( request ) {
	document.maintForm.ApprovalUpdate.value = request;
	document.maintForm.submit();
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
	
function disableForms() {
var objfms = document.forms;
for(var i=0;i < objfms.length;i++) {
	disableForm( objfms[i] );
	}
}

function disableForm(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset" || tempobj.type.toLowerCase() == "image" || tempobj.type.toLowerCase() == "button")
			tempobj.disabled = true;
		}
		return true;
	} else {
		return false;
	}
}
function disableLinks(){
var objLink = document.links;
for(var i=0;i < objLink.length;i++) {
	objLink[i].disabled=true;
	objLink[i].onclick = new Function("return false;");
	}
	return true;
}
function waitaminute(msec,msec2) {
	if (msec == null){
		msec = 100;
	}
	if (msec2 == null){
		msec2 = 1500;
	}
	//disableForms();
	var x=setTimeout("disableLinks()",msec);
	var t=setTimeout("showwaitdiv()",msec2);
	return true;
}
function showwaitdiv() {
	document.getElementById('pleasewait').style.display='block';
	document.getElementById( 'processing' ).innerHTML = '<img src="../images/framework/ajax-loader.gif" width="32" height="32"><BR><BR><div style="width:300px;text-align:center;">Processing...</div>';
	document.getElementById('processing').style.display='block';
}
function setLinkDisabler(){
	var objLink = document.links;
	for(var i=0;i < objLink.length;i++) {
		objLink[i].onclick = function(){waitaminute();};
	}
}

function checkboxLimit( o, limit ){
       var l = document.getElementsByName(o.name)
        var found=0;
        for( var i=0; i < l.length; ++i) 
        {
                if( l[i].checked )
                        ++found;
        }
        if(found>limit) {
			alert("Please Select a maximum of " + limit);
          return false;
        }
}

// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homepage of this code:
//     http://www.php-development.ru/javascripts/dropdown.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.


// ***** Popup Control *********************************************************

// ***** at_show_aux *****

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["at_position"] == "y") ? p.offsetTop+p.offsetHeight+2 : p.offsetTop;
  var left = (c["at_position"] == "x") ? p.offsetLeft+p.offsetWidth +2 : p.offsetLeft;

  //for (; p; p = p.offsetParent)
  //{
  //  top  += p.offsetTop;
  //  left += p.offsetLeft;
  //}

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** at_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}
function showBubble( text ) {
	document.getElementById( 'bubble' ).innerHTML = text;
	document.getElementById( 'bubble' ).style.display = "block";
}
function hideBubble() {
	document.getElementById( 'bubble' ).style.display = "none";
	document.getElementById( 'bubble' ).innerHTML = '';
}
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
function DashPos(){
	var DashDiv = document.getElementById("DashContainer");
	var winX = pageWidth();
	var winY = pageHeight();
	var cookieLeft = Get_Cookie('Dashboard-x');
	var cookieTop = Get_Cookie('Dashboard-y');
	if (parseFloat(cookieLeft) > 0){
		var DashLeft = Math.min(parseFloat(cookieLeft),winX-325);
		if (DashLeft < parseFloat(cookieLeft)) Set_Cookie('Dashboard-x',DashLeft);
	} else {
		var DashLeft = 10;
	}
	if (parseFloat(cookieTop) > 0){
		var DashTop = Math.min(parseFloat(cookieTop),winY-90);
		if (DashTop < parseFloat(cookieTop)) Set_Cookie('Dashboard-y',DashTop);
	} else {
		var DashTop = 10;
	}
	if (Get_Cookie('DashFlow')=='hidden'){
		document.getElementById('DashFlow').style.display='none';
		document.getElementById('DashButton').src = 'images/framework/maximize.jpg';
	} else {
		document.getElementById('DashFlow').style.display='block';
		document.getElementById('DashButton').src = 'images/framework/minimize.jpg';
	}
	DashDiv.style.top = DashTop + 'px';
	DashDiv.style.left = DashLeft + 'px';
	DashDiv.style.display='block';
}
function toggleDashFlow () {
	if(document.getElementById('DashFlow').style.display=='none'){
		document.getElementById('DashFlow').style.display='block';
		document.getElementById('DashButton').src = 'images/framework/minimize.jpg';
		Set_Cookie('DashFlow', 'visible');
	} else {
		document.getElementById('DashFlow').style.display='none';
		document.getElementById('DashButton').src = 'images/framework/maximize.jpg';
		Set_Cookie('DashFlow','hidden');
	}
}
function CheckUploadType( obj, fileName, fileTypes ) {
	if (!fileName) return;
	dots = fileName.split(".")
	fileType = "." + dots[dots.length-1].toLowerCase();
	fileTypes[0] = "." + fileTypes[0];
	if (fileTypes.join(".").toLowerCase().indexOf(fileType) != -1) {
		obj.className = "";
	} else {
		obj.style.backgroundColor='pink';
		alert("This file will not be accepted due to its type (" + fileType + ").\n\nWe only accept the following types of files: \n\n" + (fileTypes.join(" .")) + "\n\nPlease re-select another file.");
	}
}
function SameAsBuilder (p,a,w) {
	var d=new Date();
	var t = escape(d.toString());
	$.get('/ajax/MakeSameAs.cfm', {p: p, a: a, w: w, t: d },function(data){alert(data.replace(/^\s+|\s+$/g,""));});
	//alert( 'Created' );
	return false;
}
function slideSwitch() {
    var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');
    // uncomment the 3 lines below to pull the images in random order
    //var $sibs  = $active.siblings();
    //var rndNum = Math.floor(Math.random() * $sibs.length );
    //var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() { $active.removeClass('active last-active'); });
}
		
