function ShowMenuPopup (action, vMenu_ID, ppwidth, ppheight) 
{    
    document.forms[0].vMenu_ID.value = vMenu_ID;
    document.forms[0].target= '_new';
    document.forms[0].action = action;
    document.forms[0].method = 'post';
    document.forms[0].target= 'intraySearch';
    w = 600;
    h = 600;
    if(ppwidth != null)
        w=ppwidth;
    if(ppheight != null)
        h=ppheight;
    scrleft=(screen.width)?(screen.width-w)/2:100;
    scrtop=(screen.height)?(screen.height-h)/2:100;
    window.open('', 'intraySearch', 'height='+ h + ',' + 'width=' + w + ',status=0,toolbar=0,menubar=0,resizable=yes,scrollbars=yes,top=' + scrtop + ',left=' + scrleft); 	
    document.forms[0].submit();
}

function TakeMeToMenu(menuID) 
{
    document.forms[0].vMenu_ID.value = menuID;
    
    if(document.getElementById('post.AggregationService.vMenu_ID') != null)
        document.getElementById('post.AggregationService.vMenu_ID').value = menuID;
        
    document.forms[0].target="_self";
    SubmitForm("index.asp");
}

function TakeMeIPublish(action, vMenu_ID) 
{
    document.forms[0].vMenu_ID.value = vMenu_ID;
    if(document.getElementById('post.AggregationService.vMenu_ID') != null)
        document.getElementById('post.AggregationService.vMenu_ID').value = vMenu_ID;
    document.forms[0].target="_self";
    SubmitForm(action);
}

function TakeMeIPublishForm(action, vMenu_ID, formName) 
{
    document.forms[formName].vMenu_ID.value = vMenu_ID;
    document.forms[formName].target="_self";
    SubmitForm(action);
}

function TakeMeIPublishInNewWindow(action, vMenu_ID) 
{
	this.document.forms[0].vMenu_ID.value = vMenu_ID;
	this.document.forms[0].target="_blank";
	SubmitForm(action)
}

function TakeMeIPublishInNewWindowForm(action, vMenu_ID, formName) 
{
	this.document.forms[formName].vMenu_ID.value = vMenu_ID;
	this.document.forms[formName].target="_blank";
	SubmitForm(action)
}

function TakeMeThere(action)
{
    document.forms[0].target="_self";
    SubmitForm(action);
}

function TakeMeBack(action)
{
    document.forms[0].target="_self";
    SubmitForm(action);
}

function TakeMeIPublishWithFields(action, vMenu_ID)
{
    document.forms[0].ipub_readPostedFields.value = 1
    document.forms[0].vMenu_ID.value = vMenu_ID;
    document.forms[0].target="_self";
    SubmitForm(action);
}

function TakeMeToMenuWithFields(vMenu_ID, target)
{
    if (!target || target == "")
    {
      target = "_self";
    }
    document.forms[0].ipub_readPostedFields.value = 1
    document.forms[0].vMenu_ID.value = vMenu_ID;
    document.forms[0].target= target;
    SubmitForm("index.asp");
}

function TakeMeToMenuInNewWindow(vMenu_ID)
{
    document.forms[0].vMenu_ID.value = vMenu_ID;
    document.forms[0].target="_blank";
    SubmitForm("index.asp");
}

function TakeMeToMenuInNewWindowWithFields(vMenu_ID)
{
    document.forms[0].ipub_readPostedFields.value = 1
    var currentMenuID = document.forms[0].vMenu_ID.value;
    document.forms[0].vMenu_ID.value = vMenu_ID;
    document.forms[0].target="_blank";
    SubmitForm("index.asp");
    document.forms[0].ipub_readPostedFields.value = 0;
    document.forms[0].vMenu_ID.value = currentMenuID;
    
}

function SubmitWithFields(target)
{
    if (!target || target == "")
    {
      target = "_self";
    }
    document.forms[0].ipub_readPostedFields.value = 1
    document.forms[0].target=target;
    SubmitForm("index.asp");
}

function SetStep(stepID)
{
	var x = this.document.getElementById('Step');
	x.value = stepID;
}

function SubmitForm(action) 
{
	myForm = document.forms[0];
	myForm.method = "post";
	myForm.action = action;
	myForm.submit();
}

function SubmitForm_NewWindow(action) 
{	
	settings = 'toolbar=0,status=1,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes';
	mywin = window.open('', 'subManWin', settings);
	myForm = document.forms[0];
	myForm.method = "post";
	myForm.action = action;
	myForm.target = 'subManWin';
	myForm.submit();
}

