var strFormErrMsg = ""

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_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_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];}
}

function displayToggle(id)
{ 
var el = document.getElementById(id).style; 
var eA = document.getElementById('About').style; 
var eB = document.getElementById('Publications').style; 
var eC = document.getElementById('Programs').style;
var eD = document.getElementById('People').style;
var eE = document.getElementById('Newsroom').style;

	if(el.display == "none")
	{ 
		eA.display = "none";
		eB.display = "none";
		eC.display = "none";
		eD.display = "none";
		eE.display = "none";
		el.display = "block"; 
	} 
	else if(el.display == "block")
	{ 
		el.display = "none"; 
	} 
}

function openMenu(branch)
{
	if (branch > "")
	{
		displayToggle(branch);
	}
}

function doHighlight(frmElement)
{
	if ((frmElement.value == "your email address") || (frmElement.value == "your first name"))
	{
		frmElement.select();
	}
}

function doRegister()
{
	if (checkEmail(document.regfrm.regEmail) && (document.regfrm.regName.value > "") && (document.regfrm.regName.value != "your first name") )
	{
		document.regfrm.action = "/RegisterForNews.asp";
		document.regfrm.submit();
	}
	else
	{
		alert("Please enter your first name and a valid email address.");
		document.regfrm.regEmail.focus();
	}
}

function checkRegisterForm(formname)
{
strFormErrMsg = "";

	checkText(formname.Title, " - Title");
	checkText(formname.FirstName, " - First name");
	checkText(formname.LastName, " - Last name");
	if (checkEmail(formname.Email) == 0)
	{
		strFormErrMsg = strFormErrMsg + "\n - Valid email address";
	}
	
	
	if (strFormErrMsg == "")
	{
		formname.action = "/RegisterForNewsThankyou.asp";
		formname.submit();
	}
	else
	{
		alert("Please fill out the following fields:\n" + strFormErrMsg);
	}	
}

function toggleAllInterests(formname, objAll, strname, startnum, endnum)
{
var flagcheck = 0;
var intCountAnswers = 0;

	if (objAll.checked == false)
	{
		for (var i=startnum; i<=endnum; i++) 
		{
			eval("formname." + strname + i + ".checked" + "= false;")
		}
	}
	else
	{
		for (var i=startnum; i<=endnum; i++) 
		{
			eval("formname." + strname + i + ".checked" + "= true;")
		}
	}

}

function doPreLoad()
{
	MM_preloadImages('images/Nav-Home-On.gif','images/Nav-About-On.gif','images/Nav-Publications-On.gif','images/Nav-Programs-On.gif','images/Nav-People-On.gif','images/Nav-Newsroom-On.gif','images/Nav-Contact-On.gif','images/Nav-Search-On.gif');
}

function doSearch()
{
	if (document.searchfrm.searchText.value == "")
	{
		alert("Please enter keywords separated by spaces.");
	}
	else
	{
		document.searchfrm.action = "/Search.asp";
		document.searchfrm.submit();
	}
}

function getNews(thefrm, strDate)
{
	thefrm.m.value = strDate.substr(0, 2);
	thefrm.y.value = strDate.substr(2, 4);
	thefrm.submit();
}

function doAuthorSearch(intID)
{
	document.frmS.process.value = "search";
	document.frmS.author.value = intID;
	document.frmS.submit();
}

function doSubjectSearch(intID)
{
	document.frmS.process.value = "search";
	document.frmS.subject.value = intID;
	document.frmS.submit();
}

function searchType(i)
{
document.frmPubsLink.pubtype.value = i;
document.frmPubsLink.submit();
}

function checkEmail(afield)
{
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if (re.test(afield.value) == false)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}

function checkText(objtext, strcomment)
{
var flagcheck = 0;
var strText = "";
var strChar = "";
var x = 0;

	strText = objtext.value;
	if (strText > "")
	{
		strChar = strText.substr(x, 1);
		while ((strChar == " ") && (x < strText.length))
		{
			x = x + 1;
			if (x < strText.length)
			{
				strChar = strText.substr(x, 1);
			}
		}
		
		if (x > 0)
		{
			if (x == strText.length)
			{
				strText = "";
			}
			else
			{
				strText = strText.substr(x);
			}
		}
		
		objtext.value = strText;
		
		if (strText != "")
		{
			flagcheck = 1;
		}
	}
	
	if (flagcheck == 0)
	{
		strFormErrMsg = strFormErrMsg + "\n" + strcomment;
	}

	return(flagcheck);	
}

function showBigImage(strImage, imageID)
{
	imageID.src = strImage;
}


function resizeSidebarImages()
{
	var imgheight;
	var imgwidth;
	if (typeof document.images["topImage_SidebarInc"] == 'object')
	{
		imgheight = document.images["topImage_SidebarInc"].height;
		imgwidth = document.images["topImage_SidebarInc"].width;
		if (imgwidth > 125)
		{
			document.images["topImage_SidebarInc"].width = 125;
		}
//		else
//		{
//			document.images["bottomImage_SidebarInc"].width = imgwidth;
//		}
	}
	if (typeof document.images["bottomImage_SidebarInc"] == 'object')
	{
		imgheight = document.images["bottomImage_SidebarInc"].height;
		imgwidth = document.images["bottomImage_SidebarInc"].width;
		if (imgwidth > 125)
		{
			document.images["bottomImage_SidebarInc"].width = 125;
		}
//		else
//		{
//			document.images["bottomImage_SidebarInc"].width = imgwidth;
//		}
	}
}

