// $Header: //ems1/branches/wess_4.6/emf/emfmta/www/source/img/emf.js#1 $
// $Log: emf.js,v $
//
// 20 JAN 2010	yuvaraj
// Added function to detect Internet Explorer versions or detect other browsers.
// Please use this getInternetExplorerVersion() function to fix IE specific bugs
//
// Revision 1.9  2006/05/25 09:59:08  ben
// graphical updates since infosec 2006
//
// Revision 1.8  2006/02/24 18:20:05  jim
// Improved timezone support
//
// Revision 1.7  2006/01/12 15:35:19  jim
// Added session timezone support
//
// Revision 1.6  2006/01/11 17:39:32  jim
// Added get_timezone_offset function
//
// Revision 1.5  2005/11/30 16:57:44  rs
// Using square brackets for forms collection
//
// Revision 1.4  2005/07/26 12:29:55  ben
// took long path from help launcher
//
// Revision 1.3  2005/04/24 17:25:21  jim
// fixed some javascript errors
//
// Revision 1.1  2005/04/19 14:02:24  jim
// Moved comman javascript to emf.js
//

function selectAll(elem)
{
	if (typeof elem.length != 'undefined')
	{
		for (i=0; i< elem.length; i++)
		{
			elem[i].checked = true;
		}
	}
	else
	{
		elem.checked = true;
	}
}

function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1 (other browsers)
{
	var rv = -1; // Return value assumes failure.
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		{
			rv = parseFloat( RegExp.$1 );
		}
	}
	return rv;
}

function open_window(target, title)
{
	var win = window.open(target, title, config='height=400,width=500,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
	win.focus();
}

function open_help(helpserver,target)
{
	theUrl=helpserver+"";
	window.open(theUrl,'Help','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=800,height=600,top=100,left=100');
}

function check_cboxes(name, check)
{
	var ver = getInternetExplorerVersion();
	if (( ver> -1 ) && ( ver < 8.0 ))
	{
		a = document.all(name);
		if (a)
		{
			for (c=0;c<a.length;++c)
			{
				a[c].checked = check;
			}
		}			
	}
	else // Internet Explorer 8.0 and up, Mozilla, other standards compliant browser
	{
		a = document.getElementsByTagName("input");
		if (a)
		{
			for (c=0;c<a.length;++c)
			{
				if (a[c].name == name)
				{
					a[c].checked = check;
				}
			}
		}
	}
}

function hide_pleasewait()
{
	var a;
	a = document.getElementById("pleasewait");
	if(a!=null) a.style.visibility="hidden";
	a = document.getElementById("_xpbar0");
	if(a!=null) a.style.visibility="hidden";
}

function disable_buttons()
{
	var a = document.getElementsByTagName("input");
	if(a!=null)
		for (var i = 0; i < a.length; i++)
		{
			if(a.item(i).type.toLowerCase() == "submit")
				a.item(i).disabled=true;
		}
	return true;
}

function copy_and_disable(clickedbtn, jvsavename, formname)
{
	var a, i;
	a = document.getElementsByName(jvsavename);
	if(a!=null)
		for (i = 0; i < a.length; i++)
		{
			a.item(i).value = clickedbtn.name;
		}

	a = document.getElementsByTagName("input");
	if(a!=null)
		for (i = 0; i < a.length; i++)
		{
			if(a.item(i).type.toLowerCase() == "submit")
				a.item(i).disabled=true;
		}

	document.forms[formname].submit();
	return false;
}

// find time offset in minutes from GMT/UTC/Zulu
// and enter it into the specified field
// plus localtime
function set_client_timezone(tzfieldname,localtimefieldname,localunixtime)
{
	//alert('tzfieldname = ' + tzfieldname);
	//alert('localtimefieldname = ' + localtimefieldname);
	//alert('localunixtime = ' + localunixtime);
	
	var curDateTime = new Date();
	var f=(document.all)?document.all[tzfieldname]:document.getElementById(tzfieldname);
	if(f!=null)
		f.value=-curDateTime.getTimezoneOffset();
	var g=(document.all)?document.all[localtimefieldname]:document.getElementById(localtimefieldname);
	if(g!=null)
		g.value=curDateTime;
	var h=(document.all)?document.all[localunixtime]:document.getElementById(localunixtime);
	if(h!=null)
		h.value=Date.parse(curDateTime)/1000;
}

function flash_anim(filename, width, height) // created to fix the new Microsoft "click to activeX" problem
{
	document.write('<OBJECT width='+width+' height='+height+' classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" '+
		'codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0">'+
		'<param name="WMode" value="Transparent"/>'+
		'<param name="BGColor" value=""/>'+
		'<param name=movie value="'+filename+'">'+
		'<param name=quality value=high>'+
		'<EMBED wmode="transparent" src="'+filename+'" width='+width+' height='+height+' quality=high '+
		'pluginspage="https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" '+
		'type="application/x-shockwave-flash"></EMBED></OBJECT>');
}

function setStyleByClass(t,c,p,v)
{
	var elements;
	if(t == '*')
	{
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	}
	else
	{
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++)
	{
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++)
		{
			if(node.attributes.item(j).nodeName == 'class')
			{
				if(node.attributes.item(j).nodeValue == c)
				{
			  		eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

function swap(opt)
{
	
	var val = document.getElementById(opt).checked?(document.all?"block":"table-cell"):"none";
		
	for(var i = 1; i < 6; i++)
	{
	  document.getElementById(opt + "_" + i).style.display=val;
	}
}

function swapDomainMappingOption(elem, target)
{
	var targetElement = '';
	targetElement = document.getElementById(target);

	if(elem.checked) {
		targetElement.className = 'optionGroupItemParamBlackText';
		targetElement.removeAttribute('readOnly',true);
		if(target=='outboundManualTextArea') {
			document.getElementById('outboundManualSelect').removeAttribute('disabled',true);
		} else if (target=='inboundManualTextArea') {
			document.getElementById('inboundManualSelect').removeAttribute('disabled',true);
		}
	} else {
		targetElement.className = 'optionGroupItemParamGreyText';
		targetElement.setAttribute('readOnly',true);
		if(target=='outboundManualTextArea') {
			document.getElementById('outboundManualSelect').setAttribute('disabled',true);
		} else if (target=='inboundManualTextArea') {
			document.getElementById('inboundManualSelect').setAttribute('disabled',true);
		}
	}
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}