function SubmitFormWithTimeOut(action)
{
	setTimeout("SubmitForm('" + action + "')", 10);
}

function getKeyCharCode(event) {
	var key = null;
	if (window.event) { //ie
		key = window.event.keyCode;
	} else if (event.which) {
		key = event.which;
	}
	return key;
} 

function checkSearchKey(event) {
	if (getKeyCharCode(event) == 13) { //13 = VK_ENTER
		SubmitForm('search.asp');
		return true;
	} else {
		return false;
	}
}

function iPublishMenuInit() 
{
	var M;
	var bContinue = true;
	for (var i=0; bContinue; i++) {
		if ($('iPublishMenu'+i)) {
			DynarchMenu.setup('iPublishMenu'+i, { vertical: true, electric: true });
		} else bContinue = false;
	}
	bContinue = true;
	for (var i=0; bContinue; i++) {
		if ($('iPublishMenuH'+i)) {
			DynarchMenu.setup('iPublishMenuH'+i, { electric: true });
		} else bContinue = false;
	}
}

function get(name)
{
  controls = document.getElementsByName(name);
  value = "";
  if (controls.length == 1)
  {
    var control = controls[0];
    if (control.options)
    {
      value = control.options[control.selectedIndex].text;
    }
    else if (control.type == 'checkbox')
    {
      if (control.checked)
      {
        value = control.value;
      }
    }
    else
    {
      value = control.value;
    }
  }
  else
  {
    for (i = 0; i != controls.length; i++)
    {
      if (controls[i].checked)
      {
        if (value != "")
        {
          value = value + ",";
        }
        value += controls[i].value;
      }
    }
  }
  return value;
}

function getValue(name)
{
	return get(name);
}
		
function set(name, value)
{
	controls = document.getElementsByName(name);
	if (controls.length == 1)
	{
		if (controls[0].options)
		{
			if (value != "")
			{
				var options = controls[0].options
				for (var index = 0; index != options.length; index++)
				{
					if (options[index].value == value)
					{
						options[index].selected = true;
						break;
					}
				}
			}
			else
			{
				controls[0].selectedIndex = -1;
			}
		}
		else
		{
			controls[0].value = value;
		}
	}
	else
	{
		for (var index = 0; index != controls.length; index++)
		{
			if (value == "")
			{
				controls[index].checked = false;
			}
			else
			{
				if (controls[index].value == value)
				{
					controls[index].checked = true;
					break;
				}
			}
		}
	}
	return value;
}
      
function fontsizeup() 
{
  active = getActiveStyleSheet();
  switch (active) {
    case 'A--' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A++');
      break;
    case 'A++' :
      break;
    default :
      setActiveStyleSheet('A-');
      break;
  }
}

function fontsizedown() 
{
  active = getActiveStyleSheet();
  switch (active) {
    case 'A++' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A--');
      break;
    case 'A--' : 
       break;
    default :
      setActiveStyleSheet('A-');
      break;
  }
}

function setActiveStyleSheet(title) 
{
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() 
{
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('A-');
}

function createCookie(name,value,days) 
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else expires = "";
  var secure = (window.location.protocol=="https:") ? "; secure" : "";
  document.cookie = name +"="+ value + expires +"; path=/"+ secure;
}

function readCookie(name) 
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


Event.observe(window, 'load', function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  iPublishMenuInit();

  if ($('dvRelatedinfo') && $('tblRelatedinfo')) {
    if ($('dvRelatedinfo').innerHTML != "") {
      $('tblRelatedinfo').style.display = "";
    }
  }
  if ($('dvMenu')) { DisplayMenus();}
});

window.onunload = function(e) {
Event.observe(window, 'unload', function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
});

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}
};

function callAggregationService(updateSection, command, renderer, AggregParams, objectParam)
{
	
	var pars = 'command=' + command +'&renderer=' + renderer + '&objectparam=' + objectParam + AggregParams;
	var url = 'aggreg_service.asp';
	

	var myAjax = new Ajax.Request(
		url,
		{
			method: 'post',
			parameters: pars,
			onComplete: function(response)
			{
				Element.replace('aggreg_comm_result', response.responseText);	
			}
		}
	);

}



function popup(url)
{
  locstr = "resizable=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no";
  window.open(url, "_new");
}
      
function displayErrorPopup(lvError)
{
   var msgWindow = window.open("error.asp?lvError=" + lvError,"displayWindow","directories=no,height=222,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=405");
   msgWindow.self.focus();
   return false;
}

