// popup functions
var newwin;
var sitesurveywin;
var flakeswin;

function GoToSurvey(url, windowname)
 {
 	if (sitesurveywin)
 	{
 		if (sitesurveywin.closed)
 		{
 			//alert("Site survey win closed!");
			sitesurveywin = window.open(url,windowname,'width=700,height=520,scrollbars=yes,resizable=yes');
 		}
 		else
 		{
			//alert("Focus on Site survey win");
			sitesurveywin.focus();
 		}
 	}
 	else
 	{
		//alert("Making new Site survey win");
 		sitesurveywin = window.open(url,windowname,'width=700,height=520,scrollbars=yes,resizable=yes');
 	}
 }

function launchwin(winurl,winname,winfeatures)
{
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	//intX = 0;	// value for x position on screen
	//intY = 0;	// value for y position on screen
	
	//winfeatures = winfeatures + 'top=' + intX + ', screenX =' + intX + ', left=' + intY + ', screenY = ' + intY;
	
	newwin = window.open(winurl,winname,winfeatures);
	newwin.opener = self;
	
	//delay a bit here because IE4 encounters errors
	//when trying to focus a recently opened window

    setTimeout('newwin.focus();',250);
}

function launchflakeswin(winurl,winname,winfeatures)
{

	//This launches a new window and then
	//focuses it if window.focus() is supported.
	flakeswin = window.open(winurl,winname,winfeatures);
	flakeswin.opener = self;
	
	//delay a bit here because IE4 encounters errors
	//when trying to focus a recently opened window

   setTimeout('flakeswin.focus();',250);
}

function closeMe()
{
result=window.confirm("do you really want to close me?");
{
if (result==true){window.alert(result);}
else{window.alert(result);}
}
}
// here is the code that goes with this function:
//<body class="popupbox" onBeforeUnload="if(ClosesWindow == true){closeMe();}" onmouseover="ClosesWindow=false;" onmouseout="ClosesWindow=true;">


function rolloverRadio(theElement,theDivName,iLeft,iTop,iWidth)		// function to pop up window from radio button
{
  if (theElement.checked) {
	switchDivSize(theDivName,true,iLeft,iTop,iWidth);
  }
  else {
  	switchDiv(theDivName,false);
  }
}

//rollover functions
	
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) { //v3.0
  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); 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];}
}

function middleString(fullString, startString, endString) {
   if (fullString.indexOf(startString) == -1) {
      return "";
   } else {
      var sub = fullString.substring(fullString.indexOf(startString)+startString.length, fullString.length);
      if (sub.indexOf(endString) == -1) {
         return sub;
      } else {
         return (sub.substring(0, sub.indexOf(endString)));
      }
   }
}

function middleBackString(fullString, startString, endString) {
   if (fullString.lastIndexOf(startString) == -1) {
      return "";
   } else {
      var sub = fullString.substring(0, fullString.lastIndexOf(startString));
      if (sub.indexOf(endString) == -1) {
         return sub;
      } else {
         return (sub.substring(sub.indexOf(endString)+endString.length, sub.length));
      }
   }
}


// generic cookie functions

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
	  
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// flip outs

function toggleFlipOut(rowName)
{	if(document.getElementById(rowName).style.display == 'none')
		{
		document.getElementById(rowName).style.display = 'inline';
		}
	else
		{document.getElementById(rowName).style.display = 'none';}
};

function flipAll()
{
	for (i=1;i<9;i++)
	{
	rowName = 'step' + i + 'flipout';
	document.getElementById(rowName).style.display = 'none'
	}
};

function highlightComp(objName, imgName)
{	
	if(document.getElementById(objName).style.color == 'black')
		{
		document.getElementById(objName).style.color = '#306530';
		MM_swapImage(imgName,'','../images/global/spacer.gif',1)
		}
	else
		{
		document.getElementById(objName).style.color = 'black';
		MM_swapImage(imgName,'','../images/global/redspacer.gif',1)
		}
	};

//-->

function txtChange(t,txtSrc,txtStyle) {
chunk = document.getElementById(t);
chunk.innerHTML = txtSrc;
if (txtStyle) {chunk.style.color = txtStyle};
}

// div functions

function showByPosition(object,x) {
    if (document.layers && document.layers[object]) {
		x = (window.innerWidth - x) / 2;
		if (x < 26) {
			x = 26;
		}
        document.layers[object].left = x;
        document.layers[object].visibility = 'visible';
    }
    else if (document.all) {
		x = (document.body.clientWidth - x) / 2;
		if (x < 26) {
			x = 26;
		}
        document.all[object].style.posLeft = x;
        document.all[object].style.visibility = 'visible';
    }
}

isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

function switchDiv(strDivName,bolVisible){

//identify the element based on browser type
if (isNS4) {
  objElement = document.layers[strDivName];
} else if (isIE4) {
  objElement = document.all[strDivName];
} else if (isIE5 || isNS6) {
  objElement = document.getElementById(strDivName);
}

if(isNS4){
    if(!bolVisible) {
      objElement.visibility ="hidden"
    } else {
      objElement.visibility ="visible"
    }     
}else{
    if(!bolVisible) {
      objElement.style.visibility = "hidden";
    } else {
      objElement.style.visibility = "visible";
    }
}
}

function switchDivSize(strDivName,bolVisible,iLeft,iTop,iWidth){

//identify the element based on browser type
if (isNS4) {
  objElement = document.layers[strDivName];
} else if (isIE4) {
  objElement = document.all[strDivName];
} else if (isIE5 || isNS6) {
  objElement = document.getElementById(strDivName);
}

if(isNS4){
    if(!bolVisible) {
      objElement.visibility ="hidden"
    } else {
      objElement.visibility ="visible"
    }     
}else{
    if(!bolVisible) {
      objElement.style.visibility = "hidden";
    } else {
      objElement.style.visibility = "visible";
	  objElement.style.left = iLeft;
	  objElement.style.top = iTop;
	  objElement.style.width = iWidth;
    }
}
}