//Script for controlling Pop Up/Down Windows

var windowWidth, windowHeight;
var str;

//Controls SiteMap
function SiteMap()
{
	windowWidth = 310;
	windowHeight = 450;
	str = "scrollbars=yes,toolbar=no,menubar=no,status=no";
	openModelessWindow("/SiteMap/Sitemap.asp", "SiteMap", str, windowWidth, windowHeight);
}
//function SubscribeNow()
//{
//	windowWidth = 310;
//	windowHeight = 50;
//	str = "scrollbars=yes,toolbar=no,menubar=no,status=no";
//	openModelessWindow("about:blank", "WndSubscribe", str, windowWidth, windowHeight);
//	document.SubForm.action='/Subscribe/SubscribeResp.asp'
//	document.SubForm.submit();
//}
function UnsubscribeNow()
{
	windowWidth = 310;
	windowHeight = 50;
	str = "scrollbars=yes,toolbar=no,menubar=no,status=no";
	openModelessWindow("about:blank", "WndSubscribe", str, windowWidth, windowHeight);
	document.SubForm.action='/Subscribe/UnSubscribeResp.asp'
	document.SubForm.submit();
}
//Controls Poll. Remove .blur() on the last line of this function to have the poll pop up.

function OpenPoll()
{
	windowWidth = 325;
	windowHeight = 275;
	str = "scrollbars=no,toolbar=no,menubar=no,status=no";
	openModelessWindow("/Poll/Poll.asp", "Poll", str, windowWidth, windowHeight).blur();
}

var toolsWindow=null;


		//alert("hi");
function tools(mypage,myname,w,h,pos,infocus){

	if(pos=='random'){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=='center'){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!='center' && pos!='random') || pos==null){
		LeftPosition=100;
		TopPosition=100;
	}
	settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=no,dependent=no';
	toolsWindow=window.open('',myname,settings);
	if(infocus=='front'){
		toolsWindow.focus();toolsWindow.location=mypage+'&Title='+strNodeTitle;
	}
}


// Create a cookie with the specified name and value.
// The cookie expires at the end of the 20th century.
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
}

//This example retrieves the value of the portion of the cookie specified by the sCookie parameter.
// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split(";");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == Trim(aCrumb[0])) 
      return unescape(Trim(aCrumb[1]));
  }

  // a cookie with the requested name does not exist
  return null;
}

/////////////////////////////////////////////////////////////////////////
// function strTrim(str) - 
// params:	str - string to be trimmed
//
// This function removes white space at the beginning and end of the 
// string and returns the altered string without the leading and 
// trailing white space. If a null string is passed, a null string 
// will be returned. 
//
function Trim(str)
{
	var i, j;
	
	if (str == null)
		return "";

	str = str.toString();
		
	var nLen = str.length;

	for (i = 0; i < nLen; i++)
	{
		if (str.charAt(i) != ' ')
		{	
			break;
		}
	}
	
	for (j = nLen; j >= 0; j--)
	{
		if (str.charAt(j-1) != ' ')
		{
			break;
		}
	}

	if (i > j)
		return "";
	else
		return str.substring(i,j);
}

/////////////////////////////////////////////////////////////////////////
// function trimTextField(textField) - 
// params:	textField - text box to be trimmed
//
// This function removes white space at the beginning and end of the 
// text box.
//
function trimTextField(textField)
{
	if (textField.value == "")
		return;
	
	textField.value = Trim(textField.value);
}

/////////////////////////////////////////////////////////////////////////
// function CheckLegalText(strText) - 
//
// This function will filter
// out invalid characters.
//
function CheckLegalText(strText)
{
	var strInvalidCharacters = "";
	for (var lngIndex = 0; lngIndex < strInvalidCharacters.length; lngIndex++)
	{
		var chr = strInvalidCharacters.charAt(lngIndex);
		if (strText.search(chr) != -1)
		{
			alert("'" + strInvalidCharacters + "' are not valid characters. Please try again.");
			return false;
		}
	}
			
	return true;
}

/////////////////////////////////////////////////////////////////////////
// function MM_findObj(n,d) - 
//
// This function perform mouse over image swaps
//
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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;}/* Functions that swaps images. */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_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 newImage(arg) {	if (document.images) {		rslt = new Image();		rslt.src = arg;		return rslt;	}}function changeImages() {	if (document.images && (preloadFlag == true)) {		for (var i=0; i<changeImages.arguments.length; i+=2) {			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];		}	}}

function FindNode(argOrigNodeId,argOrigNodeDesc)
{
	var windowWidth, windowHeight;
	var str;

	windowWidth = 500;
	windowHeight = 250;
	str = "toolbar=no,menubar=no,status=no,scrollbars=1,resizeable=1,scrolling=yes";

	openModelessWindow("/Admin/Common/FindNode.asp?OrigNodeDesc="+argOrigNodeDesc+"&OrigNodeId="+argOrigNodeId, "FindNode", str, windowWidth, windowHeight);
}
