function openFeedbackPopup()
{
	// NOTE: the LanguageID and TopicID are hardcoded right now
	// that will need to change when we know exactly how it will work
	// the content of the popup is also hardcoded for now
	var theWindow = window.open(fullWebAppPath + '/FeedbackPopupView/LanguageID=1000/TopicID=1040', '', 'width=200, height=100');
}

function openPresentation (url) {
	var cks=document.cookie.split(';');
	var state = null;
	var i;
	var nDays = 1;

	for(i=0;i<cks.length;i++)
	{
		if(cks[i].indexOf("sxtree")!=-1)
		{
			state=cks[i].substring(cks[i].indexOf("=")+1);			
			break;
		}
	}	
	
	if(state!=null)
	{
		if (nDays>0)
		{
			var now=new Date();
		 	//fixDate(now);
			//Fix the Date
			var base=new Date (0);
			var off = base.getTime();
			if (off>0)now.setTime(now.getTime()-off);
			
			now.setTime(now.getTime()+nDays*24*60*60*1000);
			var strnow=now.toGMTString();
		
			document.cookie="sxtree="+state+"; expires="+strnow;
		}

		var retVal = window.open(url+"?state="+state,"","height=451,width=612,status=no,toolbar=no,menubar=no,location=no,titlebar=no,scrollbars=yes"); 

	}
	else
	{
		var retVal = window.open(url,"","height=451,width=612,status=no,toolbar=no,menubar=no,location=no,titlebar=no,scrollbars=yes"); 
	}
}

// Added to make "email a friend" more generic.
function openEmailAFriend(url) {
	var cks=document.cookie.split(';');
	var state = null;
	var i;
	var nDays = 1;

	url = url + window.location.href;
	
	for(i=0;i<cks.length;i++)
	{
		if(cks[i].indexOf("sxtree")!=-1)
		{
			state=cks[i].substring(cks[i].indexOf("=")+1);			
			break;
		}
	}	
	
	if(state!=null)
	{
		if (nDays>0)
		{
			var now=new Date();
		 	//fixDate(now);
			//Fix the Date
			var base=new Date (0);
			var off = base.getTime();
			if (off>0)now.setTime(now.getTime()-off);
			
			now.setTime(now.getTime()+nDays*24*60*60*1000);
			var strnow=now.toGMTString();
		
			document.cookie="sxtree="+state+"; expires="+strnow;
		}

		var retVal = window.location.href = url+"&state="+state ;

	}
	else
	{
		//var regexp= new RegExp("<.*>", "g");//use if html needs to be stripped out of the email title.
		var regexp2= new RegExp("&(.)*?;", "g");//use if escape sequences need to be stripped out the email title.
		var regexp3= new RegExp("\s&\s");//use to strip '&' surrounded by space
		url= url.replace(regexp2, "%26$1;")
		url= url.replace(regexp3, "and");
		//window.alert(url);
		var retVal= window.location.href = url;
	}
}


function openPF_Presentation (url) {
	var retVal = window.open(url,"","height=550,width=612,status=no,toolbar=yes,menubar=yes,location=no,titlebar=no,scrollbars=yes"); 
}


function openBlank (url) {
//	Changed from specs to default params for new window.  Allows Browser to determine size, etc.
//	var retVal = window.open(url, "", "height=550, width=612, left=status=yes,toolbar=yes,menubar=yes,location=yes,titlebar=yes,scrollbars=yes,resizable=yes");
	var reVal = window.open(url);
}

function openAlertWindow (msg) {
	var windowWidth = 300;
	var windowHeight = 150;
	var centerLeft = (screen.width-windowWidth)/2;
	var centerTop = (screen.height-windowHeight)/2;
	var retVal = window.open(fullWebAppPath + "/ErrorAlertView?ErrorMessage="+ encodeURIComponent(msg),"","height="+windowHeight+",width="+windowWidth+", left="+centerLeft+", top="+centerTop+",status=no,toolbar=no,menubar=no,location=no,titlebar=no,scrollbars=yes");
	retVal.moveTo(centerLeft, centerTop); 
}

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];}
}

function changeLanguage()
{
	document.location.href = document.getElementById("firstpart").value + 
		document.getElementById("secondpart").value + 
		document.getElementById("thirdpart").value + "&link=Y";
}

function toggleLanguage(oldLang){
	var surl = window.location.href;
	var newLang = document.forms['langform'].newLanguage.value
	surl = surl.replace(oldLang, newLang);
	window.location.href= surl;
}

function changeLanguageHomepage()
{
	document.location.href = document.getElementById("firstpart").value + 
		document.getElementById("secondpart").value + 
		document.getElementById("thirdpart").value;
}

function storeState(state)
{
	document.cookie = "state=" + state + ";path=/";
}

function populateModifyLanguageURLNameDisplayName(DisplayNameFieldId, URLNameFieldId, LanguageOptionBoxId, AllLanguage)
{
	var displayNameTextField = document.getElementById(DisplayNameFieldId)
	var URLNameField = document.getElementById(URLNameFieldId)
	var languageOptionBox = document.getElementById(LanguageOptionBoxId)
	displayNameTextField.value = "";
	
	var allLanguageArray = new Array()
	allLanguageArray = AllLanguage.split(":::")
	
	// loop through the array to find its URL name and display name
	var i = 0
	for (i = 0; i < allLanguageArray.length - 1; i=i+3)
	{
		if (allLanguageArray[i] == languageOptionBox.value)
		{
			URLNameField.value = allLanguageArray[i + 1];
			displayNameTextField.value = allLanguageArray[i + 2];
		}
	}
}

function populateModifyTopicURLNames(TopicUrlNameFieldId, DefaultLanguageUrlNameFieldId, DefaultAssetIdUrlNameFieldId, TopicOptionBoxId, AllTopic)
{
	var topicUrlNameTextField = document.getElementById(TopicUrlNameFieldId);
	var defaultLanguageUrlNameTextField = document.getElementById(DefaultLanguageUrlNameFieldId);
	var defaultAssetIdUrlNameTextField = document.getElementById(DefaultAssetIdUrlNameFieldId);
	var topicOptionBox = document.getElementById(TopicOptionBoxId);

	var allTopicArray = new Array();
	allTopicArray = AllTopic.split(":::");
	
	// loop through the array to find its URL name, defaultLanguageUrlName, and defaultAssetIdUrlName
	var i = 0;
	for (i=0; i<allTopicArray.length - 1; i=i+4)
	{
		if (allTopicArray[i] == topicOptionBox.value)
		{
			topicUrlNameTextField.value = allTopicArray[i+1];
			defaultLanguageUrlNameTextField.value = allTopicArray[i+2];
			defaultAssetIdUrlNameTextField.value = allTopicArray[i+3];
		}
	}
}