function popFora(strForaCode)
{
var popFora;
	
	popFora = window.open("/Fora-Popup.asp?sViewClip=" + strForaCode, "ForaPop", "menubar=yes,resizable=yes,height=350,width=500");
	popFora.focus();

}

function popPub(pid)
{
var popPub;
	
	popPub = window.open("/PublicationPop.asp?pid=" + pid, "PubPop_" + pid, "menubar=yes,resizable=yes,height=278,width=325");
	popPub.focus();
}

function doVideoPop(strFLV, theobj) {

    // Apply the Highslide settings
    hs.graphicsDir = '/include/highslide/graphics/';
    hs.outlineType = 'rounded-white';
    hs.wrapperClassName = 'draggable-header no-footer';
    hs.allowSizeReduction = false;
    // always use this with flash, else the movie will be stopped on close:
    hs.preserveContent = false;

    hs.src = "/include/media/player.swf";
    hs.swfOptions.version = "9";
    hs.swfOptions.expressInstallSwfurl = null;

    if (strFLV.substr(0, 4).toLowerCase() == "http") {
        hs.swfOptions.flashvars.file = strFLV;
    }
    else {
        hs.swfOptions.flashvars.file = "http://lowyinstitute.richmedia-server.com/video/" + strFLV;
    }

    hs.swfOptions.flashvars.skin = "/include/media/stijl.swf";
    hs.swfOptions.params.allowscriptaccess = "always";
    hs.swfOptions.params.allowfullscreen = "true";
    hs.swfOptions.flashvars.autostart = "true";
	hs.swfOptions.flashvars.bufferlength = "5";

    return hs.htmlExpand(theobj, { objectType: 'swf', width: 600, objectWidth: 600, objectHeight: 374, maincontentText: 'You need to upgrade your Flash player' });
}


function doVPopSize(strFLV, theobj, intwidth, intobjectWidth, intobjectHeight) {

    if (intwidth == -1) {
        intwidth = 600;
    }
    if (intobjectWidth == -1) {
        intobjectWidth = 600;
    }
    if (intobjectHeight == -1) {
        intobjectHeight = 374;
    }

    // Apply the Highslide settings
    hs.graphicsDir = '/include/highslide/graphics/';
    hs.outlineType = 'rounded-white';
    hs.wrapperClassName = 'draggable-header no-footer';
    hs.allowSizeReduction = false;
    // always use this with flash, else the movie will be stopped on close:
    hs.preserveContent = false;


    hs.src = "/include/media/player.swf";
    hs.swfOptions.version = "9";
    hs.swfOptions.expressInstallSwfurl = null;

    if (strFLV.substr(0, 4).toLowerCase() == "http") {
        hs.swfOptions.flashvars.file = strFLV;
    }
    else {
        hs.swfOptions.flashvars.file = "http://lowyinstitute.richmedia-server.com/video/" + strFLV;
    }

    hs.swfOptions.flashvars.skin = "/include/media/stijl.swf";
    hs.swfOptions.params.allowscriptaccess = "always";
    hs.swfOptions.params.allowfullscreen = "true";
    hs.swfOptions.flashvars.autostart = "true";
    hs.swfOptions.flashvars.bufferlength = "5";

    return hs.htmlExpand(theobj, { objectType: 'swf', width: intwidth, objectWidth: intobjectWidth, objectHeight: intobjectHeight, maincontentText: 'You need to upgrade your Flash player' });
}


function highslidePopFlash(strFLV, theobj, intwidth, intobjectWidth, intobjectHeight) {
    var strPathToFlash;

    if (intwidth == -1) {
        intwidth = 600;
    }
    if (intobjectWidth == -1) {
        intobjectWidth = 600;
    }
    if (intobjectHeight == -1) {
        intobjectHeight = 374;
    }


    if (strFLV.substr(0, 4).toLowerCase() == "http") {
        strPathToFlash = strFLV;
    }
    else {
        strPathToFlash = "http://lowyinstitute.richmedia-server.com/video/" + strFLV;
    }


    // Build Highslide Object(s)

    var objALLOptions = {
        outlineType: 'rounded-white',
        wrapperClassName: 'draggable-header no-footer',
        allowSizeReduction: false,
        preserveContent: false,
        slideshowGroup: 'flshflv',
        objectType: 'swf',
        src: "/include/media/player.swf",
        width: intwidth, 
        objectWidth: intobjectWidth, 
        objectHeight: intobjectHeight, 
        maincontentText: 'You need to upgrade your Flash player',
        swfOptions: {
            version: "9",
            expressInstallSwfurl: null,
            flashvars: {
                file: strPathToFlash,
                skin: "/include/media/stijl.swf",
                autostart: "true",
                bufferlength: "5"
                },
            params: {
                allowscriptaccess: "always",
                allowfullscreen: "true"
            }
        }
    };
    

    return hs.htmlExpand(theobj, objALLOptions);

}
